boot: one hand-off contract, defined once
Groundwork for the unified loader: before the two paths can share code, they have to agree on what they are producing, and until now they only agreed by coincidence. Every field of the loader/kernel hand-off was #defined in whichever file happened to need it -- kernel/core/main.c, kernel/dev/vga.c, kernel/arch/x86_64/e820.c, boot/bios/cdboot.S, boot/bios/stage2main.c and boot/uefi/main.c, six copies of the same addresses. schboot.h existed for exactly this and held only the entry magic and the RSDP slot, with a comment describing the rest of the block it did not define. The whole block lives there now: the VBE info fields, the verbose and media flags (with the real-mode segment:offset spelling cdboot.S needs), the e820 count, map and cap, and the RSDP. Every one of those files includes it instead of restating it. This is not a tidy-up. It is the same hazard as defining the entry magic twice, only quieter -- nothing breaks until one copy moves, and the two loaders diverging is precisely what produced the EFER.SCE and RSDP bugs, where a fix on one path silently did not exist on the other. Verified on both firmwares: BIOS boots to schinit with the same e820, ACPI and VGA lines as before; UEFI reaches cpu0 with 1018 MB in 7 regions and its own 1280x800 mode. `make iso` still builds. bootcheck 108 [ok]. Next: the loaders become starters that gather firmware-specific facts and hand to one common stage. That needs the BIOS side to climb to long mode first, since common code can only be compiled for one CPU mode -- which is the risky part, and is why the contract went first. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
b34779111a
commit
0500e4382d
7 changed files with 89 additions and 56 deletions
|
|
@ -23,13 +23,10 @@
|
|||
// than in some new way.
|
||||
uint64 phystop = PHYSTOP_FALLBACK;
|
||||
|
||||
// Where stage2 left the map. Must match E820_COUNT_ADDR / E820_MAP_ADDR in
|
||||
// boot/bios/stage2main.c, which are themselves relative to VBE_INFO_ADDR.
|
||||
#define E820_COUNT_ADDR (0x30000 + 0x200)
|
||||
#define E820_MAP_ADDR (0x30000 + 0x208)
|
||||
#include "schboot.h" /* the hand-off block */
|
||||
|
||||
#define E820_USABLE 1
|
||||
#define E820_MAXENTRIES MEMREGION_MAX
|
||||
#define E820_MAXENTRIES SCHBOOT_E820_MAX
|
||||
|
||||
// Every usable region, page aligned inwards and clipped to PHYSTOP_MAX.
|
||||
// kinit1() frees these; see include/memlayout.h for why a list and not just a
|
||||
|
|
@ -59,8 +56,8 @@ struct e820entry {
|
|||
void
|
||||
e820_init(void)
|
||||
{
|
||||
uint32 count = *(uint32 *)P2V(E820_COUNT_ADDR);
|
||||
struct e820entry *e = (struct e820entry *)P2V(E820_MAP_ADDR);
|
||||
uint32 count = *(uint32 *)P2V(SCHBOOT_E820_COUNT);
|
||||
struct e820entry *e = (struct e820entry *)P2V(SCHBOOT_E820_MAP);
|
||||
|
||||
// A count of zero means the firmware declined; anything absurd means we are
|
||||
// reading something that is not a memory map. Either way the constant is the
|
||||
|
|
|
|||
|
|
@ -12,15 +12,15 @@ static void startothers(void);
|
|||
static void mpmain(void) __attribute__((noreturn));
|
||||
extern char end[]; // first address after kernel loaded from ELF file
|
||||
|
||||
// Set by stage2main.c (boot/bios/stage2main.c, BOOT_VERBOSE_FLAG_ADDR) when the
|
||||
// Set by stage2main.c (boot/bios/stage2main.c, SCHBOOT_VERBOSE_FLAG) when the
|
||||
// user picks "Boot SchOS (verbose)" from the F8 boot menu; read once here,
|
||||
// before anything else, so subsystem init can log its own steps.
|
||||
int boot_verbose;
|
||||
|
||||
// Must match BOOT_VERBOSE_FLAG_ADDR in boot/bios/stage2main.c exactly: just past
|
||||
// Must match SCHBOOT_VERBOSE_FLAG in boot/bios/stage2main.c exactly: just past
|
||||
// the VBE info block, not 0x7000 (startothers() below uses that address for
|
||||
// the AP boot trampoline).
|
||||
#define BOOT_VERBOSE_FLAG_ADDR (0x30000 + 0x100)
|
||||
#include "schboot.h"
|
||||
|
||||
// Bootstrap processor starts running C code here.
|
||||
// Allocate a real stack and switch to it, first
|
||||
|
|
@ -28,7 +28,7 @@ int boot_verbose;
|
|||
int
|
||||
kmain(uint32 fb_addr)
|
||||
{
|
||||
boot_verbose = *(uchar*)P2V(BOOT_VERBOSE_FLAG_ADDR);
|
||||
boot_verbose = *(uchar*)P2V(SCHBOOT_VERBOSE_FLAG);
|
||||
|
||||
uartearlyinit();
|
||||
if (boot_verbose) cprintf("verbose boot: uartearlyinit done\n");
|
||||
|
|
|
|||
|
|
@ -40,23 +40,23 @@ vga_set_bg(uint32 color)
|
|||
}
|
||||
|
||||
// Written by boot/bios/stage2.S's VBE call and read by boot/bios/stage2main.c under
|
||||
// the same name (VBE_INFO_ADDR) — not 0x9000, since stage2's own code now
|
||||
// the same name (SCHBOOT_VBE_INFO) — not 0x9000, since stage2's own code now
|
||||
// runs up to nearly 0x9000 once the boot-menu/progress-bar logic is
|
||||
// included, which would otherwise clobber a mode info block placed there.
|
||||
#define VBE_INFO_ADDR 0x30000
|
||||
#include "schboot.h" /* the hand-off block */
|
||||
|
||||
void
|
||||
vga_init(uint64 phys_addr) {
|
||||
if (phys_addr == 0) {
|
||||
phys_addr = *(uint32*)(P2V(VBE_INFO_ADDR) + 40);
|
||||
phys_addr = *(uint32*)(P2V(SCHBOOT_VBE_LFB));
|
||||
}
|
||||
vga_mem = (volatile uchar*)P2V(phys_addr);
|
||||
vga_phys = phys_addr;
|
||||
|
||||
vga_stride = *(ushort*)(P2V(VBE_INFO_ADDR) + 16);
|
||||
vga_width = *(ushort*)(P2V(VBE_INFO_ADDR) + 18);
|
||||
vga_height = *(ushort*)(P2V(VBE_INFO_ADDR) + 20);
|
||||
vga_bpp = *(uchar*)(P2V(VBE_INFO_ADDR) + 25);
|
||||
vga_stride = *(ushort*)(P2V(SCHBOOT_VBE_STRIDE));
|
||||
vga_width = *(ushort*)(P2V(SCHBOOT_VBE_WIDTH));
|
||||
vga_height = *(ushort*)(P2V(SCHBOOT_VBE_HEIGHT));
|
||||
vga_bpp = *(uchar*)(P2V(SCHBOOT_VBE_BPP));
|
||||
|
||||
if (vga_width == 0) vga_width = 800;
|
||||
if (vga_height == 0) vga_height = 600;
|
||||
|
|
|
|||
Loading…
Reference in a new issue