Blob


1 // 386 support
3 defn acidinit() // Called after all the init modules are loaded
4 {
5 bplist = {};
6 bpfmt = 'b';
8 srcpath = {
9 "./",
10 "/sys/src/libc/port/",
11 "/sys/src/libc/9sys/",
12 "/sys/src/libc/386/"
13 };
15 srcfiles = {}; // list of loaded files
16 srctext = {}; // the text of the files
17 }
19 defn linkreg(addr)
20 {
21 return {};
22 }
24 defn stk() // trace
25 {
26 _stk({"PC", *PC, "SP", *SP}, 0);
27 }
29 defn lstk() // trace with locals
30 {
31 _stk({"PC", *PC, "SP", *SP}, 1);
32 }
34 defn 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 }
40 defn spr() // print special processor registers
41 {
42 local pc;
43 local cause;
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");
52 cause = *TRAP;
53 print("TRAP\t", cause, " ", reason(cause), "\n");
54 }
56 defn regs() // print all registers
57 {
58 spr();
59 gpr();
60 }
62 defn 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 }
70 defn 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 }
79 defn pstop(pid)
80 {
81 local l;
82 local pc;
83 local why;
85 pc = *PC;
87 // FIgure out why we stopped.
88 if *fmt(pc, 'b') == 0xCC then {
89 why = "breakpoint";
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";
99 if printstopped then {
100 print(pid,": ", why, "\t");
101 print(fmt(pc, 'a'), "\t", *fmt(pc, 'i'), "\n");
104 if why == "breakpoint" then
105 *fmt(pc, bpfmt) = bpinst;
107 if printstopped && notes then {
108 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;
119 aggr Ureg
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;
139 'U' 68 usp;
140 'U' 68 sp;
141 };
142 'U' 72 ss;
143 };
145 defn
146 Ureg(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 };
168 sizeofUreg = 76;
170 aggr Linkdebug
172 'X' 0 version;
173 'X' 4 map;
174 };
176 aggr Linkmap
178 'X' 0 addr;
179 'X' 4 name;
180 'X' 8 dynsect;
181 'X' 12 next;
182 'X' 16 prev;
183 };
185 defn
186 linkdebug()
188 local a;
190 if !havesymbol("_DYNAMIC") then
191 return 0;
193 a = _DYNAMIC;
194 while *a != 0 do {
195 if *a == 21 then // 21 == DT_DEBUG
196 return *(a+4);
197 a = a+8;
199 return 0;
202 defn
203 dynamicmap()
205 if systype == "linux" || systype == "freebsd" then {
206 local r, m, n;
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;
215 if m.name && *(m.name\b) && access(*(m.name\s)) then
216 print("textfile({\"", *(m.name\s), "\", ", m.addr\X, "});\n");
217 m = m.next;
218 n = n+1;
224 defn
225 acidmap()
227 // dynamicmap();
228 acidtypes();
231 print(acidfile);