1/* $NetBSD: __sigtramp2.S,v 1.7 2021/11/23 02:49:56 thorpej Exp $ */ 2 3/*- 4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Matt Thomas of 3am Software Foundry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include "SYS.h" 33#include "assym.h" 34 35/* 36 * The ARM64 signal trampoline is invoked only to return from 37 * the signal; the kernel calls the signal handler directly. 38 * 39 * On entry, the stack looks like: 40 * 41 * ucontext structure 42 * sp-> siginfo structure 43 * and x28 points to the ucontext 44 * 45 * A DWARF pseudo-register is used for the return address from the 46 * signal trampoline. 47 */ 48 49#if defined(__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__) 50#define DWARF_SIGRETURN_REG __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__ 51#else 52#define DWARF_SIGRETURN_REG 96 53#endif 54 55#define CFI_OFFSET_DWARF_REG(d, r) .cfi_offset d, r * 8 56#define CFI_OFFSET(r) CFI_OFFSET_DWARF_REG(r, r) 57 58 .text 59 .cfi_startproc simple 60 .cfi_signal_frame 61 .cfi_def_cfa _REG_X28, _UC_GREGS 62 CFI_OFFSET(_REG_X0) 63 CFI_OFFSET(_REG_X1) 64 CFI_OFFSET(_REG_X2) 65 CFI_OFFSET(_REG_X3) 66 CFI_OFFSET(_REG_X4) 67 CFI_OFFSET(_REG_X5) 68 CFI_OFFSET(_REG_X6) 69 CFI_OFFSET(_REG_X7) 70 CFI_OFFSET(_REG_X8) 71 CFI_OFFSET(_REG_X9) 72 CFI_OFFSET(_REG_X10) 73 CFI_OFFSET(_REG_X11) 74 CFI_OFFSET(_REG_X12) 75 CFI_OFFSET(_REG_X13) 76 CFI_OFFSET(_REG_X14) 77 CFI_OFFSET(_REG_X15) 78 CFI_OFFSET(_REG_X16) 79 CFI_OFFSET(_REG_X17) 80 CFI_OFFSET(_REG_X18) 81 CFI_OFFSET(_REG_X19) 82 CFI_OFFSET(_REG_X20) 83 CFI_OFFSET(_REG_X21) 84 CFI_OFFSET(_REG_X22) 85 CFI_OFFSET(_REG_X23) 86 CFI_OFFSET(_REG_X24) 87 CFI_OFFSET(_REG_X25) 88 CFI_OFFSET(_REG_X26) 89 CFI_OFFSET(_REG_X27) 90 CFI_OFFSET(_REG_X28) 91 CFI_OFFSET(_REG_X29) 92 CFI_OFFSET(_REG_X30) /* a.k.a. _REG_LR */ 93 CFI_OFFSET(_REG_X31) /* a.k.a. _REG_SP */ 94 .cfi_return_column DWARF_SIGRETURN_REG 95 CFI_OFFSET_DWARF_REG(DWARF_SIGRETURN_REG, _REG_PC) 96 97/* 98 * The unwind entry includes the one instruction prior to the trampoline 99 * because the unwinder will look up (return PC - 1) while unwinding. 100 * Normally this would be the jump / branch, but since there isn't one in 101 * this case, we place an explicit nop there instead. 102 */ 103 nop 104 105ENTRY_NP(__sigtramp_siginfo_2) 106 mov x0, x28 /* set the arg */ 107 SYSTRAP(setcontext) /* and call setcontext */ 108 109 /* If that failed, exit with the error code. */ 110 SYSTRAP(exit) 111 .cfi_endproc 112END(__sigtramp_siginfo_2) 113