home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / source / s1 / cdb2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1975-05-13  |  6.7 KB  |  385 lines

  1. #
  2. /*
  3.  * C debugger -- part 2
  4.  */
  5.  
  6. char    ssymbol[];
  7. int    dotinc;
  8. int    dot;
  9.  
  10.  
  11. psymoff(v, lim)
  12. {
  13.     register char *w;
  14.  
  15.     w = vallook(v);
  16.     if (w > lim) {
  17.         printf("%.1o", v);
  18.         return;
  19.     }
  20.     printf("%.8s", ssymbol);
  21.     if (w)
  22.         printf("+%d", w);
  23. }
  24.  
  25. #define    ISP    1
  26. #define    DOUBLE    0
  27. #define    SINGLE    1
  28. #define    SINGLW    2
  29. #define    MULDIV    4
  30. #define    BRANCH    5
  31. #define    NOADDR    6
  32. #define    FLTREV    7
  33. #define    FLTNOR    8
  34. #define    SPECL1    9
  35. #define    SPECL2    10
  36. #define    SPECL3    11
  37. #define    SPECL4    12
  38. #define    SPECL5    13
  39. #define    SPECL6    14
  40. #define    SPECL7    15
  41. #define    SPECL8    18
  42. #define    SPECL9    19
  43.  
  44. struct optab {
  45.     int    mask;
  46.     int    val;
  47.     int    itype;
  48.     char    *iname;
  49. } optab[] {
  50.     0107777, 0010000, DOUBLE, "mov",
  51.     0107777, 0020000, DOUBLE, "cmp",
  52.     0107777, 0030000, DOUBLE, "bit",
  53.     0107777, 0040000, DOUBLE, "bic",
  54.     0107777, 0050000, DOUBLE, "bis",
  55.     0007777, 0060000, DOUBLE, "add",
  56.     0007777, 0160000, DOUBLE, "su",
  57.     0100077, 0005000, SINGLE, "clr",
  58.     0100077, 0005100, SINGLE, "com",
  59.     0100077, 0005200, SINGLE, "inc",
  60.     0100077, 0005300, SINGLE, "dec",
  61.     0100077, 0005400, SINGLE, "neg",
  62.     0100077, 0005500, SINGLE, "adc",
  63.     0100077, 0005600, SINGLE, "sbc",
  64.     0100077, 0005700, SINGLE, "tst",
  65.     0100077, 0006000, SINGLE, "ror",
  66.     0100077, 0006100, SINGLE, "rol",
  67.     0100077, 0006200, SINGLE, "asr",
  68.     0100077, 0006300, SINGLE, "asl",
  69.     0000077, 0000100, SINGLE, "jmp",
  70.     0000077, 0000300, SINGLE, "swab",
  71.     0000077, 0170100, SINGLW, "ldfps",
  72.     0000077, 0170200, SINGLW, "stfps",
  73.     0000077, 0170300, SINGLW, "stst",
  74.     0000077, 0170400, SINGLW, "clrf",
  75.     0000077, 0170500, SINGLW, "tstf",
  76.     0000077, 0170600, SINGLW, "absf",
  77.     0000077, 0170700, SINGLW, "negf",
  78.     0000077, 0006700, SINGLW, "sxt",
  79.     0000077, 0006600, SINGLW, "mtpi",
  80.     0000077, 0106600, SINGLW, "mtpd",
  81.     0000077, 0006500, SINGLW, "mfpi",
  82.     0000077, 0106500, SINGLW, "mfpd",
  83.     0000777, 0070000, MULDIV, "mul",
  84.     0000777, 0071000, MULDIV, "div",
  85.     0000777, 0072000, MULDIV, "ash",
  86.     0000777, 0073000, MULDIV, "ashc",
  87.     0000377, 0000400, BRANCH, "br",
  88.     0000377, 0001000, BRANCH, "bne",
  89.     0000377, 0001400, BRANCH, "beq",
  90.     0000377, 0002000, BRANCH, "bge",
  91.     0000377, 0002400, BRANCH, "blt",
  92.     0000377, 0003000, BRANCH, "bgt",
  93.     0000377, 0003400, BRANCH, "ble",
  94.     0000377, 0100000, BRANCH, "bpl",
  95.     0000377, 0100400, BRANCH, "bmi",
  96.     0000377, 0101000, BRANCH, "bhi",
  97.     0000377, 0101400, BRANCH, "blos",
  98.     0000377, 0102000, BRANCH, "bvc",
  99.     0000377, 0102400, BRANCH, "bvs",
  100.     0000377, 0103000, BRANCH, "bhis",
  101.     0000377, 0103400, BRANCH, "blo",
  102.     0000000, 0000000, NOADDR, "halt",
  103.     0000000, 0000001, NOADDR, "wait",
  104.     0000000, 0000002, NOADDR, "rti",
  105.     0000000, 0000004, NOADDR, "iot",
  106.     0000000, 0000005, NOADDR, "reset",
  107.     0000377, 0171000, FLTREV, "mulf",
  108.     0000377, 0171400, FLTREV, "modf",
  109.     0000377, 0172000, FLTREV, "addf",
  110.     0000377, 0172400, FLTREV, "movf",
  111.     0000377, 0173000, FLTREV, "subf",
  112.     0000377, 0173400, FLTREV, "cmpf",
  113.     0000377, 0174000, FLTNOR, "movf",
  114.     0000377, 0174400, FLTREV, "divf",
  115.     0000377, 0175000, FLTNOR, "movei",
  116.     0000377, 0175400, FLTNOR, "movfi",
  117.     0000377, 0176000, FLTNOR, "movfo",
  118.     0000377, 0176400, FLTREV, "movie",
  119.     0000377, 0177000, FLTREV, "movif",
  120.     0000377, 0177400, FLTREV, "movof",
  121.     0000000, 0170000, NOADDR, "cfcc",
  122.     0000000, 0170001, NOADDR, "setf",
  123.     0000000, 0170002, NOADDR, "seti",
  124.     0000000, 0170011, NOADDR, "setd",
  125.     0000000, 0170012, NOADDR, "setl",
  126.     0000777, 0004000, SPECL1, "jsr",
  127.     0000777, 0074000, SPECL1, "xor",
  128.     0000007, 0000200, SPECL2, "rts",
  129.     0000017, 0000240, SPECL3, "cflg",
  130.     0000017, 0000260, SPECL3, "sflg",
  131.     0000377, 0104000, SPECL4, "emt",
  132.     0000377, 0104400, SPECL5, "sys",
  133.     0000077, 0006400, SPECL7, "mark",
  134.     0000777, 0077000, SPECL8, "sob",
  135.     0000007, 0000230, SPECL9, "spl",
  136.     0177777, 0000000, SPECL6, "oct",
  137. };
  138.  
  139. struct systab {
  140.     int    argc;
  141.     char    *sname;
  142. } systab[] {
  143.     1, "indir",
  144.     0, "exit",
  145.     0, "fork",
  146.     2, "read",
  147.     2, "write",
  148.     2, "open",
  149.     0, "close",
  150.     0, "wait",
  151.     2, "creat",
  152.     2, "link",
  153.     1, "unlink",
  154.     2, "exec",
  155.     1, "chdir",
  156.     0, "time",
  157.     3, "mknod",
  158.     2, "chmod",
  159.     2, "chown",
  160.     1, "break",
  161.     2, "stat",
  162.     2, "seek",
  163.     0, "getpid",
  164.     3, "mount",
  165.     1, "umount",
  166.     0, "setuid",
  167.     0, "getuid",
  168.     0, "stime",
  169.     3, "ptrace",
  170.     0, "27",
  171.     1, "fstat",
  172.     0, "29",
  173.     1, "smdate",
  174.     1, "stty",
  175.     1, "gtty",
  176.     0, "33",
  177.     0, "nice",
  178.     0, "sleep",
  179.     0, "sync",
  180.     1, "kill",
  181.     0, "switch",
  182.     0, "39",
  183.     0, "40",
  184.     0, "dup",
  185.     0, "pipe",
  186.     1, "times",
  187.     4, "profil",
  188.     0, "45",
  189.     0, "setgid",
  190.     0, "getgid",
  191.     2, "signal",
  192.     0, "49",
  193.     0, "50",
  194.     0, "51",
  195.     0, "52",
  196.     0, "53",
  197.     0, "54",
  198.     0, "55",
  199.     0, "56",
  200.     0, "57",
  201.     0, "58",
  202.     0, "59",
  203.     0, "60",
  204.     0, "61",
  205.     0, "62",
  206.     0, "63",
  207. };
  208.  
  209. char    *regname[] { "r0", "r1", "r2", "r3", "r4", "r5", "sp", "pc"};
  210.  
  211. printins(f)
  212. {
  213.     register ins, w;
  214.     register struct optab *p;
  215.  
  216.     dotinc = 2;
  217.     ins = cget(dot, ISP);
  218.     if (vallook(dot)==0)
  219.         printf("%.8s:", ssymbol);
  220.     printf("\t");
  221.     for (p=optab;; p++)
  222.         if ((ins & ~p->mask) == p->val)
  223.             break;
  224.     printf("%s", p->iname);
  225.     switch (p->itype) {
  226.  
  227.     /* rts */
  228.     case SPECL2:
  229.         ins =& 07;
  230.  
  231.     case SINGLE:
  232.         if (ins < 0)
  233.             printf("b");
  234.  
  235.     case SINGLW:
  236.         printf("\t");
  237.         paddr(ins);
  238.         return;
  239.  
  240.     case FLTREV:
  241.         ins =& 0377;
  242.  
  243.     case MULDIV:
  244.         ins = ((ins>>6)&07) | ((ins<<6)&07700);
  245.         goto doub;
  246.  
  247.     case FLTNOR:
  248.         ins =& 0377;
  249.  
  250.     /* jsr, xor */
  251.     case SPECL1:
  252.         ins =& 0777;
  253.         goto doub;
  254.  
  255.     case DOUBLE:
  256.         if (ins<0)
  257.             printf("b");
  258.     doub:
  259.         printf("\t");
  260.         paddr(ins>>6);
  261.         printf(",");
  262.         paddr(ins);
  263.         return;
  264.  
  265.     case NOADDR:
  266.         return;
  267.  
  268.     /* sob */
  269.     case SPECL8:
  270.         printf("\t");
  271.         paddr((ins>>6)&07);
  272.         printf(",");
  273.         ins = - (ins&077);
  274.         goto bran;
  275.  
  276.     case BRANCH:
  277.         printf("\t");
  278.     bran:
  279.         ins =& 0377;
  280.         if (ins&0200)
  281.             ins =| 0177400;
  282.         ins = dot + (ins<<1) + 2;
  283.         psymoff(ins, 010000);
  284.         return;
  285.  
  286.     /* emt */
  287.     case SPECL4:
  288.         ins =& 0377;
  289.     /* mark */
  290.     case SPECL7:
  291.         ins =& 077;
  292.     /* spl */
  293.     case SPECL9:
  294.         ins =& 07;
  295.         printf("\t%d", ins);
  296.         return;
  297.  
  298.     /* sys */
  299.     case SPECL5:
  300.         printf("\t%s", systab[ins =& 077].sname);
  301.         if (ins==0 && f==0) {    /* indir */
  302.             w = dot;
  303.             dot = cget(dot+2, ISP);
  304.             printf(" {");
  305.             printins(1);
  306.             printf("}");
  307.             dotinc = 4;
  308.             dot = w;
  309.             return;
  310.         }
  311.         w = systab[ins].argc;
  312.         while (w--) {
  313.             printf("; ");
  314.             psymoff(cget(dot+dotinc, ISP), 010000);
  315.             dotinc =+ 2;
  316.         }
  317.         return;
  318.  
  319.     default:
  320.         printf("\t%.1o", ins);
  321.     }
  322. }
  323.  
  324. paddr(aa)
  325. {
  326.     register a, r;
  327.  
  328.     a = aa;
  329.     r = a&07;
  330.     a =& 070;
  331.     if (r==7 && a&020) {
  332.         if (a&010)
  333.             printf("*");
  334.         if (a&040)
  335.             psymoff(cget(dot+dotinc, ISP)+dot+dotinc+2, 010000);
  336.         else {
  337.             printf("$");
  338.             psymoff(cget(dot+dotinc, ISP), 010000);
  339.         }
  340.         dotinc =+ 2;
  341.         return;
  342.     }
  343.     r = regname[r];
  344.     switch (a) {
  345.     /* r */
  346.     case 000:
  347.         printf("%s", r);
  348.         return;
  349.  
  350.     /* (r) */
  351.     case 010:
  352.         printf("(%s)", r);
  353.         return;
  354.  
  355.     /* *(r)+ */
  356.     case 030:
  357.         printf("*");
  358.  
  359.     /* (r)+ */
  360.     case 020:
  361.         printf("(%s)+", r);
  362.         return;
  363.  
  364.     /* *-(r) */
  365.     case 050:
  366.         printf("*");
  367.  
  368.     /* -(r) */
  369.     case 040:
  370.         printf("-(%s)", r);
  371.         return;
  372.  
  373.     /* *x(r) */
  374.     case 070:
  375.         printf("*");
  376.  
  377.     /* x(r) */
  378.     case 060:
  379.         psymoff(cget(dot+dotinc, ISP), 010000);
  380.         dotinc =+ 2;
  381.         printf("(%s)", r);
  382.         return;
  383.     }
  384. }
  385.