This commit is contained in:
2025-09-27 15:16:26 +02:00
parent 5af7c5276a
commit 3b1bb9d531
63 changed files with 1087 additions and 407 deletions

View File

@ -7,7 +7,7 @@
#define GDT_PRESENT 0x80
#define GDT_TSS 0x89
#define KSTACK 8192
#define KSTACK (1024*2*4096)
ALIGNED(16) static uint8_t kernelstack[KSTACK];
typedef struct {

View File

@ -178,8 +178,6 @@ void hal_syscalldispatch(IntrStackFrame *frame) {
frame->regs.rax = E_BADSYSCALL;
return;
}
uint64_t cr3;
asm volatile("mov %%cr3, %0" : "=r"(cr3));
int32_t ret = fn(frame, frame->regs.rdi, frame->regs.rsi, frame->regs.rdx,
frame->regs.r10, frame->regs.r8, frame->regs.r9);
@ -215,7 +213,7 @@ void intr_handleintr(IntrStackFrame *frame) {
break;
case INTR_IRQBASE+1:
int32_t c = ps2kb_intr();
if (c >= 0) {
if (c >= 0 && PS2KB_BUF.init) {
uint8_t b = c;
spinlock_acquire(&PS2KB_BUF.spinlock);
rbuf_push(&PS2KB_BUF.rbuf, b);

View File

@ -62,13 +62,13 @@
.endm
.macro _vecintr_bodygen
cli
_push_regs
cld
mov %rsp, %rdi
movq %rsp, %rdi
call intr_handleintr
_pop_regs
add $0x10, %rsp
iretq
.endm

View File

@ -2,15 +2,11 @@
.global hal_switchproc
hal_switchproc:
mov %cr3, %rcx
cmp %rsi, %rcx
je .done
mov %rsi, %cr3
.done:
testq %rsi, %rsi
je 1f
movq %rsi, %cr3
1:
mov %rdi, %rsp
_pop_regs
add $0x10, %rsp
iretq

View File

@ -29,12 +29,16 @@ PgIndex hal_vmm_pageindex(uint64_t vaddr) {
return ret;
}
uint64_t *hal_vmm_nexttable(uint64_t *table, uint64_t ent) {
uint64_t *hal_vmm_nexttable(uint64_t *table, uint64_t ent, bool alloc) {
uint64_t entry = table[ent];
uint64_t phys;
if (entry & HAL_PG_PRESENT) {
phys = entry & ~0xFFFULL;
} else {
if (!alloc) {
return NULL;
}
uint8_t *newphys = pmm_alloc(1);
phys = (uint64_t)newphys;
hal_memset(VIRT(phys), 0, HAL_PAGE_SIZE);
@ -47,9 +51,9 @@ void hal_vmm_map_page(uint64_t cr3phys, uint64_t virtaddr, uint64_t physaddr, ui
uint64_t *pml4 = (uint64_t *)VIRT(cr3phys);
PgIndex pi = hal_vmm_pageindex(virtaddr);
uint64_t *pml3 = hal_vmm_nexttable(pml4, pi.pml4);
uint64_t *pml2 = hal_vmm_nexttable(pml3, pi.pml3);
uint64_t *pml1 = hal_vmm_nexttable(pml2, pi.pml2);
uint64_t *pml3 = hal_vmm_nexttable(pml4, pi.pml4, true);
uint64_t *pml2 = hal_vmm_nexttable(pml3, pi.pml3, true);
uint64_t *pml1 = hal_vmm_nexttable(pml2, pi.pml2, true);
uint64_t *pte = &pml1[pi.pml1];
*pte = (physaddr & ~0xFFFULL) | ((uint64_t)flags & 0x7ULL);
@ -59,9 +63,9 @@ void hal_vmm_unmap_page(uint64_t cr3phys, uint64_t virtaddr, uint64_t physaddr)
uint64_t *pml4 = (uint64_t *)VIRT(cr3phys);
PgIndex pi = hal_vmm_pageindex(virtaddr);
uint64_t *pml3 = hal_vmm_nexttable(pml4, pi.pml4);
uint64_t *pml2 = hal_vmm_nexttable(pml3, pi.pml3);
uint64_t *pml1 = hal_vmm_nexttable(pml2, pi.pml2);
uint64_t *pml3 = hal_vmm_nexttable(pml4, pi.pml4, false);
uint64_t *pml2 = hal_vmm_nexttable(pml3, pi.pml3, false);
uint64_t *pml1 = hal_vmm_nexttable(pml2, pi.pml2, false);
uint64_t *pte = &pml1[pi.pml1];
*pte &= ~HAL_PG_PRESENT;