home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / SRC / unc.lzh / UNC / prin.c < prev    next >
Text File  |  1991-06-10  |  6KB  |  295 lines

  1. /*
  2.  *   SCCS:   %W%   %G%   %U%
  3.  *   Print stuff.
  4.  *
  5.  *EMACS_MODES:c
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include "a.out.h"
  10. #include "unc.h"
  11. #include <ctype.h>
  12.  
  13. #define   LINELNG   70
  14.  
  15. void   gette(), getde();
  16. long   gettw(), getdw();
  17. void   prinst();
  18.  
  19. char   noabs;         /*  No non-global absolutes  */
  20. extern int   rel;         /*  File being analysed is relocatable  */
  21. int   lpos;
  22.  
  23. extern struct   commit   abstab, comtab;
  24. #ifdef   COFF
  25. extern char shlibout;
  26. #endif   /*  COFF  */
  27.  
  28. void gopos(x)
  29. int x;
  30. {
  31.    do    /* mindestens 1 Space ausgeben */
  32.       xp += printf(" ");
  33.    while(xp < x);
  34. }
  35.  
  36. void go1st()
  37. {
  38.    xp = 0;
  39.    if (popt) gopos(PFIRST);
  40.    xp = 0;
  41. }
  42.  
  43.  
  44. /*
  45.  *   Print absolute and common values.
  46.  */
  47.  
  48. void   pabs()
  49. {
  50.    register  int   i;
  51.    register  symbol  cs;
  52.  
  53.    for  (i = 0;  i < abstab.c_int;  i++)
  54.    
  55.    for  (i = 0;  i < abstab.c_int;  i++)  {
  56.       cs = abstab.c_symb[i];
  57.       xp += printf("#\tglobal\t%s\n", cs->s_name);
  58.       xp += printf("# %s\t= 0x%lx\n", cs->s_name, cs->s_value);
  59.    }
  60.    for  (i = 0;  i < comtab.c_int;  i++)  {
  61.       cs = comtab.c_symb[i];
  62.       xp += printf("\tcomm\t%s,%d\n", cs->s_name, cs->s_value);
  63.       xp += printf("\t.globl\t%s\n", cs->s_name);
  64.       xp += printf("%s\t=\t0x%lx\n", cs->s_name, cs->s_value);
  65.    }
  66.    for  (i = 0;  i < comtab.c_int;  i++)  {
  67.       cs = comtab.c_symb[i];
  68.       xp += printf("\t.comm\t%s,%d\n", cs->s_name, cs->s_value);
  69.    }
  70. }
  71.  
  72. void phdr()
  73. {
  74.    char *s;
  75.  
  76.    go1st();
  77.    xp += printf("Ed");
  78.    gopos(OPCODE);
  79.    xp += printf("equ");
  80.    gopos(ARGUMENT);
  81.    xp += printf("%d\n", hdr._mh._medit);
  82.  
  83.    go1st();
  84.    xp += printf("Typ_Lang");
  85.    gopos(OPCODE);
  86.    xp += printf("equ");
  87.    gopos(ARGUMENT);
  88.    xp += printf("$%x\n", 0xFFFF & hdr._mh._mtylan);
  89.  
  90.    go1st();
  91.    xp += printf("Attr_Rev");
  92.    gopos(OPCODE);
  93.    xp += printf("equ");
  94.    gopos(ARGUMENT);
  95.    xp += printf("$%x\n", 0xFFFF & hdr._mh._mattrev);
  96.    
  97.    go1st();
  98.    xp += printf("stk");
  99.    gopos(OPCODE);
  100.    xp += printf("equ");
  101.    gopos(ARGUMENT);
  102.    xp += printf("$%x\n\n", hdr._mstack);
  103.    
  104.    go1st();
  105.    gopos(OPCODE);   
  106.    xp += printf("psect");
  107.    gopos(ARGUMENT);
  108.    xp += printf("disas,Typ_Lang,Attr_Rev,Ed,stk,start\n\n");
  109. }
  110.    
  111.       
  112. /*
  113.  * print Addr & contents
  114.  */
  115. void pconts(pos)
  116. long pos;
  117. {
  118.    int len;
  119.    t_entry tent;
  120.    
  121.    xp = 0;
  122.    gette(pos, &tent);
  123.    xp = printf("%05x %04x", pos, tent.t_contents);
  124.    for (len = tent.t_lng; len > 1; len--)
  125.    {
  126.       pos += 2;
  127.       gette(pos, &tent);
  128.       xp += printf("%04x", tent.t_contents);
  129.    }
  130.    do
  131.       xp += printf(" ");
  132.    while (xp < PFIRST);   
  133. }
  134.       
  135. /*
  136.  *   Print out labels.
  137.  */
  138.  
  139. void   plabs(ls, seg)
  140. register  symbol  ls;
  141. int   seg;
  142. {
  143.    for  (; ls != NULL;  ls = ls->s_link)  {
  144. /* hcz !!!!!      if  (ls->s_type != seg)
  145.          continue; */
  146.       xp += printf("%s:", ls->s_name);
  147.    }
  148. }
  149.  
  150. void addchar(s, c)
  151. char *s;
  152. char c;
  153. {
  154.    char s1[2];
  155.    c &= '\xff';
  156.    strcpy(s1, " ");
  157.    if (isprint(c))
  158.       s1[0] = c;
  159.    strcat(s, s1);
  160. }
  161.  
  162. /*
  163.  *   Print out text.
  164.  */
  165.  
  166. void   ptext(fid)
  167. register  ef_fid  fid;
  168. {
  169.    register  long   tpos;
  170.    t_entry   tstr;
  171.    char s[20];
  172.    int len, i;
  173.  
  174.    tpos = hdr._mexec;
  175.  
  176.    if (ismodule)
  177.       phdr();
  178.    for  (;  tpos < endp;  tpos += len)
  179.    {
  180.       xp = 0;      
  181.       if (popt > 0)
  182.          pconts(tpos);
  183.       xp = 0;   
  184.       gette(tpos, &tstr);
  185.       plabs(tstr.t_lab, TEXT);
  186.       gopos(OPCODE);
  187.       gette(tpos, &tstr);
  188.       if  (tstr.t_type == T_OPCODE)
  189.       {
  190.          prinst(&tstr, tpos);
  191.          len = tstr.t_lng << 1;
  192.       }
  193.       else
  194.       {
  195.          xp += printf("dc.w");
  196.          gopos(ARGUMENT);
  197.          s[0] = '\0';
  198.          xp += printf("$%x", tstr.t_contents);
  199.          addchar(s, (char) (tstr.t_contents >> 8));
  200.          addchar(s, (char) tstr.t_contents);
  201.          for (i = 2; i < 8; i += 2)         
  202.          {
  203.             gette (tpos + i, &tstr);
  204.             if (tstr.t_type != T_OPCODE)
  205.             {
  206.                xp += printf(",$%x", tstr.t_contents);
  207.                addchar(s, (char) (tstr.t_contents >> 8));
  208.                addchar(s, (char) tstr.t_contents);
  209.             }
  210.             else
  211.                break;
  212.          }
  213.          gopos(STRING);
  214.          xp += printf("'%s'\n", s);
  215.          len = i;
  216.       }
  217.    }
  218.  
  219.    /*
  220.     *   Print out any trailing label.
  221.     */
  222.    
  223.    gette(tpos, &tstr);
  224.    plabs(tstr.t_lab, TEXT);
  225. }
  226.  
  227. /*
  228.  *   Print out data.
  229.  */
  230.  
  231. void   pdata(fid)
  232. register  ef_fid  fid;
  233. {
  234.    long beg, addr, len;
  235.    int init;
  236.    d_entry dent;
  237.    
  238.    if (hdr._mdata == 0)
  239.       return;
  240.       
  241.    printf("\n");
  242.    go1st();
  243.    gopos(OPCODE);
  244.    xp += printf("vsect\n");
  245.    go1st();
  246.    xp += printf("vstart:");
  247.    gopos(OPCODE);
  248.    xp += printf("ds.b");
  249.    init = 0;
  250.    gopos(ARGUMENT);
  251.  
  252.    for (len = 0, beg = addr = a6offset; addr < a6offset + hdr._mdata;
  253.       len++, addr++ )
  254.    {
  255.       getde(addr, &dent);
  256.       if (dent.d_lab != NULL)
  257.       {         
  258.          if (init == 0)
  259.             xp += printf("%d", len);
  260.          gopos(COMMENT);
  261.          xp += printf("$%x(a6)\n", beg);
  262.          len = 0;
  263.          beg = addr;
  264.          go1st();
  265.          xp += printf("%s", dent.d_lab->s_name);
  266.          gopos(OPCODE);
  267.          if ((init = dent.d_initialized) != 0)
  268.          {
  269.             xp += printf("dc.b");
  270.             gopos(ARGUMENT);
  271.             xp += printf("$%x", dent.d_contents & 0xff);
  272.          }
  273.          else
  274.          {
  275.             xp += printf("ds.b");
  276.             gopos(ARGUMENT);
  277.          }            
  278.       }
  279.       else if (init)
  280.          xp += printf(",$%x", dent.d_contents);
  281.    }
  282.    if ((init = dent.d_initialized) == 0)
  283.             xp += printf("%d", len);
  284.    gopos(COMMENT);
  285.    xp += printf("$%x(a6)\n", beg);
  286.    go1st();
  287.    gopos(OPCODE);
  288.    xp += printf("ends\n\n");
  289.    go1st();
  290.    gopos(OPCODE);
  291.    xp += printf("ends");
  292.    xp = 0;
  293. }
  294.  
  295.