X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=blobdiff_plain;f=KernelLand%2FKernel%2Farch%2Fx86_64%2Flib.c;fp=KernelLand%2FKernel%2Farch%2Fx86_64%2Flib.c;h=60770f63679495e9b3d991330cd221d309ea7765;hp=b35db69cdc707681b838bfda15eccdf6ad343397;hb=845b6f9d90bb87b5e760e4d49aa93b0e003ab750;hpb=67a7fe2bb79eceaf10c572a99bd8345c4e81cf5b diff --git a/KernelLand/Kernel/arch/x86_64/lib.c b/KernelLand/Kernel/arch/x86_64/lib.c index b35db69c..60770f63 100644 --- a/KernelLand/Kernel/arch/x86_64/lib.c +++ b/KernelLand/Kernel/arch/x86_64/lib.c @@ -88,6 +88,8 @@ void SHORTLOCK(struct sShortSpinlock *Lock) Lock->Depth ++; return ; } + #else + ASSERT( !CPU_HAS_LOCK(Lock) ); #endif // Wait for another CPU to release @@ -146,6 +148,18 @@ void SHORTREL(struct sShortSpinlock *Lock) #endif } +void __AtomicTestSetLoop(Uint *Ptr, Uint Value) +{ + __ASM__( + "1:\n\t" + "xor %%eax, %%eax;\n\t" + "lock cmpxchg %0, (%1);\n\t" // if( Ptr==0 ) { ZF=1; Ptr=Value } else { ZF=0; _=Ptr } + "jnz 1b;\n\t" + :: "r"(Value), "r"(Ptr) + : "eax" // EAX clobbered + ); +} + // === DEBUG IO === #if USE_GDB_STUB void initGdbSerial(void) @@ -358,11 +372,11 @@ void *memset(void *__dest, int __val, size_t __count) __asm__ __volatile__ ("rep stosb" : : "D"(__dest),"a"(__val),"c"(__count)); else { Uint8 *dst = __dest; + size_t qwords = __count / 8; + size_t trail_bytes = __count % 8; - __asm__ __volatile__ ("rep stosq" : : "D"(dst),"a"(0),"c"(__count/8)); - dst += __count & ~7; - __count = __count & 7; - while( __count-- ) + __asm__ __volatile__ ("rep stosq" : "=D"(dst) : "D"(dst),"a"(0),"c"(qwords)); + while( trail_bytes-- ) *dst++ = 0; } return __dest;