From c0019e9d0bd2059351dc7d0274ee0479a71192fc Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Tue, 28 Sep 2021 09:08:38 -0500 Subject: arch: i386: fix IDT exception handler Fix the i386's general exception handler to actually work. Fix provided by Jon Sanderson (jjs295356@gmail.com). Signed-off-by: Danny Holman --- arch/i386/include/kernel/idt.h | 35 +++++++++++++++++++++++++++++++++++ arch/i386/include/kernel/isr.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 arch/i386/include/kernel/idt.h create mode 100644 arch/i386/include/kernel/isr.h (limited to 'arch/i386/include/kernel') diff --git a/arch/i386/include/kernel/idt.h b/arch/i386/include/kernel/idt.h new file mode 100644 index 0000000..7ccad30 --- /dev/null +++ b/arch/i386/include/kernel/idt.h @@ -0,0 +1,35 @@ +#ifndef I386_IDT_H +#define I386_IDT_H + +#include + +// IDT Flags +#define SEGMENT_PRESENT 0x8 +#define SEGMENT_RING0 0x0 +#define SEGMENT_STORAGE 0x0 +#define SEGMENT_GATE 0xE +#define SEGMENT_DPL 0x8 + +#define SEGMENT_FLAG SEGMENT_PRESENT | SEGMENT_RING0 | SEGMENT_STORAGE |\ + SEGMENT_GATE | SEGMENT_DPL; + +struct idt_entry { + uint16_t isr_low; + uint16_t kernel_cs; + uint8_t reserved; + uint8_t flags; + uint16_t isr_high; +} __attribute__((packed)); + +struct idt_ptr { + uint16_t limit; + uint32_t base; +} __attribute__((packed)); + +extern struct idt_entry idt[256]; +extern struct idt_ptr idtr; + +extern void idt_set_gate(uint8_t num, void(*handler)(void), uint16_t cs, uint8_t flags); +extern void exception_handler(int num); + +#endif \ No newline at end of file diff --git a/arch/i386/include/kernel/isr.h b/arch/i386/include/kernel/isr.h new file mode 100644 index 0000000..a924cd6 --- /dev/null +++ b/arch/i386/include/kernel/isr.h @@ -0,0 +1,37 @@ +#ifndef I386_ISR_H +#define I386_ISR_H + +extern void isr_stub_0(void); +extern void isr_stub_1(void); +extern void isr_stub_2(void); +extern void isr_stub_3(void); +extern void isr_stub_4(void); +extern void isr_stub_5(void); +extern void isr_stub_6(void); +extern void isr_stub_7(void); +extern void isr_stub_8(void); +extern void isr_stub_9(void); +extern void isr_stub_10(void); +extern void isr_stub_11(void); +extern void isr_stub_12(void); +extern void isr_stub_13(void); +extern void isr_stub_14(void); +extern void isr_stub_15(void); +extern void isr_stub_16(void); +extern void isr_stub_17(void); +extern void isr_stub_18(void); +extern void isr_stub_19(void); +extern void isr_stub_20(void); +extern void isr_stub_21(void); +extern void isr_stub_22(void); +extern void isr_stub_23(void); +extern void isr_stub_24(void); +extern void isr_stub_25(void); +extern void isr_stub_26(void); +extern void isr_stub_27(void); +extern void isr_stub_28(void); +extern void isr_stub_29(void); +extern void isr_stub_30(void); +extern void isr_stub_31(void); + +#endif \ No newline at end of file -- cgit v1.2.3