Exception handler can access their ID

This commit is contained in:
Mathieu Maret 2020-04-23 23:59:57 +02:00
parent de14e795d6
commit 59a8d3b582
3 changed files with 22 additions and 10 deletions

View File

@ -1,16 +1,22 @@
#include "exception.h"
#include "klibc.h"
#include "vga.h"
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
// Need GCC > 6
__attribute__((interrupt)) void print_handler(struct interrupt_frame *frame, ulong error_code)
{
printStringDetails("EXCEPTION", RED, BLACK, 0, VGA_HEIGHT - 1);
printIntDetails(error_code, RED, BLACK, 11, VGA_HEIGHT - 1);
(void)frame;
(void)error_code;
}
#define DEFINE_INTERRUPT(int_nb) \
__attribute__((interrupt)) void print_handler_##int_nb(struct interrupt_frame *frame, \
ulong error_code) \
{ \
int intNbInt = int_nb; \
printStringDetails("EXCEPTION ", RED, BLACK, 0, VGA_HEIGHT - 1); \
printIntDetails(intNbInt, RED, BLACK, 11, VGA_HEIGHT - 1); \
printIntDetails(error_code, RED, BLACK, 14, VGA_HEIGHT - 1); \
printf("Exception %d (Err %d) at 0x%x\n", int_nb, error_code, frame->eip); \
}
DEFINE_INTERRUPT(EXCEPTION_DOUBLE_FAULT)
// c.f. https://wiki.osdev.org/Paging#Handling
// error_code bit0: Present ?
// bit1: Trying to write ?

View File

@ -12,8 +12,14 @@ struct interrupt_frame {
};
// Exception
void print_handler(struct interrupt_frame *frame, ulong error_code);
// Exception
#define DECLARE_INTERRUPT(int_nb) \
void print_handler_##int_nb(struct interrupt_frame *frame, ulong error_code);
#define ACCESS_INTERRUPT(int_nb) print_handler_##int_nb
void pagefault_handler(struct interrupt_frame *frame, ulong error_code);
DECLARE_INTERRUPT(EXCEPTION_DOUBLE_FAULT)
// IRQ
void pit_handler(struct interrupt_frame *frame);

View File

@ -110,7 +110,7 @@ void kmain(unsigned long magic, unsigned long addr)
irqSetRoutine(IRQ_KEYBOARD, keyboard_handler);
printf("Enabling HW interrupts\n");
exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, print_handler);
exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, ACCESS_INTERRUPT(EXCEPTION_DOUBLE_FAULT));
exceptionSetRoutine(EXCEPTION_PAGE_FAULT, pagefault_handler);
// Enabling the HW interrupts
asm volatile("sti\n");