GPF loop, yay
This commit is contained in:
parent
43ebf1d873
commit
904df77287
BIN
bin/boot.bin
BIN
bin/boot.bin
Binary file not shown.
BIN
bin/kernel.bin
BIN
bin/kernel.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
os-image.bin
BIN
os-image.bin
Binary file not shown.
|
@ -50,5 +50,5 @@ void main() {
|
||||||
idt_init();
|
idt_init();
|
||||||
kernel_msg_ok("Interrupts initialized");
|
kernel_msg_ok("Interrupts initialized");
|
||||||
|
|
||||||
__asm__ __volatile__("int $2");
|
//__asm__ __volatile__("int $2");
|
||||||
}
|
}
|
|
@ -1,8 +1,52 @@
|
||||||
#include "int.h"
|
#include "int.h"
|
||||||
#include "../../print.h"
|
#include "../../print.h"
|
||||||
|
|
||||||
void exception_handler() {
|
char *exception_messages[] = {
|
||||||
print_str("I");
|
"Division By Zero",
|
||||||
|
"Debug",
|
||||||
|
"Non Maskable Interrupt",
|
||||||
|
"Breakpoint",
|
||||||
|
"Into Detected Overflow",
|
||||||
|
"Out of Bounds",
|
||||||
|
"Invalid Opcode",
|
||||||
|
"No Coprocessor",
|
||||||
|
|
||||||
|
"Double Fault",
|
||||||
|
"Coprocessor Segment Overrun",
|
||||||
|
"Bad TSS",
|
||||||
|
"Segment Not Present",
|
||||||
|
"Stack Fault",
|
||||||
|
"General Protection Fault",
|
||||||
|
"Page Fault",
|
||||||
|
"Unknown Interrupt",
|
||||||
|
|
||||||
|
"Coprocessor Fault",
|
||||||
|
"Alignment Check",
|
||||||
|
"Machine Check",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved",
|
||||||
|
"Reserved"
|
||||||
|
};
|
||||||
|
|
||||||
|
void exception_handler(registers_t r) {
|
||||||
|
print_str("int: ");
|
||||||
|
char s[3];
|
||||||
|
int_to_ascii(r.int_no, s);
|
||||||
|
print_str(s);
|
||||||
|
print_str("\n");
|
||||||
|
print_str(exception_messages[r.int_no]);
|
||||||
|
print_str("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void idt_set_descriptor(u8 vector, void* isr, u8 flags) {
|
void idt_set_descriptor(u8 vector, void* isr, u8 flags) {
|
||||||
|
|
|
@ -21,8 +21,17 @@ 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 present)
|
||||||
|
u32 eip, cs, eflags, useresp, ss; // Pushed automatically by the CPU
|
||||||
|
} 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);
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,58 @@
|
||||||
%macro isr_err_stub 1
|
%macro isr_err_stub 1
|
||||||
isr_stub_%+%1:
|
isr_stub_%+%1:
|
||||||
call exception_handler
|
push byte %1
|
||||||
iret
|
|
||||||
|
; 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
|
||||||
|
|
||||||
|
call exception_handler ; Call C handler
|
||||||
|
|
||||||
|
; Restore CPU 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:
|
||||||
call exception_handler
|
push byte 0
|
||||||
iret
|
push byte %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
|
||||||
|
|
||||||
|
call exception_handler ; Call C handler
|
||||||
|
|
||||||
|
; Restore CPU 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
|
||||||
|
|
Loading…
Reference in New Issue