1 // Global Definitions for 68000 Assembler 2 // 3 // Author: Paul McKee 4 // ECE492 North Carolina State University 5 // Date: 12/13/86 6 // 7 // Copyright 1990-1991 North Carolina State University. All Rights Reserved. 8 9 // Status values 10 // These status values are 12 bits long with 11 // a severity code in the upper 4 bits 12 #define OK 0x00 13 #define FALSE 0x00 14 #define TRUE 0x01 15 16 // Severe errors 17 #define SEVERE 0x400 18 #define SYNTAX 0x401 19 #define INV_OPCODE 0x402 20 #define INV_ADDR_MODE 0x403 21 #define LABEL_REQUIRED 0x404 22 #define PHASE_ERROR 0x405 23 24 // Errors 25 #define ERROR 0x300 26 #define UNDEFINED 0x301 27 #define DIV_BY_ZERO 0x302 28 #define MULTIPLE_DEFS 0x303 29 #define REG_MULT_DEFS 0x304 30 #define REG_LIST_UNDEF 0x305 31 #define INV_FORWARD_REF 0x306 32 #define INV_LENGTH 0x307 33 34 // Minor errors 35 #define MINOR 0x200 36 #define INV_SIZE_CODE 0x201 37 #define INV_QUICK_CONST 0x202 38 #define INV_VECTOR_NUM 0x203 39 #define INV_BRANCH_DISP 0x204 40 #define INV_DISP 0x205 41 #define INV_ABS_ADDRESS 0x206 42 #define INV_8_BIT_DATA 0x207 43 #define INV_16_BIT_DATA 0x208 44 #define ODD_ADDRESS 0x209 45 #define NOT_REG_LIST 0x20A 46 #define REG_LIST_SPEC 0x20B 47 #define INV_SHIFT_COUNT 0x20C 48 49 // Warnings 50 #define WARNING 0x100 51 #define ASCII_TOO_BIG 0x101 52 #define NUMBER_TOO_BIG 0x102 53 #define INCOMPLETE 0x103 54 55 #define SEVERITY 0xF00 56 57 // The NEWERROR macros updates the error variable var only if the 58 // new error code is more severe than all previous errors. Throughout 59 // ASM this is the standard means of reporting errors. 60 #define NEWERROR(var, code) if ((code & SEVERITY) > var) var = code 61 62 // Symbol table definitions 63 64 // Significant length of a symbol 65 #define SIGCHARS 8 66 67 // Structure for a symbol table entry 68 typedef struct symbolEntry { 69 int value; // 32-bit value of the symbol 70 struct symbolEntry *next; // Pointer to next symbol in linked list 71 char flags; // Flags (see below) 72 char name[SIGCHARS + 1]; // Name 73 } symbolDef; 74 75 // Flag values for the "flags" field of a symbol 76 #define BACKREF 0x01 // Set when the symbol is defined on the 2nd pass 77 #define REDEFINABLE 0x02 // Set for symbols defined by the SET directive 78 #define REG_LIST_SYM 0x04 // Set for symbols defined by the REG directive 79 80 81 // Instruction table definitions 82 83 // Structure to describe one "flavor" of an instruction 84 typedef struct { 85 int source; // Bit masks for the legal source... 86 int dest; // and destination addressing modes 87 int sizes; // Bit mask for the legal sizes 88 void (*exec)(); // Pointer to routine to build the instruction 89 int bytemask; // Skeleton instruction masks for byte size... 90 int wordmask; // word size, ... 91 int longmask; // and long sizes of the instruction 92 } flavor; 93 94 // Structure for the instruction table 95 typedef struct { 96 char *mnemonic; // Mnemonic 97 flavor *flavorPtr; // Pointer to flavor list 98 int flavorCount; // Number of flavors in flavor list 99 int parseFlag; // Should assemble() parse the operands? 100 void (*exec)(); // Routine to be called if parseFlag is FALSE 101 } instruction; 102 103 // Structure for operand descriptors 104 typedef struct { 105 int mode; // Mode number (see below) 106 int data; // Immediate value, displacement, or absolute address 107 int reg; // Principal register number (0-7) 108 int index; // Index register number (0-7 = D0-D7, 8-15 = A0-A7) 109 int size; // Size of index register (WORD or LONG, see below) 110 int backRef; // True if data field is known on first pass 111 } opDescriptor; 112 113 // Addressing mode codes/bitmasks 114 #define DnDirect 0x00001 115 #define AnDirect 0x00002 116 #define AnInd 0x00004 117 #define AnIndPost 0x00008 118 #define AnIndPre 0x00010 119 #define AnIndDisp 0x00020 120 #define AnIndIndex 0x00040 121 #define AbsShort 0x00080 122 #define AbsLong 0x00100 123 #define PCDisp 0x00200 124 #define PCIndex 0x00400 125 #define Immediate 0x00800 126 #define SRDirect 0x01000 127 #define CCRDirect 0x02000 128 #define USPDirect 0x04000 129 #define SFCDirect 0x08000 130 #define DFCDirect 0x10000 131 #define VBRDirect 0x20000 132 133 // Register and operation size codes/bitmasks 134 #define BYTE 1 135 #define WORD 2 136 #define LONG 4 137 #define SHORT 8 138 139 // Prototypes. 140 void processFile(void); 141 void assemble(char *line, int *errorPtr); 142 int pickMask(int size, flavor *flavorPtr, int *errorPtr); 143 void moveq(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 144 void move(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 145 void zeroOp(int mask, int size, int *errorPtr); 146 void oneOp(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 147 void arithReg(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 148 void arithAddr(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 149 void quickMath(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 150 void immedInst(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 151 void movep(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 152 void moves(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 153 void moveReg(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 154 void staticBit(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 155 void movec(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 156 void trap(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 157 void branch(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 158 void immedToCCR(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 159 void immedWord(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 160 void dbcc(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 161 void scc(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 162 void shiftReg(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 163 void exg(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 164 void twoReg(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 165 void oneReg(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 166 void moveUSP(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 167 void link(int mask, int size, opDescriptor *source, opDescriptor *dest, int *errorPtr); 168 void output(int data, int size); 169 int effAddr(opDescriptor *operand); 170 void extWords(opDescriptor *op, int size, int *errorPtr); 171 void org(int size, char *label, char *op, int *errorPtr); 172 void End(int size, char *label, char *op, int *errorPtr); 173 void equ(int size, char *label, char *op, int *errorPtr); 174 void set(int size, char *label, char *op, int *errorPtr); 175 void dc(int size, char *label, char *op, int *errorPtr); 176 char *collect(char *s, char *d); 177 void dcb(int size, char *label, char *op, int *errorPtr); 178 void ds(int size, char *label, char *op, int *errorPtr); 179 void printError(FILE *outFile, int errorCode, int lineNum); 180 char *eval(char *p, int *valuePtr, int *refPtr, int *errorPtr); 181 char *evalNumber(char *p, int *numberPtr, int *refPtr, int *errorPtr); 182 int precedence(int op); 183 int doOp(int val1, int val2, int op, int *result); 184 char *buildCompleteSourceFile(FILE *currentFile, char *currentFileName, FILE *completeFile, int level); 185 char *instLookup(char *p, instruction *(*instPtrPtr), char *sizePtr, int *errorPtr); 186 void initList(char *name); 187 void listLine(void); 188 void listLoc(void); 189 void listObj(int data, int size); 190 void strcap(char *d, char *s); 191 char *skipSpace(char *p); 192 void setFlags(int argc, char *argv[], int *argi); 193 int getoptions(int argc, char *argv[], char *optstring, int *argi); 194 int help(void); 195 void movem(int size, char *label, char *op, int *errorPtr); 196 void reg(int size, char *label, char *op, int *errorPtr); 197 char *evalList(char *p, unsigned short *listPtr, int *errorPtr); 198 void initObj(char *name); 199 void outputObj(int newAddr, int data, int size); 200 int checkValue(int data); 201 void writeObj(void); 202 void finishObj(void); 203 char *opParse(char *p, opDescriptor *d, int *errorPtr); 204 symbolDef *lookup(char *sym, int create, int *errorPtr); 205 int hash(char *symbol); 206 symbolDef *define(char *sym, int value, int check, int *errorPtr); 207