working on exposing vga to userspace

This commit is contained in:
2026-07-16 14:44:08 -05:00
parent 37aa46c847
commit b588634253
16 changed files with 251 additions and 139 deletions

View File

@@ -1,5 +1,8 @@
#include "drivers/serial/serial.h"
#include <lib/console.h>
#include <lib/font.h>
#include <lib/print.h>
#include <drivers/vga/vga.h>
@@ -7,10 +10,13 @@ static psf_font_t* font;
static uint32_t console_row;
static uint32_t console_col;
static uint32_t console_width;
static uint32_t console_height;
static uint32_t console_text_color;
static uint32_t console_backgrnd_color;
static void write_vga_char(char c) {
print_serial("write_vga_char invoked\r\n");
uint32_t vga_pitch = vga_get_pitch();
uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->hdr->charsz);
@@ -34,7 +40,14 @@ static void write_vga_char(char c) {
int set_console_font(const char* path) {
font = load_font(path);
return font != NULL;
if (!font) {
return 0;
}
console_width = vga_get_width() / 8;
console_height = vga_get_height() / font->hdr->charsz;
return 1;
}
void set_console_fg(uint32_t color) {
@@ -48,10 +61,35 @@ void set_console_bg(uint32_t color) {
void console_init() {
console_row = 0;
console_col = 0;
set_console_fg(0xFFFFFFFF);
vga_clear_scrn(0x000000FF);
set_console_bg(0xFF6c7482);
vga_clear_scrn(console_backgrnd_color);
}
void console_putchar(char c) {
if (!font) return;
if (c == '\n') {
print_serial("\r\n");
console_col = 0;
console_row++;
if (console_row >= console_height) {
console_row = 0;
}
return;
}
write_serial(c);
write_vga_char(c);
console_col++;
if (console_col >= console_width) {
console_col = 0;
console_row++;
}
if (console_row >= console_height) {
console_row = 0;
}
}

View File

@@ -1,18 +1,22 @@
#include "drivers/serial/serial.h"
#include "vfs.h"
#include <lib/font.h>
#include <lib/memory.h>
#include <lib/print.h>
#include <stddef.h>
psf_font_t* load_font(const char* path) {
int fd = vfs_open(path, 0);
if (fd == -1) {
kprintf("failed to open font file %s\n", path);
return NULL;
}
psf_hdr_t* header = kalloc(sizeof(psf_hdr_t));
int rd = vfs_read(fd, header, sizeof(psf_hdr_t));
if (rd <= 0) {
kprintf("failed to read font header\n");
kfree(header);
return NULL;
}

View File

@@ -1,4 +1,5 @@
#include "print.h"
#include "drivers/serial/serial.h"
#include "stream.h"
#include "tasks.h"
@@ -13,16 +14,21 @@ extern psf_font_t* kfont;
static char* hex_chars = "0123456789abcdef";
static void kwrite(char c) {
write_serial(c);
console_putchar(c);
}
static void kprint(const char *str) {
while (*str) {
console_putchar(*str);
kwrite(*str);
str++;
}
}
static void kputd(int d) {
if (d == 0) {
console_putchar('0');
kwrite('0');
return;
}
char buffer[12];
@@ -32,13 +38,13 @@ static void kputd(int d) {
d /= 10;
}
for (int j = i - 1; j >= 0; j--) {
console_putchar(buffer[j]);
kwrite(buffer[j]);
}
}
static void kputx(unsigned int x) {
if (x == 0) {
console_putchar('0');
kwrite('0');
return;
}
char buffer[8];
@@ -49,13 +55,13 @@ static void kputx(unsigned int x) {
x >>= 4;
}
for (int j = i - 1; j >= 0; j--) {
console_putchar(buffer[j]);
kwrite(buffer[j]);
}
}
void kputc(const char c) {
spin_lock(&kwrite_lock);
console_putchar(c);
kwrite(c);
spin_unlock(&kwrite_lock);
}
@@ -85,20 +91,20 @@ void kprintf(const char* fmt, ...) {
}
case 'c': {
int c = va_arg(args, int);
console_putchar((char)c);
kwrite((char)c);
break;
}
case '%':
console_putchar('%');
kwrite('%');
break;
default:
console_putchar('%');
console_putchar(*fmt);
kwrite('%');
kwrite(*fmt);
break;
}
fmt++;
} else {
console_putchar(*fmt);
kwrite(*fmt);
fmt++;
}
}