__sigtramp2.S revision 1.7
1/*	$NetBSD: __sigtramp2.S,v 1.7 2022/06/26 14:37:13 skrll Exp $	*/
2
3/*
4 * Copyright (c) 1998-2001 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Portitions of this file are derived from other sources, see
29 * the copyrights and acknowledgements below.
30 */
31/*
32 * Copyright (c) 1990,1991,1992,1994 The University of Utah and
33 * the Computer Systems Laboratory (CSL).  All rights reserved.
34 *
35 * THE UNIVERSITY OF UTAH AND CSL PROVIDE THIS SOFTWARE IN ITS "AS IS"
36 * CONDITION, AND DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
37 * WHATSOEVER RESULTING FROM ITS USE.
38 *
39 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
40 * improvements that they make and grant CSL redistribution rights.
41 *
42 *	Utah $Hdr: locore.s 1.62 94/12/15$
43 */
44/*
45 *  (c) Copyright 1988 HEWLETT-PACKARD COMPANY
46 *
47 *  To anyone who acknowledges that this file is provided "AS IS"
48 *  without any express or implied warranty:
49 *      permission to use, copy, modify, and distribute this file
50 *  for any purpose is hereby granted without fee, provided that
51 *  the above copyright notice and this notice appears in all
52 *  copies, and that the name of Hewlett-Packard Company not be
53 *  used in advertising or publicity pertaining to distribution
54 *  of the software without specific, written prior permission.
55 *  Hewlett-Packard Company makes no representations about the
56 *  suitability of this software for any purpose.
57 */
58
59#include "SYS.h"
60#include "assym.h"
61
62/*
63 * The hppa signal trampoline is required to call the handler
64 * possibily via a PLABEL.
65 *
66 * On entry, stack looks like:
67 *
68 *	sp->					[x]
69 * r3,arg2->	ucontext structure
70 *    arg1->	siginfo structure		[0]
71 *
72 * where
73 *	x = HPPA_FRAME_ROUND(sizeof(sigframe_siginfo))
74 *
75 * and
76 * 	struct sigframe_siginfo {
77 *		siginfo_t sf_si;
78 *		ucontext_t sf_uc;
79 *	};
80 *
81 * The DWARF register numbers for the general purpose registers are the
82 * same as the architected register numbers.  For HPPA, there is a DWARF
83 * pseudo-register for signal handler return addresses.
84 */
85
86#if defined(__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__)
87#define	DWARF_SIGRETURN_REG		__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__
88#else
89#define	DWARF_SIGRETURN_REG		89	/* 61 on hppa64 */
90#endif
91
92#define	CFI_OFFSET_DWARF_REG(d, r)	.cfi_offset d, r * 4
93#define	CFI_OFFSET(r)			CFI_OFFSET_DWARF_REG(r, r)
94
95	.text
96	.cfi_startproc
97	.cfi_signal_frame
98	.cfi_def_cfa _REG_R30,  -SIZEOF_SIGTRAMP + SIZEOF_SIGINFO + _UC_GREGS
99	CFI_OFFSET(_REG_R1)
100	CFI_OFFSET(_REG_R2)
101	CFI_OFFSET(_REG_R3)
102	CFI_OFFSET(_REG_R4)
103	CFI_OFFSET(_REG_R5)
104	CFI_OFFSET(_REG_R6)
105	CFI_OFFSET(_REG_R7)
106	CFI_OFFSET(_REG_R8)
107	CFI_OFFSET(_REG_R9)
108	CFI_OFFSET(_REG_R10)
109	CFI_OFFSET(_REG_R11)
110	CFI_OFFSET(_REG_R12)
111	CFI_OFFSET(_REG_R13)
112	CFI_OFFSET(_REG_R14)
113	CFI_OFFSET(_REG_R15)
114	CFI_OFFSET(_REG_R16)
115	CFI_OFFSET(_REG_R17)
116	CFI_OFFSET(_REG_R18)
117	CFI_OFFSET(_REG_R19)
118	CFI_OFFSET(_REG_R20)
119	CFI_OFFSET(_REG_R21)
120	CFI_OFFSET(_REG_R22)
121	CFI_OFFSET(_REG_R23)
122	CFI_OFFSET(_REG_R24)
123	CFI_OFFSET(_REG_R25)
124	CFI_OFFSET(_REG_R26)
125	CFI_OFFSET(_REG_R27)
126	CFI_OFFSET(_REG_R28)
127	CFI_OFFSET(_REG_R29)
128	CFI_OFFSET(_REG_R30)
129	CFI_OFFSET(_REG_R31)
130	.cfi_return_column DWARF_SIGRETURN_REG
131	CFI_OFFSET_DWARF_REG(DWARF_SIGRETURN_REG, _REG_PCOQH)
132
133/*
134 * The unwind entry includes one instruction slot prior to the trampoline
135 * because the unwinder will look up to (return PC - 1 insn) while unwinding.
136 * Normally this would be the jump / branch, but since there isn't one in
137 * this case, we place an explicit nop there instead.
138 */
139
140	nop
141
142ENTRY_NOPROFILE(__sigtramp_siginfo_2, 0)
143	.call
144
145	/*
146	 * Our sendsig() places the address of the signal handler in %arg3.
147	 * It may actually be a PLABEL.
148	 */
149	bb,>=,n	%arg3, 30, L$sigcode_bounce	; branch if not a PLABEL
150	depi	0, 31, 2, %arg3			; zero L bit in PLABEL pointer
151	ldw	4(%arg3), %r19			; load shared library linkage
152	ldw	0(%arg3), %arg3			; load real catcher address
153
154L$sigcode_bounce:
155
156	/*
157	 * This blr puts the address of the following nop in rp.
158	 * It also schedules the nop for execution, which is why
159	 * that instruction has to be a nop, or, rather, not any
160	 * instruction only meant to execute once the signal handler
161	 * returns.
162	 */
163	blr	%r0, %rp
164
165	/*
166	 * This bv schedules the instruction pointed to by arg3
167	 * for execution.  So, arg3 is the address of the signal
168	 * handler.
169	 */
170	bv,n	%r0(%arg3)
171	nop
172
173	/*
174	 * The signal handler has returned.  Since r3 is on the list
175	 * of callee-saved registers, it's whatever the sendsig
176	 * code wanted it set to.  Since we copy it into arg0,
177	 * it looks like sendsig leaves r3 holding the desired
178	 * single argument to sys_setcontext, i.e., the ucontext_t *.
179	 */
180
181	/* Make a SYS_setcontext system call. */
182	copy	%r3, %arg0
183	ldil	L%SYSCALLGATE, %r1
184	.call
185	ble	4(%sr2, %r1)
186	 ldi	SYS_setcontext, %t1
187
188	/* Make a SYS_exit system call. */
189	copy	%ret0, %arg0
190	ldil	L%SYSCALLGATE, %r1
191	.call
192	ble	4(%sr2, %r1)
193	 ldi	SYS_exit, %t1
194	.cfi_endproc
195EXIT(__sigtramp_siginfo_2)
196