Move vmm fully into hal
This commit is contained in:
@ -43,7 +43,6 @@ SRCFILES += $(call GRABSRC, \
|
|||||||
bootinfo \
|
bootinfo \
|
||||||
spinlock \
|
spinlock \
|
||||||
term \
|
term \
|
||||||
vmm \
|
|
||||||
dlmalloc \
|
dlmalloc \
|
||||||
vfs \
|
vfs \
|
||||||
storedev \
|
storedev \
|
||||||
|
@ -13,11 +13,7 @@ BootInfo BOOT_INFO;
|
|||||||
static volatile struct limine_paging_mode_request paging_req = {
|
static volatile struct limine_paging_mode_request paging_req = {
|
||||||
.id = LIMINE_PAGING_MODE_REQUEST,
|
.id = LIMINE_PAGING_MODE_REQUEST,
|
||||||
.revision = 0,
|
.revision = 0,
|
||||||
#if defined(__x86_64__)
|
|
||||||
.mode = LIMINE_PAGING_MODE_X86_64_4LVL,
|
.mode = LIMINE_PAGING_MODE_X86_64_4LVL,
|
||||||
#else
|
|
||||||
# error "Paging mode is unknown for this architecture"
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_REQ(kernel_address, KERNEL_ADDRESS);
|
DEFINE_REQ(kernel_address, KERNEL_ADDRESS);
|
||||||
@ -38,9 +34,7 @@ void bootinfo_init(void) {
|
|||||||
BOOT_INFO.modules = modulesres;
|
BOOT_INFO.modules = modulesres;
|
||||||
|
|
||||||
struct limine_paging_mode_response *pagingres = paging_req.response;
|
struct limine_paging_mode_response *pagingres = paging_req.response;
|
||||||
#if defined(__x86_64__)
|
|
||||||
if (pagingres->mode != LIMINE_PAGING_MODE_X86_64_4LVL) {
|
if (pagingres->mode != LIMINE_PAGING_MODE_X86_64_4LVL) {
|
||||||
#endif
|
|
||||||
hal_hang();
|
hal_hang();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
#include "bitmap/bitmap.h"
|
#include "bitmap/bitmap.h"
|
||||||
#include "util/util.h"
|
#include "util/util.h"
|
||||||
#include "vmm/vmm.h"
|
|
||||||
#include "pmm/pmm.h"
|
#include "pmm/pmm.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
#include "bootinfo/bootinfo.h"
|
||||||
|
|
||||||
#define USE_DL_PREFIX 1
|
#define USE_DL_PREFIX 1
|
||||||
#define LACKS_SYS_TYPES_H 1
|
#define LACKS_SYS_TYPES_H 1
|
||||||
|
@ -21,13 +21,11 @@ char *hal_strchr(const char *s, int c);
|
|||||||
void hal_init_withmalloc(void);
|
void hal_init_withmalloc(void);
|
||||||
void hal_wait(uint32_t ms);
|
void hal_wait(uint32_t ms);
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
#define HAL_PAGE_SIZE 0x1000
|
||||||
# define HAL_PAGE_SIZE 0x1000
|
#include "x86_64/vmm.h"
|
||||||
# include "x86_64/vmm.h"
|
#include "x86_64/switch.h"
|
||||||
# include "x86_64/proc.h"
|
#include "x86_64/paging.h"
|
||||||
# include "x86_64/switch.h"
|
#include "x86_64/cpu.h"
|
||||||
# include "x86_64/paging.h"
|
#include "x86_64/intr.h"
|
||||||
# include "x86_64/cpu.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // KERNEL_HAL_HAL_H_
|
#endif // KERNEL_HAL_HAL_H_
|
||||||
|
@ -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_
|
|
@ -7,8 +7,10 @@
|
|||||||
#include "paging.h"
|
#include "paging.h"
|
||||||
#include "proc/proc.h"
|
#include "proc/proc.h"
|
||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
|
#include "spinlock/spinlock.h"
|
||||||
|
|
||||||
PgTable *KERNEL_CR3 = NULL;
|
PgTable *KERNEL_CR3 = NULL;
|
||||||
|
SpinLock spinlock;
|
||||||
|
|
||||||
PgTable *hal_vmm_current_cr3(void) {
|
PgTable *hal_vmm_current_cr3(void) {
|
||||||
PgTable *cr3;
|
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 *pml1 = hal_vmm_nexttable((uint64_t *)pml2, pi.pml2);
|
||||||
uint64_t *pte = &pml1[pi.pml1];
|
uint64_t *pte = &pml1[pi.pml1];
|
||||||
|
|
||||||
|
spinlock_acquire(&spinlock);
|
||||||
*pte = (physaddr & ~0xFFF) | (flags & 0x7);
|
*pte = (physaddr & ~0xFFF) | (flags & 0x7);
|
||||||
|
spinlock_release(&spinlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hal_vmm_unmap_page(PgTable *pml4, uint64_t virtaddr, uint64_t physaddr) {
|
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 *pml1 = hal_vmm_nexttable((uint64_t *)pml2, pi.pml2);
|
||||||
uint64_t *pte = &pml1[pi.pml1];
|
uint64_t *pte = &pml1[pi.pml1];
|
||||||
|
|
||||||
|
spinlock_acquire(&spinlock);
|
||||||
*pte &= ~HAL_PG_PRESENT;
|
*pte &= ~HAL_PG_PRESENT;
|
||||||
|
spinlock_release(&spinlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hal_vmm_map_range(PgTable *cr3, void *virtstart, void *physstart, size_t size, uint32_t flags) {
|
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) {
|
void hal_vmm_init(void) {
|
||||||
|
spinlock_init(&spinlock);
|
||||||
KERNEL_CR3 = hal_vmm_current_cr3();
|
KERNEL_CR3 = hal_vmm_current_cr3();
|
||||||
kprintf("KERNEL_CR3 = %p\n", KERNEL_CR3);
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,20 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include "compiler/attr.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;
|
struct Proc;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "hal/hal.h"
|
#include "hal/hal.h"
|
||||||
#include "bootinfo/bootinfo.h"
|
#include "bootinfo/bootinfo.h"
|
||||||
#include "pmm/pmm.h"
|
#include "pmm/pmm.h"
|
||||||
#include "vmm/vmm.h"
|
|
||||||
#include "term/term.h"
|
#include "term/term.h"
|
||||||
#include "dlmalloc/malloc.h"
|
#include "dlmalloc/malloc.h"
|
||||||
#include "vfs/vfs.h"
|
#include "vfs/vfs.h"
|
||||||
@ -61,7 +60,7 @@ void kmain(void) {
|
|||||||
log_bootinfo();
|
log_bootinfo();
|
||||||
hal_init();
|
hal_init();
|
||||||
pmm_init();
|
pmm_init();
|
||||||
vmm_init();
|
hal_vmm_init();
|
||||||
dlmalloc_check();
|
dlmalloc_check();
|
||||||
storedev_init();
|
storedev_init();
|
||||||
baseimg_init();
|
baseimg_init();
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "hal/hal.h"
|
#include "hal/hal.h"
|
||||||
#include "vmm/vmm.h"
|
|
||||||
#include "spinlock/spinlock.h"
|
#include "spinlock/spinlock.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "dlmalloc/malloc.h"
|
#include "dlmalloc/malloc.h"
|
||||||
@ -35,10 +34,8 @@ bool proc_checkelf(uint8_t *elf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ElfAuxval proc_load_elf_segs(Proc *proc, uint8_t *data) {
|
ElfAuxval proc_load_elf_segs(Proc *proc, uint8_t *data) {
|
||||||
#if defined(__x86_64__)
|
PgTable *vas = proc->platformdata.cr3;
|
||||||
PgTable *vas = proc->platformdata.cr3;
|
ElfAuxval aux = {0};
|
||||||
#endif
|
|
||||||
ElfAuxval aux = {0};
|
|
||||||
|
|
||||||
Elf64_Ehdr *elfhdr = (Elf64_Ehdr *)data;
|
Elf64_Ehdr *elfhdr = (Elf64_Ehdr *)data;
|
||||||
aux.entry = elfhdr->e_entry;
|
aux.entry = elfhdr->e_entry;
|
||||||
@ -62,18 +59,14 @@ ElfAuxval proc_load_elf_segs(Proc *proc, uint8_t *data) {
|
|||||||
hal_memset(VIRT(physaddr), 0, phdr->p_memsz);
|
hal_memset(VIRT(physaddr), 0, phdr->p_memsz);
|
||||||
hal_memcpy(VIRT(physaddr) + off, (data + phdr->p_offset), phdr->p_filesz);
|
hal_memcpy(VIRT(physaddr) + off, (data + phdr->p_offset), phdr->p_filesz);
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
uint32_t pgflags = HAL_PG_USER | HAL_PG_RW | HAL_PG_PRESENT;
|
||||||
uint32_t pgflags = HAL_PG_USER | HAL_PG_RW | HAL_PG_PRESENT;
|
hal_vmm_map_range(VIRT(vas), virtaddr, physaddr, blocks * HAL_PAGE_SIZE, pgflags);
|
||||||
hal_vmm_map_range(VIRT(vas), virtaddr, physaddr, blocks * HAL_PAGE_SIZE, pgflags);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
VasRange *range = dlmalloc(sizeof(*range));
|
VasRange *range = dlmalloc(sizeof(*range));
|
||||||
range->virtstart = virtaddr;
|
range->virtstart = virtaddr;
|
||||||
range->physstart = physaddr;
|
range->physstart = physaddr;
|
||||||
range->size = blocks * HAL_PAGE_SIZE;
|
range->size = blocks * HAL_PAGE_SIZE;
|
||||||
#if defined(__x86_64__)
|
range->pgflags = pgflags;
|
||||||
range->pgflags = pgflags;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LL_APPEND(proc->vas, range);
|
LL_APPEND(proc->vas, range);
|
||||||
} break;
|
} break;
|
||||||
@ -98,19 +91,17 @@ Proc *proc_spawnkern(void (*ent)(void), char *name) {
|
|||||||
|
|
||||||
uint8_t *sp = (uint8_t *)pmm_alloc(PROC_STACKBLOCKS) + PROC_STACKSIZE;
|
uint8_t *sp = (uint8_t *)pmm_alloc(PROC_STACKBLOCKS) + PROC_STACKSIZE;
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
proc->platformdata.kstack = sp;
|
||||||
proc->platformdata.kstack = sp;
|
hal_memset(&proc->platformdata.trapframe, 0, sizeof(proc->platformdata.trapframe));
|
||||||
hal_memset(&proc->platformdata.trapframe, 0, sizeof(proc->platformdata.trapframe));
|
|
||||||
|
|
||||||
proc->platformdata.trapframe.ss = 0x10;
|
proc->platformdata.trapframe.ss = 0x10;
|
||||||
proc->platformdata.trapframe.rsp = (uint64_t)VIRT(sp);
|
proc->platformdata.trapframe.rsp = (uint64_t)VIRT(sp);
|
||||||
proc->platformdata.trapframe.rflags = 0x202;
|
proc->platformdata.trapframe.rflags = 0x202;
|
||||||
proc->platformdata.trapframe.cs = 0x08;
|
proc->platformdata.trapframe.cs = 0x08;
|
||||||
proc->platformdata.trapframe.rip = (uint64_t)ent;
|
proc->platformdata.trapframe.rip = (uint64_t)ent;
|
||||||
proc->platformdata.cr3 = hal_vmm_current_cr3();
|
proc->platformdata.cr3 = hal_vmm_current_cr3();
|
||||||
proc->state = PROC_READY;
|
proc->state = PROC_READY;
|
||||||
proc->pid = pids++;
|
proc->pid = pids++;
|
||||||
#endif
|
|
||||||
|
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
@ -136,29 +127,27 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
|||||||
uint8_t *sp = (uint8_t *)pmm_alloc(PROC_STACKBLOCKS) + PROC_STACKSIZE;
|
uint8_t *sp = (uint8_t *)pmm_alloc(PROC_STACKBLOCKS) + PROC_STACKSIZE;
|
||||||
uint8_t *spbase = sp - PROC_STACKSIZE;
|
uint8_t *spbase = sp - PROC_STACKSIZE;
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
proc->platformdata.kstack = sp;
|
||||||
proc->platformdata.kstack = sp;
|
hal_memset(&proc->platformdata.trapframe, 0, sizeof(proc->platformdata.trapframe));
|
||||||
hal_memset(&proc->platformdata.trapframe, 0, sizeof(proc->platformdata.trapframe));
|
|
||||||
|
|
||||||
proc->platformdata.cr3 = hal_vmm_userproc_pml4(proc);
|
proc->platformdata.cr3 = hal_vmm_userproc_pml4(proc);
|
||||||
uint32_t flags = HAL_PG_RW | HAL_PG_USER | HAL_PG_PRESENT;
|
uint32_t flags = HAL_PG_RW | HAL_PG_USER | HAL_PG_PRESENT;
|
||||||
hal_vmm_map_range(VIRT(proc->platformdata.cr3), spbase, spbase, PROC_STACKSIZE, flags);
|
hal_vmm_map_range(VIRT(proc->platformdata.cr3), spbase, spbase, PROC_STACKSIZE, flags);
|
||||||
VasRange *range = dlmalloc(sizeof(*range));
|
VasRange *range = dlmalloc(sizeof(*range));
|
||||||
range->virtstart = spbase;
|
range->virtstart = spbase;
|
||||||
range->physstart = spbase;
|
range->physstart = spbase;
|
||||||
range->size = PROC_STACKSIZE;
|
range->size = PROC_STACKSIZE;
|
||||||
range->pgflags = flags;
|
range->pgflags = flags;
|
||||||
|
|
||||||
LL_APPEND(proc->vas, range);
|
LL_APPEND(proc->vas, range);
|
||||||
|
|
||||||
ElfAuxval aux = proc_load_elf_segs(proc, data);
|
ElfAuxval aux = proc_load_elf_segs(proc, data);
|
||||||
|
|
||||||
proc->platformdata.trapframe.ss = 0x20 | 0x3;
|
proc->platformdata.trapframe.ss = 0x20 | 0x3;
|
||||||
proc->platformdata.trapframe.rsp = (uint64_t)VIRT(sp);
|
proc->platformdata.trapframe.rsp = (uint64_t)VIRT(sp);
|
||||||
proc->platformdata.trapframe.rflags = 0x202;
|
proc->platformdata.trapframe.rflags = 0x202;
|
||||||
proc->platformdata.trapframe.cs = 0x18 | 0x3;
|
proc->platformdata.trapframe.cs = 0x18 | 0x3;
|
||||||
proc->platformdata.trapframe.rip = aux.entry;
|
proc->platformdata.trapframe.rip = aux.entry;
|
||||||
#endif
|
|
||||||
proc->state = PROC_READY;
|
proc->state = PROC_READY;
|
||||||
proc->pid = pids++;
|
proc->pid = pids++;
|
||||||
|
|
||||||
@ -186,9 +175,7 @@ void proc_reaper(void) {
|
|||||||
|
|
||||||
LL_REMOVE(PROCS.procs, zombie);
|
LL_REMOVE(PROCS.procs, zombie);
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
pmm_free((uintptr_t)(zombie->platformdata.kstack - PROC_STACKSIZE), PROC_STACKBLOCKS);
|
||||||
pmm_free((uintptr_t)(zombie->platformdata.kstack - PROC_STACKSIZE), PROC_STACKBLOCKS);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!zombie->kern) {
|
if (!zombie->kern) {
|
||||||
VasRange *vashead = zombie->vas;
|
VasRange *vashead = zombie->vas;
|
||||||
@ -196,9 +183,7 @@ void proc_reaper(void) {
|
|||||||
while (vashead) {
|
while (vashead) {
|
||||||
VasRange *tmp = vashead;
|
VasRange *tmp = vashead;
|
||||||
vashead = vashead->next;
|
vashead = vashead->next;
|
||||||
#if defined(__x86_64__)
|
hal_vmm_unmap_range(zombie->platformdata.cr3, tmp->virtstart, tmp->physstart, tmp->size);
|
||||||
hal_vmm_unmap_range(zombie->platformdata.cr3, tmp->virtstart, tmp->physstart, tmp->size);
|
|
||||||
#endif
|
|
||||||
// first pmm mapping is for the elf itself
|
// first pmm mapping is for the elf itself
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
pmm_free((uintptr_t)tmp->physstart, tmp->size / HAL_PAGE_SIZE);
|
pmm_free((uintptr_t)tmp->physstart, tmp->size / HAL_PAGE_SIZE);
|
||||||
@ -207,9 +192,7 @@ void proc_reaper(void) {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
pmm_free((uintptr_t)zombie->platformdata.cr3, 1);
|
||||||
pmm_free((uintptr_t)zombie->platformdata.cr3, 1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
dlfree(zombie);
|
dlfree(zombie);
|
||||||
} else {
|
} else {
|
||||||
@ -226,20 +209,16 @@ void proc_sched(void *cpustate) {
|
|||||||
proc_reaper();
|
proc_reaper();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
IntrStackFrame *frame = cpustate;
|
||||||
IntrStackFrame *frame = cpustate;
|
|
||||||
|
|
||||||
PROCS.current->platformdata.trapframe = *frame;
|
PROCS.current->platformdata.trapframe = *frame;
|
||||||
PROCS.current->platformdata.fsbase = hal_cpu_rdmsr(HAL_CPU_FSBASE);
|
PROCS.current->platformdata.fsbase = hal_cpu_rdmsr(HAL_CPU_FSBASE);
|
||||||
#endif
|
|
||||||
|
|
||||||
PROCS.current = proc_nextready();
|
PROCS.current = proc_nextready();
|
||||||
PROCS.current->state = PROC_RUNNING;
|
PROCS.current->state = PROC_RUNNING;
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
hal_cpu_wrmsr(HAL_CPU_FSBASE, PROCS.current->platformdata.fsbase);
|
||||||
hal_cpu_wrmsr(HAL_CPU_FSBASE, PROCS.current->platformdata.fsbase);
|
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc_kill(Proc *proc) {
|
void proc_kill(Proc *proc) {
|
||||||
@ -285,7 +264,5 @@ void proc_init(void) {
|
|||||||
proc_register(proc_spawnkern(&proc_status, "status"));
|
proc_register(proc_spawnkern(&proc_status, "status"));
|
||||||
proc_register(proc_spawnuser("base", "/bin/hello"));
|
proc_register(proc_spawnuser("base", "/bin/hello"));
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "hal/hal.h"
|
#include "hal/hal.h"
|
||||||
#include "vmm/vmm.h"
|
|
||||||
#include "spinlock/spinlock.h"
|
#include "spinlock/spinlock.h"
|
||||||
#include "bitmap/bitmap.h"
|
#include "bitmap/bitmap.h"
|
||||||
|
|
||||||
@ -14,6 +13,13 @@
|
|||||||
|
|
||||||
#define PROC_MAX 0x100 // max amount of processes
|
#define PROC_MAX 0x100 // max amount of processes
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t fsbase;
|
||||||
|
IntrStackFrame trapframe;
|
||||||
|
uint8_t *kstack;
|
||||||
|
PgTable *cr3;
|
||||||
|
} ProcPlatformData;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROC_READY,
|
PROC_READY,
|
||||||
PROC_RUNNING,
|
PROC_RUNNING,
|
||||||
|
@ -8,12 +8,7 @@ typedef struct {
|
|||||||
atomic_bool lock;
|
atomic_bool lock;
|
||||||
} SpinLock;
|
} SpinLock;
|
||||||
|
|
||||||
// Spin more efficiently - cpu dependant
|
#define SPINLOCK_HINT() asm volatile("pause")
|
||||||
#if defined(__x86_64__)
|
|
||||||
# define SPINLOCK_HINT() asm volatile("pause")
|
|
||||||
#else
|
|
||||||
# define SPINLOCK_HINT()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void spinlock_init(SpinLock *sl);
|
void spinlock_init(SpinLock *sl);
|
||||||
void spinlock_acquire(SpinLock *sl);
|
void spinlock_acquire(SpinLock *sl);
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "bitmap/bitmap.h"
|
|
||||||
#include "spinlock/spinlock.h"
|
|
||||||
#include "bootinfo/bootinfo.h"
|
|
||||||
#include "vmm.h"
|
|
||||||
#include "kprintf.h"
|
|
||||||
#include "util/util.h"
|
|
||||||
#include "hal/hal.h"
|
|
||||||
#include "pmm/pmm.h"
|
|
||||||
|
|
||||||
VirtMem VIRT_MEM;
|
|
||||||
|
|
||||||
void vmm_map_kern_page(uint64_t virtaddr, uint64_t physaddr, uint32_t flags) {
|
|
||||||
spinlock_acquire(&VIRT_MEM.spinlock);
|
|
||||||
#if defined(__x86_64__)
|
|
||||||
hal_vmm_map_page(KERNEL_CR3, virtaddr, physaddr, flags);
|
|
||||||
#endif
|
|
||||||
spinlock_release(&VIRT_MEM.spinlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vmm_unmap_kern_page(uint64_t virtaddr, uint64_t physaddr) {
|
|
||||||
spinlock_acquire(&VIRT_MEM.spinlock);
|
|
||||||
#if defined(__x86_64__)
|
|
||||||
hal_vmm_unmap_page(KERNEL_CR3, virtaddr, physaddr);
|
|
||||||
#endif
|
|
||||||
spinlock_release(&VIRT_MEM.spinlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vmm_map_kern_range(void *virtstart, void *physstart, size_t size, uint32_t flags) {
|
|
||||||
spinlock_acquire(&VIRT_MEM.spinlock);
|
|
||||||
#if defined(__x86_64__)
|
|
||||||
hal_vmm_map_range(KERNEL_CR3, virtstart, physstart, size, flags);
|
|
||||||
#endif
|
|
||||||
spinlock_release(&VIRT_MEM.spinlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vmm_unmap_kern_range(void *virtstart, void *physstart, size_t size) {
|
|
||||||
spinlock_acquire(&VIRT_MEM.spinlock);
|
|
||||||
#if defined(__x86_64__)
|
|
||||||
hal_vmm_unmap_range(KERNEL_CR3, virtstart, physstart, size);
|
|
||||||
#endif
|
|
||||||
spinlock_release(&VIRT_MEM.spinlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vmm_init(void) {
|
|
||||||
spinlock_init(&VIRT_MEM.spinlock);
|
|
||||||
|
|
||||||
hal_vmm_init();
|
|
||||||
|
|
||||||
LOG("vmm", "init\n");
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
|||||||
#ifndef VMM_VMM_H_
|
|
||||||
#define VMM_VMM_H_
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "spinlock/spinlock.h"
|
|
||||||
#include "bootinfo/bootinfo.h"
|
|
||||||
#include "compiler/attr.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
SpinLock spinlock;
|
|
||||||
} VirtMem;
|
|
||||||
|
|
||||||
typedef struct VasRange {
|
|
||||||
struct VasRange *next;
|
|
||||||
|
|
||||||
uint8_t *virtstart;
|
|
||||||
uint8_t *physstart;
|
|
||||||
size_t size;
|
|
||||||
uint8_t pgflags;
|
|
||||||
} PACKED VasRange;
|
|
||||||
|
|
||||||
extern VirtMem VIRT_MEM;
|
|
||||||
|
|
||||||
void vmm_init(void);
|
|
||||||
|
|
||||||
#define VIRT(X) ((void *)(BOOT_INFO.hhdm_off + (uint64_t)(X)))
|
|
||||||
|
|
||||||
#endif // VMM_VMM_H_
|
|
Reference in New Issue
Block a user