diff --git a/.gitignore b/.gitignore index 3ac905f..82ca499 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ isodir/ root/ *.iso *.img +*.sym + diff --git a/README.md b/README.md index 2e5fbb6..155afd0 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ W.I.P - Working on interrupt handling ![Multiboot integration](screenshots/multiboot.png) \ Multiboot information can be read by the kernel. + +![Page faulting](screenshots/PageFault.png) \ +Enabled paging and am getting page faults! + + ________________________ ### The goal diff --git a/screenshots/PageFault.png b/screenshots/PageFault.png new file mode 100644 index 0000000..adc5332 --- /dev/null +++ b/screenshots/PageFault.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edf3a8ff640f0a3fbf58756d10526ee3bc03068d0cea4d81d64a897d52e29c85 +size 10406 diff --git a/src/kernel/Interrupts/idt/idt.cpp b/src/kernel/Interrupts/idt/idt.cpp index 4c5f934..8b4fd83 100644 --- a/src/kernel/Interrupts/idt/idt.cpp +++ b/src/kernel/Interrupts/idt/idt.cpp @@ -122,31 +122,29 @@ void irs_handler (registers regs) { // General Protection Exception #GP printf("#GP\n"); - - printf("ERR_CODE: 0x%x", regs.err_code); + printf("Accessing memory caused a general protectuion exception.\n"); - if( regs.err_code & 0x1) - { - printf("Originated externally!"); - } + printf("Fault due to entry at index: %d", (regs.err_code >> 3 & 0xFFF ) ); if(regs.err_code & 0x3 >> 1 == 0 ){ - printf("Index references GDT"); + printf("* Index references GDT"); } if(regs.err_code & 0x3 >> 1 == 1 ){ - printf("Index references IDT"); + printf("* Index references IDT"); } if(regs.err_code & 0x3 >> 1 == 2 ){ - printf("Index references LDT"); + printf("* Index references LDT"); } if(regs.err_code & 0x3 >> 1 == 4 ){ - printf("Index references IDT"); + printf("* Index references IDT"); } - - printf("Index: ", (regs.err_code >> 3 & 0xFFF ) ); + if( regs.err_code & 0x1) + { + printf("* Originated externally!"); + } __asm__("cli;" "1: hlt;" "jmp 1b;"); @@ -157,7 +155,7 @@ void irs_handler (registers regs) { printf("#PF\n"); FaultingAddress = GetCR2(); - printf("Faulting instruction adddress: 0x%x\n", FaultingAddress); + printf("Accessing the linear address 0x%x resulted in a page fault!\n\n", FaultingAddress); // Error code of 32 bits are on the stack // CR2 register contains the 32-bit linear virtual address that generated the exception @@ -171,27 +169,27 @@ void irs_handler (registers regs) { #define PF_ERR_SHADOW_STACK_BIT 0x7 #define PF_ERR_SOFTWARE_GUARD_EXTENSION_BIT 0xE - printf("Determining cause of fault...\n"); + printf("REASON: \n\n"); if (regs.err_code & PF_ERR_PRESENT_BIT ){ - printf("Page protection violation!\n"); + printf("* Page protection violation!\n"); } else{ - printf("page not-present!\n"); + printf("* Page not-present!\n"); } if(regs.err_code & PF_ERR_WRITE_BIT){ - printf("Write access violation!\n"); + printf("* Write access violation!\n"); } else{ - printf("Read access violation!\n"); + printf("* Read access violation!\n"); } if(regs.err_code & PF_ERR_USER_BIT){ - printf("Violation from user-space (CPL=3)\n"); + printf("* Violation from user-space (CPL=3)\n"); } if(regs.err_code & PF_ERR_INSTRUCTION_FETCH_BIT){ - printf("Caused by an instruction fetch. \n"); + printf("* Caused by an instruction fetch. \n"); } /* diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp index 8409b44..22aa47f 100644 --- a/src/kernel/kernel.cpp +++ b/src/kernel/kernel.cpp @@ -48,6 +48,8 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){ // Reload CR3 to force a flush asm("movl %cr3, %ecx;" "movl %ecx, %cr3" ); */ + + printf("DEBUG:\n Magic: 0x%x\n MBT_addr: 0x%x\n", magic, addr); /** * Check Multiboot magic number * NOTE: Printf call should not be a thing this early on ... @@ -61,12 +63,12 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){ * Show a little banner for cuteness */ printf("|=== BarinkOS ===|\n"); - + const uint32_t KERNEL_BASE_ADDR = 0xC0000000; /** * Use the address given as an argument as the pointer * to a Multiboot information structure. */ - multiboot_info_t* mbt = (multiboot_info_t*) addr; + multiboot_info_t* mbt = (multiboot_info_t*) (addr + KERNEL_BASE_ADDR); /** * Construct our own bootInfo structure