From 05b9ca73793047e795e46a2ae13db02c34b8a7c3 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 6 Mar 2017 02:52:05 +0100 Subject: idt: add interruption handling The Interruption Descriptor Table (IDT) is implemented in idt.{c,h} as part of the core, but the setup and activation of the IDT and the registration of specific interruption request handlers is part of arch.{c,h}. The request handlers are implemented in idt.s and delegate to kernel_handle_interrupt. --- arch/x86_64/arch.c | 20 ++++++++++++++++++++ arch/x86_64/idt.s | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 arch/x86_64/idt.s (limited to 'arch') diff --git a/arch/x86_64/arch.c b/arch/x86_64/arch.c index d7762c2..a8c1417 100644 --- a/arch/x86_64/arch.c +++ b/arch/x86_64/arch.c @@ -15,6 +15,16 @@ #include #include +void irqhdl0x00(void); +void irqhdl0x01(void); + +uint8_t irqnos[3] = { 0x20, 0x21, 0 }; +uint32_t irqhdls[3] = { + (uint32_t) &irqhdl0x00, + (uint32_t) &irqhdl0x01, + 0 +}; + void prtset8(const uint16_t port, const uint8_t val) { asm volatile("outb %0, %1" : : "a" (val), "Nd" (port)); @@ -79,3 +89,13 @@ void gdtset(struct gdtp gdtp) { asm volatile("lgdt %0" : : "m" (gdtp)); } + +void idtset(struct idtp idtp) +{ + asm volatile("lidt %0" : : "m" (idtp)); +} + +void idtact(void) +{ + asm("sti"); +} diff --git a/arch/x86_64/idt.s b/arch/x86_64/idt.s new file mode 100644 index 0000000..ead5b20 --- /dev/null +++ b/arch/x86_64/idt.s @@ -0,0 +1,47 @@ +.set IRQ_BASE, 0x20 + +.section .text +.extern handle_interrput +.global irqign + +.macro gen_irq_handler num +.global irqhdl\num\() +irqhdl\num\(): +movb $\num + IRQ_BASE, (intrptno) +jmp _bot +.endm + +gen_irq_handler 0x00 +gen_irq_handler 0x01 + +_bot: +/* store current data */ +push %ebp +push %edi +push %esi +push %edx +push %ecx +push %ebx +push %eax + +/* call interrupt handler */ +push %esp +push (intrptno) +call kernel_handle_interrupt +movl %eax, %esp + +/* restore previous data */ +pop %eax +pop %ebx +pop %ecx +pop %edx +pop %esi +pop %edi +pop %ebp + +irqign: +/* continue */ +iret + +.data +intrptno: .byte 0 -- cgit v1.2.3