summaryrefslogtreecommitdiff
path: root/kernel/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/main.c')
-rw-r--r--kernel/main.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/kernel/main.c b/kernel/main.c
new file mode 100644
index 0000000..2168b9f
--- /dev/null
+++ b/kernel/main.c
@@ -0,0 +1,42 @@
+#include "types.h"
+#include "param.h"
+#include "memlayout.h"
+#include "riscv.h"
+#include "defs.h"
+
+volatile static int started = 0;
+
+// Bootstrap processor starts running C code here.
+// Allocate a real stack and switch to it, first
+// doing some setup required for memory allocator to work.
+void
+main()
+{
+ if(cpuid() == 0){
+ uartinit(); // serial port
+ consoleinit();
+ printf("hart %d starting\n", cpuid());
+ kinit(); // physical page allocator
+ kvminit(); // create kernel page table
+ kvminithart(); // turn on paging
+ procinit(); // process table
+ trapinit(); // trap vectors
+ trapinithart(); // install kernel trap vector
+ plicinit(); // set up interrupt controller
+ plicinithart(); // ask PLIC for device interrupts
+ binit(); // buffer cache
+ fileinit(); // file table
+ ramdiskinit(); // disk
+ userinit(); // first user process
+ started = 1;
+ } else {
+ while(started == 0)
+ ;
+ printf("hart %d starting\n", cpuid());
+ kvminithart(); // turn on paging
+ trapinithart(); // install kernel trap vector
+ plicinithart(); // ask PLIC for device interrupts
+ }
+
+ scheduler();
+}