Files
StarForth/src/starkernel/artemis_sig.c
T
Robert Allan JamesandClaude Sonnet 5 29b6789860 Artemis bus-agnostic discovery: signature format + idle-loop generalization (FABRIC-3.md §XXVI follow-on)
Step 1: new artemis_sig_t header format (magic 'ARTM', sibling to
homeblocks_sig_t, distinct so a generic scan can tell Artemis's own disk
apart from an identity thumbdrive by content alone) -- artemis_sig.h/.c,
wired into Makefile.starkernel.

Step 2: sk_repl_idle()'s existing per-USB-MSC-slot attach handling (the
pattern WIREBIND already uses for identity thumbdrives) now also checks
for the ARTM signature whenever a device's home-blocks check comes back
BLANK. On a match, once Artemis's own storage-attach round-trip
(HERA-BLK-ATTACH-REQ/BLK-ATTACH-ACK) confirms success,
capsule_zuse_boot_load_root_pubkey() runs -- the same call kernel_main.c's
synchronous QEMU-only virtio-blk path already makes, now reachable
without a hardcoded PCI vendor/device scan. That function is already
idempotent (no-op once zuse_root_pubkey_known is set), so no boot
restructuring was needed despite the initial concern that deferring
Artemis discovery to the idle loop would require one.

Verified: clean build + QEMU boot to [zuse@Hera] ok> on all three
architectures, zero regression to the existing virtio-blk/Zuse-thumbdrive
attach path.

Steps 3 (genesis-stamping onto disk/artemis.img) and 4 (growable
production log-persistence region) not yet started.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXieurDfDSsDFdnSyusuWo
2026-09-13 07:16:48 -04:00

88 lines
3.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
StarForth — Steady-State Virtual Machine Runtime
Copyright (c) 2023–2025 Robert A. James
All rights reserved.
This file is part of the StarForth project.
Licensed under the StarForth License, Version 1.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
express or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose, and noninfringement.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* artemis_sig.c - Artemis disk signature check (FABRIC-3.md §XXVI follow-on).
* See starkernel/artemis_sig.h for the format and interface design.
*/
#include "starkernel/artemis_sig.h"
#include <stddef.h>
#include <string.h>
#include "blkio.h"
#include "block_subsystem.h" /* compute_crc64() -- same CRC-64/ISO
* homeblocks_sig.c's own check reuses,
* not duplicated here either */
uint64_t artemis_sig_compute_crc(const artemis_sig_t *sig) {
/* Covers every field up to but not including hdr_crc itself (and never
* _pad, which sits after it) -- offsetof is the exact boundary, same
* discipline as homeblocks_sig_compute_crc(). */
size_t crc_span = offsetof(artemis_sig_t, hdr_crc);
return compute_crc64((const uint8_t *)sig, crc_span);
}
artemis_sig_result_t artemis_sig_check(struct blkio_dev *dev,
uint32_t sig_start_fblock,
artemis_sig_t *out_sig) {
uint8_t buf[4096];
uint32_t i;
artemis_sig_t local;
uint64_t expected_crc;
if (!dev) return ARTEMIS_SIG_READ_ERROR;
/* artemis_sig_t is exactly one 4KiB devblock; blkio's own unit is a
* 1KiB "forth block" (BLKIO_FORTH_BLOCK_SIZE), so the header spans 4
* consecutive reads starting at sig_start_fblock -- same pattern as
* homeblocks_sig_check(). */
for (i = 0; i < 4; i++) {
if (blkio_read((blkio_dev_t *)dev, sig_start_fblock + i,
buf + (size_t)i * BLKIO_FORTH_BLOCK_SIZE) != BLKIO_OK) {
return ARTEMIS_SIG_READ_ERROR;
}
}
/* Copy into a properly-aligned local rather than reinterpreting buf's
* address directly -- same strict-aliasing/alignment reasoning as
* homeblocks_sig_check(). */
memcpy(&local, buf, sizeof(local));
if (ARTEMIS_SIG_GET_MAGIC(local.magic) != (uint32_t)(ARTEMIS_SIG_MAGIC & 0xFFFFFFFFULL)) {
return ARTEMIS_SIG_BLANK;
}
if (ARTEMIS_SIG_GET_VERSION(local.magic) != ARTEMIS_SIG_VERSION_0) {
return ARTEMIS_SIG_BAD_VERSION;
}
expected_crc = artemis_sig_compute_crc(&local);
if (expected_crc != local.hdr_crc) {
return ARTEMIS_SIG_BAD_CRC;
}
if (out_sig) *out_sig = local;
return ARTEMIS_SIG_OK;
}