1 /* SPDX-License-Identifier: GPL-2.0-or-later */
10 static uint32_t bits(uint32_t value, unsigned int hi, unsigned int lo)
12 return (value >> lo) & ((1 << (hi+1-lo)) - 1);
15 static uint32_t bit(uint32_t value, unsigned int b)
17 return (value >> b) & 1;
20 static uint32_t jal(unsigned int rd, uint32_t imm) __attribute__ ((unused));
21 static uint32_t jal(unsigned int rd, uint32_t imm)
23 return (bit(imm, 20) << 31) |
24 (bits(imm, 10, 1) << 21) |
25 (bit(imm, 11) << 20) |
26 (bits(imm, 19, 12) << 12) |
31 static uint32_t csrsi(unsigned int csr, uint16_t imm) __attribute__ ((unused));
32 static uint32_t csrsi(unsigned int csr, uint16_t imm)
35 (bits(imm, 4, 0) << 15) |
39 static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
40 static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset)
42 return (bits(offset, 11, 5) << 25) |
45 (bits(offset, 4, 0) << 7) |
49 static uint32_t sd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
50 static uint32_t sd(unsigned int src, unsigned int base, uint16_t offset)
52 return (bits(offset, 11, 5) << 25) |
55 (bits(offset, 4, 0) << 7) |
59 static uint32_t sh(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
60 static uint32_t sh(unsigned int src, unsigned int base, uint16_t offset)
62 return (bits(offset, 11, 5) << 25) |
65 (bits(offset, 4, 0) << 7) |
69 static uint32_t sb(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
70 static uint32_t sb(unsigned int src, unsigned int base, uint16_t offset)
72 return (bits(offset, 11, 5) << 25) |
75 (bits(offset, 4, 0) << 7) |
79 static uint32_t ld(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
80 static uint32_t ld(unsigned int rd, unsigned int base, uint16_t offset)
82 return (bits(offset, 11, 0) << 20) |
84 (bits(rd, 4, 0) << 7) |
88 static uint32_t lw(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
89 static uint32_t lw(unsigned int rd, unsigned int base, uint16_t offset)
91 return (bits(offset, 11, 0) << 20) |
93 (bits(rd, 4, 0) << 7) |
97 static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
98 static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset)
100 return (bits(offset, 11, 0) << 20) |
102 (bits(rd, 4, 0) << 7) |
106 static uint32_t lb(unsigned int rd, unsigned int base, uint16_t offset) __attribute__ ((unused));
107 static uint32_t lb(unsigned int rd, unsigned int base, uint16_t offset)
109 return (bits(offset, 11, 0) << 20) |
111 (bits(rd, 4, 0) << 7) |
115 static uint32_t csrw(unsigned int source, unsigned int csr) __attribute__ ((unused));
116 static uint32_t csrw(unsigned int source, unsigned int csr)
118 return (csr << 20) | (source << 15) | MATCH_CSRRW;
121 static uint32_t addi(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
122 static uint32_t addi(unsigned int dest, unsigned int src, uint16_t imm)
124 return (bits(imm, 11, 0) << 20) |
130 static uint32_t csrr(unsigned int rd, unsigned int csr) __attribute__ ((unused));
131 static uint32_t csrr(unsigned int rd, unsigned int csr)
133 return (csr << 20) | (rd << 7) | MATCH_CSRRS;
136 static uint32_t csrrs(unsigned int rd, unsigned int rs, unsigned int csr) __attribute__ ((unused));
137 static uint32_t csrrs(unsigned int rd, unsigned int rs, unsigned int csr)
139 return (csr << 20) | (rs << 15) | (rd << 7) | MATCH_CSRRS;
142 static uint32_t csrrw(unsigned int rd, unsigned int rs, unsigned int csr) __attribute__ ((unused));
143 static uint32_t csrrw(unsigned int rd, unsigned int rs, unsigned int csr)
145 return (csr << 20) | (rs << 15) | (rd << 7) | MATCH_CSRRW;
148 static uint32_t csrrci(unsigned int rd, unsigned int zimm, unsigned int csr) __attribute__ ((unused));
149 static uint32_t csrrci(unsigned int rd, unsigned int zimm, unsigned int csr)
151 return (csr << 20) | (zimm << 15) | (rd << 7) | MATCH_CSRRCI;
154 static uint32_t csrrsi(unsigned int rd, unsigned int zimm, unsigned int csr) __attribute__ ((unused));
155 static uint32_t csrrsi(unsigned int rd, unsigned int zimm, unsigned int csr)
157 return (csr << 20) | (zimm << 15) | (rd << 7) | MATCH_CSRRSI;
160 static uint32_t fsw(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
161 static uint32_t fsw(unsigned int src, unsigned int base, uint16_t offset)
163 return (bits(offset, 11, 5) << 25) |
164 (bits(src, 4, 0) << 20) |
166 (bits(offset, 4, 0) << 7) |
170 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
171 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset)
173 return (bits(offset, 11, 5) << 25) |
174 (bits(src, 4, 0) << 20) |
176 (bits(offset, 4, 0) << 7) |
180 static uint32_t flw(unsigned int dest, unsigned int base, uint16_t offset) __attribute__ ((unused));
181 static uint32_t flw(unsigned int dest, unsigned int base, uint16_t offset)
183 return (bits(offset, 11, 0) << 20) |
185 (bits(dest, 4, 0) << 7) |
189 static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset) __attribute__ ((unused));
190 static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset)
192 return (bits(offset, 11, 0) << 20) |
194 (bits(dest, 4, 0) << 7) |
198 static uint32_t fmv_x_w(unsigned dest, unsigned src) __attribute__ ((unused));
199 static uint32_t fmv_x_w(unsigned dest, unsigned src)
206 static uint32_t fmv_x_d(unsigned dest, unsigned src) __attribute__ ((unused));
207 static uint32_t fmv_x_d(unsigned dest, unsigned src)
214 static uint32_t fmv_w_x(unsigned dest, unsigned src) __attribute__ ((unused));
215 static uint32_t fmv_w_x(unsigned dest, unsigned src)
222 static uint32_t fmv_d_x(unsigned dest, unsigned src) __attribute__ ((unused));
223 static uint32_t fmv_d_x(unsigned dest, unsigned src)
230 static uint32_t ebreak(void) __attribute__ ((unused));
231 static uint32_t ebreak(void)
235 static uint32_t ebreak_c(void) __attribute__ ((unused));
236 static uint32_t ebreak_c(void)
238 return MATCH_C_EBREAK;
241 static uint32_t wfi(void) __attribute__ ((unused));
242 static uint32_t wfi(void) { return MATCH_WFI; }
244 static uint32_t fence_i(void) __attribute__ ((unused));
245 static uint32_t fence_i(void)
247 return MATCH_FENCE_I;
250 static uint32_t lui(unsigned int dest, uint32_t imm) __attribute__ ((unused));
251 static uint32_t lui(unsigned int dest, uint32_t imm)
253 return (bits(imm, 19, 0) << 12) |
259 static uint32_t csrci(unsigned int csr, uint16_t imm) __attribute__ ((unused));
260 static uint32_t csrci(unsigned int csr, uint16_t imm)
263 (bits(imm, 4, 0) << 15) |
267 static uint32_t li(unsigned int dest, uint16_t imm) __attribute__ ((unused));
268 static uint32_t li(unsigned int dest, uint16_t imm)
270 return addi(dest, 0, imm);
273 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__ ((unused));
274 static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset)
276 return (bits(offset, 11, 5) << 25) |
277 (bits(src, 4, 0) << 20) |
279 (bits(offset, 4, 0) << 7) |
283 static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
284 static uint32_t ori(unsigned int dest, unsigned int src, uint16_t imm)
286 return (bits(imm, 11, 0) << 20) |
292 static uint32_t nop(void) __attribute__ ((unused));
293 static uint32_t nop(void)
295 return addi(0, 0, 0);
299 static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm) __attribute__ ((unused));
300 static uint32_t xori(unsigned int dest, unsigned int src, uint16_t imm)
302 return (bits(imm, 11, 0) << 20) |
308 static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt) __attribute__ ((unused));
309 static uint32_t srli(unsigned int dest, unsigned int src, uint8_t shamt)
311 return (bits(shamt, 4, 0) << 20) |
317 static uint32_t fence(void) __attribute__((unused));
318 static uint32_t fence(void)
323 static uint32_t auipc(unsigned int dest) __attribute__((unused));
324 static uint32_t auipc(unsigned int dest)
326 return MATCH_AUIPC | (dest << 7);
329 static uint32_t vsetvli(unsigned int dest, unsigned int src, uint16_t imm) __attribute__((unused));
330 static uint32_t vsetvli(unsigned int dest, unsigned int src, uint16_t imm)
332 return (bits(imm, 10, 0) << 20) |
338 static uint32_t vmv_x_s(unsigned int rd, unsigned int vs2) __attribute__((unused));
339 static uint32_t vmv_x_s(unsigned int rd, unsigned int vs2)
341 return (vs2 << 20) | (rd << 7) | MATCH_VMV_X_S;
344 static uint32_t vmv_s_x(unsigned int vd, unsigned int vs2) __attribute__((unused));
345 static uint32_t vmv_s_x(unsigned int vd, unsigned int rs1)
347 return (rs1 << 15) | (vd << 7) | MATCH_VMV_S_X;
350 static uint32_t vslide1down_vx(unsigned int vd, unsigned int vs2,
351 unsigned int rs1, unsigned int vm) __attribute__((unused));
352 static uint32_t vslide1down_vx(unsigned int vd, unsigned int vs2,
353 unsigned int rs1, unsigned int vm)
355 return (vm << 25) | (vs2 << 20) | (rs1 << 15) | (vd << 7) |
356 MATCH_VSLIDE1DOWN_VX;