2018-07-20 15:41:58 +02:00
|
|
|
#include "exception.h"
|
|
|
|
#include "gdt.h"
|
|
|
|
#include "idt.h"
|
|
|
|
#include "interrupt.h"
|
|
|
|
#include "io.h"
|
|
|
|
#include "irq.h"
|
2018-08-05 15:09:32 +02:00
|
|
|
#include "multiboot.h"
|
2018-07-20 15:41:58 +02:00
|
|
|
#include "pit.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "vga.h"
|
|
|
|
|
2018-08-05 15:09:32 +02:00
|
|
|
#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit)))
|
2018-07-20 15:41:58 +02:00
|
|
|
void cpuid(int code, uint32_t *a, uint32_t *d)
|
|
|
|
{
|
|
|
|
asm volatile("cpuid" : "=a"(*a), "=d"(*d) : "0"(code) : "ebx", "ecx");
|
|
|
|
}
|
|
|
|
|
2018-08-05 15:09:32 +02:00
|
|
|
|
|
|
|
// Multiboot information available here : https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#kernel_002ec
|
|
|
|
void kmain(unsigned long magic, unsigned long addr)
|
2018-07-20 15:41:58 +02:00
|
|
|
{
|
|
|
|
initVGA(BLACK, GREEN);
|
|
|
|
printString("Setting up IDT\n");
|
|
|
|
gdtSetup();
|
|
|
|
idtSetup();
|
|
|
|
irqSetup();
|
|
|
|
initPit(100);
|
|
|
|
|
2018-08-05 15:09:32 +02:00
|
|
|
if (magic == MULTIBOOT_BOOTLOADER_MAGIC) { // Get loaded by Grub wuth mutliboot version 1
|
|
|
|
multiboot_info_t *mbi = (multiboot_info_t *)addr;
|
|
|
|
/* Are mem_* valid? */
|
|
|
|
if (CHECK_FLAG(mbi->flags, 0)){
|
|
|
|
printString("mem_lower = ");
|
|
|
|
printInt((unsigned)mbi->mem_lower);
|
|
|
|
printString("KB mem_upper = ");
|
|
|
|
printInt((unsigned)mbi->mem_upper);
|
|
|
|
printString("KB\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is boot_device valid? */
|
|
|
|
if (CHECK_FLAG(mbi->flags, 1)){
|
|
|
|
printString("boot_device = ");
|
|
|
|
printInt((unsigned)mbi->boot_device);
|
|
|
|
printString("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the command line passed? */
|
|
|
|
if (CHECK_FLAG(mbi->flags, 2)){
|
|
|
|
printString("cmdline = ");
|
|
|
|
printString((char *)mbi->cmdline);
|
|
|
|
printString("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 15:41:58 +02:00
|
|
|
printString("Setting up IRQ handlers\n");
|
|
|
|
irqSetRoutine(IRQ_KEYBOARD, keyboard_handler);
|
|
|
|
irqSetRoutine(IRQ_TIMER, timer_handler);
|
|
|
|
printString("Enabling HW interrupts\n");
|
|
|
|
exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, print_handler);
|
|
|
|
// Enabling the HW interrupts
|
|
|
|
asm volatile("sti\n");
|
|
|
|
int count = 0;
|
|
|
|
while (1) {
|
|
|
|
printIntDetails(count++, GREEN, BLACK, 0, VGA_HEIGHT - 1);
|
|
|
|
}
|
|
|
|
printString("exiting\n");
|
|
|
|
}
|