11.3Sskrll/*	$NetBSD: ptrace.S,v 1.3 2023/05/07 12:41:47 skrll Exp $	*/
21.1Smatt
31.1Smatt/*-
41.1Smatt * Copyright (c) 1991, 1993
51.1Smatt *	The Regents of the University of California.  All rights reserved.
61.1Smatt *
71.1Smatt * This code is derived from software contributed to Berkeley by
81.1Smatt * Ralph Campbell.
91.1Smatt *
101.1Smatt * Redistribution and use in source and binary forms, with or without
111.1Smatt * modification, are permitted provided that the following conditions
121.1Smatt * are met:
131.1Smatt * 1. Redistributions of source code must retain the above copyright
141.1Smatt *    notice, this list of conditions and the following disclaimer.
151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
161.1Smatt *    notice, this list of conditions and the following disclaimer in the
171.1Smatt *    documentation and/or other materials provided with the distribution.
181.1Smatt * 3. Neither the name of the University nor the names of its contributors
191.1Smatt *    may be used to endorse or promote products derived from this software
201.1Smatt *    without specific prior written permission.
211.1Smatt *
221.1Smatt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.1Smatt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Smatt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Smatt * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Smatt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Smatt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Smatt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Smatt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Smatt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Smatt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Smatt * SUCH DAMAGE.
331.1Smatt */
341.1Smatt
351.1Smatt#include "SYS.h"
361.1Smatt
371.1Smatt#if defined(LIBC_SCCS) && !defined(lint)
381.3Sskrll	RCSID("$NetBSD: ptrace.S,v 1.3 2023/05/07 12:41:47 skrll Exp $")
391.1Smatt#endif /* LIBC_SCCS and not lint */
401.1Smatt
411.3Sskrll#define	XCALLFRAME_SIZ	(8 * SZREG)
421.3Sskrll#define	XCALLFRAME_RA	(0 * SZREG)
431.3Sskrll#define	XCALLFRAME_A0	(1 * SZREG)
441.3Sskrll#define	XCALLFRAME_A1	(2 * SZREG)
451.3Sskrll#define	XCALLFRAME_A2	(3 * SZREG)
461.3Sskrll#define	XCALLFRAME_A3	(4 * SZREG)
471.1Smatt
481.1SmattENTRY(ptrace)
491.1Smatt#ifdef _REENTRANT
501.1Smatt	addi	sp, sp, -XCALLFRAME_SIZ
511.1Smatt	REG_S	ra, XCALLFRAME_RA(sp)
521.1Smatt	REG_S	a0, XCALLFRAME_A0(sp)
531.1Smatt	REG_S	a1, XCALLFRAME_A1(sp)
541.1Smatt	REG_S	a2, XCALLFRAME_A2(sp)
551.1Smatt	REG_S	a3, XCALLFRAME_A3(sp)
561.1Smatt
571.1Smatt	call	PLT(_C_LABEL(__errno))
581.1Smatt
591.2Smatt	INT_S	zero, 0(a0)
601.2Smatt
611.1Smatt	REG_L	a3, XCALLFRAME_A3(sp)
621.1Smatt	REG_L	a2, XCALLFRAME_A2(sp)
631.1Smatt	REG_L	a1, XCALLFRAME_A1(sp)
641.1Smatt	REG_L	a0, XCALLFRAME_A0(sp)
651.1Smatt	REG_L	ra, XCALLFRAME_RA(sp)
661.1Smatt	addi	sp, sp, XCALLFRAME_SIZ
671.1Smatt
681.1Smatt#else
691.2Smatt	auipc	t0, %hi(_C_LABEL(errno))
701.2Smatt	INT_S	zero, %lo(_C_LABEL(errno))(t0)
711.1Smatt#endif
721.1Smatt
731.1Smatt	SYSTRAP(ptrace)
741.1Smatt	JUMP_TO_CERROR()	/* error */
751.1Smatt	ret			/* success */
761.1SmattEND(ptrace)
77