add Makefile for verilog compilation
[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 class OP:
44 """ Opcode constants
45 """
46 load = Constant(0x03, 7)
47 load_fp = Constant(0x07, 7)
48 custom_0 = Constant(0x0B, 7)
49 misc_mem = Constant(0x0F, 7)
50 op_imm = Constant(0x13, 7)
51 auipc = Constant(0x17, 7)
52 op_imm_32 = Constant(0x1B, 7)
53 op_48b_escape_0 = Constant(0x1F, 7)
54
55 store = Constant(0x23, 7)
56 store_fp = Constant(0x27, 7)
57 custom_1 = Constant(0x2B, 7)
58 amo = Constant(0x2F, 7)
59 op = Constant(0x33, 7)
60 lui = Constant(0x37, 7)
61 op_32 = Constant(0x3B, 7)
62 op_64b_escape = Constant(0x3F, 7)
63
64 madd = Constant(0x43, 7)
65 msub = Constant(0x47, 7)
66 nmsub = Constant(0x4B, 7)
67 nmadd = Constant(0x4F, 7)
68 op_fp = Constant(0x53, 7)
69 reserved_10101 = Constant(0x57, 7)
70 rv128_0 = Constant(0x5B, 7)
71 op_48b_escape_1 = Constant(0x5F, 7)
72
73 branch = Constant(0x63, 7)
74 jalr = Constant(0x67, 7)
75 reserved_11010 = Constant(0x6B, 7)
76 jal = Constant(0x6F, 7)
77 system = Constant(0x73, 7)
78 reserved_11101 = Constant(0x77, 7)
79 rv128_1 = Constant(0x7B, 7)
80 op_80b_escape = Constant(0x7F, 7)
81
82 class F3:
83 """ Funct3 constants
84 """
85 jalr = Constant(0x0, 3)
86 beq = Constant(0x0, 3)
87 bne = Constant(0x1, 3)
88 blt = Constant(0x4, 3)
89 bge = Constant(0x5, 3)
90 bltu = Constant(0x6, 3)
91 bgeu = Constant(0x7, 3)
92
93 lb = Constant(0x0, 3)
94 lh = Constant(0x1, 3)
95 lw = Constant(0x2, 3)
96 lbu = Constant(0x4, 3)
97 lhu = Constant(0x5, 3)
98
99 sb = Constant(0x0, 3)
100 sh = Constant(0x1, 3)
101 sw = Constant(0x2, 3)
102
103 addi = Constant(0x0, 3)
104 slli = Constant(0x1, 3)
105 slti = Constant(0x2, 3)
106 sltiu = Constant(0x3, 3)
107 xori = Constant(0x4, 3)
108 srli_srai = Constant(0x5, 3)
109 ori = Constant(0x6, 3)
110 andi = Constant(0x7, 3)
111
112 add_sub = Constant(0x0, 3)
113 sll = Constant(0x1, 3)
114 slt = Constant(0x2, 3)
115 sltu = Constant(0x3, 3)
116 xor = Constant(0x4, 3)
117 srl_sra = Constant(0x5, 3)
118 _or = Constant(0x6, 3)
119 _and = Constant(0x7, 3)
120
121 fence = Constant(0x0, 3)
122 fence_i = Constant(0x1, 3)
123
124 ecall_ebreak = Constant(0x0, 3)
125 csrrw = Constant(0x1, 3)
126 csrrs = Constant(0x2, 3)
127 csrrc = Constant(0x3, 3)
128 csrrwi = Constant(0x5, 3)
129 csrrsi = Constant(0x6, 3)
130 csrrci = Constant(0x7, 3)
131
132 csr_ustatus = Constant(0x000, 12)
133 csr_fflags = Constant(0x001, 12)
134 csr_frm = Constant(0x002, 12)
135 csr_fcsr = Constant(0x003, 12)
136 csr_uie = Constant(0x004, 12)
137 csr_utvec = Constant(0x005, 12)
138 csr_uscratch = Constant(0x040, 12)
139 csr_uepc = Constant(0x041, 12)
140 csr_ucause = Constant(0x042, 12)
141 csr_utval = Constant(0x043, 12)
142 csr_uip = Constant(0x044, 12)
143 csr_cycle = Constant(0xC00, 12)
144 csr_time = Constant(0xC01, 12)
145 csr_instret = Constant(0xC02, 12)
146 csr_cycleh = Constant(0xC80, 12)
147 csr_timeh = Constant(0xC81, 12)
148 csr_instreth = Constant(0xC82, 12)
149
150 csr_sstatus = Constant(0x100, 12)
151 csr_sedeleg = Constant(0x102, 12)
152 csr_sideleg = Constant(0x103, 12)
153 csr_sie = Constant(0x104, 12)
154 csr_stvec = Constant(0x105, 12)
155 csr_scounteren = Constant(0x106, 12)
156 csr_sscratch = Constant(0x140, 12)
157 csr_sepc = Constant(0x141, 12)
158 csr_scause = Constant(0x142, 12)
159 csr_stval = Constant(0x143, 12)
160 csr_sip = Constant(0x144, 12)
161 csr_satp = Constant(0x180, 12)
162
163 csr_mvendorid = Constant(0xF11, 12)
164 csr_marchid = Constant(0xF12, 12)
165 csr_mimpid = Constant(0xF13, 12)
166 csr_mhartid = Constant(0xF14, 12)
167 csr_mstatus = Constant(0x300, 12)
168 csr_misa = Constant(0x301, 12)
169 csr_medeleg = Constant(0x302, 12)
170 csr_mideleg = Constant(0x303, 12)
171 csr_mie = Constant(0x304, 12)
172 csr_mtvec = Constant(0x305, 12)
173 csr_mcounteren = Constant(0x306, 12)
174 csr_mscratch = Constant(0x340, 12)
175 csr_mepc = Constant(0x341, 12)
176 csr_mcause = Constant(0x342, 12)
177 csr_mtval = Constant(0x343, 12)
178 csr_mip = Constant(0x344, 12)
179 csr_mcycle = Constant(0xB00, 12)
180 csr_minstret = Constant(0xB02, 12)
181 csr_mcycleh = Constant(0xB80, 12)
182 csr_minstreth = Constant(0xB82, 12)
183
184 csr_dcsr = Constant(0x7B0, 12)
185 csr_dpc = Constant(0x7B1, 12)
186 csr_dscratch = Constant(0x7B2, 12)
187