Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / sdas / aspdk16 / pdk16mch.c
blobd8ffc6c66e3048b87ab3853ef9a1205faffeb639
1 /* pdk14mch.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
29 * Benny Kim (2011/07/21)
30 * bennykim at coreriver dot com
31 * Fixed bugs in relative address with "."
34 #include "sdas.h"
35 #include "asxxxx.h"
36 #include "pdk.h"
38 char *cpu = "Padauk 16";
39 char *dsft = "asm";
42 * Process machine ops.
44 VOID
45 machine(struct mne *mp)
47 a_uint op, opWithFlags;
48 int combine;
50 /* Set the target in case it was not automatically
51 * configured from the executable filename.
53 set_sdas_target (TARGET_ID_PDK16);
55 opWithFlags = mp->m_valu;
56 op = opWithFlags & PDK_OPCODE_MASK;
57 combine = 0;
59 /* Default instructions are only used for A -> K instructions.
60 * Although they may be (ab)used for other types.
62 struct inst def = {op, 0xFF};
63 switch (mp->m_type) {
65 case S_MOV: {
66 struct inst ioa = {0x0080, 0x3F};
67 struct inst aio = {0x00C0, 0x3F};
68 struct inst ma = {0x05C0, 0x3F};
69 struct inst am = {0x07C0, 0x3F};
70 emov(opWithFlags, def, ioa, aio, ma, am);
71 break;
74 case S_IDXM: {
75 struct inst am = {op | 1, 0x1E};
76 struct inst ma = {op, 0x1E};
77 eidxm(am, ma);
78 break;
81 case S_SUB:
82 combine = 0x40;
83 /* fallthrough */
84 case S_ADD: {
85 struct inst ma = {0x0400 | combine, 0x3F};
86 struct inst am = {0x0600 | combine, 0x3F};
87 earith(def, ma, am);
88 break;
91 case S_SUBC:
92 combine = 0x40;
93 /* fallthrough */
94 case S_ADDC: {
95 struct inst ma = {0x0480 | combine, 0x3F};
96 struct inst am = {0x0680 | combine, 0x3F};
97 struct inst a = {0x0010 + (combine >> 6), 0x00};
98 struct inst m = {0x0800 + combine, 0x3F};
99 earithc(ma, am, m, a);
100 break;
103 case S_SLC:
104 case S_SRC:
105 case S_SL:
106 case S_SR: {
107 if (mp->m_type == S_SRC || mp->m_type == S_SLC)
108 combine = 2;
109 if (mp->m_type == S_SL || mp->m_type == S_SLC)
110 combine += 1;
112 struct inst a = {0x001A + combine, 0x00};
113 struct inst m = {0x0A00 + (combine << 6), 0x3F};
114 eshift(a, m);
115 break;
118 case S_OR:
119 case S_XOR:
120 case S_AND: {
121 if (mp->m_type == S_OR) {
122 combine = 0x40;
123 } else
124 if (mp->m_type == S_XOR) {
125 combine = 0x80;
128 struct inst ma = {0x0500 | combine, 0x3F};
129 struct inst am = {0x0700 | combine, 0x3F};
130 struct inst ioa = {0x0060, 0x1F};
131 ebit(opWithFlags, def, ma, am, mp->m_type == S_XOR ? &ioa : NULL);
132 break;
135 case S_NEG:
136 combine = 0x40;
137 /* fallthrough */
138 case S_NOT: {
139 struct inst m = {0x0A00 | combine, 0x3F};
140 enot(def, m);
141 break;
144 case S_SET1:
145 combine = 0x100;
146 /* fallthrough */
147 case S_SET0: {
148 struct inst io = {0x0E00 | combine, 0x1F};
149 struct inst m = {0x0300 | combine, 0x1F};
150 ebitn(opWithFlags, io, m, /*N offset*/5);
151 break;
154 case S_CNEQSN:
155 combine = 0x40;
156 /* fallthrough */
157 case S_CEQSN: {
158 struct inst m = {0x0B80 | combine, 0xFF};
159 def.op |= combine << 2;
160 eskip(def, m);
161 break;
164 case S_T1SN:
165 combine = 0x100;
166 /* fallthrough */
167 case S_T0SN: {
168 struct inst io = {0x0C00 | combine, 0x1F};
169 struct inst m = {0x0200 | combine, 0x1F};
170 ebitn(opWithFlags, io, m, /*N offset*/5);
171 break;
174 case S_DZSN:
175 combine = 0x40;
176 /* fallthrough */
177 case S_IZSN: {
178 struct inst m = {0x0880 | combine, 0x3F};
179 ezsn(def, m);
180 break;
183 case S_RET: {
184 struct inst k = {0x0100, 0xFF};
185 eret(def, k);
186 break;
189 case S_INC:
190 case S_DEC:
191 case S_CLEAR:
192 def.mask = 0x3F;
193 eone(def);
194 break;
196 case S_CALL:
197 case S_GOTO: {
198 struct expr e;
199 clrexpr(&e);
200 waddrmode = 1;
201 expr(&e, 0);
202 waddrmode = 0;
203 outrwp(&e, def.op, 0x3FF, /*jump=*/1);
204 break;
207 case S_XCH:
208 def.mask = 0x3F;
209 exch(def);
210 break;
212 case S_PUSHAF:
213 case S_POPAF:
214 epupo(def);
215 break;
217 case S_LDT16:
218 case S_STT16:
219 def.mask = 0x3E;
220 eone(def);
221 break;
223 case S_SWAP:
224 case S_PCADD:
225 eopta(def);
226 break;
228 /* Simple instructions consisting of only one opcode and no args */
229 case S_RETI:
230 case S_NOP:
231 case S_ENGINT:
232 case S_DISGINT:
233 case S_STOPSYS:
234 case S_STOPEXE:
235 case S_RESET:
236 case S_WDRESET:
237 case S_MUL:
238 case S_LDSPTL: /* undocumented */
239 case S_LDSPTH: /* undocumented */
240 outaw(op);
241 break;
246 * Machine specific initialization
249 VOID
250 minit(void)
253 * Byte Order
255 hilo = 0;
258 * Address Space
260 exprmasks(3);