Files
Espresso/kernel/kernel.c

157 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
2025-07-01 20:39:38 -05:00
#include <types.h>
2025-05-28 14:41:02 -05:00
#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-07-01 20:39:38 -05:00
#include <drivers/irq.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-17 15:50:07 -05:00
#include <drivers/pit.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/fat32.h>
#include <fs/duckfs.h>
2025-06-17 15:50:07 -05:00
#include <fs/vfs.h>
2025-07-01 20:39:38 -05:00
#include <fs/sfs.h>
2025-05-28 14:41:02 -05:00
2025-07-01 20:39:38 -05:00
#include <vector_extensions/sse.h>
2025-05-28 14:41:02 -05:00
2025-06-13 18:03:39 -05:00
#include <kernel/intro.h>
2025-05-28 14:41:02 -05:00
#define DEBUG
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-06-27 14:48:06 -05:00
/* We need to initialize the terminal so that any error/debugging messages show. */
2025-05-28 14:41:02 -05:00
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);
2025-06-27 14:48:06 -05:00
/* Make sure the magic number matches for memory mapping */
2025-05-28 14:41:02 -05:00
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();
_sti_asm();
2025-05-28 14:41:02 -05:00
2025-07-01 20:39:38 -05:00
irq_init(); /* MUST be done after pci_remap() and idt_init() */
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
{
2025-07-01 20:39:38 -05:00
printd("SSE test passed\n");
2025-05-28 14:41:02 -05:00
}
2025-06-17 15:50:07 -05:00
printd("Initializing the PIT...\n");
pit_init();
printd("PIT initialized\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 IDE system...\n");
ide_initialize();
printd("IDE initialized\n");
2025-06-13 18:03:39 -05:00
/*printd("Initializing DuckFS...\n");
2025-06-17 15:50:07 -05:00
duckfs_init();
printd("DuckFS initialized\n");*/
2025-06-13 18:03:39 -05:00
2025-07-01 20:39:38 -05:00
printd("Initializing PCI...\n");
pci_enumerate();
printd("PCI initialized\n");
2025-05-28 14:41:02 -05:00
2025-06-17 15:50:07 -05:00
2025-05-28 14:41:02 -05:00
/* --- END INITIALIZATION SECTION --- */
terminal_setcolor(VGA_COLOR_LIGHT_GREEN);
2025-06-17 15:50:07 -05:00
/*pit_sleep(4000);
begin_anim(espresso_kernel_version);*/
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-07-01 20:39:38 -05:00
/*printf("here\n");
printf("%i\n", sfs_init(false));
printf("here\n");*/
2025-06-27 14:48:06 -05:00
2025-06-13 18:03:39 -05:00
while (true)
{
}
2025-05-28 14:41:02 -05:00
}