2018-06-30 01:03:40 +02:00
|
|
|
#include "exception.h"
|
2018-06-30 01:00:25 +02:00
|
|
|
#include "gdt.h"
|
2017-11-24 23:41:14 +01:00
|
|
|
#include "idt.h"
|
2018-06-30 01:03:40 +02:00
|
|
|
#include "interrupt.h"
|
2017-11-24 23:41:14 +01:00
|
|
|
#include "io.h"
|
|
|
|
#include "irq.h"
|
2018-07-16 14:20:12 +02:00
|
|
|
#include "pit.h"
|
2017-11-24 23:41:14 +01:00
|
|
|
#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);
|
2017-11-24 23:41:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2017-11-24 23:41:14 +01:00
|
|
|
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-07-16 14:20:12 +02:00
|
|
|
initPit(100);
|
2017-11-24 23:41:14 +01:00
|
|
|
|
2018-07-16 14:20:12 +02:00
|
|
|
printString("Setting up IRQ handlers", color, BLACK, 0, 1);
|
2018-06-26 16:41:06 +02:00
|
|
|
irqSetRoutine(IRQ_KEYBOARD, keyboard_handler);
|
2018-07-16 14:20:12 +02:00
|
|
|
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");
|
2018-07-16 14:20:12 +02:00
|
|
|
int count = 0;
|
2018-06-26 16:41:06 +02:00
|
|
|
while (1) {
|
2018-07-16 14:20:12 +02:00
|
|
|
printInt(count++, color, BLACK, 0, 6);
|
2018-06-26 16:41:06 +02:00
|
|
|
}
|
2018-07-16 14:20:12 +02:00
|
|
|
printString("exiting", color, BLACK, 0, 4);
|
2017-11-24 23:41:14 +01:00
|
|
|
}
|