memw(R1) = R0
dccleana(R1) // force data out of data cache
barrier // ensure data is in memory
icinva(R1) // clear it from instruction cache
isync // ensure icinva instr is finished
jumpr R1 // can now execute code at R1
原子操作
// assume mutex address is held in R0
// assume R1,R3,P0,P1 are scratch
lockMutex:
R3 = #1
lock_test_spin:
R1 = memw_locked(R0) // do normal test to wait
P1 = cmp.eq(R1,#0) // for lock to be available
if (!P1) jump lock_test_spin
memw_locked(R0,P0) = r3 // do store conditional (SC)
if (!P0) jump lock_test_spin // was LL and SC done atomically?
如下为官方推荐的释放互斥锁的代码:
// assume mutex address is held in R0
// assume R1 is scratch
R1 = #0
memw(R0) = R1
原子的 操作用于支持AXI总线的外部访问。为实现外部内存的导入锁操作。操作系统必须定义内存页为不可缓存项,否则CPU的操作可能为未知。