usr: implement user process switching
This is a rather large commit, so the gist of it is this: User context switching is now functional, after a change to the TSS, and a few minor details in the scheduler and loader. ELF parsing is rather primitive, but basically functional, as long as it only loads code. The interrupt 0x80 is for syscalls, and will switch from user mode to kernel mode. It is currently the only interrupt that can be called from user mode This adds the syscall functionality, which currently uses a red-black tree to store the function pointers, although when the table is more flushed out, it will probably be replaced with an array The pager now correctly marks the parent nodes with attributes as it allocates them. Without doing this, the page table entries will never be reached in lower privilege modes, causing page faults Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
parent
d60da85470
commit
37518aea81
19 changed files with 262 additions and 69 deletions
17
init/main.c
17
init/main.c
|
|
@ -41,20 +41,17 @@ uintptr_t bss_end;
|
|||
|
||||
void gdt_load();
|
||||
void idt_load();
|
||||
void yield();
|
||||
void ap_kmain(struct limine_smp_info *info);
|
||||
void load_stack_and_park(uintptr_t rsp, uintptr_t rbp);
|
||||
|
||||
uintptr_t kstacks[256] = { 0 };
|
||||
|
||||
void prompt()
|
||||
{
|
||||
kprintf(COL_YELLOW_BLACK "vbos # " COL_RESET);
|
||||
}
|
||||
|
||||
void yield()
|
||||
{
|
||||
for (;;) {
|
||||
__asm__("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
void panic()
|
||||
{
|
||||
|
|
@ -159,7 +156,7 @@ void kmain()
|
|||
char *root_path = kcmdline_get_symbol("root");
|
||||
if (!root_path) {
|
||||
kprintf(LOG_ERROR "No root= parameter specified\n");
|
||||
|
||||
|
||||
kerror_print_blkdevs();
|
||||
panic();
|
||||
} else {
|
||||
|
|
@ -184,7 +181,6 @@ void kmain()
|
|||
|
||||
/* init the application processors */
|
||||
struct limine_smp_response *smp_resp = smp_req.response;
|
||||
proc_init(smp_resp->cpu_count);
|
||||
for (unsigned i = 0; i < smp_resp->cpu_count; i++) {
|
||||
struct limine_smp_info *info = smp_resp->cpus[i];
|
||||
|
||||
|
|
@ -193,6 +189,9 @@ void kmain()
|
|||
|
||||
info->goto_address = ap_kmain;
|
||||
}
|
||||
proc_init(smp_resp->cpu_count);
|
||||
void syscall_init();
|
||||
syscall_init();
|
||||
|
||||
/* wait for the application processors to finish their initialization */
|
||||
for (unsigned i = 0; i < 100000; i++)
|
||||
|
|
@ -220,6 +219,8 @@ void ap_kmain(struct limine_smp_info *info)
|
|||
void *kstack = buddy_alloc(KSTACK_SIZE);
|
||||
uintptr_t ptr = (uintptr_t)kstack + KSTACK_SIZE - 8;
|
||||
|
||||
kstacks[info->lapic_id] = (uintptr_t)ptr;
|
||||
|
||||
/* insert the TSS for each processor into the GDT */
|
||||
#ifdef KDEBUG
|
||||
kprintf(LOG_DEBUG "Inserting TSS for AP #%d\n", info->lapic_id);
|
||||
|
|
|
|||
Loading…
Reference in a new issue