2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 #include <sys/appleapiopts.h>
32 #include <ppc/asm.h> // EXT, LEXT
33 #include <machine/cpu_capabilities.h>
34 #include <machine/commpage.h>
39 #define USER_SPRG3 259 // user-mode-readable encoding for SPRG3
42 // ***********************************************************
43 // * P T H R E A D _ G E T S P E C I F I C _ S P R G 3 _ 3 2 *
44 // ***********************************************************
46 // For processors with user-readable SPRG3, in 32-bit mode. Called with:
48 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
50 pthread_getspecific_sprg3_32:
51 slwi r5,r3,2 // convert word# to byte offset
52 mfspr r3,USER_SPRG3 // get per-thread cookie
53 add r5,r5,r4 // add in offset to first word
54 lwzx r3,r3,r5 // get the thread-specific word
57 COMMPAGE_DESCRIPTOR(pthread_getspecific_sprg3_32,_COMM_PAGE_PTHREAD_GETSPECIFIC,k64Bit,0,kCommPage32)
60 // ***********************************************************
61 // * P T H R E A D _ G E T S P E C I F I C _ S P R G 3 _ 6 4 *
62 // ***********************************************************
64 // For processors with user-readable SPRG3, in 64-bit mode. This may not be used
65 // because the 64-bit ABI uses r13 for the thread-local-data pointer. Called with:
67 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
69 pthread_getspecific_sprg3_64:
70 sldi r5,r3,3 // convert double-word# to byte offset
71 mfspr r3,USER_SPRG3 // get per-thread cookie
72 add r5,r5,r4 // add in offset to first word
73 ldx r3,r3,r5 // get the thread-specific doubleword
76 COMMPAGE_DESCRIPTOR(pthread_getspecific_sprg3_64,_COMM_PAGE_PTHREAD_GETSPECIFIC,k64Bit,0,kCommPage64)
79 // ***************************************
80 // * P T H R E A D _ S E L F _ S P R G 3 *
81 // ***************************************
83 // For processors with user-readable SPRG3. Useable both in 32 and 64-bit modes.
86 mfspr r3,USER_SPRG3 // get per-thread cookie
89 COMMPAGE_DESCRIPTOR(pthread_self_sprg3,_COMM_PAGE_PTHREAD_SELF,k64Bit,0,kCommPageBoth)
92 // *******************************************************
93 // * P T H R E A D _ G E T S P E C I F I C _ U F T R A P *
94 // *******************************************************
96 // For processors that use the Ultra-Fast-Trap to get the thread-specific ptr.
99 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
101 pthread_getspecific_uftrap:
102 slwi r5,r3,2 // convert word# to byte offset
103 li r0,0x7FF2 // magic "pthread_self" ultra-fast trap code
105 add r5,r5,r4 // add in offset to first word
106 lwzx r3,r3,r5 // get the thread-specific word
109 COMMPAGE_DESCRIPTOR(pthread_getspecific_uftrap,_COMM_PAGE_PTHREAD_GETSPECIFIC,0,k64Bit,kCommPage32)
112 // *****************************************
113 // * P T H R E A D _ S E L F _ U F T R A P *
114 // *****************************************
116 // For processors that use the Ultra-Fast-Trap to get the thread-specific ptr.
119 li r0,0x7FF2 // magic "pthread_self" ultra-fast trap code
123 COMMPAGE_DESCRIPTOR(pthread_self_uftrap,_COMM_PAGE_PTHREAD_SELF,0,k64Bit,kCommPage32)