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

Subversion Repositories zipcpu

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

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 69 dgisselq
 
83 2 dgisselq
        ZIPI    op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
84
        ZIPI    op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
85
        ZIPI    op_cmp(ZIPIMM imm, ZIPREG b, ZIPREG a) const
86
                { return op_cmp(ZIPC_ALWAYS, imm, b, a); }
87
        ZIPI    op_cmp(ZIPIMM imm, ZIPREG a) const
88
                { return op_cmp(ZIPC_ALWAYS, imm, a); }
89
 
90
        ZIPI    op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
91
        ZIPI    op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
92
        ZIPI    op_tst(ZIPIMM imm, ZIPREG a) const
93
                { return op_tst(ZIPC_ALWAYS, imm, a); }
94
        ZIPI    op_tst(ZIPCOND cnd, ZIPREG a) const
95
                { return op_tst(cnd, -1, a); }
96
 
97
        ZIPI    op_mov(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
98
        ZIPI    op_mov(ZIPIMM imm, ZIPREG b, ZIPREG a) const
99
                { return op_mov(ZIPC_ALWAYS, imm, b, a); }
100
        ZIPI    op_mov(ZIPREG b, ZIPREG a) const
101
                { return op_mov(ZIPC_ALWAYS, 0, b, a); }
102
 
103
        ZIPI    op_ldi(ZIPIMM imm, ZIPREG a) const;
104
        ZIPI    op_trap(ZIPCOND cnd, ZIPIMM imm) const;
105
        ZIPI    op_trap(ZIPIMM imm) const
106
                { return op_trap(ZIPC_ALWAYS, imm); }
107
        ZIPI    op_clr(ZIPREG a) const { return op_ldi(0, a); }
108
 
109
        ZIPI    op_noop(void) const;
110
        ZIPI    op_break(void) const;
111 69 dgisselq
        ZIPI    op_lock(void) const;
112 2 dgisselq
 
113
        ZIPI    op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
114
        ZIPI    op_ldilo(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
115
        ZIPI    op_ldihi(ZIPIMM imm, ZIPREG a) const
116
                { return op_ldihi(ZIPC_ALWAYS, imm, a); }
117
        ZIPI    op_ldilo(ZIPIMM imm, ZIPREG a) const
118
                { return op_ldilo(ZIPC_ALWAYS, imm, a); }
119
 
120 26 dgisselq
        ZIPI    op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
121
        ZIPI    op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
122
        ZIPI    op_mpyu(ZIPIMM imm, ZIPREG b, ZIPREG a) const
123
                { return op_mpyu(ZIPC_ALWAYS, imm, b, a); }
124
        ZIPI    op_mpyu(ZIPIMM imm, ZIPREG a) const
125
                { return op_mpyu(ZIPC_ALWAYS, imm, a); }
126 8 dgisselq
 
127 26 dgisselq
        ZIPI    op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
128
        ZIPI    op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
129
        ZIPI    op_mpys(ZIPIMM imm, ZIPREG b, ZIPREG a) const
130
                { return op_mpys(ZIPC_ALWAYS, imm, b, a); }
131
        ZIPI    op_mpys(ZIPIMM imm, ZIPREG a) const
132
                { return op_mpys(ZIPC_ALWAYS, imm, a); }
133
 
134 8 dgisselq
        ZIPI    op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
135
        ZIPI    op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
136
        ZIPI    op_rol(ZIPIMM imm, ZIPREG b, ZIPREG a) const
137
                { return op_rol(ZIPC_ALWAYS, imm, b, a); }
138
        ZIPI    op_rol(ZIPIMM imm, ZIPREG a) const
139
                { return op_rol(ZIPC_ALWAYS, imm, a); }
140
 
141 69 dgisselq
        ZIPI    op_popc(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
142
        ZIPI    op_popc(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
143
        ZIPI    op_popc(ZIPIMM imm, ZIPREG b, ZIPREG a) const
144
                { return op_popc(ZIPC_ALWAYS, imm, b, a); }
145
        ZIPI    op_popc(ZIPIMM imm, ZIPREG a) const
146
                { return op_popc(ZIPC_ALWAYS, imm, a); }
147
 
148
        ZIPI    op_brev(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
149
        ZIPI    op_brev(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
150
        ZIPI    op_brev(ZIPIMM imm, ZIPREG b, ZIPREG a) const
151
                { return op_brev(ZIPC_ALWAYS, imm, b, a); }
152
        ZIPI    op_brev(ZIPIMM imm, ZIPREG a) const
153
                { return op_brev(ZIPC_ALWAYS, imm, a); }
154
 
155 2 dgisselq
        ZIPI    op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
156
        ZIPI    op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
157
        ZIPI    op_lod(ZIPIMM imm, ZIPREG b, ZIPREG a) const
158
                { return op_lod(ZIPC_ALWAYS, imm, b, a); }
159
        ZIPI    op_lod(ZIPIMM imm, ZIPREG a) const
160
                { return op_lod(ZIPC_ALWAYS, imm, a); }
161
 
162
        ZIPI    op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm, ZIPREG b) const;
163
        ZIPI    op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm) const;
164
        ZIPI    op_sto(ZIPREG v, ZIPIMM imm, ZIPREG b) const
165
                { return op_sto(ZIPC_ALWAYS, v, imm, b); }
166
        ZIPI    op_sto(ZIPREG v, ZIPIMM imm) const
167
                { return op_sto(ZIPC_ALWAYS, v, imm); }
168
 
169
        ZIPI    op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
170
        ZIPI    op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
171
        ZIPI    op_sub(ZIPIMM imm, ZIPREG b, ZIPREG a) const
172
                { return op_sub(ZIPC_ALWAYS, imm, b, a); }
173
        ZIPI    op_sub(ZIPIMM imm, ZIPREG a) const
174
                { return op_sub(ZIPC_ALWAYS, imm, a); }
175
 
176
        ZIPI    op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
177
        ZIPI    op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
178
        ZIPI    op_and(ZIPIMM imm, ZIPREG b, ZIPREG a) const
179
                { return op_and(ZIPC_ALWAYS, imm, b, a); }
180
        ZIPI    op_and(ZIPIMM imm, ZIPREG a) const
181
                { return op_and(ZIPC_ALWAYS, imm, a); }
182
 
183
        ZIPI    op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
184
        ZIPI    op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
185
        ZIPI    op_add(ZIPIMM imm, ZIPREG b, ZIPREG a) const
186
                { return op_add(ZIPC_ALWAYS, imm, b, a); }
187
        ZIPI    op_add(ZIPIMM imm, ZIPREG a) const      // GOOD
188
                { return op_add(ZIPC_ALWAYS, imm, a); }
189
 
190
        ZIPI    op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
191
        ZIPI    op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
192
        ZIPI    op_or(ZIPIMM imm, ZIPREG b, ZIPREG a) const
193
                { return op_or(ZIPC_ALWAYS, imm, b, a); }
194
        ZIPI    op_or(ZIPIMM imm, ZIPREG a) const
195
                { return op_or(ZIPC_ALWAYS, imm, a); }
196
 
197
        ZIPI    op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
198
        ZIPI    op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
199
        ZIPI    op_xor(ZIPIMM imm, ZIPREG b, ZIPREG a) const
200
                { return op_xor(ZIPC_ALWAYS, imm, b, a); }
201
        ZIPI    op_xor(ZIPIMM imm, ZIPREG a) const
202
                { return op_xor(ZIPC_ALWAYS, imm, a); }
203
 
204
        ZIPI    op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
205
        ZIPI    op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
206
        ZIPI    op_lsl(ZIPIMM imm, ZIPREG b, ZIPREG a) const
207
                { return op_lsl(ZIPC_ALWAYS, imm, b, a); }
208
        ZIPI    op_lsl(ZIPIMM imm, ZIPREG a) const
209
                { return op_lsl(ZIPC_ALWAYS, imm, a); }
210
        ZIPI    op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const
211
                { return op_lsl(cnd, imm, b, a); }
212
        ZIPI    op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const
213
                { return op_lsl(cnd, imm, a); }
214
        ZIPI    op_asl(ZIPIMM imm, ZIPREG b, ZIPREG a) const
215
                { return op_lsl(ZIPC_ALWAYS, imm, b, a); }
216
        ZIPI    op_asl(ZIPIMM imm, ZIPREG a) const
217
                { return op_lsl(ZIPC_ALWAYS, imm, a); }
218
 
219
        ZIPI    op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
220
        ZIPI    op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
221
        ZIPI    op_asr(ZIPIMM imm, ZIPREG b, ZIPREG a) const
222
                { return op_asr(ZIPC_ALWAYS, imm, b, a); }
223
        ZIPI    op_asr(ZIPIMM imm, ZIPREG a) const
224
                { return op_asr(ZIPC_ALWAYS, imm, a); }
225
 
226
        ZIPI    op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
227
        ZIPI    op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
228
        ZIPI    op_lsr(ZIPIMM imm, ZIPREG b, ZIPREG a) const
229
                { return op_lsr(ZIPC_ALWAYS, imm, b, a); }
230
        ZIPI    op_lsr(ZIPIMM imm, ZIPREG a) const
231
                { return op_lsr(ZIPC_ALWAYS, imm, a); }
232
 
233
        ZIPI    op_bra(ZIPCOND cnd, ZIPIMM imm) const
234 100 dgisselq
                { return op_add(cnd, imm, ZIP_PC); }
235 2 dgisselq
        ZIPI    op_bra(ZIPIMM imm) const
236 89 dgisselq
                { return op_add(ZIPC_ALWAYS, imm, ZIP_PC); }
237 2 dgisselq
        ZIPI    op_brz(ZIPIMM imm) const
238 100 dgisselq
                { return op_add(ZIPC_Z, imm, ZIP_PC); }
239 2 dgisselq
        ZIPI    op_bnz(ZIPIMM imm) const
240 100 dgisselq
                { return op_add(ZIPC_NZ, imm, ZIP_PC); }
241 2 dgisselq
        ZIPI    op_bge(ZIPIMM imm) const
242 100 dgisselq
                { return op_add(ZIPC_GE, imm, ZIP_PC); }
243 2 dgisselq
        ZIPI    op_bgt(ZIPIMM imm) const
244 100 dgisselq
                { return op_add(ZIPC_GT, imm, ZIP_PC); }
245 2 dgisselq
        ZIPI    op_blt(ZIPIMM imm) const
246 100 dgisselq
                { return op_add(ZIPC_LT, imm, ZIP_PC); }
247 2 dgisselq
        ZIPI    op_brc(ZIPIMM imm) const
248 100 dgisselq
                { return op_add(ZIPC_C, imm, ZIP_PC); }
249 2 dgisselq
        ZIPI    op_brv(ZIPIMM imm) const
250 100 dgisselq
                { return op_add(ZIPC_V, imm, ZIP_PC); }
251 2 dgisselq
        ZIPI    op_bv(ZIPIMM imm) const
252
                { return op_brv(imm); }
253
 
254
        ZIPI    op_clrf(ZIPCOND cnd, ZIPREG a) const
255
                { return op_xor(cnd, 0, a, a); }
256
        ZIPI    op_clrf(ZIPREG a) const
257
                { return op_xor(ZIPC_ALWAYS, 0, a, a); }
258 69 dgisselq
        // ZIPI op_retn(ZIPCOND c) const
259
                // { return op_lod(c, 1, ZIP_SP, ZIP_PC); }
260 2 dgisselq
        ZIPI    op_halt(ZIPCOND c) const {
261
                return op_or(c, 0x10, ZIP_CC); }
262
        ZIPI    op_wait(ZIPCOND c) const {
263 69 dgisselq
                return op_or(c, 0x30, ZIP_CC); }
264 2 dgisselq
        ZIPI    op_halt(void) const {
265
                return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); }
266
        ZIPI    op_wait(void) const {
267
                return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); }
268
        ZIPI    op_busy(ZIPCOND c) const {
269 100 dgisselq
                return op_add(c, -1, ZIP_PC); }
270 2 dgisselq
        ZIPI    op_busy(void) const {
271 100 dgisselq
                return op_add(ZIPC_ALWAYS, -1, ZIP_PC); }
272 2 dgisselq
 
273
        ZIPI    op_rtu(void) const {
274
                return op_or(ZIPC_ALWAYS, 0x20, ZIP_CC); }
275
        ZIPI    op_rtu(ZIPCOND cnd) const {
276
                return op_or(cnd, 0x20, ZIP_CC); }
277
 
278
        ZIPI    op_jmp(ZIPCOND c, ZIPIMM imm, ZIPREG r) const
279
                { return op_mov(ZIPC_ALWAYS, imm, r, ZIP_PC); }
280
 
281 100 dgisselq
        ZIPI    op_ljmp(void) const { return 0x7c87c000; }
282
 
283 2 dgisselq
        ZIPI    op_ljmp(ZIPCOND c, ZIPIMM imm) const {
284
                return op_add(ZIPC_ALWAYS, imm, ZIP_PC); }
285
 
286
        ZIPI    op_not(ZIPCOND c, ZIPREG r) const
287
                { return op_xor(c, -1, r); }
288
        ZIPI    op_not(ZIPREG r) const
289
                { return op_xor(ZIPC_ALWAYS, -1, r); }
290
 
291 69 dgisselq
        ZIPI    op_divu(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
292
        ZIPI    op_divu(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
293
        ZIPI    op_divs(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
294
        ZIPI    op_divs(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
295
 
296
        bool    can_merge(const ZIPI a, const ZIPI b);
297
        ZIPI    merge(const ZIPI a, const ZIPI b);
298
        ZIPIMM  immediate(const ZIPI a);
299
 
300 2 dgisselq
};
301
 
302
#endif

powered by: WebSVN 2.1.0

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