//
// Created by Fear1ess on 2021/3/31.
//

.global wd_syscall64
.extern wd_set_errno

.type wd_syscall64, %function

wd_syscall64:
     /* Move syscall No. from x0 to x8 */
     sub     x0, x0, #0xcd
     mov     x8, x0
     /* Move syscall parameters from x1 thru x6 to x0 thru x5 */
     mov     x0, x1
     mov     x1, x2
     mov     x2, x3
     mov     x3, x4
     mov     x4, x5
     mov     x5, x6
     svc     #0
     /* check if syscall returned successfully */
     cmn     x0, #0x1000
     cneg    x0, x0, hi
     b.hi    wd_set_errno
     ret