X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Kernel%2Farch%2Farm7%2Finclude%2Flock.h;fp=Kernel%2Farch%2Farm7%2Finclude%2Flock.h;h=9b289d137fd859f1f34155bc37d8278581dc68bc;hb=e4ccf568b07857a36382433ed73ea38874843b24;hp=0000000000000000000000000000000000000000;hpb=9c61cf12758c0977ee1dc5791cba638fd3437ba6;p=tpg%2Facess2.git diff --git a/Kernel/arch/arm7/include/lock.h b/Kernel/arch/arm7/include/lock.h new file mode 100644 index 00000000..9b289d13 --- /dev/null +++ b/Kernel/arch/arm7/include/lock.h @@ -0,0 +1,50 @@ +/* + * Acess2 + * ARM7 Architecture + * + * lock.h - Hardware level spinlocks + */ +#ifndef _LOCK_H_ +#define _LOCK_H_ + +// === CODE === +struct sShortSpinlock { + int Lock; +}; + +// --- Spinlocks --- +static inline int IS_LOCKED(struct sShortSpinlock *Lock) +{ + return !!Lock->Lock; +} + +static inline int CPU_HAS_LOCK(struct sShortSpinlock *Lock) +{ + // TODO: Handle multiple CPUs + return !!Lock->Lock; +} + +static inline int SHORTLOCK(struct sShortSpinlock *Lock) +{ + // Shamelessly copied from linux (/arch/arm/include/asm/spinlock.h) until I can fix stuff + Uint tmp; + __asm__ __volatile__ ( + "1: ldrex %0, [%1]\n" + " teq %0, #0\n" + " strexeq %0, %2, [%1]\n" // Magic? TODO: Look up + " teqeq %0, #0\n" + " bne 1b" + : "=&r" (tmp) // Temp + : "r" (&Lock->Lock), "r" (1) + : "cc" // Condition codes clobbered + ); + return 1; +} + +static inline void SHORTREL(struct sShortSpinlock *Lock) +{ + Lock->Lock = 0; +} + +#endif +