This commit is contained in:
nub31
2025-09-03 13:13:16 +02:00
parent c338e05648
commit 87d1a291f7
26 changed files with 353 additions and 287 deletions

View File

@@ -1,105 +1,9 @@
#include "kernel.h"
#include "arch/x86_64/interrupts.h"
#include "arch/x86_64/multiboot.h"
#include "arch/x86_64/pmm.h"
#include "string.h"
#include "vga.h"
#include <stdarg.h>
#include "pmm.h"
#include <stdio.h>
void kmain(multiboot_info_t* mbd)
void kmain()
{
vga_clear();
init_pmm(mbd);
remap_pic();
enable_interrupts();
init_pmm();
printf("Welcome to nub OS :)\n");
halt();
}
void panic()
{
printf("Kernel panic!\n");
disable_interrupts();
halt();
}
void printf(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
bool should_format = false;
for (size_t i = 0; fmt[i] != '\0'; i++)
{
if (should_format)
{
should_format = false;
if (fmt[i] == '%')
{
vga_put_char('%', VGA_DEFAULT_COLOR);
}
else if (fmt[i] == 's')
{
const char* str = va_arg(args, const char*);
for (size_t j = 0; str[j] != '\0'; j++)
{
vga_put_char(str[j], VGA_DEFAULT_COLOR);
}
}
else if (fmt[i] == 'c')
{
char character = (char)va_arg(args, int64_t);
vga_put_char(character, VGA_DEFAULT_COLOR);
}
else if (fmt[i] == 'd')
{
int64_t val = va_arg(args, int64_t);
char buf[21];
itoa64(val, buf);
for (size_t j = 0; buf[j] != '\0'; j++)
{
vga_put_char(buf[j], VGA_DEFAULT_COLOR);
}
}
else if (fmt[i] == 'u')
{
uint64_t val = va_arg(args, uint64_t);
char buf[21];
uitoa64(val, buf);
for (size_t j = 0; buf[j] != '\0'; j++)
{
vga_put_char(buf[j], VGA_DEFAULT_COLOR);
}
}
else if (fmt[i] == 'x')
{
uint64_t val = va_arg(args, uint64_t);
char buf[17];
uitoa64_hex(val, buf);
for (size_t j = 0; buf[j] != '\0'; j++)
{
vga_put_char(buf[j], VGA_DEFAULT_COLOR);
}
}
else
{
vga_put_char(fmt[i], VGA_DEFAULT_COLOR);
}
}
else if (fmt[i] == '%')
{
should_format = true;
}
else
{
vga_put_char(fmt[i], VGA_DEFAULT_COLOR);
}
}
va_end(args);
}