coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
virtual_memory.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Early initialization code for riscv virtual memory
4  */
5 
6 #include <arch/cpu.h>
7 #include <arch/encoding.h>
8 #include <vm.h>
9 
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)
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)
27  ;
28 
29 void mstatus_init(void)
30 {
31  // clear any pending timer interrupts.
32  clear_csr(mip, MIP_STIP | MIP_SSIP);
33 
34  // enable machine and supervisor timer and
35  // all other supervisor interrupts.
36  set_csr(mie, MIP_MTIP | MIP_STIP | MIP_SSIP);
37 
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);
43  }
44 
45  // Enable all user/supervisor-mode counters
46  write_csr(mcounteren, 7);
47 }
static int supports_extension(char ext)
Definition: cpu.h:24
#define CAUSE_ILLEGAL_INSTRUCTION
Definition: encoding.h:964
#define MIP_SSIP
Definition: encoding.h:98
#define CAUSE_STORE_ACCESS
Definition: encoding.h:969
#define MIP_STIP
Definition: encoding.h:101
#define MIP_MTIP
Definition: encoding.h:103
#define CAUSE_MISALIGNED_FETCH
Definition: encoding.h:962
#define CAUSE_LOAD_ACCESS
Definition: encoding.h:967
#define CAUSE_BREAKPOINT
Definition: encoding.h:965
#define CAUSE_FETCH_ACCESS
Definition: encoding.h:963
#define CAUSE_STORE_PAGE_FAULT
Definition: encoding.h:976
#define CAUSE_FETCH_PAGE_FAULT
Definition: encoding.h:974
#define CAUSE_USER_ECALL
Definition: encoding.h:970
#define CAUSE_LOAD_PAGE_FAULT
Definition: encoding.h:975
static int delegate
void mstatus_init(void)