ENGINE step 4 Phase 2 (plan docs/v4.0.0/plans/2026-11-13-engine-step4-phase2-word-accounts.md). Rulings, Captain Bob 2026-11-13: "ID field in the header"; "Per heartbeat tick"; the ACL "All of it in Phase 4". - The word ID, at xt-4 before the flags (ENGINE.md 3b). The system's words are numbered as they are assembled, by a new directive, #id, (and #ids, the count), in the C assembler (text.c) and in the machine ROM's (capsules/v4/rom), which counts in the system's own (NEXT-ID). (HEADER) numbers later words; FORGET gives back the IDs it frees, always the newest; COLD resets to (BOOT-ID); (SEAL) records it. All 313 system headers carry the cell. - The kernel's records (v4/mesh.h): (TELL-DEFINED) and (TELL-FORGOTTEN), requests -19/-20 on port 0, which the kernel puts in (WORD-DEFINED)/(WORD-FORGOTTEN) when it seals a node, and reads the system's own words once. A bit per address marks a word's xt (calls into the ROM or headerless code are not words); at call, the bit test and a count. v4_mesh_charge hands the owner the calls since. - The Stadium: stadium_words_charge -- N calls as N of stadium_word_dispatch's dispatches, shared by calls when the reservoir is short; sk_v4.c charges every node's words at the tick beside its opcodes, and stadium_word_forget before an ID is used again. - Tests first: test_text.c, test_host_dict.c, test_host_quit.c (numbering, FORGET, COLD), test_mesh_boot.c (44 checks), kernel/tests/test_stadium_words.c; qemu_session.py: Hera's words admitted after POST. - amd64: Stadium words: promotions=141 after POST, CONSERVED; POST 539/539; word_count=377; dict_hash 0xa854ba15b437d288 (the new cell); the boot 142 s against Phase 1's 153 s. - v4 test, test-32: all pass; v4-checks: 80 programs under the sanitizers, 0 failures; the hosted builds alike. docs/reference/v4-dictionary.tsv: the two new words; FABRIC-3 XLVIII.24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
83 lines
2.7 KiB
C
83 lines
2.7 KiB
C
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
|
|
* Copyright (c) 2023-2026 Robert A. James
|
|
*/
|
|
/* image.c -- the StarForth system, as its host knows it. See image.h.
|
|
*
|
|
* Nothing here uses the C library: the bare-metal kernel links this file.
|
|
*/
|
|
#include "v4/image.h"
|
|
|
|
int v4_image_born(v4_node *n, v4_exec_state *es, v4_heat *h, const v4_image *im)
|
|
{
|
|
if (im->cell_bits != (unsigned)V4_CELL_BITS || im->node_words != (unsigned)V4_NODE_WORDS
|
|
|| im->data_ring != (unsigned)V4_DATA_RING || im->ret_ring != (unsigned)V4_RET_RING)
|
|
return 0;
|
|
|
|
v4_node_born(n, im->port);
|
|
v4_exec_reset(es);
|
|
v4_heat_reset(h);
|
|
|
|
v4_node_console_attach(n, im->console_tx);
|
|
v4_node_console_input_attach(n, im->console_rx, im->console_status);
|
|
v4_node_stack_regs_attach(n, im->dstack_reg, im->rstack_reg);
|
|
v4_node_error_attach(n, im->node_error);
|
|
v4_node_heat_regs_attach(n, im->heat_reg, h->op, &es->anticlock);
|
|
v4_node_fault_attach(n, im->fault_table);
|
|
return 1;
|
|
}
|
|
|
|
int v4_image_from_node(const v4_node *n, v4_image *im)
|
|
{
|
|
v4_cell r = im->record, idle, faults, key, key_end;
|
|
if (r < 0 || r + 3 >= (v4_cell)V4_NODE_WORDS) return 0;
|
|
idle = n->mem[r]; faults = n->mem[r + 1]; key = n->mem[r + 2]; key_end = n->mem[r + 3];
|
|
if (idle <= 0 || idle >= (v4_cell)V4_NODE_WORDS || faults <= 0 || faults >= (v4_cell)V4_NODE_WORDS
|
|
|| key <= 0 || key_end <= key || key_end >= (v4_cell)V4_NODE_WORDS)
|
|
return 0;
|
|
im->idle = idle;
|
|
im->fault_table = faults;
|
|
im->key_start = key;
|
|
im->key_end = key_end;
|
|
return 1;
|
|
}
|
|
|
|
int v4_image_waiting(const v4_node *n, const v4_image *im)
|
|
{
|
|
return n->input_pos == n->input_len && n->p >= im->key_start && n->p < im->key_end;
|
|
}
|
|
|
|
void v4_image_seal(v4_node *n, const v4_image *im)
|
|
{
|
|
n->mem[im->boot_cells] = n->mem[im->dp];
|
|
n->mem[im->boot_cells + 1] = n->mem[im->latest];
|
|
n->mem[im->fence] = (n->mem[im->dp] + 3) / 4;
|
|
n->mem[im->boot_id] = n->mem[im->next_id];
|
|
}
|
|
|
|
/* FNV-1a over the node's memory below HERE, a cell at a time, low byte
|
|
* first, and then LATEST. */
|
|
#define FNV_OFFSET 0xcbf29ce484222325ULL
|
|
#define FNV_PRIME 0x00000100000001b3ULL
|
|
|
|
static uint64_t hash_cell(uint64_t h, v4_cell c)
|
|
{
|
|
v4_ucell u = (v4_ucell)c;
|
|
unsigned i;
|
|
for (i = 0; i < V4_CELL_BITS / 8; i++) {
|
|
h ^= (uint64_t)((u >> (8 * i)) & 0xffu);
|
|
h *= FNV_PRIME;
|
|
}
|
|
return h;
|
|
}
|
|
|
|
uint64_t v4_image_dict_hash(const v4_node *n, const v4_image *im)
|
|
{
|
|
uint64_t h = FNV_OFFSET;
|
|
v4_cell here = (n->mem[im->dp] + 3) / 4, k;
|
|
|
|
if (here < 0) here = 0;
|
|
if (here > (v4_cell)V4_NODE_WORDS) here = (v4_cell)V4_NODE_WORDS;
|
|
for (k = 0; k < here; k++) h = hash_cell(h, n->mem[k]);
|
|
return hash_cell(h, n->mem[im->latest]);
|
|
}
|