11.14Suwe/*	$NetBSD: ptrace.S,v 1.14 2025/05/06 20:21:33 uwe Exp $ */
21.1Sbjh21
31.1Sbjh21/*-
41.1Sbjh21 * Copyright (c) 1990 The Regents of the University of California.
51.1Sbjh21 * All rights reserved.
61.1Sbjh21 *
71.1Sbjh21 * Redistribution and use in source and binary forms, with or without
81.1Sbjh21 * modification, are permitted provided that the following conditions
91.1Sbjh21 * are met:
101.1Sbjh21 * 1. Redistributions of source code must retain the above copyright
111.1Sbjh21 *    notice, this list of conditions and the following disclaimer.
121.1Sbjh21 * 2. Redistributions in binary form must reproduce the above copyright
131.1Sbjh21 *    notice, this list of conditions and the following disclaimer in the
141.1Sbjh21 *    documentation and/or other materials provided with the distribution.
151.7Sagc * 3. Neither the name of the University nor the names of its contributors
161.1Sbjh21 *    may be used to endorse or promote products derived from this software
171.1Sbjh21 *    without specific prior written permission.
181.1Sbjh21 *
191.1Sbjh21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.1Sbjh21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.1Sbjh21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.1Sbjh21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.1Sbjh21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.1Sbjh21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.1Sbjh21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.1Sbjh21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.1Sbjh21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.1Sbjh21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.1Sbjh21 * SUCH DAMAGE.
301.1Sbjh21 *
311.1Sbjh21 *	from: @(#)ptrace.s	5.1 (Berkeley) 4/23/90
321.1Sbjh21 */
331.1Sbjh21
341.1Sbjh21#include "SYS.h"
351.1Sbjh21
361.1Sbjh21ENTRY(ptrace)
371.1Sbjh21#ifdef _REENTRANT
381.10Smatt#if !defined(__thumb__) || defined(_ARM_ARCH_T2)
391.10Smatt	push	{r0-r3, lr}
401.10Smatt#else
411.10Smatt	push	{r0-r4}
421.10Smatt	mov	r4, lr
431.10Smatt#endif
441.4Schris	sub	sp, sp, #4	/* align stack */
451.12Sjoerg	bl	PLT_SYM(_C_LABEL(__errno))
461.4Schris	add	sp, sp, #4	/* unalign stack */
471.10Smatt	movs	r1, #0
481.1Sbjh21	str	r1, [r0]
491.10Smatt#if !defined(__thumb__) || defined(_ARM_ARCH_T2)
501.10Smatt	pop	{r0-r3, lr}
511.10Smatt#else
521.10Smatt	mov	lr, r4
531.10Smatt	pop	{r0-r4}
541.10Smatt#endif
551.1Sbjh21#else
561.10Smatt	push	{r0, r1}
571.14Suwe#ifdef __PIC__
581.14Suwe	/* Setup the GOT */
591.14Suwe	ldr	r0, .Lgot
601.14Suwe	adr	r1, .Lgot
611.14Suwe	add	r0, r0, r1
621.14Suwe	ldr	r1, .Lerrno
631.14Suwe	ldr	r1, [r0, r1]
641.14Suwe#else
651.14Suwe	ldr	r1, .Lerrno
661.14Suwe#endif /* __PIC__ */
671.10Smatt	movs	r0, #0
681.1Sbjh21	str	r0, [r1]
691.10Smatt	pop	{r0, r1}
701.1Sbjh21#endif /* _REENTRANT */
711.1Sbjh21
721.2Sbjh21	SYSTRAP(ptrace)
731.10Smatt	_INVOKE_CERROR()
741.8Srearnsha	RET
751.1Sbjh21
761.1Sbjh21#ifndef _REENTRANT
771.14Suwe#ifdef __PIC__
781.14Suwe	.align	0
791.14Suwe.Lgot:
801.14Suwe	.word	_C_LABEL(_GLOBAL_OFFSET_TABLE_) - .Lgot
811.14Suwe#endif /* __PIC__ */
821.1Sbjh21
831.5Sthorpej.Lerrno:
841.14Suwe	.word	PIC_SYM(_C_LABEL(errno), GOT)
851.1Sbjh21#endif /* !_REENTRANT */
861.10SmattEND(ptrace)
87