struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / aspdk13 / pdk13mch.c
bloba98f4c5c0e7475e355454f8ab9e266211c84a7c5
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 13";
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_PDK13);
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, 0x1F};
67 struct inst aio = {0x00A0, 0x1F};
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 = {0x0A80 + (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 struct inst io = {0x0F00, 0x1F};
146 struct inst m = {0x0310, 0x0F};
147 ebitn(opWithFlags, io, m, /*N offset*/5);
148 break;
151 case S_SET0: {
152 struct inst io = {0x0E00, 0x1F};
153 struct inst m = {0x0300, 0x0F};
154 ebitn(opWithFlags, io, m, /*N offset*/5);
155 break;
158 case S_CEQSN: {
159 struct inst m = {0x0B80, 0xFF};
160 def.op |= combine << 2;
161 eskip(def, m);
162 break;
165 case S_T1SN: {
166 struct inst io = {0x0D00, 0x1F};
167 struct inst m = {0x0210, 0x0F};
168 ebitn(opWithFlags, io, m, /*N offset*/5);
169 break;
172 case S_T0SN: {
173 struct inst io = {0x0C00, 0x1F};
174 struct inst m = {0x0200, 0x0F};
175 ebitn(opWithFlags, io, m, /*N offset*/5);
176 break;
179 case S_DZSN:
180 combine = 0x40;
181 /* fallthrough */
182 case S_IZSN: {
183 struct inst m = {0x0880 | combine, 0x3F};
184 ezsn(def, m);
185 break;
188 case S_RET: {
189 struct inst k = {0x0100, 0xFF};
190 eret(def, k);
191 break;
194 case S_INC:
195 case S_DEC:
196 case S_CLEAR:
197 def.mask = 0x3F;
198 eone(def);
199 break;
201 case S_CALL:
202 case S_GOTO: {
203 struct expr e;
204 clrexpr(&e);
205 waddrmode = 1;
206 expr(&e, 0);
207 waddrmode = 0;
208 outrwp(&e, def.op, 0x3FF, /*jump=*/1);
209 break;
212 case S_XCH:
213 def.mask = 0x3F;
214 exch(def);
215 break;
217 case S_PUSHAF:
218 case S_POPAF:
219 epupo(def);
220 break;
222 case S_LDT16:
223 case S_STT16:
224 def.mask = 0x3E;
225 eone(def);
226 break;
228 case S_SWAP:
229 case S_PCADD:
230 eopta(def);
231 break;
233 /* Simple instructions consisting of only one opcode and no args */
234 case S_RETI:
235 case S_NOP:
236 case S_ENGINT:
237 case S_DISGINT:
238 case S_STOPSYS:
239 case S_STOPEXE:
240 case S_RESET:
241 case S_WDRESET:
242 case S_MUL:
243 case S_LDSPTL: /* undocumented */
244 case S_LDSPTH: /* undocumented */
245 outaw(op);
246 break;
251 * Machine specific initialization
254 VOID
255 minit(void)
258 * Byte Order
260 hilo = 0;
263 * Address Space
265 exprmasks(3);