1/* 2 * Copyright (c) 2014, Google, Inc. All rights reserved 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files 6 * (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24#include <arch/asm_macros.h> 25#include <asm.h> 26 27#define DAIF_MASK_IAF 0x7 28 29/* ARM syscall ABI 30 * =============== 31 * Only syscalls with 4 args (max) are currently supported 32 * r0-r3/x0-x3 = args 33 * r0-r1/x0 = return value (r0 only if 32-bit retval) 34 * r12/x12 = syscall number, expected to be trashed. 35 * syscalls run with interrupts enabled 36 */ 37FUNCTION (arm64_syscall) 38 push x0, x30 39 ldr w12, [x0, #(12 << 3)] 40 41 msr daifclr, #DAIF_MASK_IAF 42 43 adrl x14, nr_syscalls 44 ldr x14, [x14] 45 cmp x12, x14 46 b.hs .Lundefined 47 adrl x14, syscall_table 48 ldr x14, [x14, x12, lsl#3] 49 cbnz x14, .Ldefined 50.Lundefined: 51 adrl x14, sys_undefined 52.Ldefined: 53 ldp x2, x3, [x0, #16] 54 ldp x0, x1, [x0] 55 blr x14 56 57 msr daifset, #DAIF_MASK_IAF 58 59 pop x1, x30 60 61 str x0, [x1, 0] 62 63 ret 64