11.5Sthorpej/*	$NetBSD: __sigtramp2.S,v 1.5 2021/11/24 02:01:15 thorpej Exp $ */
21.1Suwe
31.1Suwe/*-
41.1Suwe * Copyright (c) 2003 The NetBSD Foundation, Inc.
51.1Suwe * All rights reserved.
61.1Suwe *
71.1Suwe * This code is derived from software contributed to The NetBSD Foundation
81.1Suwe * by Jason R. Thorpe.
91.1Suwe *
101.1Suwe * Redistribution and use in source and binary forms, with or without
111.1Suwe * modification, are permitted provided that the following conditions
121.1Suwe * are met:
131.1Suwe * 1. Redistributions of source code must retain the above copyright
141.1Suwe *    notice, this list of conditions and the following disclaimer.
151.1Suwe * 2. Redistributions in binary form must reproduce the above copyright
161.1Suwe *    notice, this list of conditions and the following disclaimer in the
171.1Suwe *    documentation and/or other materials provided with the distribution.
181.1Suwe *
191.1Suwe * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Suwe * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Suwe * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Suwe * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Suwe * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Suwe * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Suwe * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Suwe * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Suwe * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Suwe * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Suwe * POSSIBILITY OF SUCH DAMAGE.
301.1Suwe */
311.1Suwe
321.1Suwe#include "SYS.h"
331.5Sthorpej#include "assym.h"
341.1Suwe
351.1Suwe/*
361.1Suwe * The SH signal trampoline is invoked only to return from
371.1Suwe * the signal; the kernel calls the signal handler directly.
381.1Suwe *
391.1Suwe * On entry, stack looks like:
401.1Suwe *
411.1Suwe *		siginfo structure
421.1Suwe *	sp->	ucontext structure
431.1Suwe *
441.1Suwe * NB: This order is different from what other ports use (siginfo at
451.1Suwe * the top of the stack), because we want to avoid wasting two
461.1Suwe * instructions to skip to the ucontext.  Not that this order really
471.4Sskrll * matters, but I think this inconsistency deserves an explanation.
481.5Sthorpej *
491.5Sthorpej * The DWARF register numbers unforunately do not map directly to our
501.5Sthorpej * _REG_* constants that are used to index the general registers in the
511.5Sthorpej * ucontext_t at all.
521.5Sthorpej *
531.5Sthorpej * The stack pointer is, of course, r15, and there are several DWARF
541.5Sthorpej * pseudo-registers to represent other bits of the context.
551.5Sthorpej */
561.5Sthorpej
571.5Sthorpej#define	DWARF_REG_PC			16
581.5Sthorpej#define	DWARF_REG_PR			17
591.5Sthorpej#define	DWARF_REG_GBR			18
601.5Sthorpej#define	DWARF_REG_MACH			20
611.5Sthorpej#define	DWARF_REG_MACL			21
621.5Sthorpej#define	DWARF_REG_SR			22
631.5Sthorpej
641.5Sthorpej#define	CFI_OFFSET_DWARF_REG(d, r)	.cfi_offset d, r * 4
651.5Sthorpej
661.5Sthorpej	.text
671.5Sthorpej	.cfi_startproc simple
681.5Sthorpej	.cfi_signal_frame
691.5Sthorpej	.cfi_def_cfa 15, _UC_GREGS
701.5Sthorpej	CFI_OFFSET_DWARF_REG(0,  _REG_R0)
711.5Sthorpej	CFI_OFFSET_DWARF_REG(1,  _REG_R1)
721.5Sthorpej	CFI_OFFSET_DWARF_REG(2,  _REG_R2)
731.5Sthorpej	CFI_OFFSET_DWARF_REG(3,  _REG_R3)
741.5Sthorpej	CFI_OFFSET_DWARF_REG(4,  _REG_R4)
751.5Sthorpej	CFI_OFFSET_DWARF_REG(5,  _REG_R5)
761.5Sthorpej	CFI_OFFSET_DWARF_REG(6,  _REG_R6)
771.5Sthorpej	CFI_OFFSET_DWARF_REG(7,  _REG_R7)
781.5Sthorpej	CFI_OFFSET_DWARF_REG(9,  _REG_R8)
791.5Sthorpej	CFI_OFFSET_DWARF_REG(9,  _REG_R9)
801.5Sthorpej	CFI_OFFSET_DWARF_REG(10, _REG_R10)
811.5Sthorpej	CFI_OFFSET_DWARF_REG(11, _REG_R11)
821.5Sthorpej	CFI_OFFSET_DWARF_REG(12, _REG_R12)
831.5Sthorpej	CFI_OFFSET_DWARF_REG(13, _REG_R13)
841.5Sthorpej	CFI_OFFSET_DWARF_REG(14, _REG_R14)
851.5Sthorpej	CFI_OFFSET_DWARF_REG(15, _REG_R15)
861.5Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_REG_PR,   _REG_PR)
871.5Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_REG_SR,   _REG_SR)
881.5Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_REG_GBR,  _REG_GBR)
891.5Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_REG_MACH, _REG_MACH)
901.5Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_REG_MACL, _REG_MACL)
911.5Sthorpej	.cfi_return_column DWARF_REG_PC
921.5Sthorpej	CFI_OFFSET_DWARF_REG(DWARF_REG_PC,   _REG_PC)
931.5Sthorpej
941.5Sthorpej/*
951.5Sthorpej * The unwind entry includes one instruction slot prior to the trampoline
961.5Sthorpej * because the unwinder will look up to (return PC - 1 insn) while unwinding.
971.5Sthorpej * Normally this would be the jump / branch, but since there isn't one in
981.5Sthorpej * this case, we place an explicit nop there instead.
991.1Suwe */
1001.5Sthorpej	nop
1011.5Sthorpej
1021.1SuweNENTRY(__sigtramp_siginfo_2)
1031.1Suwe	mov	r15, r4			/* get pointer to ucontext */
1041.1Suwe	SYSTRAP(setcontext)		/* and call setcontext() */
1051.1Suwe	mov	r0, r4			/* exit with errno */
1061.1Suwe	SYSTRAP(exit)			/* if sigreturn fails */
1071.5Sthorpej	.cfi_endproc
1081.2Suwe	SET_ENTRY_SIZE(__sigtramp_siginfo_2)
109