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