diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | src/drivers/interrupts.asm | 142 | ||||
-rw-r--r-- | src/drivers/interrupts.c | 64 | ||||
-rw-r--r-- | src/inc/interrupts.h | 54 |
4 files changed, 260 insertions, 6 deletions
@@ -5,6 +5,7 @@ COBJS = src/main.o \ src/drivers/cpu.o \ src/drivers/serial.o \ src/drivers/interrupts.o \ + src/drivers/interrupts_asm.o \ src/drivers/keyboard.o \ src/lib/string.o CC = cross/opt/bin/i686-elf-gcc @@ -14,11 +15,16 @@ AS = nasm # TODO: Use lib as external library CFLAGS = -Wall -Wextra -nostdlib -nostdinc -ffreestanding -mgeneral-regs-only -mno-80387 -std=c99 -pedantic-errors -Isrc/lib/inc/ -Isrc/inc/ -c +ASFLAGS = -f elf32 + all: compile clean %.o: %.c $(CC) $(CFLAGS) $< -o $@ +%_asm.o: %.asm + $(AS) $(ASFLAGS) $< -o $@ + kernel: $(COBJS) compile: kernel diff --git a/src/drivers/interrupts.asm b/src/drivers/interrupts.asm new file mode 100644 index 0000000..59c323c --- /dev/null +++ b/src/drivers/interrupts.asm @@ -0,0 +1,142 @@ +; MIT License, Copyright (c) 2020 Marvin Borner + +; IRQ + +%macro IRQ 2 + global irq%1 + irq%1: + cli + push byte 0 + push byte %2 + jmp irq_common_stub +%endmacro + +IRQ 0, 32 +IRQ 1, 33 +IRQ 2, 34 +IRQ 3, 35 +IRQ 4, 36 +IRQ 5, 37 +IRQ 6, 38 +IRQ 7, 39 +IRQ 8, 40 +IRQ 9, 41 +IRQ 10, 42 +IRQ 11, 43 +IRQ 12, 44 +IRQ 13, 45 +IRQ 14, 46 +IRQ 15, 47 + +extern irq_handler +irq_common_stub: + pusha + + push ds + push es + push fs + push gs + + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + cld + + push esp + call irq_handler + add esp, 4 + + pop gs + pop fs + pop es + pop ds + popa + + add esp, 8 + sti + iret + +; ISR + +%macro ISR_NOERRCODE 1 + global isr%1 + isr%1: + cli + push byte 0 + push %1 + jmp isr_common_stub +%endmacro + +%macro ISR_ERRCODE 1 + global isr%1 + isr%1: + cli + push byte %1 + jmp isr_common_stub +%endmacro + +ISR_NOERRCODE 0 +ISR_NOERRCODE 1 +ISR_NOERRCODE 2 +ISR_NOERRCODE 3 +ISR_NOERRCODE 4 +ISR_NOERRCODE 5 +ISR_NOERRCODE 6 +ISR_NOERRCODE 7 +ISR_ERRCODE 8 +ISR_NOERRCODE 9 +ISR_ERRCODE 10 +ISR_ERRCODE 11 +ISR_ERRCODE 12 +ISR_ERRCODE 13 +ISR_ERRCODE 14 +ISR_NOERRCODE 15 +ISR_NOERRCODE 16 +ISR_NOERRCODE 17 +ISR_NOERRCODE 18 +ISR_NOERRCODE 19 +ISR_NOERRCODE 20 +ISR_NOERRCODE 21 +ISR_NOERRCODE 22 +ISR_NOERRCODE 23 +ISR_NOERRCODE 24 +ISR_NOERRCODE 25 +ISR_NOERRCODE 26 +ISR_NOERRCODE 27 +ISR_NOERRCODE 28 +ISR_NOERRCODE 29 +ISR_NOERRCODE 30 +ISR_NOERRCODE 31 +ISR_NOERRCODE 128 + +extern isr_handler +isr_common_stub: + pusha + + push ds + push es + push fs + push gs + + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + cld + + push esp + call isr_handler + add esp, 4 + + pop gs + pop fs + pop es + pop ds + popa + + add esp, 8 + sti + iret diff --git a/src/drivers/interrupts.c b/src/drivers/interrupts.c index bd20911..e3e8699 100644 --- a/src/drivers/interrupts.c +++ b/src/drivers/interrupts.c @@ -1,4 +1,5 @@ // MIT License, Copyright (c) 2020 Marvin Borner +// TODO: Remove some magic numbers #include <cpu.h> #include <def.h> @@ -68,7 +69,7 @@ void irq_remap() } // Handle IRQ ISRs -__attribute__((interrupt)) void irq_handler(struct regs *r) +void irq_handler(struct regs *r) { __asm__("cli"); void (*handler)(struct regs * r); @@ -91,8 +92,24 @@ __attribute__((interrupt)) void irq_handler(struct regs *r) void irq_install() { irq_remap(); - for (int i = 32; i < 48; i++) - idt_set_gate(i, (u32)irq_handler, 0x08, 0x8E); + + idt_set_gate(32, (u32)irq0, 0x08, 0x8E); + idt_set_gate(33, (u32)irq1, 0x08, 0x8E); + idt_set_gate(34, (u32)irq2, 0x08, 0x8E); + idt_set_gate(35, (u32)irq3, 0x08, 0x8E); + idt_set_gate(36, (u32)irq4, 0x08, 0x8E); + idt_set_gate(37, (u32)irq5, 0x08, 0x8E); + idt_set_gate(38, (u32)irq6, 0x08, 0x8E); + idt_set_gate(39, (u32)irq7, 0x08, 0x8E); + + idt_set_gate(40, (u32)irq8, 0x08, 0x8E); + idt_set_gate(41, (u32)irq9, 0x08, 0x8E); + idt_set_gate(42, (u32)irq10, 0x08, 0x8E); + idt_set_gate(43, (u32)irq11, 0x08, 0x8E); + idt_set_gate(44, (u32)irq12, 0x08, 0x8E); + idt_set_gate(45, (u32)irq13, 0x08, 0x8E); + idt_set_gate(46, (u32)irq14, 0x08, 0x8E); + idt_set_gate(47, (u32)irq15, 0x08, 0x8E); } /** @@ -111,7 +128,7 @@ void isr_uninstall_handler(int isr) isr_routines[isr] = 0; } -__attribute__((interrupt)) void isr_handler(struct regs *r) +void isr_handler(struct regs *r) { __asm__("cli"); void (*handler)(struct regs * r); @@ -131,8 +148,43 @@ __attribute__((interrupt)) void isr_handler(struct regs *r) void isr_install() { - for (int i = 0; i < 32; i++) - idt_set_gate(i, (u32)isr_handler, 0x08, 0x8E); + idt_set_gate(0, (u32)isr0, 0x08, 0x8E); + idt_set_gate(1, (u32)isr1, 0x08, 0x8E); + idt_set_gate(2, (u32)isr2, 0x08, 0x8E); + idt_set_gate(3, (u32)isr3, 0x08, 0x8E); + idt_set_gate(4, (u32)isr4, 0x08, 0x8E); + idt_set_gate(5, (u32)isr5, 0x08, 0x8E); + idt_set_gate(6, (u32)isr6, 0x08, 0x8E); + idt_set_gate(7, (u32)isr7, 0x08, 0x8E); + + idt_set_gate(8, (u32)isr8, 0x08, 0x8E); + idt_set_gate(9, (u32)isr9, 0x08, 0x8E); + idt_set_gate(10, (u32)isr10, 0x08, 0x8E); + idt_set_gate(11, (u32)isr11, 0x08, 0x8E); + idt_set_gate(12, (u32)isr12, 0x08, 0x8E); + idt_set_gate(13, (u32)isr13, 0x08, 0x8E); + idt_set_gate(14, (u32)isr14, 0x08, 0x8E); + idt_set_gate(15, (u32)isr15, 0x08, 0x8E); + + idt_set_gate(16, (u32)isr16, 0x08, 0x8E); + idt_set_gate(17, (u32)isr17, 0x08, 0x8E); + idt_set_gate(18, (u32)isr18, 0x08, 0x8E); + idt_set_gate(19, (u32)isr19, 0x08, 0x8E); + idt_set_gate(20, (u32)isr20, 0x08, 0x8E); + idt_set_gate(21, (u32)isr21, 0x08, 0x8E); + idt_set_gate(22, (u32)isr22, 0x08, 0x8E); + idt_set_gate(23, (u32)isr23, 0x08, 0x8E); + + idt_set_gate(24, (u32)isr24, 0x08, 0x8E); + idt_set_gate(25, (u32)isr25, 0x08, 0x8E); + idt_set_gate(26, (u32)isr26, 0x08, 0x8E); + idt_set_gate(27, (u32)isr27, 0x08, 0x8E); + idt_set_gate(28, (u32)isr28, 0x08, 0x8E); + idt_set_gate(29, (u32)isr29, 0x08, 0x8E); + idt_set_gate(30, (u32)isr30, 0x08, 0x8E); + idt_set_gate(31, (u32)isr31, 0x08, 0x8E); + + idt_set_gate(0x80, (u32)isr128, 0x08, 0x8E); } /** diff --git a/src/inc/interrupts.h b/src/inc/interrupts.h index 7145e62..e943e5a 100644 --- a/src/inc/interrupts.h +++ b/src/inc/interrupts.h @@ -38,4 +38,58 @@ void isr_uninstall_handler(int isr); void interrupts_install(); +// External handlers (ASM) + +extern void isr0(); +extern void isr1(); +extern void isr2(); +extern void isr3(); +extern void isr4(); +extern void isr5(); +extern void isr6(); +extern void isr7(); +extern void isr8(); +extern void isr9(); +extern void isr10(); +extern void isr11(); +extern void isr12(); +extern void isr13(); +extern void isr14(); +extern void isr15(); +extern void isr16(); +extern void isr17(); +extern void isr18(); +extern void isr19(); +extern void isr20(); +extern void isr21(); +extern void isr22(); +extern void isr23(); +extern void isr24(); +extern void isr25(); +extern void isr26(); +extern void isr27(); +extern void isr28(); +extern void isr29(); +extern void isr30(); +extern void isr31(); +extern void isr128(); + +extern void irq0(); +extern void irq1(); +extern void irq2(); +extern void irq3(); +extern void irq4(); +extern void irq5(); +extern void irq6(); +extern void irq7(); +extern void irq8(); +extern void irq9(); +extern void irq10(); +extern void irq11(); +extern void irq12(); +extern void irq13(); +extern void irq14(); +extern void irq15(); +extern void irq128(); + #endif |