feat(video): Add a framebuffer console so the TTY and nano work after graphics mode

Pressing Esc left the desktop and started the shell, but nothing appeared in the
emulator window -- the session was only visible on the host terminal. Once the
VBE adapter is switched into graphics mode the VGA text buffer at 0xB8000 stops
being scanned out, so every printk after that point reached serial and the
dmesg ring but never the display.

Disabling the DISPI interface does not bring the text console back; QEMU keeps
presenting the last framebuffer surface. So rather than clawing the adapter back
to text mode, the console is now rendered into the framebuffer:

  drivers/video/fbcon.c draws the console with the shared 8x8 font and carries a
  VT100 subset -- SGR colours, cursor addressing, relative moves, erase-display,
  erase-line and save/restore. It presents a fixed 80x25 grid, because that is
  the geometry the userland assumes (nano pads its bars with %-80s, the shell
  wraps at TTY_WIDTH), with the glyph cell scaled to fill the active resolution.

The TTY driver became the console dispatcher: tty_write, tty_clear and
tty_set_cursor route to fbcon while it owns the display. That last one is what
makes nano work -- it positions with tty_set_cursor() rather than escapes, so
its full-screen repaint was landing as an append-only stream.

Also in this change:

  - `video=WIDTHxHEIGHT` on the kernel command line selects the display mode,
    defaulting to 1280x720 so a 16:9 host panel is filled rather than pillarboxed
    when QEMU goes fullscreen. Rejects modes the heap cannot back.
  - `make run-fullscreen`, plus zoom-to-fit on the windowed target, so scaling
    preserves the guest aspect ratio instead of stretching it.
  - QEMU targets raise vgamem_mb, since a 1280x720 32-bit surface exceeds the
    default VGA memory.
  - bochs_vbe_disable()/fb_set_active() let the framebuffer be marked dormant so
    drawing routines no-op after a mode teardown.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01L5yKJT4Wo2cV3rfPrwY5MP
This commit is contained in:
subhobhai943andClaude Opus 5 committed 2026-08-25 02:06:07 +05:30
1 parent eacba4f4d3
commit 2d01fd629e
10 files changed
+470 -8

No files matched your search

+1 -1
View File
@@ -284,7 +284,7 @@ void kernel_main(void* memory_map, uint64_t memory_map_count) {
printk(ANSI_BRIGHT_CYAN " SUB-OS 64-Bit [%s] Modular Monolithic Kernel %s\n" ANSI_RESET, arch_get_name(), kernel_get_version());
printk(ANSI_BRIGHT_CYAN "=================================================================\n\n" ANSI_RESET);
init_early("root=/dev/sda console=tty1 init=/bin/lazybox quiet");
init_early("root=/dev/sda console=tty1 init=/bin/lazybox video=1280x720 quiet");
rtc_init();
printk(KERN_INFO "[1/14] Initializing 64-Bit GDT, IDT, PIC & PIT Timer... ");
+8 -1
View File
@@ -1,5 +1,6 @@
#include <kernel/printk.h>
#include <drivers/tty.h>
#include <drivers/fbcon.h>
#include <drivers/serial.h>
#include <lib/printf.h>
#include <lib/string.h>
@@ -68,7 +69,13 @@ int vprintk(const char* fmt, va_list args) {
sink_fn(display_ptr, (size_t)len, sink_ctx);
sink_active = false;
} else if (!sink_fn) {
tty_write(display_ptr, (size_t)len);
// The VGA text buffer stops being scanned out once the adapter is in
// graphics mode, so the framebuffer console takes over there.
if (fbcon_is_active()) {
fbcon_write(display_ptr, (size_t)len);
} else {
tty_write(display_ptr, (size_t)len);
}
}
// 2. Output to serial console (COM1 on x86, PL011 on ARM/AArch64)