Skip to content

More RAM for the mods: 0026 / 0029's large buffers in DDR claims outside elekloader's area (big-ram) - #34

Open
twwwy wants to merge 4 commits into
trigcondition:devfrom
twwwy:feat/big-ram-up
Open

twwwy wants to merge 4 commits into
trigcondition:devfrom
twwwy:feat/big-ram-up

Conversation

@twwwy

@twwwy twwwy commented Nov 23, 2026 •

Copy link
Copy Markdown

Closes #32. The host half is trigcondition/sidecar-firmware#73. Apply #33 first.

Why

With the full mod set, elekloader's 128 KiB area is nearly full, and MORPH, the re-hello and the later topics need room. This moves 0026's and 0029's large buffers out of it, into free DDR, claimed in the registry.

The method

Free DDR on stock 1.74.

  • elekloader's boot copier copies and zeroes only its own area. A buffer a mod addresses absolutely is never touched by it, so this works with the current core and web flasher unchanged.
  • Nothing in 1.74 uses 0x47C00000-0x47C40000:
    • Static: no instruction operand in the image names an address there, in either alias. The highest buffer named is the DMA list, ending at 0x47B47480.
    • Modwerk's RAM-booted run and elekloader's big area canary agree.
    • Hardware: one MKII ran a diagnostic build, then this design. Details are under Tests.

Registry (registry/allocations.toml).

  • A new [[pool]], ddr_mods, at 0x47C00000-0x47C40000 (256 KB). It names its OS (os = "1.74"), and the evidence is in its note, in the cave pools' style.
  • Claims are [[ddr]] tables, a claim kind beside cave / ram.
  • layout.py checks them as it checks caves (inside a pool, no overlaps), plus: named, 16-aligned, at least 32 B. A DDR pool must lie outside the image and elekloader's area, and holds claims for its own OS only.
  • build.py gives each enabled mod RAM_<NAME> / RAM_<NAME>_SIZE. verify.py checks the manifest's claims again.
  • Each stub refuses to assemble when its claim is smaller than its struct plus 16 B.
claim owner size holds
rui_frame 0026 0x3200 the frame buffers (shadow, staging, compose) and text planes
rui_names 0026 0x1000 the source lists' names, the name queue
rui_pmo 0026 0x2800 the param modulation (the audio interrupt's)
sfu_x 0029 0x2000 labels, TYPE lists, list knobs

Nobody zeroes DDR, so each mod does.

  • 0026 zeroes one claim a tick over its first ticks, before it publishes its SysEx handler. Doing them all in one tick put the boot tick over rui_emu cost's bound. 0029 zeroes its claim in its first tick.
  • Each claim gets an 8-byte sentinel at either end and an ok bit.
  • Until a claim's bit is set, nothing reads it, and the mod falls back to stock behaviour:
    • 0026: no param modulation (stage A rebuilds the words, so the sound is stock's), no frame, no names;
    • 0029: stock's reads and writes, values as numbers.

Checked every tick.

  • A changed sentinel clears that claim's bit until reboot, and the mod owes one report: 55 01 00 <bad bits> <address 5x7> <word 5x7>, sent again with each hello.
  • 0026 leaves the remote page with reason 4 and shows MOD RAM ERROR for 5 s.
  • An older Sidecar ignores 0x55.

The diagnostic (--param 0026-remote-ui:ddrdiag=1): fills the free DDR around the pool with an address-keyed pattern, checks 128 words a tick (DG_STEP), and reports 55 01 01 every 10 s. FUNC held shows DDR <passes> BAD <n>.

OS 1.73. I have no 1.73 image, so there's no static check and no build. 1.73 has no DDR pool, so build.py gives no RAM_ symbols. Each stub then keeps the same block in its own .bss (.ifndef RAM_<NAME>), set up and checked by the same code, and ddrdiag=1 refuses to assemble. I checked this on a 1.74 tree with the pool marked for another OS: it builds, verify passes, and the build notes "buffers stay in elekloader's area". Adding 1.73 later is a pool with os = "1.73", its evidence and the claims.

Cost (tools/build_rui.sh, OS 1.74; baseline tag r9b = dev 292ab6c, fix tag r9f = this branch)

  • Elekloader spare: 13,388 -> 43,284 B, which is 35 KB over the 8 KB reserve.
  • Code: +3,286 B (0026 44,590 -> 46,656, 0029 10,126 -> 11,346).
  • Area .bss: 0026 30,564 -> 4,064 B, 0029 6,706 -> 28 B.
  • DDR: 35,328 B of the pool's 256 KB.
  • The 1.73 path (buffers stay in the area): 9,888 B spare (−3,544 B). It frees nothing, but stays above the reserve.
  • Verify: passes on both. r9f sha256 248965cea725c7ce18a37da39ce1b799b4995a55b605226eb4b172cacbc8eb08.
  • hash_expect: --image build/stock_mainos.bin converted nothing, and --check passes.

What I ran

In build/os/1.74 after tools/ostarget.py port 1.74, rytm-emu, DTEMU_STRICT=1:

tools/build_rui.sh r9b    # on dev
tools/build_rui.sh r9f    # on this branch
tools/emu/us_base.sh r9b && tools/emu/us_base.sh r9f
tools/emu/suites.py r9f --changed upstream/dev -j 2   # the plan picks all 22 suites
  • Same counts as dev in every suite except these two:
  • pm's bound: raised from 100 to 105 us. One of five cases (128 entries, 96 route amounts) reads 103.6 us at most boot phases on dev's own code too. Which block a burst lands in decides it, and this branch's start-up timing makes that phase common. 105 us is about 1.5 % of a block above the old bound. The other bounds are unchanged.
  • Also run: an earlier --full run on the Makefile's release set agreed with the --changed run above.
  • Not run: the flash rehearsals (yours), and a build for 1.73 (I have no 1.73 image).

Hardware: one MKII, OS 1.74, with a larger mod set than dev's, using the same claims and addresses. This was before the licence rewrite of the caps (see the comment below).

  • The diagnostic build: ~97 min of heavy use, then a power cycle and 14 more min, then an OS .syx sent outside the upgrade menu. 0 bad words.
  • Then the real build: 1 h plus a power cycle, with no MOD RAM ERROR and no audio glitch.

Knob latency (emulator)

12 tracks of 16ths, knobs turning, mean / max ms.

On plain dev: a small cost, consistent at every budget that isn't saturated.

budget dev scene this branch, scene dev no scene this branch, no scene
122 M 460.5 / 941 502.5 / 1032 26.8 / 48 35.6 / 68
123 M 47.5 / 89 57.4 / 104 22.0 / 42 29.5 / 61
126 M 20.3 / 38 27.9 / 58 15.7 / 30 21.3 / 48
  • At 118 M both are saturated and equal. At 121 M the gap with scene edit is +32 ms.
  • The cause is pmo's guard in the audio interrupt's LFO detour, the and.l ram_ok that keeps pmo off its claim until the claim is cleared. With the guard replaced by same-size no-ops, or removed, the numbers go back to dev's. Ruled out: code layout (dev + 3,286 B of dead code), the per-tick checks, 0029, and the buffers' placement.
  • Not explained: rytm-emu models no wait states, the run's instruction counts differ by 0.001 %, and the guard never takes its branch. On a V4e it's one load per pmo call, about 2,000 a second. Moving ram_ok onto a cache line the interrupt already writes didn't change anything.
  • No safe fix so far: core 0.1 has no event before the audio interrupt, so the claim can't be cleared before pmo first runs. Ideas welcome.

On top of the performance PR (#25): no cost. The run is this branch + #33 on #25's head, against #25 alone:

budget #25 scene + this, scene #25 no scene + this, no scene
122 M 30.7 / 53 28.7 / 65 21.1 / 43 18.5 / 57
126 M 18.3 / 35 16.3 / 30 15.3 / 30 14.8 / 30

The means are equal or better. The max at 122 M is 12 to 14 ms higher.

🤖 Generated with Claude Code

twwwy and others added 3 commits November 24, 2026 03:40
A mod may keep a large zero-initialised buffer outside elekloader's
128 KB area, at a fixed DDR address the OS never uses. elekloader's boot
copier only copies and zeroes its own area, and an absolute address is
never checked by it, so this needs nothing from core 0.1 or the web page.

It fits the registry's pool scheme, as the caves do: a [[pool]] with its
evidence in its note, and claims in it.

- registry: pool ddr_mods 0x47C00000-0x47C40000 (256 KB, just above
  elekloader's area), os = "1.74", status verified. Its note gives the
  free ranges (0x47B48000-0x47BE0000, 0x47C00000-0x47FF0000; the top
  64 KB is left to the stack) and the evidence: no instruction operand
  of 1.74 names 0x47B48000-0x47FFF000 in either alias, Modwerk's and
  elekloader's DDR canaries, rytm-emu runs, and one MKII's hardware run.
  1.73 has no DDR pool yet.
- layout.py: [[ddr]] claims are checked like caves (inside a pool, no
  overlaps: POOL_OF["ddr"]), plus their own rules: named, 16-aligned,
  at least 32 B; a DDR pool names its OS and lies outside the image
  and outside elekloader's area. A pool with an `os` holds claims for
  that OS only: on another OS they are inactive.
- build.py: each enabled mod gets RAM_<NAME> and RAM_<NAME>_SIZE for
  its claims in this OS's pool as assembler symbols (defsym / .set, as
  its params), and the manifest records them. A mod whose claims are in
  another OS's pool gets none (its stub then keeps the buffers in
  elekloader's area).
- verify.py: the manifest's claims are the registry's for this OS, each
  outside the area, inside this OS's DDR pool, and disjoint.
- ostarget.py: a DDR pool is not an image address: the port passes it
  through unmapped.
- tests: test_layout.py Ddr (9 cases), test_ostarget.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a (big-ram)

On OS 1.74 the remote page's frame buffers, the source-list names and
the param modulation (0026), and 0029's labels and lists, move out of
elekloader's 128 KB area into four claims in the registry's ddr_mods
pool: rui_frame 0x47C00000 (0x3200), rui_names 0x47C03200 (0x1000),
rui_pmo 0x47C04200 (0x2800), sfu_x 0x47C06A00 (0x2000): 35,328 B of the
pool's 256 KB.

Cost, the Makefile's release set on 1.74: code +3,352 B (0026 +2,118,
0029 +1,234), area .bss -33,178 B (0026 30,564 -> 4,064, 0029 6,706 ->
28). The area's spare goes from 13,432 to 43,264 B.

- Nothing zeroes that RAM. In 0026's first three ticks (a claim a tick)
  and in 0029's first tick, before anything that reads them is
  published, each claim is zeroed and gets 8-byte sentinels at both
  ends ('RAMS' ^ address). A bit a claim (ram_ok / x_ok) says it's good;
  until then nothing reads it.
- Every tick the sentinels are checked. A changed one turns that claim
  off for the rest of the boot, and the mod falls back to what is safe
  without it: no param modulation (the sound is stock's), no frame (the
  remote page leaves with reason 4), the source names as numbers, our
  SEND FX records read-only (never stock's own write of FX 38..41), the
  value texts as numbers, the host's messages for it dropped.
- The Rytm reports it to the host once and again with each hello,
  55 01 00 <claims> <address 5x7> <word 5x7>, and shows MOD RAM ERROR
  over the stock screen for 5 s (and on TRK + YES). An older host
  ignores 0x55.
- pmo's guard is in its two detours (and.l ram_ok), not in the C
  functions, so the audio interrupt's hot path keeps gcc's code.
- ddrdiag=1 (a param, off in releases): the diagnostic image fills the
  rest of 1.74's free DDR with address ^ 0xC0DEF00D, checks 512 B of it
  a tick (a pass in ~7.5 min), reports it every 10 s (55 01 01) and
  shows "DDR <passes> BAD <n>" while FUNC is held.
- On an OS without a DDR pool (1.73) each stub keeps the same block in
  its own .bss (.ifndef RAM_<NAME>), set up and checked the same way;
  ddrdiag refuses to assemble there. That build costs 3,544 B of the
  area (the code and the sentinels) and frees nothing: 9,888 B spare
  with the release set, measured on a 1.74 tree with the pool marked
  for another OS.

Each stub refuses to assemble when its claim is smaller than its struct
+ 16. Design notes: 0026 design.md "big-ram", 0029 section 12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ram_emu.py TAG sealed | frame | pmo | names | sfux | diag:
  - sealed: the build keeps 0026 / 0029's buffers in the four DDR
    claims outside elekloader's area (fails on a build without them),
    each zeroed and sealed after boot (ram_ok 7, x_ok 1);
  - one sentinel changed per test: only that claim turns off, the
    report goes out, the mod falls back (the page leaves with reason 4
    and won't reopen, the modulation's interrupt entries stop, the
    source names stop, SEND FX turns are refused with FX 38..41
    unchanged), no fault and no strict access;
  - diag, on a ddrdiag=1 build: a changed canary word is found, written
    back and reported.
- suites.py: the ram suite.
- pm_emu cost: the worst-case bound 105 us, not 100. Its 96-route-amount
  case reads 94.2 or 103.6 us depending only on the boot's phase (which
  block a burst of records lands in), with the code before big-ram as
  well (0026 design.md, big-ram "pm's worst case"). The other bounds
  stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…vention

A provenance check of the big-ram series: its first DDR prototype was
written after another project's linker change had been looked at (a
different approach, which this series does not take: no linker or
loader change). The cap words ('RAMS' ^ address) and the clearing loops
date from after that, so they are rewritten from this tree's own design:

- caps: the two first and two last words of a claim are each their own
  address ^ 0xC0DEF00D, 0003's canary convention (this registry's cave
  canary since 2026-09, and the diagnostic image's fill);
- 0026: claim_open (clear with an end pointer, then the four caps) and
  claim_cap_bad (the first cap that does not hold); 0029: x_init /
  x_cap_bad, the same.

Same claims, addresses and sizes; the same checks, reports and
fallbacks. ram_emu sealed expects the new caps; ram 24 / 0, and 28 / 0
on a ddrdiag=1 build (diag included). Code -66 B (0026 -52, 0029 -14).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@twwwy

twwwy commented Nov 23, 2026

Copy link
Copy Markdown
Author

Licence check: I traced this series' history for anything taken from Modwerk (GPL-3.0 / Elastic-2.0). Modwerk appears only as a source of facts about the Rytm: its README reports the same DDR ranges intact on one RAM-booted MKII, and that is cited in the pool's note next to our own evidence (an operand scan of the 1.74 image, emulator canaries, and a flashed hardware run). No Modwerk code is used. Our design is fixed registry claims with no linker or loader change, the opposite of Modwerk's approach. One part, the claims' boundary words and clearing loops, was first written after Modwerk's linker change had been looked at. To be safe I rewrote it from this repo's own canary convention (address ^ 0xC0DEF00D, as the cave canary 0003 uses), in 2c25894; the claims, addresses and behaviour are unchanged, and the ram suite passes.

The full suites and the lag gate are rerunning on 2c25894; I'll post them here. The lag result is likely found: the pmo guard's load of ram_ok in the audio interrupt's LFO detour misses the cache. A fix that keeps the guard is being measured.

🤖 Generated with Claude Code

@trigcondition

Copy link
Copy Markdown
Owner

Thanks a lot for this, @twwwy. The measurements and the static operand scan are careful work, and the placement itself holds up: the pool at 0x47C00000 is clear of the sample memory, the block the OS clears at boot, the stack and every OS operand we could find on 1.74. We found no copied third-party code.

We can't merge it as it is, for four reasons:

  1. pm_emu.py ramp fails on this branch (2 of 2 runs) and passes on dev. When the modulation target changes, the modulated word drops 0x1000 to 0 in one 0.5 ms step instead of ramping. The likely cause is the next point.
  2. rui_pmo moves to DDR. The audio interrupt reads it, which is why the pm worst-case bound had to go from 100 to 105 us. Only buffers that the UI or MIDI task alone touch should move.
  3. The knob latency the PR itself reports (+42 ms with scene edit open) is still open.
  4. Nothing declares the pool to elekloader. Without a resources.regions claim the linker can't refuse an overlap, and newer cores (0.11+) place mods' data in exactly this range.

Smaller points:

  • There is no test for a dirty DDR start.
  • The sentinels guard 32 of 35 KB but cost about 3.3 KB of code and some 40 fallback branches.
  • An old Sidecar doesn't simply ignore 0x55: it falls through to the voice report.
  • On an OS without the pool, the build silently falls back to .bss instead of refusing.

What we did with it: we need this room for the next mods build, so we built a reshaped version on our side, credited "based on twwwy's #34":

  • the UI-task buffers of 0026 and 0029 only (pmo stays in .bss, so the ramp test passes and the bound stays at 100 us);
  • placed through a declared region ([[buffer]] claims plus resources.regions), so elekloader and the build refuse an overlap;
  • zeroed at the first tick, with an emulator test that boots over junk;
  • no fallback branches: the build refuses an OS without the region.

That frees about 23 KB of the area. It will be in the next mods release. So please don't spend more time on this branch; we'll close it when that release is out. Your notes made it possible, thank you.

Before we close it, one check, as AGENTS.md asks: did you use only Modwerk's README (the canary ranges and timings), and not its code?

@twwwy

twwwy commented Nov 24, 2026

Copy link
Copy Markdown
Author

Yes for the code: no Modwerk code is in #34. From Modwerk I used only facts from its README: the free ranges, and the RAM-booted run's outcome.

To be complete: on 2026-11-20, while investigating, our agents also looked at Modwerk's linker change and a few of its source files. That was before this branch existed, in a separate comparison. We took a different approach, fixed registry claims with no linker change. The two parts first written after that look, the claims' boundary words and their clearing loops, I rewrote from this repo's own canary convention in 2c25894 to be safe. That is the audit I described in my comment above.

From now on our agents don't read Modwerk's source at all.

Thanks for building the reshaped version. Your four points make sense, and keeping pmo in .bss explains both the ramp failure and the guard cost.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants