Lots of RISC-V improvements.
[openocd.git] / src / target / 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 {
10 return (value >> lo) & ((1 << (hi+1-lo)) - 1);
11 }
12
13 static uint32_t bit(uint32_t value, unsigned int b)
14 {
15 return (value >> b) & 1;
16 }
17
18 static uint32_t jal(unsigned int rd, uint32_t imm) __attribute__ ((unused));
19 static uint32_t jal(unsigned int rd, uint32_t imm)
20 {
21 return (bit(imm, 20) << 31) |
22 (bits(imm, 10, 1) << 21) |
23 (bit(imm, 11) << 20) |
24 (bits(imm, 19, 12) << 12) |
25 (rd << 7) |
26 MATCH_JAL;
27 }
28
29 static uint32_t csrsi(unsigned int csr, uint16_t imm) __attribute__ ((unused));
30 static uint32_t csrsi(unsigned int csr, uint16_t imm)
31 {
32 return (csr << 20) |
33 (bits(imm, 4, 0) << 15) |
34 MATCH_CSRRSI;
35 }
36
37 static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
38 static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset)
39 {
40 return (bits(offset, 11, 5) << 25) |
41 (src << 20) |
42 (base << 15) |
43 (bits(offset, 4, 0) << 7) |
44 MATCH_SW;
45 }
46
47 static uint32_t sd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
48 static uint32_t sd(unsigned int src, unsigned int base, uint16_t offset)
49 {
50 return (bits(offset, 11, 5) << 25) |
51 (src << 20) |
52 (base << 15) |
53 (bits(offset, 4, 0) << 7) |
54 MATCH_SD;
55 }
56
57 static uint32_t sh(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
58 static uint32_t sh(unsigned int src, unsigned int base, uint16_t offset)
59 {
60 return (bits(offset, 11, 5) << 25) |
61 (src << 20) |
62 (base << 15) |
63 (bits(offset, 4, 0) << 7) |
64 MATCH_SH;
65 }
66
67 static uint32_t sb(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
68 static uint32_t sb(unsigned int src, unsigned int base, uint16_t offset)
69 {
70 return (bits(offset, 11, 5) << 25) |
71 (src << 20) |
72 (base << 15) |
73 (bits(offset, 4, 0) << 7) |
74 MATCH_SB;
75 }
76
77 static uint32_t ld(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
78 static uint32_t ld(unsigned int rd, unsigned int base, uint16_t offset)
79 {
80 return (bits(offset, 11, 0) << 20) |
81 (base << 15) |
82 (bits(rd, 4, 0) << 7) |
83 MATCH_LD;
84 }
85
86 static uint32_t lw(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
87 static uint32_t lw(unsigned int rd, unsigned int base, uint16_t offset)
88 {
89 return (bits(offset, 11, 0) << 20) |
90 (base << 15) |
91 (bits(rd, 4, 0) << 7) |
92 MATCH_LW;
93 }
94
95 static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
96 static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset)
97 {
98 return (bits(offset, 11, 0) << 20) |
99 (base << 15) |
100 (bits(rd, 4, 0) << 7) |
101 MATCH_LH;
102 }
103
104 static uint32_t lb(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
105 static uint32_t lb(unsigned int rd, unsigned int base, uint16_t offset)
106 {
107 return (bits(offset, 11, 0) << 20) |
108 (base << 15) |
109 (bits(rd, 4, 0) << 7) |
110 MATCH_LB;
111 }
112
113 static uint32_t csrw(unsigned int source, unsigned int csr) __attribute__ ((unused));
114 static uint32_t csrw(unsigned int source, unsigned int csr)
115 {
116 return (csr << 20) | (source << 15) | MATCH_CSRRW;
117 }
118
119 static uint32_t addi(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
120 static uint32_t addi(unsigned int dest, unsigned int src, uint16_t imm)
121 {
122 return (bits(imm, 11, 0) << 20) |
123 (src << 15) |
124 (dest << 7) |
125 MATCH_ADDI;
126 }
127
128 static uint32_t csrr(unsigned int rd, unsigned int csr) __attribute__ ((unused));
129 static uint32_t csrr(unsigned int rd, unsigned int csr)
130 {
131 return (csr << 20) | (rd << 7) | MATCH_CSRRS;
132 }
133
134 static uint32_t csrrs(unsigned int rd, unsigned int rs, unsigned int csr) __attribute__ ((unused));
135 static uint32_t csrrs(unsigned int rd, unsigned int rs, unsigned int csr)
136 {
137 return (csr << 20) | (rs << 15) | (rd << 7) | MATCH_CSRRS;
138 }
139
140 static uint32_t csrrw(unsigned int rd, unsigned int rs, unsigned int csr) __attribute__ ((unused));
141 static uint32_t csrrw(unsigned int rd, unsigned int rs, unsigned int csr)
142 {
143 return (csr << 20) | (rs << 15) | (rd << 7) | MATCH_CSRRW;
144 }
145
146 static uint32_t fsw(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
147 static uint32_t fsw(unsigned int src, unsigned int base, uint16_t offset)
148 {
149 return (bits(offset, 11, 5) << 25) |
150 (bits(src, 4, 0) << 20) |
151 (base << 15) |
152 (bits(offset, 4, 0) << 7) |
153 MATCH_FSW;
154 }
155
156 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
157 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset)
158 {
159 return (bits(offset, 11, 5) << 25) |
160 (bits(src, 4, 0) << 20) |
161 (base << 15) |
162 (bits(offset, 4, 0) << 7) |
163 MATCH_FSD;
164 }
165
166 static uint32_t flw(unsigned int dest, unsigned int base, uint16_t offset) __attribute__ ((unused));
167 static uint32_t flw(unsigned int dest, unsigned int base, uint16_t offset)
168 {
169 return (bits(offset, 11, 0) << 20) |
170 (base << 15) |
171 (bits(dest, 4, 0) << 7) |
172 MATCH_FLW;
173 }
174
175 static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset) __attribute__ ((unused));
176 static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset)
177 {
178 return (bits(offset, 11, 0) << 20) |
179 (base << 15) |
180 (bits(dest, 4, 0) << 7) |
181 MATCH_FLD;
182 }
183
184 static uint32_t fmv_x_w(unsigned dest, unsigned src) __attribute__ ((unused));
185 static uint32_t fmv_x_w(unsigned dest, unsigned src)
186 {
187 return src << 15 |
188 dest << 7 |
189 MATCH_FMV_X_W;
190 }
191
192 static uint32_t fmv_x_d(unsigned dest, unsigned src) __attribute__ ((unused));
193 static uint32_t fmv_x_d(unsigned dest, unsigned src)
194 {
195 return src << 15 |
196 dest << 7 |
197 MATCH_FMV_X_D;
198 }
199
200 static uint32_t fmv_w_x(unsigned dest, unsigned src) __attribute__ ((unused));
201 static uint32_t fmv_w_x(unsigned dest, unsigned src)
202 {
203 return src << 15 |
204 dest << 7 |
205 MATCH_FMV_W_X;
206 }
207
208 static uint32_t fmv_d_x(unsigned dest, unsigned src) __attribute__ ((unused));
209 static uint32_t fmv_d_x(unsigned dest, unsigned src)
210 {
211 return src << 15 |
212 dest << 7 |
213 MATCH_FMV_D_X;
214 }
215
216 static uint32_t ebreak(void) __attribute__ ((unused));
217 static uint32_t ebreak(void)
218 {
219 return MATCH_EBREAK;
220 }
221 static uint32_t ebreak_c(void) __attribute__ ((unused));
222 static uint32_t ebreak_c(void)
223 {
224 return MATCH_C_EBREAK;
225 }
226
227 static uint32_t wfi(void) __attribute__ ((unused));
228 static uint32_t wfi(void) { return MATCH_WFI; }
229
230 static uint32_t fence_i(void) __attribute__ ((unused));
231 static uint32_t fence_i(void)
232 {
233 return MATCH_FENCE_I;
234 }
235
236 static uint32_t lui(unsigned int dest, uint32_t imm) __attribute__ ((unused));
237 static uint32_t lui(unsigned int dest, uint32_t imm)
238 {
239 return (bits(imm, 19, 0) << 12) |
240 (dest << 7) |
241 MATCH_LUI;
242 }
243
244 /*
245 static uint32_t csrci(unsigned int csr, uint16_t imm) __attribute__ ((unused));
246 static uint32_t csrci(unsigned int csr, uint16_t imm)
247 {
248 return (csr << 20) |
249 (bits(imm, 4, 0) << 15) |
250 MATCH_CSRRCI;
251 }
252
253 static uint32_t li(unsigned int dest, uint16_t imm) __attribute__ ((unused));
254 static uint32_t li(unsigned int dest, uint16_t imm)
255 {
256 return addi(dest, 0, imm);
257 }
258
259 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
260 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset)
261 {
262 return (bits(offset, 11, 5) << 25) |
263 (bits(src, 4, 0) << 20) |
264 (base << 15) |
265 (bits(offset, 4, 0) << 7) |
266 MATCH_FSD;
267 }
268
269 static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
270 static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm)
271 {
272 return (bits(imm, 11, 0) << 20) |
273 (src << 15) |
274 (dest << 7) |
275 MATCH_ORI;
276 }
277
278 static uint32_t nop(void) __attribute__ ((unused));
279 static uint32_t nop(void)
280 {
281 return addi(0, 0, 0);
282 }
283 */
284
285 static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
286 static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm)
287 {
288 return (bits(imm, 11, 0) << 20) |
289 (src << 15) |
290 (dest << 7) |
291 MATCH_XORI;
292 }
293
294 static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt) __attribute__ ((unused));
295 static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt)
296 {
297 return (bits(shamt, 4, 0) << 20) |
298 (src << 15) |
299 (dest << 7) |
300 MATCH_SRLI;
301 }
302
303 static uint32_t fence(void) __attribute__((unused));
304 static uint32_t fence(void)
305 {
306 return MATCH_FENCE;
307 }
308
309 static uint32_t auipc(unsigned int dest) __attribute__((unused));
310 static uint32_t auipc(unsigned int dest)
311 {
312 return MATCH_AUIPC | (dest << 7);
313 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)