2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <sys/appleapiopts.h>
24 #include <ppc/asm.h> // EXT, LEXT
25 #include <machine/cpu_capabilities.h>
26 #include <machine/commpage.h>
31 #define USER_SPRG3 259 // user-mode-readable encoding for SPRG3
34 // ***********************************************************
35 // * 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 *
36 // ***********************************************************
38 // For processors with user-readable SPRG3, in 32-bit mode. Called with:
40 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
42 pthread_getspecific_sprg3_32:
43 slwi r5,r3,2 // convert word# to byte offset
44 mfspr r3,USER_SPRG3 // get per-thread cookie
45 add r5,r5,r4 // add in offset to first word
46 lwzx r3,r3,r5 // get the thread-specific word
49 COMMPAGE_DESCRIPTOR(pthread_getspecific_sprg3_32,_COMM_PAGE_PTHREAD_GETSPECIFIC,k64Bit,0,kCommPage32)
52 // ***********************************************************
53 // * 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 *
54 // ***********************************************************
56 // For processors with user-readable SPRG3, in 64-bit mode. This may not be used
57 // because the 64-bit ABI uses r13 for the thread-local-data pointer. Called with:
59 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
61 pthread_getspecific_sprg3_64:
62 sldi r5,r3,3 // convert double-word# to byte offset
63 mfspr r3,USER_SPRG3 // get per-thread cookie
64 add r5,r5,r4 // add in offset to first word
65 ldx r3,r3,r5 // get the thread-specific doubleword
68 COMMPAGE_DESCRIPTOR(pthread_getspecific_sprg3_64,_COMM_PAGE_PTHREAD_GETSPECIFIC,k64Bit,0,kCommPage64)
71 // ***************************************
72 // * P T H R E A D _ S E L F _ S P R G 3 *
73 // ***************************************
75 // For processors with user-readable SPRG3. Useable both in 32 and 64-bit modes.
78 mfspr r3,USER_SPRG3 // get per-thread cookie
81 COMMPAGE_DESCRIPTOR(pthread_self_sprg3,_COMM_PAGE_PTHREAD_SELF,k64Bit,0,kCommPageBoth)
84 // *******************************************************
85 // * P T H R E A D _ G E T S P E C I F I C _ U F T R A P *
86 // *******************************************************
88 // For processors that use the Ultra-Fast-Trap to get the thread-specific ptr.
91 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
93 pthread_getspecific_uftrap:
94 slwi r5,r3,2 // convert word# to byte offset
95 li r0,0x7FF2 // magic "pthread_self" ultra-fast trap code
97 add r5,r5,r4 // add in offset to first word
98 lwzx r3,r3,r5 // get the thread-specific word
101 COMMPAGE_DESCRIPTOR(pthread_getspecific_uftrap,_COMM_PAGE_PTHREAD_GETSPECIFIC,0,k64Bit,kCommPage32)
104 // *****************************************
105 // * P T H R E A D _ S E L F _ U F T R A P *
106 // *****************************************
108 // For processors that use the Ultra-Fast-Trap to get the thread-specific ptr.
111 li r0,0x7FF2 // magic "pthread_self" ultra-fast trap code
115 COMMPAGE_DESCRIPTOR(pthread_self_uftrap,_COMM_PAGE_PTHREAD_SELF,0,k64Bit,kCommPage32)