xref: /netbsd-src/lib/libc/arch/powerpc/sys/__sigtramp2.S (revision 3f3a46002b04f3c5a00b58bb70b5c01c120fddae)
1/*	$NetBSD: __sigtramp2.S,v 1.5 2021/11/27 10:00:01 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(LIBC_SCCS) && !defined(lint)
36__RCSID("$NetBSD: __sigtramp2.S,v 1.5 2021/11/27 10:00:01 skrll Exp $")
37#endif /* LIBC_SCCS && !lint */
38
39/*
40 * On entry to user space, stack and registers look like:
41 *
42 *	r3	signal number
43 *	r4	pointer to siginfo structure
44 *	r5	pointer to ucontext structure
45 *	r30	pointer to ucontext structure
46 *	srr0	address of handler
47 *	lr	address of this trampoline
48 *
49 * We use r30 as the CFA base register since it's been conveniently set up
50 * for us that way.  The DWARF register numbers used in the .eh_frame are:
51 *
52 *   0 - 31	GPRs
53 *  32 - 63	FPRs
54 *  65		LR
55 *  66		CTR
56 *  68-75	CRs
57 *  76		XER
58 *  77 - 108	AltiVec regs
59 *  99		signal trampoline return address
60 * 109		VRSAVE
61 * 110		VCSR
62 *
63 * N.B. Only one CR slot is used (CR2) in the SVR4 ABI.
64 */
65
66#define	DWARF_LR_REG			65
67#define	DWARF_CTR_REG			66
68#define	DWARF_CR2_REG			70
69#define	DWARF_XER_REG			76
70#define	DWARF_SIGRETURN_REG		99
71
72#define	CFI_OFFSET_DWARF_REG(d, r)	.cfi_offset d, r * 4
73#define	CFI_OFFSET(r)			CFI_OFFSET_DWARF_REG(r, r)
74
75	.text
76	.cfi_startproc simple
77	.cfi_signal_frame
78	.cfi_def_cfa _REG_R30, UC_GREGS
79	CFI_OFFSET(_REG_R0)
80	CFI_OFFSET(_REG_R1)
81	CFI_OFFSET(_REG_R2)
82	CFI_OFFSET(_REG_R3)
83	CFI_OFFSET(_REG_R4)
84	CFI_OFFSET(_REG_R5)
85	CFI_OFFSET(_REG_R6)
86	CFI_OFFSET(_REG_R7)
87	CFI_OFFSET(_REG_R8)
88	CFI_OFFSET(_REG_R9)
89	CFI_OFFSET(_REG_R10)
90	CFI_OFFSET(_REG_R11)
91	CFI_OFFSET(_REG_R12)
92	CFI_OFFSET(_REG_R13)
93	CFI_OFFSET(_REG_R14)
94	CFI_OFFSET(_REG_R15)
95	CFI_OFFSET(_REG_R16)
96	CFI_OFFSET(_REG_R17)
97	CFI_OFFSET(_REG_R18)
98	CFI_OFFSET(_REG_R19)
99	CFI_OFFSET(_REG_R20)
100	CFI_OFFSET(_REG_R21)
101	CFI_OFFSET(_REG_R22)
102	CFI_OFFSET(_REG_R23)
103	CFI_OFFSET(_REG_R24)
104	CFI_OFFSET(_REG_R25)
105	CFI_OFFSET(_REG_R26)
106	CFI_OFFSET(_REG_R27)
107	CFI_OFFSET(_REG_R28)
108	CFI_OFFSET(_REG_R29)
109	CFI_OFFSET(_REG_R30)
110	CFI_OFFSET(_REG_R31)
111	CFI_OFFSET_DWARF_REG(DWARF_CR2_REG, _REG_CR)
112	CFI_OFFSET_DWARF_REG(DWARF_LR_REG, _REG_LR)
113	CFI_OFFSET_DWARF_REG(DWARF_CTR_REG, _REG_CTR)
114	CFI_OFFSET_DWARF_REG(DWARF_XER_REG, _REG_XER)
115	.cfi_return_column DWARF_SIGRETURN_REG
116	CFI_OFFSET_DWARF_REG(DWARF_SIGRETURN_REG, _REG_PC)
117
118/*
119 * The unwind entry includes one instruction slot prior to the trampoline
120 * because the unwinder will look up to (return PC - 1 insn) while unwinding.
121 * Normally this would be the jump / branch, but since there isn't one in
122 * this case, we place an explicit nop there instead.
123 */
124	nop
125
126ENTRY_NOPROFILE(__sigtramp_siginfo_2)
127	mr	%r3,%r30		/* restore ucontext pointer */
128	_DOSYSCALL(setcontext)		/* restore machine state */
129	_DOSYSCALL(exit)		/* or exit with errno if failed */
130	.cfi_endproc
131END(__sigtramp_siginfo_2)
132