it all broke. im just going to rewrite it all

This commit is contained in:
c0repwn3r 2022-05-12 21:12:29 -04:00
parent 523443ab90
commit c7888c9f25
Signed by: core
GPG Key ID: FDBF740DADDCEECF
11 changed files with 74 additions and 13 deletions

View File

@ -27,7 +27,7 @@ kernel.elf: obj/kernel/entry.o ${CO_FILES} ${AO_FILES}
i386-elf-ld -o $@ -Ttext 0x1000 $^ i386-elf-ld -o $@ -Ttext 0x1000 $^
run: clean os-image.bin run: clean os-image.bin
qemu-system-x86_64 -hdd os-image.bin qemu-system-x86_64 -hdd os-image.bin -d int
debug: clean os-image.bin kernel.elf debug: clean os-image.bin kernel.elf
qemu-system-x86_64 -s -S -hdd os-image.bin & qemu-system-x86_64 -s -S -hdd os-image.bin &

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -14,12 +14,12 @@ gdt_code:
; GDT for data segment ; GDT for data segment
gdt_data: gdt_data:
dw 0xffff dw 0xffff ; segment length
dw 0x0 dw 0x0 ; segment base
db 0x0 db 0x0 ; segment base
db 10010010b db 10010010b ; flags
db 11001111b db 11001111b ; flags + segment length
db 0x0 db 0x0 ; segment base
gdt_end: gdt_end:

View File

@ -1,8 +1,14 @@
#include "int.h" #include "int.h"
#include "../../print.h" #include "../../print.h"
void exception_handler() { int count = 0;
void exception_handler(registers_t r) {
print_str("I"); print_str("I");
count++;
if (count > 4) {
__asm__ __volatile__("cli; hlt");
}
} }
void idt_set_descriptor(u8 vector, void* isr, u8 flags) { void idt_set_descriptor(u8 vector, void* isr, u8 flags) {

View File

@ -21,8 +21,15 @@ typedef struct {
static idtr_t idtr; static idtr_t idtr;
typedef struct {
u32 ds; /* Data segment selector */
u32 edi, esi, ebp, esp, ebx, edx, ecx, eax; /* Pushed by pusha. */
u32 int_no, err_code; /* Interrupt number and error code (if applicable) */
u32 eip, cs, eflags, useresp, ss; /* Pushed by the processor automatically */
} registers_t;
__attribute__((noreturn)) __attribute__((noreturn))
void exception_handler(void); void exception_handler(registers_t r);
void idt_set_descriptor(u8 vector, void* isr, u8 flags); void idt_set_descriptor(u8 vector, void* isr, u8 flags);

View File

@ -1,16 +1,64 @@
%macro isr_err_stub 1 %macro isr_err_stub 1
isr_stub_%+%1: isr_stub_%+%1:
push byte %1 ; Push interrupt no to stack
; 1. Save CPU state
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; save the data segment descriptor
mov ax, 0x10 ; kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; 2. Call C handler
call exception_handler call exception_handler
iret
; 3. Restore state
pop eax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
sti
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
%endmacro %endmacro
; if writing for 64-bit, use iretq instead ; if writing for 64-bit, use iretq instead
%macro isr_no_err_stub 1 %macro isr_no_err_stub 1
isr_stub_%+%1: isr_stub_%+%1:
push byte 0 ; No error occured
push byte %1 ; Push interrupt no to stack
; 1. Save CPU state
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; save the data segment descriptor
mov ax, 0x10 ; kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; 2. Call C handler
call exception_handler call exception_handler
iret
; 3. Restore state
pop eax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
sti
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
%endmacro %endmacro
extern exception_handler extern exception_handler
isr_no_err_stub 0 isr_no_err_stub 0
isr_no_err_stub 1 isr_no_err_stub 1
isr_no_err_stub 2 isr_no_err_stub 2