195-6
[darwin-xtools.git] / dyld / src / threadLocalHelpers.s
blobb5bc9d56d699b2ead0a6a1a80d57bfdb10683486
1 /*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 #if __x86_64__
27 // returns address of TLV in %rax, all other registers preserved
28 .globl _tlv_get_addr
29 .private_extern _tlv_get_addr
30 _tlv_get_addr:
31 movq 8(%rdi),%rax // get key from descriptor
32 movq %gs:0x0(,%rax,8),%rax // get thread value
33 testq %rax,%rax // if NULL, lazily allocate
34 je LlazyAllocate
35 addq 16(%rdi),%rax // add offset from descriptor
36 ret
37 LlazyAllocate:
38 pushq %rbp
39 movq %rsp, %rbp
40 subq $592,%rsp
41 movq %rdi,-8(%rbp)
42 movq %rsi,-16(%rbp)
43 movq %rdx,-24(%rbp)
44 movq %rcx,-32(%rbp)
45 movq %r8,-40(%rbp)
46 movq %r9,-48(%rbp)
47 movq %r10,-56(%rbp)
48 movq %r11,-64(%rbp)
49 fxsave -592(%rbp)
50 movq 8(%rdi),%rdi // get key from descriptor
51 call _tlv_allocate_and_initialize_for_key
52 fxrstor -592(%rbp)
53 movq -64(%rbp),%r11
54 movq -56(%rbp),%r10
55 movq -48(%rbp),%r9
56 movq -40(%rbp),%r8
57 movq -32(%rbp),%rcx
58 movq -24(%rbp),%rdx
59 movq -16(%rbp),%rsi
60 movq -8(%rbp),%rdi
61 addq 16(%rdi),%rax // result = buffer + offset
62 addq $592,%rsp
63 popq %rbp
64 ret
65 #endif
69 #if __i386__
70 // returns address of TLV in %eax, all other registers (except %ecx) preserved
71 .globl _tlv_get_addr
72 .private_extern _tlv_get_addr
73 _tlv_get_addr:
74 movl 4(%eax),%ecx // get key from descriptor
75 movl %gs:0x0(,%ecx,4),%ecx // get thread value
76 testl %ecx,%ecx // if NULL, lazily allocate
77 je LlazyAllocate
78 movl 8(%eax),%eax // add offset from descriptor
79 addl %ecx,%eax
80 ret
81 LlazyAllocate:
82 pushl %ebp
83 movl %esp,%ebp
84 pushl %edx // save edx
85 subl $548,%esp
86 movl %eax,-8(%ebp) // save descriptor
87 lea -528(%ebp),%ecx // get 512 byte buffer in frame
88 and $-16, %ecx // 16-byte align buffer for fxsave
89 fxsave (%ecx)
90 movl 4(%eax),%ecx // get key from descriptor
91 movl %ecx,(%esp) // push key parameter, also leaves stack aligned properly
92 call _tlv_allocate_and_initialize_for_key
93 movl -8(%ebp),%ecx // get descriptor
94 movl 8(%ecx),%ecx // get offset from descriptor
95 addl %ecx,%eax // add offset to buffer
96 lea -528(%ebp),%ecx
97 and $-16, %ecx // 16-byte align buffer for fxrstor
98 fxrstor (%ecx)
99 addl $548,%esp
100 popl %edx // restore edx
101 popl %ebp
103 #endif
106 #if 0
107 #if __arm__
108 // returns address of TLV in r0, all other registers preserved
109 .globl _tlv_get_addr
110 .private_extern _tlv_get_addr
111 _tlv_get_addr:
112 push {r1,r2,r3,r7,lr}
113 mov r7,r0 // save descriptor in r7
114 ldr r0, [r7, #4] // get key from descriptor
115 bl _pthread_getspecific // get thread value
116 cmp r0, #0
117 bne L2 // if NULL, lazily allocate
118 ldr r0, [r7, #4] // get key from descriptor
119 bl _tlv_allocate_and_initialize_for_key
120 L2: ldr r1, [r7, #8] // get offset from descriptor
121 add r0, r1, r0 // add offset into allocation block
122 pop {r1,r2,r3,r7,pc}
123 #endif
124 #endif