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
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 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <ctype.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
30 #include <lw_expr.h>
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
31
339
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
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
35 /*
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
36 l -> lint: size of operand (0, 1, 2, -1 if not determined)
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
37 l -> pb: actual post byte (from "resolve" stage) or info passed
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
38 forward to the resolve stage (if l -> line is -1); 0x80 is indir
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
39 bits 0-2 are register number
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
40 */
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
41 void insn_parse_indexed_aux(asmstate_t *as, line_t *l, char **p)
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 struct opvals { char *opstr; int pb; };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 static const char *regs = "X Y U S W PCRPC ";
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 static const struct opvals simpleindex[] =
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 {",--x", 0x83}, {",--y", 0xa3}, {",--u", 0xc3}, {",--s", 0xe3},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 {"a,x", 0x86}, {"a,y", 0xa6}, {"a,u", 0xc6}, {"a,s", 0xe6},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 {"b,x", 0x85}, {"b,y", 0xa5}, {"b,u", 0xc5}, {"b,s", 0xe5},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 {"e,x", 0x87}, {"e,y", 0xa7}, {"e,u", 0xc7}, {"e,s", 0xe7},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 {"f,x", 0x8a}, {"f,y", 0xaa}, {"f,u", 0xca}, {"f,s", 0xea},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 {"d,x", 0x8b}, {"d,y", 0xab}, {"d,u", 0xcb}, {"d,s", 0xed},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 {"w,x", 0x8e}, {"w,y", 0xae}, {"w,u", 0xce}, {"w,s", 0xee},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 {",w", 0x8f}, {",w++", 0xcf}, {",--w", 0xef},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 {"[,x]", 0x94}, {"[,y]", 0xb4}, {"[,u", 0xd4}, {"[,s]", 0xf4},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 {"[,x++]", 0x91}, {"[,y++]", 0xb1}, {"[,u++]", 0xd1}, {"[,s++]", 0xf1},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 {"[,--x]", 0x93}, {"[,--y]", 0xb3}, {"[,--u]", 0xd3}, {"[,--s]", 0xf3},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 {"[a,x]", 0x96}, {"[a,y]", 0xb6}, {"[a,u]", 0xd6}, {"[a,s]", 0xf6},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 {"[b,x]", 0x95}, {"[b,y]", 0xb5}, {"[b,u]", 0xd5}, {"[b,s]", 0xf5},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 {"[e,x]", 0x97}, {"[e,y]", 0xb7}, {"[e,u]", 0xd7}, {"[e,s]", 0xf7},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 {"[f,x]", 0x9a}, {"[f,y]", 0xba}, {"[f,u]", 0xda}, {"[f,s]", 0xfa},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 {"[d,x]", 0x9b}, {"[d,y]", 0xbb}, {"[d,u]", 0xdb}, {"[d,s]", 0xfd},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 {"[w,x]", 0x9e}, {"[w,y]", 0xbe}, {"[w,u]", 0xde}, {"[w,s]", 0xfe},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 {"[,w]", 0x90}, {"[,w++]", 0xd0}, {"[,--w]", 0xf0},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 { "", -1 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 static const char *regs9 = "X Y U S PCRPC ";
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 static const struct opvals simpleindex9[] =
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 {",x", 0x84}, {",y", 0xa4}, {",u", 0xc4}, {",s", 0xe4},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 {",x+", 0x80}, {",y+", 0xa0}, {",u+", 0xc0}, {",s+", 0xe0},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 {",x++", 0x81}, {",y++", 0xa1}, {",u++", 0xc1}, {",s++", 0xe1},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 {",-x", 0x82}, {",-y", 0xa2}, {",-u", 0xc2}, {",-s", 0xe2},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 {",--x", 0x83}, {",--y", 0xa3}, {",--u", 0xc3}, {",--s", 0xe3},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 {"a,x", 0x86}, {"a,y", 0xa6}, {"a,u", 0xc6}, {"a,s", 0xe6},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 {"b,x", 0x85}, {"b,y", 0xa5}, {"b,u", 0xc5}, {"b,s", 0xe5},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 {"d,x", 0x8b}, {"d,y", 0xab}, {"d,u", 0xcb}, {"d,s", 0xed},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 {"[,x]", 0x94}, {"[,y]", 0xb4}, {"[,u", 0xd4}, {"[,s]", 0xf4},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 {"[,x++]", 0x91}, {"[,y++]", 0xb1}, {"[,u++]", 0xd1}, {"[,s++]", 0xf1},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 {"[,--x]", 0x93}, {"[,--y]", 0xb3}, {"[,--u]", 0xd3}, {"[,--s]", 0xf3},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 {"[a,x]", 0x96}, {"[a,y]", 0xb6}, {"[a,u]", 0xd6}, {"[a,s]", 0xf6},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 {"[b,x]", 0x95}, {"[b,y]", 0xb5}, {"[b,u]", 0xd5}, {"[b,s]", 0xf5},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 {"[d,x]", 0x9b}, {"[d,y]", 0xbb}, {"[d,u]", 0xdb}, {"[d,s]", 0xfd},
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 { "", -1 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 char stbuf[25];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 int i, j, rn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 int indir = 0;
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
99 int f0 = 1;
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 const struct opvals *simples;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 const char *reglist;
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
102 lw_expr_t e;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
103
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
104 if (as -> target == TARGET_6809)
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 simples = simpleindex9;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 reglist = regs9;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 simples = simpleindex;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 reglist = regs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 // fetch out operand for lookup
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 for (i = 0; i < 24; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 if (*((*p) + i) && !isspace(*((*p) + i)))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 stbuf[i] = *((*p) + i);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 stbuf[i] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 // now look up operand in "simple" table
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 if (!*((*p) + i) || isspace(*((*p) + i)))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 // do simple lookup
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 for (j = 0; simples[j].opstr[0]; j++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 if (!strcasecmp(stbuf, simples[j].opstr))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 if (simples[j].opstr[0])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
136 l -> pb = simples[j].pb;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
137 l -> lint = 0;
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 (*p) += i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143 // now do the "hard" ones
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 // is it indirect?
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 if (**p == '[')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 indir = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 // look for a "," - all indexed modes have a "," except extended indir
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153 rn = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 if ((*p)[i] == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158 rn = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 // if no "," and indirect, do extended indir
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164 if (!rn && indir)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166 // extended indir
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
167 l -> pb = 0x9f;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
168 e = lwasm_parse_expr(as, p);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
169 if (!e || **p != ']')
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
171 lwasm_register_error(as, l, "Bad operand");
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173 }
382
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
174 lwasm_save_expr(l, 0, e);
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 (*p)++;
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
177 l -> lint = 2;
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 if (**p == '<')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
182 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
183 l -> lint = 1;
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
184 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
185 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
186 else if (**p == '>')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
187 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
188 l -> lint = 2;
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
189 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
190 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
191
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
192 if (**p == '0' && *(*p+1) == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
193 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
194 f0 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
195 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
196
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
197 // now we have to evaluate the expression
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
198 e = lwasm_parse_expr(as, p);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
199 if (!e)
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
200 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
201 lwasm_register_error(as, l, "Bad operand");
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
202 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
203 }
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
204 lwasm_save_expr(l, 0, e);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
205
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
206 // now look for a comma; if not present, explode
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
207 if (*(*p)++ != ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
208 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
209 lwasm_register_error(as, l, "Bad operand");
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
210 return;
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 get the register
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
214 rn = lwasm_lookupreg3(reglist, p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
215 if (rn < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
216 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
217 lwasm_register_error(as, l, "Bad register");
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
218 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
219 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
220
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
221 if (indir)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
222 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
223 if (**p != ']')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
224 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
225 lwasm_register_error(as, l, "Bad operand");
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
226 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
227 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
228 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
229 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
230 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
231
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
232 // nnnn,W is only 16 bit (or 0 bit)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
233 if (rn == 4)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
234 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
235 if (l -> lint == 1)
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
236 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
237 lwasm_register_error(as, l, "n,W cannot be 8 bit");
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
238 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
239 }
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
240
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
241 if (l -> lint == 2)
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
242 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
243 l -> pb = indir ? 0xb0 : 0xcf;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
244 l -> lint = 2;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
245 return;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
246 }
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
247
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
248 l -> pb = (0x80 * indir) | rn;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
249
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
250 /* [,w] and ,w
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
251 if (indir)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
252 *b1 = 0x90;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
253 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
254 *b1 = 0x8f;
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
255 */
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
256 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
257 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
258
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
259 // PCR? then we have PC relative addressing (like B??, LB??)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
260 if (rn == 5)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
261 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
262 lw_expr_t e1, e2;
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
263 // external references are handled exactly the same as for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
264 // relative addressing modes
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
265 // on pass 1, adjust the expression for a subtraction of the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
266 // current address
371
9c24d9d485b9 Much bugfixing
lost@starbug
parents: 360
diff changeset
267 // e - (addr + linelen) => e - addr - linelen
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
268
371
9c24d9d485b9 Much bugfixing
lost@starbug
parents: 360
diff changeset
269 e2 = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, l);
9c24d9d485b9 Much bugfixing
lost@starbug
parents: 360
diff changeset
270 e1 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e, e2);
9c24d9d485b9 Much bugfixing
lost@starbug
parents: 360
diff changeset
271 lw_expr_destroy(e2);
9c24d9d485b9 Much bugfixing
lost@starbug
parents: 360
diff changeset
272 e2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e1, l -> addr);
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
273 lw_expr_destroy(e1);
371
9c24d9d485b9 Much bugfixing
lost@starbug
parents: 360
diff changeset
274 lwasm_save_expr(l, 0, e2);
441
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
275 if (l -> lint == 1)
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
276 {
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
277 l -> pb = (indir * 0x80) | 0x8C;
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
278 return;
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
279 }
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
280 if (l -> lint == 2)
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
281 {
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
282 l -> pb = (indir * 0x80) | 0x8D;
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
283 return;
7b8d89435f30 Fixed error with forced size pcr operands
lost@l-w.ca
parents: 415
diff changeset
284 }
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
285 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
286
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
287 l -> pb = (indir * 0x80) | rn | (f0 * 0x40);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
288 }
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
289
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
290 PARSEFUNC(insn_parse_indexed)
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
291 {
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
292 l -> lint = -1;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
293 insn_parse_indexed_aux(as, l, p);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
294
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
295 if (l -> lint != -1)
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
296 {
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
297 l -> len = OPLEN(instab[l -> insn].ops[0]) + l -> lint + 1;
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
298 }
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
299 }
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
300
382
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
301 void insn_resolve_indexed_aux(asmstate_t *as, line_t *l, int force, int elen)
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
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
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
305 lw_expr_t e, e2, e3;
373
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
306 int pb = -1;
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
307 int v;
382
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
308
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
309 if (l -> len != -1)
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
310 return;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
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
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
313 if (!lw_expr_istype(e, lw_expr_type_int))
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
314 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
315 // temporarily set the instruction length to see if we get a
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
316 // constant for our expression; if so, we can select an instruction
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
317 // size
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
318 e2 = lw_expr_copy(e);
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
319 // magic 2 for 8 bit (post byte + offset)
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
320 l -> len = OPLEN(instab[l -> insn].ops[0]) + elen + 2;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
321 lwasm_reduce_expr(as, e2);
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
322 // l -> len += 1;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
323 // e3 = lw_expr_copy(e);
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
324 // lwasm_reduce_expr(as, e3);
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
325 l -> len = -1;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
326 if (lw_expr_istype(e2, lw_expr_type_int))
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
327 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
328 v = lw_expr_intval(e2);
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
329 // we have a reducible expression here which depends on
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
330 // the size of this instruction
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
331 if (v < -128 || v > 127)
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
332 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
333 l -> lint = 2;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
334 switch (l -> pb & 0x07)
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
335 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
336 case 0:
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
337 case 1:
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
338 case 2:
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
339 case 3:
415
2d7255509130 Fixed error with indexed posbytes
lost@l-w.ca
parents: 382
diff changeset
340 pb = 0x89 | ((l -> pb & 0x03) << 5) | (0x10 * (l -> pb & 0x80));
382
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
341 break;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
342
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
343 case 4: // W
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
344 pb = (l -> pb & 0x80) ? 0xD0 : 0xCF;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
345 break;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
346
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
347 case 5: // PCR
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
348 case 6: // PC
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
349 pb = (l -> pb & 0x80) ? 0x9D : 0x8D;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
350 break;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
351 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
352
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
353 l -> pb = pb;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
354 lw_expr_destroy(e2);
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
355 // lw_expr_destroy(e3);
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
356 return;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
357 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
358 else if ((l -> pb & 0x80) || ((l -> pb & 0x07) > 3) || v < -16 || v > 15)
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
359 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
360 // if not a 5 bit value, is indirect, or is not X,Y,U,S
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
361 l -> lint = 1;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
362 switch (l -> pb & 0x07)
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
363 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
364 case 0:
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
365 case 1:
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
366 case 2:
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
367 case 3:
415
2d7255509130 Fixed error with indexed posbytes
lost@l-w.ca
parents: 382
diff changeset
368 pb = 0x88 | ((l -> pb & 0x03) << 5) | (0x10 * (l -> pb & 0x80));
382
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
369 break;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
370
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
371 case 4: // W
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
372 // use 16 bit because W doesn't have 8 bit, unless 0
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
373 if (v == 0 && !(CURPRAGMA(l, PRAGMA_NOINDEX0TONONE) || l -> pb & 0x40))
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
374 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
375 pb = (l -> pb & 0x80) ? 0x90 : 0x8F;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
376 l -> lint = 0;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
377 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
378 else
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
379 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
380 pb = (l -> pb & 0x80) ? 0xD0 : 0xCF;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
381 l -> lint = 2;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
382 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
383 break;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
384
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
385 case 5: // PCR
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
386 case 6: // PC
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
387 pb = (l -> pb & 0x80) ? 0x9C : 0x8C;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
388 break;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
389 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
390
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
391 l -> pb = pb;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
392 return;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
393 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
394 else
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
395 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
396 // we have X,Y,U,S and a possible 16 bit here
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
397 l -> lint = 0;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
398
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
399 if (v == 0 && !(CURPRAGMA(l, PRAGMA_NOINDEX0TONONE) || l -> pb & 0x40))
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
400 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
401 pb = (l -> pb & 0x03) << 5 | 0x84;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
402 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
403 else
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
404 {
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
405 pb = (l -> pb & 0x03) << 5 | v & 0x1F;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
406 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
407 l -> pb = pb;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
408 return;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
409 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
410 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
411 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
2d7255509130 Fixed error with indexed posbytes
lost@l-w.ca
parents: 382
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
2d7255509130 Fixed error with indexed posbytes
lost@l-w.ca
parents: 382
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
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
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
486 pb = (l -> pb & 0x03) << 5 | 0x84;
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
487 }
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
488 else
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
489 {
373
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
8f9d72cfb897 Bugfixes for indexed addressing modes
lost@starbug
parents: 371
diff changeset
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
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
505 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
506
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
507 RESOLVEFUNC(insn_resolve_indexed)
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
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
eacdae8a1575 Various bugfixes
lost@starbug
parents: 373
diff changeset
510 insn_resolve_indexed_aux(as, l, force, 0);
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
511
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
512 if (l -> lint != -1 && l -> pb != -1)
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
513 {
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
514 l -> len = OPLEN(instab[l -> insn].ops[0]) + l -> lint + 1;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
515 }
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
516 }
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
517
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
518 void insn_emit_indexed_aux(asmstate_t *as, line_t *l)
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
519 {
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
520 lw_expr_t e;
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
521
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
522 lwasm_emitop(l, instab[l -> insn].ops[0]);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
523 lwasm_emitop(l, l -> pb);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
524 if (l -> lint > 0)
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
525 {
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
526 e = lwasm_fetch_expr(l, 0);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
527 lwasm_emitexpr(l, e, l -> lint);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
528 }
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
529 }
359
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
530
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
531 EMITFUNC(insn_emit_indexed)
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
532 {
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
533 insn_emit_indexed_aux(as, l);
f50a54d0293a Indexed part 1
lost@starbug
parents: 339
diff changeset
534 }