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

Subversion Repositories zipcpu

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

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
//              Gisselquist Tecnology, LLC
18
//
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
                ZIPC_ALWAYS, ZIPC_Z, ZIPC_NZ, ZIPC_GE, ZIPC_GT, ZIPC_LT,
63
                ZIPC_C, ZIPC_V
64
        } ZIPCOND;
65
 
66
 
67
        ZIPI    op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
68
        ZIPI    op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
69
        ZIPI    op_cmp(ZIPIMM imm, ZIPREG b, ZIPREG a) const
70
                { return op_cmp(ZIPC_ALWAYS, imm, b, a); }
71
        ZIPI    op_cmp(ZIPIMM imm, ZIPREG a) const
72
                { return op_cmp(ZIPC_ALWAYS, imm, a); }
73
 
74
        ZIPI    op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
75
        ZIPI    op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
76
        ZIPI    op_tst(ZIPIMM imm, ZIPREG a) const
77
                { return op_tst(ZIPC_ALWAYS, imm, a); }
78
        ZIPI    op_tst(ZIPCOND cnd, ZIPREG a) const
79
                { return op_tst(cnd, -1, a); }
80
 
81
        ZIPI    op_mov(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
82
        ZIPI    op_mov(ZIPIMM imm, ZIPREG b, ZIPREG a) const
83
                { return op_mov(ZIPC_ALWAYS, imm, b, a); }
84
        ZIPI    op_mov(ZIPREG b, ZIPREG a) const
85
                { return op_mov(ZIPC_ALWAYS, 0, b, a); }
86
 
87
        ZIPI    op_ldi(ZIPIMM imm, ZIPREG a) const;
88
        ZIPI    op_trap(ZIPCOND cnd, ZIPIMM imm) const;
89
        ZIPI    op_trap(ZIPIMM imm) const
90
                { return op_trap(ZIPC_ALWAYS, imm); }
91
        ZIPI    op_clr(ZIPREG a) const { return op_ldi(0, a); }
92
 
93
        ZIPI    op_noop(void) const;
94
        ZIPI    op_break(void) const;
95
 
96
        ZIPI    op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
97
        ZIPI    op_ldilo(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
98
        ZIPI    op_ldihi(ZIPIMM imm, ZIPREG a) const
99
                { return op_ldihi(ZIPC_ALWAYS, imm, a); }
100
        ZIPI    op_ldilo(ZIPIMM imm, ZIPREG a) const
101
                { return op_ldilo(ZIPC_ALWAYS, imm, a); }
102
 
103 26 dgisselq
        ZIPI    op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
104
        ZIPI    op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
105
        ZIPI    op_mpyu(ZIPIMM imm, ZIPREG b, ZIPREG a) const
106
                { return op_mpyu(ZIPC_ALWAYS, imm, b, a); }
107
        ZIPI    op_mpyu(ZIPIMM imm, ZIPREG a) const
108
                { return op_mpyu(ZIPC_ALWAYS, imm, a); }
109 8 dgisselq
 
110 26 dgisselq
        ZIPI    op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
111
        ZIPI    op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
112
        ZIPI    op_mpys(ZIPIMM imm, ZIPREG b, ZIPREG a) const
113
                { return op_mpys(ZIPC_ALWAYS, imm, b, a); }
114
        ZIPI    op_mpys(ZIPIMM imm, ZIPREG a) const
115
                { return op_mpys(ZIPC_ALWAYS, imm, a); }
116
 
117 8 dgisselq
        ZIPI    op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
118
        ZIPI    op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
119
        ZIPI    op_rol(ZIPIMM imm, ZIPREG b, ZIPREG a) const
120
                { return op_rol(ZIPC_ALWAYS, imm, b, a); }
121
        ZIPI    op_rol(ZIPIMM imm, ZIPREG a) const
122
                { return op_rol(ZIPC_ALWAYS, imm, a); }
123
 
124 2 dgisselq
        ZIPI    op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
125
        ZIPI    op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
126
        ZIPI    op_lod(ZIPIMM imm, ZIPREG b, ZIPREG a) const
127
                { return op_lod(ZIPC_ALWAYS, imm, b, a); }
128
        ZIPI    op_lod(ZIPIMM imm, ZIPREG a) const
129
                { return op_lod(ZIPC_ALWAYS, imm, a); }
130
 
131
        ZIPI    op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm, ZIPREG b) const;
132
        ZIPI    op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm) const;
133
        ZIPI    op_sto(ZIPREG v, ZIPIMM imm, ZIPREG b) const
134
                { return op_sto(ZIPC_ALWAYS, v, imm, b); }
135
        ZIPI    op_sto(ZIPREG v, ZIPIMM imm) const
136
                { return op_sto(ZIPC_ALWAYS, v, imm); }
137
 
138
        ZIPI    op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
139
        ZIPI    op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
140
        ZIPI    op_sub(ZIPIMM imm, ZIPREG b, ZIPREG a) const
141
                { return op_sub(ZIPC_ALWAYS, imm, b, a); }
142
        ZIPI    op_sub(ZIPIMM imm, ZIPREG a) const
143
                { return op_sub(ZIPC_ALWAYS, imm, a); }
144
 
145
        ZIPI    op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
146
        ZIPI    op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
147
        ZIPI    op_and(ZIPIMM imm, ZIPREG b, ZIPREG a) const
148
                { return op_and(ZIPC_ALWAYS, imm, b, a); }
149
        ZIPI    op_and(ZIPIMM imm, ZIPREG a) const
150
                { return op_and(ZIPC_ALWAYS, imm, a); }
151
 
152
        ZIPI    op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
153
        ZIPI    op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
154
        ZIPI    op_add(ZIPIMM imm, ZIPREG b, ZIPREG a) const
155
                { return op_add(ZIPC_ALWAYS, imm, b, a); }
156
        ZIPI    op_add(ZIPIMM imm, ZIPREG a) const      // GOOD
157
                { return op_add(ZIPC_ALWAYS, imm, a); }
158
 
159
        ZIPI    op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
160
        ZIPI    op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
161
        ZIPI    op_or(ZIPIMM imm, ZIPREG b, ZIPREG a) const
162
                { return op_or(ZIPC_ALWAYS, imm, b, a); }
163
        ZIPI    op_or(ZIPIMM imm, ZIPREG a) const
164
                { return op_or(ZIPC_ALWAYS, imm, a); }
165
 
166
        ZIPI    op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
167
        ZIPI    op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
168
        ZIPI    op_xor(ZIPIMM imm, ZIPREG b, ZIPREG a) const
169
                { return op_xor(ZIPC_ALWAYS, imm, b, a); }
170
        ZIPI    op_xor(ZIPIMM imm, ZIPREG a) const
171
                { return op_xor(ZIPC_ALWAYS, imm, a); }
172
 
173
        ZIPI    op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
174
        ZIPI    op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
175
        ZIPI    op_lsl(ZIPIMM imm, ZIPREG b, ZIPREG a) const
176
                { return op_lsl(ZIPC_ALWAYS, imm, b, a); }
177
        ZIPI    op_lsl(ZIPIMM imm, ZIPREG a) const
178
                { return op_lsl(ZIPC_ALWAYS, imm, a); }
179
        ZIPI    op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const
180
                { return op_lsl(cnd, imm, b, a); }
181
        ZIPI    op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const
182
                { return op_lsl(cnd, imm, a); }
183
        ZIPI    op_asl(ZIPIMM imm, ZIPREG b, ZIPREG a) const
184
                { return op_lsl(ZIPC_ALWAYS, imm, b, a); }
185
        ZIPI    op_asl(ZIPIMM imm, ZIPREG a) const
186
                { return op_lsl(ZIPC_ALWAYS, imm, a); }
187
 
188
        ZIPI    op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
189
        ZIPI    op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
190
        ZIPI    op_asr(ZIPIMM imm, ZIPREG b, ZIPREG a) const
191
                { return op_asr(ZIPC_ALWAYS, imm, b, a); }
192
        ZIPI    op_asr(ZIPIMM imm, ZIPREG a) const
193
                { return op_asr(ZIPC_ALWAYS, imm, a); }
194
 
195
        ZIPI    op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
196
        ZIPI    op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
197
        ZIPI    op_lsr(ZIPIMM imm, ZIPREG b, ZIPREG a) const
198
                { return op_lsr(ZIPC_ALWAYS, imm, b, a); }
199
        ZIPI    op_lsr(ZIPIMM imm, ZIPREG a) const
200
                { return op_lsr(ZIPC_ALWAYS, imm, a); }
201
 
202
        ZIPI    op_bra(ZIPCOND cnd, ZIPIMM imm) const
203
                { return op_mov(cnd, imm, ZIP_PC, ZIP_PC); }
204
        ZIPI    op_bra(ZIPIMM imm) const
205
                { return op_mov(ZIPC_ALWAYS, imm, ZIP_PC, ZIP_PC); }
206
        ZIPI    op_brz(ZIPIMM imm) const
207
                { return op_mov(ZIPC_Z, imm, ZIP_PC, ZIP_PC); }
208
        ZIPI    op_bnz(ZIPIMM imm) const
209
                { return op_mov(ZIPC_NZ, imm, ZIP_PC, ZIP_PC); }
210
        ZIPI    op_bge(ZIPIMM imm) const
211
                { return op_mov(ZIPC_GE, imm, ZIP_PC, ZIP_PC); }
212
        ZIPI    op_bgt(ZIPIMM imm) const
213
                { return op_mov(ZIPC_GT, imm, ZIP_PC, ZIP_PC); }
214
        ZIPI    op_blt(ZIPIMM imm) const
215
                { return op_mov(ZIPC_LT, imm, ZIP_PC, ZIP_PC); }
216
        ZIPI    op_brc(ZIPIMM imm) const
217
                { return op_mov(ZIPC_C, imm, ZIP_PC, ZIP_PC); }
218
        ZIPI    op_brv(ZIPIMM imm) const
219
                { return op_mov(ZIPC_V, imm, ZIP_PC, ZIP_PC); }
220
        ZIPI    op_bv(ZIPIMM imm) const
221
                { return op_brv(imm); }
222
 
223
        ZIPI    op_clrf(ZIPCOND cnd, ZIPREG a) const
224
                { return op_xor(cnd, 0, a, a); }
225
        ZIPI    op_clrf(ZIPREG a) const
226
                { return op_xor(ZIPC_ALWAYS, 0, a, a); }
227 46 dgisselq
        ZIPI    op_retn(ZIPCOND c) const
228
                { return op_lod(c, 1, ZIP_SP, ZIP_PC); }
229 2 dgisselq
        ZIPI    op_halt(ZIPCOND c) const {
230
                return op_or(c, 0x10, ZIP_CC); }
231
        ZIPI    op_wait(ZIPCOND c) const {
232
                return op_or(c, 0x10, ZIP_CC); }
233
        ZIPI    op_halt(void) const {
234
                return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); }
235
        ZIPI    op_wait(void) const {
236
                return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); }
237
        ZIPI    op_busy(ZIPCOND c) const {
238
                return op_mov(c, -1, ZIP_PC, ZIP_PC); }
239
        ZIPI    op_busy(void) const {
240
                return op_mov(ZIPC_ALWAYS, -1, ZIP_PC, ZIP_PC); }
241
 
242
        ZIPI    op_rtu(void) const {
243
                return op_or(ZIPC_ALWAYS, 0x20, ZIP_CC); }
244
        ZIPI    op_rtu(ZIPCOND cnd) const {
245
                return op_or(cnd, 0x20, ZIP_CC); }
246
 
247
        ZIPI    op_jmp(ZIPCOND c, ZIPIMM imm, ZIPREG r) const
248
                { return op_mov(ZIPC_ALWAYS, imm, r, ZIP_PC); }
249
 
250
        ZIPI    op_ljmp(ZIPCOND c, ZIPIMM imm) const {
251
                return op_add(ZIPC_ALWAYS, imm, ZIP_PC); }
252
 
253
        ZIPI    op_not(ZIPCOND c, ZIPREG r) const
254
                { return op_xor(c, -1, r); }
255
        ZIPI    op_not(ZIPREG r) const
256
                { return op_xor(ZIPC_ALWAYS, -1, r); }
257
 
258
};
259
 
260
#endif

powered by: WebSVN 2.1.0

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