Add RISC-V support.
[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 fence_i(void) __attribute__ ((unused));
228 static uint32_t fence_i(void)
229 {
230 return MATCH_FENCE_I;
231 }
232
233 static uint32_t lui(unsigned int dest, uint32_t imm) __attribute__ ((unused));
234 static uint32_t lui(unsigned int dest, uint32_t imm)
235 {
236 return (bits(imm, 19, 0) << 12) |
237 (dest << 7) |
238 MATCH_LUI;
239 }
240
241 /*
242 static uint32_t csrci(unsigned int csr, uint16_t imm) __attribute__ ((unused));
243 static uint32_t csrci(unsigned int csr, uint16_t imm)
244 {
245 return (csr << 20) |
246 (bits(imm, 4, 0) << 15) |
247 MATCH_CSRRCI;
248 }
249
250 static uint32_t li(unsigned int dest, uint16_t imm) __attribute__ ((unused));
251 static uint32_t li(unsigned int dest, uint16_t imm)
252 {
253 return addi(dest, 0, imm);
254 }
255
256 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
257 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset)
258 {
259 return (bits(offset, 11, 5) << 25) |
260 (bits(src, 4, 0) << 20) |
261 (base << 15) |
262 (bits(offset, 4, 0) << 7) |
263 MATCH_FSD;
264 }
265
266 static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
267 static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm)
268 {
269 return (bits(imm, 11, 0) << 20) |
270 (src << 15) |
271 (dest << 7) |
272 MATCH_ORI;
273 }
274
275 static uint32_t nop(void) __attribute__ ((unused));
276 static uint32_t nop(void)
277 {
278 return addi(0, 0, 0);
279 }
280 */
281
282 static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
283 static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm)
284 {
285 return (bits(imm, 11, 0) << 20) |
286 (src << 15) |
287 (dest << 7) |
288 MATCH_XORI;
289 }
290
291 static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt) __attribute__ ((unused));
292 static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt)
293 {
294 return (bits(shamt, 4, 0) << 20) |
295 (src << 15) |
296 (dest << 7) |
297 MATCH_SRLI;
298 }
299
300 static uint32_t fence(void) __attribute__((unused));
301 static uint32_t fence(void)
302 {
303 return MATCH_FENCE;
304 }
305
306 static uint32_t auipc(unsigned int dest) __attribute__((unused));
307 static uint32_t auipc(unsigned int dest)
308 {
309 return MATCH_AUIPC | (dest << 7);
310 }

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)