1 /* 2 ** @(#) dis.h, Ver. 2.1 created 00:00:00 87/09/01 3 */ 4 5 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 6 * * 7 * Copyright (C) 1987 G. M. Harding, all rights reserved * 8 * * 9 * Permission to copy and redistribute is hereby granted, * 10 * provided full source code, with all copyright notices, * 11 * accompanies any redistribution. * 12 * * 13 * This file contains declarations and definitions used by * 14 * the 8088 disassembler program. The program was designed * 15 * for execution on a machine of its own type (i.e., it is * 16 * not designed as a cross-disassembler); consequently, A * 17 * SIXTEEN-BIT INTEGER SIZE HAS BEEN ASSUMED. This assump- * 18 * tion is not particularly important, however, except in * 19 * the machine-specific portions of the code (i.e., the * 20 * handler routines and the optab[] array). It should be * 21 * possible to override this assumption, for execution on * 22 * 32-bit machines, by use of a pre-processor directive * 23 * (see below); however, this has not been tested. * 24 * * 25 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 26 27 #include <sys/types.h> 28 #include <fcntl.h> /* System file-control definitions */ 29 #include <unistd.h> 30 #include <string.h> 31 #include <stdlib.h> 32 #include <stdio.h> /* System standard I/O definitions */ 33 #include "a.out.h" /* Object file format definitions */ 34 #include "ansi.h" 35 36 #define MAXSYM ((sizeof(int)-1)*32400/ \ 37 (sizeof(struct nlist)+sizeof(struct reloc))) 38 /* Maximum entries in symbol table */ 39 40 extern struct nlist /* Array to hold the symbol table */ 41 symtab[MAXSYM]; 42 43 extern struct reloc /* Array to hold relocation table */ 44 relo[MAXSYM]; 45 46 extern int symptr; /* Index into the symtab[] array */ 47 extern int relptr; /* Index into the relo[] array */ 48 49 struct opcode /* Format for opcode data records */ 50 { 51 char *text; /* Pointer to mnemonic text */ 52 void (*func)(); /* Pointer to handler routine */ 53 unsigned min; /* Minimum # of object bytes */ 54 unsigned max; /* Maximum # of object bytes */ 55 }; 56 57 extern struct opcode /* Array to hold the opcode table */ 58 optab[256]; 59 60 extern char *REGS[]; /* Table of register names */ 61 extern char *REGS0[]; /* Mode 0 register name table */ 62 extern char *REGS1[]; /* Mode 1 register name table */ 63 64 #define AL REGS[0] /* CPU register manifests */ 65 #define CL REGS[1] 66 #define DL REGS[2] 67 #define BL REGS[3] 68 #define AH REGS[4] 69 #define CH REGS[5] 70 #define DH REGS[6] 71 #define BH REGS[7] 72 #define AX REGS[8] 73 #define CX REGS[9] 74 #define DX REGS[10] 75 #define BX REGS[11] 76 #define SP REGS[12] 77 #define BP REGS[13] 78 #define SI REGS[14] 79 #define DI REGS[15] 80 #define ES REGS[16] 81 #define CS REGS[17] 82 #define SS REGS[18] 83 #define DS REGS[19] 84 #define BX_SI REGS0[0] 85 #define BX_DI REGS0[1] 86 #define BP_SI REGS0[2] 87 #define BP_DI REGS0[3] 88 89 extern int symrank[6][6]; /* Symbol type/rank matrix */ 90 extern unsigned long PC; /* Current program counter */ 91 extern int segflg; /* Flag: segment override in effect */ 92 extern int objflg; /* Flag: output object as a comment */ 93 94 #define OBJMAX 8 /* Size of the object code buffer */ 95 96 extern unsigned char /* Internal buffer for object code */ 97 objbuf[OBJMAX]; 98 99 extern int objptr; /* Index into the objbuf[] array */ 100 101 extern char ADD[], /* Opcode family mnemonic strings */ 102 OR[], 103 ADC[], 104 SBB[], 105 AND[], 106 SUB[], 107 XOR[], 108 CMP[], 109 NOT[], 110 NEG[], 111 MUL[], 112 DIV[], 113 MOV[], 114 ESC[], 115 TEST[], 116 AMBIG[]; 117 118 extern char *OPFAM[]; /* Indexed mnemonic family table */ 119 extern struct exec HDR; /* Holds the object file's header */ 120 121 #define LOOK_ABS 0 /* Arguments to lookup() function */ 122 #define LOOK_REL 1 123 #define LOOK_LNG 2 124 125 #define TR_STD 0 /* Arguments to mtrans() function */ 126 #define TR_SEG 8 127 128 /* Macro for byte input primitive */ 129 /* #define FETCH(p) ++PC; p = getchar() & 0xff; objbuf[objptr++] = p */ 130 static int _F_; 131 #define FETCH(p) (p)=_F_ = Fetch(); if(_F_<0) {printf("???\n"); return FRV; } 132 #define FRV 133 134 135 /* disfp.c */ 136 _PROTOTYPE(void eshand, (int j )); 137 _PROTOTYPE(void fphand, (int j )); 138 _PROTOTYPE(void inhand, (int j )); 139 140 /* dishand.c */ 141 _PROTOTYPE(void objini, (int j )); 142 _PROTOTYPE(void objout, (void)); 143 _PROTOTYPE(void badseq, (int j, int k )); 144 _PROTOTYPE(void dfhand, (int j )); 145 _PROTOTYPE(void sbhand, (int j )); 146 _PROTOTYPE(void aohand, (int j )); 147 _PROTOTYPE(void sjhand, (int j )); 148 _PROTOTYPE(void imhand, (int j )); 149 _PROTOTYPE(void mvhand, (int j )); 150 _PROTOTYPE(void mshand, (int j )); 151 _PROTOTYPE(void pohand, (int j )); 152 _PROTOTYPE(void cihand, (int j )); 153 _PROTOTYPE(void mihand, (int j )); 154 _PROTOTYPE(void mqhand, (int j )); 155 _PROTOTYPE(void tqhand, (int j )); 156 _PROTOTYPE(void rehand, (int j )); 157 _PROTOTYPE(void mmhand, (int j )); 158 _PROTOTYPE(void srhand, (int j )); 159 _PROTOTYPE(void aahand, (int j )); 160 _PROTOTYPE(void iohand, (int j )); 161 _PROTOTYPE(void ljhand, (int j )); 162 _PROTOTYPE(void mahand, (int j )); 163 _PROTOTYPE(void mjhand, (int j )); 164 165 /* dismain.c */ 166 _PROTOTYPE(void main, (int argc, char **argv )); 167 168 /* distabs.c */ 169 _PROTOTYPE(char *getnam, (int k )); 170 _PROTOTYPE(int lookext, (long off, long loc, char *buf )); 171 _PROTOTYPE(char *lookup, (long addr, int type, int kind, long ext )); 172 _PROTOTYPE(char *mtrans, (int c, int m, int type )); 173 _PROTOTYPE(void mtrunc, (char *a )); 174