clarify the purpose of this project
[nyanglibc.git] / csu / libc-tls.s
blob3f4cff3555dbb1da6209b4341a723d142c4b2124
1 .text
2 .section .rodata.str1.8,"aMS",@progbits,1
3 .align 8
4 .LC0:
5 .string "cannot set %fs base address for thread-local storage"
6 .text
7 .p2align 4,,15
8 .globl __libc_setup_tls
9 .type __libc_setup_tls, @function
10 __libc_setup_tls:
11 pushq %r15
12 pushq %r14
13 pushq %r13
14 pushq %r12
15 pushq %rbp
16 pushq %rbx
17 subq $40, %rsp
18 movq _dl_phdr(%rip), %rax
19 movq _dl_ns(%rip), %r13
20 testq %rax, %rax
21 je .L11
22 movq _dl_phnum(%rip), %rcx
23 leaq 0(,%rcx,8), %rdx
24 subq %rcx, %rdx
25 leaq (%rax,%rdx,8), %rdx
26 cmpq %rdx, %rax
27 jb .L6
28 jmp .L11
29 .p2align 4,,10
30 .p2align 3
31 .L4:
32 addq $56, %rax
33 cmpq %rax, %rdx
34 jbe .L11
35 .L6:
36 cmpl $7, (%rax)
37 jne .L4
38 movq 16(%rax), %r12
39 addq 0(%r13), %r12
40 movq 32(%rax), %rbx
41 movq 40(%rax), %rbp
42 movq %r12, 16(%rsp)
43 movq 48(%rax), %r12
44 movq %rbx, 8(%rsp)
45 cmpq $64, %r12
46 jbe .L2
47 xorl %edi, %edi
48 movq %r12, %r15
49 movq %r12, %r14
50 call _dl_tls_static_surplus_init
51 movq _dl_tls_static_surplus(%rip), %rax
52 xorl %edx, %edx
53 negq %r15
54 leaq -1(%r12), %rsi
55 leaq -1(%rbp,%rax), %rax
56 addq %r12, %rax
57 divq %r12
58 imulq %r12, %rax
59 movq %rax, %rbx
60 jmp .L9
61 .p2align 4,,10
62 .p2align 3
63 .L11:
64 xorl %r12d, %r12d
65 movq $0, 16(%rsp)
66 movq $0, 8(%rsp)
67 xorl %ebp, %ebp
68 .L2:
69 xorl %edi, %edi
70 movq $-64, %r15
71 movl $64, %r14d
72 call _dl_tls_static_surplus_init
73 movq _dl_tls_static_surplus(%rip), %rax
74 leaq 63(%rbp,%rax), %rsi
75 movq %rsi, %rbx
76 movl $63, %esi
77 andq $-64, %rbx
78 .L9:
79 leaq 2496(%rbx,%r14), %rdi
80 movq %rsi, 24(%rsp)
81 call __sbrk
82 movq 24(%rsp), %rsi
83 movq $62, _dl_static_dtv(%rip)
84 addq %rax, %rsi
85 movq %rsi, %rcx
86 andq %r15, %rcx
87 testq %r12, %r12
88 je .L12
89 leaq -1(%rbp,%r12), %rax
90 movq %r12, %r15
91 .L7:
92 xorl %edx, %edx
93 movq 16(%rsp), %rsi
94 movq %rbx, %rdi
95 divq %r15
96 movq 8(%rsp), %rdx
97 movq %rcx, 24(%rsp)
98 movq $0, 40+_dl_static_dtv(%rip)
99 imulq %rax, %r15
100 subq %r15, %rdi
101 movq %r15, 1112(%r13)
102 addq %rcx, %rdi
103 movq %rdi, 32+_dl_static_dtv(%rip)
104 call memcpy@PLT
105 movq 24(%rsp), %rcx
106 leaq 16+_dl_static_dtv(%rip), %rax
107 movl $4098, %edi
108 leaq (%rcx,%rbx), %rsi
109 movq %rax, 8(%rsi)
110 movq %rsi, (%rsi)
111 movl $158, %eax
112 movq %rsi, 16(%rsi)
113 #APP
114 # 187 "libc-tls.c" 1
115 syscall
116 # 0 "" 2
117 #NO_APP
118 testl %eax, %eax
119 je .L8
120 leaq .LC0(%rip), %rdi
121 call __libc_fatal
122 .p2align 4,,10
123 .p2align 3
124 .L8:
125 leaq _dl_stack_user(%rip), %rdx
126 leaq _dl_stack_used(%rip), %rax
127 movq %rdx, _dl_stack_user(%rip)
128 movq %rax, 8+_dl_stack_used(%rip)
129 movq %rax, _dl_stack_used(%rip)
130 movq %fs:16, %rax
131 leaq 704(%rax), %rcx
132 movq %rdx, 704(%rax)
133 movq %rdx, 712(%rax)
134 movq %rcx, 8+_dl_stack_user(%rip)
135 movq 16(%rsp), %rax
136 movq %r12, 1096(%r13)
137 movq %rbp, 1088(%r13)
138 movq $1, 1120(%r13)
139 movq %r13, 40+static_slotinfo(%rip)
140 movq %r15, _dl_tls_static_used(%rip)
141 movq %rax, 1072(%r13)
142 movq 8(%rsp), %rax
143 movq %r14, _dl_tls_static_align(%rip)
144 movq %rcx, _dl_stack_user(%rip)
145 movq $64, static_slotinfo(%rip)
146 movq $1, _dl_tls_max_dtv_idx(%rip)
147 movq %rax, 1080(%r13)
148 leaq static_slotinfo(%rip), %rax
149 movq $1, _dl_tls_static_nelem(%rip)
150 movq %rax, _dl_tls_dtv_slotinfo_list(%rip)
151 movq _dl_tls_static_surplus(%rip), %rax
152 leaq 63(%r15,%rax), %rax
153 andq $-64, %rax
154 addq $2496, %rax
155 movq %rax, _dl_tls_static_size(%rip)
156 addq $40, %rsp
157 popq %rbx
158 popq %rbp
159 popq %r12
160 popq %r13
161 popq %r14
162 popq %r15
164 .p2align 4,,10
165 .p2align 3
166 .L12:
167 movq %rbp, %rax
168 movl $1, %r15d
169 jmp .L7
170 .size __libc_setup_tls, .-__libc_setup_tls
171 .comm _dl_tls_generation,8,8
172 .comm _dl_tls_static_optional,8,8
173 .comm _dl_tls_static_surplus,8,8
174 .comm _dl_tls_static_align,8,8
175 .comm _dl_tls_static_used,8,8
176 .comm _dl_tls_static_size,8,8
177 .comm _dl_tls_static_nelem,8,8
178 .comm _dl_tls_dtv_slotinfo_list,8,8
179 .comm _dl_tls_dtv_gaps,1,1
180 .comm _dl_tls_max_dtv_idx,8,8
181 .local static_slotinfo
182 .comm static_slotinfo,1040,16
183 .comm _dl_static_dtv,1024,32
184 .hidden __libc_fatal
185 .hidden __sbrk
186 .hidden _dl_tls_static_surplus_init