formatting and make events const

This commit is contained in:
nub31
2025-08-29 15:30:30 +02:00
parent 9c1b4a2c94
commit 827d27e3e3
7 changed files with 67 additions and 47 deletions

View File

@@ -29,40 +29,42 @@ typedef struct
} __attribute__((packed)) idtr_t;
extern void* isr_stub_table[];
static irq_handler_t irq_handlers[16] = { 0 };
static irq_handler_t irq_handlers[16] = {0};
static const char* exception_messages[32] = { "divide by zero",
"debug",
"non maskable interrupt",
"breakpoint",
"overflow",
"bound range exceeded",
"invalid opcode",
"device not available",
"double fault",
"coprocessor segment overrun",
"invalid tss",
"segment not present",
"stack-segment fault",
"general protection fault",
"page fault",
"reserved",
"x87 floating point exception",
"alignment check",
"machine check",
"simd floating point exception",
"virtualization exception",
"control protection exception",
"reserved",
"reserved",
"reserved",
"reserved",
"reserved",
"reserved",
"hypervisor injection exception",
"vmm communication exception",
"security exception",
"reserved" };
static const char* exception_messages[32] = {
"divide by zero",
"debug",
"non maskable interrupt",
"breakpoint",
"overflow",
"bound range exceeded",
"invalid opcode",
"device not available",
"double fault",
"coprocessor segment overrun",
"invalid tss",
"segment not present",
"stack-segment fault",
"general protection fault",
"page fault",
"reserved",
"x87 floating point exception",
"alignment check",
"machine check",
"simd floating point exception",
"virtualization exception",
"control protection exception",
"reserved",
"reserved",
"reserved",
"reserved",
"reserved",
"reserved",
"hypervisor injection exception",
"vmm communication exception",
"security exception",
"reserved",
};
static interrupt_descriptor idt[IDT_SIZE];
@@ -126,7 +128,10 @@ void init_idt(void)
idt_set_descriptor(i, isr_stub_table[i], 0);
}
idtr_t idtr = { .base = (uintptr_t)&idt[0], .limit = (uint16_t)sizeof(interrupt_descriptor) * IDT_SIZE - 1 };
idtr_t idtr = {
.base = (uintptr_t)&idt[0],
.limit = (uint16_t)sizeof(interrupt_descriptor) * IDT_SIZE - 1,
};
__asm__ volatile("lidt %0" : : "m"(idtr));
__asm__ volatile("sti");

View File

@@ -11,7 +11,7 @@ typedef struct
uint64_t rip, cs, rflags, rsp, ss;
} __attribute__((packed)) isr_frame_t;
typedef void (*irq_handler_t)(isr_frame_t*);
typedef void (*irq_handler_t)(const isr_frame_t*);
void init_idt(void);

View File

@@ -4,7 +4,7 @@
#include "vga.h"
#include <stdbool.h>
void keyboard_handler(keyboard_event_t* event)
void keyboard_handler(const keyboard_event_t* event)
{
if (event->pressed)
{

View File

@@ -18,7 +18,7 @@ bool caps_lock = false;
static keyboard_handler_t keyboard_handlers[KEYBOARD_HANDLERS_LENGTH];
static int handler_index = 0;
void handle_keyboard(isr_frame_t* frame)
void handle_keyboard(const isr_frame_t* frame)
{
uint8_t code = inb(0x60);
uint8_t scan_code = code & 0x7F;
@@ -42,7 +42,12 @@ void handle_keyboard(isr_frame_t* frame)
}
default:
{
keyboard_event_t event = { .scan_code = scan_code, .pressed = pressed, .caps_lock = caps_lock, .shift = shift };
keyboard_event_t event = {
.scan_code = scan_code,
.pressed = pressed,
.caps_lock = caps_lock,
.shift = shift,
};
for (int i = 0; i < handler_index; i++)
{
@@ -52,9 +57,10 @@ void handle_keyboard(isr_frame_t* frame)
}
}
void register_keypress_handler(keyboard_handler_t handler)
void register_keypress_handler(const keyboard_handler_t handler)
{
// todo(nub31): remove when a memory allocator is implemented and keyboard_handlers is a dynamic list
// todo(nub31): remove when a memory allocator is implemented and
// keyboard_handlers is a dynamic list
if (handler_index >= KEYBOARD_HANDLERS_LENGTH)
{
vga_print_error();

View File

@@ -9,9 +9,10 @@ typedef struct
bool pressed;
bool shift;
bool caps_lock;
char ascii;
} keyboard_event_t;
typedef void (*keyboard_handler_t)(keyboard_event_t*);
typedef void (*keyboard_handler_t)(const keyboard_event_t*);
void init_keyboard();
void register_keypress_handler(keyboard_handler_t handler);

View File

@@ -33,7 +33,10 @@ void vga_clear(void)
{
for (uint8_t col = 0; col < COLUMNS; col++)
{
vga_char character = { .character = ' ', .color = vga_default_color() };
vga_char character = {
.character = ' ',
.color = vga_default_color(),
};
vga_set_char(row, col, character);
}
}
@@ -68,7 +71,10 @@ void vga_print_char_colored(char character, vga_color_t color)
}
default:
{
vga_char c = { .character = character, .color = color };
vga_char c = {
.character = character,
.color = color,
};
vga_set_char(cursor_row, cursor_col, c);
cursor_col += 1;
break;
@@ -93,7 +99,10 @@ void vga_print_char_colored(char character, vga_color_t color)
for (uint8_t col = 0; col < COLUMNS; col++)
{
vga_char c = { .character = ' ', .color = vga_default_color() };
vga_char c = {
.character = ' ',
.color = vga_default_color(),
};
vga_set_char(ROWS - 1, col, c);
};