feat(v4.0.0): the system boots from a nucleus and loads its capsules
One boot, v4/system/boot.c, for both products: it starts the nucleus image, finds each capsule in the baked capsule directory, recomputes its hash, checks its signature, gives its blocks to the node a line at a time, and prints PARITY:V4_NUCLEUS, PARITY:V4_CAPSULE and PARITY:OK before the prompt. A line the node does not accept ends the boot with the capsule, block and line named. docs/v4.0.0/NUCLEUS.md. - hosted Linux product for amd64, aarch64 and riscv64 (make -C v4 hosted); make -C v4 hosted-check boots all three and requires identical output - the kernel's v4 entry (STARFORTH_V4=1) calls the same boot - capsules/v4/forth79.4th, block 6000: no definitions yet - mkimage builds the nucleus only; no FORTH source is compiled at build time - capsule_blocks.c: the Block-header parse, free of any VM, for every loader Verified: make -C v4 test passes; hosted-check passes on the three ISAs with the same hashes; the kernel compiles with STARFORTH_V4=1 on the three. Not verified: no bare-metal boot of v4 has been run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
903321e548
commit
294e69463a
@@ -0,0 +1,29 @@
|
||||
/* capsule_blocks.c -- the block format of a .4th capsule payload.
|
||||
* See capsule_blocks.h. Nothing here uses the C library or a VM.
|
||||
*/
|
||||
#include "starkernel/capsule_blocks.h"
|
||||
|
||||
int capsule_block_header(const uint8_t *p, const uint8_t *end,
|
||||
uint32_t *out_num, const uint8_t **out_after)
|
||||
{
|
||||
const uint8_t *q;
|
||||
uint32_t num = 0;
|
||||
|
||||
if ((uint64_t)(end - p) < 7u) return 0;
|
||||
if (p[0] != 'B' || p[1] != 'l' || p[2] != 'o' || p[3] != 'c' || p[4] != 'k' || p[5] != ' ')
|
||||
return 0;
|
||||
|
||||
q = p + 6;
|
||||
if (q >= end || *q < '0' || *q > '9') return 0;
|
||||
while (q < end && *q >= '0' && *q <= '9') {
|
||||
num = num * 10u + (uint32_t)(*q - '0');
|
||||
q++;
|
||||
}
|
||||
|
||||
while (q < end && *q != '\n') q++;
|
||||
if (q < end) q++;
|
||||
|
||||
*out_num = num;
|
||||
*out_after = q;
|
||||
return 1;
|
||||
}
|
||||
@@ -81,6 +81,9 @@ EFI_RUNTIME_SERVICES *g_sk_runtime_services = NULL;
|
||||
log.h's line length (LOG_MSG_LINE_MAX, 256)
|
||||
are distinct names */
|
||||
#include "version.h"
|
||||
#ifdef STARFORTH_V4
|
||||
#include "starkernel/v4/sk_v4.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Forward declaration — kernel_main_deep contains everything from heartbeat
|
||||
@@ -512,6 +515,14 @@ static void kernel_main_deep(BootInfo *boot_info) {
|
||||
console_println("Kernel initialization complete.");
|
||||
console_println("Boot successful!\n");
|
||||
|
||||
#ifdef STARFORTH_V4
|
||||
/* StarForth v4 at a single prompt (Kconfig STARFORTH_V4): one host node
|
||||
* of the F18-derived engine, in place of the v3 VM and everything below.
|
||||
* It does not return. */
|
||||
(void)boot_info;
|
||||
sk_v4_run();
|
||||
#endif
|
||||
|
||||
#ifdef STARFORTH_ENABLE_VM
|
||||
/* Stadium: boot-time allocation (FABRIC-0.md item 3.2), before any VM
|
||||
* exists (§6). Soft failure -- nothing downstream consumes the Stadium
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/* sk_v4.c -- StarForth v4 on bare metal: one host node at a prompt.
|
||||
*
|
||||
* The node is the golden model of the F18-derived engine (v4/src). It comes
|
||||
* up as the hosted v4 system does, by v4_boot_run (v4/include/v4/boot.h):
|
||||
* the nucleus image, then the capsules from the directory baked into this
|
||||
* kernel, each checked and its parity line printed, then the prompt.
|
||||
* docs/v4.0.0/NUCLEUS.md. This file is all the kernel adds:
|
||||
*
|
||||
* - what the node prints goes to the kernel's console;
|
||||
* - what is typed is given to the node a line at a time. The node does
|
||||
* not send back what it reads -- on the mesh that is the console node's
|
||||
* job -- so the line is edited here: characters are echoed, backspace
|
||||
* rubs one out, and Enter hands the line over;
|
||||
* - blocks are kept in memory, and are gone at power-off.
|
||||
*
|
||||
* Nothing of the v3 VM is started. docs/v4.0.0/DECOMPOSITION.md.
|
||||
*/
|
||||
#include "starkernel/v4/sk_v4.h"
|
||||
#include "starkernel/console.h"
|
||||
#include "v4/boot.h"
|
||||
|
||||
#define SK_V4_BLOCKS 64u
|
||||
#define SK_V4_LINE 79u /* QUERY takes 80 characters: 79 and the new-line */
|
||||
|
||||
static v4_node sk_v4_node;
|
||||
static v4_exec_state sk_v4_es;
|
||||
static v4_heat sk_v4_heat;
|
||||
static unsigned char sk_v4_disk[SK_V4_BLOCKS * V4_BLOCK_BYTES];
|
||||
|
||||
static char sk_v4_line[SK_V4_LINE + 1u];
|
||||
static unsigned sk_v4_len;
|
||||
|
||||
/* One character from the keyboard. A finished line goes to the node. */
|
||||
static void sk_v4_key(int c)
|
||||
{
|
||||
if (c == '\r' || c == '\n') {
|
||||
console_putc('\n');
|
||||
sk_v4_line[sk_v4_len++] = '\n';
|
||||
(void)v4_node_console_feed(&sk_v4_node, sk_v4_line, sk_v4_len);
|
||||
sk_v4_len = 0;
|
||||
} else if (c == 8 || c == 127) {
|
||||
if (sk_v4_len > 0) {
|
||||
sk_v4_len--;
|
||||
console_putc(8); console_putc(' '); console_putc(8);
|
||||
}
|
||||
} else if (c >= 32 && c < 127 && sk_v4_len < SK_V4_LINE) {
|
||||
sk_v4_line[sk_v4_len++] = (char)c;
|
||||
console_putc((char)c);
|
||||
}
|
||||
}
|
||||
|
||||
static void sk_v4_out(const char *text, unsigned len)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < len; i++) console_putc(text[i]);
|
||||
}
|
||||
|
||||
void sk_v4_run(void)
|
||||
{
|
||||
const v4_image *im = &v4_capsule_image;
|
||||
v4_boot boot;
|
||||
unsigned i;
|
||||
|
||||
console_println("StarForth v4: one host node, the F18-derived engine");
|
||||
boot.n = &sk_v4_node; boot.es = &sk_v4_es; boot.h = &sk_v4_heat; boot.im = im; boot.out = sk_v4_out;
|
||||
if (!v4_boot_run(&boot, sk_v4_disk, SK_V4_BLOCKS)) {
|
||||
console_println("StarForth v4: not started");
|
||||
for (;;) { }
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
(void)v4_exec_step_word(&sk_v4_node, &sk_v4_es, &sk_v4_heat);
|
||||
if (sk_v4_node.console_len) {
|
||||
for (i = 0; i < sk_v4_node.console_len; i++) console_putc((char)sk_v4_node.console[i]);
|
||||
sk_v4_node.console_len = 0;
|
||||
}
|
||||
if (sk_v4_node.stopped) {
|
||||
console_println("StarForth v4: the node stopped on a fault");
|
||||
for (;;) { }
|
||||
}
|
||||
if (v4_image_waiting(&sk_v4_node, im)) {
|
||||
int c = console_getc();
|
||||
if (c >= 0) sk_v4_key(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user