1/*	$NetBSD: __sigtramp2.S,v 1.5 2021/11/24 02:01:15 thorpej Exp $ */
2
3/*-
4 * Copyright (c) 2003 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/*
36 * The SH signal trampoline is invoked only to return from
37 * the signal; the kernel calls the signal handler directly.
38 *
39 * On entry, stack looks like:
40 *
41 *		siginfo structure
42 *	sp->	ucontext structure
43 *
44 * NB: This order is different from what other ports use (siginfo at
45 * the top of the stack), because we want to avoid wasting two
46 * instructions to skip to the ucontext.  Not that this order really
47 * matters, but I think this inconsistency deserves an explanation.
48 *
49 * The DWARF register numbers unforunately do not map directly to our
50 * _REG_* constants that are used to index the general registers in the
51 * ucontext_t at all.
52 *
53 * The stack pointer is, of course, r15, and there are several DWARF
54 * pseudo-registers to represent other bits of the context.
55 */
56
57#define	DWARF_REG_PC			16
58#define	DWARF_REG_PR			17
59#define	DWARF_REG_GBR			18
60#define	DWARF_REG_MACH			20
61#define	DWARF_REG_MACL			21
62#define	DWARF_REG_SR			22
63
64#define	CFI_OFFSET_DWARF_REG(d, r)	.cfi_offset d, r * 4
65
66	.text
67	.cfi_startproc simple
68	.cfi_signal_frame
69	.cfi_def_cfa 15, _UC_GREGS
70	CFI_OFFSET_DWARF_REG(0,  _REG_R0)
71	CFI_OFFSET_DWARF_REG(1,  _REG_R1)
72	CFI_OFFSET_DWARF_REG(2,  _REG_R2)
73	CFI_OFFSET_DWARF_REG(3,  _REG_R3)
74	CFI_OFFSET_DWARF_REG(4,  _REG_R4)
75	CFI_OFFSET_DWARF_REG(5,  _REG_R5)
76	CFI_OFFSET_DWARF_REG(6,  _REG_R6)
77	CFI_OFFSET_DWARF_REG(7,  _REG_R7)
78	CFI_OFFSET_DWARF_REG(9,  _REG_R8)
79	CFI_OFFSET_DWARF_REG(9,  _REG_R9)
80	CFI_OFFSET_DWARF_REG(10, _REG_R10)
81	CFI_OFFSET_DWARF_REG(11, _REG_R11)
82	CFI_OFFSET_DWARF_REG(12, _REG_R12)
83	CFI_OFFSET_DWARF_REG(13, _REG_R13)
84	CFI_OFFSET_DWARF_REG(14, _REG_R14)
85	CFI_OFFSET_DWARF_REG(15, _REG_R15)
86	CFI_OFFSET_DWARF_REG(DWARF_REG_PR,   _REG_PR)
87	CFI_OFFSET_DWARF_REG(DWARF_REG_SR,   _REG_SR)
88	CFI_OFFSET_DWARF_REG(DWARF_REG_GBR,  _REG_GBR)
89	CFI_OFFSET_DWARF_REG(DWARF_REG_MACH, _REG_MACH)
90	CFI_OFFSET_DWARF_REG(DWARF_REG_MACL, _REG_MACL)
91	.cfi_return_column DWARF_REG_PC
92	CFI_OFFSET_DWARF_REG(DWARF_REG_PC,   _REG_PC)
93
94/*
95 * The unwind entry includes one instruction slot prior to the trampoline
96 * because the unwinder will look up to (return PC - 1 insn) while unwinding.
97 * Normally this would be the jump / branch, but since there isn't one in
98 * this case, we place an explicit nop there instead.
99 */
100	nop
101
102NENTRY(__sigtramp_siginfo_2)
103	mov	r15, r4			/* get pointer to ucontext */
104	SYSTRAP(setcontext)		/* and call setcontext() */
105	mov	r0, r4			/* exit with errno */
106	SYSTRAP(exit)			/* if sigreturn fails */
107	.cfi_endproc
108	SET_ENTRY_SIZE(__sigtramp_siginfo_2)
109