1/*	$NetBSD: __sigtramp3.S,v 1.3 2021/11/24 15:05:16 thorpej Exp $	*/
2
3/*
4 * Copyright (c) 2003 Matt Thomas <matt@3am-software.com>
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 * 3. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "SYS.h"
31#include "assym.h"
32
33#ifdef SYSLIBC_SCCS
34RCSID("$NetBSD: __sigtramp3.S,v 1.3 2021/11/24 15:05:16 thorpej Exp $")
35#endif
36
37/*
38 * Signal trampoline; registers when called:
39 *	pc, psl - obvious
40 *	sp, ap - points to a CALLG argument list
41 *	fp - address of signal handler
42 *
43 * Stack is set up like so:
44 *		ucontext structure
45 *		siginfo structure
46 *		vvvv CALLG argument list vvvv
47 *		12(ap) -- pointer to ucontext
48 *		 8(ap) -- pointer to siginfo
49 *		 4(ap) -- signal number
50 *	sp ->	 0(ap) -- argument count
51 *		^^^^ CALLG argument list ^^^^
52 *
53 * N.B. all of the DWARF register numbers match our _REG_* constants.
54 * Also notice that while the %ap is adjusted inside the trampoline,
55 * the %sp is not adjusted, and so the CFA base does not change.
56 */
57
58#define	CFI_OFFSET(r)			.cfi_offset r, r * 4
59
60	.text
61#if 0
62	.cfi_startproc simple
63	.cfi_signal_frame
64	.cfi_def_cfa _REG_SP, 16 + SIZEOF_SIGINFO + UC_GREGS
65	CFI_OFFSET(_REG_R0)
66	CFI_OFFSET(_REG_R1)
67	CFI_OFFSET(_REG_R2)
68	CFI_OFFSET(_REG_R3)
69	CFI_OFFSET(_REG_R4)
70	CFI_OFFSET(_REG_R5)
71	CFI_OFFSET(_REG_R6)
72	CFI_OFFSET(_REG_R7)
73	CFI_OFFSET(_REG_R8)
74	CFI_OFFSET(_REG_R9)
75	CFI_OFFSET(_REG_R10)
76	CFI_OFFSET(_REG_R11)
77	CFI_OFFSET(_REG_AP)
78	CFI_OFFSET(_REG_FP)
79	CFI_OFFSET(_REG_SP)
80	CFI_OFFSET(_REG_PC)
81	CFI_OFFSET(_REG_PSL)
82#endif
83
84/*
85 * The unwind entry includes one instruction slot prior to the trampoline
86 * because the unwinder will look up to (return PC - 1) while unwinding.
87 * Normally this would be the jump / branch, but since there isn't one in
88 * this case, we place an explicit nop there instead.
89 */
90
91#if 0
92	nop
93#endif
94	_ALIGN_TEXT
95
96	.globl	_C_LABEL(__sigtramp_siginfo_3)
97_C_LABEL(__sigtramp_siginfo_3):
98	nop; nop
99	callg (%ap),(%fp)		# use global arg list
100	addl2 $8,%ap			# arg is pointer to ucontext
101	SYSTRAP(setcontext)		# exit from here
102	halt				# illegal insn
103#if 0
104	.cfi_endproc
105#endif
106