1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org> 4 */ 5 6#include <linux/linkage.h> 7#include <asm/assembler.h> 8 9SYM_FUNC_START(__efi_rt_asm_wrapper) 10 stp x29, x30, [sp, #-112]! 11 mov x29, sp 12 13 /* 14 * Register x18 is designated as the 'platform' register by the AAPCS, 15 * which means firmware running at the same exception level as the OS 16 * (such as UEFI) should never touch it. 17 */ 18 stp x1, x18, [sp, #16] 19 20 /* 21 * Preserve all callee saved registers and preserve the stack pointer 22 * value at the base of the EFI runtime stack so we can recover from 23 * synchronous exceptions occurring while executing the firmware 24 * routines. 25 */ 26 stp x19, x20, [sp, #32] 27 stp x21, x22, [sp, #48] 28 stp x23, x24, [sp, #64] 29 stp x25, x26, [sp, #80] 30 stp x27, x28, [sp, #96] 31 32 ldr_l x16, efi_rt_stack_top 33 mov sp, x16 34 stp x18, x29, [sp, #-16]! 35 36 /* 37 * We are lucky enough that no EFI runtime services take more than 38 * 5 arguments, so all are passed in registers rather than via the 39 * stack. 40 */ 41 mov x8, x0 42 mov x0, x2 43 mov x1, x3 44 mov x2, x4 45 mov x3, x5 46 mov x4, x6 47 blr x8 48 49 mov sp, x29 50 ldp x1, x2, [sp, #16] 51 cmp x2, x18 52 ldp x29, x30, [sp], #112 53 b.ne 0f 54 ret 550: 56 /* 57 * With CONFIG_SHADOW_CALL_STACK, the kernel uses x18 to store a 58 * shadow stack pointer, which we need to restore before returning to 59 * potentially instrumented code. This is safe because the wrapper is 60 * called with preemption disabled and a separate shadow stack is used 61 * for interrupts. 62 */ 63#ifdef CONFIG_SHADOW_CALL_STACK 64 ldr_l x18, efi_rt_stack_top 65 ldr x18, [x18, #-16] 66#endif 67 68 b efi_handle_corrupted_x18 // tail call 69SYM_FUNC_END(__efi_rt_asm_wrapper) 70 71SYM_CODE_START(__efi_rt_asm_recover) 72 mov sp, x30 73 74 ldp x19, x20, [sp, #32] 75 ldp x21, x22, [sp, #48] 76 ldp x23, x24, [sp, #64] 77 ldp x25, x26, [sp, #80] 78 ldp x27, x28, [sp, #96] 79 ldp x29, x30, [sp], #112 80 ret 81SYM_CODE_END(__efi_rt_asm_recover) 82