Mercurial > hg-old > index.cgi
comparison src/lwasm.h @ 0:57495da01900
Initial checking of LWASM
author | lost |
---|---|
date | Fri, 03 Oct 2008 02:44:20 +0000 |
parents | |
children | 34568fab6058 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:57495da01900 |
---|---|
1 /* | |
2 * lwasm.h | |
3 * | |
4 * main defs used by the assembler | |
5 * | |
6 */ | |
7 | |
8 | |
9 #ifndef __lwasm_h_seen__ | |
10 #define __lwasm_h_seen__ | |
11 | |
12 #define MAX_OP_LEN 32 | |
13 #define SYMCHAR_START "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
14 #define SYMCHAR "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$." | |
15 | |
16 #define MACROCHAR_START "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
17 #define MACROCHAR "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
18 | |
19 | |
20 #define OPER_INH 0 | |
21 #define OPER_RTOR 1 | |
22 #define OPER_RLIST 2 | |
23 #define OPER_TFM 3 | |
24 #define OPER_IMM8 4 | |
25 #define OPER_IMM16 5 | |
26 #define OPER_IMM32 6 | |
27 #define OPER_DIR 7 | |
28 #define OPER_EXT 8 | |
29 #define OPER_INDEX 9 // indexed with no offset | |
30 #define OPER_DIREXT 10 // used as a placeholder when direct/extended unknown | |
31 #define OPER_BITBIT 11 // bit to bit direct page opers | |
32 #define OPER_REL8 12 | |
33 #define OPER_REL16 13 | |
34 #define OPER_INDEX5 14 // 5 bit offset indexed | |
35 #define OPER_INDEX8 15 // 8 bit offset indexed | |
36 #define OPER_INDEX16 16 // 16 bit offset indexed | |
37 #define OPER_INDEXV 17 // unknown size offset indexed | |
38 #define OPER_EXTIND 18 // extended indirect | |
39 #define OPER_LOGICD 19 // logic on mem, direct mode | |
40 #define OPER_LOGICE 20 // logic on mem, extended mode | |
41 #define OPER_LOGICEI 21 // logic on mem, extended indir mode | |
42 #define OPER_LOGICI 22 // logic on mem, indexed no offset | |
43 #define OPER_LOGICI5 23 // logic on mem, 5 bit indexed offset | |
44 #define OPER_LOGICI8 24 // logic on mem, 8 bit indexed offset | |
45 #define OPER_LOGICI16 25 // logic on mem, 16 bit indexed offset | |
46 #define OPER_LOGICIV 26 // logic on mem, unknown size offset | |
47 | |
48 #define OUTPUT_DECB 0 // DECB multirecord format | |
49 #define OUTPUT_RAW 1 // raw sequence of bytes | |
50 #define OUTPUT_RAWREL 2 // raw but with ORG as a relative offset | |
51 | |
52 enum | |
53 { | |
54 ERR_NONE, // no error | |
55 ERR_BADOP, // bad opcode | |
56 ERR_BADSYM, // illegal symbol | |
57 ERR_DUPSYM, // duplicate symbol definition | |
58 ERR_NOSYM, // symbol required but not present | |
59 ERR_FORWARD, // forward references not permitted here | |
60 ERR_OVERFLOW, // byte overflow | |
61 ERR_PHASE, // phasing error | |
62 ERR_BADOPER, // bad operand | |
63 ERR_SYM, // symbol present where not permitted | |
64 ERR_UNDEF, // undefined symbol | |
65 ERR_OVERFLOW3, // bit number out of range | |
66 ERR_BADEXPR, // invalid expression | |
67 ERR_BADREG, // invalid register | |
68 ERR_BADFN, // bad file name | |
69 ERR_ENDM, // end macro without macro | |
70 ERR_MACRO, // redefined macro | |
71 ERR_NESTNAME, // nested namespace | |
72 ERR_BADCOND, // bad condition | |
73 ERR_USER, // user error | |
74 ERR_PRAGMA, // bad pragma | |
75 | |
76 ERR_MAXERR // last error in the list | |
77 }; | |
78 | |
79 typedef struct sourceline_s sourceline_t; | |
80 | |
81 // structure to keep track of errors | |
82 typedef struct errortab_s errortab_t; | |
83 struct errortab_s { | |
84 int errnum; | |
85 sourceline_t *line; | |
86 errortab_t *next; | |
87 }; | |
88 | |
89 typedef struct macroline_s macroline_t; | |
90 struct macroline_s | |
91 { | |
92 char *linetext; | |
93 macroline_t *next; | |
94 }; | |
95 | |
96 typedef struct macrotab_s macrotab_t; | |
97 struct macrotab_s | |
98 { | |
99 char *name; // name of the macro | |
100 macroline_t *linehead; // start of the macro lines | |
101 macroline_t *linetail; // last line of macro | |
102 macrotab_t *next; | |
103 }; | |
104 | |
105 | |
106 // structure to keep track of each line of the source | |
107 // this also keeps various bits of state about a line | |
108 struct sourceline_s { | |
109 char *sourcefile; // name of the source file | |
110 int lineno; // line number in the source file | |
111 char *symstr; // symbol on this line (if any) | |
112 int opcode; // index to instab for this line | |
113 int opbytes; // actual bytes of opcode | |
114 int postbyte; // post byte for the instruction | |
115 int numcodebytes; // how many code bytes for this line | |
116 unsigned char *codebytes; // actual code for this line | |
117 int codesize; // size of codebytes | |
118 // if minaddr and maxaddr are the same, we know exactly which address | |
119 // we are at so there can be no possible phase error with symbols defined | |
120 // here; these are *code* addresses | |
121 int len; // length of this insn | |
122 int in_macro; // set if it's a macro expansion line | |
123 int code_symloc; | |
124 int addrmode; // addressing mode of this insn | |
125 int addr; // the lowest possible address of this line | |
126 int dpval; // dp value at this point in the code | |
127 int hassym; // is there a symbol on this line | |
128 int addrset; // is this insn a point where the address is *set* (org) | |
129 int isequ; // does this insn set a symbol address (equ)? | |
130 int isset; // is the address setting from a "set"? | |
131 int issetdp; // this insn sets DP | |
132 int symaddr; // address for the symbol (if we're setting one) | |
133 // also used for "setdp" | |
134 int undef; // set if the symbol is undefined | |
135 int p1f16; // if we forced 16 bit on pass 1 so we can force it on pass 2 | |
136 int nocode; // if set, there is no code to output (rmb) | |
137 int notinsn; // if this is not a regular insn (used for formatting output) | |
138 char *line; // the text of the line | |
139 char *opcstr; // opcode string | |
140 char *operstr; // operand string | |
141 char *remainder; // remainder string (whole line if no opcode/operand | |
142 errortab_t *errors; // errors on this line | |
143 sourceline_t *next; // next line | |
144 sourceline_t *prev; // previous line | |
145 macrotab_t *macro; // pointer to macro table entry if this is a macro | |
146 int skipped; // set if the line was skipped | |
147 char *user_error; // user error message | |
148 int macrodef; // set if it's a macro definition line | |
149 }; | |
150 | |
151 // structure to keep the symbol table | |
152 typedef struct symtab_s symtab_t; | |
153 struct symtab_s { | |
154 char *symbol; // symbol name | |
155 sourceline_t *line; // pointer to the line where symbol is defined | |
156 int addr; // address of symbol (-1 for unknown) | |
157 int flags; // flags for symbol | |
158 symtab_t *next; // next symbol | |
159 }; | |
160 | |
161 | |
162 // keep track of current assembler state | |
163 typedef struct { | |
164 int dpval; // current dp value (setdp) | |
165 int addr; // current address | |
166 symtab_t *symbol_table; | |
167 sourceline_t *source_head; | |
168 sourceline_t *source_tail; | |
169 int errorcount; // error count | |
170 int passnum; // which pass are we on? | |
171 const char *infile; // input file | |
172 const char *outfile;// output file | |
173 const char *listfile; // output listing file | |
174 int debug; // debug mode | |
175 int outformat; // output format type: 0 = decb, 1 = raw | |
176 int execaddr; // execution address for the program (END ....) | |
177 macrotab_t *macros; // pointer to macros | |
178 int inmacro; // are we in a macro? | |
179 char *cur_namespace; // current namespace prefix | |
180 int skipcond; // are we skipping a condition? | |
181 int skipcount; // number of endc we need before we stop skipping | |
182 int skipmacro; // are we skipping a macro definition? | |
183 int noelse; // skipped an else? | |
184 int pragmas; // what pragmas are in effect? | |
185 } asmstate_t; | |
186 | |
187 #define PRAGMA_NOINDEX0TONONE 1 | |
188 | |
189 | |
190 #ifndef __lwasm_c_seen__ | |
191 extern int eval_expr(asmstate_t *as, sourceline_t *cl, char **optr, int *val); | |
192 extern void register_error(asmstate_t *as, sourceline_t *cl, int errcode); | |
193 extern int lookupreg3(const char *rlist, char **str); | |
194 extern int lookupreg(const char *reglist, char **str); | |
195 extern void lwasm_read_file(asmstate_t *as, char *fname); | |
196 extern void addcodebyte(asmstate_t *as, sourceline_t *cl, int cb); | |
197 #endif | |
198 | |
199 #define SYMFLAG_NONE 0 | |
200 #define SYMFLAG_SET 1 | |
201 | |
202 #ifndef __symtab_c_seen__ | |
203 #include <stdio.h> | |
204 extern void register_symbol(asmstate_t *as, sourceline_t *cl, char *symstr, int val, int flags); | |
205 extern int lookup_symbol(asmstate_t *as, char *symstr); | |
206 extern void list_symbols(asmstate_t *as, FILE *f); | |
207 #endif | |
208 | |
209 | |
210 #ifndef __index_c_seen__ | |
211 extern int parse_index_expr(asmstate_t *as, sourceline_t *cl, char **optr, int *postbyte, int *opmode, int *v1); | |
212 #endif | |
213 | |
214 #define emit(cb) do { addcodebyte(as, cl, (cb)); } while (0) | |
215 #define emitop(cb) do { if ((cb) > 0xff) addcodebyte(as, cl, (cb)>>8); addcodebyte(as, cl, (cb) & 0xff); } while (0) | |
216 #define errorp1(e) do { if (as -> passnum == 1) register_error(as, cl, (e)); } while (0) | |
217 #define errorp2(e) do { if (as -> passnum == 2) register_error(as, cl, (e)); } while (0) | |
218 | |
219 #endif //__lwasm_h_seen__ |