yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /* Machine-dependent pthreads configuration and inline functions. |
| 2 | Alpha version. |
| 3 | Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003 |
| 4 | Free Software Foundation, Inc. |
| 5 | This file is part of the GNU C Library. |
| 6 | Contributed by Richard Henderson <rth@tamu.edu>. |
| 7 | |
| 8 | The GNU C Library is free software; you can redistribute it and/or |
| 9 | modify it under the terms of the GNU Lesser General Public License as |
| 10 | published by the Free Software Foundation; either version 2.1 of the |
| 11 | License, or (at your option) any later version. |
| 12 | |
| 13 | The GNU C Library is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | Lesser General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU Lesser General Public |
| 19 | License along with the GNU C Library; see the file COPYING.LIB. If not, |
| 20 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 21 | Boston, MA 02111-1307, USA. */ |
| 22 | |
| 23 | #ifndef _PT_MACHINE_H |
| 24 | #define _PT_MACHINE_H 1 |
| 25 | |
| 26 | #include <features.h> |
| 27 | |
| 28 | #ifndef PT_EI |
| 29 | # define PT_EI __extern_always_inline |
| 30 | #endif |
| 31 | |
| 32 | #ifdef __linux__ |
| 33 | # include <asm/pal.h> |
| 34 | #else |
| 35 | # include <machine/pal.h> |
| 36 | #endif |
| 37 | |
| 38 | /* Get some notion of the current stack. Need not be exactly the top |
| 39 | of the stack, just something somewhere in the current frame. */ |
| 40 | #define CURRENT_STACK_FRAME stack_pointer |
| 41 | register char *stack_pointer __asm__("$30"); |
| 42 | |
| 43 | |
| 44 | /* Memory barrier; default is to do nothing */ |
| 45 | #define MEMORY_BARRIER() __asm__ __volatile__("mb" : : : "memory") |
| 46 | /* Write barrier. */ |
| 47 | #define WRITE_MEMORY_BARRIER() __asm__ __volatile__("wmb" : : : "memory") |
| 48 | |
| 49 | |
| 50 | /* Spinlock implementation; required. */ |
| 51 | PT_EI long int |
| 52 | testandset (int *spinlock) |
| 53 | { |
| 54 | long int ret, temp; |
| 55 | |
| 56 | __asm__ __volatile__( |
| 57 | "/* Inline spinlock test & set */\n" |
| 58 | "1:\t" |
| 59 | "ldl_l %0,%3\n\t" |
| 60 | "bne %0,2f\n\t" |
| 61 | "or $31,1,%1\n\t" |
| 62 | "stl_c %1,%2\n\t" |
| 63 | "beq %1,1b\n" |
| 64 | "2:\tmb\n" |
| 65 | "/* End spinlock test & set */" |
| 66 | : "=&r"(ret), "=&r"(temp), "=m"(*spinlock) |
| 67 | : "m"(*spinlock) |
| 68 | : "memory"); |
| 69 | |
| 70 | return ret; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /* Begin allocating thread stacks at this address. Default is to allocate |
| 75 | them just below the initial program stack. */ |
| 76 | #define THREAD_STACK_START_ADDRESS 0x40000000000 |
| 77 | |
| 78 | |
| 79 | /* Return the thread descriptor for the current thread. */ |
| 80 | #define THREAD_SELF \ |
| 81 | ({ \ |
| 82 | register pthread_descr __self __asm__("$0"); \ |
| 83 | __asm__ ("call_pal %1" : "=r"(__self) : "i"(PAL_rduniq)); \ |
| 84 | __self; \ |
| 85 | }) |
| 86 | |
| 87 | /* Initialize the thread-unique value. */ |
| 88 | #define INIT_THREAD_SELF(descr, nr) \ |
| 89 | { \ |
| 90 | register pthread_descr __self __asm__("$16") = (descr); \ |
| 91 | __asm__ __volatile__ ("call_pal %1" : : "r"(__self), "i"(PAL_wruniq)); \ |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /* Compare-and-swap for semaphores. */ |
| 96 | |
| 97 | #define HAS_COMPARE_AND_SWAP |
| 98 | PT_EI int |
| 99 | __compare_and_swap (long int *p, long int oldval, long int newval) |
| 100 | { |
| 101 | long int ret; |
| 102 | |
| 103 | __asm__ __volatile__ ( |
| 104 | "/* Inline compare & swap */\n" |
| 105 | "1:\t" |
| 106 | "ldq_l %0,%4\n\t" |
| 107 | "cmpeq %0,%2,%0\n\t" |
| 108 | "beq %0,2f\n\t" |
| 109 | "mov %3,%0\n\t" |
| 110 | "stq_c %0,%1\n\t" |
| 111 | "beq %0,1b\n\t" |
| 112 | "2:\tmb\n" |
| 113 | "/* End compare & swap */" |
| 114 | : "=&r"(ret), "=m"(*p) |
| 115 | : "r"(oldval), "r"(newval), "m"(*p) |
| 116 | : "memory"); |
| 117 | |
| 118 | return ret; |
| 119 | } |
| 120 | |
| 121 | /* We want the OS to assign stack addresses. */ |
| 122 | #define FLOATING_STACKS 1 |
| 123 | |
| 124 | /* Maximum size of the stack if the rlimit is unlimited. */ |
| 125 | #define ARCH_STACK_MAX_SIZE 32*1024*1024 |
| 126 | |
| 127 | #endif /* pt-machine.h */ |