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 global loader ; entry symbol for ELF
extern kmain extern kmain
extern gdt_init
MAGIC_NUMBER equ 0x1BADB002 ; magic number constant MAGIC_NUMBER equ 0x1BADB002 ; magic number constant
FLAGS equ 0x3 FLAGS equ 0x3
@ -30,6 +31,8 @@ section .text
loader: loader:
mov esp, kernel_stack + KERNEL_STACK_SIZE ; move the top of the stack into esp 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 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 ; Should the system exit, we clear the interrupt flag

View File

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

View File

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

View File

@ -24,9 +24,13 @@ void exception_handler(unsigned int i)
if (i <= 31) if (i <= 31)
__asm__ volatile ("cli; hlt"); // hangs the computer __asm__ volatile ("cli; hlt"); // hangs the computer
if (i == PIC_PIT) { if (i == PIC_KEYB) {
printf("Sending EOI instruction to PIT\n"); #ifdef __TESTING__
PIC_sendEOI(0); 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 cld
push dword %1 push dword %1
call exception_handler call exception_handler
pop eax ; make sure to pop off the dword!!
popad popad
iret iret
%endmacro %endmacro
@ -16,6 +17,7 @@ isr_stub_%+%1:
cld cld
push dword %1 push dword %1
call exception_handler call exception_handler
pop eax
popad popad
iret iret
%endmacro %endmacro

View File

@ -47,7 +47,7 @@
SEG_PRIV(3) | SEG_DATA_RDWR SEG_PRIV(3) | SEG_DATA_RDWR
#define GDT_SIZE 5 #define GDT_SIZE 3
void setGdt(unsigned short limit, uint64_t* base); void setGdt(unsigned short limit, uint64_t* base);

View File

@ -14,7 +14,7 @@ void kmain(void)
terminal_initialize(); terminal_initialize();
serial_initialize(); serial_initialize();
#endif #endif
gdt_init(); //gdt_init();
idt_init(); idt_init();
#ifndef __TESTING__ #ifndef __TESTING__