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
+4 -2
View File
@@ -106,7 +106,7 @@ static void rom_boot(v4_node *n)
/* THE SYSTEM, AS THE MACHINE BUILDS IT (MACHINE.md section 6, step 1). The
* system's source, capsules/v4/sys (V4_SYS_DIR): the map, the fourteen and
* the end, each followed by a new line, then EOT -- what v4/system/boot.c
* the end, each followed by a new line and V4_ROM_BLOB_END, then EOT -- what v4/system/boot.c
* feeds the console. rom_system_text gives it whole, *len its length;
* rom_build_system has `n`, booted with its ROM, assemble it, and runs it to
* its start: 1 if it started, with *words the instruction words it took. */
@@ -129,12 +129,13 @@ static char *rom_system_text(size_t *len)
f = fopen(path, "rb");
if (!f) { printf(" cannot read %s\n", path); free(text); return NULL; }
fseek(f, 0, SEEK_END); n = ftell(f); fseek(f, 0, SEEK_SET);
if (n < 0 || total + (size_t)n + 2 > cap || fread(text + total, 1, (size_t)n, f) != (size_t)n) {
if (n < 0 || total + (size_t)n + 3 > cap || fread(text + total, 1, (size_t)n, f) != (size_t)n) {
fclose(f); free(text); return NULL;
}
fclose(f);
total += (size_t)n;
text[total++] = '\n'; /* a blob that does not end with a new line still ends a token */
text[total++] = V4_ROM_BLOB_END; /* and the blob ends, as a file ends for text.c */
}
text[total++] = 4; /* EOT */
*len = total;
@@ -157,6 +158,7 @@ static int rom_build_system(v4_node *n, long *words)
if (w % 1000 == 0 && n->mem[ROM_FAILED] != 0) break;
}
free(text);
n->input_pos = n->input_len = 0; /* what was not read is the source's: boot.c takes it back */
if (words) *words = w;
return n->p < V4_ROM_BASE && n->mem[ROM_FAILED] == 0;
}