From 4b08ffea6350d4be07038648ff9072e298d78068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=AFl=20Dogru?= Date: Fri, 22 May 2026 15:15:17 +0100 Subject: [PATCH] Add memory clobber to WITH_BACKUP_RAM_RW asm 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. --- nullbios/utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nullbios/utils.h b/nullbios/utils.h index 7850662..77908e9 100644 --- a/nullbios/utils.h +++ b/nullbios/utils.h @@ -20,10 +20,10 @@ #ifndef __NULLBIOS_UTILS_H__ #define __NULLBIOS_UTILS_H__ -#define WITH_BACKUP_RAM_RW(x) { \ - __asm__ volatile ("move.b %d0, 0x3a001d.l"); \ - x \ - __asm__ volatile ("move.b %d0, 0x3a000d.l"); \ +#define WITH_BACKUP_RAM_RW(x) { \ + __asm__ volatile ("move.b %d0, 0x3a001d.l" ::: "memory"); \ + x \ + __asm__ volatile ("move.b %d0, 0x3a000d.l" ::: "memory"); \ } #define CC_CLEAR_X_FLAG() \