diff options
author | Robert Morris <[email protected]> | 2019-05-31 09:45:59 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2019-05-31 09:45:59 -0400 |
commit | 2ec1959fd1016a18ef3b2d154ce7076be8f237e4 (patch) | |
tree | 1aa75252085964283b3a2c735771f4da02346517 /start.c | |
parent | 0f90388c893d1924e89e2e4d2187eda0004e9d73 (diff) | |
download | xv6-labs-2ec1959fd1016a18ef3b2d154ce7076be8f237e4.tar.gz xv6-labs-2ec1959fd1016a18ef3b2d154ce7076be8f237e4.tar.bz2 xv6-labs-2ec1959fd1016a18ef3b2d154ce7076be8f237e4.zip |
fork/wait/exit work
Diffstat (limited to 'start.c')
-rw-r--r-- | start.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -0,0 +1,34 @@ +#include "types.h" +#include "memlayout.h" +#include "riscv.h" +#include "defs.h" + +void main(); + +// entry.S uses this as the initial stack. +char stack0[4096]; + +// entry.S jumps here in machine mode on stack0. +void +mstart() +{ + // set M Previous Privilege mode to Supervisor, for mret. + unsigned long x = r_mstatus(); + x &= ~MSTATUS_MPP_MASK; + x |= MSTATUS_MPP_S; + w_mstatus(x); + + // set M Exception Program Counter to main, for mret. + // requires gcc -mcmodel=medany + w_mepc((uint64)main); + + // disable paging for now. + w_satp(0); + + // delegate all interrupts and exceptions to supervisor mode. + w_medeleg(0xffff); + w_mideleg(0xffff); + + // jump to main in supervisor mode. + asm("mret"); +} |