home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: bediger@nugget.rmnug.org (Bruce Allen Ediger)
- Subject: v35i017: dis - SPARC/SunOS disassembler, Part03/03
- Message-ID: <1993Feb2.064314.21066@sparky.imd.sterling.com>
- X-Md4-Signature: 3fd56a7697fda04d9bc122d0035ab881
- Date: Tue, 2 Feb 1993 06:43:14 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: bediger@nugget.rmnug.org (Bruce Allen Ediger)
- Posting-number: Volume 35, Issue 17
- Archive-name: dis/part03
- Environment: SunOS4.1.x
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: branches.c branches.h destination.c formats.h labels.c
- # makefile memory.h
- # Wrapped by kent@sparky on Tue Feb 2 00:31:41 1993
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 3 (of 3)."'
- if test -f 'branches.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'branches.c'\"
- else
- echo shar: Extracting \"'branches.c'\" \(1124 characters\)
- sed "s/^X//" >'branches.c' <<'END_OF_FILE'
- X#include <stdlib.h>
- X#include "branches.h"
- X
- X/*
- X * Branch on integer condition code decoding.
- X *
- X * These routines implement most of Table F-7 of SPARC
- X * architecture manual. The only thing left out is the
- X * Ticc column. The branches have that dang "annul" bit
- X * which mitigates against using a simple array to hold
- X * the opcodes, like I used to hold the Ticc opcodes.
- X */
- Xchar *
- Xbicc(cond)
- Xunsigned int cond;
- X{
- X char *ptr;
- X int a;
- X
- X a = cond & 0x0100; /* peel off annul bit */
- X cond &= 0xff;
- X
- X if (a)
- X ptr = branches_annul[cond];
- X else
- X ptr = branches[cond];
- X return ptr;
- X}
- X
- X/*
- X * branch on floating point condition code decoding
- X */
- Xchar *
- Xfbfcc(cond)
- Xunsigned int cond;
- X{
- X char *ptr;
- X int a;
- X
- X a = cond & 0x0100; /* peel off annul bit */
- X cond &= 0xff;
- X
- X if (a)
- X ptr = fpbranches_annul[cond];
- X else
- X ptr = fpbranches[cond];
- X return ptr;
- X}
- X
- X/*
- X * branch on coprocessor condition code decoding
- X */
- Xchar *
- Xcbcc(cond)
- Xunsigned int cond;
- X{
- X char *ptr;
- X int a;
- X
- X a = cond & 0x0100; /* peel off annul bit */
- X cond &= 0xff;
- X
- X if (a)
- X ptr = cpbranches_annul[cond];
- X else
- X ptr = cpbranches[cond];
- X return ptr;
- X}
- END_OF_FILE
- if test 1124 -ne `wc -c <'branches.c'`; then
- echo shar: \"'branches.c'\" unpacked with wrong size!
- fi
- # end of 'branches.c'
- fi
- if test -f 'branches.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'branches.h'\"
- else
- echo shar: Extracting \"'branches.h'\" \(1099 characters\)
- sed "s/^X//" >'branches.h' <<'END_OF_FILE'
- X#ifndef BRANCHES_H
- X#define BRANCHES_H
- X
- Xstatic char *branches[16] = {"bn", "be", "ble", "bl", "bleu", "bcs", "bneg",
- X "bvs", "ba", "bne", "bg", "bge", "bgu", "bcc", "bpos", "bvc"};
- Xstatic char *branches_annul[16] = {"bn,a", "be,a", "ble,a", "bl,a", "bleu,a",
- X "bcs,a", "bneg,a", "bvs,a", "ba,a", "bne,a", "bg,a", "bge,a", "bgu,a",
- X "bcc,a", "bpos,a", "bvc,a"};
- X
- Xstatic char *fpbranches_annul[16] = {"fbn,a", "fbne,a", "fblg,a", "fbul,a",
- X "fbl,a", "fbug,a", "fbg,a", "fbu,a", "fba,a", "fbe,a", "fbue,a", "fbge,a",
- X "fbuge,a", "fble,a", "fbule,a", "fbo,a"};
- X
- Xstatic char *fpbranches[16] = {"fbn", "fbne", "fblg", "fbul", "fbl", "fbug",
- X "fbg", "fbu", "fba", "fbe", "fbue", "fbge", "fbuge", "fble", "fbule",
- X "fbo"};
- X
- X
- Xstatic char *cpbranches_annul[16] = { "cba,a", "cbn,a", "cb3,a", "cb2,a",
- X "cb23,a", "cb1,a", "cb13,a", "cb12,a", "cb123,a", "cb0,a", "cb03,a",
- X "cb02,a", "cb023,a", "cb01,a", "cb013,a", "cb012,a" };
- X
- Xstatic char *cpbranches[16] = {"cba", "cbn", "cb3", "cb2", "cb23", "cb1",
- X "cb13", "cb12", "cb123", "cb0", "cb03", "cb02", "cb023", "cb01", "cb013",
- X "cb012"};
- X
- X#endif BRANCHES_H
- END_OF_FILE
- if test 1099 -ne `wc -c <'branches.h'`; then
- echo shar: \"'branches.h'\" unpacked with wrong size!
- fi
- # end of 'branches.h'
- fi
- if test -f 'destination.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'destination.c'\"
- else
- echo shar: Extracting \"'destination.c'\" \(1232 characters\)
- sed "s/^X//" >'destination.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <stdlib.h>
- X#include <string.h>
- X#include "formats.h"
- X
- X/*
- X * Find symbolic names/labels of destination of branches, jumps and calls
- X * NOT FULLY IMPLEMENTED.
- X */
- X
- Xchar *
- Xdestination_of(instr, pc, buf)
- Xunsigned long instr, pc;
- Xchar *buf;
- X{
- X struct format1 *instr1;
- X struct format2 *instr2;
- X struct format3b *instr3b;
- X unsigned long dest = 0;
- X
- X char *name_at_destination();
- X
- X buf[0] = '\0';
- X instr1 = (struct format1 *)&instr;
- X
- X switch (instr1->op) {
- X case 0:
- X /* op == 0, UNIMP, Bicc, SETHI, NOP, FBfcc, CBccc */
- X instr2 = (struct format2 *)&instr;
- X switch (instr2->op2) {
- X case 2:
- X case 6:
- X case 7:
- X dest = (int)pc + (int)(4 * (int)(SIGN_EXT22(instr2->imm22)));
- X break;
- X case 0:
- X case 1:
- X case 3:
- X case 4:
- X case 5:
- X default:
- X break;
- X }
- X break;
- X
- X case 1:
- X /* op == 1, CALL AND LINK */
- X dest = 4 * instr1->disp30 + (int)pc;
- X break;
- X
- X case 2:
- X /* maybe it's a jmpl or rett */
- X instr3b = (struct format3b *)&instr;
- X if(instr3b->op3 == 0x38 || instr3b->op3 == 0x39) {
- X if (instr3b->i && instr3b->rs1 != 0)
- X dest = SIGN_EXT13(instr3b->simm13);
- X }
- X break;
- X }
- X
- X if (dest != 0)
- X if (!line_at_address(dest, buf))
- X return NULL;
- X return buf;
- X}
- END_OF_FILE
- if test 1232 -ne `wc -c <'destination.c'`; then
- echo shar: \"'destination.c'\" unpacked with wrong size!
- fi
- # end of 'destination.c'
- fi
- if test -f 'formats.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'formats.h'\"
- else
- echo shar: Extracting \"'formats.h'\" \(1283 characters\)
- sed "s/^X//" >'formats.h' <<'END_OF_FILE'
- X#ifndef FORMATS_H
- X#define FORMATS_H
- X
- X/*
- X * structs representing SPARC 32 bit instruction formats.
- X * These may or may not be portable, because they depend
- X * heavily on how the compiler represents bit fields.
- X *
- X * This is all per version 8 of The SPARC Architecture
- X * Reference Manual.
- X */
- X
- X/* call and link instruction */
- Xstruct format1 {
- X unsigned int op:2;
- X unsigned int disp30:30;
- X};
- X
- X/* sethi and branches */
- Xstruct format2 {
- X unsigned int op:2;
- X unsigned int rd:5; /* annul bit carried around in rd */
- X unsigned int op2:3;
- X unsigned int imm22:22;
- X};
- X
- X/* memory, arithmetic, logical and shifts */
- Xstruct format3a {
- X unsigned int op:2;
- X unsigned int rd:5;
- X unsigned int op3:6;
- X unsigned int rs1:5;
- X unsigned int i:1;
- X unsigned int asi:8;
- X unsigned int rs2:5;
- X};
- X
- Xstruct format3b {
- X unsigned int op:2;
- X unsigned int rd:5;
- X unsigned int op3:6;
- X unsigned int rs1:5;
- X unsigned int i:1;
- X unsigned int simm13:13;
- X};
- X
- X
- X/* floating point ops */
- Xstruct format3c {
- X unsigned int op:2;
- X unsigned int rd:5;
- X unsigned int op3:6;
- X unsigned int rs1:5;
- X unsigned int opf:9;
- X unsigned int rs2:5;
- X};
- X
- X/* sign extension macros for the odd bit fields in SPARC instructions */
- X#define SIGN_EXT22(a) ((a)&0x200000)?0xffc00000^(a):(a)
- X#define SIGN_EXT13(a) ((a)&0x1000)?0xffffe000^(a):(a)
- X
- X#endif
- END_OF_FILE
- if test 1283 -ne `wc -c <'formats.h'`; then
- echo shar: \"'formats.h'\" unpacked with wrong size!
- fi
- # end of 'formats.h'
- fi
- if test -f 'labels.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'labels.c'\"
- else
- echo shar: Extracting \"'labels.c'\" \(1691 characters\)
- sed "s/^X//" >'labels.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <stdlib.h>
- X#include <string.h>
- X#include <a.out.h>
- X#include <stab.h>
- X#include <sys/types.h>
- X#include "hash.h"
- X
- X/*
- X * Functions for dealing with labels and label lookup.
- X * Heavily dependent on "hash" routines from CAP.
- X * NOT FULLY IMPLEMENTED
- X */
- X
- Xcaddr_t label_hash_table;
- X
- Xint
- Xlabel_address_compare(key, data)
- Xcaddr_t key, data;
- X{
- X unsigned long address = ((struct nlist *) key)->n_value;
- X
- X if (address > ((struct nlist *) data)->n_value)
- X return 1;
- X if (address == ((struct nlist *) data)->n_value)
- X return 0;
- X if (address < ((struct nlist *) data)->n_value)
- X return -1;
- X
- X return 0; /* make lint happy */
- X}
- Xu_int
- Xlabel_address_compress(key)
- Xcaddr_t key;
- X{
- X return ((struct nlist *) key)->n_value;
- X}
- X
- Xcaddr_t
- Xlabel_address_allocate(p)
- Xcaddr_t p;
- X{
- X struct nlist *tmp
- X = (struct nlist *) malloc(sizeof(struct nlist));
- X
- X if (tmp != NULL)
- X bcopy(p, (caddr_t) tmp, sizeof(struct nlist));
- X
- X return (caddr_t) tmp;
- X}
- X
- Xint
- Xinitialize_label(exhdr_p, fp)
- Xstruct exec *exhdr_p;
- XFILE *fp;
- X{
- X int sym_number, string_table_size;
- X int i;
- X
- X sym_number = exhdr_p->a_trsize / sizeof(struct reloc_info_sparc);
- X /* put N_SLINE and N_FUN things into line no. table */
- X for (i = 0; i < sym_number; ++i) {
- X int tmp;
- X /* tmp = symbol_table[i].n_type;
- X if ((tmp & N_STAB) && ((tmp & ~N_EXT) == N_SLINE || (tmp & ~N_EXT) == N_FUN)) {
- X if (h_insert(line_hash_table, &(symbol_table[i])) == NULL) {
- X fprintf(stderr, "botched adding reloc entry %d to hash table (h_insert)\n", i);
- X return 0;
- X }
- X }
- X */
- X }
- X return 1;
- X}
- X
- X
- X
- Xint
- Xlabel_at_address(addr, buffer)
- X unsigned long addr;
- X char *buffer;
- X{
- X return 0;
- X}
- END_OF_FILE
- if test 1691 -ne `wc -c <'labels.c'`; then
- echo shar: \"'labels.c'\" unpacked with wrong size!
- fi
- # end of 'labels.c'
- fi
- if test -f 'makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'makefile'\"
- else
- echo shar: Extracting \"'makefile'\" \(655 characters\)
- sed "s/^X//" >'makefile' <<'END_OF_FILE'
- XCFLAGS = -g -I. -I./include
- X
- XSRC = dis.c decode.c memory.c branches.c arithmetic.c \
- X printout.c relocation.c hash.c line.c destination.c
- XOBJ = dis.o decode.o memory.o branches.o arithmetic.o \
- X relocation.o hash.o line.o destination.o printout.o
- XHDRS = arithmetic.h branches.h memory.h formats.h hash.h sparc_stuff.h
- XOTHERS = dis.1 hash.3 README makefile labels.c
- X
- X.c: dis.h
- X.c: .h
- X
- Xdis: ${OBJ}
- X cc -o dis -g ${OBJ}
- X
- Xclean:
- X rm $(OBJ)
- X rm dis
- X
- Xlint:
- X lint ${SRC} | tee /dev/tty > lintout
- X
- Xtar:
- X tar cvf dis.tar ${SRC} ${HDRS} ${OTHERS}
- X
- Xshar:
- X shar ${HDRS} ${OTHERS} > dis1.shar
- X shar ${SRC} > dis2.shar
- X
- Xmanpage:
- X troff -t -man dis.1 | thack > dis.ps
- END_OF_FILE
- if test 655 -ne `wc -c <'makefile'`; then
- echo shar: \"'makefile'\" unpacked with wrong size!
- fi
- # end of 'makefile'
- fi
- if test -f 'memory.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'memory.h'\"
- else
- echo shar: Extracting \"'memory.h'\" \(1280 characters\)
- sed "s/^X//" >'memory.h' <<'END_OF_FILE'
- X#ifndef MEMORY_H
- X#define MEMORY_H
- X
- X/* Table F-4 in "The SPARC Architecture Manual", version 8 */
- X/*
- X * the floating point and coprocessor instructions are
- X * marked with a "?" since I haven't really exercised that stuff,
- X * and therefore may be missing a few tricks.
- X */
- Xstatic char *table_f_4[16][4] = {
- X{ "ld", "lda", "?ldf", "?ldc" },
- X{ "ldub", "lduba", "?ldfsr", "?ldcsr" },
- X{ "lduh", "lduha", "invalid op3 (0x22)", "invalid op3 (0x32)" },
- X{ "ldd", "ldda", "?lddf", "?lddc" },
- X{ "st", "sta", "?stf", "stc" },
- X{ "stb", "stba", "?stfsr", "?stcsr" },
- X{ "sth", "stha", "?stdfq", "?stdcq" },
- X{ "std", "stda", "?stdf", "?stdc" },
- X{ "invalid op3 (0x08)", "invalid op3 (0x18)", "invalid op3 (0x28)", "invalid op3 (0x38)" },
- X{ "ldsb", "ldsba", "invalid op3 (0x29)", "invalid op3 (0x39)" },
- X{ "ldsh", "ldsha", "invalid op3 (0x2a)", "invalid op3 (0x3a)" },
- X{ "invalid op3 (0x0b)", "invalid op3 (0x1b)", "invalid op3 (0x2b)", "invalid op3 (0x3b)" },
- X{ "invalid op3 (0x0c)", "invalid op3 (0x1c)", "invalid op3 (0x2c)", "invalid op3 (0x3c)" },
- X{ "ldstub", "ldstuba", "invalid op3 (0x2d)", "invalid op3 (0x3d)" },
- X{ "invalid op3 (0x0e)", "invalid op3 (0x1e)", "invalid op3 (0x2e)", "invalid op3 (0x3e)" },
- X{ "swap", "swapa", "invalid op3 (0x2f)", "invalid op3 (0x3f)" }
- X};
- X
- X#endif MEMORY_H
- END_OF_FILE
- if test 1280 -ne `wc -c <'memory.h'`; then
- echo shar: \"'memory.h'\" unpacked with wrong size!
- fi
- # end of 'memory.h'
- fi
- echo shar: End of archive 3 \(of 3\).
- cp /dev/null ark3isdone
- MISSING=""
- for I in 1 2 3 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 3 archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-