feat(kernel): v4 boots in the kernel's boot -- the Stadium, its checks, the opcode patrons
#189, ENGINE step 4, Phase 1 (plan 2026-11-13-engine-step4-phase1), Tasks 1-4. Captain Bob, 2026-11-13: Q1 "A new node key", Q2 "Per heartbeat tick", Q3 "All of v3's", Q4 "In Phase 1" / "Full births now", who runs next "Hera by compudynamics now" (Task 5, to come). - stadium.c/.h: stadium_node_key(node) ("NODE" | number), stadium_boot_init_for(first), stadium_birth_node(key, name); stadium_boot_init() and stadium_birth_hera() are them for Hera's key, so v3's path is as it was (only an impossible panic's words changed). - kernel_main.c: the system is chosen and said first, then the Stadium, sessions, switch-signal and kernel-Hermes tables for both systems in v3's order; v4: Hera, node 10, patron zero under her node key, the word, block and opcode layers. The quota self-test and the heartbeat's line are functions now, called by both systems. - sk_v4.c/.h: sk_v4_run() goes -- sk_v4_boot() returns, the kernel's checks after POST (opcodes, words, conservation, quota, heartbeat), then sk_v4_prompt(). sk_v4_charge_opcodes() at the heartbeat's service points (the key wait, after each line) and once after POST. - stadium_ops.c/.h: a node's 32 opcodes as Stadium patrons (HEAT-OP's feed, "Both"): retirements charged as the word layer's dispatches, a quantum each, the reservoir's floor kept, shared by retirements when short; cooling per tick as words. ~0.5 us a charge on the host: kept. - qemu_session.py: a v4 acceptance boot fails without "Stadium: N cells", "Stadium conservation: CONSERVED" and the heartbeat's ticks (#189). Tests first (logs/20261113-122142): the physics check failed on the v4 boot; test_stadium_node, test_stadium_ops (and its share case, after a real boot showed ";" taking all the heat) failed before. Now: kernel host tests all pass; amd64 v4 boot passes, POST 539/539, dict_hash unchanged, "Stadium opcodes: 30 resident, hottest opcode 8", CONSERVED; a system=v3 boot prints its Stadium lines as on 2026-11-06. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
+117
-63
@@ -16,7 +16,7 @@
|
||||
* M0-M6: Complete (build, boot, PMM, VMM, interrupts, timer, kmalloc) -- v1.5.1-FINAL
|
||||
* M7: Complete (the StarForth VM integrated, parity validated)
|
||||
* M7.1: In progress (capsule birth, the Mama vocabulary, the Tripod fleet, the word ACL)
|
||||
* The system booted by default is v4, StarForth's F18 engine (sk_v4_run); system=v3 boots v3
|
||||
* The system booted by default is v4, StarForth's F18 engine (sk_v4_boot, sk_v4_prompt); system=v3 boots v3
|
||||
* (docs/fabric/FABRIC-3.md XLIII).
|
||||
*/
|
||||
|
||||
@@ -59,6 +59,7 @@ EFI_RUNTIME_SERVICES *g_sk_runtime_services = NULL;
|
||||
#include "starkernel/vm/bootstrap/sk_vm_bootstrap.h"
|
||||
#include "starkernel/vm/parity.h"
|
||||
#include "starkernel/vm/stadium.h"
|
||||
#include "starkernel/vm/stadium_ops.h"
|
||||
#include "starkernel/vm/stadium_words.h"
|
||||
#include "starkernel/vm/stadium_blocks.h"
|
||||
#include "starkernel/vm/kernel_hermes.h"
|
||||
@@ -88,6 +89,9 @@ EFI_RUNTIME_SERVICES *g_sk_runtime_services = NULL;
|
||||
#include "starkernel/v4/sk_v4.h"
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SK_V4_HERA_NODE
|
||||
#define SK_V4_HERA_NODE 10u /* a kernel without v4 never keys the Stadium by node (#189) */
|
||||
#endif
|
||||
|
||||
/* Forward declaration — kernel_main_deep contains everything from heartbeat
|
||||
* init onward. The 2 MB BSS stack is set up by kernel_entry.S before
|
||||
@@ -606,6 +610,71 @@ static void sk_v4_block_chain(void)
|
||||
*
|
||||
* @param boot_info The @c BootInfo passed from @c kernel_main_impl().
|
||||
*/
|
||||
/* The boot's checks after the system is up, the same on both systems (#189, plan
|
||||
* 2026-11-13-engine-step4-phase1, Task 2; Q3: "All of v3's"). They were inline in
|
||||
* kernel_main_deep, v3's path; v4's calls them too, under Hera's node key. */
|
||||
|
||||
/* item 4.1a self-test: stadium_grant_quota() with a synthetic identity, from `parent`'s quota. */
|
||||
#ifdef STARFORTH_ENABLE_VM
|
||||
static void sk_boot_quota_selftest(VMUuid parent, const char *name) {
|
||||
{
|
||||
VMUuid test_id;
|
||||
test_id.hi = 0;
|
||||
test_id.lo = 1; /* distinct from vm_uuid_hera() (all-zero) and
|
||||
* vm_uuid_none() (all-ones) */
|
||||
int grant_rc = stadium_grant_quota(test_id, parent);
|
||||
console_puts("Stadium quota grant self-test: ");
|
||||
console_println(grant_rc == 0 ? "OK" : "REFUSED");
|
||||
if (grant_rc == 0) {
|
||||
console_puts(" "); console_puts(name); print_uint(" reservoir=", stadium_reservoir_peek(parent));
|
||||
print_uint(" test-vm reservoir=", stadium_reservoir_peek(test_id));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Phase 0 acceptance (section 25.1 item 0.10): a few real ticks, then the heartbeat's line. */
|
||||
static void sk_boot_heartbeat_line(void) {
|
||||
{
|
||||
uint64_t wait_start = heartbeat_ticks();
|
||||
uint64_t spins = 0;
|
||||
while (heartbeat_ticks() - wait_start < 3 && spins < 100000000ULL) {
|
||||
arch_relax();
|
||||
spins++;
|
||||
}
|
||||
}
|
||||
console_puts("Heartbeat: ");
|
||||
{
|
||||
char buf[24]; uint64_t v = heartbeat_ticks(); int i = 0, j = 0; char t[24];
|
||||
if (v == 0) buf[i++] = '0';
|
||||
else { while (v > 0) { t[j++] = (char)('0' + (v % 10)); v /= 10; } while (j > 0) buf[i++] = t[--j]; }
|
||||
buf[i] = '\0';
|
||||
console_puts(buf);
|
||||
}
|
||||
console_puts(" ticks, trust=0x");
|
||||
{
|
||||
char buf[9]; uint32_t v = (uint32_t)heartbeat_trust();
|
||||
for (int k = 7; k >= 0; k--) {
|
||||
int nib = (int)((v >> (k * 4)) & 0xF);
|
||||
buf[7 - k] = (char)(nib < 10 ? '0' + nib : 'a' + nib - 10);
|
||||
}
|
||||
buf[8] = '\0';
|
||||
console_puts(buf);
|
||||
}
|
||||
console_puts(", variance=0x");
|
||||
{
|
||||
char buf[9]; uint32_t v = (uint32_t)heartbeat_state()->variance;
|
||||
for (int k = 7; k >= 0; k--) {
|
||||
int nib = (int)((v >> (k * 4)) & 0xF);
|
||||
buf[7 - k] = (char)(nib < 10 ? '0' + nib : 'a' + nib - 10);
|
||||
}
|
||||
buf[8] = '\0';
|
||||
console_puts(buf);
|
||||
}
|
||||
console_println("");
|
||||
}
|
||||
|
||||
static void kernel_main_deep(BootInfo *boot_info) {
|
||||
/* M5: Initialize heartbeat subsystem */
|
||||
console_println("Heartbeat: init...");
|
||||
@@ -631,25 +700,25 @@ static void kernel_main_deep(BootInfo *boot_info) {
|
||||
* Task 3). An ISO, CD or ESP-image boot is not a stick. */
|
||||
console_println(boot_info->boot_disk.is_stick ? "Boot disk: a StarshipOS stick"
|
||||
: "Boot disk: not a StarshipOS stick");
|
||||
/* Which system runs, worked out before the Stadium is made: its first quota is keyed by it --
|
||||
* Hera's all-zero key for v3, the first node's for v4 (#189, plan 2026-11-13-engine-step4-phase1,
|
||||
* Q1: "A new node key"). Said first, as before. */
|
||||
int sk_use_v4 = 0;
|
||||
#ifdef STARFORTH_V4
|
||||
{
|
||||
const int v3_refused = boot_info->boot_disk.is_stick && boot_info->args.system == KARGS_SYSTEM_V3;
|
||||
if (boot_info->args.system == KARGS_SYSTEM_V4 || v3_refused ||
|
||||
(boot_info->args.system == KARGS_SYSTEM_DEFAULT && SK_V4_DEFAULT)) {
|
||||
sk_use_v4 = boot_info->args.system == KARGS_SYSTEM_V4 || v3_refused ||
|
||||
(boot_info->args.system == KARGS_SYSTEM_DEFAULT && SK_V4_DEFAULT);
|
||||
if (sk_use_v4)
|
||||
console_println(v3_refused ? "System: v3 is not on this stick -- StarForth v4"
|
||||
: boot_info->args.system == KARGS_SYSTEM_V4
|
||||
? "System: StarForth v4 (system=v4)"
|
||||
: "System: StarForth v4 (this build's default)");
|
||||
/* StarForth v4 at a single prompt: one host node of the F18-derived
|
||||
* engine, in place of the v3 VM and everything below. It does not
|
||||
* return. */
|
||||
sk_v4_boot_info = boot_info;
|
||||
sk_v4_run(sk_v4_block_chain, &boot_info->boot_disk);
|
||||
else
|
||||
console_println(boot_info->args.system == KARGS_SYSTEM_V3
|
||||
? "System: StarForth v3 (system=v3)"
|
||||
: "System: StarForth v3 (this build's default; system=v4 for v4)");
|
||||
}
|
||||
}
|
||||
console_println(boot_info->args.system == KARGS_SYSTEM_V3
|
||||
? "System: StarForth v3 (system=v3)"
|
||||
: "System: StarForth v3 (this build's default; system=v4 for v4)");
|
||||
#else
|
||||
console_println(boot_info->args.system == KARGS_SYSTEM_V4
|
||||
? "System: StarForth v3 -- system=v4 asked for, and this kernel has no v4"
|
||||
@@ -657,10 +726,13 @@ static void kernel_main_deep(BootInfo *boot_info) {
|
||||
#endif
|
||||
|
||||
#ifdef STARFORTH_ENABLE_VM
|
||||
/* The Stadium and the kernel's tables are the kernel's, for both systems, in v3's order (#189,
|
||||
* Phase 1 Task 1; Q3: "All of v3's"). */
|
||||
/* Stadium: boot-time allocation (FABRIC-0.md item 3.2), before any VM
|
||||
* exists (§6). Soft failure -- nothing downstream consumes the Stadium
|
||||
* yet, so a failed allocation logs and boot continues. */
|
||||
(void)stadium_boot_init();
|
||||
(void)(sk_use_v4 ? stadium_boot_init_for(stadium_node_key(SK_V4_HERA_NODE)) /* #189: keyed by node */
|
||||
: stadium_boot_init());
|
||||
|
||||
/* Session: boot-time allocation (FABRIC-2.md §H.12 step 4), sized from
|
||||
* stadium_max_vm_count() so it must run after stadium_boot_init() above
|
||||
@@ -693,6 +765,36 @@ static void kernel_main_deep(BootInfo *boot_info) {
|
||||
* table just above. Publish (task 3.3) enqueues here; nothing drains
|
||||
* it yet (task 3.4). */
|
||||
(void)sk_hermes_queues_boot_init();
|
||||
#endif
|
||||
|
||||
#ifdef STARFORTH_V4
|
||||
if (sk_use_v4) {
|
||||
#ifdef STARFORTH_ENABLE_VM
|
||||
/* Hera, the first node, is patron zero under her node key; then the word and block layers,
|
||||
* as on v3's path below (#189). */
|
||||
(void)stadium_birth_node(stadium_node_key(SK_V4_HERA_NODE), "Hera");
|
||||
stadium_words_init();
|
||||
stadium_blocks_init();
|
||||
stadium_ops_init(); /* the node's 32 opcode patrons (#189) */
|
||||
#endif
|
||||
/* StarForth v4: one host node of the F18-derived engine, in place of
|
||||
* the v3 VM, brought up in the kernel's boot (#189, Phase 1): the
|
||||
* node and POST, then the kernel's checks as v3's, then the prompt,
|
||||
* which does not return. */
|
||||
sk_v4_boot_info = boot_info;
|
||||
sk_v4_boot(sk_v4_block_chain, &boot_info->boot_disk);
|
||||
#ifdef STARFORTH_ENABLE_VM
|
||||
sk_v4_charge_opcodes(); /* what POST retired */
|
||||
stadium_ops_print_boot_diagnostics(stadium_node_key(SK_V4_HERA_NODE));
|
||||
stadium_words_print_boot_diagnostics(stadium_node_key(SK_V4_HERA_NODE));
|
||||
sk_boot_quota_selftest(stadium_node_key(SK_V4_HERA_NODE), "Hera");
|
||||
#endif
|
||||
sk_boot_heartbeat_line();
|
||||
sk_v4_prompt();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef STARFORTH_ENABLE_VM
|
||||
|
||||
/* item 4.1, FABRIC-0.md item 3.6/§17.7: actually enforce "Hera is patron
|
||||
* zero" before anything else can land on cell 0 via the free list, then
|
||||
@@ -986,19 +1088,7 @@ static void kernel_main_deep(BootInfo *boot_info) {
|
||||
* capsule birth (item 0.1 pruned automatic Hermes birth from init.4th;
|
||||
* restoring it is item 4.2's job, not this one's). Diagnostic only --
|
||||
* the synthetic VM is never used for anything else. */
|
||||
{
|
||||
VMUuid test_id;
|
||||
test_id.hi = 0;
|
||||
test_id.lo = 1; /* distinct from vm_uuid_hera() (all-zero) and
|
||||
* vm_uuid_none() (all-ones) */
|
||||
int grant_rc = stadium_grant_quota(test_id, vm_uuid_hera());
|
||||
console_puts("Stadium quota grant self-test: ");
|
||||
console_println(grant_rc == 0 ? "OK" : "REFUSED");
|
||||
if (grant_rc == 0) {
|
||||
print_uint(" Hera reservoir=", stadium_reservoir_peek(vm_uuid_hera()));
|
||||
print_uint(" test-vm reservoir=", stadium_reservoir_peek(test_id));
|
||||
}
|
||||
}
|
||||
sk_boot_quota_selftest(vm_uuid_hera(), "Hera");
|
||||
|
||||
/* FABRIC-3.6.md task 2.2 (item 28) self-test: sk_hermes_alloc()'s
|
||||
* heat-coupled allocate, against its own synthetic VM (lo=3, distinct
|
||||
@@ -1347,43 +1437,7 @@ static void kernel_main_deep(BootInfo *boot_info) {
|
||||
* (not a virtual-tick construct; §16.4/§18.5 govern patron state, not
|
||||
* this one-time boot diagnostic) rather than reporting whatever count
|
||||
* happened to land. */
|
||||
{
|
||||
uint64_t wait_start = heartbeat_ticks();
|
||||
uint64_t spins = 0;
|
||||
while (heartbeat_ticks() - wait_start < 3 && spins < 100000000ULL) {
|
||||
arch_relax();
|
||||
spins++;
|
||||
}
|
||||
}
|
||||
console_puts("Heartbeat: ");
|
||||
{
|
||||
char buf[24]; uint64_t v = heartbeat_ticks(); int i = 0, j = 0; char t[24];
|
||||
if (v == 0) buf[i++] = '0';
|
||||
else { while (v > 0) { t[j++] = (char)('0' + (v % 10)); v /= 10; } while (j > 0) buf[i++] = t[--j]; }
|
||||
buf[i] = '\0';
|
||||
console_puts(buf);
|
||||
}
|
||||
console_puts(" ticks, trust=0x");
|
||||
{
|
||||
char buf[9]; uint32_t v = (uint32_t)heartbeat_trust();
|
||||
for (int k = 7; k >= 0; k--) {
|
||||
int nib = (int)((v >> (k * 4)) & 0xF);
|
||||
buf[7 - k] = (char)(nib < 10 ? '0' + nib : 'a' + nib - 10);
|
||||
}
|
||||
buf[8] = '\0';
|
||||
console_puts(buf);
|
||||
}
|
||||
console_puts(", variance=0x");
|
||||
{
|
||||
char buf[9]; uint32_t v = (uint32_t)heartbeat_state()->variance;
|
||||
for (int k = 7; k >= 0; k--) {
|
||||
int nib = (int)((v >> (k * 4)) & 0xF);
|
||||
buf[7 - k] = (char)(nib < 10 ? '0' + nib : 'a' + nib - 10);
|
||||
}
|
||||
buf[8] = '\0';
|
||||
console_puts(buf);
|
||||
}
|
||||
console_println("");
|
||||
sk_boot_heartbeat_line();
|
||||
|
||||
/* FABRIC-3.md §XXVIII, Stage 3 (2026-09-13): register the Tripod fleet
|
||||
* as preemptive-switch-signal participants now, only after all three
|
||||
|
||||
Reference in New Issue
Block a user