blob: 3538505813d4f325c289fd20e3288949c08cad85 [file] [log] [blame]
Ronak Kanabar1ae366f2023-06-07 01:21:56 +05301/** @file
2 RISC-V CSR encodings
3
4 Copyright (c) 2019, Western Digital Corporation or its affiliates. All rights reserved.<BR>
5 Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#ifndef RISCV_ENCODING_H_
11#define RISCV_ENCODING_H_
12
13#define MSTATUS_SIE 0x00000002UL
14#define MSTATUS_MIE 0x00000008UL
15#define MSTATUS_SPIE_SHIFT 5
16#define MSTATUS_SPIE (1UL << MSTATUS_SPIE_SHIFT)
17#define MSTATUS_UBE 0x00000040UL
18#define MSTATUS_MPIE 0x00000080UL
19#define MSTATUS_SPP_SHIFT 8
20#define MSTATUS_SPP (1UL << MSTATUS_SPP_SHIFT)
21#define MSTATUS_MPP_SHIFT 11
22#define MSTATUS_MPP (3UL << MSTATUS_MPP_SHIFT)
23
24#define SSTATUS_SIE MSTATUS_SIE
25#define SSTATUS_SPIE_SHIFT MSTATUS_SPIE_SHIFT
26#define SSTATUS_SPIE MSTATUS_SPIE
27#define SSTATUS_SPP_SHIFT MSTATUS_SPP_SHIFT
28#define SSTATUS_SPP MSTATUS_SPP
29
30#define IRQ_S_SOFT 1
31#define IRQ_VS_SOFT 2
32#define IRQ_M_SOFT 3
33#define IRQ_S_TIMER 5
34#define IRQ_VS_TIMER 6
35#define IRQ_M_TIMER 7
36#define IRQ_S_EXT 9
37#define IRQ_VS_EXT 10
38#define IRQ_M_EXT 11
39#define IRQ_S_GEXT 12
40#define IRQ_PMU_OVF 13
41
42#define MIP_SSIP (1UL << IRQ_S_SOFT)
43#define MIP_VSSIP (1UL << IRQ_VS_SOFT)
44#define MIP_MSIP (1UL << IRQ_M_SOFT)
45#define MIP_STIP (1UL << IRQ_S_TIMER)
46#define MIP_VSTIP (1UL << IRQ_VS_TIMER)
47#define MIP_MTIP (1UL << IRQ_M_TIMER)
48#define MIP_SEIP (1UL << IRQ_S_EXT)
49#define MIP_VSEIP (1UL << IRQ_VS_EXT)
50#define MIP_MEIP (1UL << IRQ_M_EXT)
51#define MIP_SGEIP (1UL << IRQ_S_GEXT)
52#define MIP_LCOFIP (1UL << IRQ_PMU_OVF)
53
54#define SIP_SSIP MIP_SSIP
55#define SIP_STIP MIP_STIP
56
57#define PRV_U 0UL
58#define PRV_S 1UL
59#define PRV_M 3UL
60
61#define SATP64_MODE 0xF000000000000000ULL
62#define SATP64_ASID 0x0FFFF00000000000ULL
63#define SATP64_PPN 0x00000FFFFFFFFFFFULL
64
65#define SATP_MODE_OFF 0UL
66#define SATP_MODE_SV32 1UL
67#define SATP_MODE_SV39 8UL
68#define SATP_MODE_SV48 9UL
69#define SATP_MODE_SV57 10UL
70#define SATP_MODE_SV64 11UL
71
72#define SATP_MODE SATP64_MODE
73
74/* User Counters/Timers */
75#define CSR_CYCLE 0xc00
76#define CSR_TIME 0xc01
77
78/* Supervisor Trap Setup */
79#define CSR_SSTATUS 0x100
80#define CSR_SEDELEG 0x102
81#define CSR_SIDELEG 0x103
82#define CSR_SIE 0x104
83#define CSR_STVEC 0x105
84
85/* Supervisor Configuration */
86#define CSR_SENVCFG 0x10a
87
88/* Supervisor Trap Handling */
89#define CSR_SSCRATCH 0x140
90#define CSR_SEPC 0x141
91#define CSR_SCAUSE 0x142
92#define CSR_STVAL 0x143
93#define CSR_SIP 0x144
94
95/* Supervisor Protection and Translation */
96#define CSR_SATP 0x180
97
98/* Trap/Exception Causes */
99#define CAUSE_MISALIGNED_FETCH 0x0
100#define CAUSE_FETCH_ACCESS 0x1
101#define CAUSE_ILLEGAL_INSTRUCTION 0x2
102#define CAUSE_BREAKPOINT 0x3
103#define CAUSE_MISALIGNED_LOAD 0x4
104#define CAUSE_LOAD_ACCESS 0x5
105#define CAUSE_MISALIGNED_STORE 0x6
106#define CAUSE_STORE_ACCESS 0x7
107#define CAUSE_USER_ECALL 0x8
108#define CAUSE_SUPERVISOR_ECALL 0x9
109#define CAUSE_VIRTUAL_SUPERVISOR_ECALL 0xa
110#define CAUSE_MACHINE_ECALL 0xb
111#define CAUSE_FETCH_PAGE_FAULT 0xc
112#define CAUSE_LOAD_PAGE_FAULT 0xd
113#define CAUSE_STORE_PAGE_FAULT 0xf
114#define CAUSE_FETCH_GUEST_PAGE_FAULT 0x14
115#define CAUSE_LOAD_GUEST_PAGE_FAULT 0x15
116#define CAUSE_VIRTUAL_INST_FAULT 0x16
117#define CAUSE_STORE_GUEST_PAGE_FAULT 0x17
118
119#endif