h_execregs.S revision 1.1
1/*	$NetBSD: h_execregs.S,v 1.1 2025/02/27 00:55:31 riastradh Exp $	*/
2
3/*-
4 * Copyright (c) 2025 The NetBSD Foundation, Inc.
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 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#define	_LOCORE
30
31#include <sys/syscall.h>
32
33#include <machine/asm.h>
34
35#include "execregs.h"
36
37ENTRY(execregs_start)
38	/* create a stack frame with NEXECREGS*8 bytes */
39	stp	fp, lr, [sp, #-(16 + NEXECREGS*8)]!
40
41	/* store registers to buffer on stack */
42	stp	x0, x1, [sp, #16]	/* order matches execregs.h */
43	/* x2: ps_strings */
44	stp	x3, x4, [sp, #(16 + 1*2*8)]
45	stp	x5, x6, [sp, #(16 + 2*2*8)]
46	stp	x7, x8, [sp, #(16 + 3*2*8)]
47	stp	x9, x10, [sp, #(16 + 4*2*8)]
48	stp	x11, x12, [sp, #(16 + 5*2*8)]
49	stp	x13, x14, [sp, #(16 + 6*2*8)]
50	stp	x15, x16, [sp, #(16 + 7*2*8)]
51	stp	x17, x18, [sp, #(16 + 8*2*8)]
52	stp	x19, x20, [sp, #(16 + 9*2*8)]
53	stp	x21, x22, [sp, #(16 + 10*2*8)]
54	stp	x23, x24, [sp, #(16 + 11*2*8)]
55	stp	x25, x26, [sp, #(16 + 12*2*8)]
56	stp	x27, x28, [sp, #(16 + 13*2*8)]
57	stp	x29, x30, [sp, #(16 + 14*2*8)]
58	mrs	x0, tpidr_el0
59	str	x0, [sp, #(16 + 15*2*8)]
60
61	/* call write(STDOUT_FILENO, regs, sizeof(regs)) */
62	mov	x0, #1			/* arg0 := STDOUT_FILENO */
63	add	x1, sp, #16		/* arg1 := regs */
64	mov	x2, #(NEXECREGS*8)	/* arg2 := sizeof(regs) */
65	svc	#SYS_write
66
67	b.cs	2f			/* bail if write failed */
68	cmp	x0, #(NEXECREGS*8)	/* bail if wrote wrong # of bytes */
69	b.ne	2f
70
71	/* call exit(0) */
72	mov	x0, #0			/* arg0 := 0 */
731:	svc	#SYS_exit
74	brk	#0xffff			/* paranoia */
75
762:	/* call exit(127) */
77	mov	x0, #127		/* arg0 := 127 */
78	b	1b
79END(execregs_start)
80
81/* main stub to simplify linking */
82ENTRY(main)
83	brk	#0xffff
84END(main)
85