Skip to content

Commit

Permalink
fix up some idt stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed May 15, 2023
1 parent 1b9b498 commit ae60cd9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion asm/loader.S
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exception_gate_loop:
dec %rcx
jnz exception_gate_loop

mov $(64-32), %rcx
mov $32, %rcx
interrupt_gate_loop:
mov (%r10), %rax // Get the gate jump-table address in r10 again
add $8, %r10
Expand Down
6 changes: 4 additions & 2 deletions src/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ void symbol_fail()

void init_debug()
{
assert(module_request.response, "No module response!");
assert(module_request.response->module_count > 0, "Debug symbol module not loaded in limine.cfg");
if (!module_request.response || module_request.response->module_count == 0) {
symbol_fail();
return;
}
uint64_t filesize = module_request.response->modules[0]->size;
unsigned char* filecontent = module_request.response->modules[0]->address;
unsigned char* ptr = filecontent;
Expand Down
4 changes: 2 additions & 2 deletions src/errorhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ void init_error_handler()
dprintf("Init error handlers\n");
}

void error_handler(uint8_t int_no, [[maybe_unused]] uint64_t errorcode, [[maybe_unused]] uint64_t irq_no, void* opaque)
void error_handler(uint8_t int_no, uint64_t errorcode, [[maybe_unused]] uint64_t irq_no, void* opaque)
{
interrupts_off();
setforeground(current_console, COLOUR_LIGHTWHITE);
setbackground(current_console, COLOUR_BLACK);
PANIC_BANNER;
setforeground(current_console, COLOUR_LIGHTRED);
kprintf("Fatal exception %02X: %s\n", int_no, error_table[int_no]);
kprintf("Fatal exception %02X (Error code %016lx): %s\n", int_no, errorcode, error_table[int_no]);
setforeground(current_console, COLOUR_WHITE);
backtrace();
wait_forever();
Expand Down
17 changes: 8 additions & 9 deletions src/idt.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <kernel.h>

volatile idt_ptr_t idt64 = { sizeof(idt_entry_t) * 255, NULL };
volatile idt_ptr_t idt64 = { sizeof(idt_entry_t) * 64, NULL };

#define PIC1 0x20 /* IO base address for master PIC */
#define PIC2 0xA0 /* IO base address for slave PIC */
Expand Down Expand Up @@ -83,12 +83,18 @@ void pic_eoi(int irq)
void init_idt()
{
/* Allocate memory for IDT */
uint32_t base_32 = kmalloc_low(sizeof(idt_entry_t) * 255);
uint32_t base_32 = kmalloc_low(sizeof(idt_entry_t) * 64);
uint64_t base_64 = (uint64_t)base_32;
idt64.base = (idt_entry_t*)base_64;

dprintf("Allocated idt64 at %llx\n", base_64);

init_error_handler();
dprintf("Register timer handler\n");
register_interrupt_handler(IRQ0, timer_callback, dev_zero, NULL);
dprintf("Register debug\n");
init_debug();

/* Fill the IDT with vector addresses */
idt_init((idt_entry_t*)idt64.base);

Expand All @@ -115,13 +121,6 @@ void init_idt()
outb(0x40, (uint8_t)microsecs_divisor >> 8);

pic_remap(0x20, 0x28);

init_error_handler();
dprintf("Register timer handler\n");
register_interrupt_handler(IRQ0, timer_callback, dev_zero, NULL);
dprintf("Register debug\n");
init_debug();

pic_enable();

/* Now we are safe to enable interrupts */
Expand Down

0 comments on commit ae60cd9

Please sign in to comment.