mbr_asm/main.c

51 lines
1.2 KiB
C
Raw Normal View History

2018-06-30 01:03:40 +02:00
#include "exception.h"
2018-06-30 01:00:25 +02:00
#include "gdt.h"
#include "idt.h"
2018-06-30 01:03:40 +02:00
#include "interrupt.h"
#include "io.h"
#include "irq.h"
#include "types.h"
#include "vga.h"
char getScancode()
{
2018-06-26 16:41:06 +02:00
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)
{
2018-06-26 16:41:06 +02:00
asm volatile("cpuid" : "=a"(*a), "=d"(*d) : "0"(code) : "ebx", "ecx");
}
void kmain()
{
2018-06-26 16:41:06 +02:00
const short color = GREEN;
clearScreen(BLACK);
printString("Setting up IDT", color, BLACK, 0, 0);
2018-06-30 01:00:25 +02:00
gdtSetup();
2018-06-26 16:41:06 +02:00
idtSetup();
printString("Setting up IRQ", color, BLACK, 0, 1);
irqSetup();
2018-06-30 01:03:40 +02:00
printString("Setting up IRQ_KEYBOARD", color, BLACK, 0, 1);
2018-06-26 16:41:06 +02:00
irqSetRoutine(IRQ_KEYBOARD, keyboard_handler);
2018-06-30 01:03:40 +02:00
printString("Enabling HW interrupts", color, BLACK, 0, 1);
exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, print_handler);
2018-06-26 16:41:06 +02:00
// Enabling the HW interrupts
2018-06-30 01:03:40 +02:00
asm volatile("sti\n");
printString("Idling", color, BLACK, 0, 2);
2018-06-26 16:41:06 +02:00
while (1) {
char c = getScancode();
printChar(c, color, BLACK, 0, 5);
}
2018-06-30 01:03:40 +02:00
printString("exiting", color, BLACK, 0, 3);
}