/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright (C) 2018 Linaro Ltd <[email protected]>3*/45#include <linux/linkage.h>6#include <asm/assembler.h>78SYM_FUNC_START(__efi_rt_asm_wrapper)9stp x29, x30, [sp, #-112]!10mov x29, sp1112/*13* Register x18 is designated as the 'platform' register by the AAPCS,14* which means firmware running at the same exception level as the OS15* (such as UEFI) should never touch it.16*/17stp x1, x18, [sp, #16]1819/*20* Preserve all callee saved registers and preserve the stack pointer21* value at the base of the EFI runtime stack so we can recover from22* synchronous exceptions occurring while executing the firmware23* routines.24*/25stp x19, x20, [sp, #32]26stp x21, x22, [sp, #48]27stp x23, x24, [sp, #64]28stp x25, x26, [sp, #80]29stp x27, x28, [sp, #96]3031ldr_l x16, efi_rt_stack_top32mov sp, x1633stp x18, x29, [sp, #-16]!3435/*36* We are lucky enough that no EFI runtime services take more than37* 5 arguments, so all are passed in registers rather than via the38* stack.39*/40mov x8, x041mov x0, x242mov x1, x343mov x2, x444mov x3, x545mov x4, x646blr x84748mov x16, sp49mov sp, x2950str xzr, [x16, #8] // clear recorded task SP value5152ldp x1, x2, [sp, #16]53cmp x2, x1854ldp x29, x30, [sp], #11255b.ne 0f56ret570:58/*59* With CONFIG_SHADOW_CALL_STACK, the kernel uses x18 to store a60* shadow stack pointer, which we need to restore before returning to61* potentially instrumented code. This is safe because the wrapper is62* called with preemption disabled and a separate shadow stack is used63* for interrupts.64*/65#ifdef CONFIG_SHADOW_CALL_STACK66ldr_l x18, efi_rt_stack_top67ldr x18, [x18, #-16]68#endif6970b efi_handle_corrupted_x18 // tail call71SYM_FUNC_END(__efi_rt_asm_wrapper)7273SYM_CODE_START(__efi_rt_asm_recover)74mov sp, x307576ldr_l x16, efi_rt_stack_top // clear recorded task SP value77str xzr, [x16, #-8]7879ldp x19, x20, [sp, #32]80ldp x21, x22, [sp, #48]81ldp x23, x24, [sp, #64]82ldp x25, x26, [sp, #80]83ldp x27, x28, [sp, #96]84ldp x29, x30, [sp], #11285ret86SYM_CODE_END(__efi_rt_asm_recover)878889