xref: /inferno-os/lib/acid/386 (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1// 386 support
2
3defn acidinit()			// Called after all the init modules are loaded
4{
5	bpl = {};
6	bpid = -1;
7	bpfmt = 'b';
8
9	srcpath = {
10		"./",
11	};
12
13	nopstop = 0;
14	srcfiles = {};			// list of loaded files
15	srctext = {};			// the text of the files
16	Labspoff = 4;		// adjustment to Label's sp
17	Labpcoff = 0;		// adjustment to Label's pc
18}
19
20defn linkreg(addr)
21{
22	return 0;
23}
24
25defn stk()				// trace
26{
27	_stk(*PC, *SP, 0, 0);
28}
29
30defn lstk()				// trace with locals
31{
32	_stk(*PC, *SP, 0, 1);
33}
34
35defn kstk()				// kernel stack, PC and SP point to kernel
36{
37	_stk(*PC, *SP, 0, 0);
38}
39
40defn lkstk()				// kernel stack and locals, PC and SP are kernel's
41{
42	_stk(*PC, *SP, 0, 1);
43}
44defn gpr()		// print general(hah hah!) purpose registers
45{
46	print("AX\t", *AX, " BX\t", *BX, " CX\t", *CX, " DX\t", *DX, "\n");
47	print("DI\t", *DI, " SI\t", *SI, " BP\t", *BP, "\n");
48}
49
50defn spr()				// print special processor registers
51{
52	local pc;
53	local cause;
54
55	pc = *PC;
56	print("PC\t", pc, " ", fmt(pc, 'a'), "  ");
57	pfl(pc);
58	print("SP\t", *SP, " ECODE ", *ECODE, " EFLAG ", *EFLAGS, "\n");
59	print("CS\t", *CS, " DS\t ", *DS, " SS\t", *SS, "\n");
60	print("GS\t", *GS, " FS\t ", *FS, " ES\t", *ES, "\n");
61
62	cause = *TRAP;
63	print("TRAP\t", cause, " ", reason(cause), "\n");
64}
65
66defn regs()				// print all registers
67{
68	spr();
69	gpr();
70}
71
72defn step()
73{
74	local ur;
75	local addrs;
76	local id;
77	local l;
78	local b;
79	local bl;
80	local sl;
81	local pc;
82
83	complex Proc proc;
84	ur = proc.dbgreg;
85	if ur == 0 then
86		error("step: process not in breakpoint trap");
87	complex Ureg ur;
88
89	 //
90	 // stop all kprocs that could potentially hit this breakpoint
91	 // make a list of all the breakpoints at this address
92	 //
93	bl = {};
94	sl = {};
95	l = bpl;
96
97	while l do {
98		b = head l;
99		if ((b[2] & *PC) == b[2]) then {
100			if status(b[1]) != "Stopped" then {
101				stop(b[1]);
102				sl = append sl, b[1];
103			}
104			bl = append bl, b;
105		}
106		l = tail l;
107	}
108
109	 //
110	 // delete all the breakpoints at this address
111	 //
112	if bl then {
113		l = bl;
114		while l do {
115			b = head l;
116			_bpconddel(b[0]);
117			l = tail l;
118		}
119	}
120
121	 //
122	 // single step to the following address
123	 //
124	addrs = follow(*PC);
125	id = bpset(addrs[0]);
126	startstop(pid);
127	bpdel(id);
128
129	 //
130	 // restore all the breakpoints at this address
131	 //
132	if bl then {
133		l = bl;
134		while l do {
135			b = head l;
136			_bpcondset(b[0], b[1], b[2], b[3]);
137			l = tail l;
138		}
139	}
140
141	 //
142	 // restart all kprocs that could potentially hit this breakpoint
143	 //
144	if sl then {
145		l = sl;
146		while l do {
147			start(head l);
148			l = tail l;
149		}
150	}
151}
152
153aggr Ureg
154{
155	'X' 0 di;
156	'X' 4 si;
157	'X' 8 bp;
158	'X' 12 nsp;
159	'X' 16 bx;
160	'X' 20 dx;
161	'X' 24 cx;
162	'X' 28 ax;
163	'X' 32 gs;
164	'X' 36 fs;
165	'X' 40 es;
166	'X' 44 ds;
167	'X' 48 trap;
168	'X' 52 ecode;
169	'X' 56 pc;
170	'X' 60 cs;
171	'X' 64 flags;
172	{
173	'X' 68 usp;
174	'X' 68 sp;
175	};
176	'X' 72 ss;
177};
178
179
180defn
181Ureg(addr) {
182	complex Ureg addr;
183	print("	di	", addr.di, "\n");
184	print("	si	", addr.si, "\n");
185	print("	bp	", addr.bp, "\n");
186	print("	nsp	", addr.nsp, "\n");
187	print("	bx	", addr.bx, "\n");
188	print("	dx	", addr.dx, "\n");
189	print("	cx	", addr.cx, "\n");
190	print("	ax	", addr.ax, "\n");
191	print("	gs	", addr.gs, "\n");
192	print("	fs	", addr.fs, "\n");
193	print("	es	", addr.es, "\n");
194	print("	ds	", addr.ds, "\n");
195	print("	trap	", addr.trap, "\n");
196	print("	ecode	", addr.ecode, "\n");
197	print("	pc	", addr.pc, "\n");
198	print("	cs	", addr.cs, "\n");
199	print("	flags	", addr.flags, "\n");
200	print("	sp	", addr.sp, "\n");
201	print("}\n");
202	print("	ss	", addr.ss, "\n");
203};
204
205print("/sys/lib/acid/386");
206