This commit is contained in:
2025-05-28 14:41:02 -05:00
commit 6d366537dd
73 changed files with 4448 additions and 0 deletions

15
kernel/boot.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdint.h>
#include <string.h>
#include <kernel/boot.h>
uint8_t parse_boot_data(const char* data)
{
if (strlen(data) == 0)
{
return 0;
}
return 0;
}

72
kernel/intro_anim.c Normal file
View File

@ -0,0 +1,72 @@
#include <string.h>
#include <tty.h>
#include <stdio.h>
#include <port_io.h>
#include <kernel/intro_anim.h>
void delay_us(uint32_t microseconds, uint32_t cpu_mhz) {
uint32_t count = cpu_mhz * microseconds;
while (count--) {
asm volatile ("nop" ::: "memory");
}
}
int16_t begin_anim(const char* version)
{
if (strlen(version) < 5)
{
return -1;
}
const char* e = "Espresso";
const char* v = version;
const char* n = "Press any key to continue";
int32_t pos = 0;
int32_t v_pos = 0;
int16_t b = 0;
int32_t sh_pos = VGA_WIDTH / 2;
int32_t sv_pos = VGA_HEIGHT / 2;
while (true)
{
terminal_clear();
for (int32_t i = 0; n[i]; ++i)
{
terminal_putentryat(n[i], terminal_getcolor(), sh_pos, sv_pos);
sh_pos++;
}
for (int32_t i = 0; e[i]; ++i)
{
terminal_putentryat(e[i], terminal_getcolor(), pos + i, v_pos);
}
if ((v_pos + 1) == VGA_HEIGHT)
{
v_pos = 0;
b = 1;
}
for (int32_t i = 0; v[i]; ++i)
{
terminal_putentryat(v[i], terminal_getcolor(), pos + i + 3, (b == 0 ? (v_pos + 1) : v_pos));
}
pos += 2;
v_pos++;
sh_pos = VGA_WIDTH / 2;
b = 0;
delay_us(50000, 5000);
}
terminal_clear();
return 0;
}

137
kernel/kernel.c Normal file
View File

@ -0,0 +1,137 @@
/* 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>
#include <idt.h>
#include <multiboot.h>
#include <stdio.h>
#include <drivers/pci.h>
#include <drivers/ps2_keyboard.h>
//#include <drivers/ahci.h>
#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>
#include <kernel/intro_anim.h>
#define DEBUG
/*extern HBA_MEM *abar;
extern HBA_PORT *ahci_port;*/
extern void _hang_asm(void);
void kernel_main(multiboot_info_t* mbd, unsigned int magic)
{
/* --- BEGIN INITIALIZATION SECTION --- */
/* We need to initialize the terminal so that any error/debuging messages show. */
terminal_initialize();
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();
}
gdt_install();
pic_remap();
idt_install_isrs();
idt_install();
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");
}
/*
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");
printd("Initializing DuckFS...\n");
int32_t duckfs_init_rv = duckfs_init(0);
printf("[ DEBUG ] DuckFS initialized with RV %d\n", duckfs_init_rv);
/* --- END INITIALIZATION SECTION --- */
terminal_setcolor(VGA_COLOR_LIGHT_GREEN);
const char* espresso_kernel_version = "0.0.0b";
printf("Loading Espresso %s...\n", espresso_kernel_version);
/*begin_anim(espresso_kernel_version);*/
printf("Hello and welcome to Espresso\n");
_hang_asm();
}

10
kernel/syscalls.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
#include <kernel/syscalls.h>
int16_t syscall_write(int32_t fd, const void* buffer, int32_t length)
{
return -1;
}