Reorganize source tree: kernel/, v3/, v4/ split and board infrastructure
Source tree reorganization: - Move StarForth v3 engine to v3/ (src/, include/, Makefile) - Move kernel to kernel/ (src/, include/, linker/, Makefile) - Create v4/ skeleton for F18-ISA golden model (DECOMPOSITION.md, JUSTIFICATION.md) - Move FABRIC-0..4.md to docs/fabric/ - Move ONTOLOGY.md and ROADMAP.md to docs/ Board infrastructure: - Add boards/ser5/, boards/raspi/, boards/milkv/, boards/zynq7020/ - Each board has board.mk (ISA, CPU flags, boot recipe) and README.md - Root Makefile becomes thin dispatcher: boot_image, all, clean, docs take TARGET - make boot_image TARGET=SER5|RASPI|MILKV builds one GPT/MBR image per board - ZYNQ7020 target exists but stops with clear error (ARMv7 port not built yet) - scripts/mkdiskimage.sh builds disk images for all boards Docs pipeline: - docs/book/ with LaTeX master (main.tex) and Makefile - pandoc converts Markdown to LaTeX at build time - Two Lua filters: table-widths.lua (wide tables wrap), code-breaks.lua (inline code breaks) - make docs builds single PDF (754 pages, 0 missing characters) - make docs TARGET=<board> adds board appendix - build/docs/<book|board>/meta.tex stamps git commit into PDF Bug fixes: - 42 include paths that only worked by accident now use correct relative paths - clang-18 hardcode replaced with configurable CC variable (fixed aarch64 build) - Pi 5: kernel_2712.img linked at 0x80000, .bss zeroed, memory reserved - Doxyfile, .clang-tidy, README.md, Kconfig paths updated Verified: - Hosted v3 build passes 1012 tests, 0 failures - SER5 image boots in QEMU (OVMF), POST passes, K exact (65536 = Q48_ONE) - Milk-V image boots in QEMU (OpenSBI + U-Boot + bootefi), POST passes - make clean TARGET=<board> removes only that board and its ISA objects - make all builds all boards, hosted v3, and docs in one run Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* blkio_usb.c — USB Mass Storage (Bulk-Only Transport) blkio_dev backend,
|
||||
* see blkio_usb.h. Milestone 2h.
|
||||
*/
|
||||
|
||||
#ifndef __STARKERNEL__
|
||||
#error "blkio_usb.c is kernel-only"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "starkernel/blkio_usb.h"
|
||||
#include "starkernel/kmalloc.h"
|
||||
#include "console.h"
|
||||
|
||||
typedef struct {
|
||||
xhci_dev_t *xdev;
|
||||
uint32_t slot_id;
|
||||
uint32_t scsi_block_size;
|
||||
uint32_t scsi_blocks_per_fblock; /* BLKIO_FORTH_BLOCK_SIZE / scsi_block_size */
|
||||
uint32_t total_forth_blocks;
|
||||
} BlkioUsbState;
|
||||
|
||||
/* FABRIC-3.md §VII (2026-09-05): was a single static instance ("one USB MSC
|
||||
* device, single-outstanding-transaction scope, matching the xHCI driver
|
||||
* this backend sits on") -- now a per-slot registry, same shape and same
|
||||
* sizing precedent as xhci_dev_t's own msc_slots (registry sized off the
|
||||
* controller's own max_slots, allocated once on first use here since this
|
||||
* file has no bringup-time hook of its own to do it earlier). Indexed
|
||||
* directly by xHCI slot ID, index 0 unused, matching msc_slots[]. */
|
||||
static BlkioUsbState *g_usb_blk_slots = NULL;
|
||||
static uint32_t g_usb_blk_slot_count = 0;
|
||||
|
||||
static BlkioUsbState *usb_blk_state_for(xhci_dev_t *xdev, uint32_t slot_id) {
|
||||
if (!xdev || slot_id < 1 || slot_id > xdev->max_slots) return NULL;
|
||||
if (!g_usb_blk_slots || g_usb_blk_slot_count < xdev->max_slots + 1) {
|
||||
size_t bytes = (size_t)(xdev->max_slots + 1) * sizeof(BlkioUsbState);
|
||||
BlkioUsbState *fresh = (BlkioUsbState *)kmalloc_aligned(bytes, 64);
|
||||
if (!fresh) return NULL;
|
||||
memset(fresh, 0, bytes);
|
||||
g_usb_blk_slots = fresh;
|
||||
g_usb_blk_slot_count = xdev->max_slots + 1;
|
||||
}
|
||||
return &g_usb_blk_slots[slot_id];
|
||||
}
|
||||
|
||||
static int usb_blk_open(blkio_dev_t *dev, const blkio_params_t *p) {
|
||||
/* FABRIC-3.md §VII (2026-09-05): blkio_open() zeroes dev->state before
|
||||
* calling this (see blkio.h), so the per-slot BlkioUsbState* this
|
||||
* device should use travels in through p->opaque -- set by
|
||||
* blkio_usb_open_msc() below -- rather than a single module-global. */
|
||||
if (!dev || !p || !p->opaque) return BLKIO_EINVAL;
|
||||
BlkioUsbState *s = (BlkioUsbState *)p->opaque;
|
||||
dev->state = s;
|
||||
dev->forth_block_size = BLKIO_FORTH_BLOCK_SIZE;
|
||||
dev->total_blocks = s->total_forth_blocks;
|
||||
return BLKIO_OK;
|
||||
}
|
||||
|
||||
static int usb_blk_close(blkio_dev_t *dev) {
|
||||
(void)dev;
|
||||
return BLKIO_OK;
|
||||
}
|
||||
|
||||
static int usb_blk_read(blkio_dev_t *dev, uint32_t fblock, void *dst) {
|
||||
if (!dev || !dst) return BLKIO_EINVAL;
|
||||
BlkioUsbState *s = (BlkioUsbState *)dev->state;
|
||||
if (fblock >= s->total_forth_blocks) return BLKIO_EINVAL;
|
||||
|
||||
uint32_t lba = fblock * s->scsi_blocks_per_fblock;
|
||||
if (xhci_bot_read_block(s->xdev, s->slot_id, lba,
|
||||
(uint16_t)s->scsi_blocks_per_fblock,
|
||||
s->scsi_block_size) != 0) {
|
||||
return BLKIO_EIO;
|
||||
}
|
||||
if (xhci_bot_wait_for_idle(s->xdev, 100000u) != BOT_STATUS_PASS) {
|
||||
return BLKIO_EIO;
|
||||
}
|
||||
memcpy(dst, s->xdev->bot_data_buf, BLKIO_FORTH_BLOCK_SIZE);
|
||||
return BLKIO_OK;
|
||||
}
|
||||
|
||||
static int usb_blk_write(blkio_dev_t *dev, uint32_t fblock, const void *src) {
|
||||
if (!dev || !src) return BLKIO_EINVAL;
|
||||
BlkioUsbState *s = (BlkioUsbState *)dev->state;
|
||||
if (fblock >= s->total_forth_blocks) return BLKIO_EINVAL;
|
||||
|
||||
memcpy(s->xdev->bot_data_buf, src, BLKIO_FORTH_BLOCK_SIZE);
|
||||
|
||||
uint32_t lba = fblock * s->scsi_blocks_per_fblock;
|
||||
if (xhci_bot_write_block(s->xdev, s->slot_id, lba,
|
||||
(uint16_t)s->scsi_blocks_per_fblock,
|
||||
s->scsi_block_size) != 0) {
|
||||
return BLKIO_EIO;
|
||||
}
|
||||
if (xhci_bot_wait_for_idle(s->xdev, 100000u) != BOT_STATUS_PASS) {
|
||||
return BLKIO_EIO;
|
||||
}
|
||||
return BLKIO_OK;
|
||||
}
|
||||
|
||||
static int usb_blk_flush(blkio_dev_t *dev) {
|
||||
(void)dev;
|
||||
return BLKIO_OK; /* every write above is already synchronous -- see
|
||||
* usb_blk_write()'s own xhci_bot_wait_for_idle()
|
||||
* call -- nothing buffered here to flush. */
|
||||
}
|
||||
|
||||
static int usb_blk_info(blkio_dev_t *dev, blkio_info_t *out) {
|
||||
if (!dev || !out) return BLKIO_EINVAL;
|
||||
BlkioUsbState *s = (BlkioUsbState *)dev->state;
|
||||
out->forth_block_size = BLKIO_FORTH_BLOCK_SIZE;
|
||||
out->total_blocks = s->total_forth_blocks;
|
||||
out->phys_sector_size = s->scsi_block_size;
|
||||
out->phys_size_bytes = (uint64_t)s->total_forth_blocks * BLKIO_FORTH_BLOCK_SIZE;
|
||||
out->read_only = 0; /* WRITE(10) verified live end-to-end on amd64,
|
||||
* 2026-08-28 (FABRIC-2.md §F.1): BLK-CONFIRM-FORMAT's
|
||||
* BAM/reloc writes and an explicit content write both
|
||||
* survived a cold reboot and read back correctly. */
|
||||
return BLKIO_OK;
|
||||
}
|
||||
|
||||
static const blkio_vtable_t g_usb_blk_vtable = {
|
||||
.open = usb_blk_open,
|
||||
.close = usb_blk_close,
|
||||
.read = usb_blk_read,
|
||||
.write = usb_blk_write,
|
||||
.flush = usb_blk_flush,
|
||||
.info = usb_blk_info
|
||||
};
|
||||
|
||||
int blkio_usb_open_msc(blkio_dev_t *dev_out, xhci_dev_t *xdev, uint32_t slot_id) {
|
||||
if (!dev_out || !xdev) return -1;
|
||||
|
||||
BlkioUsbState *s = usb_blk_state_for(xdev, slot_id);
|
||||
if (!s) return -1;
|
||||
|
||||
if (xhci_bot_get_capacity(xdev, slot_id) != 0) return -1;
|
||||
if (xhci_bot_wait_for_idle(xdev, 100000u) != BOT_STATUS_PASS) return -1;
|
||||
|
||||
uint32_t block_size = xdev->bot_cap_block_size;
|
||||
if (block_size == 0 || (BLKIO_FORTH_BLOCK_SIZE % block_size) != 0) {
|
||||
console_println("blkio_usb: SCSI block size doesn't divide Forth block size -- refusing");
|
||||
return -2;
|
||||
}
|
||||
|
||||
uint64_t total_scsi_blocks = (uint64_t)xdev->bot_cap_last_lba + 1u;
|
||||
uint32_t blocks_per_fblock = BLKIO_FORTH_BLOCK_SIZE / block_size;
|
||||
uint64_t total_forth_blocks = total_scsi_blocks / blocks_per_fblock;
|
||||
|
||||
s->xdev = xdev;
|
||||
s->slot_id = slot_id;
|
||||
s->scsi_block_size = block_size;
|
||||
s->scsi_blocks_per_fblock = blocks_per_fblock;
|
||||
s->total_forth_blocks = (total_forth_blocks > 0xFFFFFFFFull)
|
||||
? 0xFFFFFFFFu
|
||||
: (uint32_t)total_forth_blocks;
|
||||
|
||||
console_println("blkio_usb: MSC device ready");
|
||||
|
||||
blkio_params_t params;
|
||||
params.forth_block_size = BLKIO_FORTH_BLOCK_SIZE;
|
||||
params.total_blocks = s->total_forth_blocks;
|
||||
params.opaque = s;
|
||||
|
||||
return blkio_open(dev_out, &g_usb_blk_vtable, ¶ms);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user