holy crap im an idiot, i was getting constatnt gpf because i forgot to pop the stack

This commit is contained in:
2025-06-01 20:57:12 -04:00
parent ecc91fdc7d
commit 4c938a0855
7 changed files with 19 additions and 14 deletions

View File

@ -4,6 +4,7 @@
global loader ; entry symbol for ELF
extern kmain
extern gdt_init
MAGIC_NUMBER equ 0x1BADB002 ; magic number constant
FLAGS equ 0x3
@ -30,6 +31,8 @@ section .text
loader:
mov esp, kernel_stack + KERNEL_STACK_SIZE ; move the top of the stack into esp
call gdt_init
call kmain ; pass execution over to our kmain function, where all of the real stuff is done
; Should the system exit, we clear the interrupt flag

View File

@ -8,12 +8,8 @@ setGdt:
mov eax, [esp + 8]
mov [gdtr + 2], eax
lgdt [gdtr]
ret
global reloadSegments
reloadSegments:
jmp 0x08:.reload_CS ; 0x08 is a stand in for the code segment
.reload_CS:
jmp 0x08:reload_CS ; 0x08 is a stand in for the code segment
reload_CS:
mov ax, 0x10 ; stand in for the data segment
mov ds, ax
mov es, ax

View File

@ -63,11 +63,11 @@ void gdt_init(void)
gdt[0] = create_descriptor(0, 0, 0); // null
gdt[1] = create_descriptor(0, 0x000FFFFF, (GDT_CODE_PL0)); // kernel code
gdt[2] = create_descriptor(0, 0x000FFFFF, (GDT_DATA_PL0)); // kernel data
gdt[3] = create_descriptor(0, 0x000FFFFF, (GDT_CODE_PL3)); // user code
gdt[4] = create_descriptor(0, 0x000FFFFF, (GDT_DATA_PL3)); // user data
//gdt[3] = create_descriptor(0, 0x000FFFFF, (GDT_CODE_PL3)); // user code
//gdt[4] = create_descriptor(0, 0x000FFFFF, (GDT_DATA_PL3)); // user data
setGdt((sizeof(uint64_t) * GDT_SIZE) - 1, &(gdt[0])); // limit, base
reloadSegments();
//reloadSegments();
#ifdef __TESTING__
kinfo("Initialized the GDT");
dump_gdt();

View File

@ -24,9 +24,13 @@ void exception_handler(unsigned int i)
if (i <= 31)
__asm__ volatile ("cli; hlt"); // hangs the computer
if (i == PIC_PIT) {
printf("Sending EOI instruction to PIT\n");
PIC_sendEOI(0);
if (i == PIC_KEYB) {
#ifdef __TESTING__
kinfo("Sending EOI instruction to KEYB");
#endif
printf("Scancode: %x\n", inb(0x60)); // read from kb
PIC_sendEOI(1);
}
}

View File

@ -6,6 +6,7 @@ isr_stub_%+%1:
cld
push dword %1
call exception_handler
pop eax ; make sure to pop off the dword!!
popad
iret
%endmacro
@ -16,6 +17,7 @@ isr_stub_%+%1:
cld
push dword %1
call exception_handler
pop eax
popad
iret
%endmacro