8 static uint32_t bits(uint32_t value,
unsigned int hi,
unsigned int lo) {
9 return (value >> lo) & ((1 << (hi+1-lo)) - 1);
12 static uint32_t bit(uint32_t value,
unsigned int b) {
13 return (value >> b) & 1;
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) |
26 static uint32_t csrsi(
unsigned int csr, uint16_t imm) __attribute__ ((unused));
27 static uint32_t csrsi(
unsigned int csr, uint16_t imm) {
29 (bits(imm, 4, 0) << 15) |
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)
36 return (bits(offset, 11, 5) << 25) |
39 (bits(offset, 4, 0) << 7) |
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)
46 return (bits(offset, 11, 5) << 25) |
49 (bits(offset, 4, 0) << 7) |
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)
56 return (bits(offset, 11, 5) << 25) |
59 (bits(offset, 4, 0) << 7) |
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)
66 return (bits(offset, 11, 5) << 25) |
69 (bits(offset, 4, 0) << 7) |
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)
76 return (bits(offset, 11, 0) << 20) |
78 (bits(rd, 4, 0) << 7) |
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)
85 return (bits(offset, 11, 0) << 20) |
87 (bits(rd, 4, 0) << 7) |
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)
94 return (bits(offset, 11, 0) << 20) |
96 (bits(rd, 4, 0) << 7) |
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)
103 return (bits(offset, 11, 0) << 20) |
105 (bits(rd, 4, 0) << 7) |
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;
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)
117 return (bits(imm, 11, 0) << 20) |
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;
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)
131 return (bits(offset, 11, 5) << 25) |
132 (bits(src, 4, 0) << 20) |
134 (bits(offset, 4, 0) << 7) |
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)
141 return (bits(offset, 11, 5) << 25) |
142 (bits(src, 4, 0) << 20) |
144 (bits(offset, 4, 0) << 7) |
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)
151 return (bits(offset, 11, 0) << 20) |
153 (bits(dest, 4, 0) << 7) |
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)
160 return (bits(offset, 11, 0) << 20) |
162 (bits(dest, 4, 0) << 7) |
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; }
171 static uint32_t dret(
void) __attribute__ ((unused));
172 static uint32_t dret(
void) {
return MATCH_DRET; }
174 static uint32_t fence_i(
void) __attribute__ ((unused));
175 static uint32_t fence_i(
void)
177 return MATCH_FENCE_I;
228 static uint32_t xori(
unsigned int dest,
unsigned int src, uint16_t imm) __attribute__ ((unused));
229 static uint32_t xori(
unsigned int dest,
unsigned int src, uint16_t imm)
231 return (bits(imm, 11, 0) << 20) |
237 static uint32_t srli(
unsigned int dest,
unsigned int src, uint8_t shamt) __attribute__ ((unused));
238 static uint32_t srli(
unsigned int dest,
unsigned int src, uint8_t shamt)
240 return (bits(shamt, 4, 0) << 20) |