Mercurial > hg-old > index.cgi
annotate src/pseudo.c @ 78:121bf4a588ea
Checkpointing deployment of non-constant expression handling
author | lost |
---|---|
date | Sat, 10 Jan 2009 05:00:42 +0000 |
parents | c8c772ef5df9 |
children | d0ce3f5f6797 |
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 pseudo.c |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
3 Copyright © 2009 William Astle |
4
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 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
21 This file implements the various pseudo operations. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
22 */ |
0 | 23 |
24 #include <stdlib.h> | |
50 | 25 #include <string.h> |
0 | 26 #include "lwasm.h" |
27 #include "instab.h" | |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
28 #include "expr.h" |
52 | 29 #include "util.h" |
0 | 30 |
52 | 31 extern int lwasm_read_file(asmstate_t *as, const char *filename); |
0 | 32 |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
33 OPFUNC(pseudo_org) |
0 | 34 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
35 int v, r; |
52 | 36 |
74 | 37 if (as -> csect) |
38 { | |
39 register_error(as, l, 1, "ORG not allowed within sections"); | |
40 return; | |
41 } | |
42 | |
52 | 43 if (as -> passnum != 1) |
44 { | |
45 // org is not needed to be processed on pass 2 | |
46 // this will prevent phasing errors for forward references that | |
47 // resolve on the second pass | |
48 // we saved the org address in l -> codeaddr on pass 1 | |
49 as -> addr = l -> codeaddr; | |
50 return; | |
51 } | |
0 | 52 |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
53 if (l -> sym) |
0 | 54 { |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
55 register_error(as, l, 1, "No symbol allowed with ORG"); |
0 | 56 } |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
57 |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
58 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
59 if (r != 0) |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
60 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
61 l -> codeaddr = v; |
49
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
62 l -> addrset = 1; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
63 as -> addr = v; |
0 | 64 } |
65 | |
47
804d7465e0f9
Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents:
4
diff
changeset
|
66 /* |
52 | 67 The operand for include is a string optionally enclosed in " |
68 */ | |
69 OPFUNC(pseudo_include) | |
0 | 70 { |
71 int v1; | |
52 | 72 char *fn; |
57 | 73 |
52 | 74 // only include files on pass 1 |
75 // but make sure local include context is right | |
76 // for the next line... | |
0 | 77 if (as -> passnum != 1) |
52 | 78 { |
57 | 79 as -> context = lwasm_next_context(as); |
0 | 80 return; |
52 | 81 } |
82 | |
83 while (**p && isspace(**p)) | |
84 (*p)++; | |
85 | |
86 if (!**p) | |
0 | 87 { |
52 | 88 register_error(as, l, 1, "Bad file name"); |
0 | 89 return; |
90 } | |
52 | 91 |
92 if (**p == '"') | |
93 { | |
94 // search for ending " | |
95 (*p)++; | |
96 for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++) | |
97 /* do nothing */ ; | |
98 if (*((*p)+v1) != '"') | |
99 { | |
100 register_error(as, l, 1, "Bad file name"); | |
101 return; | |
102 } | |
103 } | |
104 else | |
0 | 105 { |
52 | 106 // search for a space type character |
107 for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++) | |
108 ; | |
0 | 109 } |
52 | 110 |
111 fn = lwasm_alloc(v1 + 1); | |
112 memcpy(fn, *p, v1); | |
113 fn[v1] = '\0'; | |
114 | |
115 // end local label context on include | |
57 | 116 as -> context = lwasm_next_context(as); |
52 | 117 if (lwasm_read_file(as, fn) < 0) |
118 { | |
119 register_error(as, l, 1, "File include error (%s)", fn); | |
120 } | |
121 lwasm_free(fn); | |
0 | 122 } |
123 | |
50 | 124 OPFUNC(pseudo_rmb) |
0 | 125 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
126 int r, v; |
0 | 127 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
128 if (as -> passnum == 1) |
0 | 129 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
130 as -> addr += l -> nocodelen; |
0 | 131 return; |
132 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
133 |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
134 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
135 if (r != 0) |
0 | 136 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
137 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
138 as -> addr += v; |
0 | 139 } |
53 | 140 |
141 OPFUNC(pseudo_rmd) | |
0 | 142 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
143 int r, v; |
0 | 144 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
145 if (as -> passnum == 1) |
0 | 146 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
147 as -> addr += l -> nocodelen; |
0 | 148 return; |
149 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
150 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
151 if (r != 0) |
0 | 152 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
153 v *= 2; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
154 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
155 as -> addr += v; |
0 | 156 } |
157 | |
53 | 158 OPFUNC(pseudo_rmq) |
0 | 159 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
160 int r, v; |
0 | 161 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
162 if (as -> passnum == 1) |
0 | 163 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
164 as -> addr += l -> nocodelen; |
0 | 165 return; |
166 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
167 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
168 if (r != 0) |
0 | 169 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
170 v *= 4; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
171 l -> nocodelen = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
172 as -> addr += v; |
0 | 173 } |
174 | |
53 | 175 OPFUNC(pseudo_zmb) |
0 | 176 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
177 int r, v; |
0 | 178 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
179 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
180 if (r != 0) |
0 | 181 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
182 while (v--) |
53 | 183 lwasm_emit(as, l, 0); |
0 | 184 } |
185 | |
53 | 186 OPFUNC(pseudo_zmd) |
0 | 187 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
188 int r, v; |
0 | 189 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
190 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
191 if (r != 0) |
0 | 192 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
193 v *= 2; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
194 while (v--) |
53 | 195 lwasm_emit(as, l, 0); |
0 | 196 } |
197 | |
53 | 198 OPFUNC(pseudo_zmq) |
199 { | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
200 int r, v; |
53 | 201 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
202 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
203 if (r != 0) |
53 | 204 return; |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
205 v *= 4; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
206 while (v--) |
53 | 207 lwasm_emit(as, l, 0); |
208 } | |
209 | |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
210 OPFUNC(pseudo_end) |
0 | 211 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
212 int r, v; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
213 lwasm_expr_stack_t *s; |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
214 |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
215 |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
216 as -> endseen = 1; |
0 | 217 |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
218 // address only matters for DECB output |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
219 if (as -> outformat != OUTPUT_DECB) |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
220 return; |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
221 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
222 r = lwasm_expr_result2(as, l, p, 0, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
223 if (r != 0) |
0 | 224 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
225 register_error(as, l, 2, "Bad operand"); |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
226 } |
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
227 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
228 v = v & 0xffff; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
229 if (as -> passnum == 2) |
0 | 230 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
231 as -> execaddr = v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
232 l -> symaddr = v; |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
233 l -> addrset = 2; |
0 | 234 } |
54
360d53062bb9
Fixed typo in instruction table and added END directive
lost
parents:
53
diff
changeset
|
235 } |
0 | 236 |
56 | 237 |
238 OPFUNC(pseudo_align) | |
0 | 239 { |
240 int cn; | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
241 int r, v; |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
242 |
56 | 243 if (as -> passnum == 2) |
0 | 244 { |
56 | 245 while (as -> addr < l -> symaddr) |
246 lwasm_emit(as, l, 0); | |
247 return; | |
248 } | |
249 | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
250 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
251 if (r != 0) |
56 | 252 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
253 l -> symaddr = as -> addr; |
0 | 254 return; |
255 } | |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
256 |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
257 if (v < 1) |
56 | 258 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
259 register_error(as, l, 1, "Illegal alignment %d", v); |
56 | 260 return; |
0 | 261 } |
56 | 262 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
263 cn = l -> codeaddr % v; |
56 | 264 if (cn) |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
265 cn = v - cn; |
56 | 266 |
267 while (cn--) | |
268 { | |
269 lwasm_emit(as, l, 0); | |
270 } | |
271 l -> symaddr = as -> addr; | |
0 | 272 } |
56 | 273 |
50 | 274 OPFUNC(pseudo_equ) |
0 | 275 { |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
276 int r, v; |
52 | 277 |
50 | 278 if (l -> sym == NULL) |
0 | 279 { |
50 | 280 register_error(as, l, 1, "No symbol specified"); |
0 | 281 return; |
282 } | |
50 | 283 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
284 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
285 if (r < 0) |
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
286 v = 0; |
63
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
57
diff
changeset
|
287 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
288 l -> symaddr = v & 0xFFFF; |
50 | 289 l -> addrset = 2; |
63
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
57
diff
changeset
|
290 |
78
121bf4a588ea
Checkpointing deployment of non-constant expression handling
lost
parents:
74
diff
changeset
|
291 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE); |
0 | 292 } |
63
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
57
diff
changeset
|
293 |
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
57
diff
changeset
|
294 OPFUNC(pseudo_set) |
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
57
diff
changeset
|
295 { |
64 | 296 int rval; |
297 | |
298 // set MUST run on both passes as the symbol value changes! | |
299 | |
300 if (l -> sym == NULL) | |
301 { | |
302 register_error(as, l, 1, "No symbol specified"); | |
303 return; | |
304 } | |
305 | |
306 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST, &rval) < 0) | |
307 rval = 0; | |
308 | |
309 l -> symaddr = rval & 0xFFFF; | |
310 l -> addrset = 2; | |
311 | |
312 lwasm_register_symbol(as, l, l -> sym, rval, SYMBOL_SET); | |
63
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
57
diff
changeset
|
313 } |
d85ba47b1e8f
Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents:
57
diff
changeset
|
314 |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
315 OPFUNC(pseudo_setdp) |
0 | 316 { |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
317 int rval; |
0 | 318 |
65
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
319 // setdp is needed on both passes |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
320 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST | EXPR_BYTE, &rval) < 0) |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
321 rval = 0; |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
322 |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
323 l -> symaddr = rval & 0xFF; |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
324 l -> addrset = 2; |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
325 |
31d8e85706e7
Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents:
64
diff
changeset
|
326 as -> dpval = rval & 0xFF; |
0 | 327 } |
328 | |
56 | 329 OPFUNC(pseudo_fcc) |
330 { | |
0 | 331 int delim = 0; |
332 | |
56 | 333 delim = **p; |
0 | 334 if (!delim) |
335 { | |
56 | 336 register_error(as, l, 1, "Bad operand"); |
337 return; | |
0 | 338 } |
56 | 339 *p += 1; |
340 while (**p && **p != delim) | |
0 | 341 { |
56 | 342 lwasm_emit(as, l, **p); |
343 (*p)++; | |
0 | 344 } |
56 | 345 if (**p) |
346 (*p)++; | |
0 | 347 } |
348 | |
56 | 349 |
350 OPFUNC(pseudo_fcs) | |
0 | 351 { |
352 int delim = 0; | |
56 | 353 |
354 delim = **p; | |
0 | 355 if (!delim) |
356 { | |
56 | 357 register_error(as, l, 1, "Bad operand"); |
358 return; | |
0 | 359 } |
56 | 360 *p += 1; |
361 while (**p && **p != delim) | |
0 | 362 { |
56 | 363 if (!*((*p) + 1) || *((*p) + 1) == delim) |
364 lwasm_emit(as, l, **p | 0x80); | |
365 else | |
366 lwasm_emit(as, l, **p); | |
367 (*p)++; | |
0 | 368 } |
56 | 369 if (**p) |
370 (*p)++; | |
0 | 371 } |
372 | |
56 | 373 OPFUNC(pseudo_fcn) |
0 | 374 { |
375 int delim = 0; | |
376 | |
56 | 377 delim = **p; |
0 | 378 if (!delim) |
379 { | |
56 | 380 register_error(as, l, 1, "Bad operand"); |
381 return; | |
0 | 382 } |
56 | 383 *p += 1; |
384 while (**p && **p != delim) | |
0 | 385 { |
56 | 386 lwasm_emit(as, l, **p); |
387 (*p)++; | |
0 | 388 } |
56 | 389 if (**p) |
390 (*p)++; | |
391 lwasm_emit(as, l, 0); | |
0 | 392 } |
56 | 393 |
394 OPFUNC(pseudo_fcb) | |
0 | 395 { |
56 | 396 int v1; |
0 | 397 |
398 fcb_again: | |
56 | 399 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST | EXPR_BYTE, &v1) < 0) |
400 return; | |
401 | |
402 lwasm_emit(as, l, v1); | |
403 if (**p == ',') | |
0 | 404 { |
56 | 405 (*p)++; |
0 | 406 goto fcb_again; |
407 } | |
408 } | |
409 | |
56 | 410 OPFUNC(pseudo_fdb) |
0 | 411 { |
56 | 412 int v1; |
0 | 413 |
414 fdb_again: | |
56 | 415 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0) |
416 return; | |
417 | |
418 lwasm_emit(as, l, v1 >> 8); | |
419 lwasm_emit(as, l, v1 & 0xff); | |
420 if (**p == ',') | |
0 | 421 { |
56 | 422 (*p)++; |
0 | 423 goto fdb_again; |
424 } | |
425 } | |
426 | |
56 | 427 OPFUNC(pseudo_fqb) |
0 | 428 { |
56 | 429 int v1; |
430 | |
0 | 431 fqb_again: |
56 | 432 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0) |
433 return; | |
434 | |
435 lwasm_emit(as, l, v1 >> 24); | |
436 lwasm_emit(as, l, v1 >> 16); | |
437 lwasm_emit(as, l, v1 >> 8); | |
438 lwasm_emit(as, l, v1 & 0xff); | |
439 if (**p == ',') | |
0 | 440 { |
56 | 441 (*p)++; |
0 | 442 goto fqb_again; |
443 } | |
444 } | |
445 | |
446 // don't need to do anything if we are executing one of these | |
57 | 447 OPFUNC(pseudo_endc) |
0 | 448 { |
57 | 449 if (as -> skipcond && !(as -> skipmacro)) |
450 { | |
451 as -> skipcount -= 1; | |
452 if (as -> skipcount <= 0) | |
453 { | |
454 as -> skipcond = 0; | |
455 } | |
456 } | |
0 | 457 return; |
458 } | |
459 | |
460 // if "else" executes, we must be going into an "ignore" state | |
57 | 461 OPFUNC(pseudo_else) |
0 | 462 { |
57 | 463 if (as -> skipmacro) |
464 return; | |
465 | |
466 if (as -> skipcond) | |
467 { | |
468 if (as -> skipcount == 1) | |
469 { | |
470 as -> skipcount = 0; | |
471 as -> skipcond = 0; | |
472 } | |
473 return; | |
474 } | |
475 | |
0 | 476 as -> skipcond = 1; |
477 as -> skipcount = 1; | |
478 } | |
479 | |
57 | 480 OPFUNC(pseudo_ifne) |
0 | 481 { |
482 int v1; | |
483 int rval; | |
57 | 484 |
485 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 486 { |
57 | 487 as -> skipcount++; |
488 return; | |
489 } | |
490 | |
491 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); | |
492 if (rval < 0) | |
493 return; | |
494 if (!v1) | |
495 { | |
496 as -> skipcond = 1; | |
497 as -> skipcount = 1; | |
0 | 498 } |
499 } | |
57 | 500 |
501 OPFUNC(pseudo_ifeq) | |
0 | 502 { |
503 int v1; | |
504 int rval; | |
57 | 505 |
506 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 507 { |
57 | 508 as -> skipcount++; |
509 return; | |
0 | 510 } |
57 | 511 |
512 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); | |
513 if (rval < 0) | |
514 return; | |
515 if (v1) | |
0 | 516 { |
57 | 517 as -> skipcond = 1; |
518 as -> skipcount = 1; | |
0 | 519 } |
520 } | |
57 | 521 |
522 OPFUNC(pseudo_iflt) | |
0 | 523 { |
524 int v1; | |
525 int rval; | |
57 | 526 |
527 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 528 { |
57 | 529 as -> skipcount++; |
530 return; | |
0 | 531 } |
57 | 532 |
533 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); | |
534 if (rval < 0) | |
535 return; | |
536 if (v1 >= 0) | |
0 | 537 { |
57 | 538 as -> skipcond = 1; |
539 as -> skipcount = 1; | |
0 | 540 } |
541 } | |
57 | 542 |
543 OPFUNC(pseudo_ifle) | |
0 | 544 { |
545 int v1; | |
546 int rval; | |
57 | 547 |
548 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 549 { |
57 | 550 as -> skipcount++; |
551 return; | |
0 | 552 } |
57 | 553 |
554 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); | |
555 if (rval < 0) | |
556 return; | |
557 if (v1 > 0) | |
0 | 558 { |
57 | 559 as -> skipcond = 1; |
560 as -> skipcount = 1; | |
0 | 561 } |
562 } | |
57 | 563 |
564 OPFUNC(pseudo_ifgt) | |
0 | 565 { |
566 int v1; | |
567 int rval; | |
57 | 568 |
569 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 570 { |
57 | 571 as -> skipcount++; |
572 return; | |
0 | 573 } |
57 | 574 |
575 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); | |
576 if (rval < 0) | |
577 return; | |
578 if (v1 <= 0) | |
0 | 579 { |
57 | 580 as -> skipcond = 1; |
581 as -> skipcount = 1; | |
0 | 582 } |
583 } | |
57 | 584 |
585 OPFUNC(pseudo_ifge) | |
0 | 586 { |
587 int v1; | |
588 int rval; | |
57 | 589 |
590 if (as -> skipcond && !(as -> skipmacro)) | |
0 | 591 { |
57 | 592 as -> skipcount++; |
593 return; | |
0 | 594 } |
57 | 595 |
596 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); | |
597 if (rval < 0) | |
598 return; | |
599 if (v1 < 0) | |
0 | 600 { |
57 | 601 as -> skipcond = 1; |
602 as -> skipcount = 1; | |
0 | 603 } |
604 } | |
605 | |
56 | 606 OPFUNC(pseudo_error) |
0 | 607 { |
56 | 608 register_error(as, l, 1, "User error: %s", *p); |
0 | 609 } |
56 | 610 |
74 | 611 |
612 OPFUNC(pseudo_section) | |
613 { | |
614 sectiontab_t *s; | |
615 char *p2; | |
616 char *sn; | |
617 char *opts; | |
618 | |
619 | |
620 if (as -> outformat != OUTPUT_OBJ) | |
621 { | |
622 register_error(as, l, 1, "Sections only supported for obj target"); | |
623 return; | |
624 } | |
625 | |
626 if (as -> csect) | |
627 { | |
628 as -> csect -> offset = as -> addr; | |
629 as -> csect = NULL; | |
630 } | |
631 | |
632 if (!**p) | |
633 { | |
634 register_error(as, l, 1, "Need section name"); | |
635 return; | |
636 } | |
637 | |
638 for (p2 = *p; *p2 && !isspace(*p2); p2++) | |
639 /* do nothing */ ; | |
640 | |
641 sn = lwasm_alloc(p2 - *p + 1); | |
642 memcpy(sn, *p, p2 - *p); | |
643 sn[p2 - *p] = '\0'; | |
644 | |
645 *p = p2; | |
646 | |
647 opts = strchr(sn, ','); | |
648 if (opts) | |
649 { | |
650 *opts++ = '\0'; | |
651 } | |
652 | |
653 // have we seen the section name already? | |
654 for (s = as -> sections; s; s = s -> next) | |
655 { | |
656 if (!strcmp(s -> name, sn)) | |
657 break; | |
658 } | |
659 | |
660 if (s) | |
661 { | |
662 lwasm_free(sn); | |
663 if (opts) | |
664 { | |
665 register_error(as, l, 1, "Section options can only be specified the first time"); | |
666 return; | |
667 } | |
668 } | |
669 else if (!s) | |
670 { | |
671 s = lwasm_alloc(sizeof(sectiontab_t)); | |
672 s -> name = sn; | |
673 s -> offset = 0; | |
674 s -> flags = 0; | |
675 | |
676 // parse options; only one "bss" | |
677 if (opts && as -> passnum == 1) | |
678 { | |
679 if (!strcasecmp(opts, "bss")) | |
680 { | |
681 s -> flags = SECTION_BSS; | |
682 } | |
683 else | |
684 { | |
685 register_error(as, l, 1, "Unrecognized section option '%s'", opts); | |
686 lwasm_free(s -> name); | |
687 lwasm_free(s); | |
688 return; | |
689 } | |
690 } | |
691 | |
692 s -> next = as -> sections; | |
693 as -> sections = s; | |
694 } | |
695 as -> addr = s -> offset; | |
696 as -> csect = s; | |
697 as -> context = lwasm_next_context(as); | |
698 } | |
699 | |
700 OPFUNC(pseudo_endsection) | |
701 { | |
702 if (as -> outformat != OUTPUT_OBJ) | |
703 { | |
704 register_error(as, l, 1, "Sections only supported for obj target"); | |
705 return; | |
706 } | |
707 | |
708 if (!(as -> csect)) | |
709 { | |
710 register_error(as, l, 1, "ENDSECTION when not in a section"); | |
711 return; | |
712 } | |
713 | |
714 as -> csect -> offset = as -> addr; | |
715 as -> addr = 0; | |
716 as -> csect = 0; | |
717 as -> context = lwasm_next_context(as); | |
718 } |