Răsfoiți Sursa

Stage the legacy rootfs in the first 32 KB

The X201 reports DL=0x80 (the m=L bit; the printed d/lba were zero
because INT 10h clobbered the hex printer's loop value).  Its LBA read
hangs with the staging buffer above the kernel, while the boot sector
reads the kernel itself to 0x7E00..0x42460.  Use 0x3000..0x6FFF as the
staging buffer (16 KB chunks, below the boot sector) and preserve
EBX/ECX across the teletype call so the debug line shows the real drive
and LBA.  This also keeps the staging area clear of the kernel BSS.
Johannes Zellner 2 săptămâni în urmă
părinte
comite
f1cf6f9475
2 a modificat fișierele cu 21 adăugiri și 12 ștergeri
  1. 5 0
      AGENTS.md
  2. 16 12
      vesa_stage.S

+ 5 - 0
AGENTS.md

@@ -122,6 +122,11 @@ a Pentium 1 (and a Pentium II board without ACPI) on the UP path.
 | `0x80000` | Legacy ring-0 program load area (`run.c`, `serial_recv.c`, `user.ld`; max 0x6000, inside the reserved low 1 MB) |
 | `0x100000`| VGA shadow buffer (`VGA_SHADOW_BASE`, `vga.h`) |
 
+The legacy stage uses `0x3000..0x6FFF` as a 16 KB-chunk rootfs staging
+buffer before the kernel starts; the UHCI frame list (`0x3000`), ISA DMA
+buffer (`0x4000`) and AP trampoline (`0x6000`) reinitialize those addresses
+later.
+
 The boot-time rootfs pack is also dynamic: the legacy stage puts it at the
 top of RAM below 16 MB (the AH=87h 24-bit descriptor limit), the UEFI loader
 at the top of RAM below 128 MB, and kexec leaves it in the staging buffer

+ 16 - 12
vesa_stage.S

@@ -137,8 +137,8 @@ e820_done:
 	call  read_sectors
 	jc    pack_fail
 
-	/* Validate the header at 0x70000: "NBROOT1\0", version 1. */
-	movl  $0x70000, %esi
+	/* Validate the header at 0x3000: "NBROOT1\0", version 1. */
+	movl  $0x3000, %esi
 	movl  0(%esi), %eax
 	cmpl  $0x4F52424E, %eax       /* "NBRO" */
 	jne   pack_fail
@@ -170,9 +170,9 @@ load_loop:
 	subl  %eax, %ecx
 	addl  $511, %ecx
 	shrl  $9, %ecx
-	cmpl  $64, %ecx
+	cmpl  $32, %ecx
 	jbe   1f
-	movl  $64, %ecx
+	movl  $32, %ecx
 1:	movl  %ecx, chunk_sectors
 	movl  pack_off, %eax
 	shrl  $9, %eax
@@ -381,7 +381,7 @@ a20_wait:
 
 /* ---- Read sectors via INT 13h ------------------------------------------
  * in:  eax = LBA, cx = sector count
- * out: data at 0x70000, CF set on failure
+ * out: data at 0x3000, CF set on failure
  * Clobbers all general registers. */
 read_sectors:
 	movl  %eax, rd_lba
@@ -392,7 +392,7 @@ read_retry:
 	movw  rd_off, %bx
 	xorw  %ax, %ax
 	movw  %ax, %ds
-	movw  $0x7000, %ax
+	movw  $0x0300, %ax
 	movw  %ax, %es
 	movb  stage_drive, %dl
 	cmpb  $0x80, %dl
@@ -403,7 +403,7 @@ read_lba:
 	movw  $0x10, 0x500
 	movw  $1, 0x502
 	movw  %bx, 0x504
-	movw  $0x7000, 0x506
+	movw  $0x0300, 0x506
 	movl  rd_lba, %eax
 	movl  %eax, 0x508
 	movl  $0, 0x50C
@@ -514,7 +514,7 @@ pack_addr_fallback:
 	ret
 
 /* ---- Copy a chunk to high memory with INT 15h AH=87h -------------------
- * in: copy_dst (24-bit), copy_len; source is 0x70000.
+ * in: copy_dst (24-bit), copy_len; source is 0x3000.
  * Copies in 16-bit words; returns with CF set on failure. */
 bios_copy:
 	movl  copy_dst, %eax
@@ -570,7 +570,11 @@ print_hex:
 2:	addl  $48, %eax
 3:	movb  $0x0E, %ah
 	movb  $0x00, %bh
+	pushl %ebx
+	pushl %ecx
 	int   $0x10
+	popl  %ecx
+	popl  %ebx
 	loop  1b
 	popal
 	ret
@@ -640,16 +644,16 @@ stage2_gdtr:
 	.long stage2_gdt
 
 /* ---- INT 15h AH=87h descriptor table (48 bytes) -----------------------
- * 16 zero bytes, source descriptor at 0x10 (0x70000, 64 KB), destination
+ * 16 zero bytes, source descriptor at 0x10 (0x3000, 64 KB), destination
  * at 0x18 (patched per chunk), 16 zero bytes. */
 .align 16
 bios_gdt:
 	.quad 0
 	.quad 0
-	/* source: limit 0xFFFF, base 0x70000, access 0x93, 16-bit data */
+	/* source: limit 0xFFFF, base 0x3000, access 0x93, 16-bit data */
 	.word 0xFFFF
-	.word 0x0000
-	.byte 0x07
+	.word 0x3000
+	.byte 0x00
 	.byte 0x93
 	.word 0x0000
 	/* destination: limit 0xFFFF, base patched, access 0x93 */