Mercurial > hg-old > index.cgi
annotate lwasm/insn_rel.c @ 208:06effa2faea1
Added some info on building gcc6809 to use lwtools
author | lost |
---|---|
date | Tue, 21 Apr 2009 02:57:37 +0000 |
parents | e7309c716059 |
children | bae1e3ecdce1 |
rev | line source |
---|---|
29 | 1 /* |
2 insn_rel.c | |
33
74a3fef7c8d0
Added general addressing modes (immediate, base page, extended, indexed)
lost
parents:
32
diff
changeset
|
3 Copyright © 2009 William Astle |
29 | 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 relative mode instructions | |
23 */ | |
24 | |
32 | 25 #define __insn_rel_c_seen__ |
29 | 26 |
27 #include <stdlib.h> | |
28 | |
29 #include "expr.h" | |
30 #include "lwasm.h" | |
31 #include "instab.h" | |
32 | |
33 OPFUNC(insn_rel8) | |
34 { | |
35 int v; | |
77 | 36 lwasm_expr_term_t *t; |
37 int r; | |
29 | 38 |
39 lwasm_emitop(as, l, instab[opnum].ops[0]); | |
77 | 40 |
195
383caf808674
Allow relative addressing to ignore a # before the operand
lost
parents:
151
diff
changeset
|
41 if (**p == '#') |
383caf808674
Allow relative addressing to ignore a # before the operand
lost
parents:
151
diff
changeset
|
42 (*p)++; |
383caf808674
Allow relative addressing to ignore a # before the operand
lost
parents:
151
diff
changeset
|
43 |
101
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
44 if ((r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST, &v, 0)) < 0) |
77 | 45 v = 0; |
46 else | |
29 | 47 { |
77 | 48 if (as -> passnum == 1) |
49 { | |
50 // need to adjust the expression | |
51 if (l -> exprs[0]) | |
52 { | |
53 t = lwasm_expr_term_create_int(as -> addr + 1); | |
54 lwasm_expr_stack_push(l -> exprs[0], t); | |
55 lwasm_expr_term_free(t); | |
56 t = lwasm_expr_term_create_oper(LWASM_OPER_MINUS); | |
57 lwasm_expr_stack_push(l -> exprs[0], t); | |
58 lwasm_expr_term_free(t); | |
59 } | |
60 else | |
61 { | |
62 l -> exprvals[0] -= as -> addr + 1; | |
63 } | |
64 } | |
29 | 65 } |
77 | 66 if (r == 1 && as -> passnum == 2) |
67 { | |
68 register_error(as, l, 2, "Illegal external or intersegment reference"); | |
69 } | |
29 | 70 if (v < -128 || v > 127) |
71 register_error(as, l, 2, "Byte overflow"); | |
72 lwasm_emit(as, l, v & 0xff); | |
73 } | |
74 | |
77 | 75 /* |
76 External and intersegment references are adjusted for the relative addressing mode | |
77 by adjusting the expression on pass 1 and then treated as absolute references later | |
78 */ | |
29 | 79 OPFUNC(insn_rel16) |
80 { | |
81 int v; | |
77 | 82 int r; |
83 lwasm_expr_term_t *t; | |
29 | 84 |
85 lwasm_emitop(as, l, instab[opnum].ops[0]); | |
86 | |
196
e7309c716059
Allow relative addressing to ignore a # before the operand (16 bit too!)
lost
parents:
195
diff
changeset
|
87 if (**p == '#') |
e7309c716059
Allow relative addressing to ignore a # before the operand (16 bit too!)
lost
parents:
195
diff
changeset
|
88 (*p)++; |
e7309c716059
Allow relative addressing to ignore a # before the operand (16 bit too!)
lost
parents:
195
diff
changeset
|
89 |
101
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
90 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST, &v, 0); |
83 | 91 if (r < 0) |
59 | 92 v = 0; |
77 | 93 else |
94 { | |
95 if (as -> passnum == 1) | |
96 { | |
97 // need to adjust the expression | |
98 if (l -> exprs[0]) | |
99 { | |
83 | 100 t = lwasm_expr_term_create_int(as -> addr + 2); |
77 | 101 lwasm_expr_stack_push(l -> exprs[0], t); |
102 lwasm_expr_term_free(t); | |
103 t = lwasm_expr_term_create_oper(LWASM_OPER_MINUS); | |
104 lwasm_expr_stack_push(l -> exprs[0], t); | |
105 lwasm_expr_term_free(t); | |
106 } | |
107 else | |
108 { | |
109 l -> exprvals[0] -= as -> addr + 2; | |
110 } | |
111 } | |
112 } | |
113 if (as -> passnum == 2 && r == 1) | |
101
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
114 { |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
115 // since we have a reference outside this section, add |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
116 // a subtract of the section base to get the right value |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
117 // upon linking |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
118 t = lwasm_expr_term_create_secbase(); |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
119 lwasm_expr_stack_push(l -> exprs[0], t); |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
120 lwasm_expr_term_free(t); |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
121 t = lwasm_expr_term_create_oper(LWASM_OPER_MINUS); |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
122 lwasm_expr_stack_push(l -> exprs[0], t); |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
123 lwasm_expr_term_free(t); |
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
124 |
77 | 125 l -> relocoff = as -> addr - l -> codeaddr; |
101
f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents:
98
diff
changeset
|
126 } |
29 | 127 lwasm_emit(as, l, (v >> 8) & 0xff); |
128 lwasm_emit(as, l, v & 0xff); | |
129 } |