]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/commpage/pthread.s
87ae3d1da5eb238010e9a778a53f70a67b78d922
[apple/xnu.git] / osfmk / ppc / commpage / pthread.s
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 #include <sys/appleapiopts.h>
32 #include <ppc/asm.h> // EXT, LEXT
33 #include <machine/cpu_capabilities.h>
34 #include <machine/commpage.h>
35
36 .text
37 .align 2
38
39 #define USER_SPRG3 259 // user-mode-readable encoding for SPRG3
40
41
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 // ***********************************************************
45 //
46 // For processors with user-readable SPRG3, in 32-bit mode. Called with:
47 // r3 = word number
48 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
49
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
55 blr
56
57 COMMPAGE_DESCRIPTOR(pthread_getspecific_sprg3_32,_COMM_PAGE_PTHREAD_GETSPECIFIC,k64Bit,0,kCommPage32)
58
59
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 // ***********************************************************
63 //
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:
66 // r3 = word number
67 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
68
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
74 blr
75
76 COMMPAGE_DESCRIPTOR(pthread_getspecific_sprg3_64,_COMM_PAGE_PTHREAD_GETSPECIFIC,k64Bit,0,kCommPage64)
77
78
79 // ***************************************
80 // * P T H R E A D _ S E L F _ S P R G 3 *
81 // ***************************************
82 //
83 // For processors with user-readable SPRG3. Useable both in 32 and 64-bit modes.
84
85 pthread_self_sprg3:
86 mfspr r3,USER_SPRG3 // get per-thread cookie
87 blr
88
89 COMMPAGE_DESCRIPTOR(pthread_self_sprg3,_COMM_PAGE_PTHREAD_SELF,k64Bit,0,kCommPageBoth)
90
91
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 // *******************************************************
95 //
96 // For processors that use the Ultra-Fast-Trap to get the thread-specific ptr.
97 // Called with:
98 // r3 = word number
99 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
100
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
104 sc
105 add r5,r5,r4 // add in offset to first word
106 lwzx r3,r3,r5 // get the thread-specific word
107 blr
108
109 COMMPAGE_DESCRIPTOR(pthread_getspecific_uftrap,_COMM_PAGE_PTHREAD_GETSPECIFIC,0,k64Bit,kCommPage32)
110
111
112 // *****************************************
113 // * P T H R E A D _ S E L F _ U F T R A P *
114 // *****************************************
115 //
116 // For processors that use the Ultra-Fast-Trap to get the thread-specific ptr.
117
118 pthread_self_uftrap:
119 li r0,0x7FF2 // magic "pthread_self" ultra-fast trap code
120 sc // get r3==TLDP
121 blr
122
123 COMMPAGE_DESCRIPTOR(pthread_self_uftrap,_COMM_PAGE_PTHREAD_SELF,0,k64Bit,kCommPage32)