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