Compare commits
16
Commits
8a0dab7f48
...
9077618c49
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9077618c49 | ||
|
|
e0dcaa163b | ||
|
|
b0038376a7 | ||
|
|
947d044872 | ||
|
|
4738aee4c0 | ||
|
|
e453fde3d4 | ||
|
|
83898b524d | ||
|
|
d7b2f6bf54 | ||
|
|
2bac2ac8fc | ||
|
|
3c053f02a6 | ||
|
|
41f8648dd9 | ||
|
|
c778f6e0e7 | ||
|
|
8649463a58 | ||
|
|
a882465573 | ||
|
|
8b482bedb8 | ||
|
|
37b1527279 |
@@ -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).
|
||||
|
||||
@@ -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
@@ -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.
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
@@ -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;
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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
|
||||
@@ -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; }
|
||||
@@ -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
Reference in New Issue
Block a user