diff --git a/arch/x86_64/boot.s b/arch/x86_64/boot.s index a3a260d..7e3fa7d 100644 --- a/arch/x86_64/boot.s +++ b/arch/x86_64/boot.s @@ -26,13 +26,13 @@ multiboot2_header: .long MB2_LENGTH .long MB2_CHECKSUM - /* Framebuffer Request Tag (Type 5) - Requests UEFI GOP / VBE 1024x768 @ 32bpp */ + /* Framebuffer Request Tag (Type 5) - Requests UEFI GOP / VBE native @ 32bpp */ .align 8 .short 5 /* type = 5 (Framebuffer) */ - .short 1 /* flags = 1 (Optional, safe on all firmware) */ + .short 0 /* flags = 0 (Required graphics mode) */ .long 20 /* size = 20 bytes */ - .long 1024 /* width = 1024 */ - .long 768 /* height = 768 */ + .long 0 /* width = 0 (no preference / native panel) */ + .long 0 /* height = 0 (no preference / native panel) */ .long 32 /* depth = 32bpp */ /* End tag */ @@ -122,6 +122,21 @@ map_pd_loop: cmpl $4096, %ecx jne map_pd_loop + /* Identity map entries 8..511 of PDPT using 1GB huge pages (8GB .. 512GB) */ + movl $8, %ecx +map_1gb_loop: + movl %ecx, %eax + shll $30, %eax + orl $0x83, %eax /* Present + Writable + Huge 1GB Page (bit 7) */ + movl %ecx, %edx + shrl $2, %edx + movl $pdpt_table, %ebx + movl %eax, (%ebx, %ecx, 8) + movl %edx, 4(%ebx, %ecx, 8) + incl %ecx + cmpl $512, %ecx + jne map_1gb_loop + /* Load CR3 with physical address of PML4 */ movl $pml4_table, %eax movl %eax, %cr3 diff --git a/drivers/font.c b/drivers/font.c index 1d56ce6..27ad82f 100644 --- a/drivers/font.c +++ b/drivers/font.c @@ -100,6 +100,11 @@ static const uint8_t s_font8x16[95][16] = { {0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} /* '~' */ }; +const uint8_t* font_get_glyph(char c) { + if (c < 32 || c > 126) c = '?'; + return s_font8x16[(uint8_t)c - 32]; +} + void font_draw_char(uint32_t x, uint32_t y, char c, uint32_t color) { if (c < 32 || c > 126) c = '?'; const uint8_t* glyph = s_font8x16[(uint8_t)c - 32]; diff --git a/drivers/rtc.c b/drivers/rtc.c index 3552887..5a313a7 100644 --- a/drivers/rtc.c +++ b/drivers/rtc.c @@ -20,8 +20,9 @@ void rtc_init(void) { rtc_time_t rtc_get_time(void) { rtc_time_t t; - /* Wait if RTC update in progress */ - while (cmos_read(0x0A) & 0x80) {} + /* Wait if RTC update in progress (guarded by safety timeout) */ + uint32_t timeout = 50000; + while ((cmos_read(0x0A) & 0x80) && --timeout > 0) {} t.second = cmos_read(0x00); t.minute = cmos_read(0x02); diff --git a/drivers/serial.c b/drivers/serial.c index d77fe1c..a7856c3 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -1,7 +1,22 @@ #include #include +static bool s_com1_present = false; + void serial_init(void) { + /* Test if COM1 actually exists using UART scratch register (offset +7) */ + outb(COM1_PORT + 7, 0x55); + if (inb(COM1_PORT + 7) != 0x55) { + s_com1_present = false; + return; + } + outb(COM1_PORT + 7, 0xAA); + if (inb(COM1_PORT + 7) != 0xAA) { + s_com1_present = false; + return; + } + + s_com1_present = true; outb(COM1_PORT + 1, 0x00); /* Disable all interrupts */ outb(COM1_PORT + 3, 0x80); /* Enable DLAB (set baud rate divisor) */ outb(COM1_PORT + 0, 0x01); /* Set divisor to 1 (115200 baud) */ @@ -16,12 +31,17 @@ static inline bool is_transmit_empty(void) { } void serial_putchar(char c) { - while (!is_transmit_empty()) {} - outb(COM1_PORT, c); + if (!s_com1_present) return; + + uint32_t timeout = 50000; + while (!is_transmit_empty() && --timeout > 0) {} + if (timeout > 0) { + outb(COM1_PORT, c); + } } void serial_puts(const char* str) { - if (!str) return; + if (!s_com1_present || !str) return; while (*str) { if (*str == '\n') { serial_putchar('\r'); diff --git a/drivers/vbe.c b/drivers/vbe.c index 105018b..324c817 100644 --- a/drivers/vbe.c +++ b/drivers/vbe.c @@ -1,10 +1,13 @@ #include +#include #include #include #include static vbe_screen_t s_screen; static bool s_is_hardware = false; +static uint32_t s_console_x = 24; +static uint32_t s_console_y = 60; /* Static fallback buffer (1024 x 768 @ 32bpp) */ #define VBE_MAX_PIXELS (1024 * 768) @@ -15,8 +18,8 @@ bool vbe_is_hardware_framebuffer(void) { } void vbe_set_physical_framebuffer(uint64_t addr, uint32_t width, uint32_t height, uint32_t pitch, uint32_t bpp) { - if (width > 1920) width = 1920; - if (height > 1080) height = 1080; + if (width > 2560) width = 2560; + if (height > 1440) height = 1440; if (width == 0) width = 1024; if (height == 0) height = 768; @@ -27,16 +30,138 @@ void vbe_set_physical_framebuffer(uint64_t addr, uint32_t width, uint32_t height /* Point front_buffer directly to physical GPU MMIO memory */ s_screen.front_buffer = (uint32_t*)addr; - s_screen.back_buffer = (uint32_t*)kmalloc(width * height * sizeof(uint32_t)); - if (!s_screen.back_buffer) { - s_screen.back_buffer = s_pixel_buffer; - } + s_screen.back_buffer = s_pixel_buffer; s_screen.initialized = true; s_is_hardware = true; +} - printk(KERN_INFO "vbe: Physical UEFI GOP Framebuffer mapped at 0x%lx (%ux%u, pitch: %u)\n", - addr, width, height, s_screen.pitch); +void vbe_allocate_backbuffer(void) { + if (!s_screen.initialized) return; + uint32_t total_pixels = s_screen.width * s_screen.height; + uint32_t* new_buf = (uint32_t*)kmalloc(total_pixels * sizeof(uint32_t)); + if (new_buf) { + s_screen.back_buffer = new_buf; + } +} + +void vbe_early_boot_splash(void) { + if (!s_screen.initialized || !s_screen.front_buffer) return; + + /* Fill screen with deep obsidian */ + for (uint32_t y = 0; y < s_screen.height; y++) { + uint8_t* row = ((uint8_t*)s_screen.front_buffer) + (y * s_screen.pitch); + uint32_t* pixels = (uint32_t*)row; + for (uint32_t x = 0; x < s_screen.width; x++) { + pixels[x] = COLOR_OBSIDIAN; + } + } + + /* Draw top status banner */ + const char* banner = " [ AIRLYS SOVEREIGN OS 64-BIT ] - UEFI GOP Linear Framebuffer Active "; + const char* sub = " Founder & CEO: Er. Adam Eehan | Co-Pilot: Sovereign AI Aira 3 Ultra (Engine v3.6) "; + + uint32_t x0 = 24; + for (uint32_t i = 0; banner[i] != '\0'; i++) { + const uint8_t* glyph = font_get_glyph(banner[i]); + for (uint32_t row = 0; row < 16; row++) { + uint8_t line = glyph[row]; + uint8_t* dst_row = ((uint8_t*)s_screen.front_buffer) + ((16 + row) * s_screen.pitch); + uint32_t* p = (uint32_t*)dst_row; + for (uint32_t col = 0; col < 8; col++) { + if ((line >> (7 - col)) & 1) { + p[x0 + col] = COLOR_CYAN_GLOW; + } + } + } + x0 += 8; + } + + x0 = 24; + for (uint32_t i = 0; sub[i] != '\0'; i++) { + const uint8_t* glyph = font_get_glyph(sub[i]); + for (uint32_t row = 0; row < 16; row++) { + uint8_t line = glyph[row]; + uint8_t* dst_row = ((uint8_t*)s_screen.front_buffer) + ((34 + row) * s_screen.pitch); + uint32_t* p = (uint32_t*)dst_row; + for (uint32_t col = 0; col < 8; col++) { + if ((line >> (7 - col)) & 1) { + p[x0 + col] = COLOR_GREEN_OK; + } + } + } + x0 += 8; + } +} + +void vbe_console_clear(void) { + if (!s_screen.initialized || !s_screen.front_buffer) return; + for (uint32_t y = 56; y < s_screen.height; y++) { + uint8_t* row = ((uint8_t*)s_screen.front_buffer) + (y * s_screen.pitch); + uint32_t* pixels = (uint32_t*)row; + for (uint32_t x = 0; x < s_screen.width; x++) { + pixels[x] = COLOR_OBSIDIAN; + } + } + s_console_x = 24; + s_console_y = 60; +} + +void vbe_console_putchar(char c, uint32_t color) { + if (!s_screen.initialized || !s_screen.front_buffer) return; + + if (c == '\r') { + s_console_x = 24; + return; + } + + if (c == '\n') { + s_console_x = 24; + s_console_y += 18; + if (s_console_y + 18 >= s_screen.height) { + vbe_console_clear(); + } + return; + } + + if (c == '\t') { + s_console_x = (s_console_x + 32) & ~31; + if (s_console_x + 8 >= s_screen.width - 24) { + s_console_x = 24; + s_console_y += 18; + if (s_console_y + 18 >= s_screen.height) { + vbe_console_clear(); + } + } + return; + } + + if (c < 32 || c > 126) return; + + const uint8_t* glyph = font_get_glyph(c); + for (uint32_t row = 0; row < 16; row++) { + uint8_t line = glyph[row]; + uint32_t py = s_console_y + row; + if (py >= s_screen.height) break; + uint8_t* dst_row = ((uint8_t*)s_screen.front_buffer) + (py * s_screen.pitch); + uint32_t* pixels = (uint32_t*)dst_row; + for (uint32_t col = 0; col < 8; col++) { + uint32_t px = s_console_x + col; + if (px >= s_screen.width) break; + if ((line >> (7 - col)) & 1) { + pixels[px] = color; + } + } + } + + s_console_x += 8; + if (s_console_x + 8 >= s_screen.width - 24) { + s_console_x = 24; + s_console_y += 18; + if (s_console_y + 18 >= s_screen.height) { + vbe_console_clear(); + } + } } void vbe_init(uint32_t width, uint32_t height) { diff --git a/drivers/vga.c b/drivers/vga.c index 0614c17..a16030e 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -1,16 +1,41 @@ #include +#include static size_t vga_row; static size_t vga_column; static uint8_t vga_current_color; static volatile uint16_t* const vga_buffer = (volatile uint16_t*)VGA_BUFFER_PHYSICAL; +static uint32_t vga_to_rgb(uint8_t vga_color) { + uint8_t fg = vga_color & 0x0F; + switch (fg) { + case VGA_COLOR_BLACK: return 0xFF000000; + case VGA_COLOR_BLUE: return 0xFF0055AA; + case VGA_COLOR_GREEN: return 0xFF00AA00; + case VGA_COLOR_CYAN: return 0xFF00AAAA; + case VGA_COLOR_RED: return 0xFFAA0000; + case VGA_COLOR_MAGENTA: return 0xFFAA00AA; + case VGA_COLOR_BROWN: return 0xFFAA5500; + case VGA_COLOR_LIGHT_GREY: return 0xFFAAAAAA; + case VGA_COLOR_DARK_GREY: return 0xFF555555; + case VGA_COLOR_LIGHT_BLUE: return 0xFF5555FF; + case VGA_COLOR_LIGHT_GREEN: return 0xFF55FF55; + case VGA_COLOR_LIGHT_CYAN: return 0xFF00E5FF; + case VGA_COLOR_LIGHT_RED: return 0xFFFF5555; + case VGA_COLOR_LIGHT_MAGENTA:return 0xFFFF55FF; + case VGA_COLOR_LIGHT_BROWN: return 0xFFFFFF55; + case VGA_COLOR_WHITE: return 0xFFFFFFFF; + default: return 0xFFFFFFFF; + } +} + /* Outport byte to I/O port (used for hardware cursor updates) */ static inline void outb(uint16_t port, uint8_t val) { __asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port)); } static void vga_update_cursor(void) { + if (vbe_is_hardware_framebuffer()) return; uint16_t pos = (uint16_t)(vga_row * VGA_WIDTH + vga_column); outb(0x3D4, 0x0F); outb(0x3D5, (uint8_t)(pos & 0xFF)); @@ -53,6 +78,10 @@ void vga_clear(void) { } void vga_putchar(char c) { + if (vbe_is_hardware_framebuffer()) { + vbe_console_putchar(c, vga_to_rgb(vga_current_color)); + } + if (c == '\b') { if (vga_column > 12) { vga_column--; diff --git a/include/airlys/font.h b/include/airlys/font.h index f1cc42d..1645e44 100644 --- a/include/airlys/font.h +++ b/include/airlys/font.h @@ -13,6 +13,7 @@ #define FONT_CHAR_HEIGHT 16 /* Typography API */ +const uint8_t* font_get_glyph(char c); void font_draw_char(uint32_t x, uint32_t y, char c, uint32_t color); void font_draw_string(uint32_t x, uint32_t y, const char* str, uint32_t color); void font_draw_string_glow(uint32_t x, uint32_t y, const char* str, uint32_t color, uint32_t glow_color); diff --git a/include/airlys/vbe.h b/include/airlys/vbe.h index 7933e43..0593b43 100644 --- a/include/airlys/vbe.h +++ b/include/airlys/vbe.h @@ -44,6 +44,10 @@ void vbe_init(uint32_t width, uint32_t height); void vbe_set_physical_framebuffer(uint64_t addr, uint32_t width, uint32_t height, uint32_t pitch, uint32_t bpp); bool vbe_is_hardware_framebuffer(void); vbe_screen_t* vbe_get_screen(void); +void vbe_early_boot_splash(void); +void vbe_console_putchar(char c, uint32_t color); +void vbe_console_clear(void); +void vbe_allocate_backbuffer(void); void vbe_putpixel(uint32_t x, uint32_t y, uint32_t color); uint32_t vbe_getpixel(uint32_t x, uint32_t y); diff --git a/kernel/compositor.c b/kernel/compositor.c index bca1a17..32cab3f 100644 --- a/kernel/compositor.c +++ b/kernel/compositor.c @@ -21,6 +21,7 @@ void compositor_init(void) { /* Initialize VBE 1024x768 @ 32bpp Framebuffer */ vbe_init(1024, 768); + vbe_allocate_backbuffer(); apps_init(); /* Pre-seed core windows */ diff --git a/kernel/kmain.c b/kernel/kmain.c index b6346c6..c186a82 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -45,7 +45,36 @@ static void aira_sentinel_task(void) { } void kernel_main(uint64_t magic, uint64_t addr) { - /* Step 1: Initialize hardware VGA terminal console */ + /* Step 0: Extract Hardware Framebuffer immediately (UEFI GOP / VBE Tag 16) */ + if (magic == 0x36D76289 && addr != 0) { + uint32_t total_size = *(volatile uint32_t*)addr; + uint8_t* tag_ptr = (uint8_t*)(addr + 8); + + while (tag_ptr < (uint8_t*)(addr + total_size)) { + uint32_t tag_type = *(volatile uint32_t*)tag_ptr; + uint32_t tag_size = *(volatile uint32_t*)(tag_ptr + 4); + + if (tag_type == 0 || tag_size == 0) break; + + if (tag_type == 16) { /* Tag 16: Framebuffer tag */ + uint64_t fb_phys = *(volatile uint64_t*)(tag_ptr + 8); + uint32_t pitch = *(volatile uint32_t*)(tag_ptr + 16); + uint32_t w = *(volatile uint32_t*)(tag_ptr + 20); + uint32_t h = *(volatile uint32_t*)(tag_ptr + 24); + uint8_t bpp = *(volatile uint8_t*)(tag_ptr + 28); + + if (fb_phys != 0 && w >= 640 && h >= 480) { + vbe_set_physical_framebuffer(fb_phys, w, h, pitch, (uint32_t)bpp); + vbe_early_boot_splash(); + break; + } + } + + tag_ptr += (tag_size + 7) & ~7; + } + } + + /* Step 1: Initialize hardware VGA terminal console (mirrors to active GOP display) */ vga_init(); /* Banner & Sovereign Branding */ @@ -160,42 +189,9 @@ void kernel_main(uint64_t magic, uint64_t addr) { initramfs_init(); vga_puts(" [OK] Virtual File System (VFS) : In-Memory RamFS, /proc, /dev & /usr mounted\n"); - /* Step 14: Phase 7 - VESA Linear Framebuffer & Desktop Window Compositor */ - /* Parse Multiboot 2 Hardware Framebuffer Info (UEFI GOP) */ - if (magic == 0x36D76289 && addr != 0) { - uint32_t total_size = *(volatile uint32_t*)addr; - uint8_t* tag_ptr = (uint8_t*)(addr + 8); - - while (tag_ptr < (uint8_t*)(addr + total_size)) { - uint32_t tag_type = *(volatile uint32_t*)tag_ptr; - uint32_t tag_size = *(volatile uint32_t*)(tag_ptr + 4); - - if (tag_type == 0 || tag_size == 0) break; - - if (tag_type == 16) { /* Tag 16: Framebuffer tag */ - uint64_t fb_phys = *(volatile uint64_t*)(tag_ptr + 8); - uint32_t pitch = *(volatile uint32_t*)(tag_ptr + 16); - uint32_t w = *(volatile uint32_t*)(tag_ptr + 20); - uint32_t h = *(volatile uint32_t*)(tag_ptr + 24); - uint8_t bpp = *(volatile uint8_t*)(tag_ptr + 28); - - if (fb_phys != 0 && w >= 640 && h >= 480) { - vbe_set_physical_framebuffer(fb_phys, w, h, pitch, (uint32_t)bpp); - vga_puts(" [OK] Hardware GOP Framebuffer : Physical LCD Display Active ("); - vga_putdec(w); - vga_puts("x"); - vga_putdec(h); - vga_puts(" @ 32bpp TrueColor)\n"); - break; - } - } - - tag_ptr += (tag_size + 7) & ~7; - } - } - + /* Step 14: Phase 7 - Desktop Window Compositor & Hardware Acceleration */ compositor_init(); - vga_puts(" [OK] Desktop Shell Compositor : VBE 1024x768 @ 32bpp TrueColor & Acrylic Ready\n"); + vga_puts(" [OK] Desktop Shell Compositor : TrueColor Framebuffer & Acrylic Compositor Ready\n"); /* Step 15: Phase 8 - ACPI S0ix Modern Standby, Local Neural Engine & AiraStore */ acpi_init(); @@ -228,12 +224,15 @@ void kernel_main(uint64_t magic, uint64_t addr) { /* Continuous 60 FPS live rendering loop (live CPU wave graph & RTC clock) */ uint64_t last_frame_ticks = 0; + uint32_t loop_counter = 0; for (;;) { uint64_t current_ticks = timer_get_ticks(); - if (current_ticks > last_frame_ticks + 5) { /* Refresh every ~50ms */ + loop_counter++; + if (current_ticks > last_frame_ticks + 5 || loop_counter >= 300000) { compositor_render_frame(); last_frame_ticks = current_ticks; + loop_counter = 0; } - __asm__ volatile ("hlt"); + __asm__ volatile ("pause"); } } diff --git a/scripts/build_iso.sh b/scripts/build_iso.sh index a105822..6ea0c51 100755 --- a/scripts/build_iso.sh +++ b/scripts/build_iso.sh @@ -24,18 +24,24 @@ cat << 'EOF' > "${ISO_DIR}/boot/grub/grub.cfg" insmod all_video insmod efi_gop insmod efi_uga +insmod video_bochs +insmod video_cirrus +insmod vbe +insmod vga insmod font -set gfxmode=auto +set gfxmode=1920x1080x32,1024x768x32,auto set gfxpayload=keep set timeout=5 set default=0 -menuentry "Airlys Sovereign OS (x86_64 Long Mode - UEFI GOP)" { +menuentry "Airlys Sovereign OS (Universal Auto-Detect - Bare Metal & VM)" { insmod all_video insmod efi_gop insmod efi_uga + insmod vbe + insmod vga set gfxpayload=keep multiboot2 /boot/airlys.elf boot @@ -43,12 +49,23 @@ menuentry "Airlys Sovereign OS (x86_64 Long Mode - UEFI GOP)" { menuentry "Airlys Sovereign OS (1024x768 TrueColor Framebuffer)" { insmod all_video + insmod vbe + insmod efi_gop set gfxmode=1024x768x32,auto set gfxpayload=1024x768x32,keep multiboot2 /boot/airlys.elf boot } +menuentry "Airlys Sovereign OS (1920x1080 Native FHD Framebuffer)" { + insmod all_video + insmod efi_gop + set gfxmode=1920x1080x32,auto + set gfxpayload=1920x1080x32,keep + multiboot2 /boot/airlys.elf + boot +} + menuentry "Airlys Sovereign OS (Fallback Multiboot 1)" { insmod all_video set gfxpayload=keep