2 * Copyright 2018 Jacob Lifshay
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 `define cause_instruction_address_misaligned 'h0
27 `define cause_instruction_access_fault 'h1
28 `define cause_illegal_instruction 'h2
29 `define cause_breakpoint 'h3
30 `define cause_load_address_misaligned 'h4
31 `define cause_load_access_fault 'h5
32 `define cause_store_amo_address_misaligned 'h6
33 `define cause_store_amo_access_fault 'h7
34 `define cause_user_environment_call 'h8
35 `define cause_supervisor_environment_call 'h9
36 `define cause_machine_environment_call 'hB
37 `define cause_instruction_page_fault 'hC
38 `define cause_load_page_fault 'hD
39 `define cause_store_amo_page_fault 'hF
41 `define opcode_load 7'h03
42 `define opcode_load_fp 7'h07
43 `define opcode_custom_0 7'h0B
44 `define opcode_misc_mem 7'h0F
45 `define opcode_op_imm 7'h13
46 `define opcode_auipc 7'h17
47 `define opcode_op_imm_32 7'h1B
48 `define opcode_48b_escape_0 7'h1F
50 `define opcode_store 7'h23
51 `define opcode_store_fp 7'h27
52 `define opcode_custom_1 7'h2B
53 `define opcode_amo 7'h2F
54 `define opcode_op 7'h33
55 `define opcode_lui 7'h37
56 `define opcode_op_32 7'h3B
57 `define opcode_64b_escape 7'h3F
59 `define opcode_madd 7'h43
60 `define opcode_msub 7'h47
61 `define opcode_nmsub 7'h4B
62 `define opcode_nmadd 7'h4F
63 `define opcode_op_fp 7'h53
64 `define opcode_reserved_10101 7'h57
65 `define opcode_rv128_0 7'h5B
66 `define opcode_48b_escape_1 7'h5F
68 `define opcode_branch 7'h63
69 `define opcode_jalr 7'h67
70 `define opcode_reserved_11010 7'h6B
71 `define opcode_jal 7'h6F
72 `define opcode_system 7'h73
73 `define opcode_reserved_11101 7'h77
74 `define opcode_rv128_1 7'h7B
75 `define opcode_80b_escape 7'h7F
77 `define funct3_jalr 3'h0
78 `define funct3_beq 3'h0
79 `define funct3_bne 3'h1
80 `define funct3_blt 3'h4
81 `define funct3_bge 3'h5
82 `define funct3_bltu 3'h6
83 `define funct3_bgeu 3'h7
84 `define funct3_lb 3'h0
85 `define funct3_lh 3'h1
86 `define funct3_lw 3'h2
87 `define funct3_lbu 3'h4
88 `define funct3_lhu 3'h5
89 `define funct3_sb 3'h0
90 `define funct3_sh 3'h1
91 `define funct3_sw 3'h2
92 `define funct3_addi 3'h0
93 `define funct3_slli 3'h1
94 `define funct3_slti 3'h2
95 `define funct3_sltiu 3'h3
96 `define funct3_xori 3'h4
97 `define funct3_srli_srai 3'h5
98 `define funct3_ori 3'h6
99 `define funct3_andi 3'h7
100 `define funct3_add_sub 3'h0
101 `define funct3_sll 3'h1
102 `define funct3_slt 3'h2
103 `define funct3_sltu 3'h3
104 `define funct3_xor 3'h4
105 `define funct3_srl_sra 3'h5
106 `define funct3_or 3'h6
107 `define funct3_and 3'h7
108 `define funct3_fence 3'h0
109 `define funct3_fence_i 3'h1
110 `define funct3_ecall_ebreak 3'h0
111 `define funct3_csrrw 3'h1
112 `define funct3_csrrs 3'h2
113 `define funct3_csrrc 3'h3
114 `define funct3_csrrwi 3'h5
115 `define funct3_csrrsi 3'h6
116 `define funct3_csrrci 3'h7
118 `define csr_ustatus 12'h000
119 `define csr_fflags 12'h001
120 `define csr_frm 12'h002
121 `define csr_fcsr 12'h003
122 `define csr_uie 12'h004
123 `define csr_utvec 12'h005
124 `define csr_uscratch 12'h040
125 `define csr_uepc 12'h041
126 `define csr_ucause 12'h042
127 `define csr_utval 12'h043
128 `define csr_uip 12'h044
129 `define csr_cycle 12'hC00
130 `define csr_time 12'hC01
131 `define csr_instret 12'hC02
132 `define csr_cycleh 12'hC80
133 `define csr_timeh 12'hC81
134 `define csr_instreth 12'hC82
136 `define csr_sstatus 12'h100
137 `define csr_sedeleg 12'h102
138 `define csr_sideleg 12'h103
139 `define csr_sie 12'h104
140 `define csr_stvec 12'h105
141 `define csr_scounteren 12'h106
142 `define csr_sscratch 12'h140
143 `define csr_sepc 12'h141
144 `define csr_scause 12'h142
145 `define csr_stval 12'h143
146 `define csr_sip 12'h144
147 `define csr_satp 12'h180
149 `define csr_mvendorid 12'hF11
150 `define csr_marchid 12'hF12
151 `define csr_mimpid 12'hF13
152 `define csr_mhartid 12'hF14
153 `define csr_mstatus 12'h300
154 `define csr_misa 12'h301
155 `define csr_medeleg 12'h302
156 `define csr_mideleg 12'h303
157 `define csr_mie 12'h304
158 `define csr_mtvec 12'h305
159 `define csr_mcounteren 12'h306
160 `define csr_mscratch 12'h340
161 `define csr_mepc 12'h341
162 `define csr_mcause 12'h342
163 `define csr_mtval 12'h343
164 `define csr_mip 12'h344
165 `define csr_mcycle 12'hB00
166 `define csr_minstret 12'hB02
167 `define csr_mcycleh 12'hB80
168 `define csr_minstreth 12'hB82
170 `define csr_dcsr 12'h7B0
171 `define csr_dpc 12'h7B1
172 `define csr_dscratch 12'h7B2