ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Encoding.h
Go to the documentation of this file.
1 /*
2 
3  @copyright
4 
5  <pre>
6 
7  Copyright 2018 Chair of Electronic Design Automation, TUM
8 
9  This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10 
11  The initial version of this software has been created with the funding support by the German Federal
12  Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13 
14  Redistribution and use in source and binary forms, with or without modification, are permitted
15  provided that the following conditions are met:
16 
17  1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18  the following disclaimer.
19 
20  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21  and the following disclaimer in the documentation and/or other materials provided with the distribution.
22 
23  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24  or promote products derived from this software without specific prior written permission.
25 
26  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  POSSIBILITY OF SUCH DAMAGE.
34 
35  </pre>
36 
37  @author Chair of Electronic Design Automation, TUM
38 
39  @version 0.1
40 
41 */
42 
43 #ifndef RISCV_CSR_ENCODING_H
44 #define RISCV_CSR_ENCODING_H
45 
46 #define MSTATUS_UIE 0x00000001
47 #define MSTATUS_SIE 0x00000002
48 #define MSTATUS_HIE 0x00000004
49 #define MSTATUS_MIE 0x00000008
50 #define MSTATUS_UPIE 0x00000010
51 #define MSTATUS_SPIE 0x00000020
52 #define MSTATUS_HPIE 0x00000040
53 #define MSTATUS_MPIE 0x00000080
54 #define MSTATUS_SPP 0x00000100
55 #define MSTATUS_HPP 0x00000600
56 #define MSTATUS_MPP 0x00001800
57 #define MSTATUS_FS 0x00006000
58 #define MSTATUS_XS 0x00018000
59 #define MSTATUS_MPRV 0x00020000
60 #define MSTATUS_SUM 0x00040000
61 #define MSTATUS_MXR 0x00080000
62 #define MSTATUS_TVM 0x00100000
63 #define MSTATUS_TW 0x00200000
64 #define MSTATUS_TSR 0x00400000
65 #define MSTATUS32_SD 0x80000000
66 #define MSTATUS_UXL 0x0000000300000000
67 #define MSTATUS_SXL 0x0000000C00000000
68 #define MSTATUS64_SD 0x8000000000000000
69 
70 #define SSTATUS_UIE 0x00000001
71 #define SSTATUS_SIE 0x00000002
72 #define SSTATUS_UPIE 0x00000010
73 #define SSTATUS_SPIE 0x00000020
74 #define SSTATUS_SPP 0x00000100
75 #define SSTATUS_FS 0x00006000
76 #define SSTATUS_XS 0x00018000
77 #define SSTATUS_SUM 0x00040000
78 #define SSTATUS_MXR 0x00080000
79 #define SSTATUS32_SD 0x80000000
80 #define SSTATUS_UXL 0x0000000300000000
81 #define SSTATUS64_SD 0x8000000000000000
82 
83 #define MIP_SSIP (1 << IRQ_S_SOFT)
84 #define MIP_HSIP (1 << IRQ_H_SOFT)
85 #define MIP_MSIP (1 << IRQ_M_SOFT)
86 #define MIP_STIP (1 << IRQ_S_TIMER)
87 #define MIP_HTIP (1 << IRQ_H_TIMER)
88 #define MIP_MTIP (1 << IRQ_M_TIMER)
89 #define MIP_SEIP (1 << IRQ_S_EXT)
90 #define MIP_HEIP (1 << IRQ_H_EXT)
91 #define MIP_MEIP (1 << IRQ_M_EXT)
92 
93 #define SIP_SSIP MIP_SSIP
94 #define SIP_STIP MIP_STIP
95 
96 #define PRV_U 0
97 #define PRV_S 1
98 #define PRV_H 2
99 #define PRV_M 3
100 
101 #define PAGE_OFFSET 12
102 #define OFFSET_MASK ((1 << PAGE_OFFSET) - 1)
103 #define PAGE_SIZE 1 << PAGE_OFFSET
104 #define LEVELS 3
105 #define VPN_OFFSET 9
106 #define PTESIZE 8
107 #define SATP_PPN_MASK ((0x1ULL << 44ULL) - 1ULL)
108 
109 #define SATP32_MODE 0x80000000
110 #define SATP32_ASID 0x7FC00000
111 #define SATP32_PPN 0x003FFFFF
112 #define SATP64_MODE 0xF000000000000000
113 #define SATP64_ASID 0x0FFFF00000000000
114 #define SATP64_PPN 0x00000FFFFFFFFFFF
115 
116 #define SATP_MODE_OFF 0
117 #define SATP_MODE_SV32 1
118 #define SATP_MODE_SV39 8
119 #define SATP_MODE_SV48 9
120 #define SATP_MODE_SV57 10
121 #define SATP_MODE_SV64 11
122 
123 #define PMP_R 0x01
124 #define PMP_W 0x02
125 #define PMP_X 0x04
126 #define PMP_A 0x18
127 #define PMP_L 0x80
128 #define PMP_SHIFT 2
129 
130 #define PMP_TOR 0x08
131 #define PMP_NA4 0x10
132 #define PMP_NAPOT 0x18
133 
134 #define IRQ_S_SOFT 1
135 #define IRQ_H_SOFT 2
136 #define IRQ_M_SOFT 3
137 #define IRQ_S_TIMER 5
138 #define IRQ_H_TIMER 6
139 #define IRQ_M_TIMER 7
140 #define IRQ_S_EXT 9
141 #define IRQ_H_EXT 10
142 #define IRQ_M_EXT 11
143 #define IRQ_COP 12
144 #define IRQ_HOST 13
145 
146 #define DEFAULT_RSTVEC 0x00001000
147 #define CLINT_BASE 0x02000000
148 #define CLINT_SIZE 0x000c0000
149 #define EXT_IO_BASE 0x40000000
150 #define DRAM_BASE 0x80000000
151 
152 // page table entry (PTE) fields
153 #define PTE_V 0x001 // Valid
154 #define PTE_R 0x002 // Read
155 #define PTE_W 0x004 // Write
156 #define PTE_X 0x008 // Execute
157 #define PTE_U 0x010 // User
158 #define PTE_G 0x020 // Global
159 #define PTE_A 0x040 // Accessed
160 #define PTE_D 0x080 // Dirty
161 #define PTE_SOFT 0x300 // Reserved for Software
162 
163 #define PTE_TABLE(PTE) (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V)
164 
165 #define CSR_SSTATUS 0x100
166 #define CSR_SIE 0x104
167 #define CSR_STVEC 0x105
168 #define CSR_SCOUNTEREN 0x106
169 #define CSR_SSCRATCH 0x140
170 #define CSR_SEPC 0x141
171 #define CSR_SCAUSE 0x142
172 #define CSR_STVAL 0x143
173 #define CSR_SIP 0x144
174 #define CSR_SATP 0x180
175 #define CSR_MSTATUS 0x300
176 #define CSR_MISA 0x301
177 #define CSR_MEDELEG 0x302
178 #define CSR_MIDELEG 0x303
179 #define CSR_MIE 0x304
180 #define CSR_MTVEC 0x305
181 #define CSR_MCOUNTEREN 0x306
182 #define CSR_MSCRATCH 0x340
183 #define CSR_MEPC 0x341
184 #define CSR_MCAUSE 0x342
185 #define CSR_MTVAL 0x343
186 #define CSR_MIP 0x344
187 
188 #define CAUSE_MISALIGNED_FETCH 0x0
189 #define CAUSE_FETCH_ACCESS 0x1
190 #define CAUSE_ILLEGAL_INSTRUCTION 0x2
191 #define CAUSE_BREAKPOINT 0x3
192 #define CAUSE_MISALIGNED_LOAD 0x4
193 #define CAUSE_LOAD_ACCESS 0x5
194 #define CAUSE_MISALIGNED_STORE 0x6
195 #define CAUSE_STORE_ACCESS 0x7
196 #define CAUSE_USER_ECALL 0x8
197 #define CAUSE_SUPERVISOR_ECALL 0x9
198 #define CAUSE_HYPERVISOR_ECALL 0xa
199 #define CAUSE_MACHINE_ECALL 0xb
200 #define CAUSE_FETCH_PAGE_FAULT 0xc
201 #define CAUSE_LOAD_PAGE_FAULT 0xd
202 #define CAUSE_STORE_PAGE_FAULT 0xf
203 #endif