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,15 +1,15 @@
#include <stdint.h>
#include <stddef.h>
#include "kprintf.h"
#include "syscall.h"
#include "errors.h"
#include "syscall/syscall.h"
#include "spinlock/spinlock.h"
#include "proc/proc.h"
#include "sysdefs/dev.h"
#include "util/util.h"
#include "hshtb.h"
#include "dev/dev.h"
#include "std/string.h"
#include "errors.h"
#include "kprintf.h"
#include "hshtb.h"
int32_t SYSCALL2(sys_dev_gethandle, dev1, devname1) {
uint64_t *devh = (uint64_t *)dev1;

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include "syscall.h"
#include "syscall/syscall.h"
int32_t SYSCALL2(sys_dev_gethandle, dev1, devname1);
int32_t SYSCALL0(sys_dev_listsize);

View File

@ -1,14 +1,14 @@
#include <stdint.h>
#include <stddef.h>
#include "syscall.h"
#include "syscall/syscall.h"
#include "sysdefs/fs.h"
#include "errors.h"
#include "path/path.h"
#include "vfs/vfs.h"
#include "kprintf.h"
#include "proc/proc.h"
#include "spinlock/spinlock.h"
#include "util/util.h"
#include "errors.h"
#include "kprintf.h"
#define _MP_MAX 0xff
#define _PATH_MAX VFS_PATH_MAX

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include "syscall.h"
#include "syscall/syscall.h"
int32_t SYSCALL2(sys_fs_openf, opath1, oflags1);
int32_t SYSCALL1(sys_fs_closef, fsh1);

View File

@ -1,12 +1,12 @@
#include <stddef.h>
#include <stdint.h>
#include "ipcpipe.h"
#include "syscall/ipcpipe.h"
#include "ipc/pipe/pipe.h"
#include "dlmalloc/malloc.h"
#include "proc/proc.h"
#include "spinlock/spinlock.h"
#include "errors.h"
#include "util/util.h"
#include "errors.h"
#include "kprintf.h"
int32_t SYSCALL4(sys_ipc_piperead, pid1, pipenum1, buffer1, len1) {

View File

@ -1,7 +1,9 @@
#ifndef SYSCALL_IPCPIPE_H_
#define SYSCALL_IPCPIPE_H_
#include "syscall.h"
#include <stdint.h>
#include <stddef.h>
#include "syscall/syscall.h"
int32_t SYSCALL4(sys_ipc_piperead, pid1, pipenum1, buffer1, len1);
int32_t SYSCALL4(sys_ipc_pipewrite, pid1, pipenum1, buffer1, len1);

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;
}

View File

@ -1,7 +1,9 @@
#ifndef SYSCALL_MMAN_H_
#define SYSCALL_MMAN_H_
#include "syscall.h"
#include <stdint.h>
#include <stddef.h>
#include "syscall/syscall.h"
int32_t SYSCALL5(sys_mman_map, addr1, size1, prot1, flags1, out1);
int32_t SYSCALL1(sys_mman_unmap, addr1);

View File

@ -1,17 +1,17 @@
#include <stdint.h>
#include <stddef.h>
#include "syscall.h"
#include "syscall/syscall.h"
#include "proc/proc.h"
#include "spinlock/spinlock.h"
#include "errors.h"
#include "util/util.h"
#include "sysdefs/proc.h"
#include "vfs/vfs.h"
#include "path/path.h"
#include "kprintf.h"
#include "dlmalloc/malloc.h"
#include "ipc/pipe/pipe.h"
#include "std/string.h"
#include "errors.h"
#include "kprintf.h"
#define _MP_MAX 0xff
#define _PATH_MAX VFS_PATH_MAX

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include "syscall.h"
#include "syscall/syscall.h"
int32_t SYSCALL1(sys_proc_kill, pid1);
int32_t SYSCALL3(sys_proc_spawn, opath1, args1, argslen1);

View File

@ -1,8 +1,8 @@
#include <stdint.h>
#include <stddef.h>
#include "hal/hal.h"
#include "syscall.h"
#include "syscall/syscall.h"
#include "randcrypto/physrand.h"
int32_t SYSCALL0(sys_rand) {
return hal_randnum();
return randcrypto_get_physrand();
}

View File

@ -1,7 +1,9 @@
#ifndef SYSCALL_RANDCRYPTO_H_
#define SYSCALL_RANDCRYPTO_H_
#include "syscall.h"
#include <stdint.h>
#include <stddef.h>
#include "syscall/syscall.h"
int32_t SYSCALL0(sys_rand);

View File

@ -1,10 +1,10 @@
#include <stdint.h>
#include "syscall.h"
#include "sched.h"
#include "syscall/syscall.h"
#include "syscall/sched.h"
#include "proc/proc.h"
#include "spinlock/spinlock.h"
#include "intr/pit.h"
#include "errors.h"
#include "hal/hal.h"
int32_t SYSCALL0(sys_schedrelease) {
return E_DOSCHEDULING;
@ -12,6 +12,6 @@ int32_t SYSCALL0(sys_schedrelease) {
int32_t SYSCALL1(sys_schedsleep, ms1) {
uint32_t ms = (uint32_t)ms1;
hal_wait(ms);
intr_pit_wait(ms);
return E_OK;
}

View File

@ -2,7 +2,8 @@
#define SYSCALL_SCHED_H_
#include <stdint.h>
#include "syscall.h"
#include <stddef.h>
#include "syscall/syscall.h"
int32_t SYSCALL0(sys_schedrelease);
int32_t SYSCALL1(sys_schedsleep, ms1);

View File

@ -1,17 +1,17 @@
#include <stdint.h>
#include "syscall.h"
#include "sysdefs/syscall.h"
#include "syscall/syscall.h"
#include "syscall/ipcpipe.h"
#include "syscall/mman.h"
#include "syscall/sched.h"
#include "syscall/randcrypto.h"
#include "syscall/vfs.h"
#include "syscall/proc.h"
#include "syscall/fs.h"
#include "syscall/dev.h"
#include "syscall/time.h"
#include "errors.h"
#include "kprintf.h"
#include "sysdefs/syscall.h"
#include "ipcpipe.h"
#include "mman.h"
#include "sched.h"
#include "randcrypto.h"
#include "vfs.h"
#include "proc.h"
#include "fs.h"
#include "dev.h"
#include "time.h"
int32_t SYSCALL1(sys_debugprint, string) {
char *p = (char *)string;

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include "compiler/attr.h"
#include "hal/hal.h"
#include "intr/intr.h"
#define SYSCALLS_MAX 0xff

View File

@ -1,7 +1,7 @@
#include <stdint.h>
#include <stddef.h>
#include "syscall.h"
#include "time.h"
#include "syscall/syscall.h"
#include "syscall/time.h"
#include "sysdefs/time.h"
#include "time/time.h"
#include "errors.h"

View File

@ -3,6 +3,7 @@
#include <stdint.h>
#include <stddef.h>
#include "syscall/syscall.h"
int32_t SYSCALL1(sys_time, timestruct1);

View File

@ -1,10 +1,8 @@
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "hal/hal.h"
#include "syscall.h"
#include "vfs.h"
#include "errors.h"
#include "syscall/syscall.h"
#include "syscall/vfs.h"
#include "sysdefs/dev.h"
#include "sysdefs/vfs.h"
#include "vfs/vfs.h"
@ -13,8 +11,9 @@
#include "proc/proc.h"
#include "storedev/storedev.h"
#include "util/util.h"
#include "hshtb.h"
#include "std/string.h"
#include "hshtb.h"
#include "errors.h"
int32_t SYSCALL4(sys_vfsmount, mountpoint1, fstypestr1, devid1, format1) {
int32_t ret = E_OK;