Files
Espresso/kernel/kernel.c

154 lines
3.3 KiB
C
Raw Normal View History

2025-05-28 14:41:02 -05:00
/* Check if the compiler thinks you are targeting the wrong operating system. */
#if defined(__linux__)
#error "You are not using a cross-compiler, you will most certainly run into trouble"
#endif
/* This tutorial will only work for the 32-bit ix86 targets. */
#if !defined(__i386__)
#error "This kernel needs to be compiled with a ix86-elf compiler"
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <kernel/boot.h>
#include <panic.h>
#include <gdt.h>
2025-06-13 18:03:39 -05:00
#include <drivers/idt.h>
2025-05-28 14:41:02 -05:00
#include <multiboot.h>
#include <stdio.h>
#include <drivers/pci.h>
#include <drivers/ps2_keyboard.h>
2025-06-13 18:03:39 -05:00
/*#include <drivers/ahci.h>*/
2025-05-28 14:41:02 -05:00
#include <drivers/ide.h>
#include <mm/mm.h>
#include <fs/ramfs.h>
#include <fs/fat32.h>
#include <fs/duckfs.h>
#include <vector_extentions/sse.h>
2025-06-13 18:03:39 -05:00
#include <kernel/intro.h>
2025-05-28 14:41:02 -05:00
#define DEBUG
/*extern HBA_MEM *abar;
extern HBA_PORT *ahci_port;*/
extern void _hang_asm(void);
2025-06-13 18:03:39 -05:00
extern void _sti_asm(void);
2025-05-28 14:41:02 -05:00
void kernel_main(multiboot_info_t* mbd, unsigned int magic)
{
/* --- BEGIN INITIALIZATION SECTION --- */
2025-06-13 19:53:54 -05:00
const char* espresso_kernel_version = "0.0.0f";
2025-06-13 18:03:39 -05:00
2025-05-28 14:41:02 -05:00
/* We need to initialize the terminal so that any error/debuging messages show. */
terminal_initialize();
2025-06-13 18:03:39 -05:00
printf("Loading Espresso %s...\n", espresso_kernel_version);
2025-05-28 14:41:02 -05:00
terminal_setcolor(VGA_COLOR_RED);
/* Make sure the magic number matches for memory mapping*/
if(magic != MULTIBOOT_BOOTLOADER_MAGIC)
{
printf("[ ERROR ] invalid magic number!\n");
_hang_asm();
}
/* Check bit 6 to see if we have a valid memory map */
if(!(mbd->flags >> 6 & 0x1))
{
printf("[ ERROR ] invalid memory map given by GRUB bootloader\n");
_hang_asm();
}
2025-06-13 18:03:39 -05:00
gdt_install(false);
2025-05-28 14:41:02 -05:00
pic_remap();
2025-06-13 18:03:39 -05:00
idt_init();
/*pit_init(1000); 1000 Hz = 1ms tick */
_sti_asm();
2025-05-28 14:41:02 -05:00
terminal_setcolor(VGA_COLOR_GREEN);
printd("Initializing physical memory manager...\n");
pmm_init(mbd);
printd("Physical memory manager initialized\n");
printd("Initializing paging...\n");
paging_init();
printd("Paging initialized\n");
printd("Initializing heap allocator...\n");
heap_init();
printd("Heap allocator initialized\n");
printd("Testing SSE...\n");
int32_t sse_test_result = test_sse();
if (sse_test_result != 0)
{
printf("[ DEBUG ] SSE test failed with RV %d\n", sse_test_result);
}
else
{
printd("SSE test succeeded\n");
}
2025-06-13 19:53:54 -05:00
printd("Initializing the PS/2 keyboard...\n");
keyboard_init();
printd("PS/2 Keyboard initialized\n");
2025-05-28 14:41:02 -05:00
/*
printd("Initalizing AHCI...\n");
ahci_init();
printd("AHCI initialized\n");
*/
/*printd("Initializing RAMFS...\n");
ramfs_init();
printd("RAMFS initialized.\n");*/
printd("Initializing IDE system...\n");
ide_initialize();
printd("IDE initialized\n");
2025-06-13 18:03:39 -05:00
/*printd("Initializing DuckFS...\n");
2025-05-28 14:41:02 -05:00
int32_t duckfs_init_rv = duckfs_init(0);
2025-06-13 18:03:39 -05:00
printf("[ DEBUG ] DuckFS initialized with RV %d\n", duckfs_init_rv);*/
/*printd("Initializing FAT32...\n");
fat32_init(0);
printd("FAT32 initialized\n");*/
2025-05-28 14:41:02 -05:00
2025-06-13 18:03:39 -05:00
/*printd("Initializing the PIT...\n");
pit_init(1000);
printd("PIT initialized\n");*/
2025-05-28 14:41:02 -05:00
/* --- END INITIALIZATION SECTION --- */
terminal_setcolor(VGA_COLOR_LIGHT_GREEN);
2025-06-13 18:03:39 -05:00
/*sleep(1000);*/
2025-05-28 14:41:02 -05:00
2025-06-13 19:53:54 -05:00
//begin_anim(espresso_kernel_version);
2025-05-28 14:41:02 -05:00
2025-06-13 18:03:39 -05:00
printf("Guten tag and welcome to Espresso\n");
2025-05-28 14:41:02 -05:00
2025-06-13 18:03:39 -05:00
while (true)
{
}
2025-05-28 14:41:02 -05:00
}