1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Early initialization code for riscv virtual memory
7 #include <arch/encoding.h>
10 /* Delegate controls which traps are delegated to the payload. If you
11 * wish to temporarily disable some or all delegation you can, in a
12 * debugger, set it to a different value (e.g. 0 to have all traps go
13 * to M-mode). In practice, this variable has been a lifesaver. It is
14 * still not quite determined which delegation might by unallowed by
15 * the spec so for now we enumerate and set them all. */
16 static int delegate
= 0
17 | (1 << CAUSE_MISALIGNED_FETCH
)
18 | (1 << CAUSE_FETCH_ACCESS
)
19 | (1 << CAUSE_ILLEGAL_INSTRUCTION
)
20 | (1 << CAUSE_BREAKPOINT
)
21 | (1 << CAUSE_LOAD_ACCESS
)
22 | (1 << CAUSE_STORE_ACCESS
)
23 | (1 << CAUSE_USER_ECALL
)
24 | (1 << CAUSE_FETCH_PAGE_FAULT
)
25 | (1 << CAUSE_LOAD_PAGE_FAULT
)
26 | (1 << CAUSE_STORE_PAGE_FAULT
)
29 void mstatus_init(void)
31 // clear any pending timer interrupts.
32 clear_csr(mip
, MIP_STIP
| MIP_SSIP
);
34 // enable machine and supervisor timer and
35 // all other supervisor interrupts.
36 set_csr(mie
, MIP_MTIP
| MIP_STIP
| MIP_SSIP
);
38 // Delegate supervisor timer and other interrupts to supervisor mode,
39 // if supervisor mode is supported.
40 if (supports_extension('S')) {
41 set_csr(mideleg
, MIP_STIP
| MIP_SSIP
);
42 set_csr(medeleg
, delegate
);
45 // Enable all user/supervisor-mode counters
46 write_csr(mcounteren
, 7);