merge branch memory-shit into higher-half

This commit is contained in:
2025-05-10 15:48:10 +03:00
parent 65f543fa92
commit 767e74976f
14 changed files with 419 additions and 178 deletions
+27 -1
View File
@@ -23,6 +23,7 @@ void isr_custom();
void default_handler();
extern void sys_exit_handler();
extern void page_fault_handler();
void isr_install() {
idt_set_descriptor(0, (uint32)isr0, 0x8E);
@@ -39,7 +40,7 @@ void isr_install() {
idt_set_descriptor(11, (uint32)isr11, 0x8E);
idt_set_descriptor(12, (uint32)isr12, 0x8E);
idt_set_descriptor(13, (uint32)isr13, 0x8E);
idt_set_descriptor(14, (uint32)isr14, 0x8E);
idt_set_descriptor(14, (uint32)page_fault_handler, 0x8E);
idt_set_descriptor(15, (uint32)isr15, 0x8E);
idt_set_descriptor(16, (uint32)isr16, 0x8E);
idt_set_descriptor(17, (uint32)isr17, 0x8E);
@@ -75,6 +76,31 @@ void default_handler()
}
#include "../include/paging.h"
void handle_page_fault(uint32_t error_code, uint32_t faulting_address)
{
int present = !(error_code & 0x1); // Bit 0: 0 = not present, 1 = protection violation
int write = error_code & 0x2; // Bit 1: 0 = read, 1 = write
int user = error_code & 0x4; // Bit 2: 0 = supervisor, 1 = user
int reserved = error_code & 0x8; // Bit 3: 0 = no reserved bits, 1 = reserved bits
int instruction = error_code & 0x10; // Bit 4: 0 = data, 1 = instruction fetch
uint32_t pte = get_pte((void*)faulting_address);
printf("Page fault at address 0x%x\n", faulting_address);
printf("Present: %X, Write: %X, User: %X, Reserved: %X, Instruction: %X\n",
present, write, user, reserved, instruction);
printf("PTE: 0x%X (phys: 0x%X, %s, %s)\n", pte, pte & ~0xFFF,
(pte & 0x2) ? "writable" : "read-only",
(pte & 0x4) ? "user" : "supervisor");
printf("ERR: 0x%X\n", error_code);
asm("hlt");
}
__attribute__((interrupt)) void isr_timer(struct interrupt_frame *frame)
{
pit_init(100);