did some restructuring, got multitasking almost working

This commit is contained in:
2026-06-26 20:05:01 -05:00
parent 57d7d34c6d
commit 43bc0df81a
35 changed files with 481 additions and 307 deletions

View File

@@ -1,20 +1,25 @@
#include "print.h"
#include "stream.h"
#include "tasks.h"
#include <stdarg.h>
extern print_stream_t* kout;
#include <drivers/vga/vga.h>
spinlock_t kwrite_lock = {0};
static char* hex_chars = "0123456789abcdef";
static void kprint(const char *str) {
while (*str) {
kout->putchar(*str);
vga_putchar(*str);
str++;
}
}
static void kputd(int d) {
if (d == 0) {
kout->putchar('0');
vga_putchar('0');
return;
}
char buffer[12];
@@ -24,13 +29,13 @@ static void kputd(int d) {
d /= 10;
}
for (int j = i - 1; j >= 0; j--) {
kout->putchar(buffer[j]);
vga_putchar(buffer[j]);
}
}
static void kputx(unsigned int x) {
if (x == 0) {
kout->putchar('0');
vga_putchar('0');
return;
}
char buffer[8];
@@ -41,15 +46,18 @@ static void kputx(unsigned int x) {
x >>= 4;
}
for (int j = i - 1; j >= 0; j--) {
kout->putchar(buffer[j]);
vga_putchar(buffer[j]);
}
}
void kputc(const char c) {
kout->putchar(c);
spin_lock(&kwrite_lock);
vga_putchar(c);
spin_unlock(&kwrite_lock);
}
void kprintf(const char* fmt, ...) {
spin_lock(&kwrite_lock);
va_list args;
va_start(args, fmt);
@@ -73,19 +81,20 @@ void kprintf(const char* fmt, ...) {
break;
}
case '%':
kout->putchar('%');
vga_putchar('%');
break;
default:
kout->putchar('%');
kout->putchar(*fmt);
vga_putchar('%');
vga_putchar(*fmt);
break;
}
fmt++;
} else {
kout->putchar(*fmt);
vga_putchar(*fmt);
fmt++;
}
}
va_end(args);
spin_unlock(&kwrite_lock);
}