fix(v4): the final review's four defects in the ROM boot

- The boot left the source's last new line in the console input, and the
  first KEY after the boot read it.  What the ROM has not read when it
  starts the system is taken back (boot.c, rom_harness.h).  hosted-check:
  KEY after the boot reads the key typed.
- A comment or macro left open at the end of a blob ran on into the next,
  and the ROM accepted source text.c refuses.  The loader ends each blob
  with FS (V4_ROM_BLOB_END) after its new line; the ROM ends a blob there
  as text.c ends a file: an open comment or macro is an error, and the word
  being assembled ends.  test_host_rom_asm: seven blob pairs against text.c.
- store to an address outside RAM faulted the ROM with no message.  It is
  now refused, as text.c refuses it: ERR-RANGE, "address out of range".
- The kernel build did not regenerate capsules/v4/sys/map-<w>.f18 before
  packing the capsule directory; it now does.

ROM: 2084 words, rom_hash 0x4c458c6e48b35456.  dict_hash unchanged,
0xe5a57f3eb72ff94a.  make -C v4 test test-32 hosted-check pass.  QEMU:
amd64, aarch64, riscv64 to ok>, POST 538/538, POST: PASSED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-15 16:35:07 -04:00
co-authored by Claude Opus 5.5
parent a73580e949
commit ff75e69e91
14 changed files with 592 additions and 16 deletions
+61 -1
View File
@@ -38,7 +38,7 @@ static v4_cell code_of(const char *m)
{ "write the number", ROM_ERR_FETCH_P }, { "too many unresolved", ROM_ERR_REFS },
{ "not a value", ROM_ERR_VALUE }, { "not a number", ROM_ERR_VALUE },
{ "too many names", ROM_ERR_NAMES }, { "out of name space", ROM_ERR_NAMES },
{ "without", ROM_ERR_MISSING },
{ "address out of range", ROM_ERR_RANGE }, { "without", ROM_ERR_MISSING },
};
unsigned i;
for (i = 0; i < sizeof map / sizeof map[0]; i++) if (strstr(m, map[i].s)) return map[i].c;
@@ -117,6 +117,45 @@ static void same(const char *text)
}
/* text.c on each blob as a file of its own, as the host tests and text.c
* read the system; the ROM on the same blobs as the boot feeds them, each
* followed by a new line and V4_ROM_BLOB_END (Review Focus 1: a blob that
* ends mid-comment, mid-macro or mid-word). */
static void same_blobs(const char *const *blobs, unsigned count)
{
unsigned i;
int okA = 1, rb;
v4_cell w, hereA;
v4_node_reset(&a);
v4_text_begin(&tx, &a, ROM_ORIGIN);
for (i = 0; i < count && okA; i++) okA = v4_text_assemble(&tx, blobs[i]);
okA = okA && v4_text_assemble(&tx, ": ZZEND ;") && v4_text_finish(&tx);
in[0] = 0;
for (i = 0; i < count; i++) {
size_t l = strlen(in);
snprintf(in + l, sizeof in - l, "%s\n%c", blobs[i], (char)V4_ROM_BLOB_END);
}
strcat(in, ": ZZEND ;\nstart ZZEND\n\x04");
rb = rom_run(in);
if (okA) {
hereA = v4_text_here(&tx);
CHECK(rb == 1, "[%s | %s] text.c accepts; the ROM %s (code %ld)", blobs[0], blobs[count - 1],
rb == 0 ? "refused" : "did not finish", (long)b.mem[ROM_FAILED]);
if (rb != 1) return;
CHECK(b.p == v4_text_word(&tx, "ZZEND"), "[%s | %s] the ROM started at ZZEND", blobs[0], blobs[count - 1]);
for (w = ROM_ORIGIN; w < hereA; w++) if (a.mem[w] != b.mem[w]) break;
CHECK(w == hereA, "[%s | %s] word %ld differs", blobs[0], blobs[count - 1], (long)w);
} else {
const char *m = v4_text_error(&tx);
CHECK(rb == 0, "[%s | %s] text.c refuses (%s); the ROM %s", blobs[0], blobs[count - 1], m,
rb == 1 ? "accepted" : "did not finish");
if (rb != 0) return;
CHECK(b.mem[ROM_FAILED] == code_of(m), "[%s | %s] text.c: %s; ROM code %ld, want %ld", blobs[0], blobs[count - 1], m,
(long)b.mem[ROM_FAILED], (long)code_of(m));
}
}
int main(void)
{
unsigned i;
@@ -186,6 +225,27 @@ int main(void)
for (i = 0; i < 260u; i++) if (b.mem[TIB_W + (v4_cell)i] != 0) break;
CHECK(i == 260u, "the text input buffer is cleared: cell %u is not", i);
/* blobs: each ends as a file ends for text.c (Review Focus 1) */
{
static const char *const comment[] = { ": A ;\n( a comment left open", ": B 1 ; )" };
static const char *const macro[] = { "macro M 1", "endmacro : A M ;" };
static const char *const nfor[] = { ": A 3 FOR", "NEXT ;" };
static const char *const label[] = { ": A L1: 1", "jump L1 ;" };
static const char *const bsl[] = { ": A ;\n\\ a comment with no new line", ": B A ;" };
static const char *const word[] = { ": A 1", "2 ;" };
static const char *const closed[] = { "( closed ) : A ;", ": B A ;" };
same_blobs(comment, 2); same_blobs(macro, 2); same_blobs(nfor, 2); same_blobs(label, 2);
same_blobs(bsl, 2); same_blobs(word, 2); same_blobs(closed, 2);
}
/* store outside RAM: refused with an error, as text.c refuses it, not a fault */
{
static char t[80];
same("store -1 5");
snprintf(t, sizeof t, "store %ld 5", (long)V4_NODE_WORDS); same(t);
snprintf(t, sizeof t, "store %ld 5", (long)V4_NODE_WORDS - 1); same(t);
}
printf("test_host_rom_asm: %d checks, %d failures\n", checks, failures);
return failures != 0;
}