Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / sdas / aspdk / pdkmch.c
blob484b897d03351d0180863c2c1d9a39e834ba65db
1 /* pdkmch.c */
3 /*
4 * Copyright (C) 1998-2011 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
24 * This Assember Ported by
25 * John L. Hartman (JLH)
26 * jhartman at compuserve dot com
27 * noice at noicedebugger dot com
31 #include "asxxxx.h"
32 #include "pdk.h"
34 static VOID outpdkaw(struct inst inst, struct expr e) {
35 outaw(inst.op | (e.e_addr & inst.mask));
38 static VOID outpdkrm(struct inst inst, struct expr e) {
39 /* Don't generate relocatable data if everything is constant. */
40 if (is_abs(&e)) {
41 outpdkaw(inst, e);
42 } else {
43 outrwp(&e, inst.op, inst.mask, /*jump=*/0);
47 static VOID outpdka(struct inst inst) {
48 struct expr e;
49 clrexpr(&e);
50 outpdkaw(inst, e);
53 VOID emov(a_uint op,
54 struct inst def,
55 struct inst ioa,
56 struct inst aio,
57 struct inst ma,
58 struct inst am) {
59 bool ioAdr = op & PDK_OPCODE_ADR_IO;
60 struct expr e, e1;
61 clrexpr(&e);
62 clrexpr(&e1);
64 int t = addr(&e, ioAdr);
65 comma(1);
66 int t1 = addr(&e1, ioAdr);
68 if (t == S_IO && t1 == S_A) {
69 outpdkaw(ioa, e);
70 } else
71 if (t == S_A && t1 == S_IO) {
72 outpdkaw(aio, e1);
73 } else
74 if (t == S_M && t1 == S_A) {
75 outpdkrm(ma, e);
76 } else
77 if (t == S_A && t1 == S_M) {
78 outpdkrm(am, e1);
79 } else
80 if (t == S_A && t1 == S_K) {
81 outpdkrm(def, e1);
82 } else
83 aerr();
86 VOID eidxm(struct inst am, struct inst ma) {
87 struct expr e, e1;
88 clrexpr(&e);
89 clrexpr(&e1);
91 int t = addr(&e, false);
92 comma(1);
93 int t1 = addr(&e1, false);
95 if (t == S_A && t1 == S_M) {
96 outpdkrm(am, e1);
97 } else
98 if (t == S_M && t1 == S_A) {
99 outpdkrm(ma, e);
100 } else
101 aerr();
104 VOID earith(struct inst def,
105 struct inst ma,
106 struct inst am) {
107 struct expr e, e1;
108 clrexpr(&e);
109 clrexpr(&e1);
111 int t = addr(&e, false);
112 comma(1);
113 int t1 = addr(&e1, false);
115 if (t == S_M && t1 == S_A) {
116 outpdkrm(ma, e);
117 } else
118 if (t == S_A && t1 == S_M) {
119 outpdkrm(am, e1);
120 } else
121 if (t == S_A && t1 == S_K) {
122 outpdkrm(def, e1);
123 } else
124 aerr();
127 VOID earithc(struct inst ma,
128 struct inst am,
129 struct inst m,
130 struct inst a) {
131 struct expr e;
132 clrexpr(&e);
133 int t = more() ? addr(&e, false) : S_A;
135 if (comma(0)) {
136 struct expr e1;
137 clrexpr(&e1);
138 int t1 = addr(&e1, false);
139 if (t == S_M && t1 == S_A) {
140 outpdkrm(ma, e);
141 } else
142 if (t == S_A && t1 == S_M) {
143 outpdkrm(am, e1);
144 } else
145 aerr();
146 } else
147 if (t == S_M) {
148 outpdkrm(m, e);
149 } else
150 if (t == S_A) {
151 outpdka(a);
152 } else
153 aerr();
156 VOID eshift(struct inst a,
157 struct inst m) {
158 struct expr e;
159 clrexpr(&e);
160 int t = more() ? addr(&e, false) : S_A;
162 if (t == S_A) {
163 outpdka(a);
164 } else
165 if (t == S_M) {
166 outpdkrm(m, e);
167 } else
168 aerr();
171 VOID ebit(a_uint op,
172 struct inst def,
173 struct inst ma,
174 struct inst am,
175 struct inst *ioa) {
176 bool ioAdr = op & PDK_OPCODE_ADR_IO;
177 struct expr e, e1;
178 clrexpr(&e);
179 clrexpr(&e1);
181 int t = addr(&e, ioAdr), t1 = 0;
183 if (!more()) {
184 if (t == S_K) {
185 t = S_A;
186 t1 = S_K;
187 e1 = e;
188 } else if (t == S_IO) {
189 t1 = S_A;
190 } else
191 aerr();
192 } else {
193 comma(1);
194 t1 = addr(&e1, ioAdr);
197 if (t == S_M && t1 == S_A) {
198 outpdkrm(ma, e);
199 } else
200 if (t == S_A && t1 == S_M) {
201 outpdkrm(am, e1);
202 } else
203 if (t == S_A && t1 == S_K) {
204 outpdkrm(def, e1);
205 } else
206 if (t == S_IO && t1 == S_A && ioa) {
207 outpdkaw(*ioa, e);
208 } else
209 aerr();
212 VOID enot(struct inst def, struct inst m) {
213 struct expr e;
214 clrexpr(&e);
215 int t = more() ? addr(&e, false) : S_A;
217 if (t == S_M) {
218 outpdkrm(m, e);
219 } else if (t == S_A) {
220 outpdka(def);
221 } else
222 aerr();
225 VOID ebitn(a_uint op, struct inst io, struct inst m, int offset) {
226 bool ioAdr = op & PDK_OPCODE_ADR_IO;
227 struct expr e, e1;
228 clrexpr(&e);
229 clrexpr(&e1);
231 int t = addr(&e, ioAdr);
232 comma(1);
233 if (pdkbit(&e1) != S_K)
234 aerr();
236 const a_uint bitn = (e1.e_addr & 0x7) << offset;
237 if (t == S_IO) {
238 io.op |= bitn;
239 outpdkaw(io, e);
240 } else
241 if (t == S_M) {
242 m.op |= bitn;
243 outpdkrm(m, e);
244 } else
245 aerr();
248 VOID eskip(struct inst def, struct inst m) {
249 struct expr e;
250 clrexpr(&e);
251 int t = addr(&e, false);
252 if (t == S_A) {
253 comma(1);
254 t = addr(&e, false);
257 if (t == S_M) {
258 outpdkrm(m, e);
259 } else
260 if (t == S_K) {
261 outpdkrm(def, e);
262 } else
263 aerr();
266 VOID ezsn(struct inst def, struct inst m) {
267 /* IZSN and DZSN insts have the same params as NOT. */
268 enot(def, m);
271 VOID eret(struct inst def, struct inst k) {
272 if (more()) {
273 struct expr e;
274 clrexpr(&e);
275 if (addr(&e, false) != S_K)
276 aerr();
277 outpdkrm(k, e);
278 } else
279 outpdka(def);
282 VOID eone(struct inst m) {
283 struct expr e;
284 clrexpr(&e);
285 if (addr(&e, false) != S_M)
286 aerr();
288 outpdkrm(m, e);
291 VOID exch(struct inst m) {
292 struct expr e;
293 clrexpr(&e);
295 int t = addr(&e, false);
296 if (t == S_A) {
297 comma(1);
298 t = addr(&e, false);
301 if (t != S_M)
302 aerr();
303 outpdkrm(m, e);
306 VOID epupo(struct inst def) {
307 if (more() && (def.op & 0x2000)) {
308 int t = getnb();
309 if (t != 'a')
310 aerr();
311 if (!more() || ((t = getnb()) != 'f'))
312 aerr();
313 def.op &= 0x1FFF;
315 outpdka(def);
318 VOID eopta(struct inst def) {
319 if (more()) {
320 struct expr e;
321 clrexpr(&e);
322 if (addr(&e, false) != S_A)
323 aerr();
325 outpdka(def);
328 VOID eswapc(a_uint op, struct inst iok, int offset) {
329 bool ioAdr = op & PDK_OPCODE_ADR_IO;
330 struct expr e, e1;
331 clrexpr(&e);
332 clrexpr(&e1);
334 int t = addr(&e, ioAdr);
335 comma(1);
336 int t1 = pdkbit(&e1);
338 if (t != S_IO || t1 != S_K)
339 aerr();
341 iok.op |= (e1.e_addr & 0x7) << offset;
342 outpdkaw(iok, e);
345 VOID espec(struct inst am, struct inst ma) {
346 struct expr e, e1;
347 clrexpr(&e);
348 clrexpr(&e1);
350 int t = addr(&e, false);
351 comma(1);
352 int t1 = addr(&e1, false);
354 if (t == S_A && t1 == S_M) {
355 outpdkrm(am, e1);
356 } else
357 if (t == S_M && t1 == S_A) {
358 outpdkrm(ma, e);
359 } else
360 aerr();