LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
irq.c
Go to the documentation of this file.
1
9
10#include <arch/x86_64/irq.h>
11#include <arch/x86_64/idt.h>
12#include <arch/x86_64/pic.h>
13
14#include <stddef.h>
15
16static irq_handler_fn irq_handlers[16];
17
18void irq_register(uint8_t irq, irq_handler_fn fn)
19{
20 if (irq >= 16)
21 return;
22 irq_handlers[irq] = fn;
23}
24
25void irq_handler(struct interrupt_frame *frame)
26{
27 uint8_t irq = frame->vector - 32;
28
29 if (irq >= 16)
30 return;
31
32 if (irq == 7 || irq == 15) {
33 // Check for spurious IRQ7
34 uint8_t isr = pic_read_isr();
35
36 if (!(isr & (1 << (irq > 7 ? irq - 8 : irq)))) {
37 // Spurious IRQ, no EOI needed
38 return;
39 }
40 }
41
42 if (irq_handlers[irq] != NULL)
43 irq_handlers[irq](frame);
44
45 pic_send_eoi(irq);
46}
Initializes and holds the IDT for the kernel.
void irq_handler(struct interrupt_frame *frame)
Calls the correct handler and returns the interrupt.
Definition irq.c:25
void irq_register(uint8_t irq, irq_handler_fn fn)
Registers a handler function for the specified IRQ number.
Definition irq.c:18
IRQ Handler and utilities.
void pic_send_eoi(uint8_t irq)
Sends an EOI to tell the PIC that the interrupt is over.
Definition pic.c:103
Handles the legacy PIC for IRQ interrupts.
The frame holding the registers when an interrupt happens.
Definition idt.h:16