os/arch/i686/interrupts/interrupt.c

91 lines
2.2 KiB
C
Raw Normal View History

2024-07-11 08:56:52 +02:00
#include <kernel/tty.h>
#include <stddef.h>
#include <debugging.h>
2024-08-09 23:16:20 +02:00
#include <kernel/keyboard.h>
#include "../io.h"
2024-07-11 08:56:52 +02:00
struct interrupt_frame {
uint32_t eflags;
uint32_t cs;
uint32_t eip;
};
uint8_t test = 'a';
static void stack_trace()
{
uint32_t* stack = 0;
asm("mov %%esp, %0" : "=r" (stack));
for (int i = 0; i < 25; i++) {
uint32_t* current_address = stack + (i * 4);
print_hex_bytes(&current_address, 4);
terminal_writestring(": ");
print_hex_bytes(current_address, 4);
terminal_putchar('\n');
}
}
__attribute__((interrupt)) void divide_by_zero(struct interrupt_frame* frame)
{
terminal_writestring("Yo dude u cant divide by zero yao\n");
while (1) { }
}
__attribute__((interrupt)) void general_protection_fault(struct interrupt_frame* frame)
{
2024-08-08 21:34:30 +02:00
terminal_writestring("GPF handler called\n");
while (1) { }
}
__attribute__((interrupt)) void double_fault(struct interrupt_frame* frame)
{
2024-08-08 21:34:30 +02:00
terminal_writestring("2 Errors in a row, u better behave naughty naughty\n");
while (1) { }
}
__attribute__((interrupt)) void exception(struct interrupt_frame* frame)
{
terminal_writestring("Some weird error code stuff\n");
while (1) { }
}
__attribute__((interrupt)) void print(struct interrupt_frame* frame)
{
char* start;
asm("mov %%edx, %0" : "=r" (start));
terminal_writestring(start);
}
__attribute__((interrupt)) void input(struct interrupt_frame* frame)
2024-07-11 08:56:52 +02:00
{
char* buffer;
asm("mov %%edx, %0" : "=r" (buffer));
2024-08-09 23:16:20 +02:00
/* size_t index = 0;
char current_character = get_last_key_pressed();
while (current_character != '\n') {
char tmp = get_last_key_pressed();
if (current_character != -1 && tmp != current_character) {
buffer[index] = current_character;
terminal_putchar(current_character);
index++;
}
current_character = tmp;
}
2024-08-09 23:16:20 +02:00
buffer[index] = '\0'; */
}
__attribute__((interrupt)) void keyboard_interrupt(struct interrupt_frame* frame)
{
uint8_t scancode = inb(0x60);
handle_keyboard(scancode);
outb(0x20, 0x20);
2024-07-11 08:56:52 +02:00
}
__attribute__((interrupt)) void irq(struct interrupt_frame* frame)
2024-07-11 08:56:52 +02:00
{
2024-08-08 21:34:30 +02:00
outb(0x20, 0x20);
2024-07-11 08:56:52 +02:00
}