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:
Claude
2026-11-13 12:50:02 +00:00
parent 3f4988e19e
commit b1cac339c1
35 changed files with 959 additions and 85 deletions
+5 -1
View File
@@ -19,7 +19,11 @@ CC ?= cc
CFLAGS := -std=c99 -Wall -Wextra -Werror -O2 -g -I$(HERE) -I$(ROOT)/kernel/include \
-I$(ROOT)/kernel/include/starkernel -I$(ROOT)/v3/include
TESTS := test_gpt test_usb_config test_sk_v4_stop test_sk_v4_slots test_sk_v4_mint test_sk_v4_identity test_heartbeat_export test_ssm_jacquard test_physics_l2
TESTS := test_gpt test_usb_config test_sk_v4_stop test_sk_v4_slots test_sk_v4_mint test_sk_v4_identity test_heartbeat_export test_ssm_jacquard test_physics_l2 test_stadium_node test_stadium_ops
SRC_test_stadium_ops := $(ROOT)/kernel/src/vm/stadium_ops.c $(ROOT)/kernel/src/vm/stadium.c $(ROOT)/kernel/src/vm/session.c $(ROOT)/kernel/src/capsule/vm_uuid.c
EXTRA_test_stadium_ops := -D__STARKERNEL__
SRC_test_stadium_node := $(ROOT)/kernel/src/vm/stadium.c $(ROOT)/kernel/src/vm/session.c $(ROOT)/kernel/src/capsule/vm_uuid.c
EXTRA_test_stadium_node := -D__STARKERNEL__
SRC_test_physics_l2 := $(ROOT)/v3/src/physics_execution_hooks.c
SRC_test_ssm_jacquard := $(ROOT)/v3/src/ssm_jacquard.c $(ROOT)/v3/src/compudynamics.c
SRC_test_heartbeat_export := $(ROOT)/v3/src/heartbeat_export.c
+59
View File
@@ -0,0 +1,59 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* test_stadium_node.c -- kernel/src/vm/stadium.c and session.c on the host (#189, plan
* 2026-11-13-engine-step4-phase1, Task 1): the Stadium keyed by a v4 node's number (Captain Bob,
* 2026-11-13: "A new node key"). A node's key is none of v3's (not Hera's all-zero, not "none"); the
* Stadium can be made with that key in its first quota; the node is born on cell 0, its session
* registered and pinned, its whole share in its reservoir -- as Hera is on v3's path, which keeps
* vm_uuid_hera() and stadium_birth_hera().
*
* What the sources call outside themselves is defined here.
*/
#include "harness.h"
#include "starkernel/vm/stadium.h"
#include "starkernel/session.h"
#include "starkernel/vm_uuid.h"
#include "starkernel/kmalloc.h"
#include "starkernel/q48_16.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
void *kmalloc(size_t size) { return calloc(1, size); }
void kfree(void *ptr) { free(ptr); }
kmalloc_stats_t kmalloc_get_stats(void)
{
kmalloc_stats_t s;
memset(&s, 0, sizeof s);
s.free_bytes = 16u * 1024u * 1024u; /* a small heap: the Stadium takes its percentage of it */
return s;
}
void log_message(int level, const char *fmt, ...) { (void)level; (void)fmt; }
void sk_hal_panic(const char *message) { printf("PANIC: %s\n", message); exit(2); }
int blk_flush(uint32_t block_num) { (void)block_num; return 0; }
int main(void)
{
VMUuid key = stadium_node_key(10), other = stadium_node_key(11);
Session *s;
CHECK(!vm_uuid_is_hera(key) && !vm_uuid_is_none(key), "a node's key is neither Hera's (all-zero) nor none");
CHECK(!vm_uuid_equal(key, other), "two nodes, two keys");
CHECK(vm_uuid_equal(key, stadium_node_key(10)), "a node's key is the same each time");
CHECK(stadium_boot_init_for(key) == 0 && stadium_is_initialized(), "the Stadium is made with the node's key first");
CHECK(session_boot_init() == 0, "the sessions");
CHECK(stadium_quota_slot_for_vm(key) == 0, "the node holds the first quota");
CHECK(stadium_quota_slot_for_vm(vm_uuid_hera()) < 0, "and Hera's all-zero key none");
CHECK(stadium_reservoir_peek(key) == Q48_ONE, "its reservoir holds the whole share, 1.0");
CHECK(stadium_birth_node(key, "Hera") == 0, "the node is born");
s = session_find(key);
CHECK(s != 0 && s->stadium_cell == 0, "on cell 0, patron zero, its session registered");
CHECK(session_is_pinned(key), "and pinned");
CHECK(stadium_conserved(key), "conservation holds: resident heat and reservoir sum to 1.0");
CHECK(stadium_birth_node(key, "Hera") == 0 && session_find(key) == s, "born twice is born once");
return DONE();
}
+90
View File
@@ -0,0 +1,90 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* test_stadium_ops.c -- kernel/src/vm/stadium_ops.c on the host (#189, plan
* 2026-11-13-engine-step4-phase1, Task 3): HEAT-OP into the Stadium (Captain Bob, 2026-11-12: "Add
* HEAT-OP ... Both"; 2026-11-13: "Per heartbeat tick"). A node's 32 opcodes are patrons; at a charge,
* each opcode's retirements since the last are charged as that many of the word layer's dispatches --
* the same quantum, the same floor on the reservoir -- and a resident one cools by the ticks since,
* as a word does. Conservation holds throughout.
*/
#include "harness.h"
#include "starkernel/vm/stadium.h"
#include "starkernel/vm/stadium_ops.h"
#include "starkernel/session.h"
#include "starkernel/vm_uuid.h"
#include "starkernel/kmalloc.h"
#include "starkernel/q48_16.h"
#include "starforth_config.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
void *kmalloc(size_t size) { return calloc(1, size); }
void kfree(void *ptr) { free(ptr); }
kmalloc_stats_t kmalloc_get_stats(void)
{
kmalloc_stats_t s;
memset(&s, 0, sizeof s);
s.free_bytes = 512u * 1024u * 1024u; /* room for more than one quota, as on the boot (50 VM slots) */
return s;
}
void log_message(int level, const char *fmt, ...) { (void)level; (void)fmt; }
void sk_hal_panic(const char *message) { printf("PANIC: %s\n", message); exit(2); }
int blk_flush(uint32_t block_num) { (void)block_num; return 0; }
int main(void)
{
VMUuid key = stadium_node_key(10);
uint64_t counts[32], before, h20, r, q = (uint64_t)STADIUM_WORD_HEAT_QUANTUM;
unsigned k, hot = 0;
CHECK(stadium_boot_init_for(key) == 0 && session_boot_init() == 0 && stadium_birth_node(key, "Hera") == 0,
"a Stadium with the node born in it");
stadium_ops_init();
memset(counts, 0, sizeof counts);
stadium_ops_charge(key, counts, 1);
for (k = 0; k < 32; k++) if (stadium_ops_heat(key, k) != 0) hot++;
CHECK(hot == 0 && stadium_reservoir_peek(key) == Q48_ONE, "no retirements, no heat: the reservoir holds 1.0");
counts[20] = 5; /* + retired five times */
before = stadium_reservoir_peek(key);
stadium_ops_charge(key, counts, 2);
h20 = stadium_ops_heat(key, 20);
CHECK(h20 == 5u * q && stadium_reservoir_peek(key) == before - 5u * q,
"five retirements of + are five dispatches' heat, pulled from the reservoir (%llu)", (unsigned long long)h20);
CHECK(stadium_ops_heat(key, 21) == 0, "and no other opcode is heated");
CHECK(stadium_conserved(key), "conservation holds");
stadium_ops_charge(key, counts, 12); /* ten ticks later, nothing retired */
CHECK(stadium_ops_heat(key, 20) < h20 && stadium_reservoir_peek(key) > before - 5u * q,
"with nothing retired, + cools over ten ticks, back to the reservoir");
CHECK(stadium_conserved(key), "conservation holds");
counts[24] = (uint64_t)1 << 40; /* dup, very many times */
stadium_ops_charge(key, counts, 13);
r = stadium_reservoir_peek(key);
CHECK(r >= Q48_ONE / 3, "a flood of retirements leaves the reservoir its floor, a third (%llu)", (unsigned long long)r);
CHECK(stadium_ops_heat(key, 24) > 0 && stadium_conserved(key), "dup is heated, and conservation holds");
CHECK(stadium_ops_heat(vm_uuid_hera(), 20) == 0, "a key with no quota has no opcode heat");
/* more wanted than the reservoir has: shared by retirements, not by the order the opcodes are
* charged in -- a low-numbered opcode retired a little does not take it all */
{
VMUuid k2 = stadium_node_key(12);
uint64_t c2[32], h0, h5;
CHECK(stadium_grant_quota(k2, key) == 0, "a second node, its own quota");
memset(c2, 0, sizeof c2);
c2[0] = 1000000; /* ; retired a million times */
c2[5] = 3000000; /* next three million */
stadium_ops_charge(k2, c2, 20);
h0 = stadium_ops_heat(k2, 0); h5 = stadium_ops_heat(k2, 5);
CHECK(h0 > 0 && h5 > 0, "both opcodes are heated (; %llu, next %llu)", (unsigned long long)h0, (unsigned long long)h5);
CHECK(h5 > 2u * h0 && h5 < 4u * h0, "in proportion to their retirements, about 3 to 1");
CHECK(stadium_reservoir_peek(k2) >= Q48_ONE / 3 && stadium_conserved(k2), "the floor kept, conservation held");
}
return DONE();
}