comparison src/pseudo.c @ 103:26c058fa0bc1

Fixed up some issues with pseudo ops and object target
author lost
date Fri, 23 Jan 2009 05:48:55 +0000
parents 3dcb12a6f4ff
children 2ba8f9ef1417
comparison
equal deleted inserted replaced
102:dbf1b926c2f1 103:26c058fa0bc1
128 if (as -> passnum == 2) 128 if (as -> passnum == 2)
129 { 129 {
130 as -> addr += l -> nocodelen; 130 as -> addr += l -> nocodelen;
131 return; 131 return;
132 } 132 }
133 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, -1); 133 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, -1);
134 if (r != 0) 134 if (r != 0)
135 return; 135 return;
136 l -> nocodelen = v; 136 l -> nocodelen = v;
137 as -> addr += v; 137 as -> addr += v;
138 } 138 }
144 if (as -> passnum == 2) 144 if (as -> passnum == 2)
145 { 145 {
146 as -> addr += l -> nocodelen; 146 as -> addr += l -> nocodelen;
147 return; 147 return;
148 } 148 }
149 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 149 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
150 if (r != 0) 150 if (r != 0)
151 return; 151 return;
152 v *= 2; 152 v *= 2;
153 l -> nocodelen = v; 153 l -> nocodelen = v;
154 as -> addr += v; 154 as -> addr += v;
161 if (as -> passnum == 2) 161 if (as -> passnum == 2)
162 { 162 {
163 as -> addr += l -> nocodelen; 163 as -> addr += l -> nocodelen;
164 return; 164 return;
165 } 165 }
166 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 166 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
167 if (r != 0) 167 if (r != 0)
168 return; 168 return;
169 v *= 4; 169 v *= 4;
170 l -> nocodelen = v; 170 l -> nocodelen = v;
171 as -> addr += v; 171 as -> addr += v;
173 173
174 OPFUNC(pseudo_zmb) 174 OPFUNC(pseudo_zmb)
175 { 175 {
176 int r, v; 176 int r, v;
177 177
178 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 178 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
179 if (r != 0) 179 if (r != 0)
180 return; 180 return;
181 while (v--) 181 while (v--)
182 lwasm_emit(as, l, 0); 182 lwasm_emit(as, l, 0);
183 } 183 }
184 184
185 OPFUNC(pseudo_zmd) 185 OPFUNC(pseudo_zmd)
186 { 186 {
187 int r, v; 187 int r, v;
188 188
189 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 189 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
190 if (r != 0) 190 if (r != 0)
191 return; 191 return;
192 v *= 2; 192 v *= 2;
193 while (v--) 193 while (v--)
194 lwasm_emit(as, l, 0); 194 lwasm_emit(as, l, 0);
196 196
197 OPFUNC(pseudo_zmq) 197 OPFUNC(pseudo_zmq)
198 { 198 {
199 int r, v; 199 int r, v;
200 200
201 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 201 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
202 if (r != 0) 202 if (r != 0)
203 return; 203 return;
204 v *= 4; 204 v *= 4;
205 while (v--) 205 while (v--)
206 lwasm_emit(as, l, 0); 206 lwasm_emit(as, l, 0);
244 while (as -> addr < l -> symaddr) 244 while (as -> addr < l -> symaddr)
245 lwasm_emit(as, l, 0); 245 lwasm_emit(as, l, 0);
246 return; 246 return;
247 } 247 }
248 248
249 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 249 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
250 if (r != 0) 250 if (r != 0)
251 { 251 {
252 l -> symaddr = as -> addr; 252 l -> symaddr = as -> addr;
253 return; 253 return;
254 } 254 }
278 { 278 {
279 register_error(as, l, 1, "No symbol specified"); 279 register_error(as, l, 1, "No symbol specified");
280 return; 280 return;
281 } 281 }
282 282
283 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 283 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
284 if (r < 0) 284 if (r < 0)
285 v = 0; 285 v = 0;
286 286
287 l -> symaddr = v & 0xFFFF; 287 l -> symaddr = v & 0xFFFF;
288 l -> addrset = 2; 288 l -> addrset = 2;
302 { 302 {
303 register_error(as, l, 1, "No symbol specified"); 303 register_error(as, l, 1, "No symbol specified");
304 return; 304 return;
305 } 305 }
306 306
307 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 307 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
308 if (r < 0) 308 if (r < 0)
309 v = 0; 309 v = 0;
310 310
311 l -> symaddr = v & 0xFFFF; 311 l -> symaddr = v & 0xFFFF;
312 l -> addrset = 2; 312 l -> addrset = 2;
323 register_error(as, l, 1, "SETDP not permitted with OBJ target"); 323 register_error(as, l, 1, "SETDP not permitted with OBJ target");
324 return; 324 return;
325 } 325 }
326 326
327 // setdp is needed on both passes; must resolve to a constant on pass 1 327 // setdp is needed on both passes; must resolve to a constant on pass 1
328 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0); 328 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
329 if (r != 0) 329 if (r != 0)
330 return; 330 return;
331 331
332 if (v < -127 || v > 255) 332 if (v < -127 || v > 255)
333 { 333 {
437 437
438 // FIXME: handle external references in an intelligent way 438 // FIXME: handle external references in an intelligent way
439 OPFUNC(pseudo_fdb) 439 OPFUNC(pseudo_fdb)
440 { 440 {
441 int r, v; 441 int r, v;
442 int extseen = 0;
443 char *p1;
442 444
443 fdb_again: 445 fdb_again:
446 p1 = *p;
444 r = lwasm_expr_result2(as, l, p, 0, &v, -1); 447 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
445 if (r < 0) 448 if (r < 0)
446 return; 449 return;
447 450
448 if (r > 0) 451 if (r > 0 && extseen == 1)
449 { 452 {
450 register_error(as, l, 2, "Illegal external or inter-segment reference"); 453 register_error(as, l, 2, "Illegal external or inter-segment reference (only 1 per FDB line)");
451 v = 0; 454 v = 0;
455 }
456 else if (r > 0)
457 {
458 l -> relocoff = as -> addr - l -> codeaddr;
459 *p = p1;
460 r = lwasm_expr_result2(as, l, p, 0, &v, 0);
452 } 461 }
453 462
454 lwasm_emit(as, l, v >> 8); 463 lwasm_emit(as, l, v >> 8);
455 lwasm_emit(as, l, v & 0xff); 464 lwasm_emit(as, l, v & 0xff);
456 if (**p == ',') 465 if (**p == ',')
530 { 539 {
531 as -> skipcount++; 540 as -> skipcount++;
532 return; 541 return;
533 } 542 }
534 543
535 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); 544 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
536 if (rval != 0) 545 if (rval != 0)
537 return; 546 return;
538 if (!v1) 547 if (!v1)
539 { 548 {
540 as -> skipcond = 1; 549 as -> skipcond = 1;
551 { 560 {
552 as -> skipcount++; 561 as -> skipcount++;
553 return; 562 return;
554 } 563 }
555 564
556 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); 565 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
557 if (rval != 0) 566 if (rval != 0)
558 return; 567 return;
559 if (v1) 568 if (v1)
560 { 569 {
561 as -> skipcond = 1; 570 as -> skipcond = 1;
572 { 581 {
573 as -> skipcount++; 582 as -> skipcount++;
574 return; 583 return;
575 } 584 }
576 585
577 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); 586 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
578 if (rval != 0) 587 if (rval != 0)
579 return; 588 return;
580 if (v1 >= 0) 589 if (v1 >= 0)
581 { 590 {
582 as -> skipcond = 1; 591 as -> skipcond = 1;
593 { 602 {
594 as -> skipcount++; 603 as -> skipcount++;
595 return; 604 return;
596 } 605 }
597 606
598 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); 607 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
599 if (rval != 0) 608 if (rval != 0)
600 return; 609 return;
601 if (v1 > 0) 610 if (v1 > 0)
602 { 611 {
603 as -> skipcond = 1; 612 as -> skipcond = 1;
614 { 623 {
615 as -> skipcount++; 624 as -> skipcount++;
616 return; 625 return;
617 } 626 }
618 627
619 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); 628 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
620 if (rval != 0) 629 if (rval != 0)
621 return; 630 return;
622 if (v1 <= 0) 631 if (v1 <= 0)
623 { 632 {
624 as -> skipcond = 1; 633 as -> skipcond = 1;
635 { 644 {
636 as -> skipcount++; 645 as -> skipcount++;
637 return; 646 return;
638 } 647 }
639 648
640 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0); 649 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
641 if (rval != 0) 650 if (rval != 0)
642 return; 651 return;
643 if (v1 < 0) 652 if (v1 < 0)
644 { 653 {
645 as -> skipcond = 1; 654 as -> skipcond = 1;