mbr_asm/main.c

51 lines
1.2 KiB
C

#include "exception.h"
#include "gdt.h"
#include "idt.h"
#include "interrupt.h"
#include "io.h"
#include "irq.h"
#include "types.h"
#include "vga.h"
char getScancode()
{
char c = 0;
do {
if (inb(0x60) != c) {
c = inb(0x60);
if (c > 0)
return c;
}
} while (1);
}
void cpuid(int code, uint32_t *a, uint32_t *d)
{
asm volatile("cpuid" : "=a"(*a), "=d"(*d) : "0"(code) : "ebx", "ecx");
}
void kmain()
{
const short color = GREEN;
clearScreen(BLACK);
printString("Setting up IDT", color, BLACK, 0, 0);
gdtSetup();
idtSetup();
printString("Setting up IRQ", color, BLACK, 0, 1);
irqSetup();
printString("Setting up IRQ_KEYBOARD", color, BLACK, 0, 1);
irqSetRoutine(IRQ_KEYBOARD, keyboard_handler);
printString("Enabling HW interrupts", color, BLACK, 0, 1);
exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, print_handler);
// Enabling the HW interrupts
asm volatile("sti\n");
printString("Idling", color, BLACK, 0, 2);
while (1) {
char c = getScancode();
printChar(c, color, BLACK, 0, 5);
}
printString("exiting", color, BLACK, 0, 3);
}