Files
Espresso/kernel/kernel.c

160 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>
2025-10-20 21:57:30 -05:00
#include <stdio.h>
#include <stdlib.h>
2025-05-28 14:41:02 -05:00
#include <kernel/boot.h>
2025-10-20 21:57:30 -05:00
#include <kernel/kshell.h>
#include <kdebug.h>
2025-05-28 14:41:02 -05:00
#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 <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
2025-07-03 20:30:21 -05:00
#include <builtin_games/miner.h>
2025-10-20 21:57:30 -05:00
#include <fs/ssfs.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
2025-07-07 10:41:05 -05:00
char* espresso_str = ""
"####### ##### ###### ###### ####### ##### ##### #######\n"
"# # # # # # # # # # # # # #\n"
"# # # # # # # # # # #\n"
"##### ##### ###### ###### ##### ##### ##### # #\n"
"# # # # # # # # # #\n"
"# # # # # # # # # # # # #\n"
"####### ##### # # # ####### ##### ##### #######\n";
2025-10-20 21:57:30 -05:00
char* kernel_version = "0.0.2a";
2025-05-28 14:41:02 -05:00
2025-07-03 20:30:21 -05:00
void kernel_main(multiboot_info_t* mbd, uint32_t magic)
2025-05-28 14:41:02 -05:00
{
/* --- BEGIN INITIALIZATION SECTION --- */
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-10-20 21:57:30 -05:00
printf("Loading Espresso %s... ", kernel_version);
#ifdef _DEBUG
printf("[ DEBUG BUILD ]");
#endif
printf("\n");
2025-06-13 18:03:39 -05:00
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-10-20 21:57:30 -05:00
2025-06-13 18:03:39 -05:00
idt_init();
2025-10-20 21:57:30 -05:00
2025-06-13 18:03:39 -05:00
_sti_asm();
2025-05-28 14:41:02 -05:00
2025-07-03 20:30:21 -05:00
irq_init(); /* MUST be done after pic_remap() and idt_init() */
2025-07-01 20:39:38 -05:00
2025-05-28 14:41:02 -05:00
terminal_setcolor(VGA_COLOR_GREEN);
2025-10-20 21:57:30 -05:00
2025-05-28 14:41:02 -05:00
pmm_init(mbd);
paging_init();
2025-10-20 21:57:30 -05:00
heap_init(0xC2000000, 0x80000);
2025-05-28 14:41:02 -05:00
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
pit_init();
2025-06-13 19:53:54 -05:00
keyboard_init();
2025-05-28 14:41:02 -05:00
ide_initialize();
2025-06-13 18:03:39 -05:00
2025-10-20 21:57:30 -05:00
pci_init();
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);
2025-10-20 21:57:30 -05:00
begin_anim(kernel_version);*/
2025-06-17 15:50:07 -05:00
2025-10-20 21:57:30 -05:00
printf("Guten tag and welcome to Espresso %s\n", kernel_version);
2025-07-01 20:39:38 -05:00
2025-10-20 21:57:30 -05:00
sleep(1000);
2025-07-01 20:39:38 -05:00
2025-10-20 21:57:30 -05:00
intro_begin();
/*extern void terminal_clear(void);
2025-06-27 14:48:06 -05:00
2025-10-20 21:57:30 -05:00
terminal_clear();
kshell_start(1, NULL);*/
2025-07-03 20:30:21 -05:00
2025-06-13 18:03:39 -05:00
while (true)
{
2025-07-07 10:41:05 -05:00
/* Loop infinitely. We only do something when a syscall happens now. */
2025-06-13 18:03:39 -05:00
}
2025-05-28 14:41:02 -05:00
}