annotate old-trunk/lwasm/old/insn_indexed.c @ 377:55ed7d06b136

Fixed intersection internal references in object target
author lost@starbug
date Mon, 26 Apr 2010 18:37:06 -0600
parents eb230fa7d28e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 insn_indexed.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWASM.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22 for handling indexed mode instructions
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #define __insn_indexed_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include <ctype.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 #include "instab.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 #include "expr.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 void insn_indexed_aux(asmstate_t *as, lwasm_line_t *l, const char **p, int *b1, int *b2, int *b3)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 struct opvals { char *opstr; int pb; };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 static const char *regs = "X Y U S W PCRPC ";
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 static const struct opvals simpleindex[] =
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 {",--x", 0x83}, {",--y", 0xa3}, {",--u", 0xc3}, {",--s", 0xe3},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 {"a,x", 0x86}, {"a,y", 0xa6}, {"a,u", 0xc6}, {"a,s", 0xe6},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 {"b,x", 0x85}, {"b,y", 0xa5}, {"b,u", 0xc5}, {"b,s", 0xe5},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 {"e,x", 0x87}, {"e,y", 0xa7}, {"e,u", 0xc7}, {"e,s", 0xe7},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 {"f,x", 0x8a}, {"f,y", 0xaa}, {"f,u", 0xca}, {"f,s", 0xea},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 {"d,x", 0x8b}, {"d,y", 0xab}, {"d,u", 0xcb}, {"d,s", 0xed},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 {"w,x", 0x8e}, {"w,y", 0xae}, {"w,u", 0xce}, {"w,s", 0xee},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 {",w", 0x8f}, {",w++", 0xcf}, {",--w", 0xef},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 {"[,x]", 0x94}, {"[,y]", 0xb4}, {"[,u", 0xd4}, {"[,s]", 0xf4},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 {"[,x++]", 0x91}, {"[,y++]", 0xb1}, {"[,u++]", 0xd1}, {"[,s++]", 0xf1},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 {"[,--x]", 0x93}, {"[,--y]", 0xb3}, {"[,--u]", 0xd3}, {"[,--s]", 0xf3},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 {"[a,x]", 0x96}, {"[a,y]", 0xb6}, {"[a,u]", 0xd6}, {"[a,s]", 0xf6},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 {"[b,x]", 0x95}, {"[b,y]", 0xb5}, {"[b,u]", 0xd5}, {"[b,s]", 0xf5},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 {"[e,x]", 0x97}, {"[e,y]", 0xb7}, {"[e,u]", 0xd7}, {"[e,s]", 0xf7},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 {"[f,x]", 0x9a}, {"[f,y]", 0xba}, {"[f,u]", 0xda}, {"[f,s]", 0xfa},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 {"[d,x]", 0x9b}, {"[d,y]", 0xbb}, {"[d,u]", 0xdb}, {"[d,s]", 0xfd},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 {"[w,x]", 0x9e}, {"[w,y]", 0xbe}, {"[w,u]", 0xde}, {"[w,s]", 0xfe},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 {"[,w]", 0x90}, {"[,w++]", 0xd0}, {"[,--w]", 0xf0},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 { "", -1 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 static const char *regs9 = "X Y U S PCRPC ";
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 static const struct opvals simpleindex9[] =
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 {",--x", 0x83}, {",--y", 0xa3}, {",--u", 0xc3}, {",--s", 0xe3},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 {"a,x", 0x86}, {"a,y", 0xa6}, {"a,u", 0xc6}, {"a,s", 0xe6},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 {"b,x", 0x85}, {"b,y", 0xa5}, {"b,u", 0xc5}, {"b,s", 0xe5},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 {"d,x", 0x8b}, {"d,y", 0xab}, {"d,u", 0xcb}, {"d,s", 0xed},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 {"[,x]", 0x94}, {"[,y]", 0xb4}, {"[,u", 0xd4}, {"[,s]", 0xf4},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 {"[,x++]", 0x91}, {"[,y++]", 0xb1}, {"[,u++]", 0xd1}, {"[,s++]", 0xf1},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 {"[,--x]", 0x93}, {"[,--y]", 0xb3}, {"[,--u]", 0xd3}, {"[,--s]", 0xf3},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 {"[a,x]", 0x96}, {"[a,y]", 0xb6}, {"[a,u]", 0xd6}, {"[a,s]", 0xf6},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 {"[b,x]", 0x95}, {"[b,y]", 0xb5}, {"[b,u]", 0xd5}, {"[b,s]", 0xf5},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 {"[d,x]", 0x9b}, {"[d,y]", 0xbb}, {"[d,u]", 0xdb}, {"[d,s]", 0xfd},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 { "", -1 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 char stbuf[25];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 int i, j, rn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 int f8 = 0, f16 = 0, f0 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 int indir = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 int fs8 = 0, fs16 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 const struct opvals *simples;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 const char *reglist;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 if (as -> no6309)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 simples = simpleindex9;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 reglist = regs9;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 simples = simpleindex;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 reglist = regs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 // initialize output bytes
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 *b1 = *b2 = *b3 = -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 // fetch out operand for lookup
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 for (i = 0; i < 24; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 if (*((*p) + i) && !isspace(*((*p) + i)))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 stbuf[i] = *((*p) + i);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 stbuf[i] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 // now look up operand in "simple" table
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 if (!*((*p) + i) || isspace(*((*p) + i)))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 // do simple lookup
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 for (j = 0; simples[j].opstr[0]; j++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 if (!strcasecmp(stbuf, simples[j].opstr))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 if (simples[j].opstr[0])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 *b1 = simples[j].pb;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 (*p) += i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141 // now do the "hard" ones
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143 // is it indirect?
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144 if (**p == '[')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 indir = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 // look for a "," - all indexed modes have a "," except extended indir
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151 rn = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 if ((*p)[i] == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 rn = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 // if no "," and indirect, do extended indir
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162 if (!rn && indir)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164 // extended indir
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165 *b1 = 0x9f;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166 *b2 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
167 *b3 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
168 r = lwasm_expr_result2(as, l, (char **)p, 0, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
169 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
171 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173 if (**p != ']')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
174 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
177 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 if (r == 1 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
182 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
183 l -> relocoff = as -> addr - l -> codeaddr + 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
184 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
185
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
186 *b2 = (v >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
187 *b3 = v & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
188 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
189 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
190
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
191 // if we've previously forced the offset size, make a note of it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
192 if (l -> fsize == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
193 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
194 else if (l -> fsize == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
195 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
196
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
197 if (**p == '<')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
198 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
199 fs8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
200 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
201 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
202 else if (**p == '>')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
203 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
204 fs16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
205 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
206 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
207
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
208 if (**p == '0' && *(*p+1) == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
209 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
210 f0 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
211 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
212
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
213 // now we have to evaluate the expression
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
214 r = lwasm_expr_result2(as, l, (char **)p, 0, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
215 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
216 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
217 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
218 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
219 // now look for a comma; if not present, explode
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
220 if (*(*p)++ != ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
221 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
222 // syntax error; force 0 bit
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
223 *b1 = 00;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
224 l -> fsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
225 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
226 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
227
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
228 // now get the register
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
229 rn = lwasm_lookupreg3(reglist, p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
230 if (rn < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
231 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
232 *b1 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
233 l -> fsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
234 register_error(as, l, 1, "Bad register");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
235 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
236 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
237
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
238 if (indir)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
239 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
240 if (**p != ']')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
241 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
242 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
243 l -> fsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
244 *b1 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
245 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
246 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
247 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
248 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
249 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
250
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
251 // incomplete reference on pass 1 forces 16 bit
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
252 if (r == 1 && as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
253 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
254 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
255 l -> fsize = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
256 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
257
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
258 // incomplete reference on pass 2 needs relocoff set
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
259 if (r == 1 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
260 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
261 l -> relocoff = as -> addr - l -> codeaddr + 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
262 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
263
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
264 // nnnn,W is only 16 bit (or 0 bit)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
265 if (rn == 4)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
266 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
267 if (f8)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
268 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
269 register_error(as, l, 1, "n,W cannot be 8 bit");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
270 l -> fsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
271 *b1 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
272 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
273 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
274 // note: set f16 above for incomplete references
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
275 // also set reloc offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
276 if (!f16 && !f0 && !(as -> pragmas & PRAGMA_NOINDEX0TONONE) && v == 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
277 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
278 if (indir)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
279 *b1 = 0x90;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
280 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
281 *b1 = 0x8f;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
282 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
283 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
284
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
285 if (indir)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
286 *b1 = 0xb0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
287 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
288 *b1 = 0xcf;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
289 *b2 = (v >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
290 *b3 = v & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
291 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
292 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
293
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
294 // set indir to correct bit value
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
295 if (indir) indir = 0x10;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
296
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
297 // PCR? then we have PC relative addressing (like B??, LB??)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
298 if (rn == 5)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
299 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
300 lwasm_expr_term_t *t;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
301 // external references are handled exactly the same as for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
302 // relative addressing modes
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
303 // on pass 1, adjust the expression for a subtraction of the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
304 // current address
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
305
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
306 // need to re-evaluate the expression with "SECTCONST"...
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
307 r = lwasm_expr_result2(as, l, (char **)p, EXPR_SECTCONST | EXPR_REEVAL, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
308 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
309 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
310 if (as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
311 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
312 l -> fsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
313 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
314 f8 = f16 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
315 if (r == 1 && as -> passnum == 1 && !fs8)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
316 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
317 l -> fsize = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
318 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
319 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
320 if (fs8)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
321 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
322 if (fs16)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
323 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
324 if (l -> fsize == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
325 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
326 else if (l -> fsize == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
327 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
328 if (as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
329 v -= as -> addr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
330
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
331 // we have a slight problem here
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
332 // PCR based on current insn loc is really
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
333 // -125 <= offset <= +130 (8 bit offset)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
334 // NOTE: when we are called, we already have the opcode emitted
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
335 // so we only need to worry about the size of the operand
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
336 // hence the 2 and 3 magic numbers below instead of 3 and 4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
337 // (and that also avoids errors with two byte opcodes, etc)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
338 if (f8 || (!f16 && v >= -125 && v <= 130))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
339 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
340 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
341 l -> fsize = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
342 *b1 = indir | 0x8C;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
343 if (as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
344 v -= 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
345 if (v < -128 || v > 127)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
346 register_error(as, l, 2, "Byte overflow");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
347 *b2 = v & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
348 if (r != 0 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
349 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
350 register_error(as, l, 2, "Illegal incomplete reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
351 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
352 goto finpcr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
353 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
354
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
355 // anything else is 16 bit offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
356 // need 16 bit
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
357
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
358 l -> fsize = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
359 *b1 = indir | 0x8D;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
360 if (as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
361 v -= 3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
362 *b2 = (v >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
363 *b3 = v & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
364 if (as -> passnum == 2 && r == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
365 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
366 t = lwasm_expr_term_create_secbase();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
367 lwasm_expr_stack_push(l -> exprs[0], t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
368 lwasm_expr_term_free(t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
369 t = lwasm_expr_term_create_oper(LWASM_OPER_MINUS);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
370 lwasm_expr_stack_push(l -> exprs[0], t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
371 lwasm_expr_term_free(t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
372 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
373
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
374 finpcr:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
375 if (as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
376 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
377 // need to adjust the expression
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
378 if (l -> exprs[0])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
379 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
380 t = lwasm_expr_term_create_int(as -> addr + (f8 ? 2 : 3));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
381 lwasm_expr_stack_push(l -> exprs[0], t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
382 lwasm_expr_term_free(t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
383 t = lwasm_expr_term_create_oper(LWASM_OPER_MINUS);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
384 lwasm_expr_stack_push(l -> exprs[0], t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
385 lwasm_expr_term_free(t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
386 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
387 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
388 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
389 l -> exprvals[0] -= as -> addr + (f8 ? 2 : 3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
390 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
391 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
392 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
393 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
394 if (fs16)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
395 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
396 if (fs8)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
397 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
398
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
399 if (f8 && r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
400 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
401 register_error(as, l, 2, "Illegal external or inter-section reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
402 r = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
403 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
404 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
405
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
406 // constant offset from PC (using PC as regular register :) )
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
407 // FIXME: handle external references intelligently
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
408 if (rn == 6)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
409 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
410 if (f8 || (!f16 && v >= -128 && v <= 127))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
411 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
412 *b1 = indir | 0x8C;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
413 if (v < -128 || v > 127)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
414 register_error(as, l, 2, "Byte overflow");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
415 *b2 = v & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
416 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
417 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
418
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
419 // everything else must be 16 bit
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
420 // need 16 bit
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
421 *b1 = indir | 0x8D;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
422 *b2 = (v >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
423 *b3 = v & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
424 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
425 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
426
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
427 // we only have to deal with x,y,u,s here
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
428 if (!f8 && !f16 && v >= -16 && v <= 15)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
429 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
430 // zero offset going to ,R?
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
431 if (v == 0 && !f0 && !(as -> pragmas & PRAGMA_NOINDEX0TONONE))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
432 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
433 *b1 = rn << 5 | indir | 0x80 | 0x04;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
434 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
435 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
436
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
437 // no 5 bit on indirect
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
438 if (indir)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
439 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
440 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
441 l -> fsize = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
442 goto no5bit;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
443 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
444
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
445 // 5 bit addressing
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
446 *b1 = rn << 5 | (v & 0x1F);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
447 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
448 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
449
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
450 no5bit:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
451 if (f16 || (!f8 && (v < -128 || v > 127)))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
452 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
453 // must be a 16 bit offset here
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
454 *b1 = rn << 5 | indir | 0x80 | 0x09;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
455 *b2 = (v >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
456 *b3 = v & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
457 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
458 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
459
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
460 // if we're here, we have an 8 bit offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
461 // note: cannot get here if incomplete reference detected above
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
462 *b1 = rn << 5 | indir | 0x80 | 0x08;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
463 if (v < -128 || v > 127)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
464 register_error(as, l, 2, "Byte overflow");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
465 *b2 = v & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
466 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
467 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
468
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
469 OPFUNC(insn_indexed)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
470 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
471 int b1, b2, b3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
472
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
473 lwasm_emitop(as, l, instab[opnum].ops[0]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
474
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
475 insn_indexed_aux(as, l, (const char **)p, &b1, &b2, &b3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
476 if (b1 != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
477 lwasm_emit(as, l, b1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
478 if (b2 != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
479 lwasm_emit(as, l, b2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
480 if (b3 != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
481 lwasm_emit(as, l, b3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
482 }