@micro-os-plus/architecture-riscv 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +152 -0
- package/CMakeLists.txt +87 -0
- package/LICENSE +21 -0
- package/README.md +317 -0
- package/include/micro-os-plus/architecture-riscv/core-functions-inlines.h +86 -0
- package/include/micro-os-plus/architecture-riscv/core-functions.h +105 -0
- package/include/micro-os-plus/architecture-riscv/csr-functions-inlines.h +466 -0
- package/include/micro-os-plus/architecture-riscv/csr-functions.h +241 -0
- package/include/micro-os-plus/architecture-riscv/declarations.h +58 -0
- package/include/micro-os-plus/architecture-riscv/defines.h +185 -0
- package/include/micro-os-plus/architecture-riscv/device-functions-inlines.h +235 -0
- package/include/micro-os-plus/architecture-riscv/device-functions.h +166 -0
- package/include/micro-os-plus/architecture-riscv/instructions-inlines.h +172 -0
- package/include/micro-os-plus/architecture-riscv/instructions.h +153 -0
- package/include/micro-os-plus/architecture-riscv/platform-functions-inlines.h +81 -0
- package/include/micro-os-plus/architecture-riscv/platform-functions.h +75 -0
- package/include/micro-os-plus/architecture-riscv/plic-functions.h +278 -0
- package/include/micro-os-plus/architecture-riscv/semihosting-inlines.h +79 -0
- package/include/micro-os-plus/architecture-riscv/types.h +135 -0
- package/include/micro-os-plus/architecture.h +38 -0
- package/linker-scripts/README.md +7 -0
- package/linker-scripts/sections-flash.ld +425 -0
- package/linker-scripts/sections-ram.ld +425 -0
- package/linker-scripts/sections.ld +377 -0
- package/meson.build +46 -0
- package/package.json +37 -0
- package/src/.gitkeep +0 -0
- package/xpack.json +23 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the µOS++ distribution.
|
|
3
|
+
* (https://github.com/micro-os-plus/)
|
|
4
|
+
* Copyright (c) 2017 Liviu Ionescu.
|
|
5
|
+
*
|
|
6
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
7
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
8
|
+
*
|
|
9
|
+
* If a copy of the license was not distributed with this file, it can
|
|
10
|
+
* be obtained from https://opensource.org/licenses/MIT/.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#ifndef MICRO_OS_PLUS_ARCHITECTURE_RISCV_CSR_FUNCTIONS_H_
|
|
14
|
+
#define MICRO_OS_PLUS_ARCHITECTURE_RISCV_CSR_FUNCTIONS_H_
|
|
15
|
+
|
|
16
|
+
// ----------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
#include <micro-os-plus/architecture-riscv/types.h>
|
|
19
|
+
|
|
20
|
+
// ----------------------------------------------------------------------------
|
|
21
|
+
// RISC-V CSR support functions.
|
|
22
|
+
|
|
23
|
+
#if defined(__cplusplus)
|
|
24
|
+
extern "C"
|
|
25
|
+
{
|
|
26
|
+
#endif // defined(__cplusplus)
|
|
27
|
+
|
|
28
|
+
// --------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
#if 0
|
|
31
|
+
// Not available, due to ISA limitations.
|
|
32
|
+
// The workaround is to use distinct functions
|
|
33
|
+
// for each CSR. There are only 4096 of them.
|
|
34
|
+
|
|
35
|
+
riscv_architecture_register_t
|
|
36
|
+
riscv_csr_read (uint32_t reg);
|
|
37
|
+
|
|
38
|
+
void
|
|
39
|
+
riscv_csr_write (uint32_t reg, riscv_architecture_register_t value);
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
// --------------------------------------------------------------------------
|
|
43
|
+
// `mstatus`
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Read the `mstatus` CSR.
|
|
47
|
+
*/
|
|
48
|
+
static riscv_architecture_register_t
|
|
49
|
+
riscv_csr_read_mstatus (void);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Write the `mstatus` CSR.
|
|
53
|
+
*/
|
|
54
|
+
static void
|
|
55
|
+
riscv_csr_write_mstatus (riscv_architecture_register_t value);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Clear bits in the `mstatus` CSR.
|
|
59
|
+
*/
|
|
60
|
+
static riscv_architecture_register_t
|
|
61
|
+
riscv_csr_clear_mstatus_bits (riscv_architecture_register_t mask);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Set bits in the `mstatus` CSR.
|
|
65
|
+
*/
|
|
66
|
+
static riscv_architecture_register_t
|
|
67
|
+
riscv_csr_set_mstatus_bits (riscv_architecture_register_t mask);
|
|
68
|
+
|
|
69
|
+
// --------------------------------------------------------------------------
|
|
70
|
+
// `mtvec`
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Read the `mtvec` CSR.
|
|
74
|
+
*/
|
|
75
|
+
static riscv_architecture_register_t
|
|
76
|
+
riscv_csr_read_mtvec (void);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Write the `mtvec` CSR.
|
|
80
|
+
*/
|
|
81
|
+
static void
|
|
82
|
+
riscv_csr_write_mtvec (riscv_architecture_register_t value);
|
|
83
|
+
|
|
84
|
+
// --------------------------------------------------------------------------
|
|
85
|
+
// `mcause`
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Read the `mcause` CSR.
|
|
89
|
+
*/
|
|
90
|
+
static riscv_architecture_register_t
|
|
91
|
+
riscv_csr_read_mcause (void);
|
|
92
|
+
|
|
93
|
+
// --------------------------------------------------------------------------
|
|
94
|
+
// `mie`
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Read the `mie` CSR.
|
|
98
|
+
*/
|
|
99
|
+
static riscv_architecture_register_t
|
|
100
|
+
riscv_csr_read_mie (void);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Write the `mie` CSR.
|
|
104
|
+
*/
|
|
105
|
+
static void
|
|
106
|
+
riscv_csr_write_mie (riscv_architecture_register_t value);
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Clear bits in the `mie` CSR.
|
|
110
|
+
*/
|
|
111
|
+
static riscv_architecture_register_t
|
|
112
|
+
riscv_csr_clear_mie_bits (riscv_architecture_register_t mask);
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Set bits in the `mie` CSR.
|
|
116
|
+
*/
|
|
117
|
+
static riscv_architecture_register_t
|
|
118
|
+
riscv_csr_set_mie_bits (riscv_architecture_register_t mask);
|
|
119
|
+
|
|
120
|
+
// --------------------------------------------------------------------------
|
|
121
|
+
// `mcycle`
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Read the `mcycle` CSR.
|
|
125
|
+
*/
|
|
126
|
+
#if __riscv_xlen == 64
|
|
127
|
+
static
|
|
128
|
+
#endif // __riscv_xlen == 64
|
|
129
|
+
uint64_t
|
|
130
|
+
riscv_csr_read_mcycle (void);
|
|
131
|
+
|
|
132
|
+
static uint32_t
|
|
133
|
+
riscv_csr_read_mcycle_low (void);
|
|
134
|
+
|
|
135
|
+
static uint32_t
|
|
136
|
+
riscv_csr_read_mcycle_high (void);
|
|
137
|
+
|
|
138
|
+
// --------------------------------------------------------------------------
|
|
139
|
+
// `mhartid`
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Read the `mhartid` CSR.
|
|
143
|
+
*/
|
|
144
|
+
static riscv_architecture_register_t
|
|
145
|
+
riscv_csr_read_mhartid (void);
|
|
146
|
+
|
|
147
|
+
// --------------------------------------------------------------------------
|
|
148
|
+
|
|
149
|
+
#if defined(__cplusplus)
|
|
150
|
+
}
|
|
151
|
+
#endif // defined(__cplusplus)
|
|
152
|
+
|
|
153
|
+
// ============================================================================
|
|
154
|
+
|
|
155
|
+
#if defined(__cplusplus)
|
|
156
|
+
|
|
157
|
+
// ----------------------------------------------------------------------------
|
|
158
|
+
|
|
159
|
+
namespace riscv
|
|
160
|
+
{
|
|
161
|
+
namespace csr
|
|
162
|
+
{
|
|
163
|
+
// ------------------------------------------------------------------------
|
|
164
|
+
// `mstatus`
|
|
165
|
+
|
|
166
|
+
architecture::register_t
|
|
167
|
+
mstatus (void);
|
|
168
|
+
|
|
169
|
+
void
|
|
170
|
+
mstatus (architecture::register_t value);
|
|
171
|
+
|
|
172
|
+
void
|
|
173
|
+
clear_mstatus_bits (architecture::register_t mask);
|
|
174
|
+
|
|
175
|
+
void
|
|
176
|
+
set_mstatus_bits (architecture::register_t mask);
|
|
177
|
+
|
|
178
|
+
// ------------------------------------------------------------------------
|
|
179
|
+
// `mtvec`
|
|
180
|
+
|
|
181
|
+
architecture::register_t
|
|
182
|
+
mtvec (void);
|
|
183
|
+
|
|
184
|
+
void
|
|
185
|
+
mtvec (architecture::register_t value);
|
|
186
|
+
|
|
187
|
+
// ------------------------------------------------------------------------
|
|
188
|
+
// `mcause`
|
|
189
|
+
|
|
190
|
+
architecture::register_t
|
|
191
|
+
mcause (void);
|
|
192
|
+
|
|
193
|
+
// ------------------------------------------------------------------------
|
|
194
|
+
// `mie`
|
|
195
|
+
|
|
196
|
+
architecture::register_t
|
|
197
|
+
mie (void);
|
|
198
|
+
|
|
199
|
+
void
|
|
200
|
+
mie (architecture::register_t value);
|
|
201
|
+
|
|
202
|
+
void
|
|
203
|
+
clear_mie_bits (architecture::register_t mask);
|
|
204
|
+
|
|
205
|
+
void
|
|
206
|
+
set_mie_bits (architecture::register_t mask);
|
|
207
|
+
|
|
208
|
+
// ------------------------------------------------------------------------
|
|
209
|
+
// `mcycle`
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Read the mcycle counter.
|
|
213
|
+
*/
|
|
214
|
+
uint64_t
|
|
215
|
+
mcycle (void);
|
|
216
|
+
|
|
217
|
+
uint32_t
|
|
218
|
+
mcycle_low (void);
|
|
219
|
+
|
|
220
|
+
uint32_t
|
|
221
|
+
mcycle_high (void);
|
|
222
|
+
|
|
223
|
+
// ------------------------------------------------------------------------
|
|
224
|
+
// `mhartid`
|
|
225
|
+
|
|
226
|
+
architecture::register_t
|
|
227
|
+
mhartid (void);
|
|
228
|
+
|
|
229
|
+
// ------------------------------------------------------------------------
|
|
230
|
+
} // namespace csr
|
|
231
|
+
} // namespace riscv
|
|
232
|
+
|
|
233
|
+
// ----------------------------------------------------------------------------
|
|
234
|
+
|
|
235
|
+
#endif // defined(__cplusplus)
|
|
236
|
+
|
|
237
|
+
// ----------------------------------------------------------------------------
|
|
238
|
+
|
|
239
|
+
#endif // MICRO_OS_PLUS_ARCHITECTURE_RISCV_CSR_FUNCTIONS_H_
|
|
240
|
+
|
|
241
|
+
// ----------------------------------------------------------------------------
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the µOS++ distribution.
|
|
3
|
+
* (https://github.com/micro-os-plus/)
|
|
4
|
+
* Copyright (c) 2017 Liviu Ionescu.
|
|
5
|
+
*
|
|
6
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
7
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
8
|
+
*
|
|
9
|
+
* If a copy of the license was not distributed with this file, it can
|
|
10
|
+
* be obtained from https://opensource.org/licenses/MIT/.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#ifndef MICRO_OS_PLUS_ARCHITECTURE_RISCV_ARCH_DECLARATIONS_H_
|
|
14
|
+
#define MICRO_OS_PLUS_ARCHITECTURE_RISCV_ARCH_DECLARATIONS_H_
|
|
15
|
+
|
|
16
|
+
// ----------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
#include <micro-os-plus/architecture-riscv/types.h>
|
|
19
|
+
|
|
20
|
+
#include <stdint.h>
|
|
21
|
+
|
|
22
|
+
// ----------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
#if defined(__cplusplus)
|
|
25
|
+
|
|
26
|
+
// ----------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
namespace riscv
|
|
29
|
+
{
|
|
30
|
+
namespace core
|
|
31
|
+
{
|
|
32
|
+
// ------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
extern riscv_core_trap_handler_ptr_t local_interrupt_handlers[];
|
|
35
|
+
extern riscv_core_trap_handler_ptr_t global_interrupt_handlers[];
|
|
36
|
+
|
|
37
|
+
// ------------------------------------------------------------------------
|
|
38
|
+
} // namespace core
|
|
39
|
+
|
|
40
|
+
namespace architecture
|
|
41
|
+
{
|
|
42
|
+
// ------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
// TODO: add C++ declarations here.
|
|
45
|
+
|
|
46
|
+
// ------------------------------------------------------------------------
|
|
47
|
+
} // namespace architecture
|
|
48
|
+
} // namespace riscv
|
|
49
|
+
|
|
50
|
+
// ----------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
#endif // defined(__cplusplus)
|
|
53
|
+
|
|
54
|
+
// ----------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
#endif // MICRO_OS_PLUS_ARCHITECTURE_RISCV_ARCH_DECLARATIONS_H_
|
|
57
|
+
|
|
58
|
+
// ----------------------------------------------------------------------------
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the µOS++ distribution.
|
|
3
|
+
* (https://github.com/micro-os-plus/)
|
|
4
|
+
* Copyright (c) 2017 Liviu Ionescu.
|
|
5
|
+
*
|
|
6
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
7
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
8
|
+
*
|
|
9
|
+
* If a copy of the license was not distributed with this file, it can
|
|
10
|
+
* be obtained from https://opensource.org/licenses/MIT/.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#ifndef MICRO_OS_PLUS_ARCHITECTURE_RISCV_ARCH_DEFINES_H_
|
|
14
|
+
#define MICRO_OS_PLUS_ARCHITECTURE_RISCV_ARCH_DEFINES_H_
|
|
15
|
+
|
|
16
|
+
// ----------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
#define MICRO_OS_PLUS_INTEGER_STARTUP_STACK_FILL_MAGIC (0xEFBEADDE)
|
|
19
|
+
|
|
20
|
+
#if 0
|
|
21
|
+
// TODO: check and possibly prefix them.
|
|
22
|
+
|
|
23
|
+
// ----------------------------------------------------------------------------
|
|
24
|
+
// Definitions from SiFive bsp/env/encoding.h.
|
|
25
|
+
|
|
26
|
+
#define DCSR_XDEBUGVER (3U << 30)
|
|
27
|
+
#define DCSR_NDRESET (1 << 29)
|
|
28
|
+
#define DCSR_FULLRESET (1 << 28)
|
|
29
|
+
#define DCSR_EBREAKM (1 << 15)
|
|
30
|
+
#define DCSR_EBREAKH (1 << 14)
|
|
31
|
+
#define DCSR_EBREAKS (1 << 13)
|
|
32
|
+
#define DCSR_EBREAKU (1 << 12)
|
|
33
|
+
#define DCSR_STOPCYCLE (1 << 10)
|
|
34
|
+
#define DCSR_STOPTIME (1 << 9)
|
|
35
|
+
#define DCSR_CAUSE (7 << 6)
|
|
36
|
+
#define DCSR_DEBUGINT (1 << 5)
|
|
37
|
+
#define DCSR_HALT (1 << 3)
|
|
38
|
+
#define DCSR_STEP (1 << 2)
|
|
39
|
+
#define DCSR_PRV (3 << 0)
|
|
40
|
+
|
|
41
|
+
#define DCSR_CAUSE_NONE 0
|
|
42
|
+
#define DCSR_CAUSE_SWBP 1
|
|
43
|
+
#define DCSR_CAUSE_HWBP 2
|
|
44
|
+
#define DCSR_CAUSE_DEBUGINT 3
|
|
45
|
+
#define DCSR_CAUSE_STEP 4
|
|
46
|
+
#define DCSR_CAUSE_HALT 5
|
|
47
|
+
|
|
48
|
+
#define MCONTROL_TYPE(xlen) (0xfULL << ((xlen)-4))
|
|
49
|
+
#define MCONTROL_DMODE(xlen) (1ULL << ((xlen)-5))
|
|
50
|
+
#define MCONTROL_MASKMAX(xlen) (0x3fULL << ((xlen)-11))
|
|
51
|
+
|
|
52
|
+
#define MCONTROL_SELECT (1 << 19)
|
|
53
|
+
#define MCONTROL_TIMING (1 << 18)
|
|
54
|
+
#define MCONTROL_ACTION (0x3f << 12)
|
|
55
|
+
#define MCONTROL_CHAIN (1 << 11)
|
|
56
|
+
#define MCONTROL_MATCH (0xf << 7)
|
|
57
|
+
#define MCONTROL_M (1 << 6)
|
|
58
|
+
#define MCONTROL_H (1 << 5)
|
|
59
|
+
#define MCONTROL_S (1 << 4)
|
|
60
|
+
#define MCONTROL_U (1 << 3)
|
|
61
|
+
#define MCONTROL_EXECUTE (1 << 2)
|
|
62
|
+
#define MCONTROL_STORE (1 << 1)
|
|
63
|
+
#define MCONTROL_LOAD (1 << 0)
|
|
64
|
+
|
|
65
|
+
#define MCONTROL_TYPE_NONE 0
|
|
66
|
+
#define MCONTROL_TYPE_MATCH 2
|
|
67
|
+
|
|
68
|
+
#define MCONTROL_ACTION_DEBUG_EXCEPTION 0
|
|
69
|
+
#define MCONTROL_ACTION_DEBUG_MODE 1
|
|
70
|
+
#define MCONTROL_ACTION_TRACE_START 2
|
|
71
|
+
#define MCONTROL_ACTION_TRACE_STOP 3
|
|
72
|
+
#define MCONTROL_ACTION_TRACE_EMIT 4
|
|
73
|
+
|
|
74
|
+
#define MCONTROL_MATCH_EQUAL 0
|
|
75
|
+
#define MCONTROL_MATCH_NAPOT 1
|
|
76
|
+
#define MCONTROL_MATCH_GE 2
|
|
77
|
+
#define MCONTROL_MATCH_LT 3
|
|
78
|
+
#define MCONTROL_MATCH_MASK_LOW 4
|
|
79
|
+
#define MCONTROL_MATCH_MASK_HIGH 5
|
|
80
|
+
|
|
81
|
+
#define PRV_U 0
|
|
82
|
+
#define PRV_S 1
|
|
83
|
+
#define PRV_H 2
|
|
84
|
+
#define PRV_M 3
|
|
85
|
+
|
|
86
|
+
#define VM_MBARE 0
|
|
87
|
+
#define VM_MBB 1
|
|
88
|
+
#define VM_MBBID 2
|
|
89
|
+
#define VM_SV32 8
|
|
90
|
+
#define VM_SV39 9
|
|
91
|
+
#define VM_SV48 10
|
|
92
|
+
|
|
93
|
+
// ----------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
#define DEFAULT_RSTVEC 0x00001000
|
|
96
|
+
#define DEFAULT_NMIVEC 0x00001004
|
|
97
|
+
#define DEFAULT_MTVEC 0x00001010
|
|
98
|
+
#define CONFIG_STRING_ADDR 0x0000100C
|
|
99
|
+
#define EXT_IO_BASE 0x40000000
|
|
100
|
+
#define DRAM_BASE 0x80000000
|
|
101
|
+
|
|
102
|
+
// page table entry (PTE) fields
|
|
103
|
+
#define PTE_V 0x001 // Valid
|
|
104
|
+
#define PTE_R 0x002 // Read
|
|
105
|
+
#define PTE_W 0x004 // Write
|
|
106
|
+
#define PTE_X 0x008 // Execute
|
|
107
|
+
#define PTE_U 0x010 // User
|
|
108
|
+
#define PTE_G 0x020 // Global
|
|
109
|
+
#define PTE_A 0x040 // Accessed
|
|
110
|
+
#define PTE_D 0x080 // Dirty
|
|
111
|
+
#define PTE_SOFT 0x300 // Reserved for Software
|
|
112
|
+
|
|
113
|
+
#define PTE_PPN_SHIFT 10
|
|
114
|
+
|
|
115
|
+
#define PTE_TABLE(PTE) (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V)
|
|
116
|
+
|
|
117
|
+
#if __riscv_xlen == 32
|
|
118
|
+
#define MSTATUS_SD MSTATUS32_SD
|
|
119
|
+
#define SSTATUS_SD SSTATUS32_SD
|
|
120
|
+
#define RISCV_PGLEVEL_BITS 10
|
|
121
|
+
#elif __riscv_xlen == 64
|
|
122
|
+
#define MSTATUS_SD MSTATUS64_SD
|
|
123
|
+
#define SSTATUS_SD SSTATUS64_SD
|
|
124
|
+
#define RISCV_PGLEVEL_BITS 9
|
|
125
|
+
#endif // __riscv_xlen
|
|
126
|
+
|
|
127
|
+
#define RISCV_PGSHIFT 12
|
|
128
|
+
#define RISCV_PGSIZE (1 << RISCV_PGSHIFT)
|
|
129
|
+
|
|
130
|
+
// End of SiFive definitions.
|
|
131
|
+
// ----------------------------------------------------------------------------
|
|
132
|
+
#endif
|
|
133
|
+
|
|
134
|
+
#define RISCV_CSR_MSTATUS_UIE 0x00000001ul
|
|
135
|
+
#define RISCV_CSR_MSTATUS_SIE 0x00000002ul
|
|
136
|
+
#define RISCV_CSR_MSTATUS_MIE 0x00000008ul
|
|
137
|
+
#define RISCV_CSR_MSTATUS_UPIE 0x00000010ul
|
|
138
|
+
#define RISCV_CSR_MSTATUS_SPIE 0x00000020ul
|
|
139
|
+
#define RISCV_CSR_MSTATUS_MPIE 0x00000080ul
|
|
140
|
+
#define RISCV_CSR_MSTATUS_SPP 0x00000100ul
|
|
141
|
+
#define RISCV_CSR_MSTATUS_MPP 0x00001800ul
|
|
142
|
+
#define RISCV_CSR_MSTATUS_FS 0x00006000ul
|
|
143
|
+
#define RISCV_CSR_MSTATUS_XS 0x00018000ul
|
|
144
|
+
#define RISCV_CSR_MSTATUS_MPRV 0x00020000ul
|
|
145
|
+
#define RISCV_CSR_MSTATUS_PUM 0x00040000ul
|
|
146
|
+
#define RISCV_CSR_MSTATUS_MXR 0x00080000ul
|
|
147
|
+
#define RISCV_CSR_MSTATUS_VM 0x1F000000ul
|
|
148
|
+
#define RISCV_CSR_MSTATUS32_SD 0x80000000ul
|
|
149
|
+
#define RISCV_CSR_MSTATUS64_SD 0x8000000000000000ul
|
|
150
|
+
|
|
151
|
+
#define RISCV_CSR_SSTATUS_UIE 0x00000001ul
|
|
152
|
+
#define RISCV_CSR_SSTATUS_SIE 0x00000002ul
|
|
153
|
+
#define RISCV_CSR_SSTATUS_UPIE 0x00000010ul
|
|
154
|
+
#define RISCV_CSR_SSTATUS_SPIE 0x00000020ul
|
|
155
|
+
#define RISCV_CSR_SSTATUS_SPP 0x00000100ul
|
|
156
|
+
#define RISCV_CSR_SSTATUS_FS 0x00006000ul
|
|
157
|
+
#define RISCV_CSR_SSTATUS_XS 0x00018000ul
|
|
158
|
+
#define RISCV_CSR_SSTATUS_PUM 0x00040000ul
|
|
159
|
+
#define RISCV_CSR_SSTATUS32_SD 0x80000000ul
|
|
160
|
+
#define RISCV_CSR_SSTATUS64_SD 0x8000000000000000ul
|
|
161
|
+
|
|
162
|
+
#define RISCV_CSR_MIP_SSIP (1ul << riscv_interrupt_local_supervisor_software)
|
|
163
|
+
#define RISCV_CSR_MIP_MSIP (1ul << riscv_interrupt_local_machine_software)
|
|
164
|
+
#define RISCV_CSR_MIP_STIP (1ul << riscv_interrupt_local_supervisor_timer)
|
|
165
|
+
#define RISCV_CSR_MIP_MTIP (1ul << riscv_interrupt_local_machine_timer)
|
|
166
|
+
#define RISCV_CSR_MIP_SEIP (1ul << riscv_interrupt_local_supervisor_ext)
|
|
167
|
+
#define RISCV_CSR_MIP_MEIP (1ul << riscv_interrupt_local_machine_ext)
|
|
168
|
+
|
|
169
|
+
// ----------------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
#if __riscv_xlen == 32
|
|
172
|
+
#define RISCV_CSR_MCAUSE_INTERRUPT (1ul << 31ul)
|
|
173
|
+
#define RISCV_CSR_MCAUSE_CAUSE (0x7FFFFFFFul)
|
|
174
|
+
#elif __riscv_xlen == 64
|
|
175
|
+
#define RISCV_CSR_MCAUSE_INTERRUPT (1ul << 63ul)
|
|
176
|
+
#define RISCV_CSR_MCAUSE_CAUSE (0x7FFFFFFFFFFFFFFFul)
|
|
177
|
+
#else
|
|
178
|
+
#error "Unsupported __riscv_xlen"
|
|
179
|
+
#endif // __riscv_xlen
|
|
180
|
+
|
|
181
|
+
// ----------------------------------------------------------------------------
|
|
182
|
+
|
|
183
|
+
#endif // MICRO_OS_PLUS_ARCHITECTURE_RISCV_ARCH_DEFINES_H_
|
|
184
|
+
|
|
185
|
+
// ----------------------------------------------------------------------------
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the µOS++ distribution.
|
|
3
|
+
* (https://github.com/micro-os-plus/)
|
|
4
|
+
* Copyright (c) 2017 Liviu Ionescu.
|
|
5
|
+
*
|
|
6
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
7
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
8
|
+
*
|
|
9
|
+
* If a copy of the license was not distributed with this file, it can
|
|
10
|
+
* be obtained from https://opensource.org/licenses/MIT/.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#ifndef MICRO_OS_PLUS_ARCHITECTURE_RISCV_DEVICE_FUNCTIONS_INLINES_H_
|
|
14
|
+
#define MICRO_OS_PLUS_ARCHITECTURE_RISCV_DEVICE_FUNCTIONS_INLINES_H_
|
|
15
|
+
|
|
16
|
+
// ----------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
#include <stdint.h>
|
|
19
|
+
|
|
20
|
+
// ----------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
// Inline implementations for the common device support functions.
|
|
23
|
+
// Not included by architecture files, but by device files.
|
|
24
|
+
|
|
25
|
+
#if defined(__cplusplus)
|
|
26
|
+
extern "C"
|
|
27
|
+
{
|
|
28
|
+
#endif // defined(__cplusplus)
|
|
29
|
+
|
|
30
|
+
// --------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
#if __riscv_xlen == 64
|
|
33
|
+
|
|
34
|
+
static inline __attribute__ ((always_inline)) uint64_t
|
|
35
|
+
riscv_device_read_mtime (void)
|
|
36
|
+
{
|
|
37
|
+
return *(volatile uint64_t*)(RISCV_MMIO_MTIME_ADDRESS);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#endif // __riscv_xlen == 64
|
|
41
|
+
|
|
42
|
+
static inline __attribute__ ((always_inline)) uint32_t
|
|
43
|
+
riscv_device_read_mtime_low (void)
|
|
44
|
+
{
|
|
45
|
+
return *(volatile uint32_t*)(RISCV_MMIO_MTIME_ADDRESS);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static inline __attribute__ ((always_inline)) uint32_t
|
|
49
|
+
riscv_device_read_mtime_high (void)
|
|
50
|
+
{
|
|
51
|
+
return *(volatile uint32_t*)(RISCV_MMIO_MTIME_ADDRESS + 4);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#if __riscv_xlen == 64
|
|
55
|
+
|
|
56
|
+
static inline __attribute__ ((always_inline)) void
|
|
57
|
+
riscv_device_write_mtime (uint64_t value)
|
|
58
|
+
{
|
|
59
|
+
*(volatile uint64_t*)(RISCV_MMIO_MTIME_ADDRESS) = value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#endif // __riscv_xlen == 64
|
|
63
|
+
|
|
64
|
+
static inline __attribute__ ((always_inline)) void
|
|
65
|
+
riscv_device_write_mtime_low (uint32_t value)
|
|
66
|
+
{
|
|
67
|
+
*(volatile uint32_t*)(RISCV_MMIO_MTIME_ADDRESS) = value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static inline __attribute__ ((always_inline)) void
|
|
71
|
+
riscv_device_write_mtime_high (uint32_t value)
|
|
72
|
+
{
|
|
73
|
+
*(volatile uint32_t*)(RISCV_MMIO_MTIME_ADDRESS + 4) = value;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// --------------------------------------------------------------------------
|
|
77
|
+
|
|
78
|
+
static inline __attribute__ ((always_inline)) uint64_t
|
|
79
|
+
riscv_device_read_mtimecmp (void)
|
|
80
|
+
{
|
|
81
|
+
// On RV32 the compiler generates two word accesses.
|
|
82
|
+
return *(uint64_t*)(RISCV_MMIO_MTIMECMP_ADDRESS);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static inline __attribute__ ((always_inline)) uint32_t
|
|
86
|
+
riscv_device_read_mtimecmp_low (void)
|
|
87
|
+
{
|
|
88
|
+
return *(uint32_t*)(RISCV_MMIO_MTIMECMP_ADDRESS);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static inline __attribute__ ((always_inline)) uint32_t
|
|
92
|
+
riscv_device_read_mtimecmp_high (void)
|
|
93
|
+
{
|
|
94
|
+
return *(uint32_t*)(RISCV_MMIO_MTIMECMP_ADDRESS + 4);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#if __riscv_xlen == 64
|
|
98
|
+
|
|
99
|
+
static inline __attribute__ ((always_inline)) void
|
|
100
|
+
riscv_device_write_mtimecmp (uint64_t value)
|
|
101
|
+
{
|
|
102
|
+
*(uint64_t*)(RISCV_MMIO_MTIMECMP_ADDRESS) = value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#endif // __riscv_xlen == 64
|
|
106
|
+
|
|
107
|
+
static inline __attribute__ ((always_inline)) void
|
|
108
|
+
riscv_device_write_mtimecmp_low (uint32_t value)
|
|
109
|
+
{
|
|
110
|
+
*(uint32_t*)(RISCV_MMIO_MTIMECMP_ADDRESS) = value;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static inline __attribute__ ((always_inline)) void
|
|
114
|
+
riscv_device_write_mtimecmp_high (uint32_t value)
|
|
115
|
+
{
|
|
116
|
+
*(uint32_t*)(RISCV_MMIO_MTIMECMP_ADDRESS + 4) = value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// --------------------------------------------------------------------------
|
|
120
|
+
|
|
121
|
+
#if defined(__cplusplus)
|
|
122
|
+
}
|
|
123
|
+
#endif // defined(__cplusplus)
|
|
124
|
+
|
|
125
|
+
// ============================================================================
|
|
126
|
+
|
|
127
|
+
#if defined(__cplusplus)
|
|
128
|
+
|
|
129
|
+
// ----------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
namespace riscv
|
|
132
|
+
{
|
|
133
|
+
namespace device
|
|
134
|
+
{
|
|
135
|
+
// ------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
#if __riscv_xlen == 64
|
|
138
|
+
|
|
139
|
+
inline __attribute__ ((always_inline)) uint64_t
|
|
140
|
+
mtime (void)
|
|
141
|
+
{
|
|
142
|
+
return riscv_device_read_mtime ();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#endif // __riscv_xlen == 64
|
|
146
|
+
|
|
147
|
+
inline __attribute__ ((always_inline)) uint32_t
|
|
148
|
+
mtime_low (void)
|
|
149
|
+
{
|
|
150
|
+
return riscv_device_read_mtime_low ();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
inline __attribute__ ((always_inline)) uint32_t
|
|
154
|
+
mtime_high (void)
|
|
155
|
+
{
|
|
156
|
+
return riscv_device_read_mtime_high ();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#if __riscv_xlen == 64
|
|
160
|
+
|
|
161
|
+
inline __attribute__ ((always_inline)) void
|
|
162
|
+
mtime (uint64_t value)
|
|
163
|
+
{
|
|
164
|
+
riscv_device_write_mtime (value);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
#endif // __riscv_xlen == 64
|
|
168
|
+
|
|
169
|
+
inline __attribute__ ((always_inline)) void
|
|
170
|
+
mtime_low (uint32_t value)
|
|
171
|
+
{
|
|
172
|
+
riscv_device_write_mtime_low (value);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
inline __attribute__ ((always_inline)) void
|
|
176
|
+
mtime_high (uint32_t value)
|
|
177
|
+
{
|
|
178
|
+
riscv_device_write_mtime_high (value);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ------------------------------------------------------------------------
|
|
182
|
+
|
|
183
|
+
inline __attribute__ ((always_inline)) uint64_t
|
|
184
|
+
mtimecmp (void)
|
|
185
|
+
{
|
|
186
|
+
return riscv_device_read_mtimecmp ();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
inline __attribute__ ((always_inline)) uint32_t
|
|
190
|
+
mtimecmp_low (void)
|
|
191
|
+
{
|
|
192
|
+
return riscv_device_read_mtimecmp_low ();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
inline __attribute__ ((always_inline)) uint32_t
|
|
196
|
+
mtimecmp_high (void)
|
|
197
|
+
{
|
|
198
|
+
return riscv_device_read_mtimecmp_high ();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
#if __riscv_xlen == 64
|
|
202
|
+
|
|
203
|
+
inline __attribute__ ((always_inline)) void
|
|
204
|
+
mtimecmp (uint64_t value)
|
|
205
|
+
{
|
|
206
|
+
riscv_device_write_mtimecmp (value);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
#endif // __riscv_xlen == 64
|
|
210
|
+
|
|
211
|
+
inline __attribute__ ((always_inline)) void
|
|
212
|
+
mtimecmp_low (uint32_t value)
|
|
213
|
+
{
|
|
214
|
+
riscv_device_write_mtimecmp_low (value);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
inline __attribute__ ((always_inline)) void
|
|
218
|
+
mtimecmp_high (uint32_t value)
|
|
219
|
+
{
|
|
220
|
+
riscv_device_write_mtimecmp_high (value);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ------------------------------------------------------------------------
|
|
224
|
+
} // namespace device
|
|
225
|
+
} // namespace riscv
|
|
226
|
+
|
|
227
|
+
// ----------------------------------------------------------------------------
|
|
228
|
+
|
|
229
|
+
#endif // defined(__cplusplus)
|
|
230
|
+
|
|
231
|
+
// ----------------------------------------------------------------------------
|
|
232
|
+
|
|
233
|
+
#endif // MICRO_OS_PLUS_ARCHITECTURE_RISCV_DEVICE_FUNCTIONS_INLINES_H_
|
|
234
|
+
|
|
235
|
+
// ----------------------------------------------------------------------------
|