summaryrefslogtreecommitdiff
path: root/kernel/src/cpu/irq.c
blob: 6975feceb671efc18835f6f9ce68b2f1b4260476 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <types.h>
#include <irq_handler.h>

#include <pic.h>
#include <io.h>
#include <keyboard.h>
#include <timer.h>
#include <paging.h>
#include <libk/serial_stdio.h>
#include <libk/stdio.h>
#include <panic.h>
#include <ioapic.h>

#define PIT 0

const char* const exception_name[] = {
	"Divide-by-zero Error",
	"Debug",
	"Non-maskable Interrupt",
	"Breakpoint",
	"Overflow",
	"Bound Range Exceeded",
	"Invalid Opcode",
	"Device Not Available",
	"Double Fault",
	"Coprocessor Segment Overrun",
	"Invalid TSS",
	"Segment Not Present",
	"Stack-Segment Fault",
	"General Protection Fault",
	"Page Fault",
	"Reserved",
	"x87 Floating-Point Exception",
	"Alignment Check",
	"Machine Check",
	"SIMD Floating-Point Exception",
	"Virtualization Exception",
	"Control Protection Exception",
	"Reserved",
	"Reserved",
	"Reserved",
	"Reserved",
	"Reserved",
	"Reserved",
	"Hypervisor Injection Exception",
	"VMM Communication Exception",
	"Security Exception",
	"Reserved",
};

void isr_def_handler(uint64_t number, uint64_t error)
{
	switch(number) {
		case 14:
			printf("%s, error: 0x%x\n", exception_name[14], error);
			page_fault(error);
			break;
		default:
			panic("%s, error: 0x%x\n", exception_name[number], error);
	}
}

void eoi(uint64_t number)
{
	if (PIT) {
		if (number < 8) {
			outb(PIC1_COMMAND, PIC_EOI);
		} else if (number < 16) {
			outb(PIC1_COMMAND, PIC_EOI);
			outb(PIC2_COMMAND, PIC_EOI);
		}
	} else {
		ioapic_eoi();
	}
}

void irq_def_handler(uint64_t number)
{
	switch(number)
	{
		case 0:
			timer_handler();
			break;
		case 1:
			keyboard_handler();
			break;
	}
	eoi(number);
}