1: # 2: /* 3: * 4: * UNIX debugger 5: * 6: */ 7: 8: #include "defs.h" 9: 10: STRING errflg; 11: L_INT dot; 12: INT dotinc; 13: L_INT var[]; 14: MAP datmap; 15: 16: #undef SINGLE 17: 18: /* instruction printing */ 19: 20: #define DOUBLE 0 21: #define DOUBLW 1 22: #define SINGLE 2 23: #define SINGLW 3 24: #define REVERS 4 25: #define BRANCH 5 26: #define NOADDR 6 27: #define DFAULT 7 28: #define TRAP 8 29: #define SYS 9 30: #define SOB 10 31: #define JMP 11 32: #define JSR 12 33: 34: 35: TYPE struct optab *OPTAB; 36: struct optab { 37: int mask; 38: int val; 39: int itype; 40: char *iname; 41: } optab[] { 42: 0107777, 0010000, DOUBLE, "mov", 43: 0107777, 0020000, DOUBLE, "cmp", 44: 0107777, 0030000, DOUBLE, "bit", 45: 0107777, 0040000, DOUBLE, "bic", 46: 0107777, 0050000, DOUBLE, "bis", 47: 0007777, 0060000, DOUBLW, "add", 48: 0007777, 0160000, DOUBLW, "sub", 49: 0100077, 0005000, SINGLE, "clr", 50: 0100077, 0005100, SINGLE, "com", 51: 0100077, 0005200, SINGLE, "inc", 52: 0100077, 0005300, SINGLE, "dec", 53: 0100077, 0005400, SINGLE, "neg", 54: 0100077, 0005500, SINGLE, "adc", 55: 0100077, 0005600, SINGLE, "sbc", 56: 0100077, 0005700, SINGLE, "tst", 57: 0100077, 0006000, SINGLE, "ror", 58: 0100077, 0006100, SINGLE, "rol", 59: 0100077, 0006200, SINGLE, "asr", 60: 0100077, 0006300, SINGLE, "asl", 61: 0000077, 0000100, JMP, "jmp", 62: 0000077, 0000300, SINGLE, "swab", 63: 0000077, 0170100, SINGLW, "ldfps", 64: 0000077, 0170200, SINGLW, "stfps", 65: 0000077, 0170300, SINGLW, "stst", 66: 0000077, 0170400, SINGLW, "clrf", 67: 0000077, 0170500, SINGLW, "tstf", 68: 0000077, 0170600, SINGLW, "absf", 69: 0000077, 0170700, SINGLW, "negf", 70: 0000077, 0006700, SINGLW, "sxt", 71: 0000077, 0006600, SINGLW, "mtpi", 72: 0000077, 0106600, SINGLW, "mtpd", 73: 0000077, 0006500, SINGLW, "mfpi", 74: 0000077, 0106500, SINGLW, "mfpd", 75: 0000777, 0070000, REVERS, "mul", 76: 0000777, 0071000, REVERS, "div", 77: 0000777, 0072000, REVERS, "ash", 78: 0000777, 0073000, REVERS, "ashc", 79: LOBYTE, 0000400, BRANCH, "br", 80: LOBYTE, 0001000, BRANCH, "bne", 81: LOBYTE, 0001400, BRANCH, "beq", 82: LOBYTE, 0002000, BRANCH, "bge", 83: LOBYTE, 0002400, BRANCH, "blt", 84: LOBYTE, 0003000, BRANCH, "bgt", 85: LOBYTE, 0003400, BRANCH, "ble", 86: LOBYTE, 0100000, BRANCH, "bpl", 87: LOBYTE, 0100400, BRANCH, "bmi", 88: LOBYTE, 0101000, BRANCH, "bhi", 89: LOBYTE, 0101400, BRANCH, "blos", 90: LOBYTE, 0102000, BRANCH, "bvc", 91: LOBYTE, 0102400, BRANCH, "bvs", 92: LOBYTE, 0103000, BRANCH, "bcc", 93: LOBYTE, 0103400, BRANCH, "bcs", 94: 0000000, 0000000, NOADDR, "halt", 95: 0000000, 0000001, NOADDR, "wait", 96: 0000000, 0000002, NOADDR, "rti", 97: 0000000, 0000003, NOADDR, "bpt", 98: 0000000, 0000004, NOADDR, "iot", 99: 0000000, 0000005, NOADDR, "reset", 100: 0000000, 0000006, NOADDR, "rtt", 101: LOBYTE, 0171000, REVERS, "mulf", 102: LOBYTE, 0171400, REVERS, "modf", 103: LOBYTE, 0172000, REVERS, "addf", 104: LOBYTE, 0172400, REVERS, "movf", 105: LOBYTE, 0173000, REVERS, "subf", 106: LOBYTE, 0173400, REVERS, "cmpf", 107: LOBYTE, 0174000, DOUBLW, "movf", 108: LOBYTE, 0174400, REVERS, "divf", 109: LOBYTE, 0175000, DOUBLW, "movei", 110: LOBYTE, 0175400, DOUBLW, "movfi", 111: LOBYTE, 0176000, DOUBLW, "movfo", 112: LOBYTE, 0176400, REVERS, "movie", 113: LOBYTE, 0177000, REVERS, "movif", 114: LOBYTE, 0177400, REVERS, "movof", 115: 0000000, 0170000, NOADDR, "cfcc", 116: 0000000, 0170001, NOADDR, "setf", 117: 0000000, 0170002, NOADDR, "seti", 118: 0000000, 0170011, NOADDR, "setd", 119: 0000000, 0170012, NOADDR, "setl", 120: 0000777, 0004000, JSR, "jsr", 121: 0000777, 0074000, DOUBLE, "xor", 122: 0000007, 0000200, SINGLE, "rts", 123: 0000017, 0000240, DFAULT, "cflg", 124: 0000017, 0000260, DFAULT, "sflg", 125: LOBYTE, 0104000, TRAP, "emt", 126: LOBYTE, 0104400, SYS, "sys", 127: 0000077, 0006400, TRAP, "mark", 128: 0000777, 0077000, SOB, "sob", 129: 0000007, 0000230, DFAULT, "spl", 130: 0177777, 0000000, DFAULT, "<illegal op>", 131: }; 132: 133: #define SYSTAB struct systab 134: SYSTAB { 135: int argc; 136: char *sname; 137: } systab[] { 138: 1, "indir", 139: 0, "exit", 140: 0, "fork", 141: 2, "read", 142: 2, "write", 143: 2, "open", 144: 0, "close", 145: 0, "wait", 146: 2, "creat", 147: 2, "link", 148: 1, "unlink", 149: 2, "exec", 150: 1, "chdir", 151: 0, "time", 152: 3, "mknod", 153: 2, "chmod", 154: 3, "chown", 155: 1, "break", 156: 2, "stat", 157: 3, "seek", 158: 0, "getpid", 159: 3, "mount", 160: 1, "umount", 161: 0, "setuid", 162: 0, "getuid", 163: 0, "stime", 164: 3, "ptrace", 165: 0, "alarm", 166: 1, "fstat", 167: 0, "pause", 168: 2, "utime", 169: 1, "stty", 170: 1, "gtty", 171: 0, "access", 172: 0, "nice", 173: 1, "ftime", 174: 0, "sync", 175: 1, "kill", 176: 0, "38", 177: 1, "setpgrp", 178: 0, "40", 179: 0, "dup", 180: 0, "pipe", 181: 1, "times", 182: 4, "profil", 183: 0, "45", 184: 0, "setgid", 185: 0, "getgid", 186: 2, "signal", 187: 0, "rtp", 188: 0, "50", 189: 1, "acct", 190: 3, "phys", 191: 1, "lock", 192: 3, "ioctl", 193: 2, "reboot", 194: 4, "mpxchan", 195: 0, "vfork", 196: 1, "local", 197: 3, "exece", 198: 1, "umask", 199: 1, "chroot", 200: 0, "62", 201: 0, "63", 202: }, sysloctab[] { 203: 0, "nosys", 204: 3, "login", 205: 2, "lstat", 206: 0, "submit", 207: 0, "nostk", 208: 2, "killbkg", 209: 2, "killpg", 210: 2, "renice", 211: 0, "fetchi", 212: 3, "ucall", 213: 5, "quota", 214: 1, "qfstat", 215: 2, "qstat", 216: 0, "setpgrp", 217: 0, "gldav", 218: 0, "fperr", 219: 0, "vhangup", 220: }; 221: int nlocsys = sizeof(sysloctab) / sizeof(sysloctab[0]); 222: 223: STRING regname[] { "r0", "r1", "r2", "r3", "r4", "r5", "sp", "pc"}; 224: 225: POS type, space, incp; 226: 227: printins(f,idsp,ins) 228: REG INT ins; 229: { 230: INT byte; 231: REG OPTAB p; 232: 233: type=DSYM; space=idsp; incp=2; 234: FOR p=optab;; p++ 235: DO IF (ins & ~p->mask) == p->val 236: THEN break; 237: FI 238: OD 239: prints(p->iname); byte=ins&0100000; ins &= p->mask; 240: switch (p->itype) { 241: 242: case JMP: 243: type=ISYM; 244: 245: case SINGLE: 246: IF byte THEN printc('b'); FI 247: case SINGLW: 248: paddr("%8t",ins); 249: break; 250: 251: case REVERS: 252: doubl(ins&077,(ins>>6)&07); 253: break; 254: 255: case JSR: 256: type=ISYM; 257: 258: case DOUBLE: 259: IF byte THEN printc('b'); FI 260: case DOUBLW: 261: doubl(ins>>6,ins); 262: 263: case NOADDR: 264: break; 265: 266: case SOB: 267: paddr("%8t",(ins>>6)&07); 268: branch(",",-(ins&077)); 269: break; 270: 271: case BRANCH: 272: branch("%8t",ins); 273: break; 274: 275: case SYS: 276: BEGIN 277: INT indir; 278: REG INT w; 279: if (idsp == DSP && datmap.ufd == -1) 280: idsp = ISP; 281: if (f != 2) 282: printf("%8t%s", systab[ins &= 077].sname); 283: else if ((ins & 0377) < nlocsys) 284: printf("%8t%s", sysloctab[ins &= 0377].sname); 285: else 286: printf("%8t%d", ins &= 0377); 287: IF ins==0 ANDF f==0 ANDF idsp!=NSP /* indir */ 288: THEN w=dot; dot=chkget(inkdot(2),idsp); 289: prints(" {"); 290: indir=get(dot,datmap.ufd == -1? ISP : DSP); 291: IF errflg 292: THEN errflg=0; printc('?'); 293: ELSE printins(1,DSP,indir); 294: FI 295: printc('}'); 296: dot=w; incp=4; 297: ELIF ins==58 ANDF f==0 ANDF idsp!=NSP /* local */ 298: THEN w=dot; dot=chkget(inkdot(2),idsp); 299: prints(" {"); 300: indir=get(dot,datmap.ufd == -1? ISP : DSP); 301: IF errflg 302: THEN errflg=0; printc('?'); 303: ELSE printins(2,DSP,indir); 304: FI 305: printc('}'); 306: dot=w; incp=4; 307: ELSE if (f==2) { 308: if (ins < nlocsys) 309: w = sysloctab[ins].argc; 310: else 311: w = 0; 312: } else 313: w = systab[ins].argc; 314: WHILE w-- ANDF idsp!=NSP 315: DO prints("; "); 316: psymoff(leng(get(inkdot(incp),idsp)), NSYM, ""); 317: incp += 2; 318: OD 319: FI 320: END 321: break; 322: 323: case TRAP: 324: case DFAULT: 325: default: 326: printf("%8t%o", ins); 327: } 328: dotinc=incp; 329: } 330: 331: doubl(a,b) 332: { 333: paddr("%8t",a); paddr(",",b); 334: } 335: 336: branch(s,ins) 337: STRING s; 338: REG INT ins; 339: { 340: printf(s); 341: IF ins&0200 THEN ins |= 0177400; FI 342: ins = shorten(dot) + (ins<<1) + 2; 343: psymoff(leng(ins),ISYM,""); 344: } 345: 346: paddr(s, a) 347: STRING s; 348: REG INT a; 349: { 350: REG INT r; 351: 352: var[2]=var[1]; 353: r = a&07; a &= 070; 354: 355: printf(s); 356: IF r==7 ANDF a&020 357: THEN IF a&010 THEN printc('*'); FI 358: IF a&040 359: THEN IF space==NSP 360: THEN printc('?'); 361: ELSE var[1]=chkget(inkdot(incp),space) + shorten(inkdot(incp+2)); 362: psymoff(var[1],(a&010?DSYM:type),""); 363: FI 364: ELSE printc('$'); 365: IF space==NSP 366: THEN printc('?'); 367: ELSE var[1]=chkget(inkdot(incp), space); 368: psymoff(var[1], (a&010?type:NSYM), ""); 369: FI 370: FI 371: incp += 2; 372: return; 373: FI 374: r = regname[r]; 375: switch (a) { 376: /* r */ 377: case 000: 378: prints(r); 379: return; 380: 381: /* (r) */ 382: case 010: 383: printf("(%s)", r); 384: return; 385: 386: /* *(r)+ */ 387: case 030: 388: printc('*'); 389: 390: /* (r)+ */ 391: case 020: 392: printf("(%s)+", r); 393: return; 394: 395: /* *-(r) */ 396: case 050: 397: printc('*'); 398: 399: /* -(r) */ 400: case 040: 401: printf("-(%s)", r); 402: return; 403: 404: /* *x(r) */ 405: case 070: 406: printc('*'); 407: 408: /* x(r) */ 409: case 060: 410: IF space==NSP 411: THEN printc('?'); 412: ELSE var[1]=chkget(inkdot(incp), space); 413: psymoff(var[1], (a==070?type:NSYM), ""); 414: FI 415: incp += 2; 416: printf("(%s)", r); 417: return; 418: } 419: }