my exception handler sucked so i redid it
This commit is contained in:
2
Makefile
2
Makefile
@ -3,7 +3,7 @@
|
||||
|
||||
CC = i686-elf-gcc
|
||||
|
||||
DEBUG_FLAGS = -D__TESTING__ -g
|
||||
DEBUG_FLAGS = -D__TESTING__ -g -Wno-div-by-zero
|
||||
|
||||
CFLAGS = -m32 -ffreestanding -Wall -Wextra -Werror -Wpedantic --sysroot=$(PWD)/sysroot -isystem=/usr/include -Iinclude -MD $(DEBUG_FLAGS)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __TESTING__
|
||||
#include <kernel/_kernel.h>
|
||||
@ -18,17 +19,18 @@ static bool vectors[IDT_MAX_DESCRIPTORS];
|
||||
|
||||
extern struct keyboard_state keyb_state;
|
||||
|
||||
void exception_handler(unsigned int i)
|
||||
void exception_handler(struct cpu_state __attribute__((unused)) cpu, uint32_t interrupt, struct stack_state stack)
|
||||
{
|
||||
if (i <= 31) { // TODO: implement proper handling for each exception, also implement the proper gates & error code checking
|
||||
printf("%1 %2\n", interrupt, stack.eflags);
|
||||
if (interrupt <= 31) { // TODO: implement proper handling for each exception, also implement the proper gates & error code checking
|
||||
#ifdef __TESTING__
|
||||
kerror("EXCEPTION");
|
||||
printf("Exeption: %u\n", i);
|
||||
printf("Exeption: %2\n", interrupt);
|
||||
#endif
|
||||
__asm__ volatile ("cli; hlt"); // hangs the computer
|
||||
//__asm__ volatile ("cli; hlt"); // hangs the computer
|
||||
}
|
||||
|
||||
if (i == PIC_KEYB) {
|
||||
if (interrupt == PIC_KEYB) {
|
||||
unsigned char in = inb(0x60);
|
||||
do_keypress(decode_scancode(in));
|
||||
PIC_sendEOI(1);
|
||||
|
@ -1,27 +1,61 @@
|
||||
extern exception_handler
|
||||
extern exception_handler_err
|
||||
|
||||
%macro isr_err_stub 1
|
||||
isr_stub_%+%1:
|
||||
pushad
|
||||
cld
|
||||
push dword %1
|
||||
call exception_handler
|
||||
pop eax ; make sure to pop off the dword!!
|
||||
popad
|
||||
iret
|
||||
;pushad
|
||||
;cld
|
||||
;push dword %1
|
||||
;call exception_handler_err
|
||||
;pop eax ; pop the error
|
||||
;pop eax ; make sure to pop off the dword!!
|
||||
;popad
|
||||
;iret
|
||||
push dword %1 ; push the interrupt number
|
||||
jmp common_interrupt_handler
|
||||
|
||||
%endmacro
|
||||
|
||||
%macro isr_no_err_stub 1
|
||||
isr_stub_%+%1:
|
||||
pushad
|
||||
cld
|
||||
;pushad
|
||||
;cld
|
||||
;push dword %1
|
||||
;call exception_handler
|
||||
;pop eax
|
||||
;popad
|
||||
;iret
|
||||
push dword 0
|
||||
push dword %1
|
||||
call exception_handler
|
||||
pop eax
|
||||
popad
|
||||
iret
|
||||
jmp common_interrupt_handler
|
||||
%endmacro
|
||||
|
||||
common_interrupt_handler:
|
||||
; lets save the registers
|
||||
push eax
|
||||
push ebx
|
||||
push ecx
|
||||
push edx
|
||||
push esi
|
||||
push edi
|
||||
push ebp
|
||||
|
||||
call exception_handler
|
||||
|
||||
; restore the registers
|
||||
pop ebp
|
||||
pop edi
|
||||
pop esi
|
||||
pop edx
|
||||
pop ecx
|
||||
pop ebx
|
||||
pop eax
|
||||
|
||||
; restore the esp
|
||||
add esp, 8
|
||||
|
||||
iret
|
||||
|
||||
isr_no_err_stub 0
|
||||
isr_no_err_stub 1
|
||||
isr_no_err_stub 2
|
||||
|
@ -28,7 +28,24 @@
|
||||
#define EXCEPT_VIRT 20
|
||||
#define EXCEPT_CTRL_PROT 21
|
||||
|
||||
void exception_handler(unsigned int i);
|
||||
struct cpu_state {
|
||||
uint32_t eax;
|
||||
uint32_t ebx;
|
||||
uint32_t ecx;
|
||||
uint32_t edx;
|
||||
uint32_t esi;
|
||||
uint32_t edi;
|
||||
uint32_t ebp;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct stack_state {
|
||||
uint32_t error_code;
|
||||
uint32_t eip;
|
||||
uint32_t cs;
|
||||
uint32_t eflags;
|
||||
} __attribute__((packed));
|
||||
|
||||
void exception_handler(struct cpu_state cpu, uint32_t interrupt, struct stack_state stack);
|
||||
|
||||
typedef struct {
|
||||
uint16_t isr_low; // The lower 16 bits of the ISR's address
|
||||
|
Reference in New Issue
Block a user