Entering debug mode now jumps to "dynamic rom"
[riscv-isa-sim.git] / riscv / opcodes.h
1 #include "encoding.h"
2
3 #define ZERO 0
4 #define T0 5
5 #define S0 8
6 #define S1 9
7
8 static uint32_t bits(uint32_t value, unsigned int hi, unsigned int lo) {
9 return (value >> lo) & ((1 << (hi+1-lo)) - 1);
10 }
11
12 static uint32_t bit(uint32_t value, unsigned int b) {
13 return (value >> b) & 1;
14 }
15
16 static uint32_t jal(unsigned int rd, uint32_t imm) __attribute__ ((unused));
17 static uint32_t jal(unsigned int rd, uint32_t imm) {
18 return (bit(imm, 20) << 31) |
19 (bits(imm, 10, 1) << 21) |
20 (bit(imm, 11) << 20) |
21 (bits(imm, 19, 12) << 12) |
22 (rd << 7) |
23 MATCH_JAL;
24 }
25
26 static uint32_t csrsi(unsigned int csr, uint16_t imm) __attribute__ ((unused));
27 static uint32_t csrsi(unsigned int csr, uint16_t imm) {
28 return (csr << 20) |
29 (bits(imm, 4, 0) << 15) |
30 MATCH_CSRRSI;
31 }
32
33 static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
34 static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset)
35 {
36 return (bits(offset, 11, 5) << 25) |
37 (src << 20) |
38 (base << 15) |
39 (bits(offset, 4, 0) << 7) |
40 MATCH_SW;
41 }
42
43 static uint32_t sd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
44 static uint32_t sd(unsigned int src, unsigned int base, uint16_t offset)
45 {
46 return (bits(offset, 11, 5) << 25) |
47 (src << 20) |
48 (base << 15) |
49 (bits(offset, 4, 0) << 7) |
50 MATCH_SD;
51 }
52
53 static uint32_t sh(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
54 static uint32_t sh(unsigned int src, unsigned int base, uint16_t offset)
55 {
56 return (bits(offset, 11, 5) << 25) |
57 (src << 20) |
58 (base << 15) |
59 (bits(offset, 4, 0) << 7) |
60 MATCH_SH;
61 }
62
63 static uint32_t sb(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
64 static uint32_t sb(unsigned int src, unsigned int base, uint16_t offset)
65 {
66 return (bits(offset, 11, 5) << 25) |
67 (src << 20) |
68 (base << 15) |
69 (bits(offset, 4, 0) << 7) |
70 MATCH_SB;
71 }
72
73 static uint32_t ld(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
74 static uint32_t ld(unsigned int rd, unsigned int base, uint16_t offset)
75 {
76 return (bits(offset, 11, 0) << 20) |
77 (base << 15) |
78 (bits(rd, 4, 0) << 7) |
79 MATCH_LD;
80 }
81
82 static uint32_t lw(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
83 static uint32_t lw(unsigned int rd, unsigned int base, uint16_t offset)
84 {
85 return (bits(offset, 11, 0) << 20) |
86 (base << 15) |
87 (bits(rd, 4, 0) << 7) |
88 MATCH_LW;
89 }
90
91 static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
92 static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset)
93 {
94 return (bits(offset, 11, 0) << 20) |
95 (base << 15) |
96 (bits(rd, 4, 0) << 7) |
97 MATCH_LH;
98 }
99
100 static uint32_t lb(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
101 static uint32_t lb(unsigned int rd, unsigned int base, uint16_t offset)
102 {
103 return (bits(offset, 11, 0) << 20) |
104 (base << 15) |
105 (bits(rd, 4, 0) << 7) |
106 MATCH_LB;
107 }
108
109 static uint32_t csrw(unsigned int source, unsigned int csr) __attribute__ ((unused));
110 static uint32_t csrw(unsigned int source, unsigned int csr) {
111 return (csr << 20) | (source << 15) | MATCH_CSRRW;
112 }
113
114 static uint32_t addi(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
115 static uint32_t addi(unsigned int dest, unsigned int src, uint16_t imm)
116 {
117 return (bits(imm, 11, 0) << 20) |
118 (src << 15) |
119 (dest << 7) |
120 MATCH_ADDI;
121 }
122
123 static uint32_t csrr(unsigned int rd, unsigned int csr) __attribute__ ((unused));
124 static uint32_t csrr(unsigned int rd, unsigned int csr) {
125 return (csr << 20) | (rd << 7) | MATCH_CSRRS;
126 }
127
128 static uint32_t fsw(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
129 static uint32_t fsw(unsigned int src, unsigned int base, uint16_t offset)
130 {
131 return (bits(offset, 11, 5) << 25) |
132 (bits(src, 4, 0) << 20) |
133 (base << 15) |
134 (bits(offset, 4, 0) << 7) |
135 MATCH_FSW;
136 }
137
138 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
139 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset)
140 {
141 return (bits(offset, 11, 5) << 25) |
142 (bits(src, 4, 0) << 20) |
143 (base << 15) |
144 (bits(offset, 4, 0) << 7) |
145 MATCH_FSD;
146 }
147
148 static uint32_t flw(unsigned int dest, unsigned int base, uint16_t offset) __attribute__ ((unused));
149 static uint32_t flw(unsigned int dest, unsigned int base, uint16_t offset)
150 {
151 return (bits(offset, 11, 0) << 20) |
152 (base << 15) |
153 (bits(dest, 4, 0) << 7) |
154 MATCH_FLW;
155 }
156
157 static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset) __attribute__ ((unused));
158 static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset)
159 {
160 return (bits(offset, 11, 0) << 20) |
161 (base << 15) |
162 (bits(dest, 4, 0) << 7) |
163 MATCH_FLD;
164 }
165
166 static uint32_t ebreak(void) __attribute__ ((unused));
167 static uint32_t ebreak(void) { return MATCH_EBREAK; }
168 static uint32_t ebreak_c(void) __attribute__ ((unused));
169 static uint32_t ebreak_c(void) { return MATCH_C_EBREAK; }
170
171 static uint32_t fence_i(void) __attribute__ ((unused));
172 static uint32_t fence_i(void)
173 {
174 return MATCH_FENCE_I;
175 }
176
177 /*
178 static uint32_t lui(unsigned int dest, uint32_t imm) __attribute__ ((unused));
179 static uint32_t lui(unsigned int dest, uint32_t imm)
180 {
181 return (bits(imm, 19, 0) << 12) |
182 (dest << 7) |
183 MATCH_LUI;
184 }
185
186 static uint32_t csrci(unsigned int csr, uint16_t imm) __attribute__ ((unused));
187 static uint32_t csrci(unsigned int csr, uint16_t imm) {
188 return (csr << 20) |
189 (bits(imm, 4, 0) << 15) |
190 MATCH_CSRRCI;
191 }
192
193 static uint32_t li(unsigned int dest, uint16_t imm) __attribute__ ((unused));
194 static uint32_t li(unsigned int dest, uint16_t imm)
195 {
196 return addi(dest, 0, imm);
197 }
198
199 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
200 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset)
201 {
202 return (bits(offset, 11, 5) << 25) |
203 (bits(src, 4, 0) << 20) |
204 (base << 15) |
205 (bits(offset, 4, 0) << 7) |
206 MATCH_FSD;
207 }
208
209 static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
210 static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm)
211 {
212 return (bits(imm, 11, 0) << 20) |
213 (src << 15) |
214 (dest << 7) |
215 MATCH_ORI;
216 }
217
218 static uint32_t nop(void) __attribute__ ((unused));
219 static uint32_t nop(void)
220 {
221 return addi(0, 0, 0);
222 }
223 */
224
225 static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
226 static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm)
227 {
228 return (bits(imm, 11, 0) << 20) |
229 (src << 15) |
230 (dest << 7) |
231 MATCH_XORI;
232 }
233
234 static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt) __attribute__ ((unused));
235 static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt)
236 {
237 return (bits(shamt, 4, 0) << 20) |
238 (src << 15) |
239 (dest << 7) |
240 MATCH_SRLI;
241 }