Skip to content

Commit

Permalink
chore: Exceptions are being loaded in other place
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 07f6323 commit 516ca08
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
15 changes: 3 additions & 12 deletions Kernel/Arch/x86_64-pc/Entry/Entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
#include <LibK/stdio.h>
#include <Serial/Serial.h>
#include <System/GDT.h>
#include <System/Interrupts.h>
#include <System/PIC.h>
#include <limine.h>
#include <meta.h>

extern void far_jump(void);

// The Limine requests can be placed anywhere, but it is important that
// the compiler does not optimise them away, so, usually, they should
// be made volatile or equivalent.

static volatile struct limine_framebuffer_request framebuffer_request = {
.id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0};

Expand Down Expand Up @@ -54,20 +49,16 @@ void Arch_entry(void) {
// IRQ0 starts at 0x20 and IRQ8 starts at 0x28.
PIC_Initialize(0x20, 0x28);
kprintf("PIC remapped to 0x20 and 0x28\n");
PIC_Mask(ALL);

Load_Exceptions();
kprintf("Exceptions Loaded!\n");
PIC_MaskAll();

IDT_Init();
kprintf("IDT Loaded!\n");

sti();
kprintf("Interrupts enabled!\n");

kprintf("Manually raising interrupt 0:\n");
asm("int $14");

kprintf("Welcome to BlobOS!\nVersion: %s\n", GIT_VERSION);

PIC_Unmask(KEYBOARD);
halt();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdint.h>

__attribute__((packed)) struct interrupt_frame {
uint64_t rax, rds, rcx, rsi, rdi, r8, r9, r10, r11, rbp
uint64_t rax, rds, rcx, rsi, rdi, r8, r9, r10, r11, rbp;
};

typedef struct {
Expand All @@ -11,6 +11,4 @@ typedef struct {
uint64_t error;
} __attribute__((packed)) Registers;

typedef void (*ISRHandler)(Registers *regs);

void Load_Exceptions(void);
1 change: 1 addition & 0 deletions Kernel/Arch/x86_64-pc/Include/System/PIC.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ enum Interrupts {
void PIC_Initialize(int offset1, int offset2);
void PIC_SendEOI(unsigned char irq);
void PIC_Mask(unsigned char IRQline);
void PIC_MaskAll(void);
void PIC_Unmask(unsigned char IRQline);
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <IO/Ports.h>
#include <Kernel/Panic.h>
#include <LibK/stdio.h>
#include <System/Exceptions.h>
#include <System/IDT.h>
#include <System/Interrupts.h>
#include <System/PIC.h>

__attribute__((interrupt)) void C_Int_0(struct interrupt_frame *frame) {
kprintf("Divide By Zero Error #00\n");
Expand Down Expand Up @@ -80,6 +82,12 @@ Default_INT_Handler(struct interrupt_frame *frame) {
kprintf("Unhandled interrupt!\n");
}

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

void Load_Exceptions(void) {
IDT_Add_Int(0, C_Int_0, IDT_FLAGS_INTERRUPT_GATE);
IDT_Add_Int(1, C_Int_1, IDT_FLAGS_INTERRUPT_GATE);
Expand All @@ -105,4 +113,7 @@ void Load_Exceptions(void) {
for (uint8_t i = 20; i < 255; i++) {
IDT_Add_Int(i, Default_INT_Handler, IDT_FLAGS_INTERRUPT_GATE);
}

IDT_Add_Int(PIC_REMAP_OFFSET + KEYBOARD, Keyboard,
IDT_FLAGS_INTERRUPT_GATE);
}
3 changes: 3 additions & 0 deletions Kernel/Arch/x86_64-pc/System/IDT.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Asm/Asm.h>
#include <Kernel/Panic.h>
#include <System/Exceptions.h>
#include <System/IDT.h>

__attribute__((aligned(0x10))) static idt_entry_t idt[256];
Expand All @@ -20,5 +21,7 @@ void IDT_Init(void) {
idtr.base = (uintptr_t)&idt[0];
idtr.limit = (uint16_t)sizeof(idt_entry_t) * IDT_MAX_DESCRIPTORS - 1;

Load_Exceptions();

__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
}
5 changes: 5 additions & 0 deletions Kernel/Arch/x86_64-pc/System/PIC.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ void PIC_SendEOI(unsigned char irq) {
outb(PIC2_COMMAND, PIC_EOI);
outb(PIC1_COMMAND, PIC_EOI);
}

void PIC_MaskAll(void) {
outb(PIC2_DATA, ALL);
outb(PIC2_DATA, ALL);
}
3 changes: 2 additions & 1 deletion Meta/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ fi
qemu-system-x86_64 -cdrom build/BlobOS.iso\
-serial stdio\
-enable-kvm\
-boot dc
-boot dc\
-d int

0 comments on commit 516ca08

Please sign in to comment.