as.h (2766B)
1 /* 2 * First 3 bits of flags in segments and symbols are for the 3 * type of segment 4 */ 5 enum symflags { 6 FREG = 1 << 0, 7 FSECT = 1 << 1, 8 FSYM = 1 << 2, 9 FCOMMON = 1 << 3, 10 FEXTERN = 1 << 4, 11 FDEF = 1 << 5, 12 FGLOBAL = 1 << 6, 13 FABS = 1 << 7, 14 }; 15 16 enum common_args { 17 AIMM = 1, 18 ASTR, 19 AREG, 20 ANUMBER, 21 AIMM2, 22 AIMM3, 23 AIMM5, 24 AIMM8, 25 AIMM16, 26 AIMM32, 27 AIMM64, 28 AINDIR, 29 AINDEX, 30 ADIRECT, 31 AREG_OFF, 32 ASYM, 33 AOPT, 34 AREP, 35 AMAX, 36 }; 37 38 enum tokens { 39 EOS = -1, 40 IDEN = 1, 41 NUMBER, 42 REG, 43 STRING, 44 MINUS, 45 SHL, 46 SHR, 47 GE, 48 LE, 49 }; 50 51 #define MAXSYM 63 52 53 typedef struct reloc Reloc; 54 typedef struct ins Ins; 55 typedef struct op Op; 56 typedef struct node Node; 57 typedef void Format(Op *, Node **); 58 59 struct line { 60 char *label; 61 char *op; 62 char *args; 63 }; 64 65 struct ins { 66 int begin, end; 67 char *str; 68 }; 69 70 struct reloc { 71 size_t offset; 72 Symbol *sym; 73 unsigned char flags; 74 unsigned char size; 75 unsigned char nbits; 76 unsigned char shift; 77 }; 78 79 struct op { 80 unsigned char flags; 81 unsigned char size; 82 void (*format)(Op *, Node **); 83 unsigned char *bytes; 84 unsigned char *args; 85 }; 86 87 struct node { 88 unsigned char op; 89 unsigned char addr; 90 struct symbol *sym; 91 struct node *left; 92 struct node *right; 93 }; 94 95 union yylval { 96 TUINT val; 97 Symbol *sym; 98 }; 99 100 /* symbol.c */ 101 extern void cleansecs(void); 102 extern void ibinfmt(void); 103 extern void emit(char *, int); 104 extern Section *defsec(char *, char *); 105 extern Symbol *tmpsym(TUINT); 106 extern void killtmp(void); 107 extern int toobig(Node *, int); 108 extern void dumpstab(char *); 109 extern Symbol *lookup(char *); 110 extern Symbol *deflabel(char *); 111 extern unsigned long long getpc(void); 112 113 /* parser.c */ 114 extern Node **getargs(char *); 115 extern void error(char *, ...); 116 /* Avoid errors in files where stdio is not included */ 117 #ifdef stdin 118 extern int nextline(struct line *); 119 #endif 120 extern void unexpected(void); 121 extern void expect(int); 122 int next(void); 123 #define accept(t) (yytoken == (t) ? next() : 0) 124 extern void regctx(int mode); 125 extern Node *getreg(void); 126 extern Node *operand(char **); 127 extern void addinput(char *); 128 extern int delinput(void); 129 extern int ahead(void); 130 131 /* expr.c */ 132 extern Node *expr(void); 133 extern void deltree(Node *); 134 extern Node *node(int, Node *, Node *); 135 136 /* proc.c */ 137 extern void iarch(void); 138 extern int match(Op *, Node **); 139 extern Node *moperand(void); 140 141 /* ins.c */ 142 extern char *tobytes(TUINT, int, int); 143 144 /* binfmt.c */ 145 extern void writeout(char *); 146 147 /* 148 * Definition of global variables 149 */ 150 extern unsigned long M, S, K; 151 extern short hashmap[]; 152 extern Section *cursec; 153 extern Ins instab[]; 154 extern Op optab[]; 155 extern int pass; 156 extern TUINT maxaddr; 157 extern int endian; 158 extern Symbol *linesym; 159 extern char *infile, *outfile; 160 extern int endpass; 161 extern int yytoken; 162 extern size_t yylen; 163 extern union yylval yylval; 164 extern char yytext[];