Parcourir la source

Fix the boot console text size and scrolling

Johannes Zellner il y a 1 semaine
Parent
commit
11a74497bc
7 fichiers modifiés avec 118 ajouts et 67 suppressions
  1. 13 8
      AGENTS.md
  2. 2 2
      Makefile
  3. 83 47
      bootcon.c
  4. 5 4
      bootcon.h
  5. 9 4
      docs/boot.html
  6. 4 1
      docs/graphics.html
  7. 2 1
      font_8x16.h

+ 13 - 8
AGENTS.md

@@ -521,12 +521,16 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   The `keytest` kernel command drains the raw scancode tap in `io.c`
   (E0/make/break/decoded) for key mapping.
 - **Text console**: `fbtext.c`, `font_8x8.c/h`, `io.c/h`, `screen.c/h` — 8×8 font,
-  framebuffer glyph blitting (`fbtext_draw_cells`) and the boot-console cell
-  buffer (`screen.c`, used by `io.c`'s fallback screen and `bootcon`).  The
-  ring-3 terminal renders its own rows into its canvas; the kernel window
-  manager has no text-cell content path.  `screen_damage_*` remains for the
-  boot console's own bookkeeping.  The kernel console stays 8×8; userland
-  proportional text uses `ufont` (below).
+  framebuffer glyph blitting (`fbtext_draw_cells`) and the fallback cell
+  screen (`screen.c`, used by `io.c` when no tty owns the output).  The early
+  `bootcon.c` draws 8×16 text (the same Terminus face as the terminal)
+  directly into the LFB, top-left, with no heap/paging/shadow dependency; a
+  full screen scrolls the console pixels up one 16-pixel cell instead of
+  wrapping back to the top.  The ring-3 terminal renders its own rows into
+  its canvas; the kernel window manager has no text-cell content path.
+  `screen_damage_*` remains for the fallback screen's own bookkeeping.
+  `fbtext` and `panic` stay 8×8; userland proportional text uses `ufont`
+  (below).
 - **Wall clock**: `rtc.c/h` reads and writes the CMOS RTC.  Reads honour the
   register-B BCD/binary and 12/24-hour modes, retry around the update cycle,
   and expand the two-digit year with a 1970-2069 window (70-99 -> 1900s,
@@ -2211,8 +2215,9 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     (8 slots x 1 KB), and the FAT listing cache another 5 KB.  The command
     pack is out of the kernel now; after the WiFi/netmenu/install code and the
     per-connection TCP queues moved to the frame allocator, `_end` is
-    ~0x85ca0 (with the 6200/6300 DVM layer and the RTL8821AU driver),
-    ~41 KB below the `0x90000` wall, and the remaining limit is kernel code/buffers only.
+    ~0x897a0 (with the 6200/6300 DVM layer, the RTL8821AU driver and the
+    8×16 boot-console font), ~26 KB below the `0x90000` wall, and the
+    remaining limit is kernel code/buffers only.
 
 22. Browser limits: JavaScript runs inline and external classic scripts on
     QuickJS (ES2025) with the DOM surface described above (creation/mutation/selectors/

+ 2 - 2
Makefile

@@ -254,7 +254,7 @@ lsusb.o: lsusb.c io.h usb.h
 panic.o: panic.c panic.h bootinfo.h font_8x8.h phys.h process.h serial.h timer.h vga.h
 	$(CC) $(CFLAGS) -o $@ $<
 
-bootcon.o: bootcon.c bootcon.h bootinfo.h font_8x8.h vga.h
+bootcon.o: bootcon.c bootcon.h bootinfo.h font_8x16.h vga.h
 	$(CC) $(CFLAGS) -o $@ $<
 
 lspci.o: lspci.c io.h pci.h
@@ -431,7 +431,7 @@ sys_net.o: sys_net.c sys_net.h syscall.h dhcp.h dns.h net.h netcore.h netdev.h n
 syscall_stub.o: syscall_stub.S irqret.inc
 	$(AS) $(ASFLAGS) -o $@ $<
 
-kernel.elf: kernel.ld vesa_stage.o entry.o kernel.o timer.o switch.o sched.o process.o mm.o kmalloc.o paging.o elf.o tss.o syscall.o sys_wm.o syscall_stub.o screen.o io.o tty.o rtc.o terminal.o wm.o reboot.o poweroff.o disk.o fat.o serial.o serial_ring_buf.o serial_loop.o vga.o blit.o cpu.o thermal.o it87.o tpec.o ec.o cros_ec.o power_src.o power.o vga_copy.o gfxbench.o gpu.o backlight.o ati.o cirrus.o intel.o nvidia.o nv50.o radeon.o mtrr.o font_8x8.o fbtext.o gfx.o display.o mouse.o i2c.o touchpad.o touchpad_gesture.o uhci.o ohci.o ehci.o xhci.o asix.o rndis.o iwl_trans.o iwl_mvm.o iwl_dvm.o wifi_fw.o rtl8821au.o wifi.o ccmp.o usb.o usbmsc.o usbhid.o lsusb.o panic.o bootcon.o blkdev.o sdhci.o ata.o ahci.o fatdetect.o fatformat.o format.o install.o vfs.o sys_fs.o sys_info.o sys_mem.o sys_net.o idle.o kexec.o kexec_tramp.o dbg.o lspci.o peek.o ne2000.o r8168.o e1000e.o netdev.o net.o netcore.o netkexec.o netlog.o dhcp.o dns.o ntp.o tcp.o acpi.o lapic.o smp.o ap_tramp_embed.o inflate.o ramfs.o share.o payload.o
+kernel.elf: kernel.ld vesa_stage.o entry.o kernel.o timer.o switch.o sched.o process.o mm.o kmalloc.o paging.o elf.o tss.o syscall.o sys_wm.o syscall_stub.o screen.o io.o tty.o rtc.o terminal.o wm.o reboot.o poweroff.o disk.o fat.o serial.o serial_ring_buf.o serial_loop.o vga.o blit.o cpu.o thermal.o it87.o tpec.o ec.o cros_ec.o power_src.o power.o vga_copy.o gfxbench.o gpu.o backlight.o ati.o cirrus.o intel.o nvidia.o nv50.o radeon.o mtrr.o font_8x8.o font_8x16.o fbtext.o gfx.o display.o mouse.o i2c.o touchpad.o touchpad_gesture.o uhci.o ohci.o ehci.o xhci.o asix.o rndis.o iwl_trans.o iwl_mvm.o iwl_dvm.o wifi_fw.o rtl8821au.o wifi.o ccmp.o usb.o usbmsc.o usbhid.o lsusb.o panic.o bootcon.o blkdev.o sdhci.o ata.o ahci.o fatdetect.o fatformat.o format.o install.o vfs.o sys_fs.o sys_info.o sys_mem.o sys_net.o idle.o kexec.o kexec_tramp.o dbg.o lspci.o peek.o ne2000.o r8168.o e1000e.o netdev.o net.o netcore.o netkexec.o netlog.o dhcp.o dns.o ntp.o tcp.o acpi.o lapic.o smp.o ap_tramp_embed.o inflate.o ramfs.o share.o payload.o
 	$(LD) $(KERNEL_LDFLAGS) -o $@ $(filter-out kernel.ld,$^)
 
 MBR_LDFLAGS = -T mbr.ld -nostdlib -m elf_i386

+ 83 - 47
bootcon.c

@@ -4,18 +4,22 @@
  * vga_cache_boot_fb(), which probes the GPU and maps BARs, and this code runs
  * before mm_init/paging_init exist.  It reads the boot framebuffer info block
  * at 0x600 directly, exactly like paging.c does.
+ *
+ * The console uses the same 8x16 Terminus face and cell grid as the ring-3
+ * terminal, and starts at the top-left like the BIOS text console, so the
+ * loader -> kernel -> WM handoff does not change the text size or jump around
+ * the screen.  A full screen scrolls instead of wrapping back to the top.
  */
 #include "bootcon.h"
 #include "bootinfo.h"
-#include "font_8x8.h"
+#include "font_8x16.h"
 #include "mm.h"
 #include "serial.h"
 #include "vga.h"
 
-#define SCALE  2
-#define LINE_H (8 * SCALE + 2)
-#define LEFT   8
-#define TOP    8
+#define CELL_W  8
+#define CELL_H  16
+#define MARGIN  8
 
 static unsigned int fb_w, fb_h, fb_pitch, fb_bpp;
 static unsigned int fb_base;
@@ -23,11 +27,12 @@ static volatile unsigned char *fb_lfb;
 static int fb_swap;
 static int fb_ok;
 static int enabled;
-static unsigned int cur_x, cur_y;
-static unsigned int home_x, home_y;
+static unsigned int con_x, con_y;       /* console pixel origin */
+static unsigned int con_cols, con_rows;
+static unsigned int cur_col, cur_row;
 
 /* Text log kept independently of the framebuffer: bootcon is disabled when
- * the WM starts, but the e1000e probe and later driver messages still go
+ * the WM attaches, but the e1000e probe and later driver messages still go
  * through bootcon_puts().  The buffer is allocated from the frame allocator
  * (see bootcon_log_init) so it does not move the kernel's _end past the low
  * rootfs pack at 0x60000. */
@@ -59,36 +64,66 @@ static void fb_px(unsigned int x, unsigned int y, unsigned int r,
 	}
 }
 
-/* Clear the band the next line will be drawn into, so a reused line (after
- * wrapping at the bottom) cannot leave parts of an older message behind. */
+/* Clear the band the current row will be drawn into, so a reused line
+ * cannot leave parts of an older message behind. */
 static void clear_line(void)
 {
 	unsigned int x, y;
+	unsigned int y0 = con_y + cur_row * CELL_H;
 
-	for (y = 0; y < LINE_H; y++)
-		for (x = 0; x < fb_w; x++)
-			fb_px(x, cur_y + y, 0, 0, 0);
+	for (y = 0; y < CELL_H; y++)
+		for (x = 0; x < con_cols * CELL_W; x++)
+			fb_px(con_x + x, y0 + y, 0, 0, 0);
 }
 
 static void draw_char(unsigned int x, unsigned int y, unsigned char c)
 {
-	const unsigned char *g = &font_8x8[(unsigned int)c * 8];
+	const unsigned char *g = &font_8x16[(unsigned int)c * FONT_8X16_ROWS];
 	unsigned int row, col;
 
-	for (row = 0; row < 8; row++) {
+	for (row = 0; row < FONT_8X16_ROWS; row++) {
 		unsigned char bits = g[row];
 
-		for (col = 0; col < 8; col++) {
-			if (bits & (0x80u >> col)) {
-				unsigned int i, j;
+		for (col = 0; col < CELL_W; col++)
+			if (bits & (0x80u >> col))
+				fb_px(x + col, y + row, 255, 255, 255);
+	}
+}
 
-				for (i = 0; i < SCALE; i++)
-					for (j = 0; j < SCALE; j++)
-						fb_px(x + col * SCALE + i,
-						      y + row * SCALE + j,
-						      255, 255, 255);
-			}
-		}
+/* Move the console up one text row: every row takes the pixels of the row
+ * below it and the last row is cleared.  Only used when the cursor is on the
+ * last row, so a normal boot never pays for it.
+ *
+ * Every supported bpp puts a whole number of dwords on a scanline for CELL_W
+ * pixels, and the console origin is a multiple of 4 pixels, so no partial
+ * dword is left behind.  Plain word loads/stores are used rather than
+ * `rep movsl`: the source is the LFB, not RAM. */
+static void scroll_up(void)
+{
+	unsigned int pb = fb_bpp / 8;
+	unsigned int dwords = (con_cols * CELL_W * pb) / 4;
+	unsigned char *base = (unsigned char *)fb_lfb +
+			      (unsigned long)con_y * fb_pitch + con_x * pb;
+	unsigned int line, i;
+	unsigned int lines = con_rows * CELL_H;
+
+	/* Move every scanline below the first text row up by one cell. */
+	for (line = 0; line < lines - CELL_H; line++) {
+		unsigned int *dst = (unsigned int *)(base +
+					(unsigned long)line * fb_pitch);
+		const unsigned int *src = (const unsigned int *)(base +
+					(unsigned long)(line + CELL_H) * fb_pitch);
+
+		for (i = 0; i < dwords; i++)
+			dst[i] = src[i];
+	}
+	/* Clear the bottom cell. */
+	for (line = lines - CELL_H; line < lines; line++) {
+		unsigned int *dst = (unsigned int *)(base +
+					(unsigned long)line * fb_pitch);
+
+		for (i = 0; i < dwords; i++)
+			dst[i] = 0;
 	}
 }
 
@@ -101,8 +136,6 @@ void bootcon_init(void)
 
 	fb_ok = 0;
 	enabled = 0;
-	cur_x = LEFT;
-	cur_y = TOP;
 	if (!fb->valid || !fb->lfb_base)
 		return;
 
@@ -124,20 +157,19 @@ void bootcon_init(void)
 	if (!fb_w || !fb_h || !fb_pitch || !fb_lfb)
 		return;
 
+	con_x = MARGIN;
+	con_y = MARGIN;
+	if (fb_w <= con_x + CELL_W || fb_h <= con_y + CELL_H)
+		return;
+	con_cols = (fb_w - 2 * MARGIN) / CELL_W;
+	con_rows = (fb_h - 2 * MARGIN) / CELL_H;
+	if (!con_cols || !con_rows)
+		return;
+
 	fb_ok = 1;
 	enabled = 1;
-	/* Start away from the very top-left: some VBIOSes centre a mode that
-	 * does not match the panel (e.g. 1280x1024 on a 1280x800 LVDS), which
-	 * crops the outer rows/columns.  Starting at 1/8,1/4 keeps the log
-	 * inside the visible area in both the centred and the scaled case. */
-	home_x = fb_w / 8;
-	home_y = fb_h / 4;
-	if (home_x < 8)
-		home_x = 8;
-	if (home_y < 8)
-		home_y = 8;
-	cur_x = home_x;
-	cur_y = home_y;
+	cur_col = 0;
+	cur_row = 0;
 	clear_line();
 }
 
@@ -155,10 +187,13 @@ void bootcon_set_enabled(int on)
 
 static void newline(void)
 {
-	cur_x = home_x;
-	cur_y += LINE_H;
-	if (cur_y + 8 * SCALE > fb_h)
-		cur_y = home_y;
+	cur_col = 0;
+	if (cur_row + 1 >= con_rows) {
+		scroll_up();
+		cur_row = con_rows - 1;
+	} else {
+		cur_row++;
+	}
 	clear_line();
 }
 
@@ -197,17 +232,18 @@ void bootcon_puts(const char *s)
 		if (!fb_ok || !enabled)
 			continue;
 		if (c == '\r') {
-			cur_x = LEFT;
+			cur_col = 0;
 			continue;
 		}
 		if (c == '\n') {
 			newline();
 			continue;
 		}
-		if (cur_x + 8 * SCALE > fb_w)
+		if (cur_col >= con_cols)
 			newline();
-		draw_char(cur_x, cur_y, c);
-		cur_x += 8 * SCALE;
+		draw_char(con_x + cur_col * CELL_W,
+			  con_y + cur_row * CELL_H, c);
+		cur_col++;
 	}
 }
 

+ 5 - 4
bootcon.h

@@ -1,11 +1,13 @@
 /* Boot console: the earliest on-screen output.
  *
- * Draws 8x8 text straight into the boot framebuffer described at 0x600.  It
+ * Draws 8x16 text straight into the boot framebuffer described at 0x600.  It
  * needs no heap, no paging (the LFB is identity-accessible), no drivers and
  * no shadow buffer, so it can be the first C code in kernel_main.  Purpose:
  * stage tracing on machines without serial, and a last visible screen if the
  * kernel wedges before the WM paints.  The WM's first frame covers it;
- * bootcon_set_enabled(0) stops drawing before that happens.
+ * bootcon_set_enabled(0) stops drawing before that happens.  The face, cell
+ * grid and top-left origin match the BIOS loader text and the ring-3
+ * terminal, and a full screen scrolls instead of wrapping.
  */
 #ifndef BOOTCON_H
 #define BOOTCON_H
@@ -22,8 +24,7 @@ void bootcon_hex(unsigned int v);
 void bootcon_fb_info(void);
 
 /* Allocate the RAM log after the page allocator is up.  The buffer is taken
- * from the frame allocator, not BSS: the low rootfs pack limits _end to
- * 0x60000 and a 16 KB static log would overlap it. */
+ * from the frame allocator, not BSS, to keep _end below the 0x90000 wall. */
 void bootcon_log_init(void);
 /* Everything written through bootcon_puts() after bootcon_log_init(),
  * including text produced after the WM has taken over the framebuffer.  The

+ 9 - 4
docs/boot.html

@@ -397,7 +397,9 @@
 			context-switch, and a ticking timer before AP bring-up can time out.
 		</p>
 		<ol>
-			<li>Clear BSS; initialise the boot console straight into the framebuffer.</li>
+			<li>Clear BSS; initialise the boot console straight into the
+			framebuffer (8×16 text at the top-left, scrolling when full, with
+			no heap, paging or shadow-buffer dependency).</li>
 			<li>Bring up COM1 and the network-console ring buffer.</li>
 			<li>Install the GDT/TSS and per-CPU GS base.</li>
 			<li>Parse E820, build the frame bitmap and initialise <code>kmalloc</code>.</li>
@@ -428,9 +430,11 @@
 		<p>
 			The boot trace lines written along the way (<code>boot_trace</code>,
 			<code>boot_val</code>) go to the framebuffer console and COM1, so a
-			machine without serial still shows where a boot stopped. The WM
-			disables the boot console when it attaches; <code>bootlog</code>
-			prints the saved text.
+			machine without serial still shows where a boot stopped. The
+			console uses the same 8×16 face and top-left origin as the loader
+			text and the ring-3 terminal, and scrolls the framebuffer when the
+			screen is full instead of wrapping. The WM disables it when it
+			attaches; <code>bootlog</code> prints the saved text.
 		</p>
 	</section>
 
@@ -459,6 +463,7 @@
 			<li><code>kexec.c</code>, <code>kexec_tramp.S</code> — serial reload</li>
 			<li><code>netkexec.c</code> — network reload</li>
 			<li><code>kernel.c</code> — init order</li>
+			<li><code>bootcon.c</code>, <code>font_8x16.c</code> — direct-to-LFB boot console</li>
 			<li><code>install.c</code>, <code>install.h</code> — clone, self-update and net-install writer</li>
 			<li><code>rootfs.h</code> — installed image geometry</li>
 			<li><code>kernel.ld</code> — image limits</li>

+ 4 - 1
docs/graphics.html

@@ -191,7 +191,9 @@
 			kexec detection and the boot-console handoff. It starts the first
 			terminal after the storage mount
 			(<code>wm_server_boot_ready</code>) and leaves the boot console
-			visible until the WM attaches.
+			visible until the WM attaches. The console uses the same 8×16 face
+			and top-left origin as the terminal, so the first frame replaces it
+			without a size or position jump.
 		</p>
 
 		<figure class="figure">
@@ -460,6 +462,7 @@
 		<h2>Source map</h2>
 		<ul class="filelist">
 			<li><code>vga.c</code>, <code>vga.h</code> — framebuffer and damage</li>
+			<li><code>bootcon.c</code> — direct-to-LFB boot console</li>
 			<li><code>vga_copy.S</code> — copy primitives</li>
 			<li><code>blit.c</code>, <code>blit.h</code> — pixel vtable</li>
 			<li><code>cpu.c</code> — SSE2 probing</li>

+ 2 - 1
font_8x16.h

@@ -1,5 +1,6 @@
 /* 8x16 bitmap font: 256 chars, 16 bytes each (one byte per row, MSB left).
-   Userland window/terminal fonts; the kernel console keeps font_8x8. */
+   Shared by the ring-3 window/terminal renderers and the kernel's early boot
+   console; fbtext and panic keep font_8x8. */
 #ifndef FONT_8X16_H
 #define FONT_8X16_H