95 lines
2.8 KiB
C
95 lines
2.8 KiB
C
|
// TODO: CHECK/REPLACE/UPDATE OLD CODE (this file is based on xv6)
|
||
|
#include "types.h"
|
||
|
#include "param.h"
|
||
|
#include "memlayout.h"
|
||
|
#include "riscv.h"
|
||
|
#include "defs.h"
|
||
|
#include "sched.h"
|
||
|
#include "vmrd.h"
|
||
|
#include "kprintf.h"
|
||
|
|
||
|
void syscall_init();
|
||
|
void fpu_init();
|
||
|
void resources_init(); // autogenerated
|
||
|
|
||
|
volatile static int started = 0;
|
||
|
|
||
|
// start() jumps here in supervisor mode on all CPUs.
|
||
|
void
|
||
|
main()
|
||
|
{
|
||
|
if(SCHED_CORE_THISNUMBER_NOINTERRUPTS() == 0){
|
||
|
consoleinit();
|
||
|
kprintf_init();
|
||
|
kprintf("\nRealtime64 Kernel starting up...\n");
|
||
|
#ifdef _ZCC
|
||
|
printf("[compiled with new C compiler]\n");
|
||
|
#else
|
||
|
printf("[compiled with legacy C compiler]\n");
|
||
|
#endif
|
||
|
printf("\n");
|
||
|
|
||
|
timeslice_max = 1000000;
|
||
|
timeslice_min = 1000;
|
||
|
|
||
|
printf("physpg_initbegin()...\n");
|
||
|
physpg_initbegin();
|
||
|
printf("physpg_setrange(PHYSPG_FREERAM, %p, %p)...\n", end, (void*)PHYSTOP);
|
||
|
physpg_setrange(PHYSPG_FREERAM, end, (void*)PHYSTOP);
|
||
|
printf("physpg_initend()...\n");
|
||
|
physpg_initend();
|
||
|
printf("kvminit()...\n");
|
||
|
kvminit(); // create kernel page table
|
||
|
printf("kvminithart()...\n");
|
||
|
kvminithart(); // turn on paging
|
||
|
printf("resources_init()...\n");
|
||
|
resources_init();
|
||
|
printf("procinit()...\n");
|
||
|
procinit(); // process table
|
||
|
printf("trapinit()...\n");
|
||
|
trapinit(); // trap vectors
|
||
|
printf("trapinithart()...\n");
|
||
|
trapinithart(); // install kernel trap vector
|
||
|
printf("plicinit()...\n");
|
||
|
plicinit(); // set up interrupt controller
|
||
|
printf("plicinithart()...\n");
|
||
|
plicinithart(); // ask PLIC for device interrupts
|
||
|
printf("fileinit()...\n");
|
||
|
fileinit(); // file table
|
||
|
printf("vmrd_present()?\n");
|
||
|
if (vmrd_present()) {
|
||
|
printf("YES, using vmrd_init()...\n");
|
||
|
vmrd_init();
|
||
|
} else {
|
||
|
printf("NO, using virtio_disk_init()...\n");
|
||
|
virtio_disk_init(); // emulated hard disk
|
||
|
}
|
||
|
printf("syscall_init()...\n");
|
||
|
syscall_init(); // syscall table must now be initialised at startup
|
||
|
printf("fpu_init()...\n");
|
||
|
fpu_init();
|
||
|
printf("userinit()...\n");
|
||
|
userinit(); // first user process
|
||
|
printf("Kernel booted?\n");
|
||
|
printf("%d MB total %d MB free\n", (int) (physpg_totalram()/MB), (int)(physpg_freeram()/MB));
|
||
|
__sync_synchronize();
|
||
|
started = 1;
|
||
|
} else {
|
||
|
//consputc('+');
|
||
|
//while(1){}
|
||
|
while(started == 0)
|
||
|
;
|
||
|
__sync_synchronize();
|
||
|
printf("hart %d starting\n", SCHED_CORE_THISNUMBER_NOINTERRUPTS());
|
||
|
//printf("kvminithart()...\n");
|
||
|
kvminithart(); // turn on paging
|
||
|
//printf("trapinithart()...\n");
|
||
|
trapinithart(); // install kernel trap vector
|
||
|
//printf("plicinithart()...\n");
|
||
|
plicinithart(); // ask PLIC for device interrupts
|
||
|
}
|
||
|
|
||
|
//printf("ENTERING SCHEDULER ON HART %d\n", SCHED_CORE_THISNUMBER_NOINTERRUPTS());
|
||
|
scheduler();
|
||
|
}
|