Add memory clobber to WITH_BACKUP_RAM_RW asm#132
Merged
dciabrin merged 1 commit intoJul 18, 2026
Conversation
Without a memory clobber, gcc -O2 may reorder reads/writes of backup-RAM globals across the unlock/lock pair, defeating the protection. ::: "memory" makes both __asm__ volatile blocks act as proper compiler barriers.
Owner
|
LGTM |
Contributor
Author
|
Oh... That's great I have became a contributor!!!!! This made my day 😄 |
Owner
|
Oops, that commit broke the build on all arch :) |
Owner
|
Fixed in 28b5276 |
pull Bot
pushed a commit
to sysfce2/ngdevkit
that referenced
this pull request
Jul 18, 2026
Commit ca710f9 added memory fencing hints for the compiler, but in doing so, this broke the original asm instruction due to how we did not guard symbol % when referencing %d0 Ref dciabrin#132
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Without a memory clobber, gcc -O2 may reorder reads/writes of backup-RAM globals across the unlock/lock pair in WITH_BACKUP_RAM_RW, defeating the protection. Adding ::: "memory" to both asm volatile blocks makes them proper compiler barriers without changing emitted code for the asm itself.
Code example:
Without "memory", gcc might rearrange to:
The save_count write happens while BRAM is re-locked → hardware rejects the write → save data corrupted on the next save cycle.