1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-10-30 12:03:52 -04:00

Handle hardware interrupts

This commit is contained in:
Braiden Vasco 2017-11-03 02:51:24 +00:00
parent 252f8baf49
commit 729be6e089
6 changed files with 128 additions and 1 deletions

View file

@ -6,8 +6,10 @@ CC = $(CCPREFIX)gcc
OBJS = boot.s.o main.c.o
OBJS += logger.c.o console.c.o
OBJS += multiboot.c.o
OBJS += protected.c.o protected.asm.cpp.o
OBJS += exception.c.o exception.asm.cpp.o
OBJS += hwint.c.o hwint.asm.cpp.o
all: kernel

54
arch/hwint.asm Normal file
View file

@ -0,0 +1,54 @@
#include "config.h"
[EXTERN hwint_handler]
%macro HWINT 2
[GLOBAL hwint_%1]
hwint_%1:
cli
push byte 0
push byte %2
jmp hwint_common_stub
%endmacro
HWINT 0, 32
HWINT 1, 33
HWINT 2, 34
HWINT 3, 35
HWINT 4, 36
HWINT 5, 37
HWINT 6, 38
HWINT 7, 39
HWINT 8, 40
HWINT 9, 41
HWINT 10, 42
HWINT 11, 43
HWINT 12, 44
HWINT 13, 45
HWINT 14, 46
HWINT 15, 47
hwint_common_stub:
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; save the data segment descriptor
mov ax, GDT_KERNEL_DS_SELECTOR
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call hwint_handler
pop eax ; reload the original data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa ; Pops edi,esi,ebp...
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
sti
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP

32
arch/hwint.c Normal file
View file

@ -0,0 +1,32 @@
#include "logger.h"
struct IsrRegisters {
unsigned int ds; // Data segment selector
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha.
unsigned int int_no, err_code; // Interrupt number and error code (if applicable)
unsigned int eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.
};
static const char *const messages[] = {
"Unhandled hwint: 0",
"Unhandled hwint: 1",
"Unhandled hwint: 2",
"Unhandled hwint: 3",
"Unhandled hwint: 4",
"Unhandled hwint: 5",
"Unhandled hwint: 6",
"Unhandled hwint: 7",
"Unhandled hwint: 8",
"Unhandled hwint: 9",
"Unhandled hwint: 10",
"Unhandled hwint: 11",
"Unhandled hwint: 12",
"Unhandled hwint: 13",
"Unhandled hwint: 14",
"Unhandled hwint: 15",
};
void hwint_handler(struct IsrRegisters regs)
{
logger_warn(messages[regs.int_no - 32]);
}

21
arch/hwint.h Normal file
View file

@ -0,0 +1,21 @@
#ifndef KERNELMQ_INCLUDED_HWINT
#define KERNELMQ_INCLUDED_HWINT 1
void hwint_0();
void hwint_1();
void hwint_2();
void hwint_3();
void hwint_4();
void hwint_5();
void hwint_6();
void hwint_7();
void hwint_8();
void hwint_9();
void hwint_10();
void hwint_11();
void hwint_12();
void hwint_13();
void hwint_14();
void hwint_15();
#endif

View file

@ -13,7 +13,7 @@ void main(struct KernelMQ_Multiboot_Info multiboot_info)
protected_initialize();
asm volatile ("int $0x3");
asm volatile ("int $0x4");
asm volatile ("int $0x24");
logger_warn("Nothing to do.");
logger_fail("Halt.");

View file

@ -3,6 +3,7 @@
#include "config.h"
#include "logger.h"
#include "exception.h"
#include "hwint.h"
struct GdtPointer {
unsigned short limit;
@ -97,6 +98,23 @@ void protected_initialize()
idt_set_gate(30, (unsigned int)exception_30, 0x08, 0x8E);
idt_set_gate(31, (unsigned int)exception_31, 0x08, 0x8E);
idt_set_gate(32, (unsigned int)hwint_0, 0x08, 0x8E);
idt_set_gate(33, (unsigned int)hwint_1, 0x08, 0x8E);
idt_set_gate(34, (unsigned int)hwint_2, 0x08, 0x8E);
idt_set_gate(35, (unsigned int)hwint_3, 0x08, 0x8E);
idt_set_gate(36, (unsigned int)hwint_4, 0x08, 0x8E);
idt_set_gate(37, (unsigned int)hwint_5, 0x08, 0x8E);
idt_set_gate(38, (unsigned int)hwint_6, 0x08, 0x8E);
idt_set_gate(39, (unsigned int)hwint_7, 0x08, 0x8E);
idt_set_gate(40, (unsigned int)hwint_8, 0x08, 0x8E);
idt_set_gate(41, (unsigned int)hwint_9, 0x08, 0x8E);
idt_set_gate(42, (unsigned int)hwint_10, 0x08, 0x8E);
idt_set_gate(43, (unsigned int)hwint_11, 0x08, 0x8E);
idt_set_gate(44, (unsigned int)hwint_12, 0x08, 0x8E);
idt_set_gate(45, (unsigned int)hwint_13, 0x08, 0x8E);
idt_set_gate(46, (unsigned int)hwint_14, 0x08, 0x8E);
idt_set_gate(47, (unsigned int)hwint_15, 0x08, 0x8E);
logger_info("Load GDT.");
gdt_pointer.limit = sizeof(struct GdtEntry) * GDT_SIZE - 1;