home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume35 / dis / part03 < prev    next >
Encoding:
Text File  |  1993-02-03  |  12.4 KB  |  484 lines

  1. Newsgroups: comp.sources.misc
  2. From: bediger@nugget.rmnug.org (Bruce Allen Ediger)
  3. Subject: v35i017:  dis - SPARC/SunOS disassembler, Part03/03
  4. Message-ID: <1993Feb2.064314.21066@sparky.imd.sterling.com>
  5. X-Md4-Signature: 3fd56a7697fda04d9bc122d0035ab881
  6. Date: Tue, 2 Feb 1993 06:43:14 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: bediger@nugget.rmnug.org (Bruce Allen Ediger)
  10. Posting-number: Volume 35, Issue 17
  11. Archive-name: dis/part03
  12. Environment: SunOS4.1.x
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  branches.c branches.h destination.c formats.h labels.c
  19. #   makefile memory.h
  20. # Wrapped by kent@sparky on Tue Feb  2 00:31:41 1993
  21. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 3 (of 3)."'
  24. if test -f 'branches.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'branches.c'\"
  26. else
  27.   echo shar: Extracting \"'branches.c'\" \(1124 characters\)
  28.   sed "s/^X//" >'branches.c' <<'END_OF_FILE'
  29. X#include <stdlib.h>
  30. X#include "branches.h"
  31. X
  32. X/*
  33. X *  Branch on integer condition code decoding.
  34. X *
  35. X * These routines implement most of Table F-7 of SPARC
  36. X * architecture manual.  The only thing left out is the
  37. X * Ticc column.  The branches have that dang "annul" bit
  38. X * which mitigates against using a simple array to hold
  39. X * the opcodes, like I used to hold the Ticc opcodes.
  40. X */
  41. Xchar *
  42. Xbicc(cond)
  43. Xunsigned int cond;
  44. X{
  45. X    char *ptr;
  46. X    int   a;
  47. X
  48. X    a = cond & 0x0100;    /* peel off annul bit */
  49. X    cond &= 0xff;
  50. X
  51. X    if (a)
  52. X        ptr = branches_annul[cond];
  53. X    else
  54. X        ptr = branches[cond];
  55. X    return ptr;
  56. X}
  57. X
  58. X/*
  59. X *  branch on floating point condition code decoding
  60. X */
  61. Xchar *
  62. Xfbfcc(cond)
  63. Xunsigned int cond;
  64. X{
  65. X    char *ptr;
  66. X    int   a;
  67. X
  68. X    a = cond & 0x0100;    /* peel off annul bit */
  69. X    cond &= 0xff;
  70. X
  71. X    if (a)
  72. X        ptr = fpbranches_annul[cond];
  73. X    else
  74. X        ptr = fpbranches[cond];
  75. X    return ptr;
  76. X}
  77. X
  78. X/*
  79. X *  branch on coprocessor condition code decoding
  80. X */
  81. Xchar *
  82. Xcbcc(cond)
  83. Xunsigned int cond;
  84. X{
  85. X    char *ptr;
  86. X    int   a;
  87. X
  88. X    a = cond & 0x0100;    /* peel off annul bit */
  89. X    cond &= 0xff;
  90. X
  91. X    if (a)
  92. X        ptr = cpbranches_annul[cond];
  93. X    else
  94. X        ptr = cpbranches[cond];
  95. X    return ptr;
  96. X}
  97. END_OF_FILE
  98.   if test 1124 -ne `wc -c <'branches.c'`; then
  99.     echo shar: \"'branches.c'\" unpacked with wrong size!
  100.   fi
  101.   # end of 'branches.c'
  102. fi
  103. if test -f 'branches.h' -a "${1}" != "-c" ; then 
  104.   echo shar: Will not clobber existing file \"'branches.h'\"
  105. else
  106.   echo shar: Extracting \"'branches.h'\" \(1099 characters\)
  107.   sed "s/^X//" >'branches.h' <<'END_OF_FILE'
  108. X#ifndef BRANCHES_H
  109. X#define BRANCHES_H
  110. X
  111. Xstatic char *branches[16] = {"bn", "be", "ble", "bl", "bleu", "bcs", "bneg",
  112. X        "bvs", "ba", "bne", "bg", "bge", "bgu", "bcc", "bpos", "bvc"};
  113. Xstatic char *branches_annul[16] = {"bn,a", "be,a", "ble,a", "bl,a", "bleu,a",
  114. X        "bcs,a", "bneg,a", "bvs,a", "ba,a", "bne,a", "bg,a", "bge,a", "bgu,a",
  115. X        "bcc,a", "bpos,a", "bvc,a"};
  116. X
  117. Xstatic char *fpbranches_annul[16] = {"fbn,a", "fbne,a", "fblg,a", "fbul,a",
  118. X    "fbl,a", "fbug,a", "fbg,a", "fbu,a", "fba,a", "fbe,a", "fbue,a", "fbge,a",
  119. X    "fbuge,a", "fble,a", "fbule,a", "fbo,a"};
  120. X
  121. Xstatic char *fpbranches[16] = {"fbn", "fbne", "fblg", "fbul", "fbl", "fbug",
  122. X    "fbg", "fbu", "fba", "fbe", "fbue", "fbge", "fbuge", "fble", "fbule",
  123. X    "fbo"};
  124. X
  125. X
  126. Xstatic char *cpbranches_annul[16] = { "cba,a", "cbn,a", "cb3,a", "cb2,a",
  127. X    "cb23,a", "cb1,a", "cb13,a", "cb12,a", "cb123,a", "cb0,a", "cb03,a",
  128. X    "cb02,a", "cb023,a", "cb01,a", "cb013,a", "cb012,a" };
  129. X
  130. Xstatic char *cpbranches[16] = {"cba", "cbn", "cb3", "cb2", "cb23", "cb1",
  131. X    "cb13", "cb12", "cb123", "cb0", "cb03", "cb02", "cb023", "cb01", "cb013",
  132. X    "cb012"};
  133. X
  134. X#endif BRANCHES_H
  135. END_OF_FILE
  136.   if test 1099 -ne `wc -c <'branches.h'`; then
  137.     echo shar: \"'branches.h'\" unpacked with wrong size!
  138.   fi
  139.   # end of 'branches.h'
  140. fi
  141. if test -f 'destination.c' -a "${1}" != "-c" ; then 
  142.   echo shar: Will not clobber existing file \"'destination.c'\"
  143. else
  144.   echo shar: Extracting \"'destination.c'\" \(1232 characters\)
  145.   sed "s/^X//" >'destination.c' <<'END_OF_FILE'
  146. X#include <stdio.h>
  147. X#include <stdlib.h>
  148. X#include <string.h>
  149. X#include "formats.h"
  150. X
  151. X/*
  152. X * Find symbolic names/labels of destination of branches, jumps and calls
  153. X *                        NOT FULLY IMPLEMENTED.
  154. X */
  155. X
  156. Xchar *
  157. Xdestination_of(instr, pc, buf)
  158. Xunsigned long   instr, pc; 
  159. Xchar           *buf;
  160. X{
  161. X    struct format1  *instr1;
  162. X    struct format2  *instr2;
  163. X    struct format3b *instr3b;
  164. X    unsigned long dest = 0;
  165. X
  166. X    char *name_at_destination();
  167. X
  168. X    buf[0] = '\0';
  169. X    instr1 = (struct format1 *)&instr;
  170. X
  171. X    switch (instr1->op) {
  172. X    case 0:
  173. X        /* op == 0, UNIMP, Bicc, SETHI, NOP, FBfcc, CBccc */
  174. X        instr2 = (struct format2 *)&instr;
  175. X        switch (instr2->op2) {
  176. X        case 2:
  177. X        case 6:
  178. X        case 7:
  179. X            dest = (int)pc + (int)(4 * (int)(SIGN_EXT22(instr2->imm22)));
  180. X            break;
  181. X        case 0:
  182. X        case 1:
  183. X        case 3:
  184. X        case 4:
  185. X        case 5:
  186. X        default:
  187. X            break;
  188. X        }
  189. X        break;
  190. X
  191. X    case 1:
  192. X        /* op == 1, CALL AND LINK */
  193. X        dest = 4 * instr1->disp30 + (int)pc;
  194. X        break;
  195. X
  196. X    case 2:
  197. X        /* maybe it's a jmpl or rett */
  198. X        instr3b = (struct format3b *)&instr;
  199. X        if(instr3b->op3 == 0x38 || instr3b->op3 == 0x39) {
  200. X            if (instr3b->i && instr3b->rs1 != 0)
  201. X                dest = SIGN_EXT13(instr3b->simm13);
  202. X        }
  203. X        break;
  204. X    }
  205. X
  206. X    if (dest != 0)
  207. X        if (!line_at_address(dest, buf))
  208. X            return NULL;
  209. X    return buf;
  210. X}
  211. END_OF_FILE
  212.   if test 1232 -ne `wc -c <'destination.c'`; then
  213.     echo shar: \"'destination.c'\" unpacked with wrong size!
  214.   fi
  215.   # end of 'destination.c'
  216. fi
  217. if test -f 'formats.h' -a "${1}" != "-c" ; then 
  218.   echo shar: Will not clobber existing file \"'formats.h'\"
  219. else
  220.   echo shar: Extracting \"'formats.h'\" \(1283 characters\)
  221.   sed "s/^X//" >'formats.h' <<'END_OF_FILE'
  222. X#ifndef FORMATS_H
  223. X#define FORMATS_H
  224. X
  225. X/*
  226. X * structs representing SPARC 32 bit instruction formats.
  227. X * These may or may not be portable, because they depend
  228. X * heavily on how the compiler represents bit fields.
  229. X *
  230. X * This is all per version 8 of The SPARC Architecture
  231. X * Reference Manual.
  232. X */
  233. X
  234. X/* call and link instruction */
  235. Xstruct format1 {
  236. X    unsigned int op:2;
  237. X    unsigned int disp30:30;
  238. X};
  239. X
  240. X/* sethi and branches */
  241. Xstruct format2 {
  242. X    unsigned int op:2;
  243. X    unsigned int rd:5;  /* annul bit carried around in rd */
  244. X    unsigned int op2:3;
  245. X    unsigned int imm22:22;
  246. X};
  247. X
  248. X/* memory, arithmetic, logical and shifts */
  249. Xstruct format3a {
  250. X    unsigned int op:2;
  251. X    unsigned int rd:5;
  252. X    unsigned int op3:6;
  253. X    unsigned int rs1:5;
  254. X    unsigned int i:1;
  255. X    unsigned int asi:8;
  256. X    unsigned int rs2:5;
  257. X};
  258. X
  259. Xstruct format3b {
  260. X    unsigned int op:2;
  261. X    unsigned int rd:5;
  262. X    unsigned int op3:6;
  263. X    unsigned int rs1:5;
  264. X    unsigned int i:1;
  265. X    unsigned int simm13:13;
  266. X};
  267. X
  268. X
  269. X/* floating point ops */
  270. Xstruct format3c {
  271. X    unsigned int op:2;
  272. X    unsigned int rd:5;
  273. X    unsigned int op3:6;
  274. X    unsigned int rs1:5;
  275. X    unsigned int opf:9;
  276. X    unsigned int rs2:5;
  277. X};
  278. X
  279. X/* sign extension macros for the odd bit fields in SPARC instructions */
  280. X#define SIGN_EXT22(a)   ((a)&0x200000)?0xffc00000^(a):(a)
  281. X#define SIGN_EXT13(a)    ((a)&0x1000)?0xffffe000^(a):(a)
  282. X
  283. X#endif
  284. END_OF_FILE
  285.   if test 1283 -ne `wc -c <'formats.h'`; then
  286.     echo shar: \"'formats.h'\" unpacked with wrong size!
  287.   fi
  288.   # end of 'formats.h'
  289. fi
  290. if test -f 'labels.c' -a "${1}" != "-c" ; then 
  291.   echo shar: Will not clobber existing file \"'labels.c'\"
  292. else
  293.   echo shar: Extracting \"'labels.c'\" \(1691 characters\)
  294.   sed "s/^X//" >'labels.c' <<'END_OF_FILE'
  295. X#include <stdio.h>
  296. X#include <stdlib.h>
  297. X#include <string.h>
  298. X#include <a.out.h>
  299. X#include <stab.h>
  300. X#include <sys/types.h>
  301. X#include "hash.h"
  302. X
  303. X/*
  304. X * Functions for dealing with labels and label lookup.
  305. X * Heavily dependent on "hash" routines from CAP.
  306. X *      NOT FULLY IMPLEMENTED
  307. X */
  308. X
  309. Xcaddr_t         label_hash_table;
  310. X
  311. Xint
  312. Xlabel_address_compare(key, data)
  313. Xcaddr_t         key, data;
  314. X{
  315. X    unsigned long   address = ((struct nlist *) key)->n_value;
  316. X
  317. X    if (address > ((struct nlist *) data)->n_value)
  318. X        return 1;
  319. X    if (address == ((struct nlist *) data)->n_value)
  320. X        return 0;
  321. X    if (address < ((struct nlist *) data)->n_value)
  322. X        return -1;
  323. X
  324. X    return 0;  /* make lint happy */
  325. X}
  326. Xu_int
  327. Xlabel_address_compress(key)
  328. Xcaddr_t         key;
  329. X{
  330. X    return ((struct nlist *) key)->n_value;
  331. X}
  332. X
  333. Xcaddr_t
  334. Xlabel_address_allocate(p)
  335. Xcaddr_t         p;
  336. X{
  337. X    struct nlist *tmp
  338. X    = (struct nlist *) malloc(sizeof(struct nlist));
  339. X
  340. X    if (tmp != NULL)
  341. X        bcopy(p, (caddr_t) tmp, sizeof(struct nlist));
  342. X
  343. X    return (caddr_t) tmp;
  344. X}
  345. X
  346. Xint
  347. Xinitialize_label(exhdr_p, fp)
  348. Xstruct exec    *exhdr_p;
  349. XFILE           *fp;
  350. X{
  351. X    int sym_number, string_table_size;
  352. X    int i;
  353. X
  354. X    sym_number = exhdr_p->a_trsize / sizeof(struct reloc_info_sparc);
  355. X    /* put N_SLINE and N_FUN things into line no. table */
  356. X    for (i = 0; i < sym_number; ++i) {
  357. X        int tmp;
  358. X        /* tmp = symbol_table[i].n_type;
  359. X        if ((tmp & N_STAB) && ((tmp & ~N_EXT) == N_SLINE || (tmp & ~N_EXT) == N_FUN)) {
  360. X            if (h_insert(line_hash_table, &(symbol_table[i])) == NULL) {
  361. X                fprintf(stderr, "botched adding reloc entry %d to hash table (h_insert)\n", i);
  362. X                return 0;
  363. X            }
  364. X        }
  365. X        */
  366. X    }
  367. X    return 1;
  368. X}
  369. X
  370. X
  371. X
  372. Xint
  373. Xlabel_at_address(addr, buffer)
  374. X    unsigned long   addr;
  375. X    char           *buffer;
  376. X{
  377. X    return 0;
  378. X}
  379. END_OF_FILE
  380.   if test 1691 -ne `wc -c <'labels.c'`; then
  381.     echo shar: \"'labels.c'\" unpacked with wrong size!
  382.   fi
  383.   # end of 'labels.c'
  384. fi
  385. if test -f 'makefile' -a "${1}" != "-c" ; then 
  386.   echo shar: Will not clobber existing file \"'makefile'\"
  387. else
  388.   echo shar: Extracting \"'makefile'\" \(655 characters\)
  389.   sed "s/^X//" >'makefile' <<'END_OF_FILE'
  390. XCFLAGS = -g -I. -I./include
  391. X
  392. XSRC = dis.c decode.c memory.c branches.c arithmetic.c \
  393. X    printout.c relocation.c hash.c line.c destination.c
  394. XOBJ = dis.o decode.o memory.o branches.o arithmetic.o \
  395. X    relocation.o hash.o line.o destination.o printout.o
  396. XHDRS = arithmetic.h branches.h memory.h formats.h hash.h sparc_stuff.h
  397. XOTHERS = dis.1 hash.3 README makefile labels.c
  398. X
  399. X.c: dis.h
  400. X.c: .h
  401. X
  402. Xdis: ${OBJ}
  403. X    cc -o dis -g ${OBJ}
  404. X
  405. Xclean:
  406. X    rm $(OBJ)
  407. X    rm dis
  408. X
  409. Xlint:
  410. X    lint ${SRC} | tee /dev/tty > lintout
  411. X
  412. Xtar:
  413. X    tar cvf dis.tar ${SRC} ${HDRS} ${OTHERS}
  414. X
  415. Xshar:
  416. X     shar ${HDRS} ${OTHERS} > dis1.shar
  417. X     shar ${SRC} > dis2.shar
  418. X
  419. Xmanpage:
  420. X    troff -t -man dis.1 | thack > dis.ps
  421. END_OF_FILE
  422.   if test 655 -ne `wc -c <'makefile'`; then
  423.     echo shar: \"'makefile'\" unpacked with wrong size!
  424.   fi
  425.   # end of 'makefile'
  426. fi
  427. if test -f 'memory.h' -a "${1}" != "-c" ; then 
  428.   echo shar: Will not clobber existing file \"'memory.h'\"
  429. else
  430.   echo shar: Extracting \"'memory.h'\" \(1280 characters\)
  431.   sed "s/^X//" >'memory.h' <<'END_OF_FILE'
  432. X#ifndef MEMORY_H
  433. X#define MEMORY_H
  434. X
  435. X/* Table F-4 in "The SPARC Architecture Manual", version 8 */
  436. X/*
  437. X * the floating point and coprocessor instructions are 
  438. X * marked with a "?" since I haven't really exercised that stuff,
  439. X * and therefore may be missing a few tricks.
  440. X */
  441. Xstatic char *table_f_4[16][4] = {
  442. X{ "ld", "lda", "?ldf", "?ldc" },
  443. X{ "ldub", "lduba", "?ldfsr", "?ldcsr" },
  444. X{ "lduh", "lduha", "invalid op3 (0x22)", "invalid op3 (0x32)" },
  445. X{ "ldd", "ldda", "?lddf", "?lddc" },
  446. X{ "st", "sta", "?stf", "stc" },
  447. X{ "stb", "stba", "?stfsr", "?stcsr" },
  448. X{ "sth", "stha", "?stdfq", "?stdcq" },
  449. X{ "std", "stda", "?stdf", "?stdc" },
  450. X{ "invalid op3 (0x08)", "invalid op3 (0x18)", "invalid op3 (0x28)", "invalid op3 (0x38)" },
  451. X{ "ldsb", "ldsba", "invalid op3 (0x29)", "invalid op3 (0x39)" },
  452. X{ "ldsh", "ldsha", "invalid op3 (0x2a)", "invalid op3 (0x3a)" },
  453. X{ "invalid op3 (0x0b)", "invalid op3 (0x1b)", "invalid op3 (0x2b)", "invalid op3 (0x3b)" },
  454. X{ "invalid op3 (0x0c)", "invalid op3 (0x1c)", "invalid op3 (0x2c)", "invalid op3 (0x3c)" },
  455. X{ "ldstub", "ldstuba", "invalid op3 (0x2d)", "invalid op3 (0x3d)" },
  456. X{ "invalid op3 (0x0e)", "invalid op3 (0x1e)", "invalid op3 (0x2e)", "invalid op3 (0x3e)" },
  457. X{ "swap", "swapa", "invalid op3 (0x2f)", "invalid op3 (0x3f)" }
  458. X};
  459. X
  460. X#endif MEMORY_H
  461. END_OF_FILE
  462.   if test 1280 -ne `wc -c <'memory.h'`; then
  463.     echo shar: \"'memory.h'\" unpacked with wrong size!
  464.   fi
  465.   # end of 'memory.h'
  466. fi
  467. echo shar: End of archive 3 \(of 3\).
  468. cp /dev/null ark3isdone
  469. MISSING=""
  470. for I in 1 2 3 ; do
  471.     if test ! -f ark${I}isdone ; then
  472.     MISSING="${MISSING} ${I}"
  473.     fi
  474. done
  475. if test "${MISSING}" = "" ; then
  476.     echo You have unpacked all 3 archives.
  477.     rm -f ark[1-9]isdone
  478. else
  479.     echo You still must unpack the following archives:
  480.     echo "        " ${MISSING}
  481. fi
  482. exit 0
  483. exit 0 # Just in case...
  484.