blob: e9b2f036bad6fb1b6565245fc0c5d910da728583 [file] [log] [blame]
rsc0a61c072004-04-19 18:18:37 +00001// 386 support
2
3defn acidinit() // Called after all the init modules are loaded
4{
5 bplist = {};
6 bpfmt = 'b';
7
8 srcpath = {
9 "./",
10 "/sys/src/libc/port/",
11 "/sys/src/libc/9sys/",
12 "/sys/src/libc/386/"
13 };
14
15 srcfiles = {}; // list of loaded files
16 srctext = {}; // the text of the files
17}
18
19defn linkreg(addr)
20{
21 return {};
22}
23
24defn stk() // trace
25{
26 _stk({"PC", *PC, "SP", *SP}, 0);
27}
28
29defn lstk() // trace with locals
30{
31 _stk({"PC", *PC, "SP", *SP}, 1);
32}
33
34defn gpr() // print general(hah hah!) purpose registers
35{
36 print("AX\t", *AX, " BX\t", *BX, " CX\t", *CX, " DX\t", *DX, "\n");
37 print("DI\t", *DI, " SI\t", *SI, " BP\t", *BP, "\n");
38}
39
40defn spr() // print special processor registers
41{
42 local pc;
43 local cause;
44
45 pc = *PC;
46 print("PC\t", pc, " ", fmt(pc, 'a'), " ");
47 pfl(pc);
48 print("SP\t", *SP, " ECODE ", *ECODE, " EFLAG ", *EFLAGS, "\n");
49 print("CS\t", *CS, " DS\t ", *DS, " SS\t", *SS, "\n");
50 print("GS\t", *GS, " FS\t ", *FS, " ES\t", *ES, "\n");
51
52 cause = *TRAP;
53 print("TRAP\t", cause, " ", reason(cause), "\n");
54}
55
56defn regs() // print all registers
57{
58 spr();
59 gpr();
60}
61
62defn mmregs()
63{
64 print("MM0\t", *MM0, " MM1\t", *MM1, "\n");
65 print("MM2\t", *MM2, " MM3\t", *MM3, "\n");
66 print("MM4\t", *MM4, " MM5\t", *MM5, "\n");
67 print("MM6\t", *MM6, " MM7\t", *MM7, "\n");
68}
69
rsc74685412005-11-28 00:40:31 +000070defn pfixstop(pid)
71{
72 if *fmt(*PC-1, 'b') == 0xCC then {
73 // Linux stops us after the breakpoint, not at it
74 *PC = *PC-1;
75 }
76}
77
78
rsc0a61c072004-04-19 18:18:37 +000079defn pstop(pid)
80{
81 local l;
82 local pc;
rsc74685412005-11-28 00:40:31 +000083 local why;
rsc0a61c072004-04-19 18:18:37 +000084
85 pc = *PC;
86
rsc74685412005-11-28 00:40:31 +000087 // FIgure out why we stopped.
88 if *fmt(pc, 'b') == 0xCC then {
89 why = "breakpoint";
90
91 // fix up instruction for print; will put back later
92 *pc = @pc;
93 } else if *(pc-2\x) == 0x80CD then {
94 pc = pc-2;
95 why = "system call";
96 } else
97 why = "stopped";
rsc0a61c072004-04-19 18:18:37 +000098
rsc74685412005-11-28 00:40:31 +000099 if printstopped then {
100 print(pid,": ", why, "\t");
101 print(fmt(pc, 'a'), "\t", *fmt(pc, 'i'), "\n");
102 }
103
104 if why == "breakpoint" then
105 *fmt(pc, bpfmt) = bpinst;
106
107 if printstopped && notes then {
rsc0a61c072004-04-19 18:18:37 +0000108 if notes[0] != "sys: breakpoint" then {
109 print("Notes pending:\n");
110 l = notes;
111 while l do {
112 print("\t", head l, "\n");
113 l = tail l;
114 }
115 }
116 }
117}
118
119aggr Ureg
120{
121 'U' 0 di;
122 'U' 4 si;
123 'U' 8 bp;
124 'U' 12 nsp;
125 'U' 16 bx;
126 'U' 20 dx;
127 'U' 24 cx;
128 'U' 28 ax;
129 'U' 32 gs;
130 'U' 36 fs;
131 'U' 40 es;
132 'U' 44 ds;
133 'U' 48 trap;
134 'U' 52 ecode;
135 'U' 56 pc;
136 'U' 60 cs;
137 'U' 64 flags;
138 {
139 'U' 68 usp;
140 'U' 68 sp;
141 };
142 'U' 72 ss;
143};
144
145defn
146Ureg(addr) {
147 complex Ureg addr;
148 print(" di ", addr.di, "\n");
149 print(" si ", addr.si, "\n");
150 print(" bp ", addr.bp, "\n");
151 print(" nsp ", addr.nsp, "\n");
152 print(" bx ", addr.bx, "\n");
153 print(" dx ", addr.dx, "\n");
154 print(" cx ", addr.cx, "\n");
155 print(" ax ", addr.ax, "\n");
156 print(" gs ", addr.gs, "\n");
157 print(" fs ", addr.fs, "\n");
158 print(" es ", addr.es, "\n");
159 print(" ds ", addr.ds, "\n");
160 print(" trap ", addr.trap, "\n");
161 print(" ecode ", addr.ecode, "\n");
162 print(" pc ", addr.pc, "\n");
163 print(" cs ", addr.cs, "\n");
164 print(" flags ", addr.flags, "\n");
165 print(" sp ", addr.sp, "\n");
166 print(" ss ", addr.ss, "\n");
167};
168sizeofUreg = 76;
169
170aggr Linkdebug
171{
172 'X' 0 version;
173 'X' 4 map;
174};
175
176aggr Linkmap
177{
178 'X' 0 addr;
179 'X' 4 name;
180 'X' 8 dynsect;
181 'X' 12 next;
182 'X' 16 prev;
183};
184
185defn
186linkdebug()
187{
188 local a;
189
190 if !havesymbol("_DYNAMIC") then
191 return 0;
192
193 a = _DYNAMIC;
194 while *a != 0 do {
195 if *a == 21 then // 21 == DT_DEBUG
196 return *(a+4);
197 a = a+8;
198 }
199 return 0;
200}
201
202defn
rsc7284df12004-04-19 18:52:34 +0000203dynamicmap()
rsc0a61c072004-04-19 18:18:37 +0000204{
rsc6c885642004-04-20 05:51:36 +0000205 if systype == "linux" || systype == "freebsd" then {
rsc0a61c072004-04-19 18:18:37 +0000206 local r, m, n;
207
208 r = linkdebug();
209 if r then {
210 complex Linkdebug r;
211 m = r.map;
212 n = 0;
213 while m != 0 && n < 100 do {
214 complex Linkmap m;
rsc6c885642004-04-20 05:51:36 +0000215 if m.name && *(m.name\b) && access(*(m.name\s)) then
rsc08ddcb72005-02-11 02:16:18 +0000216 print("textfile({\"", *(m.name\s), "\", ", m.addr\X, "});\n");
rsc0a61c072004-04-19 18:18:37 +0000217 m = m.next;
218 n = n+1;
219 }
220 }
221 }
rsc7284df12004-04-19 18:52:34 +0000222}
rsc0a61c072004-04-19 18:18:37 +0000223
rsc7284df12004-04-19 18:52:34 +0000224defn
225acidmap()
226{
rsc08ddcb72005-02-11 02:16:18 +0000227// dynamicmap();
rsc7284df12004-04-19 18:52:34 +0000228 acidtypes();
rsc0a61c072004-04-19 18:18:37 +0000229}
230
231print(acidfile);