Skip to content

Dmod_SyncCode: make a loaded module's code safe to execute - #325

Merged
JohnAmadis merged 1 commit into
developfrom
feature/sync-code
Oct 4, 2026
Merged

JohnAmadis merged 1 commit into
developfrom
feature/sync-code

Conversation

@JohnAmadis

Copy link
Copy Markdown
Contributor

Summary

Adds the SAL function Dmod_SyncCode(Address, Size). The module loader calls it once a module is loaded and relocated, before any of its code runs.

  • Why it is needed: on a core with caches, the freshly written code may still sit in the data cache. The instruction cache may also hold an unloaded module's code from the same addresses.
  • What the system does: it cleans the data cache for the range and invalidates the instruction cache. dmod-boot implements it for the Cortex-M7 in choco-technologies/dmod-boot feature/cortex-m7-caches.
  • Default: a weak implementation that does nothing, right for cores without caches and for hosts.
  • Loader change: Dmod_Ldr_Load() calls Dmod_SyncCode(Context->Data, Context->Size) after loading the BSS and before reading the required modules.

Testing

On an STM32F746G-DISCO with I- and D-cache enabled and the SDRAM cached write-back:

  • every module loaded at boot starts and runs: drivers, systemd services, dmview, the dmell console (some of them load into the SDRAM, where the I-cache now matters);
  • the dmview demo runs for many minutes.

🤖 Generated with Claude Code

The loader calls it once a module is loaded and relocated. On a core with
caches the system cleans the data cache for the range and invalidates the
instruction cache - the code may still be in the data cache, and the
instruction cache may hold an unloaded module's code from the same
addresses. The weak default does nothing (no caches, hosts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JohnAmadis JohnAmadis self-assigned this Oct 4, 2026
@JohnAmadis
JohnAmadis merged commit fbf6c90 into develop Oct 4, 2026
6 checks passed
JohnAmadis added a commit to choco-technologies/dmod-boot that referenced this pull request Oct 4, 2026
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