Big code refactor, get rid of HAL entirely

This commit is contained in:
2025-11-11 21:26:27 +01:00
parent 7015bc9576
commit 566b35f4d5
84 changed files with 477 additions and 520 deletions

View File

@ -1,17 +1,17 @@
#include <stdint.h>
#include "syscall.h"
#include "mman.h"
#include "syscall/syscall.h"
#include "syscall/mman.h"
#include "spinlock/spinlock.h"
#include "proc/proc.h"
#include "hal/hal.h"
#include "pmm/pmm.h"
#include "util/util.h"
#include "errors.h"
#include "sysdefs/mman.h"
#include "bootinfo/bootinfo.h"
#include "dlmalloc/malloc.h"
#include "kprintf.h"
#include "std/string.h"
#include "vmm/vmm.h"
#include "errors.h"
#include "kprintf.h"
int32_t SYSCALL5(sys_mman_map, addr1, size1, prot1, flags1, out1) {
uint8_t *addr = (uint8_t *)addr1;
@ -20,16 +20,16 @@ int32_t SYSCALL5(sys_mman_map, addr1, size1, prot1, flags1, out1) {
uint64_t flags = flags1;
uint8_t **out = (uint8_t **)out1;
if (size == 0 || (size % HAL_PAGE_SIZE != 0)) {
if (size == 0 || (size % VMM_PAGE_SIZE != 0)) {
if (out != NULL) {
*out = NULL;
}
return E_INVALIDARGUMENT;
}
size_t pages = _DIV_ROUNDUP(size, HAL_PAGE_SIZE);
size_t pages = _DIV_ROUNDUP(size, VMM_PAGE_SIZE);
uint8_t *phys = (uint8_t *)pmm_alloc(pages);
memset(VIRT(phys), 0, pages * HAL_PAGE_SIZE);
memset(VIRT(phys), 0, pages * VMM_PAGE_SIZE);
spinlock_acquire(&PROCS.spinlock);
Proc *proc = NULL;
@ -38,7 +38,7 @@ int32_t SYSCALL5(sys_mman_map, addr1, size1, prot1, flags1, out1) {
uint8_t *virt = NULL;
if ((flags & MMAN_MAP_F_FIXED) && addr != NULL) {
if ((uintptr_t)addr % HAL_PAGE_SIZE != 0) {
if ((uintptr_t)addr % VMM_PAGE_SIZE != 0) {
if (out != NULL) {
*out = NULL;
}
@ -49,19 +49,19 @@ int32_t SYSCALL5(sys_mman_map, addr1, size1, prot1, flags1, out1) {
virt = addr;
} else {
virt = (uint8_t *)proc->mman_map_base;
proc->mman_map_base += pages * HAL_PAGE_SIZE;
proc->mman_map_base += pages * VMM_PAGE_SIZE;
}
uint64_t pflags = HAL_PG_USER | HAL_PG_PRESENT;
uint64_t pflags = VMM_PG_USER | VMM_PG_PRESENT;
if (prot & MMAN_MAP_PF_RW) {
pflags |= HAL_PG_RW;
pflags |= VMM_PG_RW;
}
hal_vmm_map_range(proc->platformdata.cr3, virt, phys, pages * HAL_PAGE_SIZE, pflags);
vmm_map_range(proc->platformdata.cr3, virt, phys, pages * VMM_PAGE_SIZE, pflags);
VasRange *range = dlmalloc(sizeof(*range));
range->virtstart = virt;
range->physstart = phys;
range->size = pages * HAL_PAGE_SIZE;
range->size = pages * VMM_PAGE_SIZE;
range->pgflags = pflags;
LL_APPEND(proc->vas, range);
@ -98,9 +98,9 @@ int32_t SYSCALL1(sys_mman_unmap, addr1) {
return E_INVALIDARGUMENT;
}
hal_vmm_unmap_range(proc->platformdata.cr3, tofree->virtstart, tofree->physstart, tofree->size);
vmm_unmap_range(proc->platformdata.cr3, tofree->virtstart, tofree->physstart, tofree->size);
LL_REMOVE(proc->vas, tofree);
pmm_free((uintptr_t)tofree->physstart, tofree->size / HAL_PAGE_SIZE);
pmm_free((uintptr_t)tofree->physstart, tofree->size / VMM_PAGE_SIZE);
dlfree(tofree);
return E_OK;
}