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
This commit is contained in:
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/
*.iso
*.img
*.sym

View File

@ -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

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
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");
}
/*

View File

@ -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