1/* $NetBSD: __sigtramp2.S,v 1.5 2024/05/30 15:56:43 skrll Exp $ */ 2 3/*- 4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 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#if defined(SYSLIBC_SCCS) && !defined(lint) 36 RCSID("$NetBSD: __sigtramp2.S,v 1.5 2024/05/30 15:56:43 skrll Exp $") 37#endif /* SYSLIBC_SCCS and not lint */ 38 39 40/* 41 * The RISC-V signal trampoline is invoked only to return from 42 * the signal; the kernel calls the signal handler directly. 43 * 44 * On entry, stack looks like: 45 * 46 * sp -> siginfo_t structure 47 * sp + SIGINFO_SIZE -> ucontext_t structure 48 * 49 * The DWARF register numbers for the general purpose registers are the 50 * same as the architected register numbers. For RISC-V, there is a DWARF 51 * pseudo-register for signal handler return address. 52 */ 53 54#if defined(__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__) 55#define DWARF_SIGRETURN_REG __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__ 56#else 57#define DWARF_SIGRETURN_REG 64 58#endif 59 60 .text 61 .cfi_startproc 62 .cfi_signal_frame 63 .cfi_def_cfa sp, SIGINFO_SIZE 64 .cfi_offset ra, UC_GREGS_RA 65 .cfi_offset sp, UC_GREGS_SP 66 .cfi_offset gp, UC_GREGS_GP 67 .cfi_offset tp, UC_GREGS_TP 68 .cfi_offset t0, UC_GREGS_T0 69 .cfi_offset t1, UC_GREGS_T1 70 .cfi_offset t2, UC_GREGS_T2 71 .cfi_offset s0, UC_GREGS_S0 72 .cfi_offset s1, UC_GREGS_S1 73 .cfi_offset a0, UC_GREGS_A0 74 .cfi_offset a1, UC_GREGS_A1 75 .cfi_offset a2, UC_GREGS_A2 76 .cfi_offset a3, UC_GREGS_A3 77 .cfi_offset a4, UC_GREGS_A4 78 .cfi_offset a5, UC_GREGS_A5 79 .cfi_offset a6, UC_GREGS_A6 80 .cfi_offset a7, UC_GREGS_A7 81 .cfi_offset s2, UC_GREGS_S2 82 .cfi_offset s3, UC_GREGS_S3 83 .cfi_offset s4, UC_GREGS_S4 84 .cfi_offset s5, UC_GREGS_S5 85 .cfi_offset s6, UC_GREGS_S6 86 .cfi_offset s7, UC_GREGS_S7 87 .cfi_offset s8, UC_GREGS_S8 88 .cfi_offset s9, UC_GREGS_S9 89 .cfi_offset s10, UC_GREGS_S10 90 .cfi_offset s11, UC_GREGS_S11 91 .cfi_offset t3, UC_GREGS_T3 92 .cfi_offset t4, UC_GREGS_T4 93 .cfi_offset t5, UC_GREGS_T5 94 .cfi_offset t6, UC_GREGS_T6 95 .cfi_return_column DWARF_SIGRETURN_REG 96 .cfi_offset DWARF_SIGRETURN_REG, UC_GREGS_PC 97 98/* 99 * The unwind entry includes one instruction slot prior to the trampoline 100 * because the unwinder will look up to (return PC - 1 insn) while unwinding. 101 * Normally this would be the jump / branch, but since there isn't one in 102 * this case, we place an explicit nop there instead. 103 */ 104 nop 105 106ENTRY_NP(__sigtramp_siginfo_2) 107 addi a0, sp, SIGINFO_SIZE /* address of ucontext */ 108 SYSTRAP_NOERROR(setcontext) /* and do setcontext */ 109 SYSTRAP(exit) /* if sigreturn fails */ 110 .cfi_endproc 111END(__sigtramp_siginfo_2) 112