Compare commits
No commits in common. "9436e6e0332ee2564b01497b81e272ac379166e2" and "7d6c823d79dcfb819cec7c7ab1eab33255c26dfd" have entirely different histories.
9436e6e033
...
7d6c823d79
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,6 +5,4 @@ isodir/
|
|||||||
root/
|
root/
|
||||||
*.iso
|
*.iso
|
||||||
*.img
|
*.img
|
||||||
*.sym
|
|
||||||
|
|
||||||
|
|
||||||
|
1
Makefile
1
Makefile
@ -37,7 +37,6 @@ run: all
|
|||||||
$(EMULATOR) -cdrom build/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo
|
$(EMULATOR) -cdrom build/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo
|
||||||
|
|
||||||
debug: all
|
debug: all
|
||||||
objcopy --only-keep-debug build/myos.bin kernel.sym
|
|
||||||
$(EMULATOR) -cdrom build/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo -s -d int
|
$(EMULATOR) -cdrom build/barinkOS.iso -serial stdio -vga std -display gtk -m 2G -cpu core2duo -s -d int
|
||||||
|
|
||||||
build_kernel: $(OBJ_LINK_LIST)
|
build_kernel: $(OBJ_LINK_LIST)
|
||||||
|
@ -16,11 +16,6 @@ W.I.P - Working on interrupt handling
|
|||||||
|
|
||||||
 \
|
 \
|
||||||
Multiboot information can be read by the kernel.
|
Multiboot information can be read by the kernel.
|
||||||
|
|
||||||
 \
|
|
||||||
Enabled paging and am getting page faults!
|
|
||||||
|
|
||||||
|
|
||||||
________________________
|
________________________
|
||||||
|
|
||||||
### The goal
|
### The goal
|
||||||
|
BIN
screenshots/PageFault.png
(Stored with Git LFS)
BIN
screenshots/PageFault.png
(Stored with Git LFS)
Binary file not shown.
@ -1,11 +1,10 @@
|
|||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
#include "../../Drivers/PIT/pit.h"
|
#include "../../Drivers/PIT/pit.h"
|
||||||
#include "../../Drivers/PS-2/keyboard.h"
|
#include "../../Drivers/PS-2/keyboard.h"
|
||||||
#include "../../cpu.h"
|
|
||||||
IDT_entry idt_table[256];
|
IDT_entry idt_table[256];
|
||||||
IDT_ptr idt_ptr;
|
IDT_ptr idt_ptr;
|
||||||
|
|
||||||
|
|
||||||
void set_id_entry (uint8_t num , uint32_t base, uint16_t sel, uint8_t flags){
|
void set_id_entry (uint8_t num , uint32_t base, uint16_t sel, uint8_t flags){
|
||||||
idt_table[num].offset_1 = base & 0xFFFF;
|
idt_table[num].offset_1 = base & 0xFFFF;
|
||||||
idt_table[num].selector = sel;
|
idt_table[num].selector = sel;
|
||||||
@ -16,7 +15,7 @@ void set_id_entry (uint8_t num , uint32_t base, uint16_t sel, uint8_t flags){
|
|||||||
};
|
};
|
||||||
|
|
||||||
void irs_handler (registers regs) {
|
void irs_handler (registers regs) {
|
||||||
uint32_t FaultingAddress;
|
|
||||||
//printf("(IRS) Interrupt number: %d \r", regs.int_no);
|
//printf("(IRS) Interrupt number: %d \r", regs.int_no);
|
||||||
switch (regs.int_no)
|
switch (regs.int_no)
|
||||||
{
|
{
|
||||||
@ -121,81 +120,28 @@ void irs_handler (registers regs) {
|
|||||||
case 13:
|
case 13:
|
||||||
// General Protection Exception #GP
|
// General Protection Exception #GP
|
||||||
printf("#GP\n");
|
printf("#GP\n");
|
||||||
|
printf("EIP: 0x%x\n", regs.eip);
|
||||||
printf("Accessing memory caused a general protectuion exception.\n");
|
printf("EAX: 0x%x\n", regs.eax);
|
||||||
|
printf("EBP: 0x%x\n", regs.ebp);
|
||||||
printf("Fault due to entry at index: %d", (regs.err_code >> 3 & 0xFFF ) );
|
|
||||||
|
|
||||||
if(regs.err_code & 0x3 >> 1 == 0 ){
|
|
||||||
printf("* Index references GDT");
|
|
||||||
}
|
|
||||||
if(regs.err_code & 0x3 >> 1 == 1 ){
|
|
||||||
printf("* Index references IDT");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(regs.err_code & 0x3 >> 1 == 2 ){
|
|
||||||
printf("* Index references LDT");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(regs.err_code & 0x3 >> 1 == 4 ){
|
|
||||||
printf("* Index references IDT");
|
|
||||||
}
|
|
||||||
|
|
||||||
if( regs.err_code & 0x1)
|
|
||||||
{
|
|
||||||
printf("* Originated externally!");
|
|
||||||
}
|
|
||||||
|
|
||||||
__asm__("cli;" "1: hlt;" "jmp 1b;");
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 14:
|
case 14:
|
||||||
// Page Fault Exception #PF
|
// Page Fault Exception #PF
|
||||||
printf("#PF\n");
|
printf("#PF\n");
|
||||||
|
|
||||||
FaultingAddress = GetCR2();
|
printf("EIP: 0x%x\n", regs.eip); // Points to faulting instruction ???
|
||||||
printf("Accessing the linear address 0x%x resulted in a page fault!\n\n", FaultingAddress);
|
printf("EAX: 0x%x\n", regs.eax);
|
||||||
|
printf("EBP: 0x%x\n", regs.ebp); // Base pointer pointing to the bottom of the stack
|
||||||
|
|
||||||
|
|
||||||
// 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 address that generated the exception
|
||||||
// See Intel Software Developers manual Volume 3A Part 1 page 236 for more info
|
// See Intel Software Developers manual Volume 3A Part 1 page 236 for more info
|
||||||
#define PF_ERR_PRESENT_BIT 0x1
|
|
||||||
#define PF_ERR_WRITE_BIT 0x2
|
|
||||||
#define PF_ERR_USER_BIT 0x3
|
|
||||||
#define PF_ERR_RESERVERD_WRITE_BIT 0x4
|
|
||||||
#define PF_ERR_INSTRUCTION_FETCH_BIT 0x5
|
|
||||||
#define PF_ERR_PROTECTION_KEY_BIT 0x6
|
|
||||||
#define PF_ERR_SHADOW_STACK_BIT 0x7
|
|
||||||
#define PF_ERR_SOFTWARE_GUARD_EXTENSION_BIT 0xE
|
|
||||||
|
|
||||||
printf("REASON: \n\n");
|
|
||||||
|
|
||||||
|
|
||||||
if (regs.err_code & PF_ERR_PRESENT_BIT ){
|
|
||||||
printf("* Page protection violation!\n");
|
|
||||||
} else{
|
|
||||||
printf("* Page not-present!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(regs.err_code & PF_ERR_WRITE_BIT){
|
|
||||||
printf("* Write access violation!\n");
|
|
||||||
} else{
|
|
||||||
printf("* Read access violation!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(regs.err_code & PF_ERR_USER_BIT){
|
|
||||||
printf("* Violation from user-space (CPL=3)\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(regs.err_code & PF_ERR_INSTRUCTION_FETCH_BIT){
|
|
||||||
printf("* Caused by an instruction fetch. \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check the error code to figure out what happened here
|
Check the error code to figure out what happened here
|
||||||
*/
|
*/
|
||||||
__asm__("cli;" "1: hlt;" "jmp 1b;");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ void PhysicalMemory::setup( MemoryInfo* memory) {
|
|||||||
|
|
||||||
used_blocks = 0;
|
used_blocks = 0;
|
||||||
|
|
||||||
memoryBitMap = (uint32_t*) 0xCCA00000;
|
memoryBitMap = (uint32_t*) 0x00a00000;
|
||||||
|
|
||||||
|
|
||||||
printf("Maximum Number of blocks: 0x%x, Number of bytes for memMap: 0x%x\n", max_blocks , (max_blocks/8));
|
printf("Maximum Number of blocks: 0x%x, Number of bytes for memMap: 0x%x\n", max_blocks , (max_blocks/8));
|
||||||
|
@ -60,15 +60,3 @@ extern "C" uint32_t GetCR4();
|
|||||||
|
|
||||||
#define GET_PSE_BIT(CONTROL_REGISTER_4) (CONTROL_REGISTER_4&0x4)
|
#define GET_PSE_BIT(CONTROL_REGISTER_4) (CONTROL_REGISTER_4&0x4)
|
||||||
#define GET_PAE_BIT(CONTROL_REGISTER_4) (CONTROL_REGISTER_4&0x5)
|
#define GET_PAE_BIT(CONTROL_REGISTER_4) (CONTROL_REGISTER_4&0x5)
|
||||||
|
|
||||||
/*
|
|
||||||
* CONTROL_REGISTER_2 FUNCTIONS
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern "C" uint32_t GetCR2();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* CONTROL_REGISTER_3 FUNCTIONS
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern "C" uint32_t GetCR3();
|
|
@ -37,27 +37,3 @@ GetEFLAGS:
|
|||||||
mov %ebp, %esp
|
mov %ebp, %esp
|
||||||
pop %ebp
|
pop %ebp
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.globl GetCR2
|
|
||||||
GetCR2:
|
|
||||||
push %ebp
|
|
||||||
mov %esp, %ebp
|
|
||||||
|
|
||||||
xor %eax, %eax
|
|
||||||
mov %cr2, %eax
|
|
||||||
|
|
||||||
mov %ebp, %esp
|
|
||||||
pop %ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
.globl GetCR3
|
|
||||||
GetCR3:
|
|
||||||
push %ebp
|
|
||||||
mov %esp, %ebp
|
|
||||||
|
|
||||||
xor %eax, %eax
|
|
||||||
mov %cr3, %eax
|
|
||||||
|
|
||||||
mov %ebp, %esp
|
|
||||||
pop %ebp
|
|
||||||
ret
|
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
|
|
||||||
extern "C" void kernel_main (BootInfo* bootinfo) {
|
extern "C" void kernel_main (BootInfo* bootinfo) {
|
||||||
pit_initialise();
|
init_serial();
|
||||||
|
//pit_initialise();
|
||||||
|
|
||||||
startSuperVisorTerminal(bootinfo);
|
startSuperVisorTerminal(bootinfo);
|
||||||
}
|
}
|
||||||
@ -16,40 +17,9 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
|
|||||||
initGDT();
|
initGDT();
|
||||||
kterm_init();
|
kterm_init();
|
||||||
init_serial();
|
init_serial();
|
||||||
print_serial("Hello Higher half kernel!\n");
|
print_serial("Hello Higher half kernel!");
|
||||||
|
printf("DDDDDDDDDDDDDDDD");
|
||||||
init_idt();
|
return;
|
||||||
// Enable interrupts
|
|
||||||
asm volatile("STI");
|
|
||||||
|
|
||||||
// map the multiboot structure into virtual memory
|
|
||||||
// so we can gather the necessary data from it.
|
|
||||||
/* const uint32_t KERNEL_BASE_ADDR = 0xC0000000;
|
|
||||||
|
|
||||||
uint32_t pageDirectoryIndex = (addr + KERNEL_BASE_ADDR) >> 22;
|
|
||||||
printf("pageDirectoryIndex: %d\n", pageDirectoryIndex);
|
|
||||||
|
|
||||||
uint32_t pageTableIndex = (addr + KERNEL_BASE_ADDR >> 12) & 0x1FFF;
|
|
||||||
printf("PagTableIndex: %d\n", pageTableIndex);
|
|
||||||
|
|
||||||
printf("boot_page_directory addr: 0x%x\n", &boot_page_directory);
|
|
||||||
printf("boot_page_table addr: 0x%x\n", &boot_page_table);
|
|
||||||
|
|
||||||
uint32_t* pageDirectoryEntry = (uint32_t*) ((uint32_t) &boot_page_directory) + (pageDirectoryIndex * 4);
|
|
||||||
printf("page_directory_entry addr: 0x%x\n", pageDirectoryEntry);
|
|
||||||
|
|
||||||
*pageDirectoryEntry = ( addr & 0xFFFFF000 ) | 0x003;
|
|
||||||
|
|
||||||
uint32_t* page_table_entry = (uint32_t*) ((uint32_t) &boot_page_table) + ( pageTableIndex * 4);
|
|
||||||
printf("page_table_entry addr: 0x%x\n" , page_table_entry);
|
|
||||||
|
|
||||||
*page_table_entry = addr | 0x003;
|
|
||||||
|
|
||||||
// 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
|
* 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 ...
|
||||||
@ -63,12 +33,13 @@ 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;
|
printf("Kernel Begin AT(0x%x)", kernel_begin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 + KERNEL_BASE_ADDR);
|
multiboot_info_t* mbt = (multiboot_info_t*) addr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct our own bootInfo structure
|
* Construct our own bootInfo structure
|
||||||
@ -140,11 +111,16 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
|
|||||||
//InitializePaging();
|
//InitializePaging();
|
||||||
//IdentityMap();
|
//IdentityMap();
|
||||||
//Enable();
|
//Enable();
|
||||||
} else{
|
|
||||||
printf("memory flag not set!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckMBT( (multiboot_info_t *) addr);
|
//initGDT();
|
||||||
|
//init_idt();
|
||||||
|
// Enable interrupts
|
||||||
|
//asm volatile("STI");
|
||||||
|
|
||||||
|
|
||||||
|
//CheckMBT( (multiboot_info_t *) addr);
|
||||||
|
|
||||||
|
|
||||||
kernel_main(&bootinfo);
|
kernel_main(&bootinfo);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ extern "C"
|
|||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "SuperVisorTerminal/superVisorTerminal.h"
|
#include "SuperVisorTerminal/superVisorTerminal.h"
|
||||||
|
|
||||||
#define CHECK_FLAG(flag, bit) ( flag & (1 << bit ))
|
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
||||||
#define PANIC(message) {return;}
|
#define PANIC(message) {return;}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user