Add: IRQ init
This commit is contained in:
90
irq.c
Normal file
90
irq.c
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "system.h"
|
||||
#include "io.h"
|
||||
#include "idt.h"
|
||||
|
||||
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();
|
||||
|
||||
void *irq_routines[16] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
void irq_install_handler(int irq, void (*handler)(struct regs *r))
|
||||
{
|
||||
irq_routines[irq] = handler;
|
||||
}
|
||||
|
||||
void irq_uninstall_handler(int irq)
|
||||
{
|
||||
irq_routines[irq] = 0;
|
||||
}
|
||||
|
||||
void irq_remap(void)
|
||||
{
|
||||
outb(0x20, 0x11);
|
||||
outb(0xA0, 0x11);
|
||||
outb(0x21, 0x20);
|
||||
outb(0xA1, 0x28);
|
||||
outb(0x21, 0x04);
|
||||
outb(0xA1, 0x02);
|
||||
outb(0x21, 0x01);
|
||||
outb(0xA1, 0x01);
|
||||
outb(0x21, 0x0);
|
||||
outb(0xA1, 0x0);
|
||||
}
|
||||
|
||||
void irq_install()
|
||||
{
|
||||
irq_remap();
|
||||
|
||||
idt_set_gate(32, (unsigned)irq0, 0x08, 0x8E);
|
||||
idt_set_gate(33, (unsigned)irq1, 0x08, 0x8E);
|
||||
idt_set_gate(34, (unsigned)irq2, 0x08, 0x8E);
|
||||
idt_set_gate(35, (unsigned)irq3, 0x08, 0x8E);
|
||||
idt_set_gate(36, (unsigned)irq4, 0x08, 0x8E);
|
||||
idt_set_gate(37, (unsigned)irq5, 0x08, 0x8E);
|
||||
idt_set_gate(38, (unsigned)irq6, 0x08, 0x8E);
|
||||
idt_set_gate(39, (unsigned)irq7, 0x08, 0x8E);
|
||||
idt_set_gate(40, (unsigned)irq8, 0x08, 0x8E);
|
||||
idt_set_gate(41, (unsigned)irq9, 0x08, 0x8E);
|
||||
idt_set_gate(42, (unsigned)irq10, 0x08, 0x8E);
|
||||
idt_set_gate(43, (unsigned)irq11, 0x08, 0x8E);
|
||||
idt_set_gate(44, (unsigned)irq12, 0x08, 0x8E);
|
||||
idt_set_gate(45, (unsigned)irq13, 0x08, 0x8E);
|
||||
idt_set_gate(46, (unsigned)irq14, 0x08, 0x8E);
|
||||
idt_set_gate(47, (unsigned)irq15, 0x08, 0x8E);
|
||||
}
|
||||
|
||||
void irq_handler(struct regs *r)
|
||||
{
|
||||
void (*handler)(struct regs *r);
|
||||
|
||||
handler = irq_routines[r->int_no-32];
|
||||
if (handler)
|
||||
{
|
||||
handler(r);
|
||||
}
|
||||
|
||||
if (r->int_no >= 40)
|
||||
{
|
||||
outb(0xA0, 0x20);
|
||||
}
|
||||
|
||||
outb(0x20, 0x20);
|
||||
}
|
||||
Binary file not shown.
BIN
kernel.elf
BIN
kernel.elf
Binary file not shown.
5
kmain.c
5
kmain.c
@@ -14,7 +14,10 @@ int kmain(int retvalue)
|
||||
idt_install();
|
||||
log("initialized IDT", 2);
|
||||
isr_install();
|
||||
log("initialized ISRs", 3);
|
||||
log("initialized ISRs", 2);
|
||||
irq_install();
|
||||
__asm__ __volatile__("sti");
|
||||
log("initialized IRQs", 2),
|
||||
|
||||
log("kernel started", 2);
|
||||
|
||||
|
||||
139
loader.s
139
loader.s
@@ -294,6 +294,145 @@ isr_common_stub:
|
||||
add esp, 8
|
||||
iret
|
||||
|
||||
global irq0
|
||||
global irq1
|
||||
global irq2
|
||||
global irq3
|
||||
global irq4
|
||||
global irq5
|
||||
global irq6
|
||||
global irq7
|
||||
global irq8
|
||||
global irq9
|
||||
global irq10
|
||||
global irq11
|
||||
global irq12
|
||||
global irq13
|
||||
global irq14
|
||||
global irq15
|
||||
|
||||
irq0:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 32
|
||||
jmp irq_common_stub
|
||||
|
||||
irq1:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 33
|
||||
jmp irq_common_stub
|
||||
|
||||
irq2:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 34
|
||||
jmp irq_common_stub
|
||||
|
||||
irq3:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 35
|
||||
jmp irq_common_stub
|
||||
|
||||
irq4:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 36
|
||||
jmp irq_common_stub
|
||||
|
||||
irq5:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 37
|
||||
jmp irq_common_stub
|
||||
|
||||
irq6:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 38
|
||||
jmp irq_common_stub
|
||||
|
||||
irq7:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 39
|
||||
jmp irq_common_stub
|
||||
|
||||
irq8:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 40
|
||||
jmp irq_common_stub
|
||||
|
||||
irq9:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 41
|
||||
jmp irq_common_stub
|
||||
|
||||
irq10:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 42
|
||||
jmp irq_common_stub
|
||||
|
||||
irq11:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 43
|
||||
jmp irq_common_stub
|
||||
|
||||
irq12:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 44
|
||||
jmp irq_common_stub
|
||||
|
||||
irq13:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 45
|
||||
jmp irq_common_stub
|
||||
|
||||
irq14:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 46
|
||||
jmp irq_common_stub
|
||||
|
||||
irq15:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 47
|
||||
jmp irq_common_stub
|
||||
|
||||
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
|
||||
mov eax, esp
|
||||
push eax
|
||||
mov eax, irq_handler
|
||||
call eax
|
||||
pop eax
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
add esp, 8
|
||||
iret
|
||||
|
||||
section .bss
|
||||
align 4
|
||||
kernel_stack:
|
||||
|
||||
2
makefile
2
makefile
@@ -1,4 +1,4 @@
|
||||
OBJECTS = loader.o kmain.o stdio.o io.o string.o serial.o gdt.o idt.o system.o isr.o
|
||||
OBJECTS = loader.o kmain.o stdio.o io.o string.o serial.o gdt.o idt.o system.o isr.o irq.o
|
||||
CC = gcc
|
||||
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c
|
||||
LDFLAGS = -T link.ld -melf_i386
|
||||
|
||||
Reference in New Issue
Block a user