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