struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / aspdk15 / pdk15mch.c
blobc8a98eb5e335269211f8347b9964f7003f444813
1 /* pdk15mch.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 15";
39 char *dsft = "asm";
42 * Process machine ops.
44 VOID
45 machine(struct mne *mp)
47 a_uint op, opWithFlags;
48 int combine;
50 opWithFlags = mp->m_valu;
51 op = opWithFlags & PDK_OPCODE_MASK;
52 combine = 0;
54 /* Default instructions are only used for A -> K instructions.
55 * Although they may be (ab)used for other types.
57 struct inst def = {op, 0xFF};
58 switch (mp->m_type) {
60 case S_MOV: {
61 struct inst ioa = {0x0100, 0x7F};
62 struct inst aio = {0x0180, 0x7F};
63 struct inst ma = {0x1700, 0xFF};
64 struct inst am = {0x1F00, 0xFF};
65 emov(opWithFlags, def, ioa, aio, ma, am);
66 break;
69 case S_IDXM: {
70 struct inst am = {op | 1, 0xFE};
71 struct inst ma = {op, 0xFE};
72 eidxm(am, ma);
73 break;
76 case S_SUB:
77 combine = 0x100;
78 /* fallthrough */
79 case S_ADD: {
80 struct inst ma = {0x1000 | combine, 0xFF};
81 struct inst am = {0x1800 | combine, 0xFF};
82 earith(def, ma, am);
83 break;
86 case S_SUBC:
87 combine = 0x100;
88 /* fallthrough */
89 case S_ADDC: {
90 struct inst ma = {0x1200 | combine, 0xFF};
91 struct inst am = {0x1A00 | combine, 0xFF};
92 struct inst m = {0x2000 | combine, 0xFF};
93 struct inst a = {0x0060 + (combine ? 1 : 0), 0x00};
94 earithc(ma, am, m, a);
95 break;
98 case S_SLC:
99 case S_SRC:
100 case S_SL:
101 case S_SR: {
102 if (mp->m_type == S_SRC || mp->m_type == S_SLC)
103 combine = 2;
104 if (mp->m_type == S_SL || mp->m_type == S_SLC)
105 combine += 1;
107 struct inst a = {0x006A + combine, 0x00};
108 struct inst m = {0x2A00 + (combine << 8), 0xFF};
109 eshift(a, m);
110 break;
113 case S_OR:
114 case S_XOR:
115 case S_AND: {
116 if (mp->m_type == S_OR) {
117 combine = 0x100;
118 } else
119 if (mp->m_type == S_XOR) {
120 combine = 0x200;
123 struct inst ma = {0x1400 | combine, 0xFF};
124 struct inst am = {0x1C00 | combine, 0xFF};
125 struct inst ioa = {0x0080, 0x7F};
126 ebit(opWithFlags, def, ma, am, mp->m_type == S_XOR ? &ioa : NULL);
127 break;
130 case S_NEG:
131 combine = 0x100;
132 /* fallthrough */
133 case S_NOT: {
134 struct inst m = {0x2800 | combine, 0xFF};
135 enot(def, m);
136 break;
138 case S_SWAP: {
139 struct inst m = {0x0a00, 0xFF};
140 enot(def, m);
141 break;
144 case S_SET1:
145 combine = 0x400;
146 /* fallthrough */
147 case S_SET0: {
148 struct inst io = {0x3800 | combine, 0x7F};
149 struct inst m = {0x4800 | combine, 0x7F};
150 ebitn(opWithFlags, io, m, /*N offset*/7);
151 break;
154 case S_CNEQSN:
155 combine = 0x100;
156 /* fallthrough */
157 case S_CEQSN: {
158 struct inst m = {0x2E00 | combine, 0xFF};
159 eskip(def, m);
160 break;
163 case S_T1SN:
164 combine = 0x400;
165 /* fallthrough */
166 case S_T0SN: {
167 struct inst io = {0x3000 | combine, 0x7F};
168 struct inst m = {0x4000 | combine, 0x7F};
169 ebitn(opWithFlags, io, m, /*N offset*/7);
170 break;
173 case S_DZSN:
174 combine = 0x100;
175 /* fallthrough */
176 case S_IZSN: {
177 struct inst m = {0x2200 | combine, 0xFF};
178 ezsn(def, m);
179 break;
182 case S_RET: {
183 struct inst k = {0x0200, 0xFF};
184 eret(def, k);
185 break;
188 case S_LDTABL:
189 case S_LDTABH:
190 case S_LDT16:
191 case S_STT16:
192 def.mask = 0xFE;
193 /* fallthrough */
194 case S_INC:
195 case S_DEC:
196 case S_CLEAR:
197 eone(def);
198 break;
200 case S_CALL:
201 case S_GOTO: {
202 struct expr e;
203 clrexpr(&e);
204 waddrmode = 1;
205 expr(&e, 0);
206 waddrmode = 0;
207 outrwp(&e, op, 0xFFF, /*jump=*/1);
208 break;
211 case S_XCH:
212 exch(def);
213 break;
215 case S_PUSHAF:
216 case S_POPAF:
217 epupo(def);
218 break;
220 case S_PCADD:
221 eopta(def);
222 break;
224 case S_SWAPC:
225 def.mask = 0x7F;
226 eswapc(opWithFlags, def, /*N offset*/7);
227 break;
229 case S_COMP:
230 case S_NADD: {
231 struct inst am = {op, 0xFF};
232 struct inst ma = {op | 0x100, 0xFF};
233 espec(am, ma);
234 break;
237 /* Simple instructions consisting of only one opcode and no args */
238 case S_RETI:
239 case S_NOP:
240 case S_ENGINT:
241 case S_DISGINT:
242 case S_STOPSYS:
243 case S_STOPEXE:
244 case S_RESET:
245 case S_WDRESET:
246 case S_MUL:
247 case S_LDSPTL: /* undocumented */
248 case S_LDSPTH: /* undocumented */
249 outaw(op);
250 break;
255 * Machine specific initialization
258 VOID
259 minit(void)
262 * Byte Order
264 hilo = 0;
267 * Address Space
269 exprmasks(3);
271 /* Set the target in case it was not automatically
272 * configured from the executable filename.
274 set_sdas_target(TARGET_ID_PDK15);