Big code refactor, get rid of HAL entirely
This commit is contained in:
@ -1,15 +1,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "hal/hal.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "proc.h"
|
||||
#include "proc/proc.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "pmm/pmm.h"
|
||||
#include "util/util.h"
|
||||
#include "kprintf.h"
|
||||
#include "elf.h"
|
||||
#include "errors.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "bootinfo/bootinfo.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
@ -17,6 +13,13 @@
|
||||
#include "sysdefs/fs.h"
|
||||
#include "time/time.h"
|
||||
#include "std/string.h"
|
||||
#include "cpu/gdt.h"
|
||||
#include "intr/intr.h"
|
||||
#include "switch.h"
|
||||
#include "vmm/vmm.h"
|
||||
#include "elf.h"
|
||||
#include "errors.h"
|
||||
#include "kprintf.h"
|
||||
|
||||
#define PROC_REAPER_FREQ 30
|
||||
|
||||
@ -48,25 +51,25 @@ ElfAuxval proc_load_elf_segs(Proc *proc, uint8_t *data) {
|
||||
aux.phdr = (uint64_t)phdr->p_vaddr;
|
||||
} break;
|
||||
case PT_LOAD: {
|
||||
uint64_t off = phdr->p_vaddr & (HAL_PAGE_SIZE - 1);
|
||||
uint64_t blocks = (off + phdr->p_memsz + HAL_PAGE_SIZE - 1) / HAL_PAGE_SIZE;
|
||||
uint64_t off = phdr->p_vaddr & (VMM_PAGE_SIZE - 1);
|
||||
uint64_t blocks = (off + phdr->p_memsz + VMM_PAGE_SIZE - 1) / VMM_PAGE_SIZE;
|
||||
|
||||
uint8_t *physaddr = pmm_alloc(blocks);
|
||||
uint8_t *virtaddr = (uint8_t *)(phdr->p_vaddr & ~(HAL_PAGE_SIZE - 1));
|
||||
uint8_t *virtaddr = (uint8_t *)(phdr->p_vaddr & ~(VMM_PAGE_SIZE - 1));
|
||||
|
||||
memset(VIRT(physaddr), 0, blocks * HAL_PAGE_SIZE);
|
||||
memset(VIRT(physaddr), 0, blocks * VMM_PAGE_SIZE);
|
||||
memcpy(VIRT(physaddr) + off, (data + phdr->p_offset), phdr->p_filesz);
|
||||
|
||||
uint32_t pgflags = HAL_PG_USER | HAL_PG_PRESENT;
|
||||
uint32_t pgflags = VMM_PG_USER | VMM_PG_PRESENT;
|
||||
if (phdr->p_flags & PF_W) {
|
||||
pgflags |= HAL_PG_RW;
|
||||
pgflags |= VMM_PG_RW;
|
||||
}
|
||||
hal_vmm_map_range(proc->platformdata.cr3, virtaddr, physaddr, blocks * HAL_PAGE_SIZE, pgflags);
|
||||
vmm_map_range(proc->platformdata.cr3, virtaddr, physaddr, blocks * VMM_PAGE_SIZE, pgflags);
|
||||
|
||||
VasRange *range = dlmalloc(sizeof(*range));
|
||||
range->virtstart = virtaddr;
|
||||
range->physstart = physaddr;
|
||||
range->size = blocks * HAL_PAGE_SIZE;
|
||||
range->size = blocks * VMM_PAGE_SIZE;
|
||||
range->pgflags = pgflags;
|
||||
|
||||
LL_APPEND(proc->vas, range);
|
||||
@ -110,7 +113,7 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
||||
ksprintf(proc->name, "%s:%s", mountpoint, path);
|
||||
|
||||
memset(&proc->platformdata.trapframe, 0, sizeof(proc->platformdata.trapframe));
|
||||
proc->platformdata.cr3 = hal_vmm_userproc_pml4_phys();
|
||||
proc->platformdata.cr3 = vmm_userproc_pml4_phys();
|
||||
|
||||
uint8_t *kstackp = (uint8_t *)pmm_alloc(PROC_STACKBLOCKS) + PROC_STACKSIZE;
|
||||
proc->platformdata.kstack = kstackp;
|
||||
@ -120,8 +123,8 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
||||
uint64_t virttop = PROC_USER_STACK_TOP;
|
||||
uint64_t virtbase = virttop - PROC_STACKSIZE;
|
||||
|
||||
uint32_t flags = HAL_PG_RW | HAL_PG_PRESENT | HAL_PG_USER;
|
||||
hal_vmm_map_range(proc->platformdata.cr3, (void *)virtbase, (void *)pstackp, PROC_STACKSIZE, flags);
|
||||
uint32_t flags = VMM_PG_RW | VMM_PG_PRESENT | VMM_PG_USER;
|
||||
vmm_map_range(proc->platformdata.cr3, (void *)virtbase, (void *)pstackp, PROC_STACKSIZE, flags);
|
||||
|
||||
VasRange *range = dlmalloc(sizeof(*range));
|
||||
range->virtstart = (uint8_t *)virtbase;
|
||||
@ -203,8 +206,8 @@ void proc_reaper(void) {
|
||||
|
||||
VasRange *vas, *vastmp;
|
||||
LL_FOREACH_SAFE(zombie->vas, vas, vastmp) {
|
||||
hal_vmm_unmap_range(zombie->platformdata.cr3, vas->virtstart, vas->physstart, vas->size);
|
||||
pmm_free((uintptr_t)vas->physstart, vas->size / HAL_PAGE_SIZE);
|
||||
vmm_unmap_range(zombie->platformdata.cr3, vas->virtstart, vas->physstart, vas->size);
|
||||
pmm_free((uintptr_t)vas->physstart, vas->size / VMM_PAGE_SIZE);
|
||||
dlfree(vas);
|
||||
}
|
||||
|
||||
@ -221,7 +224,7 @@ void proc_reaper(void) {
|
||||
}
|
||||
|
||||
void proc_sched(void *cpustate) {
|
||||
hal_intr_disable();
|
||||
intr_disable();
|
||||
sched_ticks++;
|
||||
|
||||
memcpy(&PROCS.current->platformdata.trapframe, cpustate, sizeof(IntrStackFrame));
|
||||
@ -233,7 +236,7 @@ void proc_sched(void *cpustate) {
|
||||
}
|
||||
|
||||
tss.rsp0 = (uint64_t)VIRT(PROCS.current->platformdata.kstack);
|
||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
proc_switch(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
}
|
||||
|
||||
void proc_kill(Proc *proc) {
|
||||
@ -259,5 +262,5 @@ void proc_init(void) {
|
||||
init->state = PROC_READY;
|
||||
|
||||
tss.rsp0 = (uint64_t)VIRT(PROCS.current->platformdata.kstack);
|
||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
proc_switch(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user