Move vmm fully into hal

This commit is contained in:
2025-09-02 07:51:02 +02:00
parent 0fb3a1ca75
commit 920de10025
13 changed files with 76 additions and 186 deletions

View File

@ -21,13 +21,11 @@ char *hal_strchr(const char *s, int c);
void hal_init_withmalloc(void);
void hal_wait(uint32_t ms);
#if defined(__x86_64__)
# define HAL_PAGE_SIZE 0x1000
# include "x86_64/vmm.h"
# include "x86_64/proc.h"
# include "x86_64/switch.h"
# include "x86_64/paging.h"
# include "x86_64/cpu.h"
#endif
#define HAL_PAGE_SIZE 0x1000
#include "x86_64/vmm.h"
#include "x86_64/switch.h"
#include "x86_64/paging.h"
#include "x86_64/cpu.h"
#include "x86_64/intr.h"
#endif // KERNEL_HAL_HAL_H_

View File

@ -1,15 +0,0 @@
#ifndef HAL_PROC_H_
#define HAL_PROC_H_
#include <stdint.h>
#include "intr.h"
#include "vmm.h"
typedef struct {
uint64_t fsbase;
IntrStackFrame trapframe;
uint8_t *kstack;
PgTable *cr3;
} ProcPlatformData;
#endif // HAL_PROC_H_

View File

@ -7,8 +7,10 @@
#include "paging.h"
#include "proc/proc.h"
#include "kprintf.h"
#include "spinlock/spinlock.h"
PgTable *KERNEL_CR3 = NULL;
SpinLock spinlock;
PgTable *hal_vmm_current_cr3(void) {
PgTable *cr3;
@ -49,7 +51,9 @@ void hal_vmm_map_page(PgTable *pml4, uint64_t virtaddr, uint64_t physaddr, uint3
uint64_t *pml1 = hal_vmm_nexttable((uint64_t *)pml2, pi.pml2);
uint64_t *pte = &pml1[pi.pml1];
spinlock_acquire(&spinlock);
*pte = (physaddr & ~0xFFF) | (flags & 0x7);
spinlock_release(&spinlock);
}
void hal_vmm_unmap_page(PgTable *pml4, uint64_t virtaddr, uint64_t physaddr) {
@ -60,7 +64,9 @@ void hal_vmm_unmap_page(PgTable *pml4, uint64_t virtaddr, uint64_t physaddr) {
uint64_t *pml1 = hal_vmm_nexttable((uint64_t *)pml2, pi.pml2);
uint64_t *pte = &pml1[pi.pml1];
spinlock_acquire(&spinlock);
*pte &= ~HAL_PG_PRESENT;
spinlock_release(&spinlock);
}
void hal_vmm_map_range(PgTable *cr3, void *virtstart, void *physstart, size_t size, uint32_t flags) {
@ -113,6 +119,6 @@ PgTable *hal_vmm_userproc_pml4(Proc *proc) {
}
void hal_vmm_init(void) {
spinlock_init(&spinlock);
KERNEL_CR3 = hal_vmm_current_cr3();
kprintf("KERNEL_CR3 = %p\n", KERNEL_CR3);
}

View File

@ -3,8 +3,20 @@
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "compiler/attr.h"
#define VIRT(X) ((void *)(BOOT_INFO.hhdm_off + (uint64_t)(X)))
typedef struct VasRange {
struct VasRange *next;
uint8_t *virtstart;
uint8_t *physstart;
size_t size;
uint8_t pgflags;
} PACKED VasRange;
struct Proc;
enum {