boot: stage2 climbs to long mode, and both loaders use one kernel entry
The BIOS loader handed the kernel a 32-bit entry that climbed into long mode itself; the UEFI loader arrived already there and used a separate 64-bit entry. Two entries meant two copies of the same preconditions, and that is not a hypothetical cost -- it is exactly where EFER.SCE went missing for months, set on one path and not the other, invisible until a program tried to return from a syscall. stage2 does the climb now. It builds the page tables where the UEFI loader builds them and meaning the same thing -- 4 GB identity-mapped with 1 GB pages, and the same 4 GB again at 0xffff800000000000, because entry64low's first instruction is a movabs to a high address and identity alone triple faults on it -- sets PAE, LME and SCE, enables paging, and far jumps through a GDT with an L-bit code descriptor, which a 32-bit descriptor cannot express. stage2main.c is compiled for x86_64 and runs in long mode. It still reads the multiboot header to find where the kernel's segments go, but enters through the SCH64 header rather than the entry named there: that entry is 32-bit code whose only job is the climb, and dropping back to 32 bits to redo work already done is a mode switch for no reason. If the SCH64 header is absent it halts, because there is no longer anything to fall back to. So both loaders now hand over identically -- long mode, interrupts off, CR3 mapping the low 4 GB twice, framebuffer in RBX -- and there is one set of preconditions instead of two that can drift. Verified on every path that exists: BIOS to schinit; BIOS with -smp 2, which brings up cpu1 through the AP trampoline's own separate climb; the resolution menu still selecting 1024x768 over serial; the ISO, which loads through ATAPI and a ramdisk root; UEFI unchanged at 1018 MB in 7 regions; bootcheck 108 [ok]. stage2 is 21988 of 24576 bytes. The 32-bit mboot_entry stays in entry.S. Nothing of ours uses it now, but it is what makes the kernel loadable by a multiboot loader that is not ours, and removing it is a separate decision from this one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
0500e4382d
commit
879db62379
3 changed files with 131 additions and 18 deletions
6
Makefile
6
Makefile
|
|
@ -569,9 +569,9 @@ $(BUILD)/boot/cdboot: boot/bios/cdboot.S
|
|||
|
||||
$(BUILD)/boot/stage2: boot/bios/stage2.S boot/bios/stage2main.c include/logo.h
|
||||
@mkdir -p $(BUILD)/boot
|
||||
$(CC32) $(STAGE2_DEF) -fno-builtin -fno-pic -nostdinc -I./include -c boot/bios/stage2.S -o $(BUILD)/boot/stage2asm.o
|
||||
$(CC32) $(STAGE2_DEF) -fno-builtin -fno-pic -O -nostdinc -I./include -c boot/bios/stage2main.c -o $(BUILD)/boot/stage2main.o
|
||||
$(LD) -m elf_i386 -nostdlib $(LD_LOWBASE) -n -N -e stage2start -Ttext 0x7E00 \
|
||||
$(CC) $(STAGE2_DEF) -fno-builtin -fno-pic -nostdinc -I./include -c boot/bios/stage2.S -o $(BUILD)/boot/stage2asm.o
|
||||
$(CC) $(STAGE2_DEF) -fno-builtin -fno-pic -O -nostdinc -mno-red-zone -mno-sse -mcmodel=small -I./include -c boot/bios/stage2main.c -o $(BUILD)/boot/stage2main.o
|
||||
$(LD) -m elf_x86_64 -nostdlib $(LD_LOWBASE) -n -N -e stage2start -Ttext 0x7E00 \
|
||||
-o $(BUILD)/boot/stage2tmp.o $(BUILD)/boot/stage2asm.o $(BUILD)/boot/stage2main.o
|
||||
$(OBJCOPY) -S -O binary -j .text -j .rodata -j .data $(BUILD)/boot/stage2tmp.o $(BUILD)/boot/stage2
|
||||
./tools/padstage2.pl $(BUILD)/boot/stage2 $(STAGE2_BYTES)
|
||||
|
|
|
|||
Loading…
Reference in a new issue