riscv64: fix linking with binutils 2.40
[uclibc-ng.git] / libc / sysdeps / linux / x86_64 / sched_getcpu.S
blob3964bf1d33fe5baeaaae0615f75ca79231a74b15
1 /* Copyright (C) 2007, 2011 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
18 #include <sysdep.h>
19 #include <tls.h>
20 #define _ERRNO_H        1
21 #include <bits/errno.h>
22 #include <bits/kernel-features.h>
24 /* For the calculation see asm/vsyscall.h.  */
25 #define VSYSCALL_ADDR_vgetcpu   0xffffffffff600800
28 ENTRY (sched_getcpu)
29         /* Align stack and create local variable for result.  */
30         sub     $0x8, %rsp
31         cfi_adjust_cfa_offset(8)
33         movq    %rsp, %rdi
34         xorl    %esi, %esi
35         movl    $VGETCPU_CACHE_OFFSET, %edx
36         addq    %fs:0, %rdx
38 #ifdef __NR_getcpu
39         movl    $__NR_getcpu, %eax
40         syscall
41 # ifndef __ASSUME_GETCPU_SYSCALL
42         cmpq    $-ENOSYS, %rax
43         jne     1f
44 # endif
45 #endif
46 #ifndef __ASSUME_GETCPU_SYSCALL
47         movq    $VSYSCALL_ADDR_vgetcpu, %rax
48         callq   *%rax
50 #else
51 # ifndef __NR_getcpu
52 #  error "cannot happen"
53 # endif
54 #endif
56         cmpq    $-4095, %rax
57         jae     SYSCALL_ERROR_LABEL
59         movl    (%rsp), %eax
61 L(pseudo_end):
62         add     $0x8, %rsp
63         cfi_adjust_cfa_offset(-8)
64         ret
65 PSEUDO_END(sched_getcpu)