Skip to content

Commit

Permalink
feat: Interrupts working!
Browse files Browse the repository at this point in the history
Signed-off-by: Redson <redson@riseup.net>
  • Loading branch information
RedsonBr140 committed Nov 6, 2023
1 parent 516ca08 commit 411cdda
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Kernel/Arch/x86_64-pc/Asm/Asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool interrupts_enabled() {
void loadIDT(idtr_t *idtr) { __asm__ volatile("lidt %0" : : "m"(*idtr)); }
void sti(void) { asm("sti"); }
void cli(void) { asm("cli"); }
void halt(void) { asm("hlt"); }
__attribute__((noreturn)) void halt(void) { asm("hlt"); }

__attribute__((noreturn)) void hcf(void) {
asm("cli");
Expand Down
7 changes: 6 additions & 1 deletion Kernel/Arch/x86_64-pc/Entry/Entry.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Asm/Asm.h>
#include <Framebuffer/Framebuffer.h>
#include <IO/Ports.h>
#include <Kernel/Panic.h>
#include <LibK/stdio.h>
#include <Serial/Serial.h>
Expand Down Expand Up @@ -60,5 +61,9 @@ void Arch_entry(void) {
kprintf("Welcome to BlobOS!\nVersion: %s\n", GIT_VERSION);

PIC_Unmask(KEYBOARD);
halt();

// FIXME: This is hacky and will slow down the kernel.
for (;;) {
io_wait();
}
}
11 changes: 9 additions & 2 deletions Kernel/Arch/x86_64-pc/System/Exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ Default_INT_Handler(struct interrupt_frame *frame) {

__attribute__((interrupt)) void Keyboard(struct interrupt_frame *frame) {
inb(0x60);
kprintf("Key pressed");
PIC_SendEOI(PIC_REMAP_OFFSET + KEYBOARD);
kprintf("Key pressed!\n");
PIC_SendEOI(KEYBOARD);
}

__attribute__((interrupt)) void TimerF(struct interrupt_frame *frame) {
kprintf(".");
PIC_SendEOI(TIMER);
}

void Load_Exceptions(void) {
Expand Down Expand Up @@ -114,6 +119,8 @@ void Load_Exceptions(void) {
IDT_Add_Int(i, Default_INT_Handler, IDT_FLAGS_INTERRUPT_GATE);
}

IDT_Add_Int(PIC_REMAP_OFFSET + TIMER, TimerF, IDT_FLAGS_INTERRUPT_GATE);

IDT_Add_Int(PIC_REMAP_OFFSET + KEYBOARD, Keyboard,
IDT_FLAGS_INTERRUPT_GATE);
}
2 changes: 1 addition & 1 deletion Kernel/Include/Asm/Asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Checks if the interrupts are enabled. Return 1 if so, otherwise, return 0.
bool interrupts_enabled();
void loadIDT(idtr_t *idtr);
void halt(void);
__attribute__((noreturn)) void halt(void);
__attribute__((noreturn)) void hcf(void);
void sti(void);
void cli(void);
Expand Down

0 comments on commit 411cdda

Please sign in to comment.