This commit is contained in:
2026-07-15 08:07:06 -05:00
parent c77d9e1725
commit 44a0c9aeba
9 changed files with 126 additions and 51 deletions

View File

@@ -18,6 +18,5 @@ cd ..
make clean
cd initrd
rm -rf output
rm -f bin/*.elf
cd ..

View File

@@ -4,6 +4,7 @@
#include <lib/stream.h>
#include <drivers/vga/vga.h>
#include <drivers/serial/serial.h>
#include <common.h>
#include <memory/mm.h>
@@ -15,13 +16,55 @@ static uint32_t framebuffer_total_pixels;
static uint32_t framebuffer_pitch;
static uint32_t framebuffer_bpp;
static uint8_t red_mask_sz;
static uint8_t red_field_pos;
static uint8_t green_mask_sz;
static uint8_t green_field_pos;
static uint8_t blue_mask_sz;
static uint8_t blue_field_pos;
static uint32_t create_pixel(uint8_t r, uint8_t g, uint8_t b) {
return (r >> (8 - red_mask_sz)) << red_field_pos
| (g >> (8 - green_mask_sz)) << green_field_pos
| (b >> (8 - blue_mask_sz)) << blue_field_pos;
}
vga_color_t VGA_COLOR_BLACK = {0, 0, 0, 255};
vga_color_t VGA_COLOR_RED = {0, 0, 255, 255};
vga_color_t VGA_COLOR_GREEN = {0, 255, 0, 255};
vga_color_t VGA_COLOR_BLUE = {255, 0, 0, 255};
void vga_init(
uint32_t fb_paddr,
uint32_t fb_width,
uint32_t fb_height,
uint32_t fb_pitch,
uint8_t fb_bpp
uint8_t fb_bpp,
uint8_t _red_mask_sz,
uint8_t _red_field_pos,
uint8_t _green_mask_sz,
uint8_t _green_field_pos,
uint8_t _blue_mask_sz,
uint8_t _blue_field_pos
) {
framebuffer_address = VGA_FRAMEBUFFER;
red_mask_sz = _red_mask_sz;
red_field_pos = _red_field_pos;
green_mask_sz = _green_mask_sz;
green_field_pos = _green_field_pos;
blue_mask_sz = _blue_mask_sz;
blue_field_pos = _blue_field_pos;
print_serial("initializing vga.\r\n");
print_serial_hex(fb_paddr);
print_serial("\r\n");
print_serial_hex(framebuffer_address);
print_serial("\r\n");
print_serial("BPP: ");
print_serial_hex(fb_bpp);
print_serial("\r\n");
uint32_t fb_size_bytes = fb_height * fb_pitch;
uint32_t num_pages = (fb_size_bytes + 4095) / 4096;
for (uint32_t i = 0; i < num_pages; i++) {
@@ -30,36 +73,58 @@ void vga_init(
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE);
}
framebuffer_address = VGA_FRAMEBUFFER;
framebuffer_width = fb_width;
framebuffer_height = fb_height;
framebuffer_pitch = fb_pitch;
framebuffer_bpp = fb_bpp;
framebuffer_total_pixels = framebuffer_width * framebuffer_height;
vga_clear_scrn(0x000000FF);
framebuffer_pitch = fb_pitch;
framebuffer_bpp = fb_bpp;
vga_clear_scrn(0x00000000);
}
uint32_t vga_get_framebuffer() {
return framebuffer_address;
}
uint32_t vga_get_width() {
return framebuffer_width;
}
uint32_t vga_get_height() {
return framebuffer_height;
}
uint32_t vga_get_pitch() {
return framebuffer_pitch;
}
uint8_t vga_get_bpp() {
return framebuffer_bpp;
}
void vga_clear_scrn(uint32_t color) {
if (framebuffer_address == 0) return;
uint8_t* fb_bytes = (uint8_t*)framebuffer_address;
uint8_t bytes_per_pixel = framebuffer_bpp / 8;
for (uint32_t y = 0; y < framebuffer_height; y++) {
uint32_t* row = (uint32_t*)((uintptr_t)framebuffer_address + (y * framebuffer_pitch));
uint8_t* row = fb_bytes + (y * framebuffer_pitch);
for (uint32_t x = 0; x < framebuffer_width; x++) {
row[x] = color;
}
}
}
void vga_drawchar(char c, int x, int y, psf_font_t* font) {
uint8_t* pixel = row + (x * bytes_per_pixel);
switch(framebuffer_bpp) {
case 32: {
*(uint32_t*)pixel = color;
break;
}
}
}
}
}
uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buf) {
// probably just memcpy here
return size;
}

View File

@@ -4,39 +4,41 @@
#include <vfs.h>
#include <lib/font.h>
#define VGA_FRAMEBUFFER 0xFF700000
#define VGA_FRAMEBUFFER 0xF0000000
enum vga_color {
VGA_COLOR_BLACK = 0,
VGA_COLOR_BLUE = 1,
VGA_COLOR_GREEN = 2,
VGA_COLOR_CYAN = 3,
VGA_COLOR_RED = 4,
VGA_COLOR_MAGENTA = 5,
VGA_COLOR_BROWN = 6,
VGA_COLOR_LIGHT_GREY = 7,
VGA_COLOR_DARK_GREY = 8,
VGA_COLOR_LIGHT_BLUE = 9,
VGA_COLOR_LIGHT_GREEN = 10,
VGA_COLOR_LIGHT_CYAN = 11,
VGA_COLOR_LIGHT_RED = 12,
VGA_COLOR_LIGHT_MAGENTA = 13,
VGA_COLOR_LIGHT_BROWN = 14,
VGA_COLOR_WHITE = 15,
};
typedef struct {
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t a;
} vga_color_t;
extern vga_color_t VGA_COLOR_BLACK;
extern vga_color_t VGA_COLOR_RED;
extern vga_color_t VGA_COLOR_GREEN;
extern vga_color_t VGA_COLOR_BLUE;
void vga_init(
uint32_t fb_paddr,
uint32_t fb_width,
uint32_t fb_height,
uint32_t fb_pitch,
uint8_t fb_bpp
uint8_t fb_bpp,
uint8_t red_mask_sz,
uint8_t red_field_pos,
uint8_t green_mask_sz,
uint8_t green_field_pos,
uint8_t blue_mask_sz,
uint8_t blue_field_pos
);
uint32_t vga_get_framebuffer();
uint32_t vga_get_width();
uint32_t vga_get_height();
uint32_t vga_get_pitch();
uint8_t vga_get_bpp();
void vga_clear_scrn(uint32_t color);
void vga_drawchar(char c, int x, int y, psf_font_t* font);
uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buf);

View File

@@ -12,6 +12,7 @@
#include <lib/print.h>
#include <lib/stream.h>
#include <lib/memory.h>
#include <lib/console.h>
#include <memory/mm.h>
@@ -24,7 +25,6 @@
#include <drivers/cpio/cpio.h>
#include <drivers/devfs/devfs.h>
#include <drivers/serial/serial.h>
#include <drivers/console/console.h>
#include <stddef.h>
#include <stdint.h>
@@ -129,10 +129,20 @@ void kmain(multiboot_info* mbi) {
vga_fb_width,
vga_fb_height,
vga_fb_pitch,
vga_fb_bpp);
vga_fb_bpp,
0, 0, 0, 0, 0, 0);
console_init();
set_console_font("/fonts/cp850-8x16.psf");
int font_loaded = set_console_font("/fonts/cp850-8x16.psf");
if (!font_loaded) {
#ifdef SERIAL_DBG
print_serial("failed to load console font");
#endif
}
console_putchar('c');
return;
kprintf("basic initializations complete\n");

View File

@@ -1,6 +1,6 @@
#include <drivers/console/console.h>
#include <lib/console.h>
#include <lib/font.h>
#include <drivers/vga/vga.h>
static psf_font_t* font;
@@ -10,7 +10,7 @@ static uint32_t console_col;
static uint32_t console_text_color;
static uint32_t console_backgrnd_color;
static void write_vga_char(int row, int col, char c) {
static void write_vga_char(char c) {
uint32_t vga_pitch = vga_get_pitch();
uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->hdr->charsz);
@@ -25,8 +25,9 @@ static void write_vga_char(int row, int col, char c) {
}
}
void set_console_font(const char* path) {
int set_console_font(const char* path) {
font = load_font(path);
return font != NULL;
}
void set_console_fg(uint32_t color) {
@@ -41,9 +42,9 @@ void console_init() {
console_row = 0;
console_col = 0;
set_console_fg(0xFFFFFFFF);
set_console_bg(0x00000000);
vga_clear_scrn(0x00000000);
}
void console_putchar(char c) {
write_vga_char(c);
}

View File

@@ -5,7 +5,7 @@
void console_putchar(char c);
void set_console_font(const char* path);
int set_console_font(const char* path);
void set_console_fg(uint32_t color);
void set_console_bg(uint32_t color);
void console_init();

View File

@@ -5,7 +5,7 @@
#include <stdarg.h>
#include <drivers/vga/vga.h>
#include <drivers/console/console.h>
#include <lib/console.h>
spinlock_t kwrite_lock = {0};

View File

@@ -8,7 +8,5 @@ mkdir -p initrd/bin
cp programs/bin/* initrd/bin
cd initrd
find . -depth -print | cpio -o -H newc > ../initrd.img
find . -depth -print | cpio -o -H newc > ../isodir/boot/initrd.img
cd ..
cp initrd.img isodir/boot

View File

@@ -33,7 +33,7 @@ obj/%.S.o: %.S
$(CC) -c $< -o $@ $(CFLAGS)
run: $(OSNAME).iso
qemu-system-i386 -cdrom $(OSNAME).iso
qemu-system-i386 -device VGA,edid=on -cdrom $(OSNAME).iso
clean:
@echo "Cleaning up build artifacts..."