clarify the purpose of this project
[nyanglibc.git] / io / ttyname.shared.s
blob7dbf13f61549e254095e1de8cf59dcdc94891570
1 .text
2 #APP
3 memmove = __GI_memmove
4 memset = __GI_memset
5 memcpy = __GI_memcpy
6 .section __libc_freeres_ptrs, "aw", %nobits
7 .previous
8 .section __libc_freeres_ptrs, "aw", %nobits
9 .previous
10 .section .rodata.str1.1,"aMS",@progbits,1
11 .LC0:
12 .string "stdin"
13 .LC1:
14 .string "stdout"
15 .LC2:
16 .string "stderr"
17 #NO_APP
18 .section .text.compat,"ax",@progbits
19 .p2align 4,,15
20 .type getttyname, @function
21 getttyname:
22 pushq %r15
23 pushq %r14
24 pushq %r13
25 pushq %r12
26 movq %rcx, %r13
27 pushq %rbp
28 pushq %rbx
29 movq %rdi, %rbx
30 movq %rsi, %rbp
31 subq $200, %rsp
32 movq %rdi, 16(%rsp)
33 movl %edx, 36(%rsp)
34 call __GI_strlen
35 movq %rbx, %rdi
36 movq %rax, 24(%rsp)
37 leaq 1(%rax), %r15
38 call __opendir
39 testq %rax, %rax
40 je .L23
41 cmpq %r15, namelen.8896(%rip)
42 movq %rax, %rbx
43 ja .L24
44 .L4:
45 leaq 48(%rsp), %rax
46 leaq .LC0(%rip), %r12
47 movq %rax, 8(%rsp)
48 .p2align 4,,10
49 .p2align 3
50 .L5:
51 movq %rbx, %rdi
52 call __GI___readdir64
53 testq %rax, %rax
54 je .L25
55 movq 8(%rbp), %rdx
56 cmpq %rdx, (%rax)
57 je .L6
58 movl 0(%r13), %edx
59 testl %edx, %edx
60 je .L5
61 .L6:
62 leaq 19(%rax), %r14
63 movl $6, %ecx
64 movq %r12, %rdi
65 movq %r14, %rsi
66 repz cmpsb
67 je .L5
68 leaq .LC1(%rip), %rdi
69 movl $7, %ecx
70 movq %r14, %rsi
71 repz cmpsb
72 je .L5
73 leaq .LC2(%rip), %rdi
74 movl $7, %ecx
75 movq %r14, %rsi
76 repz cmpsb
77 je .L5
78 movzwl 16(%rax), %ecx
79 movq getttyname_name(%rip), %r8
80 addq %rax, %rcx
81 subq %r14, %rcx
82 leaq (%r15,%rcx), %rax
83 cmpq namelen.8896(%rip), %rax
84 movq %rax, (%rsp)
85 jbe .L8
86 movq %r8, %rdi
87 movq %rcx, 40(%rsp)
88 call free@PLT
89 movq (%rsp), %rax
90 leaq (%rax,%rax), %rdi
91 movq %rdi, namelen.8896(%rip)
92 call malloc@PLT
93 testq %rax, %rax
94 movq %rax, getttyname_name(%rip)
95 movq 40(%rsp), %rcx
96 je .L26
97 movq 24(%rsp), %rdx
98 movq 16(%rsp), %rsi
99 movq %rax, %rdi
100 movq %rcx, 40(%rsp)
101 movq %rax, (%rsp)
102 call __GI_mempcpy@PLT
103 movq 40(%rsp), %rcx
104 movq (%rsp), %r8
105 movb $47, (%rax)
106 .L8:
107 leaq (%r8,%r15), %rdi
108 movq %rcx, %rdx
109 movq %r14, %rsi
110 movq %r8, (%rsp)
111 call __GI_memcpy@PLT
112 movq (%rsp), %r8
113 movq 8(%rsp), %rsi
114 movq %r8, %rdi
115 call __GI___stat64
116 testl %eax, %eax
117 jne .L5
118 movq 8(%rbp), %rax
119 cmpq %rax, 56(%rsp)
120 jne .L5
121 movq 0(%rbp), %rax
122 cmpq %rax, 48(%rsp)
123 jne .L5
124 movl 72(%rsp), %eax
125 andl $61440, %eax
126 cmpl $8192, %eax
127 jne .L5
128 movq 40(%rbp), %rax
129 cmpq %rax, 88(%rsp)
130 jne .L5
131 movq %rbx, %rdi
132 call __closedir
133 movq __libc_errno@gottpoff(%rip), %rax
134 movl 36(%rsp), %ebx
135 movq getttyname_name(%rip), %r14
136 movl %ebx, %fs:(%rax)
137 jmp .L1
138 .p2align 4,,10
139 .p2align 3
140 .L25:
141 movq %rbx, %rdi
142 xorl %r14d, %r14d
143 call __closedir
144 movq __libc_errno@gottpoff(%rip), %rax
145 movl 36(%rsp), %ebx
146 movl %ebx, %fs:(%rax)
147 .L1:
148 addq $200, %rsp
149 movq %r14, %rax
150 popq %rbx
151 popq %rbp
152 popq %r12
153 popq %r13
154 popq %r14
155 popq %r15
157 .p2align 4,,10
158 .p2align 3
159 .L24:
160 movq 24(%rsp), %rdx
161 movq 16(%rsp), %rsi
162 movq getttyname_name(%rip), %rdi
163 call __GI_mempcpy@PLT
164 movb $47, (%rax)
165 jmp .L4
166 .L23:
167 movl $-1, 0(%r13)
168 xorl %r14d, %r14d
169 jmp .L1
170 .L26:
171 movl $-1, 0(%r13)
172 movq %rbx, %rdi
173 movq %rax, %r14
174 call __closedir
175 jmp .L1
176 .size getttyname, .-getttyname
177 .section .rodata.str1.1
178 .LC3:
179 .string "(unreachable)"
180 .LC4:
181 .string "/dev/pts"
182 .LC5:
183 .string "/dev"
184 .text
185 .p2align 4,,15
186 .globl ttyname
187 .type ttyname, @function
188 ttyname:
189 pushq %r14
190 pushq %r13
191 pushq %r12
192 pushq %rbp
193 pushq %rbx
194 movl %edi, %ebx
195 subq $400, %rsp
196 movq __libc_errno@gottpoff(%rip), %rbp
197 leaq 48(%rsp), %rsi
198 movl $0, 12(%rsp)
199 movl %fs:0(%rbp), %r14d
200 call __GI___tcgetattr
201 testl %eax, %eax
202 js .L56
203 leaq 112(%rsp), %r13
204 movl %ebx, %edi
205 movq %r13, %rsi
206 call __GI___fstat64
207 testl %eax, %eax
208 js .L56
209 leaq 16(%rsp), %r12
210 movabsq $7310238724270485551, %rax
211 xorl %ecx, %ecx
212 movq %rax, 16(%rsp)
213 movl $10, %edx
214 movl $12132, %eax
215 leaq 14(%r12), %rsi
216 movslq %ebx, %rdi
217 movl $1714382444, 24(%rsp)
218 movw %ax, 28(%rsp)
219 movb $0, 30(%rsp)
220 call _fitoa_word
221 movq buflen.8909(%rip), %rdx
222 movb $0, (%rax)
223 testq %rdx, %rdx
224 je .L57
225 movq ttyname_buf(%rip), %rax
226 .L32:
227 movq %rax, %rsi
228 movq %r12, %rdi
229 call __readlink
230 cmpq $-1, %rax
231 je .L48
232 cmpq buflen.8909(%rip), %rax
233 movq %rax, %rbx
234 jnb .L56
235 cmpq $13, %rax
236 movq ttyname_buf(%rip), %rcx
237 jbe .L34
238 movabsq $7521962890978293032, %rax
239 cmpq %rax, (%rcx)
240 je .L58
241 .L34:
242 movb $0, (%rcx,%rbx)
243 cmpb $47, (%rcx)
244 leaq 256(%rsp), %rbx
245 je .L37
246 .L38:
247 movl $1, %r12d
248 .L33:
249 leaq .LC4(%rip), %rdi
250 movq %rbx, %rsi
251 call __GI___stat64
252 testl %eax, %eax
253 jne .L40
254 movl 280(%rsp), %eax
255 andl $61440, %eax
256 cmpl $16384, %eax
257 je .L59
258 .L40:
259 cmpl $-1, 12(%rsp)
260 movl %r14d, %fs:0(%rbp)
261 je .L45
262 leaq 12(%rsp), %rbx
263 .L44:
264 leaq .LC5(%rip), %rdi
265 movq %rbx, %rcx
266 movl %r14d, %edx
267 movq %r13, %rsi
268 call getttyname
269 testq %rax, %rax
270 jne .L27
271 cmpl $-1, 12(%rsp)
272 je .L45
273 leaq .LC5(%rip), %rdi
274 movl %r14d, %edx
275 movq %rbx, %rcx
276 movq %r13, %rsi
277 movl $1, 12(%rsp)
278 call getttyname
279 testq %rax, %rax
280 sete %dl
281 jmp .L46
282 .p2align 4,,10
283 .p2align 3
284 .L59:
285 leaq 12(%rsp), %rbx
286 leaq .LC4(%rip), %rdi
287 movl %r14d, %edx
288 movq %r13, %rsi
289 movq %rbx, %rcx
290 call getttyname
291 testq %rax, %rax
292 jne .L27
293 cmpl $-1, 12(%rsp)
294 jne .L44
295 .p2align 4,,10
296 .p2align 3
297 .L45:
298 movl $1, %edx
299 xorl %eax, %eax
300 .L46:
301 testl %r12d, %r12d
302 je .L27
303 testb %dl, %dl
304 je .L27
305 movq 152(%rsp), %rax
306 movq %rax, %rdx
307 shrq $32, %rax
308 shrq $8, %rdx
309 andl $-4096, %eax
310 andl $4095, %edx
311 orl %edx, %eax
312 subl $136, %eax
313 cmpl $7, %eax
314 ja .L56
315 movl $19, %fs:0(%rbp)
316 .p2align 4,,10
317 .p2align 3
318 .L56:
319 xorl %eax, %eax
320 .L27:
321 addq $400, %rsp
322 popq %rbx
323 popq %rbp
324 popq %r12
325 popq %r13
326 popq %r14
328 .p2align 4,,10
329 .p2align 3
330 .L57:
331 movl $4096, %edi
332 movq $4095, buflen.8909(%rip)
333 call malloc@PLT
334 testq %rax, %rax
335 movq %rax, ttyname_buf(%rip)
336 movl $4095, %edx
337 jne .L32
338 movq $0, buflen.8909(%rip)
339 jmp .L27
340 .p2align 4,,10
341 .p2align 3
342 .L37:
343 movq %rbx, %rsi
344 movq %rcx, %rdi
345 call __GI___stat64
346 testl %eax, %eax
347 jne .L38
348 movq 264(%rsp), %rax
349 cmpq %rax, 120(%rsp)
350 jne .L38
351 movq 112(%rsp), %rax
352 cmpq %rax, 256(%rsp)
353 jne .L38
354 movl 280(%rsp), %eax
355 andl $61440, %eax
356 cmpl $8192, %eax
357 jne .L38
358 movq 152(%rsp), %rax
359 cmpq %rax, 296(%rsp)
360 jne .L38
361 movq ttyname_buf(%rip), %rax
362 jmp .L27
363 .p2align 4,,10
364 .p2align 3
365 .L58:
366 cmpl $1701601889, 8(%rcx)
367 jne .L34
368 cmpb $41, 12(%rcx)
369 jne .L34
370 leaq 13(%rcx), %rsi
371 subq $13, %rbx
372 movq %rcx, %rdi
373 movq %rbx, %rdx
374 call __GI_memmove
375 movq %rax, %rcx
376 jmp .L34
377 .p2align 4,,10
378 .p2align 3
379 .L48:
380 xorl %r12d, %r12d
381 leaq 256(%rsp), %rbx
382 jmp .L33
383 .size ttyname, .-ttyname
384 .local namelen.8896
385 .comm namelen.8896,8,8
386 .local buflen.8909
387 .comm buflen.8909,8,8
388 .section __libc_freeres_ptrs
389 #,"aw",@progbits
390 .align 8
391 .type ttyname_buf, @object
392 .size ttyname_buf, 8
393 ttyname_buf:
394 .zero 8
395 .align 8
396 .type getttyname_name, @object
397 .size getttyname_name, 8
398 getttyname_name:
399 .zero 8
400 .hidden __readlink
401 .hidden _fitoa_word
402 .hidden __closedir
403 .hidden __opendir