mbr_asm/main.c

52 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 "pit.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();
initPit(100);
printString("Setting up IRQ handlers", color, BLACK, 0, 1);
2018-06-26 16:41:06 +02:00
irqSetRoutine(IRQ_KEYBOARD, keyboard_handler);
irqSetRoutine(IRQ_TIMER, timer_handler);
printString("Enabling HW interrupts", color, BLACK, 0, 2);
2018-06-30 01:03:40 +02:00
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");
int count = 0;
2018-06-26 16:41:06 +02:00
while (1) {
printInt(count++, color, BLACK, 0, 6);
2018-06-26 16:41:06 +02:00
}
printString("exiting", color, BLACK, 0, 4);
}