8 static uint32_t bits(uint32_t value, unsigned int hi, unsigned int lo)
10 return (value >> lo) & ((1 << (hi+1-lo)) - 1);
13 static uint32_t bit(uint32_t value, unsigned int b)
15 return (value >> b) & 1;
18 static uint32_t jal(unsigned int rd, uint32_t imm) __attribute__ ((unused));
19 static uint32_t jal(unsigned int rd, uint32_t imm)
21 return (bit(imm, 20) << 31) |
22 (bits(imm, 10, 1) << 21) |
23 (bit(imm, 11) << 20) |
24 (bits(imm, 19, 12) << 12) |
29 static uint32_t csrsi(unsigned int csr, uint16_t imm) __attribute__ ((unused));
30 static uint32_t csrsi(unsigned int csr, uint16_t imm)
33 (bits(imm, 4, 0) << 15) |
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)
40 return (bits(offset, 11, 5) << 25) |
43 (bits(offset, 4, 0) << 7) |
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)
50 return (bits(offset, 11, 5) << 25) |
53 (bits(offset, 4, 0) << 7) |
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)
60 return (bits(offset, 11, 5) << 25) |
63 (bits(offset, 4, 0) << 7) |
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)
70 return (bits(offset, 11, 5) << 25) |
73 (bits(offset, 4, 0) << 7) |
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)
80 return (bits(offset, 11, 0) << 20) |
82 (bits(rd, 4, 0) << 7) |
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)
89 return (bits(offset, 11, 0) << 20) |
91 (bits(rd, 4, 0) << 7) |
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)
98 return (bits(offset, 11, 0) << 20) |
100 (bits(rd, 4, 0) << 7) |
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)
107 return (bits(offset, 11, 0) << 20) |
109 (bits(rd, 4, 0) << 7) |
113 static uint32_t csrw(unsigned int source, unsigned int csr) __attribute__ ((unused));
114 static uint32_t csrw(unsigned int source, unsigned int csr)
116 return (csr << 20) | (source << 15) | MATCH_CSRRW;
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)
122 return (bits(imm, 11, 0) << 20) |
128 static uint32_t csrr(unsigned int rd, unsigned int csr) __attribute__ ((unused));
129 static uint32_t csrr(unsigned int rd, unsigned int csr)
131 return (csr << 20) | (rd << 7) | MATCH_CSRRS;
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)
137 return (csr << 20) | (rs << 15) | (rd << 7) | MATCH_CSRRS;
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)
143 return (csr << 20) | (rs << 15) | (rd << 7) | MATCH_CSRRW;
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)
149 return (bits(offset, 11, 5) << 25) |
150 (bits(src, 4, 0) << 20) |
152 (bits(offset, 4, 0) << 7) |
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)
159 return (bits(offset, 11, 5) << 25) |
160 (bits(src, 4, 0) << 20) |
162 (bits(offset, 4, 0) << 7) |
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)
169 return (bits(offset, 11, 0) << 20) |
171 (bits(dest, 4, 0) << 7) |
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)
178 return (bits(offset, 11, 0) << 20) |
180 (bits(dest, 4, 0) << 7) |
184 static uint32_t fmv_x_w(unsigned dest, unsigned src) __attribute__ ((unused));
185 static uint32_t fmv_x_w(unsigned dest, unsigned src)
192 static uint32_t fmv_x_d(unsigned dest, unsigned src) __attribute__ ((unused));
193 static uint32_t fmv_x_d(unsigned dest, unsigned src)
200 static uint32_t fmv_w_x(unsigned dest, unsigned src) __attribute__ ((unused));
201 static uint32_t fmv_w_x(unsigned dest, unsigned src)
208 static uint32_t fmv_d_x(unsigned dest, unsigned src) __attribute__ ((unused));
209 static uint32_t fmv_d_x(unsigned dest, unsigned src)
216 static uint32_t ebreak(void) __attribute__ ((unused));
217 static uint32_t ebreak(void)
221 static uint32_t ebreak_c(void) __attribute__ ((unused));
222 static uint32_t ebreak_c(void)
224 return MATCH_C_EBREAK;
227 static uint32_t fence_i(void) __attribute__ ((unused));
228 static uint32_t fence_i(void)
230 return MATCH_FENCE_I;
233 static uint32_t lui(unsigned int dest, uint32_t imm) __attribute__ ((unused));
234 static uint32_t lui(unsigned int dest, uint32_t imm)
236 return (bits(imm, 19, 0) << 12) |
242 static uint32_t csrci(unsigned int csr, uint16_t imm) __attribute__ ((unused));
243 static uint32_t csrci(unsigned int csr, uint16_t imm)
246 (bits(imm, 4, 0) << 15) |
250 static uint32_t li(unsigned int dest, uint16_t imm) __attribute__ ((unused));
251 static uint32_t li(unsigned int dest, uint16_t imm)
253 return addi(dest, 0, imm);
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)
259 return (bits(offset, 11, 5) << 25) |
260 (bits(src, 4, 0) << 20) |
262 (bits(offset, 4, 0) << 7) |
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)
269 return (bits(imm, 11, 0) << 20) |
275 static uint32_t nop(void) __attribute__ ((unused));
276 static uint32_t nop(void)
278 return addi(0, 0, 0);
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)
285 return (bits(imm, 11, 0) << 20) |
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)
294 return (bits(shamt, 4, 0) << 20) |
300 static uint32_t fence(void) __attribute__((unused));
301 static uint32_t fence(void)
306 static uint32_t auipc(unsigned int dest) __attribute__((unused));
307 static uint32_t auipc(unsigned int dest)
309 return MATCH_AUIPC | (dest << 7);