Initial commit
This commit is contained in:
51
kernel/start.c
Normal file
51
kernel/start.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include "kernel/lib.h"
|
||||
#include "kernel/riscv.h"
|
||||
#include "kernel/kalloc.h"
|
||||
#include "kernel/vm.h"
|
||||
#include "kernel/cpu.h"
|
||||
|
||||
Cpu cpus[MAX_CPU];
|
||||
|
||||
extern uint32_t _bss_start;
|
||||
extern uint32_t _bss_end;
|
||||
extern uint32_t _ram_end;
|
||||
|
||||
void kstrap()
|
||||
{
|
||||
panic("kstrap");
|
||||
}
|
||||
|
||||
void kstart()
|
||||
{
|
||||
kalloc_init();
|
||||
kvm_init();
|
||||
|
||||
panic("kstart: end");
|
||||
}
|
||||
|
||||
void kinit()
|
||||
{
|
||||
// @Todo Initialize CPUs
|
||||
Cpu null_cpu = {0};
|
||||
cpus[0] = null_cpu;
|
||||
|
||||
// Clear the BSS section
|
||||
for (uint32_t* ptr = &_bss_start; ptr < &_bss_end; ++ptr)
|
||||
{
|
||||
*ptr = 0U;
|
||||
}
|
||||
|
||||
w_mideleg(0xFFFF);
|
||||
w_medeleg(0xFFFF);
|
||||
|
||||
w_sstatus(SSTATUS_SPIE | SSTATUS_SPP_S);
|
||||
w_sie(SIE_SEIE);
|
||||
w_sepc(&kstart);
|
||||
w_stvec(&kstrap);
|
||||
|
||||
w_pmpcfg0(PMPCFG_RW | PMPCFG_X | PMPCFG_TOR);
|
||||
w_pmpaddr0(((uint32_t)&_ram_end) >> PMPADDR_SHIFT);
|
||||
|
||||
__asm__ volatile("sret");
|
||||
}
|
||||
|
Reference in New Issue
Block a user