diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2017-03-06 02:52:05 +0100 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2017-03-06 02:52:05 +0100 |
commit | 05b9ca73793047e795e46a2ae13db02c34b8a7c3 (patch) | |
tree | 5ab672db87c57cbe01662547e7733e71aa748743 /arch | |
parent | 28301499381cb541eec4eb99f61e3d1a193c5a2d (diff) | |
download | garmos-05b9ca73793047e795e46a2ae13db02c34b8a7c3.tar.gz garmos-05b9ca73793047e795e46a2ae13db02c34b8a7c3.tar.bz2 |
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.
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86_64/arch.c | 20 | ||||
-rw-r--r-- | arch/x86_64/idt.s | 47 |
2 files changed, 67 insertions, 0 deletions
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 <garmos/arch.h> #include <garmos/types.h> +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 |