2019-07-08 12:56:36 +02:00
|
|
|
/**************************************
|
2021-01-02 17:49:15 +01:00
|
|
|
* VulcanOS Kernel *
|
2019-07-08 12:56:36 +02:00
|
|
|
* Developed by Marco 'icebit' Cetica *
|
2021-01-02 17:49:15 +01:00
|
|
|
* (c) 2019-2021 *
|
2019-07-08 12:56:36 +02:00
|
|
|
* Released under GPLv3 *
|
|
|
|
* https://github.com/ice-bit/iceOS *
|
|
|
|
***************************************/
|
2019-07-03 18:12:57 +02:00
|
|
|
#include "drivers/tty.h"
|
2019-07-04 12:49:53 +02:00
|
|
|
#include "drivers/gdt.h"
|
2019-07-05 18:25:58 +02:00
|
|
|
#include "drivers/idt.h"
|
2019-07-06 01:09:10 +02:00
|
|
|
#include "drivers/timer.h"
|
2019-07-08 18:43:45 +02:00
|
|
|
#include "drivers/keyboard.h"
|
2019-09-28 12:11:43 +02:00
|
|
|
#include "mem/paging.h"
|
|
|
|
#include "mem/kheap.h"
|
2021-01-05 18:43:59 +01:00
|
|
|
#include "mem/multiboot.h"
|
2021-01-02 17:49:15 +01:00
|
|
|
#include "userspace/shell.h"
|
2019-07-08 20:36:53 +02:00
|
|
|
#include "libc/stdio.h"
|
2021-01-05 18:43:59 +01:00
|
|
|
#include "libc/panic.h"
|
2019-07-03 18:12:57 +02:00
|
|
|
|
2019-09-24 18:32:38 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2020-08-24 01:12:39 +02:00
|
|
|
#define PRTOK printf("\n["); printf_color(" OK ", LIGHT_GREEN, BLACK); printf("]"); // Ugly hack to print "[ OK ]"
|
|
|
|
#define PRTAT printf("\n["); printf_color(" ** ", LIGHT_BROWN, BLACK); printf("]"); // Ugly hack to print "[ * ]"
|
2021-01-05 18:43:59 +01:00
|
|
|
#define PRTER printf("\n["); printf_color(" ERR ", LIGHT_RED, BLACK); printf("]"); // Ugly hack to print "[ ER ]"
|
2020-08-24 01:12:39 +02:00
|
|
|
|
2019-07-08 20:36:53 +02:00
|
|
|
|
2021-01-05 18:43:59 +01:00
|
|
|
void kernel_main(unsigned long magic, uint32_t addr) {
|
|
|
|
// First of all, check if we're booted by a Multiboot-compliant boot loader
|
|
|
|
if(magic != MULTIBOOT2_BOOTLOADER_MAGIC) {
|
|
|
|
PRTER
|
|
|
|
printf(" - Invalid magic number: %x\n", (unsigned)magic);
|
|
|
|
PANIC("Invalid multiboot magic number");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr & 7) {
|
|
|
|
PRTER
|
|
|
|
printf(" - Unaligned mbi: %x\n", addr);
|
|
|
|
PANIC("Unaligned multiboot MBI");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
printf("Loading kernel, wait please...");
|
|
|
|
|
2019-07-04 12:49:53 +02:00
|
|
|
gdt_setup(); // Setup Global Descriptor Table
|
2020-08-24 01:12:39 +02:00
|
|
|
PRTOK
|
|
|
|
printf(" - Loaded GDT");
|
2019-07-08 20:36:53 +02:00
|
|
|
|
2019-07-05 18:25:58 +02:00
|
|
|
idt_setup(); // Setup Interrupt Descriptor Table
|
2020-08-24 01:12:39 +02:00
|
|
|
PRTOK
|
|
|
|
printf(" - Loaded IDT");
|
2019-07-08 20:36:53 +02:00
|
|
|
|
|
|
|
init_timer(1); // Initialize PIT driver
|
2020-08-24 01:12:39 +02:00
|
|
|
PRTOK
|
|
|
|
printf(" - Loaded PIT");
|
2019-07-03 18:12:57 +02:00
|
|
|
|
2019-07-08 20:36:53 +02:00
|
|
|
init_keyboard(); // Initialize keyboard driver
|
2020-08-24 01:12:39 +02:00
|
|
|
PRTOK
|
|
|
|
printf(" - Loaded PS/2 driver");
|
2019-09-28 12:11:43 +02:00
|
|
|
|
2019-09-28 17:42:47 +02:00
|
|
|
init_paging(); // Initialize paging
|
2020-08-24 01:12:39 +02:00
|
|
|
PRTOK
|
|
|
|
printf(" - Loaded Paging");
|
2019-07-08 20:36:53 +02:00
|
|
|
|
2020-08-24 01:12:39 +02:00
|
|
|
PRTAT
|
|
|
|
printf(" - Testing heap...\t");
|
2019-09-28 17:42:47 +02:00
|
|
|
|
|
|
|
uint32_t x = kmalloc(32), y = kmalloc(32);
|
|
|
|
printf("x: %x, y: %x", x, y);
|
|
|
|
kfree((void*)y);
|
|
|
|
uint32_t z = kmalloc(8);
|
2020-08-24 01:12:39 +02:00
|
|
|
printf(", z: %x", z); // If z is equal to y, heap's anti-fragmentation algorithm works
|
2019-09-28 17:42:47 +02:00
|
|
|
ASSERT(z == y);
|
|
|
|
kfree((void*)z), kfree((void*)x);
|
|
|
|
|
2020-08-24 01:12:39 +02:00
|
|
|
PRTOK
|
2020-08-24 01:16:32 +02:00
|
|
|
printf(" - Heap works!");
|
2021-01-05 18:43:59 +01:00
|
|
|
|
2019-07-06 00:32:41 +02:00
|
|
|
init_prompt(); // Initialize frame buffer
|
2020-08-17 17:57:06 +02:00
|
|
|
}
|