aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/interrupts
diff options
context:
space:
mode:
authorMarvin Borner2019-11-24 23:34:32 +0100
committerMarvin Borner2019-11-24 23:34:32 +0100
commitbb57b124d1bb385d41747f50be7dd4f3625539c1 (patch)
treefe461afad63df40571784565e8d435cba8c8e59c /src/kernel/interrupts
parentf9c50b9ff23e9a3e8db5826fef7a6e7ebb8af21d (diff)
Major coding style reformatting -> Kernighan & Ritchie
This project now (hopefully) uses the same style recommended by Kernighan and Ritchie and used in the Linux Kernel
Diffstat (limited to 'src/kernel/interrupts')
-rw-r--r--src/kernel/interrupts/idt.c8
-rw-r--r--src/kernel/interrupts/irq.c44
-rw-r--r--src/kernel/interrupts/isr.c24
3 files changed, 47 insertions, 29 deletions
diff --git a/src/kernel/interrupts/idt.c b/src/kernel/interrupts/idt.c
index 5f92294..b06a52a 100644
--- a/src/kernel/interrupts/idt.c
+++ b/src/kernel/interrupts/idt.c
@@ -21,7 +21,8 @@ struct idt_ptr idtp;
// Defined in idt.asm
extern void idt_load();
-void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags) {
+void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
+{
// Specify the interrupt routine's base address
idt[num].base_lo = (base & 0xFFFF);
idt[num].base_hi = (base >> 16) & 0xFFFF;
@@ -33,7 +34,8 @@ void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, uns
}
// Install IDT
-void idt_install() {
+void idt_install()
+{
// Set IDT pointer and limit
idtp.limit = (sizeof(struct idt_entry) * 256) - 1;
idtp.base = &idt;
@@ -42,5 +44,5 @@ void idt_install() {
memset(&idt, 0, sizeof(struct idt_entry) * 256);
idt_load();
- vga_log("Installed Interrupt Descriptor Table", 6);
+ vga_log("Installed Interrupt Descriptor Table", 5);
}
diff --git a/src/kernel/interrupts/irq.c b/src/kernel/interrupts/irq.c
index 979b25c..a0a396d 100644
--- a/src/kernel/interrupts/irq.c
+++ b/src/kernel/interrupts/irq.c
@@ -41,35 +41,40 @@ void *irq_routines[16] = {
};
// Install custom IRQ handler
-void irq_install_handler(int irq, void (*handler)(struct regs *r)) {
+void irq_install_handler(int irq, void (*handler)(struct regs *r))
+{
irq_routines[irq] = handler;
}
// Removes the custom IRQ handler
-void irq_uninstall_handler(int irq) {
+void irq_uninstall_handler(int irq)
+{
irq_routines[irq] = 0;
}
-int irq_is_installed(int irq) {
+int irq_is_installed(int irq)
+{
return irq_routines[irq] != 0;
}
// Remap IRQs for protected mode compatibility via the PIC
-void irq_remap(void) {
- send_b(0x20, 0x11);
- send_b(0xA0, 0x11);
- send_b(0x21, 0x20);
- send_b(0xA1, 0x28);
- send_b(0x21, 0x04);
- send_b(0xA1, 0x02);
- send_b(0x21, 0x01);
- send_b(0xA1, 0x01);
- send_b(0x21, 0x0);
- send_b(0xA1, 0x0);
+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);
}
// Map ISRs to the correct entries in the IDT
-void irq_install() {
+void irq_install()
+{
irq_remap();
idt_set_gate(32, (unsigned) irq0, 0x08, 0x8E);
idt_set_gate(33, (unsigned) irq1, 0x08, 0x8E);
@@ -87,11 +92,12 @@ void irq_install() {
idt_set_gate(45, (unsigned) irq13, 0x08, 0x8E);
idt_set_gate(46, (unsigned) irq14, 0x08, 0x8E);
idt_set_gate(47, (unsigned) irq15, 0x08, 0x8E);
- vga_log("Installed Interrupt Requests", 8);
+ vga_log("Installed Interrupt Requests", 7);
}
// Handle IRQ ISRs
-void irq_handler(struct regs *r) {
+void irq_handler(struct regs *r)
+{
void (*handler)(struct regs *r);
// Execute custom handler if exists
@@ -102,9 +108,9 @@ void irq_handler(struct regs *r) {
// Send end of interrupt to second (slave) IRQ controller
if (r->int_no >= 40) {
- send_b(0xA0, 0x20);
+ outb(0xA0, 0x20);
}
// Send end of interrupt to master interrupt controller
- send_b(0x20, 0x20);
+ outb(0x20, 0x20);
}
diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c
index 28f67ae..d511dda 100644
--- a/src/kernel/interrupts/isr.c
+++ b/src/kernel/interrupts/isr.c
@@ -73,7 +73,8 @@ extern void isr31();
uint32_t ignored_isr[8] = {0};
// Install ISRs in IDT
-void isrs_install() {
+void isrs_install()
+{
idt_set_gate(0, (unsigned) isr0, 0x08, 0x8E);
idt_set_gate(1, (unsigned) isr1, 0x08, 0x8E);
idt_set_gate(2, (unsigned) isr2, 0x08, 0x8E);
@@ -110,7 +111,7 @@ void isrs_install() {
idt_set_gate(30, (unsigned) isr30, 0x08, 0x8E);
idt_set_gate(31, (unsigned) isr31, 0x08, 0x8E);
- vga_log("Installed Interrupt Service Routines", 7);
+ vga_log("Installed Interrupt Service Routines", 6);
}
// Error exception messages
@@ -153,10 +154,11 @@ const char *exception_messages[] = {
};
// Master exception/interrupt/fault handler - halt via panic
-void fault_handler(struct regs *r) {
+void fault_handler(struct regs *r)
+{
if (r->int_no < 32 && !(ignored_isr[r->int_no / 32] & (1 << (r->int_no % 32)))) {
uint32_t faulting_address;
- asm volatile("mov %%cr2, %0" : "=r" (faulting_address));
+ asm ("mov %%cr2, %0" : "=r" (faulting_address));
serial_write("\n[DEBUG]\nEIP: ");
serial_write_hex(r->eip);
@@ -174,14 +176,22 @@ void fault_handler(struct regs *r) {
serial_write_hex(r->eflags);
serial_write("\nError code: ");
serial_write_hex(r->err_code);
+ serial_write("\nInterrupt code: ");
+ serial_write_hex(r->int_no);
+ halt_loop(); // Idk loop?
char *message = (char *) exception_messages[r->int_no];
strcat(message, " Exception");
- if (r->err_code == 2) halt_loop(); // Idk loop?
panic(message);
}
}
-void isr_ignore(uint8_t int_no) { ignored_isr[int_no / 32] |= 1 << (int_no % 32); }
+void isr_ignore(uint8_t int_no)
+{
+ ignored_isr[int_no / 32] |= 1 << (int_no % 32);
+}
-void isr_remember(uint8_t int_no) { ignored_isr[int_no / 32] &= ~(1 << (int_no % 32)); }
+void isr_remember(uint8_t int_no)
+{
+ ignored_isr[int_no / 32] &= ~(1 << (int_no % 32));
+}