Skip to content

Cortex-M: add compiler fences to interrupt enable/disable asm - #1002

Merged
Grazfather merged 3 commits into
mainfrom
copilot/fix-missing-compiler-fences
Jul 29, 2026
Merged

Cortex-M: add compiler fences to interrupt enable/disable asm#1002
Grazfather merged 3 commits into
mainfrom
copilot/fix-missing-compiler-fences

Conversation

Copilot AI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Cortex-M interrupt toggling used inline cpsie i / cpsid i without a compiler memory clobber, allowing surrounding memory operations to be reordered by the optimizer. This aligns the implementation with expected compiler-fence semantics for IRQ state transitions.

  • What changed

    • Updated core/src/cpus/cortex_m.zig interrupt primitives to include a "memory" clobber on both global IRQ control instructions.
  • Why this matters

    • Ensures memory accesses are not moved across interrupt enable/disable boundaries by the compiler.
  • Code update

    pub fn enable_interrupts() void {
        asm volatile ("cpsie i" ::: "memory");
    }
    
    pub fn disable_interrupts() void {
        asm volatile ("cpsid i" ::: "memory");
    }

Copilot AI changed the title [WIP] Fix missing compiler fences in interrupt code Cortex-M: add compiler fences to interrupt enable/disable asm Jul 29, 2026
Copilot AI requested a review from Grazfather July 29, 2026 18:54
@Grazfather

Copy link
Copy Markdown
Collaborator

@copilot Use the new clobber syntax:
https://ziglang.org/documentation/master/#toc-Assembly

.{ .memory = true}

Copilot AI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Use the new clobber syntax:
https://ziglang.org/documentation/master/#toc-Assembly

...

Updated in commit 314fb60 to use the new clobber syntax for both Cortex-M IRQ helpers: asm volatile ("cpsie i" ::: .{ .memory = true }); and asm volatile ("cpsid i" ::: .{ .memory = true });.

Copilot AI requested a review from Grazfather July 29, 2026 20:02
@Grazfather
Grazfather marked this pull request as ready for review July 29, 2026 21:59
@Grazfather
Grazfather merged commit faf3c06 into main Jul 29, 2026
31 of 33 checks passed
@Grazfather
Grazfather deleted the copilot/fix-missing-compiler-fences branch July 29, 2026 22:00
@g-berthiaume

g-berthiaume commented Jul 30, 2026

Copy link
Copy Markdown

Thanks!

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.

[CPU: Cortex-M] Missing compiler fences in the interrupt code?

4 participants