aboutsummaryrefslogtreecommitdiff
path: root/pk/minit.c
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2015-03-12 17:38:04 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2015-03-12 17:38:04 -0700
commit6517fe26a2a0c89c3112f4a383c601572c71d64a (patch)
treed37eea7ae6f3e15eee94afb5c9c749a4cd800577 /pk/minit.c
parenta4ae7da6ef0c09c2616a0b82f7f569e4e134f75c (diff)
downloadpk-6517fe26a2a0c89c3112f4a383c601572c71d64a.zip
pk-6517fe26a2a0c89c3112f4a383c601572c71d64a.tar.gz
pk-6517fe26a2a0c89c3112f4a383c601572c71d64a.tar.bz2
Update to new privileged spec
Diffstat (limited to 'pk/minit.c')
-rw-r--r--pk/minit.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/pk/minit.c b/pk/minit.c
new file mode 100644
index 0000000..a8a449f
--- /dev/null
+++ b/pk/minit.c
@@ -0,0 +1,62 @@
+#include "vm.h"
+#include "mtrap.h"
+
+uintptr_t mem_size;
+uint32_t num_harts;
+
+static void mstatus_init()
+{
+ uintptr_t ms = read_csr(mstatus);
+ ms = INSERT_FIELD(ms, MSTATUS_SA, UA_RV64);
+ ms = INSERT_FIELD(ms, MSTATUS_UA, UA_RV64);
+ ms = INSERT_FIELD(ms, MSTATUS_PRV1, PRV_S);
+ ms = INSERT_FIELD(ms, MSTATUS_IE1, 0);
+ ms = INSERT_FIELD(ms, MSTATUS_PRV2, PRV_U);
+ ms = INSERT_FIELD(ms, MSTATUS_IE2, 1);
+ ms = INSERT_FIELD(ms, MSTATUS_MPRV, PRV_M);
+ ms = INSERT_FIELD(ms, MSTATUS_VM, VM_SV43);
+ ms = INSERT_FIELD(ms, MSTATUS_FS, 3);
+ ms = INSERT_FIELD(ms, MSTATUS_XS, 3);
+ write_csr(mstatus, ms);
+ ms = read_csr(mstatus);
+
+ if (EXTRACT_FIELD(ms, MSTATUS_PRV1) != PRV_S) {
+ ms = INSERT_FIELD(ms, MSTATUS_PRV1, PRV_U);
+ ms = INSERT_FIELD(ms, MSTATUS_IE1, 1);
+ write_csr(mstatus, ms);
+
+ panic("supervisor support is required");
+ }
+
+ if (EXTRACT_FIELD(ms, MSTATUS_VM) != VM_SV43)
+ have_vm = 0;
+}
+
+static void memory_init()
+{
+ if (mem_size == 0)
+ panic("could not determine memory capacity");
+}
+
+static void hart_init()
+{
+ if (num_harts == 0)
+ panic("could not determine number of harts");
+
+ if (num_harts != 1)
+ panic("TODO: SMP support");
+}
+
+void machine_init()
+{
+ file_init();
+
+ struct mainvars arg_buffer;
+ struct mainvars *args = parse_args(&arg_buffer);
+
+ mstatus_init();
+ memory_init();
+ hart_init();
+ vm_init();
+ boot_loader(args);
+}