From 058f61d3ba51231d83635c54d8fb2d33af72261b Mon Sep 17 00:00:00 2001 From: Greg Bowne Date: Wed, 27 Sep 2023 15:57:12 -0700 Subject: [PATCH] Fixed the declarations in gdt.c idt.c isr.c and isr.h --- src/kernel/arch/x86/gdt.c | 2 +- src/kernel/arch/x86/idt.c | 10 ++++---- src/kernel/arch/x86/isr.c | 50 ++++++++++++++++++++++++++++----------- src/kernel/arch/x86/isr.h | 2 +- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/kernel/arch/x86/gdt.c b/src/kernel/arch/x86/gdt.c index 73153b4..f93ac52 100644 --- a/src/kernel/arch/x86/gdt.c +++ b/src/kernel/arch/x86/gdt.c @@ -71,7 +71,7 @@ void (*isr_table[256])(void) = {0}; void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs)); // ISR handler -void isr_handler(struct isr_regs *regs) +void isr_handler(struct idt_regs *regs); { void (*handler)(void); diff --git a/src/kernel/arch/x86/idt.c b/src/kernel/arch/x86/idt.c index 740f03b..1cf09f6 100644 --- a/src/kernel/arch/x86/idt.c +++ b/src/kernel/arch/x86/idt.c @@ -38,11 +38,11 @@ extern void serial_port_handler(); void idt_set_gate(uint8_t num, void *base, uint16_t sel, uint8_t flags) { uintptr_t base_addr = (uintptr_t)base; - idt[num].base_lo = base_addr & BYTE_MASK; - idt[num].base_hi = (base_addr >> BASE_MIDDLE_SHIFT) & 0xFFFF; - idt[num].sel = sel; - idt[num].always0 = 0; - idt[num].flags = flags; + idt[num].base_lo = base_addr & BYTE_MASK; + idt[num].base_hi = (base_addr >> BASE_MIDDLE_SHIFT) & 0xFFFF; + idt[num].sel = sel; + idt[num].always0 = 0; + idt[num].flags = flags; } // Initialize the IDT diff --git a/src/kernel/arch/x86/isr.c b/src/kernel/arch/x86/isr.c index 0bee369..e7b2bea 100644 --- a/src/kernel/arch/x86/isr.c +++ b/src/kernel/arch/x86/isr.c @@ -1,5 +1,6 @@ #include "isr.h" #include "idt.h" +#include #include enum @@ -21,27 +22,48 @@ void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs)) } // ISR handler -// ISR handler -void isr_handler(struct isr_regs *regs) +void isr_handler(struct idt_regs *regs) { switch (regs->int_no) { - case 0: + case 0x00: divide_error(); break; - case 13: + case 0x06: + invalid_opcode(); + break; + case 0x0D: general_protection_fault(regs); break; - case 14: + case 0x0E: page_fault(regs); break; + case 0x08: + double_fault(); + break; + case 0x80: + system_call(regs); + break; + case 0x20: + timer(); + break; + case 0x21: + keyboard(); + break; + case 0x2F: + device(); + break; + case 0x28: + network(); + break; + case 0x2E: + disk(); + break; + case 0x24: + serial_port(); + break; default: - void (*handler)(struct isr_regs *regs); - handler = isr_table[regs->int_no]; - if (handler) - { - handler(regs); - } + printf("Unhandled interrupt: %d\n", regs->int_no); break; } } @@ -53,7 +75,7 @@ void divide_error() // Additional actions can be taken as needed } -void page_fault(struct isr_regs *regs) +void page_fault(struct idt_regs *regs) { uint32_t faulting_address; @@ -67,7 +89,7 @@ void page_fault(struct isr_regs *regs) // Additional actions can be taken as needed } -void general_protection_fault(struct isr_regs *regs) +void general_protection_fault(struct idt_regs *regs) { printf("General protection fault occurred!\n"); // Additional actions can be taken as needed @@ -79,7 +101,7 @@ void double_fault() } // Interrupt handlers -void system_call(struct isr_regs *regs) +void system_call(struct idt_regs *regs) { // Get the system call number from the eax register uint32_t syscall_number = regs->eax; diff --git a/src/kernel/arch/x86/isr.h b/src/kernel/arch/x86/isr.h index ccb5185..f540fee 100644 --- a/src/kernel/arch/x86/isr.h +++ b/src/kernel/arch/x86/isr.h @@ -19,6 +19,6 @@ struct isr_regs void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs)); // ISR handler -void isr_handler(struct isr_regs *regs); +void isr_handler(struct idt_regs *regs); #endif /* ISR_H */ \ No newline at end of file