aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/arch.c20
-rw-r--r--arch/x86_64/idt.s47
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