End of the day cleanup.

* Added symbol files to .gitignore
* Improved text in #PG and #GP handlers
* Added the printing of the multiboot structure address and the magic value
* Added page fault screenshot to readme
dev
Nigel Barink 2022-08-19 01:05:10 +02:00
parent d280aa0584
commit 9436e6e033
5 changed files with 32 additions and 22 deletions

2
.gitignore vendored
View File

@ -5,4 +5,6 @@ isodir/
root/ root/
*.iso *.iso
*.img *.img
*.sym

View File

@ -16,6 +16,11 @@ W.I.P - Working on interrupt handling
![Multiboot integration](screenshots/multiboot.png) \ ![Multiboot integration](screenshots/multiboot.png) \
Multiboot information can be read by the kernel. Multiboot information can be read by the kernel.
![Page faulting](screenshots/PageFault.png) \
Enabled paging and am getting page faults!
________________________ ________________________
### The goal ### The goal

BIN
screenshots/PageFault.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -122,31 +122,29 @@ void irs_handler (registers regs) {
// General Protection Exception #GP // General Protection Exception #GP
printf("#GP\n"); printf("#GP\n");
printf("Accessing memory caused a general protectuion exception.\n");
printf("ERR_CODE: 0x%x", regs.err_code);
if( regs.err_code & 0x1) printf("Fault due to entry at index: %d", (regs.err_code >> 3 & 0xFFF ) );
{
printf("Originated externally!");
}
if(regs.err_code & 0x3 >> 1 == 0 ){ if(regs.err_code & 0x3 >> 1 == 0 ){
printf("Index references GDT"); printf("* Index references GDT");
} }
if(regs.err_code & 0x3 >> 1 == 1 ){ if(regs.err_code & 0x3 >> 1 == 1 ){
printf("Index references IDT"); printf("* Index references IDT");
} }
if(regs.err_code & 0x3 >> 1 == 2 ){ if(regs.err_code & 0x3 >> 1 == 2 ){
printf("Index references LDT"); printf("* Index references LDT");
} }
if(regs.err_code & 0x3 >> 1 == 4 ){ if(regs.err_code & 0x3 >> 1 == 4 ){
printf("Index references IDT"); printf("* Index references IDT");
} }
if( regs.err_code & 0x1)
printf("Index: ", (regs.err_code >> 3 & 0xFFF ) ); {
printf("* Originated externally!");
}
__asm__("cli;" "1: hlt;" "jmp 1b;"); __asm__("cli;" "1: hlt;" "jmp 1b;");
@ -157,7 +155,7 @@ void irs_handler (registers regs) {
printf("#PF\n"); printf("#PF\n");
FaultingAddress = GetCR2(); 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 // Error code of 32 bits are on the stack
// CR2 register contains the 32-bit linear virtual address that generated the exception // 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_SHADOW_STACK_BIT 0x7
#define PF_ERR_SOFTWARE_GUARD_EXTENSION_BIT 0xE #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 ){ if (regs.err_code & PF_ERR_PRESENT_BIT ){
printf("Page protection violation!\n"); printf("* Page protection violation!\n");
} else{ } else{
printf("page not-present!\n"); printf("* Page not-present!\n");
} }
if(regs.err_code & PF_ERR_WRITE_BIT){ if(regs.err_code & PF_ERR_WRITE_BIT){
printf("Write access violation!\n"); printf("* Write access violation!\n");
} else{ } else{
printf("Read access violation!\n"); printf("* Read access violation!\n");
} }
if(regs.err_code & PF_ERR_USER_BIT){ 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){ if(regs.err_code & PF_ERR_INSTRUCTION_FETCH_BIT){
printf("Caused by an instruction fetch. \n"); printf("* Caused by an instruction fetch. \n");
} }
/* /*

View File

@ -48,6 +48,8 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
// Reload CR3 to force a flush // Reload CR3 to force a flush
asm("movl %cr3, %ecx;" "movl %ecx, %cr3" ); 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 * Check Multiboot magic number
* NOTE: Printf call should not be a thing this early on ... * 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 * Show a little banner for cuteness
*/ */
printf("|=== BarinkOS ===|\n"); printf("|=== BarinkOS ===|\n");
const uint32_t KERNEL_BASE_ADDR = 0xC0000000;
/** /**
* Use the address given as an argument as the pointer * Use the address given as an argument as the pointer
* to a Multiboot information structure. * 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 * Construct our own bootInfo structure