annotate src/pseudo.c @ 74:c8c772ef5df9

Checkpointing object target implementation
author lost
date Thu, 08 Jan 2009 01:18:40 +0000
parents 31d8e85706e7
children 121bf4a588ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
1 /*
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
2 pseudo.c
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
3 Copyright © 2009 William Astle
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
5 This file is part of LWASM.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
6
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
8 terms of the GNU General Public License as published by the Free Software
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
10 version.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
11
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
15 more details.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
16
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
17 You should have received a copy of the GNU General Public License along with
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
19
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
20
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
21 This file implements the various pseudo operations.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
22 */
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 #include <stdlib.h>
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
25 #include <string.h>
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26 #include "lwasm.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
27 #include "instab.h"
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
28 #include "expr.h"
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
29 #include "util.h"
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
31 extern int lwasm_read_file(asmstate_t *as, const char *filename);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
33 OPFUNC(pseudo_org)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
34 {
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
35 int rval;
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
36 lwasm_expr_stack_t *s;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
37
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
38 if (as -> csect)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
39 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
40 register_error(as, l, 1, "ORG not allowed within sections");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
41 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
42 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
43
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
44 if (as -> passnum != 1)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
45 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
46 // org is not needed to be processed on pass 2
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
47 // this will prevent phasing errors for forward references that
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
48 // resolve on the second pass
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
49 // we saved the org address in l -> codeaddr on pass 1
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
50 as -> addr = l -> codeaddr;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
51 return;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
52 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
53
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
54 if (l -> sym)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
55 {
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
56 register_error(as, l, 1, "No symbol allowed with ORG");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
57 }
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
58 s = lwasm_evaluate_expr(as, l, *p, NULL);
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
59 if (!s)
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
60 {
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
61 register_error(as, l, 1, "Bad expression");
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
62 return;
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
63 }
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
64 if (!lwasm_expr_is_constant(s))
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
65 {
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
66 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
67 lwasm_expr_stack_free(s);
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
68 return;
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
69 }
49
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
70 rval = lwasm_expr_get_value(s) & 0xffff;
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
71 lwasm_expr_stack_free(s);
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
72 l -> codeaddr = rval;
49
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
73 l -> addrset = 1;
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
74 as -> addr = rval;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
75 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
76
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
77 /*
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
78 The operand for include is a string optionally enclosed in "
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
79 */
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
80 OPFUNC(pseudo_include)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
81 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
82 int v1;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
83 char *fn;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
84
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
85 // only include files on pass 1
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
86 // but make sure local include context is right
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
87 // for the next line...
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
88 if (as -> passnum != 1)
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
89 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
90 as -> context = lwasm_next_context(as);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
91 return;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
92 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
93
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
94 while (**p && isspace(**p))
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
95 (*p)++;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
96
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
97 if (!**p)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
98 {
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
99 register_error(as, l, 1, "Bad file name");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
100 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
101 }
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
102
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
103 if (**p == '"')
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
104 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
105 // search for ending "
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
106 (*p)++;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
107 for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
108 /* do nothing */ ;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
109 if (*((*p)+v1) != '"')
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
110 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
111 register_error(as, l, 1, "Bad file name");
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
112 return;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
113 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
114 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
115 else
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
116 {
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
117 // search for a space type character
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
118 for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
119 ;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
120 }
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
121
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
122 fn = lwasm_alloc(v1 + 1);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
123 memcpy(fn, *p, v1);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
124 fn[v1] = '\0';
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
125
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
126 // end local label context on include
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
127 as -> context = lwasm_next_context(as);
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
128 if (lwasm_read_file(as, fn) < 0)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
129 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
130 register_error(as, l, 1, "File include error (%s)", fn);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
131 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
132 lwasm_free(fn);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
133 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
134
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
135 OPFUNC(pseudo_rmb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
136 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
137 int rval;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
138 lwasm_expr_stack_t *s;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
139
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
140 s = lwasm_evaluate_expr(as, l, *p, NULL);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
141 if (!s)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
142 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
143 register_error(as, l, 1, "Bad expression");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
144 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
145 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
146 if (!lwasm_expr_is_constant(s))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
147 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
148 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
149 lwasm_expr_stack_free(s);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
150 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
151 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
152 rval = lwasm_expr_get_value(s);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
153 lwasm_expr_stack_free(s);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
154 l -> nocodelen = rval;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
155 as -> addr += rval;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
156 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
157
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
158 OPFUNC(pseudo_rmd)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
159 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
160 int rval;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
161 lwasm_expr_stack_t *s;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
162
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
163 s = lwasm_evaluate_expr(as, l, *p, NULL);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
164 if (!s)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
165 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
166 register_error(as, l, 1, "Bad expression");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
167 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
168 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
169 if (!lwasm_expr_is_constant(s))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
170 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
171 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
172 lwasm_expr_stack_free(s);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
173 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
174 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
175 rval = lwasm_expr_get_value(s) * 2;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
176 lwasm_expr_stack_free(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
177 l -> nocodelen = rval;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
178 as -> addr += rval;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
179 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
180
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
181 OPFUNC(pseudo_rmq)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
182 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
183 int rval;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
184 lwasm_expr_stack_t *s;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
185
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
186 s = lwasm_evaluate_expr(as, l, *p, NULL);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
187 if (!s)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
188 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
189 register_error(as, l, 1, "Bad expression");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
190 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
191 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
192 if (!lwasm_expr_is_constant(s))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
193 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
194 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
195 lwasm_expr_stack_free(s);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
196 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
197 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
198 rval = lwasm_expr_get_value(s) * 4;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
199 lwasm_expr_stack_free(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
200 l -> nocodelen = rval;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
201 as -> addr += rval;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
202 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
203
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
204 OPFUNC(pseudo_zmb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
205 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
206 int rval;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
207 lwasm_expr_stack_t *s;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
208
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
209 s = lwasm_evaluate_expr(as, l, *p, NULL);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
210 if (!s)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
211 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
212 register_error(as, l, 1, "Bad expression");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
213 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
214 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
215 if (!lwasm_expr_is_constant(s))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
216 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
217 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
218 lwasm_expr_stack_free(s);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
219 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
220 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
221 rval = lwasm_expr_get_value(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
222 lwasm_expr_stack_free(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
223 while (rval-- > 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
224 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
225 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
226 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
227 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
228
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
229 OPFUNC(pseudo_zmd)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
230 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
231 int rval;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
232 lwasm_expr_stack_t *s;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
233
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
234 s = lwasm_evaluate_expr(as, l, *p, NULL);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
235 if (!s)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
236 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
237 register_error(as, l, 1, "Bad expression");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
238 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
239 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
240 if (!lwasm_expr_is_constant(s))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
241 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
242 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
243 lwasm_expr_stack_free(s);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
244 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
245 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
246 rval = lwasm_expr_get_value(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
247 lwasm_expr_stack_free(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
248 while (rval-- > 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
249 {
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
250 lwasm_emit(as, l, 0);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
251 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
252 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
253 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
254
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
255 OPFUNC(pseudo_zmq)
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
256 {
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
257 int rval;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
258 lwasm_expr_stack_t *s;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
259
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
260 s = lwasm_evaluate_expr(as, l, *p, NULL);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
261 if (!s)
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
262 {
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
263 register_error(as, l, 1, "Bad expression");
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
264 return;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
265 }
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
266 if (!lwasm_expr_is_constant(s))
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
267 {
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
268 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
269 lwasm_expr_stack_free(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
270 return;
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
271 }
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
272 rval = lwasm_expr_get_value(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
273 lwasm_expr_stack_free(s);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
274 while (rval-- > 0)
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
275 {
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
276 lwasm_emit(as, l, 0);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
277 lwasm_emit(as, l, 0);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
278 lwasm_emit(as, l, 0);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
279 lwasm_emit(as, l, 0);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
280 }
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
281 }
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
282
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
283 OPFUNC(pseudo_end)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
284 {
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
285 int rval;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
286 lwasm_expr_stack_t *s;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
287
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
288
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
289 as -> endseen = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
290
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
291 // address only matters for DECB output
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
292 if (as -> outformat != OUTPUT_DECB)
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
293 return;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
294
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
295 s = lwasm_evaluate_expr(as, l, *p, NULL);
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
296 if (!s)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
297 {
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
298 register_error(as, l, 1, "Bad expression");
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
299 return;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
300 }
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
301 if (!lwasm_expr_is_constant(s))
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
302 {
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
303 register_error(as, l, 2, "Incomplete reference");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
304 }
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
305 rval = lwasm_expr_get_value(s);
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
306 lwasm_expr_stack_free(s);
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
307
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
308 rval = rval & 0xffff;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
309 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
310 {
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
311 as -> execaddr = rval;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
312 l -> symaddr = rval;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
313 l -> addrset = 2;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
314 }
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
315 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
316
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
317
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
318 OPFUNC(pseudo_align)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
319 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
320 int rval;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
321 lwasm_expr_stack_t *s;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
322 int cn;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
323
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
324 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
325 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
326 while (as -> addr < l -> symaddr)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
327 lwasm_emit(as, l, 0);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
328 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
329 }
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
330
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
331 s = lwasm_evaluate_expr(as, l, *p, NULL);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
332 if (!s)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
333 {
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
334 register_error(as, l, 1, "Bad expression");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
335 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
336 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
337 if (!lwasm_expr_is_constant(s))
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
338 {
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
339 register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
340 }
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
341 rval = lwasm_expr_get_value(s);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
342 lwasm_expr_stack_free(s);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
343
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
344 if (rval < 1)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
345 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
346 register_error(as, l, 1, "Illegal alignment %d", rval);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
347 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
348 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
349
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
350 cn = l -> codeaddr % rval;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
351 if (cn)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
352 cn = rval - cn;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
353
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
354 while (cn--)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
355 {
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
356 lwasm_emit(as, l, 0);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
357 }
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
358 l -> symaddr = as -> addr;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
359 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
360
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
361 OPFUNC(pseudo_equ)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
362 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
363 int rval;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
364
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
365 // equ is not needed to be processed on pass 2
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
366 if (as -> passnum != 1)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
367 return;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
368
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
369 if (l -> sym == NULL)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
370 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
371 register_error(as, l, 1, "No symbol specified");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
372 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
373 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
374
63
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 57
diff changeset
375 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &rval) < 0)
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
376 rval = 0;
63
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 57
diff changeset
377
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
378 l -> symaddr = rval & 0xFFFF;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
379 l -> addrset = 2;
63
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 57
diff changeset
380
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
381 lwasm_register_symbol(as, l, l -> sym, rval, SYMBOL_NORM);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
382 }
63
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 57
diff changeset
383
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 57
diff changeset
384 OPFUNC(pseudo_set)
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 57
diff changeset
385 {
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
386 int rval;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
387
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
388 // set MUST run on both passes as the symbol value changes!
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
389
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
390 if (l -> sym == NULL)
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
391 {
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
392 register_error(as, l, 1, "No symbol specified");
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
393 return;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
394 }
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
395
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
396 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST, &rval) < 0)
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
397 rval = 0;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
398
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
399 l -> symaddr = rval & 0xFFFF;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
400 l -> addrset = 2;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
401
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
402 lwasm_register_symbol(as, l, l -> sym, rval, SYMBOL_SET);
63
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 57
diff changeset
403 }
d85ba47b1e8f Moved symbol registration so symbols that are in skipped code do not get registered and so EQU/SET can do their own registration
lost
parents: 57
diff changeset
404
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
405 OPFUNC(pseudo_setdp)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
406 {
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
407 int rval;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
408
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
409 // setdp is needed on both passes
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
410 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST | EXPR_BYTE, &rval) < 0)
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
411 rval = 0;
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
412
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
413 l -> symaddr = rval & 0xFF;
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
414 l -> addrset = 2;
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
415
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
416 as -> dpval = rval & 0xFF;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
417 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
418
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
419 OPFUNC(pseudo_fcc)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
420 {
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
421 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
422
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
423 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
424 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
425 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
426 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
427 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
428 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
429 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
430 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
431 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
432 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
433 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
434 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
435 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
436 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
437 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
438
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
439
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
440 OPFUNC(pseudo_fcs)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
441 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
442 int delim = 0;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
443
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
444 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
445 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
446 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
447 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
448 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
449 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
450 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
451 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
452 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
453 if (!*((*p) + 1) || *((*p) + 1) == delim)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
454 lwasm_emit(as, l, **p | 0x80);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
455 else
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
456 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
457 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
458 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
459 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
460 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
461 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
462
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
463 OPFUNC(pseudo_fcn)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
464 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
465 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
466
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
467 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
468 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
469 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
470 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
471 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
472 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
473 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
474 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
475 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
476 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
477 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
478 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
479 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
480 (*p)++;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
481 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
482 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
483
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
484 OPFUNC(pseudo_fcb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
485 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
486 int v1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
487
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
488 fcb_again:
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
489 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST | EXPR_BYTE, &v1) < 0)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
490 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
491
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
492 lwasm_emit(as, l, v1);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
493 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
494 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
495 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
496 goto fcb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
497 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
498 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
499
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
500 OPFUNC(pseudo_fdb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
501 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
502 int v1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
503
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
504 fdb_again:
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
505 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
506 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
507
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
508 lwasm_emit(as, l, v1 >> 8);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
509 lwasm_emit(as, l, v1 & 0xff);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
510 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
511 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
512 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
513 goto fdb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
514 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
515 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
516
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
517 OPFUNC(pseudo_fqb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
518 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
519 int v1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
520
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
521 fqb_again:
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
522 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
523 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
524
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
525 lwasm_emit(as, l, v1 >> 24);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
526 lwasm_emit(as, l, v1 >> 16);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
527 lwasm_emit(as, l, v1 >> 8);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
528 lwasm_emit(as, l, v1 & 0xff);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
529 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
530 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
531 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
532 goto fqb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
533 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
534 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
535
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
536 // don't need to do anything if we are executing one of these
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
537 OPFUNC(pseudo_endc)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
538 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
539 if (as -> skipcond && !(as -> skipmacro))
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
540 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
541 as -> skipcount -= 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
542 if (as -> skipcount <= 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
543 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
544 as -> skipcond = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
545 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
546 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
547 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
548 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
549
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
550 // if "else" executes, we must be going into an "ignore" state
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
551 OPFUNC(pseudo_else)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
552 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
553 if (as -> skipmacro)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
554 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
555
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
556 if (as -> skipcond)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
557 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
558 if (as -> skipcount == 1)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
559 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
560 as -> skipcount = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
561 as -> skipcond = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
562 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
563 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
564 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
565
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
566 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
567 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
568 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
569
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
570 OPFUNC(pseudo_ifne)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
571 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
572 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
573 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
574
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
575 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
576 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
577 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
578 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
579 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
580
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
581 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
582 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
583 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
584 if (!v1)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
585 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
586 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
587 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
588 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
589 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
590
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
591 OPFUNC(pseudo_ifeq)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
592 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
593 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
594 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
595
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
596 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
597 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
598 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
599 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
600 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
601
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
602 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
603 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
604 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
605 if (v1)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
606 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
607 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
608 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
609 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
610 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
611
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
612 OPFUNC(pseudo_iflt)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
613 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
614 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
615 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
616
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
617 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
618 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
619 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
620 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
621 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
622
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
623 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
624 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
625 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
626 if (v1 >= 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
627 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
628 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
629 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
630 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
631 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
632
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
633 OPFUNC(pseudo_ifle)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
634 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
635 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
636 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
637
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
638 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
639 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
640 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
641 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
642 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
643
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
644 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
645 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
646 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
647 if (v1 > 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
648 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
649 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
650 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
651 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
652 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
653
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
654 OPFUNC(pseudo_ifgt)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
655 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
656 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
657 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
658
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
659 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
660 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
661 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
662 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
663 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
664
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
665 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
666 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
667 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
668 if (v1 <= 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
669 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
670 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
671 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
672 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
673 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
674
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
675 OPFUNC(pseudo_ifge)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
676 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
677 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
678 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
679
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
680 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
681 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
682 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
683 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
684 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
685
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
686 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
687 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
688 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
689 if (v1 < 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
690 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
691 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
692 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
693 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
694 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
695
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
696 OPFUNC(pseudo_error)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
697 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
698 register_error(as, l, 1, "User error: %s", *p);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
699 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
700
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
701
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
702 OPFUNC(pseudo_section)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
703 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
704 sectiontab_t *s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
705 char *p2;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
706 char *sn;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
707 char *opts;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
708
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
709
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
710 if (as -> outformat != OUTPUT_OBJ)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
711 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
712 register_error(as, l, 1, "Sections only supported for obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
713 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
714 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
715
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
716 if (as -> csect)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
717 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
718 as -> csect -> offset = as -> addr;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
719 as -> csect = NULL;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
720 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
721
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
722 if (!**p)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
723 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
724 register_error(as, l, 1, "Need section name");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
725 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
726 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
727
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
728 for (p2 = *p; *p2 && !isspace(*p2); p2++)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
729 /* do nothing */ ;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
730
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
731 sn = lwasm_alloc(p2 - *p + 1);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
732 memcpy(sn, *p, p2 - *p);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
733 sn[p2 - *p] = '\0';
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
734
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
735 *p = p2;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
736
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
737 opts = strchr(sn, ',');
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
738 if (opts)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
739 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
740 *opts++ = '\0';
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
741 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
742
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
743 // have we seen the section name already?
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
744 for (s = as -> sections; s; s = s -> next)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
745 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
746 if (!strcmp(s -> name, sn))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
747 break;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
748 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
749
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
750 if (s)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
751 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
752 lwasm_free(sn);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
753 if (opts)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
754 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
755 register_error(as, l, 1, "Section options can only be specified the first time");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
756 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
757 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
758 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
759 else if (!s)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
760 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
761 s = lwasm_alloc(sizeof(sectiontab_t));
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
762 s -> name = sn;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
763 s -> offset = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
764 s -> flags = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
765
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
766 // parse options; only one "bss"
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
767 if (opts && as -> passnum == 1)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
768 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
769 if (!strcasecmp(opts, "bss"))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
770 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
771 s -> flags = SECTION_BSS;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
772 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
773 else
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
774 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
775 register_error(as, l, 1, "Unrecognized section option '%s'", opts);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
776 lwasm_free(s -> name);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
777 lwasm_free(s);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
778 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
779 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
780 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
781
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
782 s -> next = as -> sections;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
783 as -> sections = s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
784 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
785 as -> addr = s -> offset;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
786 as -> csect = s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
787 as -> context = lwasm_next_context(as);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
788 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
789
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
790 OPFUNC(pseudo_endsection)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
791 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
792 if (as -> outformat != OUTPUT_OBJ)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
793 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
794 register_error(as, l, 1, "Sections only supported for obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
795 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
796 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
797
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
798 if (!(as -> csect))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
799 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
800 register_error(as, l, 1, "ENDSECTION when not in a section");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
801 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
802 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
803
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
804 as -> csect -> offset = as -> addr;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
805 as -> addr = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
806 as -> csect = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
807 as -> context = lwasm_next_context(as);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
808 }