OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zparser.h] - Blame information for rev 128

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    zparser.h
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU core
6
//
7 13 dgisselq
// Purpose:     This file is really mis-named.  At one time it was going to
8
//              be header file for the parser for the Zip Assembler, zasm. 
9
//              Since then, I discovered Flex and Bison and have written a
10
//              parser using those tools.  The true parser may therefore be
11
//              found in zasm.y.  This file, however, still declares some
12
//              very valuable tools.  In particular, all of the routines used
13
//              to build instructions from the appropriate fields are declared
14
//              in this file. 
15 2 dgisselq
//
16
// Creator:     Dan Gisselquist, Ph.D.
17 69 dgisselq
//              Gisselquist Technology, LLC
18 2 dgisselq
//
19
////////////////////////////////////////////////////////////////////////////////
20
//
21
// Copyright (C) 2015, Gisselquist Technology, LLC
22
//
23
// This program is free software (firmware): you can redistribute it and/or
24
// modify it under the terms of  the GNU General Public License as published
25
// by the Free Software Foundation, either version 3 of the License, or (at
26
// your option) any later version.
27
//
28
// This program is distributed in the hope that it will be useful, but WITHOUT
29
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
30
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31
// for more details.
32
//
33
// You should have received a copy of the GNU General Public License along
34
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
35
// target there if the PDF file isn't present.)  If not, see
36
// <http://www.gnu.org/licenses/> for a copy.
37
//
38
// License:     GPL, v3, as defined and found on www.gnu.org,
39
//              http://www.gnu.org/licenses/gpl.html
40
//
41
//
42
////////////////////////////////////////////////////////////////////////////////
43
 
44
#ifndef ZPARSER_H
45
#define ZPARSER_H
46
 
47
class   ZPARSER {
48
public:
49
        typedef unsigned int    ZIPI, ZIPA;
50
        typedef int     ZIPIMM;
51
        typedef enum {
52
                ZIP_R0, ZIP_R1, ZIP_R2, ZIP_R3, ZIP_R4, ZIP_R5, ZIP_R6, ZIP_R7,
53
                ZIP_R8, ZIP_R9, ZIP_R10, ZIP_R11, ZIP_R12,
54
                        ZIP_SP, ZIP_CC, ZIP_PC,
55
                ZIP_uR0, ZIP_uR1, ZIP_uR2, ZIP_uR3, ZIP_uR4, ZIP_uR5, ZIP_uR6, ZIP_uR7,
56
                ZIP_uR8, ZIP_uR9, ZIP_uR10, ZIP_uR11, ZIP_uR12,
57
                        ZIP_uSP, ZIP_uCC, ZIP_uPC,
58
                ZIP_Rnone
59
        } ZIPREG;
60
 
61
        typedef enum {
62 69 dgisselq
                ZIPC_ALWAYS, ZIPC_LT, ZIPC_Z, ZIPC_NZ,
63
                ZIPC_GT, ZIPC_GE, ZIPC_C, ZIPC_V
64 2 dgisselq
        } ZIPCOND;
65
 
66 69 dgisselq
        typedef enum {
67
                // 16 ALU instructions
68
                ZIPO_SUB=0, ZIPO_AND, ZIPO_ADD, ZIPO_OR, // 5'h000xx
69
                ZIPO_XOR, ZIPO_LSR, ZIPO_LSL, ZIPO_ASR,         // 5'h001xx
70
                ZIPO_LDIHI, ZIPO_LDILO, ZIPO_MPYU, ZIPO_MPYS,   // 5'h010xx
71
                ZIPO_BREV, ZIPO_POPC, ZIPO_ROL, ZIPO_MOV,       // 5'h011xx
72
                ZIPO_CMP, ZIPO_TST,                             // 5'h1000x
73
                ZIPO_LOD, ZIPO_STO,                             // 5'h1001w
74
                ZIPO_DIVU, ZIPO_DIVS,                           // 5'h1010s
75
                ZIPO_LDI, ZIPO_LDIn,                            // 5'h1011x
76
                // ZIPO_, ZIPO_DIVS,                            // 5'h11000
77
                ZIPO_FPADD=0x18, ZIPO_FPSUB,                    // 5'h1100x
78
                ZIPO_FPMUL, ZIPO_FPDIV,                         // 5'h1101x
79
                ZIPO_FPCVT, ZIPO_FPINT,                         // 5'h1110x
80
        } ZIPOP;
81 2 dgisselq
 
82 126 dgisselq
#define ZIPO_MPY        ZIPO_LDIHI
83
#define ZIPO_MPYSHI     ZIPO_MPYS
84
#define ZIPO_MPYUHI     ZIPO_MPYU
85 69 dgisselq
 
86 126 dgisselq
        ZIPIMM  brev(ZIPIMM) const;
87
 
88 2 dgisselq
        ZIPI    op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
89
        ZIPI    op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
90
        ZIPI    op_cmp(ZIPIMM imm, ZIPREG b, ZIPREG a) const
91
                { return op_cmp(ZIPC_ALWAYS, imm, b, a); }
92
        ZIPI    op_cmp(ZIPIMM imm, ZIPREG a) const
93
                { return op_cmp(ZIPC_ALWAYS, imm, a); }
94
 
95
        ZIPI    op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
96
        ZIPI    op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
97
        ZIPI    op_tst(ZIPIMM imm, ZIPREG a) const
98
                { return op_tst(ZIPC_ALWAYS, imm, a); }
99
        ZIPI    op_tst(ZIPCOND cnd, ZIPREG a) const
100
                { return op_tst(cnd, -1, a); }
101
 
102
        ZIPI    op_mov(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
103
        ZIPI    op_mov(ZIPIMM imm, ZIPREG b, ZIPREG a) const
104
                { return op_mov(ZIPC_ALWAYS, imm, b, a); }
105
        ZIPI    op_mov(ZIPREG b, ZIPREG a) const
106
                { return op_mov(ZIPC_ALWAYS, 0, b, a); }
107
 
108
        ZIPI    op_ldi(ZIPIMM imm, ZIPREG a) const;
109
        ZIPI    op_trap(ZIPCOND cnd, ZIPIMM imm) const;
110
        ZIPI    op_trap(ZIPIMM imm) const
111
                { return op_trap(ZIPC_ALWAYS, imm); }
112
        ZIPI    op_clr(ZIPREG a) const { return op_ldi(0, a); }
113
 
114
        ZIPI    op_noop(void) const;
115
        ZIPI    op_break(void) const;
116 69 dgisselq
        ZIPI    op_lock(void) const;
117 2 dgisselq
 
118 126 dgisselq
        ZIPI    op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
119
        ZIPI    op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
120
//
121 2 dgisselq
        ZIPI    op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
122
        ZIPI    op_ldihi(ZIPIMM imm, ZIPREG a) const
123
                { return op_ldihi(ZIPC_ALWAYS, imm, a); }
124 126 dgisselq
        ZIPI    op_ldilo(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
125 2 dgisselq
        ZIPI    op_ldilo(ZIPIMM imm, ZIPREG a) const
126
                { return op_ldilo(ZIPC_ALWAYS, imm, a); }
127
 
128 26 dgisselq
        ZIPI    op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
129
        ZIPI    op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
130
        ZIPI    op_mpyu(ZIPIMM imm, ZIPREG b, ZIPREG a) const
131
                { return op_mpyu(ZIPC_ALWAYS, imm, b, a); }
132
        ZIPI    op_mpyu(ZIPIMM imm, ZIPREG a) const
133
                { return op_mpyu(ZIPC_ALWAYS, imm, a); }
134 126 dgisselq
//
135
        ZIPI    op_mpyuhi(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const
136
                { return op_mpyu(cnd,imm,b,a); }
137
        ZIPI    op_mpyuhi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const
138
                { return op_mpyu(cnd,imm,a); }
139 8 dgisselq
 
140 26 dgisselq
        ZIPI    op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
141
        ZIPI    op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
142
        ZIPI    op_mpys(ZIPIMM imm, ZIPREG b, ZIPREG a) const
143
                { return op_mpys(ZIPC_ALWAYS, imm, b, a); }
144
        ZIPI    op_mpys(ZIPIMM imm, ZIPREG a) const
145
                { return op_mpys(ZIPC_ALWAYS, imm, a); }
146 126 dgisselq
//
147
        ZIPI    op_mpyshi(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const
148
                { return op_mpys(cnd,imm,b,a);  }
149
        ZIPI    op_mpyshi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const
150
                { return op_mpys(cnd,imm,a);    }
151 26 dgisselq
 
152 8 dgisselq
        ZIPI    op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
153
        ZIPI    op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
154
        ZIPI    op_rol(ZIPIMM imm, ZIPREG b, ZIPREG a) const
155
                { return op_rol(ZIPC_ALWAYS, imm, b, a); }
156
        ZIPI    op_rol(ZIPIMM imm, ZIPREG a) const
157
                { return op_rol(ZIPC_ALWAYS, imm, a); }
158
 
159 69 dgisselq
        ZIPI    op_popc(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
160
        ZIPI    op_popc(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
161
        ZIPI    op_popc(ZIPIMM imm, ZIPREG b, ZIPREG a) const
162
                { return op_popc(ZIPC_ALWAYS, imm, b, a); }
163
        ZIPI    op_popc(ZIPIMM imm, ZIPREG a) const
164
                { return op_popc(ZIPC_ALWAYS, imm, a); }
165
 
166
        ZIPI    op_brev(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
167
        ZIPI    op_brev(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
168
        ZIPI    op_brev(ZIPIMM imm, ZIPREG b, ZIPREG a) const
169
                { return op_brev(ZIPC_ALWAYS, imm, b, a); }
170
        ZIPI    op_brev(ZIPIMM imm, ZIPREG a) const
171
                { return op_brev(ZIPC_ALWAYS, imm, a); }
172
 
173 2 dgisselq
        ZIPI    op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
174
        ZIPI    op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
175
        ZIPI    op_lod(ZIPIMM imm, ZIPREG b, ZIPREG a) const
176
                { return op_lod(ZIPC_ALWAYS, imm, b, a); }
177
        ZIPI    op_lod(ZIPIMM imm, ZIPREG a) const
178
                { return op_lod(ZIPC_ALWAYS, imm, a); }
179
 
180
        ZIPI    op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm, ZIPREG b) const;
181
        ZIPI    op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm) const;
182
        ZIPI    op_sto(ZIPREG v, ZIPIMM imm, ZIPREG b) const
183
                { return op_sto(ZIPC_ALWAYS, v, imm, b); }
184
        ZIPI    op_sto(ZIPREG v, ZIPIMM imm) const
185
                { return op_sto(ZIPC_ALWAYS, v, imm); }
186
 
187
        ZIPI    op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
188
        ZIPI    op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
189
        ZIPI    op_sub(ZIPIMM imm, ZIPREG b, ZIPREG a) const
190
                { return op_sub(ZIPC_ALWAYS, imm, b, a); }
191
        ZIPI    op_sub(ZIPIMM imm, ZIPREG a) const
192
                { return op_sub(ZIPC_ALWAYS, imm, a); }
193
 
194
        ZIPI    op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
195
        ZIPI    op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
196
        ZIPI    op_and(ZIPIMM imm, ZIPREG b, ZIPREG a) const
197
                { return op_and(ZIPC_ALWAYS, imm, b, a); }
198
        ZIPI    op_and(ZIPIMM imm, ZIPREG a) const
199
                { return op_and(ZIPC_ALWAYS, imm, a); }
200
 
201
        ZIPI    op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
202
        ZIPI    op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
203
        ZIPI    op_add(ZIPIMM imm, ZIPREG b, ZIPREG a) const
204
                { return op_add(ZIPC_ALWAYS, imm, b, a); }
205
        ZIPI    op_add(ZIPIMM imm, ZIPREG a) const      // GOOD
206
                { return op_add(ZIPC_ALWAYS, imm, a); }
207
 
208
        ZIPI    op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
209
        ZIPI    op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
210
        ZIPI    op_or(ZIPIMM imm, ZIPREG b, ZIPREG a) const
211
                { return op_or(ZIPC_ALWAYS, imm, b, a); }
212
        ZIPI    op_or(ZIPIMM imm, ZIPREG a) const
213
                { return op_or(ZIPC_ALWAYS, imm, a); }
214
 
215
        ZIPI    op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
216
        ZIPI    op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
217
        ZIPI    op_xor(ZIPIMM imm, ZIPREG b, ZIPREG a) const
218
                { return op_xor(ZIPC_ALWAYS, imm, b, a); }
219
        ZIPI    op_xor(ZIPIMM imm, ZIPREG a) const
220
                { return op_xor(ZIPC_ALWAYS, imm, a); }
221
 
222
        ZIPI    op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
223
        ZIPI    op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
224
        ZIPI    op_lsl(ZIPIMM imm, ZIPREG b, ZIPREG a) const
225
                { return op_lsl(ZIPC_ALWAYS, imm, b, a); }
226
        ZIPI    op_lsl(ZIPIMM imm, ZIPREG a) const
227
                { return op_lsl(ZIPC_ALWAYS, imm, a); }
228
        ZIPI    op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const
229
                { return op_lsl(cnd, imm, b, a); }
230
        ZIPI    op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const
231
                { return op_lsl(cnd, imm, a); }
232
        ZIPI    op_asl(ZIPIMM imm, ZIPREG b, ZIPREG a) const
233
                { return op_lsl(ZIPC_ALWAYS, imm, b, a); }
234
        ZIPI    op_asl(ZIPIMM imm, ZIPREG a) const
235
                { return op_lsl(ZIPC_ALWAYS, imm, a); }
236
 
237
        ZIPI    op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
238
        ZIPI    op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
239
        ZIPI    op_asr(ZIPIMM imm, ZIPREG b, ZIPREG a) const
240
                { return op_asr(ZIPC_ALWAYS, imm, b, a); }
241
        ZIPI    op_asr(ZIPIMM imm, ZIPREG a) const
242
                { return op_asr(ZIPC_ALWAYS, imm, a); }
243
 
244
        ZIPI    op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
245
        ZIPI    op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
246
        ZIPI    op_lsr(ZIPIMM imm, ZIPREG b, ZIPREG a) const
247
                { return op_lsr(ZIPC_ALWAYS, imm, b, a); }
248
        ZIPI    op_lsr(ZIPIMM imm, ZIPREG a) const
249
                { return op_lsr(ZIPC_ALWAYS, imm, a); }
250
 
251
        ZIPI    op_bra(ZIPCOND cnd, ZIPIMM imm) const
252 100 dgisselq
                { return op_add(cnd, imm, ZIP_PC); }
253 2 dgisselq
        ZIPI    op_bra(ZIPIMM imm) const
254 89 dgisselq
                { return op_add(ZIPC_ALWAYS, imm, ZIP_PC); }
255 2 dgisselq
        ZIPI    op_brz(ZIPIMM imm) const
256 100 dgisselq
                { return op_add(ZIPC_Z, imm, ZIP_PC); }
257 2 dgisselq
        ZIPI    op_bnz(ZIPIMM imm) const
258 100 dgisselq
                { return op_add(ZIPC_NZ, imm, ZIP_PC); }
259 2 dgisselq
        ZIPI    op_bge(ZIPIMM imm) const
260 100 dgisselq
                { return op_add(ZIPC_GE, imm, ZIP_PC); }
261 2 dgisselq
        ZIPI    op_bgt(ZIPIMM imm) const
262 100 dgisselq
                { return op_add(ZIPC_GT, imm, ZIP_PC); }
263 2 dgisselq
        ZIPI    op_blt(ZIPIMM imm) const
264 100 dgisselq
                { return op_add(ZIPC_LT, imm, ZIP_PC); }
265 2 dgisselq
        ZIPI    op_brc(ZIPIMM imm) const
266 100 dgisselq
                { return op_add(ZIPC_C, imm, ZIP_PC); }
267 2 dgisselq
        ZIPI    op_brv(ZIPIMM imm) const
268 100 dgisselq
                { return op_add(ZIPC_V, imm, ZIP_PC); }
269 2 dgisselq
        ZIPI    op_bv(ZIPIMM imm) const
270
                { return op_brv(imm); }
271
 
272
        ZIPI    op_clrf(ZIPCOND cnd, ZIPREG a) const
273
                { return op_xor(cnd, 0, a, a); }
274
        ZIPI    op_clrf(ZIPREG a) const
275
                { return op_xor(ZIPC_ALWAYS, 0, a, a); }
276 69 dgisselq
        // ZIPI op_retn(ZIPCOND c) const
277
                // { return op_lod(c, 1, ZIP_SP, ZIP_PC); }
278 2 dgisselq
        ZIPI    op_halt(ZIPCOND c) const {
279
                return op_or(c, 0x10, ZIP_CC); }
280
        ZIPI    op_wait(ZIPCOND c) const {
281 69 dgisselq
                return op_or(c, 0x30, ZIP_CC); }
282 2 dgisselq
        ZIPI    op_halt(void) const {
283
                return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); }
284
        ZIPI    op_wait(void) const {
285
                return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); }
286
        ZIPI    op_busy(ZIPCOND c) const {
287 100 dgisselq
                return op_add(c, -1, ZIP_PC); }
288 2 dgisselq
        ZIPI    op_busy(void) const {
289 100 dgisselq
                return op_add(ZIPC_ALWAYS, -1, ZIP_PC); }
290 2 dgisselq
 
291
        ZIPI    op_rtu(void) const {
292
                return op_or(ZIPC_ALWAYS, 0x20, ZIP_CC); }
293
        ZIPI    op_rtu(ZIPCOND cnd) const {
294
                return op_or(cnd, 0x20, ZIP_CC); }
295
 
296
        ZIPI    op_jmp(ZIPCOND c, ZIPIMM imm, ZIPREG r) const
297
                { return op_mov(ZIPC_ALWAYS, imm, r, ZIP_PC); }
298
 
299 100 dgisselq
        ZIPI    op_ljmp(void) const { return 0x7c87c000; }
300
 
301 2 dgisselq
        ZIPI    op_ljmp(ZIPCOND c, ZIPIMM imm) const {
302
                return op_add(ZIPC_ALWAYS, imm, ZIP_PC); }
303
 
304
        ZIPI    op_not(ZIPCOND c, ZIPREG r) const
305
                { return op_xor(c, -1, r); }
306
        ZIPI    op_not(ZIPREG r) const
307
                { return op_xor(ZIPC_ALWAYS, -1, r); }
308
 
309 69 dgisselq
        ZIPI    op_divu(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
310
        ZIPI    op_divu(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
311
        ZIPI    op_divs(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
312
        ZIPI    op_divs(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
313
 
314
        bool    can_merge(const ZIPI a, const ZIPI b);
315
        ZIPI    merge(const ZIPI a, const ZIPI b);
316
        ZIPIMM  immediate(const ZIPI a);
317
 
318 2 dgisselq
};
319
 
320
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.