]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/irq/sample_handler.c
Add PS/2 driver
[nameless-os.git] / kernel / arch / x86 / irq / sample_handler.c
1 #include <tty.h>
2 #include <irq/i8259a.h>
3 #include <io.h>
4 #include <stdint.h>
5 #include <input/ps2.h>
6
7 int was_released = 0;
8 int is_caps = 0;
9
10 typedef uint32_t uword_t;
11
12 struct interrupt_frame {
13 uword_t ip;
14 uword_t cs;
15 uword_t flags;
16 };
17
18 struct abort_frame;
19
20 __attribute__((interrupt))
21 void keyb_handler(struct interrupt_frame *frame)
22 {
23 pic_send_eoi(1);
24 uint8_t scancode = inb(PS2_DATA_PORT);
25 if (was_released) {
26 was_released = 0;
27 return;
28 }
29
30 if (scancode == 0xf0) {
31 was_released = 1;
32 uint8_t scancode = inb(PS2_DATA_PORT);
33 if (scancode == 0x12) {
34 is_caps = 0;
35 }
36 return;
37 } else {
38 if (scancode == 0x12) {
39 is_caps = 1;
40 return;
41 }
42 if (!is_caps) {
43 kprintc(scancodes[scancode], 0);
44 } else {
45 kprintc(scancodes[scancode] - ('a'-'A'), 0);
46 }
47 }
48 }
49
50
51 __attribute__((interrupt))
52 void double_fault(struct abort_frame *frame)
53 {
54 *(volatile uint32_t *) (0xb8000) = 0xcf28cf3a;
55 halt:
56 asm volatile ("cli; hlt");
57 goto halt;
58 }
59