From bfa3d5b0337eac77f6aadde5c91197ade1eb67b0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 19:46:18 +0000 Subject: [PATCH] Remove console module entirely Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- kernel/include/kernel/console.h | 31 ------- kernel/src/core/console.c | 102 --------------------- kernel/src/main.c | 24 +---- tests/unit/test_console.c | 156 -------------------------------- 4 files changed, 2 insertions(+), 311 deletions(-) delete mode 100644 kernel/include/kernel/console.h delete mode 100644 kernel/src/core/console.c delete mode 100644 tests/unit/test_console.c diff --git a/kernel/include/kernel/console.h b/kernel/include/kernel/console.h deleted file mode 100644 index 8465e48..0000000 --- a/kernel/include/kernel/console.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef METALOS_KERNEL_CONSOLE_H -#define METALOS_KERNEL_CONSOLE_H - -#include - -// Simple framebuffer console for early boot messages - -typedef struct { - uint32_t* framebuffer; - uint32_t width; - uint32_t height; - uint32_t pitch; - uint32_t x; - uint32_t y; - uint32_t fg_color; - uint32_t bg_color; -} Console; - -// Initialize console with framebuffer -void console_init(uint32_t* fb, uint32_t width, uint32_t height, uint32_t pitch); - -// Print functions -void console_putchar(char c); -void console_print(const char* str); -void console_println(const char* str); -void console_clear(void); - -// Set colors (RGB) -void console_set_color(uint32_t fg, uint32_t bg); - -#endif // METALOS_KERNEL_CONSOLE_H diff --git a/kernel/src/core/console.c b/kernel/src/core/console.c deleted file mode 100644 index 842a4ff..0000000 --- a/kernel/src/core/console.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Simple framebuffer console for kernel messages - * Minimal implementation - just enough for debugging - */ - -#include "kernel/console.h" - -static Console console; - -void console_init(uint32_t* fb, uint32_t width, uint32_t height, uint32_t pitch) { - console.framebuffer = fb; - console.width = width; - console.height = height; - console.pitch = pitch; - console.x = 0; - console.y = 0; - console.fg_color = 0xFFFFFFFF; // White - console.bg_color = 0x00000000; // Black -} - -void console_clear(void) { - if (!console.framebuffer) return; - - for (uint32_t y = 0; y < console.height; y++) { - for (uint32_t x = 0; x < console.width; x++) { - console.framebuffer[y * (console.pitch / 4) + x] = console.bg_color; - } - } - - console.x = 0; - console.y = 0; -} - -void console_set_color(uint32_t fg, uint32_t bg) { - console.fg_color = fg; - console.bg_color = bg; -} - -// Draw a simple 8x8 character (simplified version) -static void draw_char(char c, uint32_t x, uint32_t y) { - if (!console.framebuffer) return; - if (x + 8 > console.width || y + 8 > console.height) return; - - // For simplicity, just draw a simple pattern based on character - // In a real implementation, we'd use the font bitmap - for (int cy = 0; cy < 8; cy++) { - for (int cx = 0; cx < 8; cx++) { - uint32_t pixel_x = x + cx; - uint32_t pixel_y = y + cy; - - // Simple algorithm: draw pixels based on char value - // This creates a unique pattern for each character - uint8_t pattern = (c + cy) & (1 << cx) ? 0xFF : 0x00; - - uint32_t color = pattern ? console.fg_color : console.bg_color; - console.framebuffer[pixel_y * (console.pitch / 4) + pixel_x] = color; - } - } -} - -void console_putchar(char c) { - if (!console.framebuffer) return; - - if (c == '\n') { - console.x = 0; - console.y += 8; - if (console.y >= console.height) { - console.y = 0; // Wrap around (simplified scrolling) - } - return; - } - - if (c == '\r') { - console.x = 0; - return; - } - - draw_char(c, console.x, console.y); - console.x += 8; - - if (console.x >= console.width) { - console.x = 0; - console.y += 8; - if (console.y >= console.height) { - console.y = 0; // Wrap around - } - } -} - -void console_print(const char* str) { - if (!str) return; - - while (*str) { - console_putchar(*str); - str++; - } -} - -void console_println(const char* str) { - console_print(str); - console_putchar('\n'); -} diff --git a/kernel/src/main.c b/kernel/src/main.c index b981669..59f1897 100644 --- a/kernel/src/main.c +++ b/kernel/src/main.c @@ -7,7 +7,6 @@ */ #include "kernel/kernel.h" -#include "kernel/console.h" /* * Kernel main entry point @@ -17,55 +16,36 @@ * Just set up hardware and jump to the QT6 app. */ void kernel_main(BootInfo* boot_info) { - // Initialize basic console output using framebuffer - console_init( - (uint32_t*)boot_info->framebuffer_base, - boot_info->framebuffer_width, - boot_info->framebuffer_height, - boot_info->framebuffer_pitch - ); - - console_clear(); - console_print("MetalOS v0.1 - MINIMAL\n"); - console_print("======================\n\n"); + // Suppress unused parameter warning + (void)boot_info; // TODO: Set up minimal page tables (identity mapped or simple offset) - console_print("[ ] Memory (identity map)\n"); // TODO: Set up IDT with only interrupts we need: // - Keyboard/mouse (USB or PS/2) // - Timer (for QT event loop) // - GPU (if needed) // That's it! Maybe 5 interrupt handlers total. - console_print("[ ] Interrupts (minimal)\n"); // TODO: Simple memory allocator (bump allocator is fine) - console_print("[ ] Heap (bump allocator)\n"); // TODO: Find RX 6600 GPU via PCI (hardcode vendor/device ID) - console_print("[ ] PCI (find GPU only)\n"); // TODO: Initialize GPU - minimal // - Enable BAR // - Init display pipeline // - Set up framebuffer at 1920x1080 (hardcoded) - console_print("[ ] GPU (RX 6600, 1920x1080)\n"); // TODO: Initialize input // Try PS/2 first (simpler!) // Fall back to minimal USB XHCI if needed - console_print("[ ] Input (PS/2 or USB)\n"); // TODO: Jump directly to QT6 Hello World app // No shell, no init, no fork/exec // Just: jump to application entry point - console_print("[ ] Jump to QT6 app\n"); - - console_print("\nBooting app...\n"); // TODO: Replace this with jump to QT6 app // For now, halt - console_print("ERROR: App not linked yet\n"); while(1) { __asm__ volatile("hlt"); diff --git a/tests/unit/test_console.c b/tests/unit/test_console.c deleted file mode 100644 index 00e519c..0000000 --- a/tests/unit/test_console.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Unit tests for console module - * Tests console initialization, color setting, and basic operations - */ - -#include "test_framework.h" -#include -#include -#include - -// Mock console structure (matching kernel/console.h) -typedef struct { - uint32_t* framebuffer; - uint32_t width; - uint32_t height; - uint32_t pitch; - uint32_t x; - uint32_t y; - uint32_t fg_color; - uint32_t bg_color; -} Console; - -// Simplified console functions for unit testing -// In real implementation, these would be in a testable module -static Console test_console; - -void mock_console_init(uint32_t* fb, uint32_t width, uint32_t height, uint32_t pitch) { - test_console.framebuffer = fb; - test_console.width = width; - test_console.height = height; - test_console.pitch = pitch; - test_console.x = 0; - test_console.y = 0; - test_console.fg_color = 0xFFFFFFFF; // White - test_console.bg_color = 0x00000000; // Black -} - -void mock_console_set_color(uint32_t fg, uint32_t bg) { - test_console.fg_color = fg; - test_console.bg_color = bg; -} - -void mock_console_clear(void) { - if (!test_console.framebuffer) return; - - for (uint32_t y = 0; y < test_console.height; y++) { - for (uint32_t x = 0; x < test_console.width; x++) { - test_console.framebuffer[y * (test_console.pitch / 4) + x] = test_console.bg_color; - } - } - - test_console.x = 0; - test_console.y = 0; -} - -// Test: Console initialization -TEST(console_init) { - uint32_t* test_framebuffer = malloc(1920 * 1080 * sizeof(uint32_t)); - ASSERT_NOT_NULL(test_framebuffer); - - mock_console_init(test_framebuffer, 1920, 1080, 1920 * 4); - - ASSERT_NOT_NULL(test_console.framebuffer); - ASSERT_EQ(test_console.width, 1920); - ASSERT_EQ(test_console.height, 1080); - ASSERT_EQ(test_console.pitch, 1920 * 4); - ASSERT_EQ(test_console.x, 0); - ASSERT_EQ(test_console.y, 0); - ASSERT_EQ(test_console.fg_color, 0xFFFFFFFF); - ASSERT_EQ(test_console.bg_color, 0x00000000); - - free(test_framebuffer); - TEST_PASS(); -} - -// Test: Console color setting -TEST(console_set_color) { - uint32_t* test_framebuffer = malloc(1920 * 1080 * sizeof(uint32_t)); - ASSERT_NOT_NULL(test_framebuffer); - - mock_console_init(test_framebuffer, 1920, 1080, 1920 * 4); - - mock_console_set_color(0xFF0000FF, 0x00FF00FF); - - ASSERT_EQ(test_console.fg_color, 0xFF0000FF); - ASSERT_EQ(test_console.bg_color, 0x00FF00FF); - - free(test_framebuffer); - TEST_PASS(); -} - -// Test: Console clear operation -TEST(console_clear) { - uint32_t* test_framebuffer = malloc(800 * 600 * sizeof(uint32_t)); - ASSERT_NOT_NULL(test_framebuffer); - - mock_console_init(test_framebuffer, 800, 600, 800 * 4); - mock_console_set_color(0xFFFFFFFF, 0x00112233); - - // Set some position - test_console.x = 100; - test_console.y = 200; - - mock_console_clear(); - - // Check that position is reset - ASSERT_EQ(test_console.x, 0); - ASSERT_EQ(test_console.y, 0); - - // Check that first few pixels are background color - ASSERT_EQ(test_framebuffer[0], 0x00112233); - ASSERT_EQ(test_framebuffer[1], 0x00112233); - ASSERT_EQ(test_framebuffer[10], 0x00112233); - - free(test_framebuffer); - TEST_PASS(); -} - -// Test: Console with NULL framebuffer (edge case) -TEST(console_null_framebuffer) { - mock_console_init(NULL, 1920, 1080, 1920 * 4); - - ASSERT_NULL(test_console.framebuffer); - - // Clear should handle NULL gracefully (no crash) - mock_console_clear(); - - TEST_PASS(); -} - -// Test: Console with small dimensions -TEST(console_small_dimensions) { - uint32_t* test_framebuffer = malloc(64 * 48 * sizeof(uint32_t)); - ASSERT_NOT_NULL(test_framebuffer); - - mock_console_init(test_framebuffer, 64, 48, 64 * 4); - - ASSERT_EQ(test_console.width, 64); - ASSERT_EQ(test_console.height, 48); - - free(test_framebuffer); - TEST_PASS(); -} - -// Main test runner -int main(void) { - test_init("Console Module"); - - RUN_TEST(console_init); - RUN_TEST(console_set_color); - RUN_TEST(console_clear); - RUN_TEST(console_null_framebuffer); - RUN_TEST(console_small_dimensions); - - return test_summary(); -}