OSDN Git Service

ed6915387425e552eaee8c7034c061c89b2be656
[uclinux-h8/uClibc.git] / libpthread / linuxthreads.old / sysdeps / x86_64 / pt-machine.h
1 /* Machine-dependent pthreads configuration and inline functions.
2    x86-64 version.
3    Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 #ifndef _PT_MACHINE_H
21 #define _PT_MACHINE_H   1
22
23 #include <features.h>
24
25 #ifndef __ASSEMBLER__
26 # include <stddef.h>    /* For offsetof.  */
27 # include <stdlib.h>    /* For abort().  */
28 # include <asm/prctl.h>
29
30
31 # ifndef PT_EI
32 #  define PT_EI __extern_always_inline
33 # endif
34
35 /* Get some notion of the current stack.  Need not be exactly the top
36    of the stack, just something somewhere in the current frame.  */
37 # define CURRENT_STACK_FRAME  stack_pointer
38 register char * stack_pointer __asm__ ("%rsp") __attribute_used__;
39
40
41 /* Spinlock implementation; required.  */
42 PT_EI long int
43 testandset (int *__spinlock)
44 {
45   long int ret;
46
47   __asm__ __volatile__ (
48         "xchgl %k0, %1"
49         : "=r"(ret), "=m"(*__spinlock)
50         : "0"(1), "m"(*__spinlock)
51         : "memory");
52
53   return ret;
54 }
55
56
57 /* Compare-and-swap for semaphores.  */
58 # define HAS_COMPARE_AND_SWAP
59
60 PT_EI int
61 __compare_and_swap (long int *__p, long int __oldval, long int __newval)
62 {
63   char ret;
64   long int readval;
65
66   __asm__ __volatile__ ("lock; cmpxchgq %3, %1; sete %0"
67                         : "=q" (ret), "=m" (*__p), "=a" (readval)
68                         : "r" (__newval), "m" (*__p), "a" (__oldval)
69                         : "memory");
70   return ret;
71 }
72
73 #endif /* !__ASSEMBLER__ */
74
75 /* We want the OS to assign stack addresses.  */
76 #define FLOATING_STACKS 1
77
78 /* Maximum size of the stack if the rlimit is unlimited.  */
79 #define ARCH_STACK_MAX_SIZE     32*1024*1024
80
81 /* The ia32e really want some help to prevent overheating.  */
82 #define BUSY_WAIT_NOP   __asm__ ("rep; nop")
83
84 #endif /* pt-machine.h */