Skip to content

Commit

Permalink
Add isb and prevent CPU from postponing threadOnException memory writes
Browse files Browse the repository at this point in the history
  • Loading branch information
TuxSH committed Sep 15, 2023
1 parent a4634c0 commit 0f09885
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libctru/include/3ds/synchronization.h
Expand Up @@ -42,6 +42,12 @@ static inline void __dmb(void)
__asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 5" :: [val] "r" (0) : "memory");
}

/// Performs an Instruction Synchronization Barrier (officially "flush prefetch buffer") operation.
static inline void __isb(void)
{
__asm__ __volatile__("mcr p15, 0, %[val], c7, c5, 4" :: [val] "r" (0) : "memory");
}

/// Performs a clrex operation.
static inline void __clrex(void)
{
Expand Down
3 changes: 3 additions & 0 deletions libctru/include/3ds/thread.h
Expand Up @@ -117,4 +117,7 @@ static inline void threadOnException(ExceptionHandler handler, void* stack_top,
*(u32*)(tls + 0x40) = (u32)handler;
*(u32*)(tls + 0x44) = (u32)stack_top;
*(u32*)(tls + 0x48) = (u32)exception_data;

__dsb();
__isb();
}

0 comments on commit 0f09885

Please sign in to comment.