]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/commpage/pthread.s
24c785121e80498d412797233b15d82076f92167
[apple/xnu.git] / osfmk / ppc / commpage / pthread.s
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <sys/appleapiopts.h>
24 #include <ppc/asm.h> // EXT, LEXT
25 #include <machine/cpu_capabilities.h>
26 #include <machine/commpage.h>
27
28 .text
29 .align 2
30
31 #define USER_SPRG3 259 // user-mode-readable encoding for SPRG3
32
33
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 // ***********************************************************
37 //
38 // For processors with user-readable SPRG3, in 32-bit mode. Called with:
39 // r3 = word number
40 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
41
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
47 blr
48
49 COMMPAGE_DESCRIPTOR(pthread_getspecific_sprg3_32,_COMM_PAGE_PTHREAD_GETSPECIFIC,k64Bit,0,kCommPage32)
50
51
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 // ***********************************************************
55 //
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:
58 // r3 = word number
59 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
60
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
66 blr
67
68 COMMPAGE_DESCRIPTOR(pthread_getspecific_sprg3_64,_COMM_PAGE_PTHREAD_GETSPECIFIC,k64Bit,0,kCommPage64)
69
70
71 // ***************************************
72 // * P T H R E A D _ S E L F _ S P R G 3 *
73 // ***************************************
74 //
75 // For processors with user-readable SPRG3. Useable both in 32 and 64-bit modes.
76
77 pthread_self_sprg3:
78 mfspr r3,USER_SPRG3 // get per-thread cookie
79 blr
80
81 COMMPAGE_DESCRIPTOR(pthread_self_sprg3,_COMM_PAGE_PTHREAD_SELF,k64Bit,0,kCommPageBoth)
82
83
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 // *******************************************************
87 //
88 // For processors that use the Ultra-Fast-Trap to get the thread-specific ptr.
89 // Called with:
90 // r3 = word number
91 // r4 = offset to thread specific data (_PTHREAD_TSD_OFFSET)
92
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
96 sc
97 add r5,r5,r4 // add in offset to first word
98 lwzx r3,r3,r5 // get the thread-specific word
99 blr
100
101 COMMPAGE_DESCRIPTOR(pthread_getspecific_uftrap,_COMM_PAGE_PTHREAD_GETSPECIFIC,0,k64Bit,kCommPage32)
102
103
104 // *****************************************
105 // * P T H R E A D _ S E L F _ U F T R A P *
106 // *****************************************
107 //
108 // For processors that use the Ultra-Fast-Trap to get the thread-specific ptr.
109
110 pthread_self_uftrap:
111 li r0,0x7FF2 // magic "pthread_self" ultra-fast trap code
112 sc // get r3==TLDP
113 blr
114
115 COMMPAGE_DESCRIPTOR(pthread_self_uftrap,_COMM_PAGE_PTHREAD_SELF,0,k64Bit,kCommPage32)