Skip to content

Map simulated MEM-AP devices and shared RAM. - #83

Merged
jon merged 2 commits into
mainfrom
work/sim-mapped-memory
Oct 4, 2026
Merged

jon merged 2 commits into
mainfrom
work/sim-mapped-memory

Conversation

@jon

@jon jon commented Oct 4, 2026

Copy link
Copy Markdown
Owner

MEM-AP simulations can now route bounded address ranges to devices and share RAM across APs. After adding both MEM-AP fixtures, map one store through them before connecting the wire:

ram := new(dapsim.RAM)
if err := ram.SetBytes(0x20040000, []byte{0, 0, 0, 0}); err != nil {
    return err
}
for _, sel := range []dap.APSel{dap.NewAPSel(0), dap.NewAPSel(1)} {
    if err := target.MapMEMAPDevice(sel, 0x20040000, 0x100, ram); err != nil {
        return err
    }
}
snapshot, err := ram.Bytes(0x20040000, 4)

Here dapsim is dap/sim. Separate MemoryDevice values can occupy the same register address through different APs. Their Read(ctx, addr, data) and Write(ctx, addr, data) methods receive one complete access in address byte order; the MEM-AP keeps numeric byte order, DRW lanes, posting and TAR state. Compose the target with the existing swd/sim wire and acquire MEM-APs through the public DAP API. Release MEM-APs before the DP, retaining owners if cleanup fails. All traffic and shared-store access must be serialized.

Existing ordinary-memory fixture calls remain usable:

err := target.SetMEMAPBytes(sel, addr, data)
snapshot, err := target.MEMAPBytes(sel, addr, len(data))

For a mapped RAM range, use ram.SetBytes(addr, data) and ram.Bytes(addr, len(data)) instead. Target fixture helpers reject mapped ranges so they cannot bypass device effects. Live reads and writes still go through dap.MemAP.

Why

The simulator previously stored ordinary bytes behind each MEM-AP. Register side effects required separate memory fakes, and AP views could not share one RAM store. Device callbacks now run beneath the real SWD and DAP layers. Mapping crossings and ErrBusFault set STICKYERR after AP acceptance; subsequent requests observe FAULT. Other callback errors report ErrDeviceFailure; errors.Is(err, dapsim.ErrDeviceFailure) distinguishes them from bus faults. Their text and context cancellation/deadline identity survive, but their protocol classifications do not, so a callback WAIT cannot replay an accepted write. Mappings freeze before traffic, narrow writes do not synthesize read/modify/write, and no failed access is replayed.

The simulator does not execute processors or model bus latency or pending completion.

Documentation

The DAP guide describes mapping, shared-store setup and snapshots, fault behavior, serialization and cleanup. Architecture and capability documentation reflect the implemented scope.

jon added 2 commits October 4, 2026 13:53
MEM-AP fixtures held only ordinary bytes, so register side effects
and device bus errors could not run through the simulated DAP stack.

Map fixed address ranges to complete device accesses while keeping
byte order, posting and TAR state in the MEM-AP. Bus errors set sticky
DP state after acceptance; fixture helpers reject mapped ranges so
they cannot bypass device effects.

Wrap callback failures so a callback WAIT cannot replay an accepted
access. Preserve the diagnostic text and context cancellation or
deadline identity.
Independent MEM-AP byte fixtures could not expose one memory store
through several APs. Add sparse shared RAM with explicit fixture
writes and detached snapshots, preserving each AP's byte order and
keeping private device windows separate.

The zero RAM value is usable. Bus accesses validate width, alignment,
bounds and cancellation before effects; fixture operations copy their
slices and remain separate from bus traffic.
@jon

jon commented Oct 4, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T23:26:06.019179Z da23041 Manual request
🔒 Security Review ✅ Completed 2026-10-04T23:16:08.988858Z da23041 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da230411d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread dap/sim/ram.go
@jon

jon commented Oct 4, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Please review head da230411d8fe1d8eb7f4c671beb23898f45acecc again. The previous finding counted the aggregate PR diff as one commit; the published commits add 245 and 82 non-test Go lines, with tests and documentation at each capability boundary. The thread has the commit details.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: da230411d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jon
jon merged commit efdbbc0 into main Oct 4, 2026
9 checks passed
@jon
jon deleted the work/sim-mapped-memory branch October 4, 2026 23:30
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.

1 participant