1d2912cb1SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */ 27e611e7dSArd Biesheuvel/* 37e611e7dSArd Biesheuvel * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org> 47e611e7dSArd Biesheuvel */ 57e611e7dSArd Biesheuvel 67e611e7dSArd Biesheuvel#include <linux/linkage.h> 718bba184SArd Biesheuvel#include <asm/assembler.h> 87e611e7dSArd Biesheuvel 90343a7e4SMark BrownSYM_FUNC_START(__efi_rt_asm_wrapper) 10e8dfdf31SArd Biesheuvel stp x29, x30, [sp, #-112]! 117e611e7dSArd Biesheuvel mov x29, sp 127e611e7dSArd Biesheuvel 137e611e7dSArd Biesheuvel /* 147e611e7dSArd Biesheuvel * Register x18 is designated as the 'platform' register by the AAPCS, 157e611e7dSArd Biesheuvel * which means firmware running at the same exception level as the OS 167e611e7dSArd Biesheuvel * (such as UEFI) should never touch it. 177e611e7dSArd Biesheuvel */ 187e611e7dSArd Biesheuvel stp x1, x18, [sp, #16] 197e611e7dSArd Biesheuvel 20e8dfdf31SArd Biesheuvel /* 21e8dfdf31SArd Biesheuvel * Preserve all callee saved registers and preserve the stack pointer 22e8dfdf31SArd Biesheuvel * value at the base of the EFI runtime stack so we can recover from 23e8dfdf31SArd Biesheuvel * synchronous exceptions occurring while executing the firmware 24e8dfdf31SArd Biesheuvel * routines. 25e8dfdf31SArd Biesheuvel */ 26e8dfdf31SArd Biesheuvel stp x19, x20, [sp, #32] 27e8dfdf31SArd Biesheuvel stp x21, x22, [sp, #48] 28e8dfdf31SArd Biesheuvel stp x23, x24, [sp, #64] 29e8dfdf31SArd Biesheuvel stp x25, x26, [sp, #80] 30e8dfdf31SArd Biesheuvel stp x27, x28, [sp, #96] 31e8dfdf31SArd Biesheuvel 32ff7a1679SArd Biesheuvel ldr_l x16, efi_rt_stack_top 33ff7a1679SArd Biesheuvel mov sp, x16 34e8dfdf31SArd Biesheuvel stp x18, x29, [sp, #-16]! 35ff7a1679SArd Biesheuvel 367e611e7dSArd Biesheuvel /* 377e611e7dSArd Biesheuvel * We are lucky enough that no EFI runtime services take more than 387e611e7dSArd Biesheuvel * 5 arguments, so all are passed in registers rather than via the 397e611e7dSArd Biesheuvel * stack. 407e611e7dSArd Biesheuvel */ 417e611e7dSArd Biesheuvel mov x8, x0 427e611e7dSArd Biesheuvel mov x0, x2 437e611e7dSArd Biesheuvel mov x1, x3 447e611e7dSArd Biesheuvel mov x2, x4 457e611e7dSArd Biesheuvel mov x3, x5 467e611e7dSArd Biesheuvel mov x4, x6 477e611e7dSArd Biesheuvel blr x8 487e611e7dSArd Biesheuvel 49*8a9a1a18SArd Biesheuvel mov x16, sp 50ff7a1679SArd Biesheuvel mov sp, x29 51*8a9a1a18SArd Biesheuvel str xzr, [x16, #8] // clear recorded task SP value 52*8a9a1a18SArd Biesheuvel 537e611e7dSArd Biesheuvel ldp x1, x2, [sp, #16] 547e611e7dSArd Biesheuvel cmp x2, x18 55e8dfdf31SArd Biesheuvel ldp x29, x30, [sp], #112 567e611e7dSArd Biesheuvel b.ne 0f 577e611e7dSArd Biesheuvel ret 58e73f02c6SSami Tolvanen0: 59e73f02c6SSami Tolvanen /* 60e73f02c6SSami Tolvanen * With CONFIG_SHADOW_CALL_STACK, the kernel uses x18 to store a 61e73f02c6SSami Tolvanen * shadow stack pointer, which we need to restore before returning to 62e73f02c6SSami Tolvanen * potentially instrumented code. This is safe because the wrapper is 63e73f02c6SSami Tolvanen * called with preemption disabled and a separate shadow stack is used 64e73f02c6SSami Tolvanen * for interrupts. 65e73f02c6SSami Tolvanen */ 66ff7a1679SArd Biesheuvel#ifdef CONFIG_SHADOW_CALL_STACK 67ff7a1679SArd Biesheuvel ldr_l x18, efi_rt_stack_top 68ff7a1679SArd Biesheuvel ldr x18, [x18, #-16] 69ff7a1679SArd Biesheuvel#endif 70ff7a1679SArd Biesheuvel 71e73f02c6SSami Tolvanen b efi_handle_corrupted_x18 // tail call 720343a7e4SMark BrownSYM_FUNC_END(__efi_rt_asm_wrapper) 73e8dfdf31SArd Biesheuvel 74e8dfdf31SArd BiesheuvelSYM_CODE_START(__efi_rt_asm_recover) 75e8dfdf31SArd Biesheuvel mov sp, x30 76e8dfdf31SArd Biesheuvel 77*8a9a1a18SArd Biesheuvel ldr_l x16, efi_rt_stack_top // clear recorded task SP value 78*8a9a1a18SArd Biesheuvel str xzr, [x16, #-8] 79*8a9a1a18SArd Biesheuvel 80e8dfdf31SArd Biesheuvel ldp x19, x20, [sp, #32] 81e8dfdf31SArd Biesheuvel ldp x21, x22, [sp, #48] 82e8dfdf31SArd Biesheuvel ldp x23, x24, [sp, #64] 83e8dfdf31SArd Biesheuvel ldp x25, x26, [sp, #80] 84e8dfdf31SArd Biesheuvel ldp x27, x28, [sp, #96] 85e8dfdf31SArd Biesheuvel ldp x29, x30, [sp], #112 86e8dfdf31SArd Biesheuvel ret 87e8dfdf31SArd BiesheuvelSYM_CODE_END(__efi_rt_asm_recover) 88