16 Commits
Author SHA1 Message Date
Claude 9077618c49 logs: the developer protocol on e0dcaa16 -- PASS, all eight stages
Build / Image RASPI (push) Successful in 9m57s
Build / Image PC (push) Successful in 11m0s
Build / Image MILKV (push) Successful in 5m18s
Build / v4 tests (32- and 64-bit cells) (push) Successful in 11m33s
Acceptance / Acceptance (pull_request) Successful in 27m34s
logs/20261112-185800/PROTOCOL.md, for #142, #173, #174 and the notes: the four
boots 538/538, word_count=318, dict_hash 0x8c92508f748f99cf on all three; the
new post-count stage (#173) on the real boots: all four at or above the floor,
all passed; test-32 39 programs, 1,869,223 checks, 0 failures; the proofs
(40 s); the images; the documents. The tree clean before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 19:29:28 +00:00
Claude e0dcaa163b notes: the release order, the documents last; the floor, the signing, the host tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:57:50 +00:00
Claude b0038376a7 ci: the gate into master refuses an unsigned build (#174)
Captain Bob, 2026-11-12: "Yes, reject unsigned builds". acceptance.yml's
"The capsule-signing key" step warned when CAPSULE_SIGN_KEY was missing and
the PR's acceptance went on, unsigned. Now it is an ::error:: and the step
fails, so the gate does too. A local or protocol build may still be unsigned
(kernel/Makefile, v4/Makefile): the refusal is the gate's. build.yml,
nightly.yml and release.yml still warn -- release.yml is Captain Bob's to rule.

scripts/test_acceptance_signing.sh takes the step from acceptance.yml as CI
runs it and runs it with and without a key. Against the workflow as it was:
the unsigned case passed, no error -- 2 failures. Now: no key fails with an
::error::, a key is handed to the build as SIGN_KEY. logs/20261112-185739/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:57:39 +00:00
Claude 947d044872 logs: #173's tests against nightly.sh before the stage, run for real
4738aee4's log has a placeholder where the run against the code before #173
belongs ("see the session") -- not evidence. Rerun against
scripts/nightly.sh as it was (4738aee4~1): every one of the 7 cases fails,
the stage not existing. post-count-before-rerun.log; the first log is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:56:32 +00:00
Claude 4738aee4c0 ci: acceptance asserts POST's test count against a floor in the tree (#173)
Captain Bob, 2026-11-12: "Yes". Acceptance checked POST: PASSED, so a POST
that lost cases still passed. Now scripts/nightly.sh post-count, which the
stick-high stage runs after dict-hash: each of the four boots must report
PARITY:V4_POST with every test passed and at least the floor's tests --
v4/system/POST_FLOOR, 538 today, raised when POST grows and never lowered
without Captain Bob. A boot with no POST line, not run, or no floor file is
refused, not skipped.

scripts/test_nightly_post_count.sh, written first and seen to fail (the stage
not existing), then 7 cases: 538 and 600 pass; fewer than the floor, a
failure, no POST line, a boot not run, no floor -- refused. Run on the boots
of the last protocol (d7b2f6bf): all four 538 of 538. logs/20261112-185620/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:56:20 +00:00
Claude e453fde3d4 fix(v3): the DoE row's cache and bucket hits are measured, not written as 0 (#142)
Captain Bob, 2026-11-12: "correct deficiencies". heartbeat_capture_tick_snapshot
wrote cache_hits_delta and bucket_hits_delta as 0 ("TODO: wire ..."), though
physics_hotwords_cache.c counts both. Now each is read from the VM's hot-words
cache as a delta since the previous tick, the way word_executions_delta is
(and after the cache's stats are reset, the count since then); a VM with no
cache has 0. word_executions_delta was measured already: doe_log.c's "TODO: 0"
for it was stale, and its three column notes are corrected.

kernel/tests/test_heartbeat_export.c, 4 checks: a VM in memory with a cache
whose counters the test sets, captured tick by tick. Against the code as it
was: 3 failures (the hits 0 where the cache counted 5 and 3, then 7 and 7).
Now: 0. Built for amd64, aarch64, riscv64 and the hosted v3. Shared v3 code,
under the ruling. v3 is not part of acceptance; no DoE has run since 2026-09-16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:55:30 +00:00
Claude 83898b524d logs: the developer protocol on d7b2f6bf -- PASS, all eight stages
logs/20261112-182015/PROTOCOL.md, for the kernel host-test chunk: the harness
and #170, #171, #176, #177, #178, #182. The four boots 538/538 -- a data stick
enumerating through the moved USB descriptor walk, genesis through the identity
code's new seed handling -- word_count=318, dict_hash 0x8c92508f748f99cf on all
three; test-32 39 programs, 1,869,223 checks, 0 failures; the proofs (37 s);
the images, no race; the documents. The tree clean before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:48:21 +00:00
Claude d7b2f6bf54 fix(v4): the identity code wipes Zuse's seed after every drive it handles (#176, the identity code)
sk_v4_genesis never wiped its seed or its read-back; sk_v4_drive_arrived
never wiped the proxy's seed after her login; sk_v4_real_zuse_arrived wiped
the seed only on a match. (The logged-in Zuse's own key stays in g_zuse_seed,
by design.)

Option 1: the three use one buffer the identity module owns, g_seeds (seed,
then its read-back), and sk_v4_drive_arrived -- which every drive goes through,
and which alone calls the other two -- runs the drive's handling (now
handle_drive()) and then wipes it, whichever way it went.
sk_v4_identity_seeds() lets the host tests read it.

kernel/tests/test_sk_v4_identity.c, 10 checks, through the real drive-arrival
path: a fake xHCI controller marks a slot attach-pending, the identity code's
idle beat handles it, the real gpt.c reads the stick's table from the RAM disk;
the block layer, signatures, key mint, marker and console faked. Genesis; a
genesis not read back; the proxy logging in; a real Zuse named, then her stick
logging in. Against the code before the wipe: 5 failures (every case's seeds
left). Now: 0. The harness gains fake_disk_bind. Built for amd64, aarch64,
riscv64. #176 done with 2bac2ac8 (the mint).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:20:09 +00:00
Claude 2bac2ac8fc fix(v4): MINT-ZUSE wipes Zuse's seed on every return, not only on success (#176, the mint)
sk_v4_mint_zuse wiped seed and rseed only when the real Zuse was minted; its
refusals and every failure after YES left them in stack memory.

Option 1 (Captain Bob, 2026-11-12: "1 is great"): the seeds are in a 64-byte
buffer the caller owns. sk_v4_mint_zuse_with(seeds) runs the mint (now a
private mint()) and then wipes the buffer, whichever way it returned -- one
place, every exit; sk_v4_mint_zuse() gives it a buffer of its own.

kernel/tests/test_sk_v4_mint.c, 17 checks: the real gpt.c on the RAM disk, the
identity code, key mint, signature checks, marker and keyboard faked; each of
the mint's eight exits run with the buffer filled with 0xEE first -- no stick,
under 64 MiB, not YES, the key mint failing, the read-back not hers, no
marker, the marker write failing, and minted. Against the mint as it was: 7
failures (every exit but success). Now: 0. Both runs in logs/20261112-181719/. Built for
amd64, aarch64, riscv64. The identity code's two (sk_v4_genesis,
sk_v4_real_zuse_arrived) follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:17:19 +00:00
Claude 3c053f02a6 fix(v4): the build refuses an Artemis cap its 32-bit block numbers cannot hold (#182)
sk_v4_grow.c's dev_rw4k computes 1 KiB block numbers as (uint32_t)devblock * 4,
which wraps past 4 TiB; Artemis is capped at 256 GiB (STICK_ARTEMIS_CAP_GIB,
kernel/Makefile), so it is latent -- but nothing said so where the cast is. Now
a compile-time check there (the C99 negative-array pattern the tree uses): a
cap past 4 TiB stops the build, and a cap not defined at all is an #error, not
a skipped check. gpt.c's casts are bounded by the disk's own size, itself a
32-bit count of 1 KiB blocks, checked before each: each now says so.

kernel/tests' check_cap, seen to fail first (a 4096 GiB cap built); now 3
checks, 0 failures -- 256 GiB builds, 4096 GiB and none refused. Built for
amd64, aarch64, riscv64. The plan's increments 2 and 3 marked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:07:23 +00:00
Claude 41f8648dd9 fix(v4): a controller's drive slots are allocated once, never replaced (#178)
sk_v4_idle allocated a controller's slot array again whenever max_slots + 1
was more than it held -- the old array dropped, neither copied nor freed --
while the identity code holds pointers into it (g_offered, g_spare,
g_pending_real, g_real_drive, g_zuse_dev). Its two slot loops then ran to
max_slots whatever the array held.

sk_v4_slots_get() (kernel/src/v4/sk_v4_slots.c): allocated once, zeroed, at the
size first asked for; never replaced; the slots that may be used are those it
has. sk_v4_idle uses it, and its loops stop at the array's end.

kernel/tests/test_sk_v4_slots.c, kmalloc_aligned faked, seen to fail first
against the allocation as it was (4 failures: replaced when more were asked
for, 17 said usable where 9 existed, a held pointer left behind, an allocation
for 0); now 6 checks, 0 failures. Built for amd64, aarch64, riscv64; latent
today (max_slots does not grow), so the boots show no change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:05:57 +00:00
Claude c778f6e0e7 fix(v4): the kernel's fatal stops halt, interrupts off, instead of spinning (#177)
sk_v4_run's three stops -- "not started", "did not let go of POST's
blocks", "stopped on a fault" -- ended in for (;;) { }: a core spinning at
100%, the thing #151 removed from the prompt. Each now calls sk_v4_stop()
(kernel/src/v4/sk_v4_stop.c): interrupts off, then arch_halt() for ever. Each
still says why first. sk_v4_stop.c added to the loader's and the kernel's v4
sources.

kernel/tests/test_sk_v4_stop.c, with arch_halt and arch_disable_interrupts
faked (the halt jumps back out after three calls; an alarm fails a spin):
against the stop as it was -- "spun for 2 s without halting"; now -- 2
checks, 0 failures: halts in a loop, interrupts off before the first halt.
Built for amd64, aarch64 and riscv64. #177's "seen on the three
architectures": no boot reaches these stops, so it is shown on the host only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:04:31 +00:00
Claude 8649463a58 logs: #170/#171's test against the old decision, run again correctly
a8824655's evidence log shows its "before" run failing to compile: the copy
of usb_config.c with the old decision was cut at the wrong brace by my script.
The failure the commit describes was real (seen in the session), but the log
did not show it. Rerun with a correct copy:
test_usb_config-before-rerun.log -- 20 checks, 10 failures (wTotalLength 1 to
9 asked for again; the cut unsaid). The first log is kept, as what it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:02:03 +00:00
Claude a882465573 fix(usb): a configuration of 9 bytes or less is refused, and a cut one is said (#170, #171)
After the configuration descriptor's first 9 bytes the event loop asked for
min(wTotalLength, 128) whatever it was. A wTotalLength of 9 or less was then
asked for again as "short" -- for ever, that slot never leaving enumeration
(#170); 0 also issued a zero-length data stage. A set longer than the 128-byte
buffer was cut without a word, its later interfaces never seen (#171).

The decision is usb_config_request_length() (moved out of the event loop,
then fixed): 9 or less is 0 -- "xhci: a configuration of N bytes has no
interface -- not used", and nothing more is asked; longer than the buffer is
cut and said -- "xhci: config of N bytes cut to 128 -- rest unseen" (at most
53 characters). The buffer stays 128 bytes; its size is #171's to rule.

kernel/tests/test_usb_config.c, seen to fail first against the decision as it
was (10 failures: wTotalLength 1 to 9 asked for again, the cut unsaid), now
20 checks, 0 failures. Both runs in logs/20261112-180140/kernel-tests/. Built for amd64,
aarch64 and riscv64; the boots come with the protocol. #171's other box, a
composite device on the SER5, is Captain Bob's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:01:40 +00:00
Claude 8b482bedb8 refactor(usb): the configuration-descriptor walk moved out of the event loop, unchanged
xhci.c's XHCI_XFER_CONFIG_DESC_FULL case walked the descriptor set inline, in
the event loop, where nothing could test it. The walk is now
usb_config_parse() (kernel/src/usb/usb_config.c), returning what it found;
the case acts on it as before -- the same messages, the same decisions: the
first Interface descriptor only, a BOT interface's bulk endpoints (the last of
each direction), a boot keyboard's first interrupt IN endpoint, bLength 0
ending the walk, nothing read past len. One difference, in debug output only:
the bulk endpoints are logged IN then OUT, not in descriptor order.

kernel/tests/test_usb_config.c, 7 checks, pins the walk as moved: a BOT stick
as QEMU presents it, a boot keyboard with its HID descriptor, a mouse before a
drive (the first interface only), a drive with bulk IN only, bLength 0, an
endpoint cut by len, an interface cut before its protocol byte. All pass.
Built for amd64, aarch64, riscv64; the boots come with the protocol (a data
stick enumerates through this path). The fixes for #170 and #171 follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 17:59:52 +00:00
Claude 37b1527279 test: kernel host tests -- the harness, and gpt.c tested on the host
Captain Bob, 2026-11-12: "Build an appropriate test harness! Love the idea."
The kernel had no tests below the boots, so defects QEMU cannot provoke could
not be tested first. Plan: docs/v4.0.0/plans/2026-11-12-kernel-host-tests.md.

kernel/tests/: one host program per kernel source, built with that source as
it is, the kernel's flags (-std=c99 -Wall -Wextra -Werror), and fakes --
the console captured line by line, a deterministic RNG that can fail, and a RAM
disk whose reads, writes or flushes fail at chosen 1 KiB blocks.
make -C kernel/tests test runs them; SRC_<test>= runs a test against other
code, which is how a test is seen to fail against the code before a fix.

test_gpt.c, 12 checks: a table written and read back; 16, 17 and 18 used
entries against max 16 and an entry out of range after the 16th (#180); the
RNG, the first write, a later write and a flush failing (#168). Against gpt.c
before #168 and #180: 4 failures, each defect caught. Now: 0. Both runs in
logs/.../kernel-tests/. Not yet a protocol stage: to rule (the plan, step 5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 17:57:04 +00:00
83 changed files with 1589 additions and 167 deletions
+11
View File
@@ -117,3 +117,14 @@ v3 is not part of acceptance. There is no `make test`. Hosted `make` is compile
- The docs stage takes ~30 min here (the API reference); it outlasts the foreground limit and the tool
moves it to the background (not an acceptance boot; no QEMU). Proofs need the HOL-Library heap
(ci/runner-image's URL, checksum in its Dockerfile).
## Releasing (Captain Bob, 2026-11-12)
Order for alpha.5 and after: the protocol on everything -> push (on his word) -> merge the PR through the gate ->
move what is left to the next milestone -> the release commit (version, CHANGELOG, README together, as
93828e0e did for alpha.4) -> **the documentation review, the very last thing before the tag**: README.md,
CHANGELOG.md, .claude/CLAUDE.md, docs/README.md, docs/INDEX.md, FABRIC-3, boards/BRINGUP.md, the plans --
every claim, count and issue reference checked against the tree and the tracker as they then are, shown to
him -> the tag, on his word.
- The gate refuses unsigned builds (#174); a protocol run here is unsigned -- the gate's signing is CI's.
- POST's floor is v4/system/POST_FLOOR (#173): raise it when POST grows; never lower it without him.
- Kernel host tests: make -C kernel/tests test (docs/v4.0.0/plans/2026-11-12-kernel-host-tests.md).
+4 -1
View File
@@ -44,6 +44,8 @@ jobs:
- name: The developer protocol's evidence
run: scripts/check_protocol.sh "${{ github.event.pull_request.head.sha || 'HEAD' }}"
# The gate into master refuses an unsigned build (#174; Captain Bob, 2026-11-12: "Yes, reject
# unsigned builds"). It warned and went on. scripts/test_acceptance_signing.sh runs this step.
- name: The capsule-signing key
env:
KEY: ${{ secrets.CAPSULE_SIGN_KEY }}
@@ -53,7 +55,8 @@ jobs:
(umask 077; printf '%s\n' "$KEY" > "$f")
echo "SIGN_KEY=$f" >> "$GITHUB_ENV"; echo "The capsules will be signed."
else
echo "::warning::No CAPSULE_SIGN_KEY secret: the capsules are built unsigned."
echo "::error::No CAPSULE_SIGN_KEY secret: the gate into master does not accept an unsigned build."
exit 1
fi
- name: Acceptance amd64
@@ -0,0 +1,42 @@
# Kernel host tests -- plan and progress (kept current, one line per increment)
Captain Bob, 2026-11-12: "Build an appropriate test harness! Love the idea." -- for the kernel's own
C code, so that a defect QEMU cannot provoke (a USB descriptor no emulated device sends, a write that
fails half-way, a stop that spins) is still tested first and seen to fail. v4 has had this since step
1 (`make -C v4 test`); the kernel had none.
## The design (my calls, open to a ruling)
- **`kernel/tests/`**, one program per kernel source under test: `test_<unit>.c` compiled on the
host with the kernel's own source file, `-std=c99 -Wall -Wextra -Werror`, and nothing else of the
kernel. `make -C kernel/tests test` builds and runs them all; each prints `N checks, M failures`
as v4's do, and the run fails if any does.
- **Fakes, not mocks** (`kernel/tests/fakes.[ch]`): the console captured line by line (so a test
reads what the kernel said), a deterministic RNG, and a RAM disk whose reads or writes fail at the
1 KiB blocks a test chooses -- the disk faults QEMU's blkdebug gives the boots, here per block and
without a boot.
- **Code is moved only to be testable, never changed in the move.** Where a unit is buried in a
larger function (the xHCI configuration-descriptor walk inside the event loop), it is moved out
into a function of its own in one commit, the boots and the tests unchanged, and then tested.
- **Not a substitute for acceptance.** The boots stay the only acceptance of the kernel; these run
beside them. Whether they become a stage of the protocol and the PR's gate (`nightly.sh
kernel-tests`, after test-32) is **to rule** -- proposed once there are enough tests to matter.
## Increments
- [x] 1. The harness (`Makefile`, `harness.h`, `fakes.[ch]`) and `test_gpt.c`: `gpt_read` and
`gpt_write_one` against a RAM disk -- a valid table; more used entries than `max` (#180); an
entry out of range past `max` (#180); the first write failing and a later one failing (#168).
Seen to fail against `gpt.c` as it was before #168 and #180 (`54311be1~1`): 12 checks, 4
failures -- each of the two defects caught. Now: 0 failures.
- [x] 2. The xHCI configuration-descriptor walk moved out of the event loop (`usb_config.c`,
`test_usb_config`), then #170 and #171 tested first (10 failures against the old decision)
and fixed.
- [x] 3. #176 (seeds wiped on every exit; option 1, Captain Bob 2026-11-12: "1 is great" -- the
caller owns the buffer: `test_sk_v4_mint`, 7 failures before; `test_sk_v4_identity`, through the
real drive-arrival path, 5 failures before). [x] #177 (the fatal stops halt:
`sk_v4_stop.c`, `test_sk_v4_stop`, a spin seen failing). [x] #178 (the slot array:
`sk_v4_slots.c`, `test_sk_v4_slots`, 4 failures against the old allocation). [x] #182 (the
cap checked at compile time: `check_cap`, a 4 TiB cap seen building before).
- [ ] 4. #179 once #187 is ruled (the block layer's header read).
- [ ] 5. To rule: the kernel tests as a protocol stage and in the gate.
+2 -2
View File
@@ -730,8 +730,8 @@ V4_ENGINE_SRCS := $(addprefix v4/src/,node.c exec.c stack.c iword.c heat.c guard
V4_ROM_C := $(BUILD_DIR)/v4_rom_64.c
V4_MAP_C := $(BUILD_DIR)/v4_map_64.c
LOADER_EXTRA_SRCS += $(KERNEL_SRC)/v4/sk_v4.c $(KERNEL_SRC)/v4/sk_v4_identity.c $(KERNEL_SRC)/v4/sk_v4_marker.c $(KERNEL_SRC)/v4/sk_v4_grow.c $(KERNEL_SRC)/v4/sk_v4_mint.c
KERNEL_EXTRA_SRCS += $(KERNEL_SRC)/v4/sk_v4.c $(KERNEL_SRC)/v4/sk_v4_identity.c $(KERNEL_SRC)/v4/sk_v4_marker.c $(KERNEL_SRC)/v4/sk_v4_grow.c $(KERNEL_SRC)/v4/sk_v4_mint.c
LOADER_EXTRA_SRCS += $(KERNEL_SRC)/v4/sk_v4.c $(KERNEL_SRC)/v4/sk_v4_identity.c $(KERNEL_SRC)/v4/sk_v4_marker.c $(KERNEL_SRC)/v4/sk_v4_grow.c $(KERNEL_SRC)/v4/sk_v4_mint.c $(KERNEL_SRC)/v4/sk_v4_stop.c $(KERNEL_SRC)/v4/sk_v4_slots.c
KERNEL_EXTRA_SRCS += $(KERNEL_SRC)/v4/sk_v4.c $(KERNEL_SRC)/v4/sk_v4_identity.c $(KERNEL_SRC)/v4/sk_v4_marker.c $(KERNEL_SRC)/v4/sk_v4_grow.c $(KERNEL_SRC)/v4/sk_v4_mint.c $(KERNEL_SRC)/v4/sk_v4_stop.c $(KERNEL_SRC)/v4/sk_v4_slots.c
# v4/system/boot.c is the boot the hosted v4 system runs too: the ROM
# assembles the system, then the capsules from this kernel's own capsule
# directory, then the prompt.
+40
View File
@@ -0,0 +1,40 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* usb_config.h -- a USB configuration descriptor set, read: what xhci.c's event loop needs to know
* of a device (its first interface, and that interface's endpoints). Moved out of the loop's
* XHCI_XFER_CONFIG_DESC_FULL case unchanged, so it can be tested on the host
* (kernel/tests/test_usb_config.c; docs/v4.0.0/plans/2026-11-12-kernel-host-tests.md).
*/
#ifndef STARKERNEL_USB_CONFIG_H
#define STARKERNEL_USB_CONFIG_H
#include <stdint.h>
#define USB_CONFIG_NO_INTERFACE 0 /* no Interface descriptor in the set */
#define USB_CONFIG_MSC 1 /* Mass Storage / SCSI / Bulk-Only Transport */
#define USB_CONFIG_KBD 2 /* a HID boot keyboard */
#define USB_CONFIG_OTHER 3 /* anything else -- not used */
typedef struct {
int kind; /* USB_CONFIG_* */
uint8_t iface_class, iface_subclass, iface_protocol;
uint8_t config_value; /* bConfigurationValue, for SET_CONFIGURATION */
uint8_t bulk_in_ep, bulk_out_ep; /* USB_CONFIG_MSC: 0 when not found */
uint16_t bulk_in_max, bulk_out_max;
uint8_t hid_iface; /* USB_CONFIG_KBD */
uint8_t hid_ep, hid_interval; /* hid_ep 0 when not found */
uint16_t hid_max;
} usb_config_t;
/* Read the first `len` bytes of a configuration descriptor set (the Configuration descriptor and
* the Interface and Endpoint descriptors after it). Only the first Interface descriptor counts;
* a descriptor with bLength 0 ends the walk. Never reads past `len`. */
void usb_config_parse(const uint8_t *desc, uint16_t len, usb_config_t *out);
/* After the configuration descriptor's first 9 bytes: how many bytes of the whole set to ask
* for, given its wTotalLength and the buffer's size `cap` -- 0 when wTotalLength is 9 or less (the
* device is not used: #170); *cut set to 1 when the set is longer than the buffer (#171). */
uint16_t usb_config_request_length(uint16_t total, uint16_t cap, int *cut);
#endif
@@ -56,6 +56,10 @@ void sk_v4_identity_set_marker(const sk_v4_marker_t *m);
* written its GPT and identity (it is then recognised as the real Zuse's). */
void sk_v4_identity_recheck_offered(void);
/* The 64 bytes the identity code mints and reads Zuse's seed into while it handles a drive (seed,
* then its read-back): zero whenever no drive is being handled (#176). For the host tests. */
const uint8_t *sk_v4_identity_seeds(void);
/* Headless: no prompt, and what is typed is read and dropped, until Zuse's
* session begins (v3's sk_repl_headless_wait()). */
void sk_v4_identity_wait(void);
@@ -9,6 +9,8 @@
#ifndef STARKERNEL_V4_SK_V4_MINT_H
#define STARKERNEL_V4_SK_V4_MINT_H
#include <stdint.h>
/* The whole of STICK.md 6a's minting: asks for a stick, shows its size, writes
* nothing until YES, then a GPT and a fresh Zuse identity on it, read back,
* and only then the real key in the genesis marker. 0 when she is minted;
@@ -16,4 +18,8 @@
* MINT-ZUSE word, and (Task 5) the fixed screen's R. */
int sk_v4_mint_zuse(void);
/* The same, with Zuse's seed and its read-back in `seeds` (64 bytes), owned by the caller: on every
* return the 64 bytes are zero (#176). */
int sk_v4_mint_zuse_with(uint8_t seeds[64]);
#endif /* STARKERNEL_V4_SK_V4_MINT_H */
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* sk_v4_slots.h -- an xHCI controller's drive slots, for sk_v4_identity.c (#178): the array the
* attached drives live in, which the identity code holds pointers into (the offered stick, the
* spare, the real Zuse's, Zuse's own device). */
#ifndef STARKERNEL_V4_SK_V4_SLOTS_H
#define STARKERNEL_V4_SK_V4_SLOTS_H
#include <stddef.h>
#include <stdint.h>
/* The slot array in *slots, `elem` bytes a slot, *count of them: allocated (zeroed) when there is
* none, with `want` slots. Returns how many slots may be used (0: none could be allocated). */
uint32_t sk_v4_slots_get(void **slots, uint32_t *count, uint32_t want, size_t elem);
#endif
+12
View File
@@ -0,0 +1,12 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* sk_v4_stop.h -- the v4 kernel's fatal stop (#177): what sk_v4_run does when the system cannot
* go on ("not started", "did not let go of POST's blocks", "stopped on a fault"). Never returns.
*/
#ifndef STARKERNEL_V4_SK_V4_STOP_H
#define STARKERNEL_V4_SK_V4_STOP_H
void sk_v4_stop(void) __attribute__((noreturn));
#endif
+3 -3
View File
@@ -36,9 +36,9 @@
* 1. tick_number uint32 — monotonic heartbeat counter
* 2. elapsed_ns uint64 — ns since run start
* 3. tick_interval_ns uint64 — actual interval from prior tick
* 4. cache_hits_delta uint32 — hot-words cache hits this tick (TODO: 0)
* 5. bucket_hits_delta uint32 — bucket hits this tick (TODO: 0)
* 6. word_executions_delta uint32 — words executed this tick (TODO: 0)
* 4. cache_hits_delta uint32 — hot-words cache hits this tick (measured since #142)
* 5. bucket_hits_delta uint32 — bucket hits this tick (measured since #142)
* 6. word_executions_delta uint32 — words executed this tick (measured; the "TODO: 0" here was stale)
* 7. hot_word_count uint64 — words with heat >= threshold
* 8. avg_word_heat_q48 uint64 — mean execution heat as raw Q48.16 integer
* 9. window_width uint32 — rolling window effective size
+3 -2
View File
@@ -118,6 +118,7 @@ int gpt_read(blkio_dev_t *disk, gpt_part_t *parts, unsigned max, unsigned *count
if (ent_lba + (ebytes + GPT_SECTOR - 1u) / GPT_SECTOR > first_usable) return GPT_BAD;
/* the entry array, a 1 KiB block at a time */
/* #182: the entries' block numbers are 32 bits -- ent_lba < disk_sectors, checked above */
for (i = 0; (size_t)i * BLKIO_FORTH_BLOCK_SIZE < ebytes; i++) {
if (blkio_read(disk, (uint32_t)(ent_lba / 2u) + i, g_gpt_entries + (size_t)i * BLKIO_FORTH_BLOCK_SIZE) != BLKIO_OK)
return GPT_BAD;
@@ -172,7 +173,7 @@ static int put_sectors(blkio_dev_t *disk, uint64_t lba, const uint8_t *src, uint
uint32_t i;
for (i = 0; i < n; i++) {
uint64_t s = lba + i;
uint32_t blk = (uint32_t)(s / 2u);
uint32_t blk = (uint32_t)(s / 2u); /* #182: s < the disk's sectors, a uint32 count of blocks x 2 */
if (blkio_read(disk, blk, g_gpt_rmw) != BLKIO_OK) return -1;
memcpy(g_gpt_rmw + (s % 2u) * GPT_SECTOR, src + (size_t)i * GPT_SECTOR, GPT_SECTOR);
if (blkio_write(disk, blk, g_gpt_rmw) != BLKIO_OK) return -1;
@@ -424,7 +425,7 @@ int gpt_part_open(blkio_dev_t *dev, gpt_part_dev_t *st, blkio_dev_t *disk, const
if ((p->first_lba % 2u) != 0u || (sectors % 2u) != 0u) return BLKIO_EINVAL;
if (p->first_lba / 2u + sectors / 2u > disk->total_blocks) return BLKIO_EINVAL;
st->disk = disk;
st->first_fblock = (uint32_t)(p->first_lba / 2u);
st->first_fblock = (uint32_t)(p->first_lba / 2u); /* #182: checked against total_blocks just above */
st->fblocks = (uint32_t)(sectors / 2u);
params.forth_block_size = BLKIO_FORTH_BLOCK_SIZE;
params.total_blocks = st->fblocks;
+93
View File
@@ -0,0 +1,93 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* usb_config.c -- see usb_config.h. Moved from xhci.c's XHCI_XFER_CONFIG_DESC_FULL case, the walk
* unchanged: found by bDescriptorType, not by a fixed offset; the first Interface descriptor only;
* a Mass Storage/SCSI/BOT interface's bulk endpoints up to the next Interface descriptor (the last
* of each direction wins); a boot keyboard's first interrupt IN endpoint.
*/
#include "starkernel/usb_config.h"
#include "starkernel/xhci.h"
#include <string.h>
/* The event loop asked for min(wTotalLength, cap) whatever it was. A wTotalLength of 9 or less was
* then asked for again as "short" (xhci_ep0_get_config_descriptor: length <= 9), for ever (#170),
* and a set longer than the buffer was cut without a word (#171). Now: 9 or less is refused (0),
* and a cut is said. */
uint16_t usb_config_request_length(uint16_t total, uint16_t cap, int *cut)
{
*cut = 0;
if (total <= 9u) return 0; /* no room for anything after the Configuration descriptor */
if (total > cap) { *cut = 1; return cap; }
return total;
}
static uint16_t le16(const uint8_t *p) { return (uint16_t)(p[0] | ((uint16_t)p[1] << 8)); }
void usb_config_parse(const uint8_t *desc, uint16_t len, usb_config_t *out)
{
uint16_t off = 0;
memset(out, 0, sizeof *out);
out->kind = USB_CONFIG_NO_INTERFACE;
out->config_value = desc[USB_CONFIG_OFF_CONFIG_VALUE];
while (off + 2 <= len) {
uint8_t desc_len = desc[off + USB_DESC_OFF_LENGTH];
uint8_t desc_type = desc[off + USB_DESC_OFF_TYPE];
if (desc_len == 0) break; /* malformed -- avoid an infinite loop */
if (desc_type == USB_DESC_TYPE_INTERFACE && off + USB_IFACE_OFF_PROTOCOL < len) {
uint16_t ep_off = (uint16_t)(off + desc_len);
out->iface_class = desc[off + USB_IFACE_OFF_CLASS];
out->iface_subclass = desc[off + USB_IFACE_OFF_SUBCLASS];
out->iface_protocol = desc[off + USB_IFACE_OFF_PROTOCOL];
if (out->iface_class == USB_CLASS_MASS_STORAGE && out->iface_subclass == USB_SUBCLASS_SCSI &&
out->iface_protocol == USB_PROTOCOL_BOT) {
out->kind = USB_CONFIG_MSC;
while (ep_off + 2 <= len) {
uint8_t ep_len = desc[ep_off + USB_DESC_OFF_LENGTH];
uint8_t ep_type = desc[ep_off + USB_DESC_OFF_TYPE];
if (ep_len == 0) break;
if (ep_type == USB_DESC_TYPE_INTERFACE) break;
if (ep_type == USB_DESC_TYPE_ENDPOINT && ep_off + USB_EP_OFF_MAX_PACKET_SIZE + 1 < len) {
uint8_t ep_addr = desc[ep_off + USB_EP_OFF_ADDRESS];
uint8_t ep_attr = desc[ep_off + USB_EP_OFF_ATTRIBUTES];
if ((ep_attr & USB_EP_ATTR_TYPE_MASK) == USB_EP_TYPE_BULK) {
if (ep_addr & USB_EP_ADDR_DIR_MASK) {
out->bulk_in_ep = ep_addr; out->bulk_in_max = le16(desc + ep_off + USB_EP_OFF_MAX_PACKET_SIZE);
} else {
out->bulk_out_ep = ep_addr; out->bulk_out_max = le16(desc + ep_off + USB_EP_OFF_MAX_PACKET_SIZE);
}
}
}
ep_off = (uint16_t)(ep_off + ep_len);
}
} else if (out->iface_class == USB_CLASS_HID && out->iface_subclass == USB_SUBCLASS_HID_BOOT &&
out->iface_protocol == USB_PROTOCOL_HID_KEYBOARD) {
out->kind = USB_CONFIG_KBD;
out->hid_iface = desc[off + USB_IFACE_OFF_NUMBER];
while (ep_off + 2 <= len) {
uint8_t ep_len = desc[ep_off + USB_DESC_OFF_LENGTH];
uint8_t ep_type = desc[ep_off + USB_DESC_OFF_TYPE];
if (ep_len == 0) break;
if (ep_type == USB_DESC_TYPE_INTERFACE) break;
if (ep_type == USB_DESC_TYPE_ENDPOINT && ep_off + USB_EP_OFF_INTERVAL < len) {
uint8_t ep_addr = desc[ep_off + USB_EP_OFF_ADDRESS];
uint8_t ep_attr = desc[ep_off + USB_EP_OFF_ATTRIBUTES];
if ((ep_attr & USB_EP_ATTR_TYPE_MASK) == USB_EP_TYPE_INTERRUPT && (ep_addr & USB_EP_ADDR_DIR_MASK)) {
out->hid_ep = ep_addr;
out->hid_max = (uint16_t)(le16(desc + ep_off + USB_EP_OFF_MAX_PACKET_SIZE) & 0x7FFu);
out->hid_interval = desc[ep_off + USB_EP_OFF_INTERVAL];
break;
}
}
ep_off = (uint16_t)(ep_off + ep_len);
}
} else {
out->kind = USB_CONFIG_OTHER;
}
return; /* the first Interface descriptor only */
}
off = (uint16_t)(off + desc_len);
}
}
+66 -132
View File
@@ -26,6 +26,7 @@
#include "starkernel/xhci.h"
#include "starkernel/xhci_driver.h"
#include "starkernel/usb_kbd.h" /* A3: a boot keyboard's reports and lights */
#include "starkernel/usb_config.h" /* the configuration descriptor set, read */
#include "starkernel/console.h" /* A3: "USB keyboard ready" */
#include "starkernel/kmalloc.h"
#include "starkernel/timer.h"
@@ -2213,148 +2214,81 @@ static void xhci_poll_one(xhci_dev_t *dev)
case XHCI_XFER_CONFIG_DESC_SHORT: {
uint16_t total_len = (uint16_t)(xms->config_descriptor[USB_CONFIG_OFF_TOTAL_LENGTH] |
((uint16_t)xms->config_descriptor[USB_CONFIG_OFF_TOTAL_LENGTH + 1] << 8));
int cut;
uint16_t want = usb_config_request_length(total_len, (uint16_t)sizeof(xms->config_descriptor), &cut);
xms->config_total_length = total_len;
xhci_log_hex32("xhci: config wTotalLength=", total_len);
if (want == 0) { /* #170: it would be asked for again, for ever */
log_message(LOG_WARN, "xhci: a configuration of %u bytes has no interface -- not used", (unsigned)total_len);
break;
}
if (cut) /* #171: interfaces past the buffer are not seen */
log_message(LOG_WARN, "xhci: config of %u bytes cut to %u -- rest unseen",
(unsigned)total_len, (unsigned)want);
xms->next_action = XHCI_NEXT_ACTION_GET_CONFIG_DESC;
xms->next_action_length = total_len;
xms->next_action_length = want;
break;
}
case XHCI_XFER_CONFIG_DESC_FULL: {
log_message(LOG_DEBUG, "xhci: full config descriptor received");
/* Walk the concatenated descriptor stream
* (Config + Interface + Endpoint descriptors
* back to back) looking for the Interface
* descriptor -- its fixed offset within the
* stream isn't guaranteed, has to be found by
* bDescriptorType, not assumed. */
/* The walk of the descriptor set is usb_config_parse() (usb_config.c,
* moved out of here unchanged and tested on the host,
* kernel/tests/test_usb_config.c); what it found is acted on here, as
* before. */
usb_config_t cfg;
uint16_t len = xms->config_total_length;
if (len > sizeof(xms->config_descriptor)) len = (uint16_t)sizeof(xms->config_descriptor);
uint16_t off = 0;
int found = 0;
while (off + 2 <= len) {
uint8_t desc_len = xms->config_descriptor[off + USB_DESC_OFF_LENGTH];
uint8_t desc_type = xms->config_descriptor[off + USB_DESC_OFF_TYPE];
if (desc_len == 0) break; /* malformed -- avoid an infinite loop */
if (desc_type == USB_DESC_TYPE_INTERFACE &&
off + USB_IFACE_OFF_PROTOCOL < len) {
uint8_t iface_class = xms->config_descriptor[off + USB_IFACE_OFF_CLASS];
uint8_t iface_subclass = xms->config_descriptor[off + USB_IFACE_OFF_SUBCLASS];
uint8_t iface_protocol = xms->config_descriptor[off + USB_IFACE_OFF_PROTOCOL];
xhci_log_hex32("xhci: bInterfaceClass=", iface_class);
xhci_log_hex32("xhci: bInterfaceSubClass=", iface_subclass);
xhci_log_hex32("xhci: bInterfaceProtocol=", iface_protocol);
if (iface_class == USB_CLASS_MASS_STORAGE &&
iface_subclass == USB_SUBCLASS_SCSI &&
iface_protocol == USB_PROTOCOL_BOT) {
log_message(LOG_DEBUG, "xhci: confirmed Mass Storage / SCSI / BOT device");
/* Walk the Endpoint descriptors that
* follow this Interface descriptor,
* stopping at the next Interface
* descriptor (start of a different
* interface's endpoints) or end of
* the stream. Only bulk endpoints
* are of interest for BOT. */
uint16_t ep_off = (uint16_t)(off + desc_len);
while (ep_off + 2 <= len) {
uint8_t ep_desc_len = xms->config_descriptor[ep_off + USB_DESC_OFF_LENGTH];
uint8_t ep_desc_type = xms->config_descriptor[ep_off + USB_DESC_OFF_TYPE];
if (ep_desc_len == 0) break; /* malformed -- avoid an infinite loop */
if (ep_desc_type == USB_DESC_TYPE_INTERFACE) break;
if (ep_desc_type == USB_DESC_TYPE_ENDPOINT &&
ep_off + USB_EP_OFF_MAX_PACKET_SIZE + 1 < len) {
uint8_t ep_addr = xms->config_descriptor[ep_off + USB_EP_OFF_ADDRESS];
uint8_t ep_attr = xms->config_descriptor[ep_off + USB_EP_OFF_ATTRIBUTES];
uint16_t ep_max_packet = (uint16_t)(xms->config_descriptor[ep_off + USB_EP_OFF_MAX_PACKET_SIZE] |
((uint16_t)xms->config_descriptor[ep_off + USB_EP_OFF_MAX_PACKET_SIZE + 1] << 8));
if ((ep_attr & USB_EP_ATTR_TYPE_MASK) == USB_EP_TYPE_BULK) {
if (ep_addr & USB_EP_ADDR_DIR_MASK) {
xms->bulk_in_ep_addr = ep_addr;
xms->bulk_in_max_packet = ep_max_packet;
xhci_log_hex32("xhci: bulk IN endpoint=", ep_addr);
} else {
xms->bulk_out_ep_addr = ep_addr;
xms->bulk_out_max_packet = ep_max_packet;
xhci_log_hex32("xhci: bulk OUT endpoint=", ep_addr);
}
}
}
ep_off = (uint16_t)(ep_off + ep_desc_len);
}
/* Deferred (see xhci_dev_t's
* next_action doc comment) rather
* than called directly here --
* same doorbell-ordering hazard
* as the device/config descriptor
* chaining above. next_action_
* config_value is staged now but
* not consumed until SET_CONFIG
* actually runs, after Configure
* Endpoint completes below. */
xms->next_action_config_value =
xms->config_descriptor[USB_CONFIG_OFF_CONFIG_VALUE];
if (xms->bulk_in_ep_addr == 0 || xms->bulk_out_ep_addr == 0) {
/* Can't Configure Endpoint
* without knowing both bulk
* endpoints -- go straight to
* SET_CONFIGURATION so the
* device is still usable for
* whatever doesn't need BOT
* (nothing, today, but this
* keeps the two concerns
* separate rather than
* failing enumeration
* outright). */
log_message(LOG_WARN, "xhci: warning -- BOT device missing a bulk IN or OUT endpoint, skipping configure endpoint");
xms->next_action = XHCI_NEXT_ACTION_SET_CONFIG;
} else {
xms->next_action = XHCI_NEXT_ACTION_CONFIGURE_ENDPOINT;
}
} else if (iface_class == USB_CLASS_HID &&
iface_subclass == USB_SUBCLASS_HID_BOOT &&
iface_protocol == USB_PROTOCOL_HID_KEYBOARD) {
/* A boot keyboard (2026-10-14, A3): its
* interface number, and the first
* interrupt IN endpoint after it. */
uint16_t ep_off = (uint16_t)(off + desc_len);
xms->hid_iface = xms->config_descriptor[off + USB_IFACE_OFF_NUMBER];
while (ep_off + 2 <= len) {
uint8_t ep_desc_len = xms->config_descriptor[ep_off + USB_DESC_OFF_LENGTH];
uint8_t ep_desc_type = xms->config_descriptor[ep_off + USB_DESC_OFF_TYPE];
if (ep_desc_len == 0) break;
if (ep_desc_type == USB_DESC_TYPE_INTERFACE) break;
if (ep_desc_type == USB_DESC_TYPE_ENDPOINT &&
ep_off + USB_EP_OFF_INTERVAL < len) {
uint8_t ep_addr = xms->config_descriptor[ep_off + USB_EP_OFF_ADDRESS];
uint8_t ep_attr = xms->config_descriptor[ep_off + USB_EP_OFF_ATTRIBUTES];
if ((ep_attr & USB_EP_ATTR_TYPE_MASK) == USB_EP_TYPE_INTERRUPT &&
(ep_addr & USB_EP_ADDR_DIR_MASK)) {
xms->hid_ep_addr = ep_addr;
xms->hid_max_packet = (uint16_t)(xms->config_descriptor[ep_off + USB_EP_OFF_MAX_PACKET_SIZE] |
((uint16_t)xms->config_descriptor[ep_off + USB_EP_OFF_MAX_PACKET_SIZE + 1] << 8)) & 0x7FFu;
xms->hid_interval = xms->config_descriptor[ep_off + USB_EP_OFF_INTERVAL];
break;
}
}
ep_off = (uint16_t)(ep_off + ep_desc_len);
}
xms->next_action_config_value =
xms->config_descriptor[USB_CONFIG_OFF_CONFIG_VALUE];
if (xms->hid_ep_addr) {
xms->hid_kbd = 1;
xms->next_action = XHCI_NEXT_ACTION_CONFIGURE_ENDPOINT;
} else {
log_message(LOG_WARN, "xhci: keyboard without an interrupt IN endpoint -- not used");
}
} else {
log_message(LOG_WARN, "xhci: neither a Mass Storage/SCSI/BOT drive nor a boot keyboard -- not used");
}
found = 1;
break;
}
off = (uint16_t)(off + desc_len);
}
if (!found) {
usb_config_parse(xms->config_descriptor, len, &cfg);
if (cfg.kind == USB_CONFIG_NO_INTERFACE) {
log_message(LOG_WARN, "xhci: no Interface descriptor found in config set");
break;
}
xhci_log_hex32("xhci: bInterfaceClass=", cfg.iface_class);
xhci_log_hex32("xhci: bInterfaceSubClass=", cfg.iface_subclass);
xhci_log_hex32("xhci: bInterfaceProtocol=", cfg.iface_protocol);
if (cfg.kind == USB_CONFIG_MSC) {
log_message(LOG_DEBUG, "xhci: confirmed Mass Storage / SCSI / BOT device");
if (cfg.bulk_in_ep) {
xms->bulk_in_ep_addr = cfg.bulk_in_ep;
xms->bulk_in_max_packet = cfg.bulk_in_max;
xhci_log_hex32("xhci: bulk IN endpoint=", cfg.bulk_in_ep);
}
if (cfg.bulk_out_ep) {
xms->bulk_out_ep_addr = cfg.bulk_out_ep;
xms->bulk_out_max_packet = cfg.bulk_out_max;
xhci_log_hex32("xhci: bulk OUT endpoint=", cfg.bulk_out_ep);
}
/* Deferred (see xhci_dev_t's next_action doc comment) rather than
* called directly here -- the same doorbell-ordering hazard as the
* device/config descriptor chaining above. */
xms->next_action_config_value = cfg.config_value;
if (xms->bulk_in_ep_addr == 0 || xms->bulk_out_ep_addr == 0) {
/* Can't Configure Endpoint without both bulk endpoints -- go
* straight to SET_CONFIGURATION, keeping the two concerns
* separate rather than failing enumeration outright. */
log_message(LOG_WARN, "xhci: warning -- BOT device missing a bulk IN or OUT endpoint, skipping configure endpoint");
xms->next_action = XHCI_NEXT_ACTION_SET_CONFIG;
} else {
xms->next_action = XHCI_NEXT_ACTION_CONFIGURE_ENDPOINT;
}
} else if (cfg.kind == USB_CONFIG_KBD) {
/* A boot keyboard (2026-10-14, A3): its interface number, and the
* first interrupt IN endpoint after it. */
xms->hid_iface = cfg.hid_iface;
if (cfg.hid_ep) {
xms->hid_ep_addr = cfg.hid_ep;
xms->hid_max_packet = cfg.hid_max;
xms->hid_interval = cfg.hid_interval;
}
xms->next_action_config_value = cfg.config_value;
if (xms->hid_ep_addr) {
xms->hid_kbd = 1;
xms->next_action = XHCI_NEXT_ACTION_CONFIGURE_ENDPOINT;
} else {
log_message(LOG_WARN, "xhci: keyboard without an interrupt IN endpoint -- not used");
}
} else {
log_message(LOG_WARN, "xhci: neither a Mass Storage/SCSI/BOT drive nor a boot keyboard -- not used");
}
break;
}
+4 -3
View File
@@ -26,6 +26,7 @@
#include "starkernel/v4/sk_v4_mint.h"
#include "starkernel/v4/sk_v4.h"
#include "starkernel/v4/sk_v4_identity.h"
#include "starkernel/v4/sk_v4_stop.h"
#include "starkernel/kbd_input.h"
#include "starkernel/console.h"
#include "starkernel/arch.h"
@@ -159,7 +160,7 @@ void sk_v4_run(void (*chain)(void), const BootDisk *boot_disk)
blk_subsys_init(sk_v4_post_blk_ram, sizeof(sk_v4_post_blk_ram));
if (!v4_boot_run(&boot)) {
console_println("StarForth v4: not started");
for (;;) { }
sk_v4_stop(); /* #177: halts, not a 100% spin */
}
if (chain) {
/* the blocks are other blocks now: what the node has in its two
@@ -167,7 +168,7 @@ void sk_v4_run(void (*chain)(void), const BootDisk *boot_disk)
chain();
if (v4_boot_line(&boot, "EMPTY-BUFFERS", 13) != V4_TEXT_COMPLETED) {
console_println("StarForth v4: the node did not let go of POST's blocks");
for (;;) { }
sk_v4_stop(); /* #177: halts, not a 100% spin */
}
}
sk_v4_identity_boot(boot_disk);
@@ -230,7 +231,7 @@ void sk_v4_run(void (*chain)(void), const BootDisk *boot_disk)
else if (how == V4_BOOT_LINE_REFUSED) console_puts("Message refused\n ERROR\n"); /* the node's wire is full: error 19's words */
else if (how == V4_BOOT_LINE_STOPPED) {
console_println("StarForth v4: the node stopped on a fault");
for (;;) { }
sk_v4_stop(); /* #177: halts, not a 100% spin */
}
}
}
+8
View File
@@ -26,6 +26,14 @@ static union {
} g_hdr;
static uint8_t g_move[4096];
/* #182: the 1 KiB block numbers below are 32 bits ((uint32_t)devblock * 4u, as the block layer's
* are): enough for 4 TiB, and Artemis is capped at STICK_ARTEMIS_CAP_GIB (kernel/Makefile, 256 GiB).
* A cap past 4 TiB stops the build here instead of wrapping the block numbers. */
#ifndef STICK_ARTEMIS_CAP_GIB
#error "STICK_ARTEMIS_CAP_GIB (kernel/Makefile) must be defined: the check below depends on it"
#endif
typedef char sk_v4_grow_cap_fits_32_bit_blocks[(STICK_ARTEMIS_CAP_GIB * 1024ULL * 1024ULL <= 0xFFFFFFFFULL) ? 1 : -1];
static int dev_rw4k(blkio_dev_t *dev, uint64_t devblock, uint8_t *buf, int write)
{
uint32_t base = (uint32_t)devblock * 4u, k;
+35 -15
View File
@@ -35,6 +35,7 @@
* ACL-ZUSE-BOOT.
*/
#include "starkernel/v4/sk_v4_identity.h"
#include "starkernel/v4/sk_v4_slots.h"
#include "starkernel/console.h"
#include "starkernel/arch.h"
#include "starkernel/apic.h"
@@ -65,6 +66,11 @@
static int g_zuse_session;
static int g_zuse_cert_installed;
static uint8_t g_zuse_seed[32], g_zuse_pubkey[32];
/* The seed being minted or read, and its read-back, while a drive is handled: seed the first 32
* bytes, rseed the next 32 (#176). The logged-in Zuse's own is g_zuse_seed, kept by design. */
static uint8_t g_seeds[64];
const uint8_t *sk_v4_identity_seeds(void) { return g_seeds; }
static uint8_t g_zuse_root_pubkey[32];
static int g_zuse_root_known;
static struct blkio_dev *g_zuse_dev;
@@ -241,7 +247,8 @@ static void sk_v4_login(blkio_dev_t *dev, const uint8_t seed[32], const uint8_t
* system headless. Returns 1 when she is logged in. */
static int sk_v4_genesis(blkio_dev_t *dev, blkio_dev_t *art)
{
uint8_t seed[32], pubkey[32], rseed[32], rpub[32];
uint8_t pubkey[32], rpub[32];
uint8_t *seed = g_seeds, *rseed = g_seeds + 32;
homeblocks_sig_t sig;
homeblocks_sig_result_t sig_rc;
uint32_t lbn, nblk;
@@ -288,7 +295,8 @@ static int sk_v4_real_zuse_arrived(sk_v4_drive_t *d, unsigned nparts)
{
homeblocks_sig_t sig;
homeblocks_sig_result_t sig_rc;
uint8_t seed[32], pubkey[32];
uint8_t pubkey[32];
uint8_t *seed = g_seeds;
int ii = gpt_find(g_gpt_parts, nparts, gpt_type_starship_identity);
if (!g_marker.present || !g_marker.has_real || ii < 0) return 0;
@@ -306,21 +314,23 @@ static int sk_v4_real_zuse_arrived(sk_v4_drive_t *d, unsigned nparts)
g_real_drive = d;
g_proxy_fallback = 0;
sk_v4_login(&d->part, seed, pubkey, "Zuse: identity confirmed from attached thumbdrive");
memset(seed, 0, sizeof seed);
memset(seed, 0, 32);
return 1;
}
/* A drive that has arrived. This system's stick: its Artemis partition is
* attached (the first disk slot, the block subsystem's), Zuse's public key is
* read from its genesis marker, then its identity partition is attached and,
* if it is Zuse's, her session begins. Any other drive is not used. */
static int sk_v4_drive_arrived(sk_v4_drive_t *d)
* if it is Zuse's, her session begins. Any other drive is not used.
* Called only by sk_v4_drive_arrived, which wipes g_seeds after it (#176). */
static int handle_drive(sk_v4_drive_t *d)
{
blkio_dev_t *dev;
homeblocks_sig_t sig;
homeblocks_sig_result_t sig_rc;
artemis_sig_t asig;
uint8_t seed[32], pubkey[32];
uint8_t pubkey[32];
uint8_t *seed = g_seeds;
zuse_drive_t which;
unsigned nparts;
int gpt_rc;
@@ -431,6 +441,17 @@ static int sk_v4_drive_arrived(sk_v4_drive_t *d)
return 1;
}
/* One place wipes the seeds, after every drive handled: genesis (seed and its read-back), the
* proxy's login and the real Zuse's (sk_v4_genesis, sk_v4_real_zuse_arrived, handle_drive) --
* whichever way each went. The logged-in Zuse's own key stays in g_zuse_seed, by design; the
* working copies did not, and were left in memory (#176). */
static int sk_v4_drive_arrived(sk_v4_drive_t *d)
{
int rc = handle_drive(d);
memset(g_seeds, 0, sizeof g_seeds);
return rc;
}
/* A drive that has left: its identity partition is let go, then its Artemis
* partition -- in that order, because blk_subsys_detach_device() removes
* only the chain's tail, and the identity partition was attached last. */
@@ -510,15 +531,14 @@ static void sk_v4_idle(void)
for (xc = 0; xc < xhci_dev_count() && xc < XHCI_MAX_CONTROLLERS; xc++) {
xhci_dev_t *xdev = xhci_dev_at(xc);
if (!xdev) continue;
if (!g_usb[xc].slots || g_usb[xc].count < xdev->max_slots + 1) {
size_t bytes = (size_t)(xdev->max_slots + 1) * sizeof(sk_v4_drive_t);
sk_v4_drive_t *fresh = (sk_v4_drive_t *)kmalloc_aligned(bytes, 64);
if (!fresh) continue;
memset(fresh, 0, bytes);
g_usb[xc].slots = fresh;
g_usb[xc].count = xdev->max_slots + 1;
/* allocated once and never replaced: the identity code holds pointers into it (#178) */
{
void *slots = g_usb[xc].slots;
uint32_t usable = sk_v4_slots_get(&slots, &g_usb[xc].count, xdev->max_slots + 1, sizeof(sk_v4_drive_t));
g_usb[xc].slots = (sk_v4_drive_t *)slots;
if (usable == 0) continue;
}
for (slot = 1; slot <= xdev->max_slots; slot++) {
for (slot = 1; slot <= xdev->max_slots && slot < g_usb[xc].count; slot++) {
xhci_msc_slot_t *ms = xhci_msc_slot_for(xdev, slot);
if (!ms || !ms->bot_msc_attach_pending) continue;
ms->bot_msc_attach_pending = 0;
@@ -526,7 +546,7 @@ static void sk_v4_idle(void)
sk_v4_drive_arrived(&g_usb[xc].slots[slot]))
ms->bot_msc_attached = 1;
}
for (slot = 1; slot <= xdev->max_slots; slot++) {
for (slot = 1; slot <= xdev->max_slots && slot < g_usb[xc].count; slot++) {
xhci_msc_slot_t *ms = xhci_msc_slot_for(xdev, slot);
if (!ms || !ms->bot_msc_detach_pending) continue;
ms->bot_msc_detach_pending = 0;
+23 -4
View File
@@ -81,7 +81,10 @@ static int erased(void) /* its old partition table is gone (#168
return -1;
}
int sk_v4_mint_zuse(void)
/* The mint, with Zuse's seed and its read-back in `seeds`, which the caller owns: seed is its first
* 32 bytes, rseed the next 32. Called only by sk_v4_mint_zuse_with, which wipes `seeds` after it
* whichever way it returned (#176). */
static int mint(uint8_t seeds[64])
{
static blkio_dev_t part;
static gpt_part_dev_t part_state;
@@ -89,7 +92,8 @@ int sk_v4_mint_zuse(void)
static uint8_t zero[BLKIO_FORTH_BLOCK_SIZE];
blkio_dev_t *raw;
uint64_t bytes, sectors;
uint8_t guid[16], seed[32], pub[32], rseed[32], rpub[32];
uint8_t guid[16], pub[32], rpub[32];
uint8_t *seed = seeds, *rseed = seeds + 32;
homeblocks_sig_t sig;
homeblocks_sig_result_t sig_rc;
sk_v4_marker_t m;
@@ -148,10 +152,25 @@ int sk_v4_mint_zuse(void)
m.has_real = 1;
if (sk_v4_marker_write(&m) != 0) return erased();
sk_v4_identity_set_marker(&m);
memset(seed, 0, sizeof seed);
memset(rseed, 0, sizeof rseed);
memset(seeds, 0, 64);
console_println("Zuse: real Zuse minted onto the second stick");
sk_v4_identity_recheck_offered();
return 0;
}
/* One place wipes the seeds, after every return of the mint -- its refusals, each failure after
* YES, and success alike. They were wiped on success only, and left in memory on every other way
* out (#176). */
int sk_v4_mint_zuse_with(uint8_t seeds[64])
{
int rc = mint(seeds);
memset(seeds, 0, 64);
return rc;
}
int sk_v4_mint_zuse(void)
{
static uint8_t seeds[64];
return sk_v4_mint_zuse_with(seeds);
}
+23
View File
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* sk_v4_slots.c -- see sk_v4_slots.h. */
#include "starkernel/v4/sk_v4_slots.h"
#include "starkernel/kmalloc.h"
#include <string.h>
/* sk_v4_idle replaced the array whenever a controller's max_slots + 1 was more than it held: the
* old one dropped, neither copied nor freed, while the identity code held pointers into it (#178).
* Now it is allocated once, at the size first asked for, and never replaced; the slots that may be
* used are the ones it has. */
uint32_t sk_v4_slots_get(void **slots, uint32_t *count, uint32_t want, size_t elem)
{
if (!*slots && want) {
void *fresh = kmalloc_aligned(want * elem, 64);
if (!fresh) return 0;
memset(fresh, 0, want * elem);
*slots = fresh;
*count = want;
}
return *slots ? *count : 0;
}
+14
View File
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* sk_v4_stop.c -- see sk_v4_stop.h. */
#include "starkernel/v4/sk_v4_stop.h"
#include "starkernel/arch.h"
/* Interrupts off, then halt for ever: the core sleeps instead of spinning at 100% (#177), and no
* timer or device wakes it to do anything. sk_v4_run's three stops each said why first. */
void sk_v4_stop(void)
{
arch_disable_interrupts();
for (;;) arch_halt();
}
+62
View File
@@ -0,0 +1,62 @@
# SPDX-License-Identifier: LicenseRef-Starship-1.0
# Copyright (c) 2023-2026 Robert A. James
#
# The kernel host tests (docs/v4.0.0/plans/2026-11-12-kernel-host-tests.md): each test_<unit>.c
# built on the host with the kernel source file(s) it tests and the fakes, nothing else of the
# kernel, and run.
#
# make -C kernel/tests test build and run them all; fails if any check fails
# make -C kernel/tests run-test_gpt
#
# A test's sources are SRC_<test>; give another on the command line to run the same test against
# it (how a test is seen to fail against the code before a fix):
# make -C kernel/tests run-test_gpt SRC_test_gpt=/path/to/old/gpt.c
HERE := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
ROOT := $(abspath $(HERE)/../..)
BUILD := $(ROOT)/build/kernel-tests
CC ?= cc
CFLAGS := -std=c99 -Wall -Wextra -Werror -O2 -g -I$(HERE) -I$(ROOT)/kernel/include \
-I$(ROOT)/kernel/include/starkernel -I$(ROOT)/v3/include
TESTS := test_gpt test_usb_config test_sk_v4_stop test_sk_v4_slots test_sk_v4_mint test_sk_v4_identity test_heartbeat_export
SRC_test_heartbeat_export := $(ROOT)/v3/src/heartbeat_export.c
SRC_test_sk_v4_identity := $(ROOT)/kernel/src/v4/sk_v4_identity.c $(ROOT)/kernel/src/v4/sk_v4_slots.c $(ROOT)/kernel/src/gpt.c
EXTRA_test_sk_v4_identity := -D__STARKERNEL__ -I$(ROOT)/v4/include -DSTICK_GROW_MIN_BYTES=8000000000ULL -DSTICK_ARTEMIS_CAP_GIB=256ULL
SRC_test_sk_v4_mint := $(ROOT)/kernel/src/v4/sk_v4_mint.c $(ROOT)/kernel/src/gpt.c
EXTRA_test_sk_v4_mint := -D__STARKERNEL__ -I$(ROOT)/v4/include
SRC_test_sk_v4_slots := $(ROOT)/kernel/src/v4/sk_v4_slots.c
SRC_test_sk_v4_stop := $(ROOT)/kernel/src/v4/sk_v4_stop.c
SRC_test_gpt := $(ROOT)/kernel/src/gpt.c
SRC_test_usb_config := $(ROOT)/kernel/src/usb/usb_config.c
define TEST_RULE
$(BUILD)/$(1): $(HERE)/$(1).c $(HERE)/fakes.c $(HERE)/fakes.h $(HERE)/harness.h $$(SRC_$(1))
@mkdir -p $(BUILD)
$(CC) $(CFLAGS) $$(EXTRA_$(1)) $(HERE)/$(1).c $(HERE)/fakes.c $$(SRC_$(1)) -o $$@
.PHONY: run-$(1)
run-$(1): $(BUILD)/$(1)
@echo "$(1)"
@$(BUILD)/$(1)
endef
$(foreach t,$(TESTS),$(eval $(call TEST_RULE,$(t))))
.PHONY: test
test: $(addprefix run-,$(TESTS))
@echo "all kernel host tests passed"
# #182: sk_v4_grow.c's 32-bit block arithmetic holds while Artemis is capped below 4 TiB -- the build
# itself refuses a cap past that. Seen here: 256 GiB (the real cap) compiles, 4096 GiB must not.
.PHONY: run-check_cap
run-check_cap:
@echo "check_cap"
@$(CC) $(CFLAGS) -I$(ROOT)/v4/include -DSTICK_ARTEMIS_CAP_GIB=256ULL -c $(ROOT)/kernel/src/v4/sk_v4_grow.c -o /dev/null \
|| { echo "FAIL #182: sk_v4_grow.c does not build with the real cap, 256 GiB"; exit 1; }
@if $(CC) $(CFLAGS) -I$(ROOT)/v4/include -DSTICK_ARTEMIS_CAP_GIB=4096ULL -c $(ROOT)/kernel/src/v4/sk_v4_grow.c -o /dev/null 2>/dev/null; then \
echo "FAIL #182: a 4096 GiB cap builds -- its block numbers do not fit 32 bits, and nothing stops it"; exit 1; fi
@if $(CC) $(CFLAGS) -I$(ROOT)/v4/include -c $(ROOT)/kernel/src/v4/sk_v4_grow.c -o /dev/null 2>/dev/null; then \
echo "FAIL #182: no cap defined builds -- the check would be skipped, not failed"; exit 1; fi
@echo " 3 checks, 0 failures"
test: run-check_cap
+113
View File
@@ -0,0 +1,113 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* fakes.c -- see fakes.h. */
#include "fakes.h"
#include <stdlib.h>
#include <string.h>
/* ---- the console ---- */
#define FAKE_LINES 256
#define FAKE_LINE 256
static char lines[FAKE_LINES][FAKE_LINE];
static unsigned n_lines;
void fake_console_reset(void) { n_lines = 0; }
unsigned fake_console_lines(void) { return n_lines; }
const char *fake_console_line(unsigned i) { return i < n_lines ? lines[i] : ""; }
int fake_console_said(const char *text)
{
unsigned i;
for (i = 0; i < n_lines; i++) if (strstr(lines[i], text)) return 1;
return 0;
}
static void take(const char *s)
{
if (n_lines < FAKE_LINES) {
strncpy(lines[n_lines], s, FAKE_LINE - 1);
lines[n_lines][FAKE_LINE - 1] = '\0';
n_lines++;
}
}
void console_println(const char *s) { take(s); }
void console_puts(const char *s) { take(s); }
void console_putc(char c) { (void)c; }
/* ---- the RNG ---- */
static uint32_t rng_state = 1u;
static int rng_fails;
void fake_rng_reset(void) { rng_state = 1u; rng_fails = 0; }
void fake_rng_fail(int fail) { rng_fails = fail; }
int rng_get_bytes(uint8_t *buf, size_t n)
{
size_t i;
if (rng_fails) return -1;
for (i = 0; i < n; i++) { rng_state = rng_state * 1103515245u + 12345u; buf[i] = (uint8_t)(rng_state >> 16); }
return 0;
}
/* ---- the disk ---- */
static int listed(const uint32_t *list, uint32_t n, uint32_t block)
{
uint32_t i;
for (i = 0; i < n; i++) if (list[i] == block) return 1;
return 0;
}
static int d_open(blkio_dev_t *dev, const blkio_params_t *p) { dev->state = p->opaque; return BLKIO_OK; }
static int d_close(blkio_dev_t *dev) { (void)dev; return BLKIO_OK; }
static int d_read(blkio_dev_t *dev, uint32_t fblock, void *dst)
{
fake_disk *d = (fake_disk *)dev->state;
if (fblock >= d->blocks) return BLKIO_EINVAL;
if (listed(d->fail_read, d->n_fail_read, fblock)) return BLKIO_EIO;
memcpy(dst, d->bytes + (size_t)fblock * BLKIO_FORTH_BLOCK_SIZE, BLKIO_FORTH_BLOCK_SIZE);
return BLKIO_OK;
}
static int d_write(blkio_dev_t *dev, uint32_t fblock, const void *src)
{
fake_disk *d = (fake_disk *)dev->state;
if (fblock >= d->blocks) return BLKIO_EINVAL;
if (listed(d->fail_write, d->n_fail_write, fblock)) return BLKIO_EIO;
memcpy(d->bytes + (size_t)fblock * BLKIO_FORTH_BLOCK_SIZE, src, BLKIO_FORTH_BLOCK_SIZE);
d->writes++;
return BLKIO_OK;
}
static int d_flush(blkio_dev_t *dev) { fake_disk *d = (fake_disk *)dev->state; d->flushes++; return d->fail_flush ? BLKIO_EIO : BLKIO_OK; }
static int d_info(blkio_dev_t *dev, blkio_info_t *out)
{
fake_disk *d = (fake_disk *)dev->state;
memset(out, 0, sizeof *out);
out->forth_block_size = BLKIO_FORTH_BLOCK_SIZE;
out->total_blocks = d->blocks;
out->phys_sector_size = 512u;
out->phys_size_bytes = (uint64_t)d->blocks * BLKIO_FORTH_BLOCK_SIZE;
return BLKIO_OK;
}
static const blkio_vtable_t fake_vt = { d_open, d_close, d_read, d_write, d_flush, d_info };
int fake_disk_open(blkio_dev_t *dev, fake_disk *d, uint32_t blocks)
{
blkio_params_t p;
memset(d, 0, sizeof *d);
d->bytes = (uint8_t *)calloc(blocks, BLKIO_FORTH_BLOCK_SIZE);
d->blocks = blocks;
if (!d->bytes) return BLKIO_EIO;
memset(&p, 0, sizeof p);
p.forth_block_size = BLKIO_FORTH_BLOCK_SIZE;
p.total_blocks = blocks;
p.opaque = d;
return blkio_open(dev, &fake_vt, &p);
}
int fake_disk_bind(blkio_dev_t *dev, fake_disk *d)
{
blkio_params_t p;
memset(&p, 0, sizeof p);
p.forth_block_size = BLKIO_FORTH_BLOCK_SIZE;
p.total_blocks = d->blocks;
p.opaque = d;
return blkio_open(dev, &fake_vt, &p);
}
void fake_disk_free(fake_disk *d) { free(d->bytes); d->bytes = 0; }
void fake_disk_fail_read(fake_disk *d, uint32_t block) { if (d->n_fail_read < FAKE_DISK_MAX_FAULTS) d->fail_read[d->n_fail_read++] = block; }
void fake_disk_fail_write(fake_disk *d, uint32_t block) { if (d->n_fail_write < FAKE_DISK_MAX_FAULTS) d->fail_write[d->n_fail_write++] = block; }
uint8_t *fake_disk_sector(fake_disk *d, uint64_t lba) { return d->bytes + (size_t)lba * 512u; }
+45
View File
@@ -0,0 +1,45 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* fakes.h -- what a kernel unit calls, faked on the host: the console (captured), the RNG
* (deterministic), and a RAM disk whose reads or writes fail at chosen 1 KiB blocks
* (docs/v4.0.0/plans/2026-11-12-kernel-host-tests.md).
*/
#ifndef KERNEL_TESTS_FAKES_H
#define KERNEL_TESTS_FAKES_H
#include <stdint.h>
#include <stddef.h>
#include "blkio.h"
/* The console: every console_println/console_puts line, in order. */
void fake_console_reset(void);
int fake_console_said(const char *text); /* 1 if some line contains `text` */
unsigned fake_console_lines(void);
const char *fake_console_line(unsigned i);
/* The RNG: a fixed sequence, so a test's GUIDs are the same every run; fake_rng_fail makes
* rng_get_bytes return -1 (no backend). */
void fake_rng_reset(void);
void fake_rng_fail(int fail);
/* A RAM disk of `blocks` 1 KiB blocks (512-byte sectors, so 2 per block). A read or write of a
* block in its fail lists returns BLKIO_EIO and changes nothing; every write is counted. */
#define FAKE_DISK_MAX_FAULTS 8
typedef struct {
uint8_t *bytes;
uint32_t blocks;
uint32_t fail_read[FAKE_DISK_MAX_FAULTS], n_fail_read;
uint32_t fail_write[FAKE_DISK_MAX_FAULTS], n_fail_write;
unsigned writes, flushes;
int fail_flush;
} fake_disk;
int fake_disk_open(blkio_dev_t *dev, fake_disk *d, uint32_t blocks); /* zeroed; BLKIO_OK */
int fake_disk_bind(blkio_dev_t *dev, fake_disk *d); /* open another handle on d */
void fake_disk_free(fake_disk *d);
void fake_disk_fail_read(fake_disk *d, uint32_t block);
void fake_disk_fail_write(fake_disk *d, uint32_t block);
uint8_t *fake_disk_sector(fake_disk *d, uint64_t lba); /* a 512-byte sector */
#endif

Some files were not shown because too many files have changed in this diff Show More