2538ef79cca0446328b2718e12fa7b9c1aeb24a1
[sbcl.git] / src / runtime / x86-64-arch.h
1 /* FIXME: Aren't preprocessor symbols with underscore prefixes
2  * reserved for the system libraries? If so, it would be tidy to
3  * rename flags like _X86_ARCH_H so their names are in a part of the
4  * namespace that we control. */
5 #ifndef _X86_64_ARCH_H
6 #define _X86_64_ARCH_H
7
8 #ifndef SBCL_GENESIS_CONFIG
9 #error genesis/config.h (or sbcl.h) must be included before this file
10 #endif
11
12 #include "interr.h"                     /* for declaration of lose() */
13
14 #define ARCH_HAS_STACK_POINTER
15
16 /* FIXME: Do we also want
17  *   #define ARCH_HAS_FLOAT_REGISTERS
18  * here? (The answer wasn't obvious to me when merging the
19  * architecture-abstracting patches for CSR's SPARC port. -- WHN 2002-02-15) */
20
21 #include "interr.h"
22
23 static inline void
24 get_spinlock(volatile lispobj *word,long value)
25 {
26 #ifdef LISP_FEATURE_SB_THREAD
27     u64 rax=0;
28     if(*word==value)
29         lose("recursive get_spinlock: 0x%x,%ld\n",word,value);
30     do {
31 #if defined(LISP_FEATURE_DARWIN)
32         asm volatile
33             ("xor %0,%0\n\
34               lock/cmpxchg %1,%2"
35              : "=a" (rax)
36              : "r" (value), "m" (*word)
37              : "memory", "cc");
38 #else
39         asm volatile
40             ("xor %0,%0\n\
41               lock cmpxchg %1,%2"
42              : "=a" (rax)
43              : "r" (value), "m" (*word)
44              : "memory", "cc");
45 #endif
46     } while(rax!=0);
47 #else
48     *word=value;
49 #endif
50 }
51
52 static inline lispobj
53 swap_lispobjs(volatile lispobj *dest, lispobj value)
54 {
55     lispobj old_value;
56     asm volatile
57         ("lock xchg %0,(%1)"
58          : "=r" (old_value)
59          : "r" (dest), "0" (value)
60          : "memory");
61     return old_value;
62 }
63
64 static inline void
65 release_spinlock(volatile lispobj *word)
66 {
67     /* A memory barrier is needed, use swap_lispobjs. See comment in
68      * RELEASE-SPINLOCK in target-thread.lisp. */
69     swap_lispobjs(word,0);
70 }
71
72 #endif /* _X86_64_ARCH_H */