The emulated PC only ever read a mass storage disk and then ejected it, so
the write path through a gadget went untested and the disk could not be
used from the machine running the emulator.
The default session now asks MODE SENSE(6) for the write-protect bit and,
on a writable disk whose read checked out, writes the last 8 sectors back
as read (WRITE(10), SYNCHRONIZE CACHE) and reads them again.
--usb-host nbd[:port] (or [usb] nbd_port, or the config window) locks the
medium and serves the disk on 127.0.0.1 with a small non-blocking NBD
server (t210/nbd.cpp: fixed newstyle handshake, READ/WRITE/FLUSH/DISC).
Requests become READ(10)/WRITE(10)s of up to 64 KiB, a quiet client gets
a TEST UNIT READY every second, a write-protected disk is exported
read-only, and when the client disconnects the host ejects the disk.
Serving Nyx exposed a controller model bug: a device transfer shorter than
the host's request was taken as a short packet, so bdk's 64 KiB READ(10),
sent as two 32 KiB transfers, lost the second half. Only a short or
zero-length packet (the USB2 controller's own ZLP unless the queue head
disables it) now ends the host's transfer.
tests/usb grows a write-protected scenario, WRITE(10), MODE SENSE and
SYNCHRONIZE CACHE on its RAM disk (reads sent in 32 KiB transfers, as bdk
does), and three NBD runs driven by a Python client. Checked with Nyx SD
UMS on Erista and Mariko: nbdinfo negotiates, qemu-img convert copies the
256 MiB disk byte for byte, and a qemu-io write lands in the SD image.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
Both USB controllers were plain register caches: USBCMD.RESET never
cleared, so bdk's usb_device_init() timed out and none of Nyx's USB
tools could even wait for a cable.
- The Erista USB2 controller (USB1, 0x7D000000, bdk usbd.c): queue
heads at ENDPOINTLISTADDR (bdk's are in the controller at +0x1000),
transfer descriptors in DRAM, ENDPTPRIME / ENDPTSTATUS /
ENDPTCOMPLETE, SETUP packets in queue head 0 with ENDPTSETUPSTAT,
a self-clearing controller reset and the PHY's clock-valid bit. Byte
and halfword accesses work, since bdk memcpy()s SETUP packets out.
- The Mariko XUSB device controller (0x700D0000, bdk xusbd.c): endpoint
contexts and TRB rings with Link TRBs and cycle bits, the doorbell, a
two-segment event ring with Port Status Change, Setup and Transfer
events, EP_HALT / EP_STCHG, EP_RELOAD, and PORTSC's write-1-to-clear
changes and link-state writes.
- The host (--usb-host, [usb] host, or the config window) plays the PC
on whichever controller attaches: debounce, bus reset at high speed,
enumeration with SET_ADDRESS recovery, then after 100 ms for its class
driver to bind - bdk's XUSB driver stalls an early GET_MAX_LUN - the
class. For mass storage it runs Bulk-Only Transport: GET_MAX_LUN,
INQUIRY, TEST UNIT READY with REQUEST SENSE for the unit attention,
READ CAPACITY, READ(10) of the first 64 and last 8 blocks with their
CRC32s, checked against the SD image when the size matches, then allow
removal, eject, and poll until the gadget detaches. For HID it reads
the report descriptor, sets idle 0 and polls the interrupt endpoint.
It only reads, and it runs on the controllers' register accesses, so
runs repeat. [usb-host] lines log it; RCM_USB_TRACE=1 logs every
descriptor, TRB and doorbell.
With hekate 6.5.3, Nyx's SD card mass storage enumerates as 11EC:A7E0,
reads back identical to the SD image and ends at "Disk ejected" on both
Erista and Mariko; the gamepad enumerates and serves its report
descriptor (with no Joy-Cons it has nothing to report). Without a host
Nyx waits and reports a timeout, as with no cable.
tests/usb/ runs a mass storage gadget over a RAM disk on each controller
and a HID gadget on the USB2 one, checks what the host logs - the
enumeration, the SCSI commands, CRC32s equal to the payload's, the eject
and the detach - and a run with nothing on the cable.
The Windows pread/pwrite shim moves from mmio.cpp to platform.h, as the
host reads the SD image too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
Both ops finished with OP_DONE and produced nothing. se_rng_pseudo()
left its buffer as it was, so Nyx's partition manager wrote whatever
was on the stack into GPT partition GUIDs, and the SD benchmark drew
its random offsets from uninitialised memory. se_rsa_exp_mod() read
back zeros.
- RSA, as Lockpick's bdk drives it: two keyslots of up to 2048 bits
loaded through SE_RSA_KEYTABLE_ADDR/DATA, KEY_SIZE in 512-bit steps,
EXP_SIZE in words, the input a little-endian number over DMA and the
result in SE_RSA_OUTPUT (or memory). Montgomery multiplication on
32-bit words; an even modulus fails the op.
- RNG into memory or a keyslot quad, LAST_BLOCK + 1 blocks cut to the
buffer. The bytes come from SplitMix64 with a fixed seed, reset with
the SE, so runs stay reproducible.
tests/se/ is a new make test payload: RSA-2048 and RSA-1024 in the two
slots, each m^d and s^e checked against Python (gen_vectors.py writes
vectors.h), SHA-256 one-shot and in two parts, AES-128 ECB, and the
RNG filling a zeroed buffer, changing between calls and stopping at
the size asked for. Run against the previous binary it fails the RSA
and RNG checks. The README's "RSA, RNG and chunked SHA are stubs" is
gone; chunked SHA was already modelled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
- DC: a window's fetch starts at ADDR_V_OFFSET * LINE_STRIDE +
ADDR_H_OFFSET (TRM 24.11.1). That is the window's top-left pixel, or
top-right with H_DIRECTION, or bottom-left with V_DIRECTION, and the
fetch walks away from it; before, the offsets were ignored and flips
mirrored within the window. HOS's column-scan offset (0x13FF) and
hekate's inverted-pitch offset (1279) both land where they should.
Layer order is documented: the TRM sorts windows by depth without
saying which way.
- VIC: slot and output surfaces may be block linear (BlkKind 1, 2^BlkHeight
GOBs per block) as well as pitch.
- GOB addressing moves to t210/block_linear.h, shared by the scan-out
and VIC.
- tests/display: one bare-metal payload built per scenario (a pitch
window, Nyx's VIC turn into pitch and into block-linear surfaces, a
block-linear VIC source, the DC's own column scan with an address
offset, a mirrored window with window D blended over). check.py
compares every pixel of the frame the emulator shows with the picture
drawn. It runs in make test and in CI.
hwtest's frame is unchanged, and Nyx's differs only in its clock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
- tests/ccplex: a self-contained BPMP payload (ARM, arm-none-eabi-gcc; the
AArch64 side is pre-assembled words) that drives CPU0 through bdk's
ccplex_boot_cpu0() register sequence. It checks that an unpowered
release is refused with its reason, that a powered one runs at EL3 from
the SB vector and writes the mailbox, that CPU0 sees TIMERUS move, that
WFE parks the core, and that RST_CPUG_CMPLX_SET stops it. `make test`.
- tests/hwtest: build hwtest-rcm from a pinned commit with distro
toolchains (an empty base_rules stands in for devkitARM, the CPU0 stub
builds with gcc-aarch64-linux-gnu) and run its whole sweep headless,
checking the CPU0-driven Wi-Fi probe enumerates the CYW4356.
- CI runs both in the Linux job and keeps their logs on failure.
- Makefile: `test` target; the clean rule's line continuation was a
literal "\n" that only worked by accident.
- README/DESIGN: CCPLEX CPU0, the uc_mmio_map bus, the block-level clock
and TIMERUS poll pacing, the new bug-history entries.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
Double-clicking the emulator printed a usage line to a console nobody sees
and exited. It now opens a window that accepts a dropped .bin, with O for the
system file dialog - GetOpenFileName on Windows, zenity or kdialog on Linux,
since there is no such thing there without dragging in a toolkit. The window
draws a dashed frame and an upload glyph from rectangles and one filled
triangle; no text, because a font would have to be vendored for a screen that
lives a few seconds and the instruction is on the title bar already. It is
created and destroyed before the emulator's own display comes up, so it
cannot interfere with the framebuffer window. A headless or toolkit-less
machine falls back to the old usage message, and dragging a payload onto the
executable still skips all of it - that arrives as argv[1].
Dropping a payload was then unusably slow, and the reason had nothing to do
with the picker. A full hwtest sweep printed 52,452 lines, of which about
51,900 were per-register-access traces: 29,673 [gpio], 16,707 [mmio], 5,430
[sdmmc]. Redirected to a file that is merely wasteful, which is why it went
unnoticed - every scripted run here redirects. On a Windows console it is
not: each line goes through conhost one write at a time. Those traces now
need --trace or RCM_EMU_TRACE=1, which drops default output to 578 lines -
the payload's own UART plus the handful of [emu], [display], [pcie] and
[audio] lines worth seeing. The flag brings all 48,354 back when a
register-level question needs answering.
Also adds RCM_EMU_PICK, which runs the picker's window lifecycle and returns
a path as if it had been dropped, so that path can be tested by a script
instead of only by a human dragging a file.
Two things, both about being able to check the emulator's work rather than
infer it.
Sound. The samples a payload pushes through the ADMAIF PIO port were being
discarded; now they are written to last_audio.wav and played on the host.
Each FIFO word is already a stereo frame, so the capture needs only a header.
The take is played after it is complete rather than streamed while it is
produced: the emulator generates samples in bursts and stalls entirely
between phrases while the payload talks to the codec over I2C, so a live
stream underruns wherever the producer falls behind the sound card, heard as
flicker. Queueing the finished buffer removes the producer from the timing
path. The rate comes from the I2S_TIMING the payload programmed, not a
nominal 48 kHz, or the melody replays at the wrong pitch.
Windows. Cross-compiled in a container, since neither dependency has a MinGW
package. Three things had to be fixed to get there, none of them findable
without actually trying it:
- mingw GCC 13 hits an internal compiler error on unicorn's
qemu/softmmu/memory.c at -O2, so unicorn is built at -O1.
- pread/pwrite are POSIX and absent on MinGW. The SD/eMMC image access now
has a seek-then-read shim, which is equivalent here because the emulated
storage is only touched from the CPU thread.
- SDL renames main on Windows, so SDL2main must be linked before SDL2 with
SDL_MAIN_HANDLED, and unicorn's threads need winpthread.
The .exe is static: one file, no DLLs beside it. Verified running natively -
it emulates a full hwtest sweep and plays the melody through WASAPI.
CI covers both platforms, and a third job runs the .exe on a Windows runner,
because a cross-build only proves it links. Builds on push and PR, not just
tags: the Windows build broke in three separate ways the first time it was
attempted, and a Linux-only workflow would have shown none of them.