1*3760Sroot # 2*3760Sroot /* 3*3760Sroot * 4*3760Sroot * UNIX debugger 5*3760Sroot * 6*3760Sroot */ 7*3760Sroot 8*3760Sroot #include "defs.h" 9*3760Sroot static char sccsid[] = "@(#)opset.c 4.1 05/14/81"; 10*3760Sroot 11*3760Sroot STRING errflg; 12*3760Sroot L_INT dot; 13*3760Sroot INT dotinc; 14*3760Sroot L_INT var[]; 15*3760Sroot 16*3760Sroot 17*3760Sroot /* instruction printing */ 18*3760Sroot 19*3760Sroot /* 20*3760Sroot * Argument access types 21*3760Sroot */ 22*3760Sroot #define ACCA (8<<3) /* address only */ 23*3760Sroot #define ACCR (1<<3) /* read */ 24*3760Sroot #define ACCW (2<<3) /* write */ 25*3760Sroot #define ACCM (3<<3) /* modify */ 26*3760Sroot #define ACCB (4<<3) /* branch displacement */ 27*3760Sroot #define ACCI (5<<3) /* XFC code */ 28*3760Sroot 29*3760Sroot /* 30*3760Sroot * Argument data types 31*3760Sroot */ 32*3760Sroot #define TYPB 0 /* byte */ 33*3760Sroot #define TYPW 1 /* word */ 34*3760Sroot #define TYPL 2 /* long */ 35*3760Sroot #define TYPQ 3 /* quad */ 36*3760Sroot #define TYPF 4 /* floating */ 37*3760Sroot #define TYPD 5 /* double floating */ 38*3760Sroot 39*3760Sroot 40*3760Sroot TYPE struct optab *OPTAB; 41*3760Sroot struct optab { 42*3760Sroot char *iname; 43*3760Sroot char val; 44*3760Sroot char nargs; 45*3760Sroot char argtype[6]; 46*3760Sroot } optab[]; 47*3760Sroot #define SYSTAB struct systab 48*3760Sroot SYSTAB { 49*3760Sroot int argc; 50*3760Sroot char *sname; 51*3760Sroot } systab[]; 52*3760Sroot STRING regname[]; 53*3760Sroot STRING fltimm[]; 54*3760Sroot POS type, space, incp; 55*3760Sroot 56*3760Sroot int ioptab[256]; /* index by opcode to optab */ 57*3760Sroot 58*3760Sroot mkioptab() {/* set up ioptab */ 59*3760Sroot REG OPTAB p=optab; 60*3760Sroot while (p->iname){ 61*3760Sroot ioptab[p->val&LOBYTE]=p-optab; 62*3760Sroot p++; 63*3760Sroot } 64*3760Sroot } 65*3760Sroot 66*3760Sroot extern char *fmtr; /* not used */ 67*3760Sroot extern char *fmtR; /* not used */ 68*3760Sroot 69*3760Sroot printins(f,idsp,ins) 70*3760Sroot #ifndef vax 71*3760Sroot REG INT ins; 72*3760Sroot #else 73*3760Sroot REG L_INT ins; 74*3760Sroot #endif 75*3760Sroot { 76*3760Sroot short argno; /* argument index */ 77*3760Sroot short mode; /* mode */ 78*3760Sroot char **r; /* register name */ 79*3760Sroot long d; /* assembled byte, word, long or float */ 80*3760Sroot long snarf(); 81*3760Sroot REG char * ap; 82*3760Sroot REG OPTAB ip; 83*3760Sroot 84*3760Sroot type = DSYM; 85*3760Sroot space = idsp; 86*3760Sroot ins &= LOBYTE; 87*3760Sroot ip=optab+ioptab[ins]; 88*3760Sroot printf("%s%8t",ip->iname); 89*3760Sroot incp = 1; 90*3760Sroot ap = ip->argtype; 91*3760Sroot for (argno=0; argno<ip->nargs; argno++,ap++) { 92*3760Sroot var[argno] = 0x80000000; 93*3760Sroot if (argno!=0) printc(','); 94*3760Sroot top: 95*3760Sroot if (*ap&ACCB) 96*3760Sroot mode = 0xAF + ((*ap&7)<<5); /* branch displacement */ 97*3760Sroot else{ 98*3760Sroot mode = bchkget(inkdot(incp),idsp); ++incp; 99*3760Sroot } 100*3760Sroot if (mode & 0300) {/* not short literal */ 101*3760Sroot r = ®name[mode&0xF]; 102*3760Sroot mode >>= 4; 103*3760Sroot switch ((int)mode) { 104*3760Sroot case 4: /* [r] */ 105*3760Sroot printf("[%s]",*r); 106*3760Sroot goto top; 107*3760Sroot case 5: /* r */ 108*3760Sroot printf("%s",*r); 109*3760Sroot break; 110*3760Sroot case 6: /* (r) */ 111*3760Sroot printf("(%s)",*r); 112*3760Sroot break; 113*3760Sroot case 7: /* -(r) */ 114*3760Sroot printf("-(%s)",*r); 115*3760Sroot break; 116*3760Sroot case 9: /* *(r)+ */ 117*3760Sroot printc('*'); 118*3760Sroot case 8: /* (r)+ */ 119*3760Sroot if (r==(regname+0xF)) { 120*3760Sroot printc('$'); 121*3760Sroot if (mode==9){ /* PC absolute, always 4 bytes*/ 122*3760Sroot d = snarf(4, idsp); 123*3760Sroot goto disp; 124*3760Sroot } 125*3760Sroot switch(*ap&7){ 126*3760Sroot case TYPB: 127*3760Sroot d = snarf(1, idsp); 128*3760Sroot goto disp; 129*3760Sroot case TYPW: 130*3760Sroot d = snarf(2, idsp); 131*3760Sroot goto disp; 132*3760Sroot case TYPL: 133*3760Sroot d = snarf(4, idsp); 134*3760Sroot goto disp; 135*3760Sroot case TYPQ: 136*3760Sroot d = snarf(4, idsp); 137*3760Sroot printquad(d, snarf(4, idsp)); 138*3760Sroot break; 139*3760Sroot case TYPF: 140*3760Sroot printfloating(TYPF, snarf(4, idsp), 0); 141*3760Sroot break; 142*3760Sroot case TYPD: 143*3760Sroot d = snarf(4, idsp); 144*3760Sroot printfloating(TYPQ, d, snarf(4, idsp)); 145*3760Sroot break; 146*3760Sroot } /*end of type switch */ 147*3760Sroot /* 148*3760Sroot * here only for TYPQ, TYPf, TYPD 149*3760Sroot * others went to disp 150*3760Sroot */ 151*3760Sroot } else { /*it's not PC immediate or abs*/ 152*3760Sroot printf("(%s)+",*r); 153*3760Sroot } 154*3760Sroot break; 155*3760Sroot case 0xB: /* byte displacement defferred*/ 156*3760Sroot printc('*'); 157*3760Sroot case 0xA: /* byte displacement */ 158*3760Sroot d = snarf(1, idsp); 159*3760Sroot goto disp; 160*3760Sroot case 0xD: /* word displacement deferred */ 161*3760Sroot printc('*'); 162*3760Sroot case 0xC: /* word displacement */ 163*3760Sroot d = snarf(2, idsp); 164*3760Sroot goto disp; 165*3760Sroot case 0xF: /* long displacement deferred */ 166*3760Sroot printc('*'); 167*3760Sroot case 0xE: /* long displacement */ 168*3760Sroot d = snarf(4, idsp); 169*3760Sroot goto disp; 170*3760Sroot disp: 171*3760Sroot var[argno]=d; 172*3760Sroot if (r==(regname+0xF) && mode>=0xA){ 173*3760Sroot /* PC offset addressing */ 174*3760Sroot var[argno] += dot+incp; 175*3760Sroot } 176*3760Sroot psymoff(var[argno],type,""); 177*3760Sroot if (r != regname+0xF) 178*3760Sroot printf("(%s)",*r); 179*3760Sroot break; 180*3760Sroot } /* end of the mode switch */ 181*3760Sroot } else { /* short literal */ 182*3760Sroot var[argno]=mode; 183*3760Sroot if( (*ap&7)==TYPF 184*3760Sroot || (*ap&7)==TYPD) 185*3760Sroot printf("$%s",fltimm[mode]); 186*3760Sroot else 187*3760Sroot printf("$%r",mode); 188*3760Sroot } 189*3760Sroot } 190*3760Sroot if (ins==0xCF || ins==0xAF || ins==0x8F) {/* CASEx instr */ 191*3760Sroot for (argno=0; argno<=var[2]; ++argno) { 192*3760Sroot printc(EOR); 193*3760Sroot printf(" %R: ",argno+var[1]); 194*3760Sroot d=get(inkdot(incp+argno+argno),idsp)&0xFFFF; 195*3760Sroot if (d&0x8000) d -= 0x10000; 196*3760Sroot psymoff(inkdot(incp)+d,type,""); 197*3760Sroot } 198*3760Sroot incp += var[2]+var[2]+2; 199*3760Sroot } 200*3760Sroot dotinc=incp; 201*3760Sroot } 202*3760Sroot 203*3760Sroot /* 204*3760Sroot * magic values to mung an offset to a register into 205*3760Sroot * something that psymoff can understand.. all magic 206*3760Sroot */ 207*3760Sroot /* 0 1 2 3 4 */ 208*3760Sroot static long magic_masks[5] = {0, 0x80, 0x8000, 0, 0}; 209*3760Sroot static long magic_compl[5] = {0, 0x100, 0x10000,0, 0}; 210*3760Sroot 211*3760Sroot /* 212*3760Sroot * The following code is NO LONGER portable from the PDP 11 to the VAX 213*3760Sroot */ 214*3760Sroot long snarf (nbytes, idsp) 215*3760Sroot int nbytes; 216*3760Sroot { 217*3760Sroot register int byteindex; 218*3760Sroot union Long{ 219*3760Sroot char long_bytes[4]; 220*3760Sroot long long_value; 221*3760Sroot } d; 222*3760Sroot 223*3760Sroot d.long_value = 0; 224*3760Sroot for (byteindex = 0; byteindex < nbytes; byteindex++){ 225*3760Sroot d.long_bytes[byteindex] = bchkget(inkdot(incp), idsp); 226*3760Sroot ++incp; 227*3760Sroot } 228*3760Sroot if (d.long_value & magic_masks[nbytes]) 229*3760Sroot d.long_value -= magic_compl[nbytes]; 230*3760Sroot return(d.long_value); 231*3760Sroot } 232*3760Sroot 233*3760Sroot printfloating(type, word_first, word_last) 234*3760Sroot int type; 235*3760Sroot long word_first; 236*3760Sroot long word_last; 237*3760Sroot { 238*3760Sroot union Double{ 239*3760Sroot struct { 240*3760Sroot long word_first; 241*3760Sroot long word_last; 242*3760Sroot } composite; 243*3760Sroot double dvalue; 244*3760Sroot } reconstructed; 245*3760Sroot 246*3760Sroot reconstructed.composite.word_first = word_first; 247*3760Sroot reconstructed.composite.word_last = word_last; 248*3760Sroot printf( "%f", reconstructed.dvalue); 249*3760Sroot } 250*3760Sroot 251*3760Sroot printquad(word_first, word_last) 252*3760Sroot long word_first; 253*3760Sroot long word_last; 254*3760Sroot { 255*3760Sroot union Quad { 256*3760Sroot char quad_bytes[8]; 257*3760Sroot long quad_long[2]; 258*3760Sroot } reconstructed; 259*3760Sroot int leading_zero = 1; 260*3760Sroot int byteindex; 261*3760Sroot int nibbleindex; 262*3760Sroot register int ch; 263*3760Sroot 264*3760Sroot reconstructed.quad_long[0] = word_first; 265*3760Sroot reconstructed.quad_long[1] = word_last; 266*3760Sroot for (byteindex = 7; byteindex >= 0; --byteindex){ 267*3760Sroot for (nibbleindex = 4; nibbleindex >= 0; nibbleindex -= 4){ 268*3760Sroot ch = (reconstructed.quad_bytes[byteindex] 269*3760Sroot >> nibbleindex) & 0x0F; 270*3760Sroot if ( ! (leading_zero &= (ch == 0) ) ){ 271*3760Sroot if (ch <= 0x09) 272*3760Sroot printc(ch + '0'); 273*3760Sroot else 274*3760Sroot printc(ch - 0x0A + 'a'); 275*3760Sroot } 276*3760Sroot } 277*3760Sroot } 278*3760Sroot } 279