xref: /netbsd-src/lib/libc/arch/powerpc/sys/__sigtramp2.S (revision 3f3a46002b04f3c5a00b58bb70b5c01c120fddae)
1*3f3a4600Sskrll/*	$NetBSD: __sigtramp2.S,v 1.5 2021/11/27 10:00:01 skrll Exp $	*/
24e7e0da4Smatt
34e7e0da4Smatt/*-
44e7e0da4Smatt * Copyright (c) 2002 The NetBSD Foundation, Inc.
54e7e0da4Smatt * All rights reserved.
64e7e0da4Smatt *
74e7e0da4Smatt * This code is derived from software contributed to The NetBSD Foundation
84e7e0da4Smatt * by Jason R. Thorpe.
94e7e0da4Smatt *
104e7e0da4Smatt * Redistribution and use in source and binary forms, with or without
114e7e0da4Smatt * modification, are permitted provided that the following conditions
124e7e0da4Smatt * are met:
134e7e0da4Smatt * 1. Redistributions of source code must retain the above copyright
144e7e0da4Smatt *    notice, this list of conditions and the following disclaimer.
154e7e0da4Smatt * 2. Redistributions in binary form must reproduce the above copyright
164e7e0da4Smatt *    notice, this list of conditions and the following disclaimer in the
174e7e0da4Smatt *    documentation and/or other materials provided with the distribution.
184e7e0da4Smatt *
194e7e0da4Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
204e7e0da4Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
214e7e0da4Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
224e7e0da4Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
234e7e0da4Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
244e7e0da4Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
254e7e0da4Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
264e7e0da4Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
274e7e0da4Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
284e7e0da4Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
294e7e0da4Smatt * POSSIBILITY OF SUCH DAMAGE.
304e7e0da4Smatt */
314e7e0da4Smatt
324e7e0da4Smatt#include "SYS.h"
33f8ce6918Sthorpej#include "assym.h"
344e7e0da4Smatt
35cf88c389Smatt#if defined(LIBC_SCCS) && !defined(lint)
36*3f3a4600Sskrll__RCSID("$NetBSD: __sigtramp2.S,v 1.5 2021/11/27 10:00:01 skrll Exp $")
37cf88c389Smatt#endif /* LIBC_SCCS && !lint */
38cf88c389Smatt
394e7e0da4Smatt/*
404e7e0da4Smatt * On entry to user space, stack and registers look like:
414e7e0da4Smatt *
424e7e0da4Smatt *	r3	signal number
434e7e0da4Smatt *	r4	pointer to siginfo structure
444e7e0da4Smatt *	r5	pointer to ucontext structure
454e7e0da4Smatt *	r30	pointer to ucontext structure
464e7e0da4Smatt *	srr0	address of handler
474e7e0da4Smatt *	lr	address of this trampoline
484e7e0da4Smatt *
49f8ce6918Sthorpej * We use r30 as the CFA base register since it's been conveniently set up
50f8ce6918Sthorpej * for us that way.  The DWARF register numbers used in the .eh_frame are:
51f8ce6918Sthorpej *
52f8ce6918Sthorpej *   0 - 31	GPRs
53f8ce6918Sthorpej *  32 - 63	FPRs
54f8ce6918Sthorpej *  65		LR
55f8ce6918Sthorpej *  66		CTR
56f8ce6918Sthorpej *  68-75	CRs
57f8ce6918Sthorpej *  76		XER
58f8ce6918Sthorpej *  77 - 108	AltiVec regs
59f8ce6918Sthorpej *  99		signal trampoline return address
60f8ce6918Sthorpej * 109		VRSAVE
61f8ce6918Sthorpej * 110		VCSR
62f8ce6918Sthorpej *
63f8ce6918Sthorpej * N.B. Only one CR slot is used (CR2) in the SVR4 ABI.
644e7e0da4Smatt */
65f8ce6918Sthorpej
66f8ce6918Sthorpej#define	DWARF_LR_REG			65
67f8ce6918Sthorpej#define	DWARF_CTR_REG			66
68f8ce6918Sthorpej#define	DWARF_CR2_REG			70
69f8ce6918Sthorpej#define	DWARF_XER_REG			76
70f8ce6918Sthorpej#define	DWARF_SIGRETURN_REG		99
71f8ce6918Sthorpej
72f8ce6918Sthorpej#define	CFI_OFFSET_DWARF_REG(d, r)	.cfi_offset d, r * 4
73f8ce6918Sthorpej#define	CFI_OFFSET(r)			CFI_OFFSET_DWARF_REG(r, r)
74f8ce6918Sthorpej
75f8ce6918Sthorpej	.text
76f8ce6918Sthorpej	.cfi_startproc simple
77f8ce6918Sthorpej	.cfi_signal_frame
78f8ce6918Sthorpej	.cfi_def_cfa _REG_R30, UC_GREGS
79f8ce6918Sthorpej	CFI_OFFSET(_REG_R0)
80f8ce6918Sthorpej	CFI_OFFSET(_REG_R1)
81f8ce6918Sthorpej	CFI_OFFSET(_REG_R2)
82f8ce6918Sthorpej	CFI_OFFSET(_REG_R3)
83f8ce6918Sthorpej	CFI_OFFSET(_REG_R4)
84f8ce6918Sthorpej	CFI_OFFSET(_REG_R5)
85f8ce6918Sthorpej	CFI_OFFSET(_REG_R6)
86f8ce6918Sthorpej	CFI_OFFSET(_REG_R7)
87f8ce6918Sthorpej	CFI_OFFSET(_REG_R8)
88f8ce6918Sthorpej	CFI_OFFSET(_REG_R9)
89f8ce6918Sthorpej	CFI_OFFSET(_REG_R10)
90f8ce6918Sthorpej	CFI_OFFSET(_REG_R11)
91f8ce6918Sthorpej	CFI_OFFSET(_REG_R12)
92f8ce6918Sthorpej	CFI_OFFSET(_REG_R13)
93f8ce6918Sthorpej	CFI_OFFSET(_REG_R14)
94f8ce6918Sthorpej	CFI_OFFSET(_REG_R15)
95f8ce6918Sthorpej	CFI_OFFSET(_REG_R16)
96f8ce6918Sthorpej	CFI_OFFSET(_REG_R17)
97f8ce6918Sthorpej	CFI_OFFSET(_REG_R18)
98f8ce6918Sthorpej	CFI_OFFSET(_REG_R19)
99f8ce6918Sthorpej	CFI_OFFSET(_REG_R20)
100f8ce6918Sthorpej	CFI_OFFSET(_REG_R21)
101f8ce6918Sthorpej	CFI_OFFSET(_REG_R22)
102f8ce6918Sthorpej	CFI_OFFSET(_REG_R23)
103f8ce6918Sthorpej	CFI_OFFSET(_REG_R24)
104f8ce6918Sthorpej	CFI_OFFSET(_REG_R25)
105f8ce6918Sthorpej	CFI_OFFSET(_REG_R26)
106f8ce6918Sthorpej	CFI_OFFSET(_REG_R27)
107f8ce6918Sthorpej	CFI_OFFSET(_REG_R28)
108f8ce6918Sthorpej	CFI_OFFSET(_REG_R29)
109f8ce6918Sthorpej	CFI_OFFSET(_REG_R30)
110f8ce6918Sthorpej	CFI_OFFSET(_REG_R31)
111f8ce6918Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_CR2_REG, _REG_CR)
112f8ce6918Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_LR_REG, _REG_LR)
113f8ce6918Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_CTR_REG, _REG_CTR)
114f8ce6918Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_XER_REG, _REG_XER)
115f8ce6918Sthorpej	.cfi_return_column DWARF_SIGRETURN_REG
116f8ce6918Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_SIGRETURN_REG, _REG_PC)
117f8ce6918Sthorpej
118f8ce6918Sthorpej/*
119f8ce6918Sthorpej * The unwind entry includes one instruction slot prior to the trampoline
120f8ce6918Sthorpej * because the unwinder will look up to (return PC - 1 insn) while unwinding.
121f8ce6918Sthorpej * Normally this would be the jump / branch, but since there isn't one in
122f8ce6918Sthorpej * this case, we place an explicit nop there instead.
123f8ce6918Sthorpej */
124f8ce6918Sthorpej	nop
125f8ce6918Sthorpej
1264e7e0da4SmattENTRY_NOPROFILE(__sigtramp_siginfo_2)
1274e7e0da4Smatt	mr	%r3,%r30		/* restore ucontext pointer */
1284e7e0da4Smatt	_DOSYSCALL(setcontext)		/* restore machine state */
1294e7e0da4Smatt	_DOSYSCALL(exit)		/* or exit with errno if failed */
130f8ce6918Sthorpej	.cfi_endproc
131cf88c389SmattEND(__sigtramp_siginfo_2)
132