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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zparser.cpp] - Blame information for rev 14

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

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    zparser.cpp
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 the parser for the Zip Assembler, zasm.  Since then, I
9
//              discovered Flex and Bison and have written a parser using
10
//              those tools.  The true parser may therefore be found in zasm.y.
11
//              This file, however, still contains some very valuable tools.
12
//              In particular, all of the routines used to build instructions
13
//              from the appropriate fields are kept in this file.  For example,
14
//              op_noop() returns the instruction code for a NOOP  instruction.
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
#include <stdio.h>
45
#include <stdlib.h>
46
#include <string.h>
47
#include <ctype.h>
48
#include <strings.h>
49
 
50
#include "zparser.h"
51
#include "zopcodes.h"
52
 
53
typedef ZPARSER::ZIPI ZIPI;     // A Zip Instruction (i.e. uint32)
54
 
55
#define IMMOP(OP,CND,IMM,A) (((OP&0x0f)<<28)|((A&0x0f)<<24)|((CND&0x07)<<21) \
56
                        | (IMM & 0x0fffff))
57
 
58
#define DBLREGOP(OP,CND,IMM,B,A) (((OP&0x0f)<<28)|((A&0x0f)<<24)        \
59
                        |((CND&0x07)<<21)|(1<<20)|((B&0x0f)<<16)         \
60
                        | (IMM & 0x0ffff))
61
 
62
ZIPI    ZPARSER::op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
63
        return DBLREGOP(0x0, cnd, imm, b, a);
64
}
65
 
66
ZIPI    ZPARSER::op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
67
        return IMMOP(0x0, cnd, imm, a);
68
}
69
 
70
 
71
ZIPI    ZPARSER::op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
72
        return DBLREGOP(0x1, cnd, imm, b, a);
73
} ZIPI  ZPARSER::op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
74
        return IMMOP(0x1, cnd, imm, a);
75
}
76
 
77
ZIPI    ZPARSER::op_mov(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
78
        ZIPI    in;
79
        in = (0x02 << 28)|((a&0x0f)<<24)|((cnd&0x07)<<21);
80
        in |= (a&0x10)<<16;
81
        in |= (b&0x0f)<<16;
82
        in |= (b&0x10)<<11;
83
        in |= imm & 0x07fff;
84
        return in;
85
}
86
 
87
 
88
ZIPI    ZPARSER::op_ldi(ZIPIMM imm, ZIPREG a) const {
89
        ZIPI    in;
90
        in = ((0x03)<<28) | ((a&0x0f)<<24) | (imm & ((1<<24)-1));
91
        return in;
92
}
93
 
94
ZIPI    ZPARSER::op_trap(ZIPCOND cnd, ZIPIMM imm) const {
95
        ZIPI    in;
96 13 dgisselq
        if (cnd != ZIPC_ALWAYS)
97
                return op_ldilo(cnd, imm, ZIP_CC);
98
        else
99
                return op_ldi(imm, ZIP_CC);
100
        // in  = ((0x4f)<<24)|((cnd&0x07)<<21)|(1<<20)|((0x0e)<<16);
101
        // in |= (imm & 0x0ffff);
102 2 dgisselq
        return in;
103
}
104
 
105
ZIPI    ZPARSER::op_noop(void) const {
106
        return 0x4e000000;
107
}
108
ZIPI    ZPARSER::op_break(void) const {
109
        return 0x4e000001;
110
}
111
 
112
ZIPI    ZPARSER::op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
113
        ZIPI    in;
114
        in  = ((0x4f)<<24)|((cnd&0x07)<<21)|(1<<20)|((a&0x0f)<<16);
115
        in |= (imm & 0x0ffff);
116
        return in;
117
}
118
ZIPI    ZPARSER::op_ldilo(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
119
        ZIPI    in;
120
        in  = ((0x4f)<<24)|((cnd&0x07)<<21)|(0<<20)|((a&0x0f)<<16);
121
        in |= (imm & 0x0ffff);
122
        return in;
123
}
124
 
125 8 dgisselq
ZIPI    ZPARSER::op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
126
        return DBLREGOP(0x4, cnd, imm, b, a);
127
} ZIPI  ZPARSER::op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
128
        return IMMOP(0x4, cnd, imm, a);
129
}
130
 
131
ZIPI    ZPARSER::op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
132
        return DBLREGOP(0x5, cnd, imm, b, a);
133
} ZIPI  ZPARSER::op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
134
        return IMMOP(0x5, cnd, imm, a);
135
}
136
 
137 2 dgisselq
ZIPI    ZPARSER::op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
138
        return DBLREGOP(0x6, cnd, imm, b, a);
139 8 dgisselq
} ZIPI  ZPARSER::op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
140 2 dgisselq
        return IMMOP(0x6, cnd, imm, a);
141
}
142
 
143
 
144
ZIPI    ZPARSER::op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm, ZIPREG b) const {
145
        return DBLREGOP(0x7, cnd, imm, b, v);
146
} ZIPI  ZPARSER::op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm) const {
147
        return IMMOP(0x7, cnd, imm, v);
148
}
149
 
150
 
151
ZIPI    ZPARSER::op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
152
        return DBLREGOP(0x8, cnd, imm, b, a);
153
} ZIPI  ZPARSER::op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
154
        return IMMOP(0x8, cnd, imm, a);
155
}
156
 
157
 
158
ZIPI    ZPARSER::op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
159
        return DBLREGOP(0x9, cnd, imm, b, a);
160
} ZIPI  ZPARSER::op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
161
        return IMMOP(0x9, cnd, imm, a);
162
}
163
 
164
 
165
ZIPI    ZPARSER::op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
166
        return DBLREGOP(0xa, cnd, imm, b, a);
167
} ZIPI  ZPARSER::op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
168
        return IMMOP(0xa, cnd, imm, a);
169
}
170
 
171
 
172
ZIPI    ZPARSER::op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
173
        return DBLREGOP(0xb, cnd, imm, b, a);
174
} ZIPI  ZPARSER::op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
175
        return IMMOP(0xb, cnd, imm, a);
176
}
177
 
178
ZIPI    ZPARSER::op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
179
        return DBLREGOP(0xc, cnd, imm, b, a);
180
} ZIPI  ZPARSER::op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
181
        return IMMOP(0xc, cnd, imm, a);
182
}
183
 
184
ZIPI    ZPARSER::op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
185
        return DBLREGOP(0xd, cnd, imm, b, a);
186
} ZIPI  ZPARSER::op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
187
        return IMMOP(0xd, cnd, imm, a);
188
}
189
 
190
ZIPI    ZPARSER::op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
191
        return DBLREGOP(0xe, cnd, imm, b, a);
192
} ZIPI  ZPARSER::op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
193
        return IMMOP(0xe, cnd, imm, a);
194
}
195
 
196
ZIPI    ZPARSER::op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
197
        return DBLREGOP(0xf, cnd, imm, b, a);
198
} ZIPI  ZPARSER::op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
199
        return IMMOP(0xf, cnd, imm, a);
200
}
201
 

powered by: WebSVN 2.1.0

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