Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: __sigtramp2.S,v 1.5 2022/04/07 20:23:44 andvar 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 2022/04/07 20:23:44 andvar Exp $")
     37 #endif /* SYSLIBC_SCCS and not lint */
     38 
     39 
     40 /*
     41  * The MIPS 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  *		ucontext structure	sp + sizeof(siginfo_t)
     47  *	sp->	siginfo structure
     48  *
     49  * The DWARF register numbers for the general purpose registers are the
     50  * same as the architected register numbers.  For MIPS, there is a DWARF
     51  * pseudo-register for signal handler return addresses, as well as for the
     52  * MDLO and MDHI registers.
     53  */
     54 
     55 #define	DWARF_MDHI_REG			64
     56 #define	DWARF_MDLO_REG			65
     57 
     58 #if defined(__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__)
     59 #define	DWARF_SIGRETURN_REG		__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__
     60 #else
     61 #define	DWARF_SIGRETURN_REG		66
     62 #endif
     63 
     64 #define	CFI_OFFSET_DWARF_REG(d, r)	.cfi_offset d, r * SZREG
     65 #define	CFI_OFFSET(r)			CFI_OFFSET_DWARF_REG(r, r)
     66 
     67 	.text
     68 	.cfi_startproc
     69 	.cfi_signal_frame
     70 	.cfi_def_cfa _REG_SP, SIGINFO_SIZE + _UC_GREGS
     71 	CFI_OFFSET(_REG_R0)
     72 	CFI_OFFSET(_REG_AT)
     73 	CFI_OFFSET(_REG_V0)
     74 	CFI_OFFSET(_REG_V1)
     75 	CFI_OFFSET(_REG_A0)
     76 	CFI_OFFSET(_REG_A1)
     77 	CFI_OFFSET(_REG_A2)
     78 	CFI_OFFSET(_REG_A3)
     79 	CFI_OFFSET(_REG_T0)
     80 	CFI_OFFSET(_REG_T1)
     81 	CFI_OFFSET(_REG_T2)
     82 	CFI_OFFSET(_REG_T3)
     83 	CFI_OFFSET(_REG_T4)
     84 	CFI_OFFSET(_REG_T5)
     85 	CFI_OFFSET(_REG_T6)
     86 	CFI_OFFSET(_REG_T7)
     87 	CFI_OFFSET(_REG_S0)
     88 	CFI_OFFSET(_REG_S1)
     89 	CFI_OFFSET(_REG_S2)
     90 	CFI_OFFSET(_REG_S3)
     91 	CFI_OFFSET(_REG_S4)
     92 	CFI_OFFSET(_REG_S5)
     93 	CFI_OFFSET(_REG_S6)
     94 	CFI_OFFSET(_REG_S7)
     95 	CFI_OFFSET(_REG_T8)
     96 	CFI_OFFSET(_REG_T9)
     97 	CFI_OFFSET(_REG_K0)
     98 	CFI_OFFSET(_REG_K1)
     99 	CFI_OFFSET(_REG_GP)
    100 	CFI_OFFSET(_REG_SP)
    101 	CFI_OFFSET(_REG_S8)
    102 	CFI_OFFSET(_REG_RA)
    103 	CFI_OFFSET_DWARF_REG(DWARF_MDHI_REG, _REG_MDHI)
    104 	CFI_OFFSET_DWARF_REG(DWARF_MDLO_REG, _REG_MDLO)
    105 	.cfi_return_column DWARF_SIGRETURN_REG
    106 	CFI_OFFSET_DWARF_REG(DWARF_SIGRETURN_REG, _REG_EPC)
    107 
    108 /*
    109  * The unwind entry includes one instruction slot prior to the trampoline
    110  * because the unwinder will look up to (return PC - 1 insn) while unwinding.
    111  * Normally this would be the jump / branch, but since there isn't one in
    112  * this case, we place an explicit nop there instead.
    113  */
    114 	nop
    115 
    116 LEAF_NOPROFILE(__sigtramp_siginfo_2)
    117 	PTR_ADDU	a0, sp, SIGINFO_SIZE	/* address of ucontext */
    118 	SYSTRAP(setcontext)			/* and do setcontext */
    119 	move		a0, v0			/* exit with errno */
    120 	SYSTRAP(exit)				/* if sigreturn fails */
    121 	.cfi_endproc
    122 END(__sigtramp_siginfo_2)
    123