14267c5be3650d0fe7ab4157d9f97817039fdac1
[rv32.git] / riscvdefs.py
1 """
2 /*
3 * Copyright 2018 Jacob Lifshay
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 */
24 """
25
26 from migen import Constant
27
28 cause_instruction_address_misaligned = Constant(0x0, 4)
29 cause_instruction_access_fault = Constant(0x1, 4)
30 cause_illegal_instruction = Constant(0x2, 4)
31 cause_breakpoint = Constant(0x3, 4)
32 cause_load_address_misaligned = Constant(0x4, 4)
33 cause_load_access_fault = Constant(0x5, 4)
34 cause_store_amo_address_misaligned = Constant(0x6, 4)
35 cause_store_amo_access_fault = Constant(0x7, 4)
36 cause_user_environment_call = Constant(0x8, 4)
37 cause_supervisor_environment_call = Constant(0x9, 4)
38 cause_machine_environment_call = Constant(0xB, 4)
39 cause_instruction_page_fault = Constant(0xC, 4)
40 cause_load_page_fault = Constant(0xD, 4)
41 cause_store_amo_page_fault = Constant(0xF, 4)
42
43 opcode_load = Constant(0x03, 7)
44 opcode_load_fp = Constant(0x07, 7)
45 opcode_custom_0 = Constant(0x0B, 7)
46 opcode_misc_mem = Constant(0x0F, 7)
47 opcode_op_imm = Constant(0x13, 7)
48 opcode_auipc = Constant(0x17, 7)
49 opcode_op_imm_32 = Constant(0x1B, 7)
50 opcode_48b_escape_0 = Constant(0x1F, 7)
51
52 opcode_store = Constant(0x23, 7)
53 opcode_store_fp = Constant(0x27, 7)
54 opcode_custom_1 = Constant(0x2B, 7)
55 opcode_amo = Constant(0x2F, 7)
56 opcode_op = Constant(0x33, 7)
57 opcode_lui = Constant(0x37, 7)
58 opcode_op_32 = Constant(0x3B, 7)
59 opcode_64b_escape = Constant(0x3F, 7)
60
61 opcode_madd = Constant(0x43, 7)
62 opcode_msub = Constant(0x47, 7)
63 opcode_nmsub = Constant(0x4B, 7)
64 opcode_nmadd = Constant(0x4F, 7)
65 opcode_op_fp = Constant(0x53, 7)
66 opcode_reserved_10101 = Constant(0x57, 7)
67 opcode_rv128_0 = Constant(0x5B, 7)
68 opcode_48b_escape_1 = Constant(0x5F, 7)
69
70 opcode_branch = Constant(0x63, 7)
71 opcode_jalr = Constant(0x67, 7)
72 opcode_reserved_11010 = Constant(0x6B, 7)
73 opcode_jal = Constant(0x6F, 7)
74 opcode_system = Constant(0x73, 7)
75 opcode_reserved_11101 = Constant(0x77, 7)
76 opcode_rv128_1 = Constant(0x7B, 7)
77 opcode_80b_escape = Constant(0x7F, 7)
78
79 funct3_jalr = Constant(0x0, 3)
80 funct3_beq = Constant(0x0, 3)
81 funct3_bne = Constant(0x1, 3)
82 funct3_blt = Constant(0x4, 3)
83 funct3_bge = Constant(0x5, 3)
84 funct3_bltu = Constant(0x6, 3)
85 funct3_bgeu = Constant(0x7, 3)
86
87 funct3_lb = Constant(0x0, 3)
88 funct3_lh = Constant(0x1, 3)
89 funct3_lw = Constant(0x2, 3)
90 funct3_lbu = Constant(0x4, 3)
91 funct3_lhu = Constant(0x5, 3)
92
93 funct3_sb = Constant(0x0, 3)
94 funct3_sh = Constant(0x1, 3)
95 funct3_sw = Constant(0x2, 3)
96
97 funct3_addi = Constant(0x0, 3)
98 funct3_slli = Constant(0x1, 3)
99 funct3_slti = Constant(0x2, 3)
100 funct3_sltiu = Constant(0x3, 3)
101 funct3_xori = Constant(0x4, 3)
102 funct3_srli_srai = Constant(0x5, 3)
103 funct3_ori = Constant(0x6, 3)
104 funct3_andi = Constant(0x7, 3)
105
106 funct3_add_sub = Constant(0x0, 3)
107 funct3_sll = Constant(0x1, 3)
108 funct3_slt = Constant(0x2, 3)
109 funct3_sltu = Constant(0x3, 3)
110 funct3_xor = Constant(0x4, 3)
111 funct3_srl_sra = Constant(0x5, 3)
112 funct3_or = Constant(0x6, 3)
113 funct3_and = Constant(0x7, 3)
114
115 funct3_fence = Constant(0x0, 3)
116 funct3_fence_i = Constant(0x1, 3)
117
118 funct3_ecall_ebreak = Constant(0x0, 3)
119 funct3_csrrw = Constant(0x1, 3)
120 funct3_csrrs = Constant(0x2, 3)
121 funct3_csrrc = Constant(0x3, 3)
122 funct3_csrrwi = Constant(0x5, 3)
123 funct3_csrrsi = Constant(0x6, 3)
124 funct3_csrrci = Constant(0x7, 3)
125
126 csr_ustatus = Constant(0x000, 12)
127 csr_fflags = Constant(0x001, 12)
128 csr_frm = Constant(0x002, 12)
129 csr_fcsr = Constant(0x003, 12)
130 csr_uie = Constant(0x004, 12)
131 csr_utvec = Constant(0x005, 12)
132 csr_uscratch = Constant(0x040, 12)
133 csr_uepc = Constant(0x041, 12)
134 csr_ucause = Constant(0x042, 12)
135 csr_utval = Constant(0x043, 12)
136 csr_uip = Constant(0x044, 12)
137 csr_cycle = Constant(0xC00, 12)
138 csr_time = Constant(0xC01, 12)
139 csr_instret = Constant(0xC02, 12)
140 csr_cycleh = Constant(0xC80, 12)
141 csr_timeh = Constant(0xC81, 12)
142 csr_instreth = Constant(0xC82, 12)
143
144 csr_sstatus = Constant(0x100, 12)
145 csr_sedeleg = Constant(0x102, 12)
146 csr_sideleg = Constant(0x103, 12)
147 csr_sie = Constant(0x104, 12)
148 csr_stvec = Constant(0x105, 12)
149 csr_scounteren = Constant(0x106, 12)
150 csr_sscratch = Constant(0x140, 12)
151 csr_sepc = Constant(0x141, 12)
152 csr_scause = Constant(0x142, 12)
153 csr_stval = Constant(0x143, 12)
154 csr_sip = Constant(0x144, 12)
155 csr_satp = Constant(0x180, 12)
156
157 csr_mvendorid = Constant(0xF11, 12)
158 csr_marchid = Constant(0xF12, 12)
159 csr_mimpid = Constant(0xF13, 12)
160 csr_mhartid = Constant(0xF14, 12)
161 csr_mstatus = Constant(0x300, 12)
162 csr_misa = Constant(0x301, 12)
163 csr_medeleg = Constant(0x302, 12)
164 csr_mideleg = Constant(0x303, 12)
165 csr_mie = Constant(0x304, 12)
166 csr_mtvec = Constant(0x305, 12)
167 csr_mcounteren = Constant(0x306, 12)
168 csr_mscratch = Constant(0x340, 12)
169 csr_mepc = Constant(0x341, 12)
170 csr_mcause = Constant(0x342, 12)
171 csr_mtval = Constant(0x343, 12)
172 csr_mip = Constant(0x344, 12)
173 csr_mcycle = Constant(0xB00, 12)
174 csr_minstret = Constant(0xB02, 12)
175 csr_mcycleh = Constant(0xB80, 12)
176 csr_minstreth = Constant(0xB82, 12)
177
178 csr_dcsr = Constant(0x7B0, 12)
179 csr_dpc = Constant(0x7B1, 12)
180 csr_dscratch = Constant(0x7B2, 12)
181