Mercurial > hg-old > index.cgi
annotate lwasm/insn_indexed.c @ 441:7b8d89435f30 3.0
Fixed error with forced size pcr operands
author | lost@l-w.ca |
---|---|
date | Sat, 30 Oct 2010 11:51:25 -0600 |
parents | 2d7255509130 |
children | a9521955554f |
rev | line source |
---|---|
339 | 1 /* |
2 insn_indexed.c | |
3 Copyright © 2009 William Astle | |
4 | |
5 This file is part of LWASM. | |
6 | |
7 LWASM is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 */ | |
20 | |
21 /* | |
22 for handling indexed mode instructions | |
23 */ | |
24 | |
25 #include <config.h> | |
26 | |
27 #include <ctype.h> | |
28 #include <string.h> | |
29 | |
359 | 30 #include <lw_expr.h> |
31 | |
339 | 32 #include "lwasm.h" |
33 #include "instab.h" | |
34 | |
359 | 35 /* |
36 l -> lint: size of operand (0, 1, 2, -1 if not determined) | |
37 l -> pb: actual post byte (from "resolve" stage) or info passed | |
38 forward to the resolve stage (if l -> line is -1); 0x80 is indir | |
39 bits 0-2 are register number | |
40 */ | |
41 void insn_parse_indexed_aux(asmstate_t *as, line_t *l, char **p) | |
339 | 42 { |
43 struct opvals { char *opstr; int pb; }; | |
44 | |
45 static const char *regs = "X Y U S W PCRPC "; | |
46 static const struct opvals simpleindex[] = | |
47 { | |
48 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4}, | |
49 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0}, | |
50 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1}, | |
51 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2}, | |
52 {",--x", 0x83}, {",--y", 0xa3}, {",--u", 0xc3}, {",--s", 0xe3}, | |
53 {"a,x", 0x86}, {"a,y", 0xa6}, {"a,u", 0xc6}, {"a,s", 0xe6}, | |
54 {"b,x", 0x85}, {"b,y", 0xa5}, {"b,u", 0xc5}, {"b,s", 0xe5}, | |
55 {"e,x", 0x87}, {"e,y", 0xa7}, {"e,u", 0xc7}, {"e,s", 0xe7}, | |
56 {"f,x", 0x8a}, {"f,y", 0xaa}, {"f,u", 0xca}, {"f,s", 0xea}, | |
57 {"d,x", 0x8b}, {"d,y", 0xab}, {"d,u", 0xcb}, {"d,s", 0xed}, | |
58 {"w,x", 0x8e}, {"w,y", 0xae}, {"w,u", 0xce}, {"w,s", 0xee}, | |
59 {",w", 0x8f}, {",w++", 0xcf}, {",--w", 0xef}, | |
60 | |
61 {"[,x]", 0x94}, {"[,y]", 0xb4}, {"[,u", 0xd4}, {"[,s]", 0xf4}, | |
62 {"[,x++]", 0x91}, {"[,y++]", 0xb1}, {"[,u++]", 0xd1}, {"[,s++]", 0xf1}, | |
63 {"[,--x]", 0x93}, {"[,--y]", 0xb3}, {"[,--u]", 0xd3}, {"[,--s]", 0xf3}, | |
64 {"[a,x]", 0x96}, {"[a,y]", 0xb6}, {"[a,u]", 0xd6}, {"[a,s]", 0xf6}, | |
65 {"[b,x]", 0x95}, {"[b,y]", 0xb5}, {"[b,u]", 0xd5}, {"[b,s]", 0xf5}, | |
66 {"[e,x]", 0x97}, {"[e,y]", 0xb7}, {"[e,u]", 0xd7}, {"[e,s]", 0xf7}, | |
67 {"[f,x]", 0x9a}, {"[f,y]", 0xba}, {"[f,u]", 0xda}, {"[f,s]", 0xfa}, | |
68 {"[d,x]", 0x9b}, {"[d,y]", 0xbb}, {"[d,u]", 0xdb}, {"[d,s]", 0xfd}, | |
69 {"[w,x]", 0x9e}, {"[w,y]", 0xbe}, {"[w,u]", 0xde}, {"[w,s]", 0xfe}, | |
70 {"[,w]", 0x90}, {"[,w++]", 0xd0}, {"[,--w]", 0xf0}, | |
71 | |
72 { "", -1 } | |
73 }; | |
74 | |
75 static const char *regs9 = "X Y U S PCRPC "; | |
76 static const struct opvals simpleindex9[] = | |
77 { | |
78 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4}, | |
79 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0}, | |
80 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1}, | |
81 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2}, | |
82 {",--x", 0x83}, {",--y", 0xa3}, {",--u", 0xc3}, {",--s", 0xe3}, | |
83 {"a,x", 0x86}, {"a,y", 0xa6}, {"a,u", 0xc6}, {"a,s", 0xe6}, | |
84 {"b,x", 0x85}, {"b,y", 0xa5}, {"b,u", 0xc5}, {"b,s", 0xe5}, | |
85 {"d,x", 0x8b}, {"d,y", 0xab}, {"d,u", 0xcb}, {"d,s", 0xed}, | |
86 | |
87 {"[,x]", 0x94}, {"[,y]", 0xb4}, {"[,u", 0xd4}, {"[,s]", 0xf4}, | |
88 {"[,x++]", 0x91}, {"[,y++]", 0xb1}, {"[,u++]", 0xd1}, {"[,s++]", 0xf1}, | |
89 {"[,--x]", 0x93}, {"[,--y]", 0xb3}, {"[,--u]", 0xd3}, {"[,--s]", 0xf3}, | |
90 {"[a,x]", 0x96}, {"[a,y]", 0xb6}, {"[a,u]", 0xd6}, {"[a,s]", 0xf6}, | |
91 {"[b,x]", 0x95}, {"[b,y]", 0xb5}, {"[b,u]", 0xd5}, {"[b,s]", 0xf5}, | |
92 {"[d,x]", 0x9b}, {"[d,y]", 0xbb}, {"[d,u]", 0xdb}, {"[d,s]", 0xfd}, | |
93 | |
94 { "", -1 } | |
95 }; | |
96 char stbuf[25]; | |
97 int i, j, rn; | |
98 int indir = 0; | |
359 | 99 int f0 = 1; |
339 | 100 const struct opvals *simples; |
101 const char *reglist; | |
359 | 102 lw_expr_t e; |
103 | |
104 if (as -> target == TARGET_6809) | |
339 | 105 { |
106 simples = simpleindex9; | |
107 reglist = regs9; | |
108 } | |
109 else | |
110 { | |
111 simples = simpleindex; | |
112 reglist = regs; | |
113 } | |
114 | |
115 // fetch out operand for lookup | |
116 for (i = 0; i < 24; i++) | |
117 { | |
118 if (*((*p) + i) && !isspace(*((*p) + i))) | |
119 stbuf[i] = *((*p) + i); | |
120 else | |
121 break; | |
122 } | |
123 stbuf[i] = '\0'; | |
124 | |
125 // now look up operand in "simple" table | |
126 if (!*((*p) + i) || isspace(*((*p) + i))) | |
127 { | |
128 // do simple lookup | |
129 for (j = 0; simples[j].opstr[0]; j++) | |
130 { | |
131 if (!strcasecmp(stbuf, simples[j].opstr)) | |
132 break; | |
133 } | |
134 if (simples[j].opstr[0]) | |
135 { | |
359 | 136 l -> pb = simples[j].pb; |
137 l -> lint = 0; | |
339 | 138 (*p) += i; |
139 return; | |
140 } | |
141 } | |
142 | |
143 // now do the "hard" ones | |
144 | |
145 // is it indirect? | |
146 if (**p == '[') | |
147 { | |
148 indir = 1; | |
149 (*p)++; | |
150 } | |
151 | |
152 // look for a "," - all indexed modes have a "," except extended indir | |
153 rn = 0; | |
154 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++) | |
155 { | |
156 if ((*p)[i] == ',') | |
157 { | |
158 rn = 1; | |
159 break; | |
160 } | |
161 } | |
162 | |
163 // if no "," and indirect, do extended indir | |
164 if (!rn && indir) | |
165 { | |
166 // extended indir | |
359 | 167 l -> pb = 0x9f; |
168 e = lwasm_parse_expr(as, p); | |
169 if (!e || **p != ']') | |
339 | 170 { |
359 | 171 lwasm_register_error(as, l, "Bad operand"); |
339 | 172 return; |
173 } | |
382 | 174 lwasm_save_expr(l, 0, e); |
339 | 175 |
176 (*p)++; | |
359 | 177 l -> lint = 2; |
339 | 178 return; |
179 } | |
180 | |
181 if (**p == '<') | |
182 { | |
359 | 183 l -> lint = 1; |
339 | 184 (*p)++; |
185 } | |
186 else if (**p == '>') | |
187 { | |
359 | 188 l -> lint = 2; |
339 | 189 (*p)++; |
190 } | |
191 | |
192 if (**p == '0' && *(*p+1) == ',') | |
193 { | |
194 f0 = 1; | |
195 } | |
196 | |
197 // now we have to evaluate the expression | |
359 | 198 e = lwasm_parse_expr(as, p); |
199 if (!e) | |
339 | 200 { |
359 | 201 lwasm_register_error(as, l, "Bad operand"); |
339 | 202 return; |
203 } | |
359 | 204 lwasm_save_expr(l, 0, e); |
205 | |
339 | 206 // now look for a comma; if not present, explode |
207 if (*(*p)++ != ',') | |
208 { | |
359 | 209 lwasm_register_error(as, l, "Bad operand"); |
339 | 210 return; |
211 } | |
212 | |
213 // now get the register | |
214 rn = lwasm_lookupreg3(reglist, p); | |
215 if (rn < 0) | |
216 { | |
359 | 217 lwasm_register_error(as, l, "Bad register"); |
339 | 218 return; |
219 } | |
220 | |
221 if (indir) | |
222 { | |
223 if (**p != ']') | |
224 { | |
359 | 225 lwasm_register_error(as, l, "Bad operand"); |
339 | 226 return; |
227 } | |
228 else | |
229 (*p)++; | |
230 } | |
231 | |
232 // nnnn,W is only 16 bit (or 0 bit) | |
233 if (rn == 4) | |
234 { | |
359 | 235 if (l -> lint == 1) |
339 | 236 { |
359 | 237 lwasm_register_error(as, l, "n,W cannot be 8 bit"); |
339 | 238 return; |
239 } | |
359 | 240 |
241 if (l -> lint == 2) | |
339 | 242 { |
359 | 243 l -> pb = indir ? 0xb0 : 0xcf; |
244 l -> lint = 2; | |
245 return; | |
246 } | |
247 | |
248 l -> pb = (0x80 * indir) | rn; | |
249 | |
250 /* [,w] and ,w | |
339 | 251 if (indir) |
252 *b1 = 0x90; | |
253 else | |
254 *b1 = 0x8f; | |
359 | 255 */ |
339 | 256 return; |
257 } | |
258 | |
259 // PCR? then we have PC relative addressing (like B??, LB??) | |
260 if (rn == 5) | |
261 { | |
359 | 262 lw_expr_t e1, e2; |
339 | 263 // external references are handled exactly the same as for |
264 // relative addressing modes | |
265 // on pass 1, adjust the expression for a subtraction of the | |
266 // current address | |
371 | 267 // e - (addr + linelen) => e - addr - linelen |
339 | 268 |
371 | 269 e2 = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, l); |
270 e1 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e, e2); | |
271 lw_expr_destroy(e2); | |
272 e2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e1, l -> addr); | |
359 | 273 lw_expr_destroy(e1); |
371 | 274 lwasm_save_expr(l, 0, e2); |
441 | 275 if (l -> lint == 1) |
276 { | |
277 l -> pb = (indir * 0x80) | 0x8C; | |
278 return; | |
279 } | |
280 if (l -> lint == 2) | |
281 { | |
282 l -> pb = (indir * 0x80) | 0x8D; | |
283 return; | |
284 } | |
339 | 285 } |
286 | |
359 | 287 l -> pb = (indir * 0x80) | rn | (f0 * 0x40); |
288 } | |
339 | 289 |
359 | 290 PARSEFUNC(insn_parse_indexed) |
291 { | |
292 l -> lint = -1; | |
293 insn_parse_indexed_aux(as, l, p); | |
294 | |
295 if (l -> lint != -1) | |
339 | 296 { |
359 | 297 l -> len = OPLEN(instab[l -> insn].ops[0]) + l -> lint + 1; |
339 | 298 } |
359 | 299 } |
339 | 300 |
382 | 301 void insn_resolve_indexed_aux(asmstate_t *as, line_t *l, int force, int elen) |
359 | 302 { |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
303 // here, we have an expression which needs to be |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
304 // resolved; the post byte is determined here as well |
382 | 305 lw_expr_t e, e2, e3; |
373 | 306 int pb = -1; |
307 int v; | |
382 | 308 |
309 if (l -> len != -1) | |
310 return; | |
311 | |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
312 e = lwasm_fetch_expr(l, 0); |
382 | 313 if (!lw_expr_istype(e, lw_expr_type_int)) |
314 { | |
315 // temporarily set the instruction length to see if we get a | |
316 // constant for our expression; if so, we can select an instruction | |
317 // size | |
318 e2 = lw_expr_copy(e); | |
319 // magic 2 for 8 bit (post byte + offset) | |
320 l -> len = OPLEN(instab[l -> insn].ops[0]) + elen + 2; | |
321 lwasm_reduce_expr(as, e2); | |
322 // l -> len += 1; | |
323 // e3 = lw_expr_copy(e); | |
324 // lwasm_reduce_expr(as, e3); | |
325 l -> len = -1; | |
326 if (lw_expr_istype(e2, lw_expr_type_int)) | |
327 { | |
328 v = lw_expr_intval(e2); | |
329 // we have a reducible expression here which depends on | |
330 // the size of this instruction | |
331 if (v < -128 || v > 127) | |
332 { | |
333 l -> lint = 2; | |
334 switch (l -> pb & 0x07) | |
335 { | |
336 case 0: | |
337 case 1: | |
338 case 2: | |
339 case 3: | |
415 | 340 pb = 0x89 | ((l -> pb & 0x03) << 5) | (0x10 * (l -> pb & 0x80)); |
382 | 341 break; |
342 | |
343 case 4: // W | |
344 pb = (l -> pb & 0x80) ? 0xD0 : 0xCF; | |
345 break; | |
346 | |
347 case 5: // PCR | |
348 case 6: // PC | |
349 pb = (l -> pb & 0x80) ? 0x9D : 0x8D; | |
350 break; | |
351 } | |
352 | |
353 l -> pb = pb; | |
354 lw_expr_destroy(e2); | |
355 // lw_expr_destroy(e3); | |
356 return; | |
357 } | |
358 else if ((l -> pb & 0x80) || ((l -> pb & 0x07) > 3) || v < -16 || v > 15) | |
359 { | |
360 // if not a 5 bit value, is indirect, or is not X,Y,U,S | |
361 l -> lint = 1; | |
362 switch (l -> pb & 0x07) | |
363 { | |
364 case 0: | |
365 case 1: | |
366 case 2: | |
367 case 3: | |
415 | 368 pb = 0x88 | ((l -> pb & 0x03) << 5) | (0x10 * (l -> pb & 0x80)); |
382 | 369 break; |
370 | |
371 case 4: // W | |
372 // use 16 bit because W doesn't have 8 bit, unless 0 | |
373 if (v == 0 && !(CURPRAGMA(l, PRAGMA_NOINDEX0TONONE) || l -> pb & 0x40)) | |
374 { | |
375 pb = (l -> pb & 0x80) ? 0x90 : 0x8F; | |
376 l -> lint = 0; | |
377 } | |
378 else | |
379 { | |
380 pb = (l -> pb & 0x80) ? 0xD0 : 0xCF; | |
381 l -> lint = 2; | |
382 } | |
383 break; | |
384 | |
385 case 5: // PCR | |
386 case 6: // PC | |
387 pb = (l -> pb & 0x80) ? 0x9C : 0x8C; | |
388 break; | |
389 } | |
390 | |
391 l -> pb = pb; | |
392 return; | |
393 } | |
394 else | |
395 { | |
396 // we have X,Y,U,S and a possible 16 bit here | |
397 l -> lint = 0; | |
398 | |
399 if (v == 0 && !(CURPRAGMA(l, PRAGMA_NOINDEX0TONONE) || l -> pb & 0x40)) | |
400 { | |
401 pb = (l -> pb & 0x03) << 5 | 0x84; | |
402 } | |
403 else | |
404 { | |
405 pb = (l -> pb & 0x03) << 5 | v & 0x1F; | |
406 } | |
407 l -> pb = pb; | |
408 return; | |
409 } | |
410 } | |
411 } | |
412 | |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
413 if (lw_expr_istype(e, lw_expr_type_int)) |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
414 { |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
415 // we know how big it is |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
416 v = lw_expr_intval(e); |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
417 if (v < -128 || v > 127) |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
418 { |
373 | 419 do16bit: |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
420 l -> lint = 2; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
421 switch (l -> pb & 0x07) |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
422 { |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
423 case 0: |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
424 case 1: |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
425 case 2: |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
426 case 3: |
415 | 427 pb = 0x89 | (l -> pb & 0x03) << 5 | (0x10 * (l -> pb & 0x80)); |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
428 break; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
429 |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
430 case 4: // W |
373 | 431 pb = (l -> pb & 0x80) ? 0xD0 : 0xCF; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
432 break; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
433 |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
434 case 5: // PCR |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
435 case 6: // PC |
373 | 436 pb = (l -> pb & 0x80) ? 0x9D : 0x8D; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
437 break; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
438 } |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
439 |
373 | 440 l -> pb = pb; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
441 return; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
442 } |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
443 else if ((l -> pb & 0x80) || ((l -> pb & 0x07) > 3) || v < -16 || v > 15) |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
444 { |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
445 // if not a 5 bit value, is indirect, or is not X,Y,U,S |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
446 l -> lint = 1; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
447 switch (l -> pb & 0x07) |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
448 { |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
449 case 0: |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
450 case 1: |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
451 case 2: |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
452 case 3: |
415 | 453 pb = 0x88 | (l -> pb & 0x03) << 5 | (0x10 * (l -> pb & 0x80)); |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
454 break; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
455 |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
456 case 4: // W |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
457 // use 16 bit because W doesn't have 8 bit, unless 0 |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
458 if (v == 0 && !(CURPRAGMA(l, PRAGMA_NOINDEX0TONONE) || l -> pb & 0x40)) |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
459 { |
373 | 460 pb = (l -> pb & 0x80) ? 0x90 : 0x8F; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
461 l -> lint = 0; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
462 } |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
463 else |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
464 { |
373 | 465 pb = (l -> pb & 0x80) ? 0xD0 : 0xCF; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
466 l -> lint = 2; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
467 } |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
468 break; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
469 |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
470 case 5: // PCR |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
471 case 6: // PC |
373 | 472 pb = (l -> pb & 0x80) ? 0x9C : 0x8C; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
473 break; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
474 } |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
475 |
373 | 476 l -> pb = pb; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
477 return; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
478 } |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
479 else |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
480 { |
382 | 481 // we have X,Y,U,S and a possible 16 bit here |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
482 l -> lint = 0; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
483 |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
484 if (v == 0 && !(CURPRAGMA(l, PRAGMA_NOINDEX0TONONE) || l -> pb & 0x40)) |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
485 { |
382 | 486 pb = (l -> pb & 0x03) << 5 | 0x84; |
487 } | |
488 else | |
489 { | |
373 | 490 pb = (l -> pb & 0x03) << 5 | v & 0x1F; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
491 } |
373 | 492 l -> pb = pb; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
493 return; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
494 } |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
495 } |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
496 else |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
497 { |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
498 // we don't know how big it is |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
499 if (!force) |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
500 return; |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
501 // force 16 bit if we don't know |
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
502 l -> lint = 2; |
373 | 503 goto do16bit; |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
504 } |
339 | 505 } |
506 | |
359 | 507 RESOLVEFUNC(insn_resolve_indexed) |
339 | 508 { |
360
7d91ab7ac7d6
Indexed stage 2; set line structure to track pragmas in effect for that line
lost@starbug
parents:
359
diff
changeset
|
509 if (l -> lint == -1) |
382 | 510 insn_resolve_indexed_aux(as, l, force, 0); |
339 | 511 |
359 | 512 if (l -> lint != -1 && l -> pb != -1) |
513 { | |
514 l -> len = OPLEN(instab[l -> insn].ops[0]) + l -> lint + 1; | |
515 } | |
516 } | |
339 | 517 |
359 | 518 void insn_emit_indexed_aux(asmstate_t *as, line_t *l) |
519 { | |
520 lw_expr_t e; | |
521 | |
522 lwasm_emitop(l, instab[l -> insn].ops[0]); | |
523 lwasm_emitop(l, l -> pb); | |
524 if (l -> lint > 0) | |
525 { | |
526 e = lwasm_fetch_expr(l, 0); | |
527 lwasm_emitexpr(l, e, l -> lint); | |
528 } | |
339 | 529 } |
359 | 530 |
531 EMITFUNC(insn_emit_indexed) | |
532 { | |
533 insn_emit_indexed_aux(as, l); | |
534 } |