struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / asf8 / f8pst.c
blob8346302920b3e43c8c85c6eedc44b93cd45235dd
1 /* stm8pst.c */
3 /*
4 * Copyright (C) 1010 Alan R. Baldwin
5 * Copyright (C) 2022 Philipp K. Krause
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Alan R. Baldwin
22 * 721 Berkeley St.
23 * Kent, Ohio 44240
27 #include "asxxxx.h"
28 #include "f8.h"
30 #if 0
32 * Coding Banks
34 struct bank bank[2] = {
35 /* The '_CODE' area/bank has a NULL default file suffix. */
36 { NULL, "_CSEG", NULL, 0, 0, 0, 0, 0 },
37 { &bank[0], "_DSEG", "_DS", 1, 0, 0, 0, B_FSFX }
41 * Coding Areas
43 struct area area[2] = {
44 { NULL, &bank[0], "_CODE", 0, 0, 0, A_1BYTE|A_BNK|A_CSEG },
45 { &area[0], &bank[1], "_DATA", 1, 0, 0, A_1BYTE|A_BNK|A_DSEG }
47 #endif
50 * Basic Relocation Mode Definition
52 * #define R_NORM 0000 No Bit Positioning
54 char mode0[32] = { /* R_NORM */
55 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
56 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
57 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
58 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237'
62 * Additional Relocation Mode Definitions
66 * Bit Relocation Mode Definition
68 * #define R_BITS 0100 Bit Test Positioning
70 char mode1[32] = { /* R_BITS */
71 '\201', '\202', '\203', '\003', '\004', '\005', '\006', '\007',
72 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
73 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
74 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037'
79 * *m_def is a pointer to the bit relocation definition.
80 * m_flag indicates that bit position swapping is required.
81 * m_dbits contains the active bit positions for the output.
82 * m_sbits contains the active bit positions for the input.
84 * struct mode
85 * {
86 * char * m_def; Bit Relocation Definition
87 * a_uint m_flag; Bit Swapping Flag
88 * a_uint m_dbits; Destination Bit Mask
89 * a_uint m_sbits; Source Bit Mask
90 * };
92 struct mode mode[2] = {
93 { &mode0[0], 0, 0x0000FFFF, 0x0000FFFF },
94 { &mode1[0], 1, 0x0000000E, 0x00000007 }
99 * Array of Pointers to mode Structures
101 struct mode *modep[16] = {
102 &mode[0], &mode[1], NULL, NULL,
103 NULL, NULL, NULL, NULL,
104 NULL, NULL, NULL, NULL,
105 NULL, NULL, NULL, NULL
109 * Mnemonic Structure
111 struct mne mne[] = {
113 /* machine */
115 //{ NULL, "CSEG", S_ATYP, 0, A_CSEG|A_1BYTE },
116 //{ NULL, "DSEG", S_ATYP, 0, A_DSEG|A_1BYTE },
118 /* system */
120 //{ NULL, "BANK", S_ATYP, 0, A_BNK },
121 { NULL, "CON", S_ATYP, 0, A_CON },
122 { NULL, "OVR", S_ATYP, 0, A_OVR },
123 { NULL, "REL", S_ATYP, 0, A_REL },
124 { NULL, "ABS", S_ATYP, 0, A_ABS },
125 { NULL, "NOPAG", S_ATYP, 0, A_NOPAG },
126 { NULL, "PAG", S_ATYP, 0, A_PAG },
128 #if 0 /* ljm -- figure out what S_BTYP (bank type?) is */
129 { NULL, "BASE", S_BTYP, 0, B_BASE },
130 { NULL, "SIZE", S_BTYP, 0, B_SIZE },
131 { NULL, "FSFX", S_BTYP, 0, B_FSFX },
132 { NULL, "MAP", S_BTYP, 0, B_MAP },
133 #endif
134 { NULL, "NOLOAD", S_ATYP, 0, A_NOLOAD},
135 { NULL, ".page", S_PAGE, 0, 0 },
136 { NULL, ".title", S_HEADER, 0, O_TITLE },
137 { NULL, ".sbttl", S_HEADER, 0, O_SBTTL },
138 { NULL, ".module", S_MODUL, 0, 0 },
139 { NULL, ".include", S_INCL, 0, I_CODE },
140 { NULL, ".incbin", S_INCL, 0, I_BNRY },
141 { NULL, ".area", S_AREA, 0, 0 },
142 //{ NULL, ".bank", S_BANK, 0, 0 },
143 { NULL, ".org", S_ORG, 0, 0 },
144 { NULL, ".radix", S_RADIX, 0, 0 },
145 { NULL, ".globl", S_GLOBL, 0, 0 },
146 { NULL, ".local", S_LOCAL, 0, 0 },
147 { NULL, ".if", S_CONDITIONAL, 0, O_IF },
148 { NULL, ".iff", S_CONDITIONAL, 0, O_IFF },
149 { NULL, ".ift", S_CONDITIONAL, 0, O_IFT },
150 { NULL, ".iftf", S_CONDITIONAL, 0, O_IFTF },
151 { NULL, ".ifdef", S_CONDITIONAL, 0, O_IFDEF },
152 { NULL, ".ifndef", S_CONDITIONAL, 0, O_IFNDEF},
153 { NULL, ".ifgt", S_CONDITIONAL, 0, O_IFGT },
154 { NULL, ".iflt", S_CONDITIONAL, 0, O_IFLT },
155 { NULL, ".ifge", S_CONDITIONAL, 0, O_IFGE },
156 { NULL, ".ifle", S_CONDITIONAL, 0, O_IFLE },
157 { NULL, ".ifeq", S_CONDITIONAL, 0, O_IFEQ },
158 { NULL, ".ifne", S_CONDITIONAL, 0, O_IFNE },
159 { NULL, ".ifb", S_CONDITIONAL, 0, O_IFB },
160 { NULL, ".ifnb", S_CONDITIONAL, 0, O_IFNB },
161 { NULL, ".ifidn", S_CONDITIONAL, 0, O_IFIDN },
162 { NULL, ".ifdif", S_CONDITIONAL, 0, O_IFDIF },
163 { NULL, ".iif", S_CONDITIONAL, 0, O_IIF },
164 { NULL, ".iiff", S_CONDITIONAL, 0, O_IIFF },
165 { NULL, ".iift", S_CONDITIONAL, 0, O_IIFT },
166 { NULL, ".iiftf", S_CONDITIONAL, 0, O_IIFTF },
167 { NULL, ".iifdef", S_CONDITIONAL, 0, O_IIFDEF},
168 { NULL, ".iifndef", S_CONDITIONAL, 0, O_IIFNDEF},
169 { NULL, ".iifgt", S_CONDITIONAL, 0, O_IIFGT },
170 { NULL, ".iiflt", S_CONDITIONAL, 0, O_IIFLT },
171 { NULL, ".iifge", S_CONDITIONAL, 0, O_IIFGE },
172 { NULL, ".iifle", S_CONDITIONAL, 0, O_IIFLE },
173 { NULL, ".iifeq", S_CONDITIONAL, 0, O_IIFEQ },
174 { NULL, ".iifne", S_CONDITIONAL, 0, O_IIFNE },
175 { NULL, ".iifb", S_CONDITIONAL, 0, O_IIFB },
176 { NULL, ".iifnb", S_CONDITIONAL, 0, O_IIFNB },
177 { NULL, ".iifidn", S_CONDITIONAL, 0, O_IIFIDN},
178 { NULL, ".iifdif", S_CONDITIONAL, 0, O_IIFDIF},
179 { NULL, ".else", S_CONDITIONAL, 0, O_ELSE },
180 { NULL, ".endif", S_CONDITIONAL, 0, O_ENDIF },
181 { NULL, ".list", S_LISTING, 0, O_LIST },
182 { NULL, ".nlist", S_LISTING, 0, O_NLIST },
183 { NULL, ".uleb128", S_ULEB128, 0, 0 },
184 { NULL, ".sleb128", S_SLEB128, 0, 0 },
185 { NULL, ".equ", S_EQU, 0, O_EQU },
186 { NULL, ".gblequ", S_EQU, 0, O_GBLEQU},
187 { NULL, ".lclequ", S_EQU, 0, O_LCLEQU},
188 { NULL, ".byte", S_DATA, 0, O_1BYTE },
189 { NULL, ".db", S_DATA, 0, O_1BYTE },
190 { NULL, ".fcb", S_DATA, 0, O_1BYTE },
191 { NULL, ".word", S_DATA, 0, O_2BYTE },
192 { NULL, ".dw", S_DATA, 0, O_2BYTE },
193 { NULL, ".fdb", S_DATA, 0, O_2BYTE },
194 { NULL, ".3byte", S_DATA, 0, O_3BYTE },
195 { NULL, ".triple", S_DATA, 0, O_3BYTE },
196 /* { NULL, ".4byte", S_DATA, 0, O_4BYTE }, */
197 /* { NULL, ".quad", S_DATA, 0, O_4BYTE }, */
198 { NULL, ".blkb", S_BLK, 0, O_1BYTE },
199 { NULL, ".ds", S_BLK, 0, O_1BYTE },
200 { NULL, ".rmb", S_BLK, 0, O_1BYTE },
201 { NULL, ".rs", S_BLK, 0, O_1BYTE },
202 { NULL, ".blkw", S_BLK, 0, O_2BYTE },
203 { NULL, ".blk3", S_BLK, 0, O_3BYTE },
204 /* { NULL, ".blk4", S_BLK, 0, O_4BYTE }, */
205 { NULL, ".ascii", S_ASCIX, 0, O_ASCII },
206 { NULL, ".ascis", S_ASCIX, 0, O_ASCIS },
207 { NULL, ".asciz", S_ASCIX, 0, O_ASCIZ },
208 { NULL, ".str", S_ASCIX, 0, O_ASCII },
209 { NULL, ".strs", S_ASCIX, 0, O_ASCIS },
210 { NULL, ".strz", S_ASCIX, 0, O_ASCIZ },
211 { NULL, ".fcc", S_ASCIX, 0, O_ASCII },
212 { NULL, ".define", S_DEFINE, 0, O_DEF },
213 { NULL, ".undefine", S_DEFINE, 0, O_UNDEF },
214 { NULL, ".even", S_BOUNDARY, 0, O_EVEN },
215 { NULL, ".odd", S_BOUNDARY, 0, O_ODD },
216 { NULL, ".bndry", S_BOUNDARY, 0, O_BNDRY },
217 { NULL, ".msg" , S_MSG, 0, 0 },
218 { NULL, ".assume", S_ERROR, 0, O_ASSUME},
219 { NULL, ".error", S_ERROR, 0, O_ERROR },
220 //{ NULL, ".msb", S_MSB, 0, 0 },
221 /* { NULL, ".lohi", S_MSB, 0, O_LOHI }, */
222 /* { NULL, ".hilo", S_MSB, 0, O_HILO }, */
223 /* { NULL, ".8bit", S_BITS, 0, O_1BYTE }, */
224 /* { NULL, ".16bit", S_BITS, 0, O_2BYTE }, */
225 /* { NULL, ".24bit", S_BITS, 0, O_3BYTE }, */
226 /* { NULL, ".32bit", S_BITS, 0, O_4BYTE }, */
227 { NULL, ".end", S_END, 0, 0 },
228 /* sdas specific */
229 { NULL, ".optsdcc", S_OPTSDCC, 0, 0 },
230 /* end sdas specific */
232 /* Macro Processor */
234 { NULL, ".macro", S_MACRO, 0, O_MACRO },
235 { NULL, ".endm", S_MACRO, 0, O_ENDM },
236 { NULL, ".mexit", S_MACRO, 0, O_MEXIT },
238 { NULL, ".narg", S_MACRO, 0, O_NARG },
239 { NULL, ".nchr", S_MACRO, 0, O_NCHR },
240 { NULL, ".ntyp", S_MACRO, 0, O_NTYP },
242 { NULL, ".irp", S_MACRO, 0, O_IRP },
243 { NULL, ".irpc", S_MACRO, 0, O_IRPC },
244 { NULL, ".rept", S_MACRO, 0, O_REPT },
246 { NULL, ".nval", S_MACRO, 0, O_NVAL },
248 { NULL, ".mdelete", S_MACRO, 0, O_MDEL },
250 /* f8 instructions */
252 /* 8-bit 2-op-instrustions */
253 { NULL, "sub", S_2OPSUB, 0, 0x00 },
254 { NULL, "sbc", S_2OPSUB, 0, 0x08 },
255 { NULL, "add", S_2OP, 0, 0x10 },
256 { NULL, "adc", S_2OP, 0, 0x18 },
257 { NULL, "cp", S_2OP, 0, 0x20 },
258 { NULL, "or", S_2OP, 0, 0x28 },
259 { NULL, "and", S_2OP, 0, 0x30 },
260 { NULL, "xor", S_2OP, 0, 0x38 },
262 /* 8-bit 1-op-instrustions */
263 { NULL, "srl", S_1OP, 0, 0x40 },
264 { NULL, "sll", S_1OP, 0, 0x44 },
265 { NULL, "rrc", S_1OP, 0, 0x48 },
266 { NULL, "rlc", S_1OP, 0, 0x4c },
267 { NULL, "inc", S_1OP, 0, 0x50 },
268 { NULL, "dec", S_1OP, 0, 0x54 },
269 { NULL, "clr", S_1OP, 0, 0x58 },
270 { NULL, "tst", S_1OP, 0, 0x5c },
271 { NULL, "push", S_1OPPUSH, 0, 0x60 },
273 /* 16-bit 2-op-instrustions */
274 { NULL, "subw", S_2OPWSUB, 0, 0x70 },
275 { NULL, "sbcw", S_2OPWSBC, 0, 0x74 },
276 { NULL, "addw", S_2OPWADD, 0, 0x78 },
277 { NULL, "adcw", S_2OPWADC, 0, 0x7c },
278 { NULL, "orw", S_2OPW, 0, 0xf0 },
279 { NULL, "xorw", S_2OPW, 0, 0xfc },
281 /* 16-bit 1-op-instrustions */
282 { NULL, "clrw", S_1OPW, 0, 0xa0 },
283 { NULL, "incw", S_1OPW, 0, 0xa4 },
284 //{ NULL, "adcw", S_1OPW, 0, 0xa8 },
285 //{ NULL, "sbcw", S_1OPW, 0, 0xac },
286 { NULL, "pushw", S_1OPWPUSH, 0, 0xb0 },
287 { NULL, "tstw", S_1OPW, 0, 0xb4 },
289 /* 8-bit loads */
290 { NULL, "ld", S_LD, 0, 0x80 },
291 { NULL, "ldi", S_LDI, 0, 0xed },
293 /* 16-bit loads */
294 { NULL, "ldw", S_LDW, 0, 0xc0 },
295 { NULL, "ldwi", S_LDI, 0, 0xcf },
297 /* 8-bit 0-op-instrustions */
298 { NULL, "bool", S_0OP, 0, 0x98 },
299 { NULL, "sra", S_0OP, 0, 0x96 },
300 { NULL, "daa", S_0OP, 0, 0x97 },
301 { NULL, "pop", S_0OP, 0, 0x99 },
302 { NULL, "xch", S_0OPXCH, 0, 0x90 },
303 { NULL, "msk", S_0OPMSK, 0, 0xb8 },
304 { NULL, "cax", S_0OP, 0, 0x9b },
305 { NULL, "mad", S_0OPMAD, 0, 0xbc },
306 { NULL, "rot", S_0OPROT, 0, 0x95 },
307 { NULL, "thrd", S_0OP, 0, 0x9a },
308 { NULL, "cax", S_0OPCAX, 0, 0x9b },
309 //{ NULL, "push", S_0OP, 0, 0x90 },
311 /* 16-bit 0-op-instrustions */
312 { NULL, "negw", S_0OPW, 0, 0xfa },
313 { NULL, "boolw", S_0OPW, 0, 0xfb },
314 { NULL, "srlw", S_0OPW, 0, 0xe0 },
315 { NULL, "sllw", S_0OPWSLL, 0, 0xe1 },
316 { NULL, "rrcw", S_0OPWRLC, 0, 0xe2 },
317 { NULL, "rlcw", S_0OPWRLC, 0, 0xe3 },
318 { NULL, "sraw", S_0OPW, 0, 0xe4 },
319 { NULL, "mul", S_0OPW, 0, 0xb9 },
320 { NULL, "popw", S_0OPW, 0, 0xe9 },
321 { NULL, "xchw", S_0OPWXCH, 0, 0xf4 },
322 { NULL, "caxw", S_0OPW, 0, 0xf9 },
323 // { NULL, "addw", S_0OPW, 0, 0xea },
324 { NULL, "cpw", S_0OPWCP, 0, 0xf8 },
325 { NULL, "incnw", S_0OPW, 0, 0xf6 },
326 { NULL, "decw", S_0OPWDEC, 0, 0xf3 },
327 // { NULL, "pushw", S_0OPW, 0, 0xe8 },
328 // { NULL, "sllw", S_0OPW, 0, 0xe5 },
329 // { NULL, "rlcw", S_0OPW, 0, 0xe6 },
330 // { NULL, "rrcw", S_0OPW, 0, 0xe7 },
331 { NULL, "cltz", S_0OPW, 0, 0xed },
332 { NULL, "sex", S_0OPWSEX, 0, 0xee },
333 { NULL, "zex", S_0OPWSEX, 0, 0xef },
334 // { NULL, "addw", S_0OPW, 0, 0xec },
335 { NULL, "caxw", S_0OPWCAX, 0, 0xf9 },
337 /* bit instructions */
338 { NULL, "xchb", S_BIT, 0, 0x68 },
340 /* relative jumps */
341 { NULL, "jr", S_JR, 0, 0xd0 },
342 { NULL, "jrz", S_JR, 0, 0xd2 },
343 { NULL, "jrnz", S_JR, 0, 0xd3 },
344 { NULL, "jrc", S_JR, 0, 0xd4 },
345 { NULL, "jrnc", S_JR, 0, 0xd5 },
346 { NULL, "jrn", S_JR, 0, 0xd6 },
347 { NULL, "jrnn", S_JR, 0, 0xd7 },
348 { NULL, "jrno", S_JR, 0, 0xd9 },
349 { NULL, "jro", S_JR2, 0, 0xd9 },
350 { NULL, "jrsge", S_JR, 0, 0xda },
351 { NULL, "jrslt", S_JR, 0, 0xdb },
352 { NULL, "jrsle", S_JR, 0, 0xdd },
353 { NULL, "jrsgt", S_JR2, 0, 0xdd },
354 { NULL, "jrle", S_JR, 0, 0xdf },
355 { NULL, "jrgt", S_JR2, 0, 0xdf },
356 { NULL, "dnjnz", S_DNJNZ, 0, 0xd1 },
358 /* other instructions */
359 { NULL, "call", S_JP, 0, 0x66 },
360 { NULL, "jp", S_JP, 0, 0x64 },
361 { NULL, "ret", S_RET, 0, 0xba },
362 { NULL, "reti", S_RET, 0, 0xbb },
364 /* nop */
365 { NULL, "nop", S_TRAP, 0, 0x08 },
367 /* trap */
368 { NULL, "trap", S_TRAP, S_EOL, 0x00 }