]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Added automatic page mapping on some page faults. Also fixed a critical bug in the...
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Sat, 11 Mar 2023 01:09:12 +0000 (02:09 +0100)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Sat, 11 Mar 2023 01:09:12 +0000 (02:09 +0100)
kernel/src/interrupts.S
kernel/src/interrupts.cpp
kernel/src/kernel.cpp

index 0974203ee06612e00560158240c0d6c01c0ee358..a5f6c8ab3c406981622d3f9ab76f17b015879229 100644 (file)
@@ -44,7 +44,7 @@
        call set_APIC_reg_asm; \
        sti; \
        POP_REGS \
-       addq 4, %rsp;\
+       addq $8, %rsp;\
        iretq
 #define HANDLER_NOERRCODE(n, handler) \
 .globl handler_##n ;\
@@ -73,7 +73,20 @@ HANDLER_ERRCODE  (0x0a, int_invalid_TSS)
 HANDLER_ERRCODE  (0x0b, int_segment_not_present)
 HANDLER_ERRCODE  (0x0c, int_stack_segment_fault)
 HANDLER_ERRCODE  (0x0d, int_general_protection_fault)
-HANDLER_ERRCODE  (0x0e, int_page_fault)
+.globl handler_0x0e
+       handler_0x0e:
+       cli
+       PUSH_REGS
+       movl 72(%rsp), %edi
+       movq %cr2, %rsi
+       call int_page_fault
+       movq $0xB0, %rdi
+       movq $0, %rsi
+       call set_APIC_reg_asm
+       sti
+       POP_REGS
+       addq $8, %rsp
+       iretq
 HANDLER_NOERRCODE(0x0f, int_default)
 HANDLER_NOERRCODE(0x10, int_x87_floating_point_exception)
 HANDLER_ERRCODE  (0x11, int_alignment_check)
index 1d22bdbde2ac87aa1a899e790c191f9a87b20108..667b09cbf40d81d94d9738ee0607037c48aabf23 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <cpuid.h>
 #include "interrupts.hpp"
+#include "paging.hpp"
 
 void os::lidt(idtr idtr) {
        asm volatile("lidt %0" : : "m"(idtr));
@@ -104,9 +105,18 @@ extern "C" void int_general_protection_fault(std::uint32_t err_code) {
        os::print("Err code: {}.\n", err_code);
        while (true) { os::hlt(); }
 }
-extern "C" void int_page_fault(std::uint32_t err_code) {
+extern "C" os::paging::PML4T PML4T;
+extern "C" void int_page_fault(std::uint32_t err_code, std::uint64_t vaddr) {
+       if (
+               (0xFFFF'C000'0000'0000 <= vaddr && vaddr < 0xFFFF'C000'0801'0000) // process/port info
+       ) { // Kernel memory
+               os::print("Alloccing: {}\n", vaddr);
+               os::paging::setup_page(PML4T, (void*)vaddr, true, false);
+               return;
+       }
        os::print("Interrupt: Page Fault.\n");
        os::print("Err code: {}.\n", err_code);
+       os::print("Vaddr: {}.\n", vaddr);
        while (true) { os::hlt(); }
 }
 extern "C" void int_x87_floating_point_exception() {
index 6684df72bae7202f2c0007fc4db5ce7957117516..2e4146e0f73bb1973285d74620a2ef313840daad 100644 (file)
@@ -204,7 +204,6 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_s
        os::print("Enabling syscalls.\n");
        os::enable_syscalls();
 
-       os::paging::setup_page(PML4T, (void*)0xFFFF'C000'0000'0000, true, false);
        os::current_pid = 1;
        os::get_process(os::current_pid) = test_module_process;