14906e5653c57d49f94940f28556009a88c42a583Elliott Hughes/*
24906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * Copyright (C) 2013 The Android Open Source Project
34906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * All rights reserved.
44906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *
54906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * Redistribution and use in source and binary forms, with or without
64906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * modification, are permitted provided that the following conditions
74906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * are met:
84906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *  * Redistributions of source code must retain the above copyright
94906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *    notice, this list of conditions and the following disclaimer.
104906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *  * Redistributions in binary form must reproduce the above copyright
114906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *    notice, this list of conditions and the following disclaimer in
124906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *    the documentation and/or other materials provided with the
134906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *    distribution.
144906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *
154906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
164906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
174906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
184906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
194906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
204906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
214906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
224906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
234906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
244906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
254906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * SUCH DAMAGE.
274906e5653c57d49f94940f28556009a88c42a583Elliott Hughes */
284906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
294906e5653c57d49f94940f28556009a88c42a583Elliott Hughes/*
304906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * Generic syscall call.
314906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * Upon entry:
324906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *   %rax: system call number
334906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *   %rdi: arg0 to system call
344906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *   %rsi: arg1
354906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *   %rdx: arg2
364906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *   %rcx: arg3 - syscall expects it at %r10
374906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *   %r8: arg4
384906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *   %r9: arg5
394906e5653c57d49f94940f28556009a88c42a583Elliott Hughes */
404906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
41ed74484dcbc2e156a6e5fa861a62425b12e55128Elliott Hughes#include <private/bionic_asm.h>
424906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
434906e5653c57d49f94940f28556009a88c42a583Elliott HughesENTRY(syscall)
444906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    # All arguments are passed via registers.
454906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    # (Not all will be valid, depending on the syscall.)
464906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    mov     %edi, %eax
474906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    mov     %rsi, %rdi
484906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    mov     %rdx, %rsi
494906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    mov     %rcx, %rdx
504906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    mov     %r8,  %r10
514906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    mov     %r9,  %r8
524906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    mov     8(%rsp), %r9
534906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
544906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    # Make the system call.
554906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    syscall
564906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    cmpq    $-MAX_ERRNO, %rax
574906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    jb      1f
584906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    negl    %eax
594906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    movl    %eax, %edi
607efad83d430f4d824f2aaa75edea5106f6ff8aaeElliott Hughes    call    __set_errno_internal
614906e5653c57d49f94940f28556009a88c42a583Elliott Hughes1:
624906e5653c57d49f94940f28556009a88c42a583Elliott Hughes    ret
63ed74484dcbc2e156a6e5fa861a62425b12e55128Elliott HughesEND(syscall)
64