Mercurial > hg > Members > kono > os9 > sbc09
annotate trace.c @ 44:b26c23331d02
add more function on vdisk
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 19 Jul 2018 11:31:17 +0900 (2018-07-19) |
parents | 52f7ad4c2ebb |
children | 51b437557f42 |
rev | line source |
---|---|
9 | 1 /* 6808 Simulator V092 |
20 | 2 * |
3 * tracer | |
0 | 4 |
5 */ | |
6 | |
7 #include<stdio.h> | |
8 #include<stdlib.h> | |
9 #include<ctype.h> | |
10 #include<signal.h> | |
11 #include<sys/time.h> | |
12 | |
13 #include <unistd.h> | |
14 #include <fcntl.h> | |
15 #include <string.h> | |
1 | 16 #include <time.h> |
0 | 17 |
18 #ifdef USE_TERMIOS | |
19 #include <termios.h> | |
20 #endif | |
21 | |
22 #define engine extern | |
23 #include "v09.h" | |
24 | |
25 struct termios termsetting; | |
26 | |
27 int xmstat; /* 0= no XMODEM transfer, 1=send, 2=receiver */ | |
28 unsigned char xmbuf[132]; | |
29 int xidx; | |
30 int acknak; | |
31 int rcvdnak; | |
32 int blocknum; | |
33 | |
20 | 34 extern FILE *logfile; |
35 extern FILE *infile; | |
36 extern FILE *xfile; | |
37 extern FILE *disk[]; | |
0 | 38 |
39 extern void hexadump( unsigned char *b, int l, int loc, int w); | |
12
111e5defb8ab
boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
40 extern int disasm(int,int); |
20 | 41 extern void restore_term(void) ; |
42 | |
9 | 43 #ifdef USE_MMU |
44 extern char *prog ; // for disass | |
11 | 45 extern Byte * mem0(Byte *iphymem, Word adr, Byte *immu) ; |
21 | 46 extern int paddr(Word adr, Byte *immu) ; |
47 #else | |
48 #define paddr(a,m) (a) | |
9 | 49 #endif |
50 | |
0 | 51 void do_exit(void) { |
52 restore_term(); | |
53 exit(0); | |
54 } | |
55 | |
4 | 56 |
0 | 57 typedef struct bp { |
21 | 58 int address; // physical address |
59 int laddr; | |
0 | 60 int count; |
35 | 61 int watch; // watch point |
0 | 62 struct bp *next; |
63 } BP, *BPTR; | |
64 | |
65 BPTR breakpoint = 0; | |
66 int bpskip = 0; | |
67 int trskip = 0; | |
68 int stkskip = 0; | |
69 | |
70 int getarg(char *buf, char** next) { | |
35 | 71 int value = strtol(buf,next,0); |
72 for(;next;) { | |
73 if ( **next == '+' ) { | |
74 value += strtol(*next+1,next,0); | |
75 } else if ( **next == '*' ) { | |
76 value *= strtol(*next+1,next,0); | |
77 } else if ( **next == '/' ) { | |
78 value /= strtol(*next+1,next,0); | |
79 } else if ( **next == '-' ) { | |
80 value -= strtol(*next+1,next,0); | |
81 } else if ( **next == '&' ) { | |
82 value &= strtol(*next+1,next,0); | |
83 } else if ( **next == '|' ) { | |
84 value |= strtol(*next+1,next,0); | |
85 } else break; | |
86 } | |
87 return value; | |
0 | 88 } |
89 | |
90 void printhelp(void) | |
91 { | |
92 printf( | |
93 " s [count] one step trace\n" | |
94 " n step over\n" | |
95 " f finish this call (until stack pop)\n" | |
28 | 96 " b [adr] set break point (on current physical addreaa)\n" |
33 | 97 " B break point list\n" |
0 | 98 " d [n] delte break point list\n" |
99 " c [count] continue;\n" | |
33 | 100 " x [adr] [count] dump\n" |
9 | 101 #ifdef USE_MMU |
28 | 102 " xp page [adr] dump physical memory\n" |
9 | 103 #endif |
33 | 104 " xi [adr] [count] disassemble\n" |
1 | 105 " 0 file disk drive 0 image\n" |
106 " 1 file disk drive 1 image\n" | |
0 | 107 " L file start log to file\n" |
108 " S file set input file\n" | |
109 " X exit\n" | |
110 " q exit\n" | |
111 " U file upload from srecord file \n" | |
112 " D file download to srecord file \n" | |
113 " R do reset\n" | |
114 " h,? print this\n" | |
115 ); | |
116 } | |
117 | |
21 | 118 |
119 void setbreak(int adr,int count) ; | |
22 | 120 int nexti(void); |
21 | 121 |
0 | 122 void do_escape(void) { |
123 char s[80]; | |
28 | 124 int adr,page; |
38 | 125 int ppc = paddr(pcreg,mmu); |
0 | 126 if (bpskip) { // skip unbreak instruction |
127 bpskip--; | |
21 | 128 BPTR *prev = &breakpoint; |
22 | 129 for(BPTR b = breakpoint; b ; prev=&b->next, b=b->next ) { |
35 | 130 #ifdef USE_MMU |
131 int watch = phymem[b->address]; | |
132 #else | |
133 int watch = mem[b->address]; | |
134 #endif | |
135 if (ppc==b->address || b->watch != watch ) { | |
136 b->watch = watch; | |
21 | 137 if (b->count==-1) { // temporaly break point |
138 BPTR next = b->next; | |
139 free(b); | |
22 | 140 *prev = next; |
21 | 141 goto restart0; |
142 } | |
0 | 143 if (b->count) b->count--; |
144 if (b->count==0) { | |
145 goto restart0; | |
146 } | |
147 } | |
148 } | |
149 return; | |
150 } | |
151 if (stkskip) { // skip until return | |
38 | 152 #ifdef USE_MMU |
153 if (phymem[ppc]==0x3b||(phymem[ppc]==0x10&&phymem[ppc+1]==0x3f)) | |
154 goto restart0; | |
155 #else | |
156 if (mem[ppc]==0x3b||(mem[ppc]==0x10&&mem[ppc+1]==0x3f)) | |
157 goto restart0; | |
158 #endif | |
0 | 159 if (sreg < stkskip ) return; |
160 } | |
161 restart0: | |
162 stkskip = 0; | |
163 restore_term(); | |
9 | 164 #ifdef USE_MMU |
38 | 165 Byte *phyadr = phymem + ppc; |
9 | 166 prog = (char*)phyadr - pcreg; |
167 #endif | |
0 | 168 do_trace(stdout); |
169 if (trskip>1) { // show trace and step | |
170 trskip--; | |
35 | 171 int watch; // watch point |
0 | 172 set_term(escchar); |
173 return; | |
174 } | |
175 restart: | |
176 printf("v09>"); | |
28 | 177 fgets(s, sizeof(s)-1, stdin); |
178 s[strlen(s)-1] = 0; // chop | |
0 | 179 switch (s[0]) { |
21 | 180 case 'n': // step over |
181 if (nexti()) { | |
182 bpskip = -1; | |
183 break; | |
184 } | |
29
3c14d647bb51
assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
185 default: |
0 | 186 case 's': // one step trace |
187 trskip = 1; | |
188 if (s[1]) { | |
189 trskip = getarg(s+1,0); | |
190 } | |
191 bpskip = 0; | |
192 attention = escape = 1; | |
193 break; | |
194 case 'f': // finish this call (until stack pop) | |
195 stkskip = sreg + 2; | |
196 attention = escape = 1; | |
197 break; | |
198 case 'b': // set break point | |
21 | 199 if (s[1]) { |
200 char *next; | |
201 int count = 0; | |
23 | 202 int adr = getarg(s+1,&next); |
21 | 203 if (next[0]) { |
204 count = getarg(next,&next); | |
205 } | |
206 setbreak(adr,count); | |
207 } else { | |
208 setbreak(pcreg,0); | |
0 | 209 } |
210 bpskip = -1; | |
211 goto restart; | |
28 | 212 case 'B': // break point list |
0 | 213 for(BPTR bp = breakpoint; bp ; bp = bp->next) { |
21 | 214 #ifdef USE_MMU |
35 | 215 printf("0x%x p=0x%x c=%d w=0x%x\n", bp->laddr, bp->address, bp->count, bp->watch); |
21 | 216 #else |
35 | 217 printf("0x%x c=%d w=0x%x\n", bp->address, bp->count,bp->watch); |
21 | 218 #endif |
0 | 219 } |
220 goto restart; | |
221 case 'd': // delte break point list | |
222 if (s[1]) { | |
223 int trskip = getarg(s+1,0); | |
224 BPTR *prev = &breakpoint; | |
22 | 225 for(BPTR bp = breakpoint; bp ; prev=&bp->next, bp = bp->next) { |
0 | 226 if (trskip-- == 0) { |
22 | 227 BPTR next = bp->next; |
21 | 228 free(bp); |
22 | 229 *prev = next; |
0 | 230 break; |
231 } | |
232 prev = &bp->next; | |
233 } | |
234 } | |
235 goto restart; | |
236 case 'c': // continue; | |
237 bpskip = -1; | |
238 attention = escape = 1; | |
239 if (s[1]) { | |
240 bpskip = getarg(s+1,0); | |
241 } | |
242 break; | |
28 | 243 case 'x': // dump |
244 { char *next = s+1; | |
245 if (s[1]=='i') next=s+2; | |
246 else if (s[1]=='p') { | |
247 next = s+2; | |
248 if (next[0]) { | |
249 page = getarg(next,&next); | |
250 } | |
251 } | |
252 if (next[0]) { | |
253 int adr = getarg(next,&next); | |
0 | 254 int len = 32; |
255 if (next[0]) { | |
256 len = getarg(next,&next); | |
257 } | |
28 | 258 if (s[1]=='i') { |
12
111e5defb8ab
boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
259 Word end = adr + len; |
111e5defb8ab
boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
260 while(adr < end) { |
9 | 261 #ifdef USE_MMU |
12
111e5defb8ab
boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
262 Byte *phyadr = mem0(phymem,adr,mmu); |
111e5defb8ab
boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
263 prog = (char*)phyadr - adr ; |
111e5defb8ab
boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
264 if (phyadr > phymem+memsize) goto restart; |
9 | 265 #endif |
12
111e5defb8ab
boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
266 int len = adr+16<end? 16 : end-adr -1 ; |
111e5defb8ab
boot is called, rti failed
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
11
diff
changeset
|
267 adr = disasm(adr,adr+len); |
9 | 268 } |
0 | 269 } else { |
9 | 270 #ifdef USE_MMU |
271 for(int i=0; len > 0 ; i+=16, len-=16) { | |
28 | 272 if (s[1]=='p') { |
273 int phy = page * 0x2000 + adr + i; | |
274 if (phy > rommemsize) goto restart; | |
275 hexadump(phymem+phy,len>16?16:len,adr+i,16); | |
9 | 276 } else { |
11 | 277 Byte *phyadr = mem0(phymem,adr+i,mmu); |
28 | 278 if (phyadr > phymem+rommemsize) goto restart; |
9 | 279 hexadump(phyadr,len>16?16:len,adr+i,16); |
280 } | |
281 } | |
282 #else | |
0 | 283 for(int i=0; len > 0 ; i+=16, len-=16) { |
284 hexadump(mem+adr+i,len>16?16:len,adr+i,16); | |
285 } | |
9 | 286 #endif |
0 | 287 } |
288 } else | |
289 disasm(pcreg,pcreg+32); | |
290 goto restart; | |
28 | 291 } |
0 | 292 case 'L': |
293 if (logfile) | |
294 fclose(logfile); | |
295 logfile = 0; | |
296 if (s[1]) { | |
1 | 297 int i=1; while(s[i]==' ') i++; |
298 logfile = fopen(s + i, "w"); | |
0 | 299 } |
300 break; | |
301 case 'S': | |
302 if (infile) | |
303 fclose(infile); | |
304 infile = 0; | |
305 if (s[1]) { | |
1 | 306 int i=1; while(s[i]==' ') i++; |
307 infile = fopen(s + i, "r"); | |
0 | 308 } |
309 break; | |
310 case 'h': | |
311 case '?': | |
312 printhelp(); | |
313 goto restart; | |
314 case 'X': | |
315 case 'q': | |
316 if (!xmstat) | |
317 do_exit(); | |
318 else { | |
319 xmstat = 0; | |
320 fclose(xfile); | |
321 xfile = 0; | |
322 } | |
323 break; | |
1 | 324 case '0': |
325 case '1': | |
326 { FILE **drv = &disk[ s[0]-'0'] ; | |
327 if (*drv) | |
328 fclose(*drv); | |
329 *drv = 0; | |
330 if (s[1]) { | |
331 int i=1; while(s[i]==' ') i++; | |
332 *drv = fopen(s + i, "r+b"); | |
333 if ( *drv == 0 ) { printf("can't open %s\n", &s[i]); } | |
334 } | |
335 } | |
336 break; | |
0 | 337 case 'U': |
338 if (xfile) | |
339 fclose(xfile); | |
340 xfile = 0; | |
341 if (s[1]) { | |
1 | 342 int i=1; while(s[i]==' ') i++; |
343 xfile = fopen(s + i, "rb"); | |
344 if ( xfile == 0 ) { printf("can't open %s\n", &s[i]); } | |
0 | 345 } |
346 if (xfile) | |
347 xmstat = 1; | |
348 else | |
349 xmstat = 0; | |
350 xidx = 0; | |
351 acknak = 21; | |
352 rcvdnak = EOF; | |
353 blocknum = 1; | |
354 break; | |
355 case 'D': | |
356 if (xfile) | |
357 fclose(xfile); | |
358 xfile = 0; | |
359 if (s[1]) { | |
1 | 360 int i=1; while(s[i]==' ') i++; |
361 xfile = fopen(s + i, "wb"); | |
362 if ( xfile == 0 ) { printf("can't open %s\n", &s[i]); } | |
0 | 363 } |
364 if (xfile) | |
365 xmstat = 2; | |
366 else | |
367 xmstat = 0; | |
368 xidx = 0; | |
369 acknak = 21; | |
370 blocknum = 1; | |
371 break; | |
372 case 'R': | |
373 pcreg = (mem[0xfffe] << 8) + mem[0xffff]; | |
13 | 374 bpskip = 0; |
24 | 375 #ifdef USE_MMU |
376 mmu = &mem[0xffa0]; | |
28 | 377 mem[0xffa7]=0x3f; |
24 | 378 #endif |
13 | 379 attention = escape = 1; |
0 | 380 break; |
381 } | |
382 if (tracing||breakpoint||trskip||bpskip||stkskip) { attention = escape = 1; } | |
383 else attention = 0; | |
384 set_term(escchar); | |
385 } | |
386 | |
21 | 387 void setbreak(int adr, int count) { |
388 BPTR bp = calloc(1,sizeof(BP)); | |
389 bp->next = breakpoint; | |
390 breakpoint = bp; | |
391 bp->count = count; | |
22 | 392 bp->laddr = adr; |
393 bp->address = paddr(adr,mmu); | |
35 | 394 #ifdef USE_MMU |
395 bp->watch = *mem0(phymem,adr,mmu); | |
396 #else | |
397 bp->watch = mem[adr]; | |
398 #endif | |
21 | 399 } |
400 | |
401 int nexti(void) { | |
22 | 402 #ifdef USE_MMU |
403 int op1 = *mem0(phymem,pcreg,mmu); | |
404 int op2 = *mem0(phymem,pcreg+1,mmu); | |
405 #else | |
406 int op1 = mem[pcreg]; | |
407 int op2 = mem[pcreg+1]; | |
408 #endif | |
21 | 409 int ofs = 0; |
410 switch(op1) { | |
411 case 0x17: // LBSR | |
412 case 0xbd: // JSR extended | |
22 | 413 ofs=3; break; |
21 | 414 case 0x10: // page2 |
415 { | |
416 if (op2==0x3f) { // os9 system call | |
22 | 417 ofs=3; break; |
21 | 418 } |
419 } | |
29
3c14d647bb51
assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
420 break; |
21 | 421 case 0x11: // page3 |
422 { | |
423 if (op2==0x3f) { // SWI3 | |
22 | 424 ofs=2; break; |
21 | 425 } |
426 } | |
29
3c14d647bb51
assembler and emulator fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
427 break; |
21 | 428 case 0x3f: // SWI |
22 | 429 ofs=1; break; |
21 | 430 case 0x3c: // CWAI |
431 case 0x8d: // BSR | |
432 case 0x9d: // JSR direct | |
22 | 433 ofs=2; break; |
21 | 434 case 0xad: // JSR index |
435 { | |
436 if (op2<0x80) ofs = 2; // 5bit ofs | |
437 else switch (op2&0xf) { | |
438 case 8: case 0xc: | |
439 ofs = 3; break; | |
440 case 9: case 0xd: case 0xf: | |
441 ofs = 4; break; | |
442 default: | |
443 ofs = 2; break; | |
444 } | |
445 } | |
446 break; | |
447 } | |
22 | 448 if (ofs) setbreak(pcreg+ofs,-1); |
449 return ofs; | |
21 | 450 } |
451 | |
452 | |
453 | |
454 | |
455 | |
456 | |
457 | |
458 |