11.2Sriastrad/* $NetBSD: h_execregs.S,v 1.2 2025/04/25 12:58:40 riastradh Exp $ */ 21.1Sriastrad 31.1Sriastrad/*- 41.1Sriastrad * Copyright (c) 2025 The NetBSD Foundation, Inc. 51.1Sriastrad * All rights reserved. 61.1Sriastrad * 71.1Sriastrad * Redistribution and use in source and binary forms, with or without 81.1Sriastrad * modification, are permitted provided that the following conditions 91.1Sriastrad * are met: 101.1Sriastrad * 1. Redistributions of source code must retain the above copyright 111.1Sriastrad * notice, this list of conditions and the following disclaimer. 121.1Sriastrad * 2. Redistributions in binary form must reproduce the above copyright 131.1Sriastrad * notice, this list of conditions and the following disclaimer in the 141.1Sriastrad * documentation and/or other materials provided with the distribution. 151.1Sriastrad * 161.1Sriastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171.1Sriastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181.1Sriastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191.1Sriastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201.1Sriastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211.1Sriastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221.1Sriastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231.1Sriastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241.1Sriastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251.1Sriastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261.1Sriastrad * POSSIBILITY OF SUCH DAMAGE. 271.1Sriastrad */ 281.1Sriastrad 291.1Sriastrad#define _LOCORE 301.1Sriastrad 311.1Sriastrad#include <sys/syscall.h> 321.1Sriastrad 331.1Sriastrad#include <machine/asm.h> 341.1Sriastrad 351.1Sriastrad#include "execregs.h" 361.1Sriastrad 371.1SriastradENTRY(execregs_start) 381.2Sriastrad /* create a stack frame with NEXECREGS*8 bytes, aligned to 16-byte */ 391.2Sriastrad stp fp, lr, [sp, #-(16 + ((NEXECREGS*8 + 15)/16)*16)]! 401.1Sriastrad 411.1Sriastrad /* store registers to buffer on stack */ 421.1Sriastrad stp x0, x1, [sp, #16] /* order matches execregs.h */ 431.1Sriastrad /* x2: ps_strings */ 441.1Sriastrad stp x3, x4, [sp, #(16 + 1*2*8)] 451.1Sriastrad stp x5, x6, [sp, #(16 + 2*2*8)] 461.1Sriastrad stp x7, x8, [sp, #(16 + 3*2*8)] 471.1Sriastrad stp x9, x10, [sp, #(16 + 4*2*8)] 481.1Sriastrad stp x11, x12, [sp, #(16 + 5*2*8)] 491.1Sriastrad stp x13, x14, [sp, #(16 + 6*2*8)] 501.1Sriastrad stp x15, x16, [sp, #(16 + 7*2*8)] 511.1Sriastrad stp x17, x18, [sp, #(16 + 8*2*8)] 521.1Sriastrad stp x19, x20, [sp, #(16 + 9*2*8)] 531.1Sriastrad stp x21, x22, [sp, #(16 + 10*2*8)] 541.1Sriastrad stp x23, x24, [sp, #(16 + 11*2*8)] 551.1Sriastrad stp x25, x26, [sp, #(16 + 12*2*8)] 561.1Sriastrad stp x27, x28, [sp, #(16 + 13*2*8)] 571.1Sriastrad stp x29, x30, [sp, #(16 + 14*2*8)] 581.1Sriastrad mrs x0, tpidr_el0 591.1Sriastrad str x0, [sp, #(16 + 15*2*8)] 601.1Sriastrad 611.1Sriastrad /* call write(STDOUT_FILENO, regs, sizeof(regs)) */ 621.1Sriastrad mov x0, #1 /* arg0 := STDOUT_FILENO */ 631.1Sriastrad add x1, sp, #16 /* arg1 := regs */ 641.1Sriastrad mov x2, #(NEXECREGS*8) /* arg2 := sizeof(regs) */ 651.1Sriastrad svc #SYS_write 661.1Sriastrad 671.1Sriastrad b.cs 2f /* bail if write failed */ 681.1Sriastrad cmp x0, #(NEXECREGS*8) /* bail if wrote wrong # of bytes */ 691.1Sriastrad b.ne 2f 701.1Sriastrad 711.1Sriastrad /* call exit(0) */ 721.1Sriastrad mov x0, #0 /* arg0 := 0 */ 731.1Sriastrad1: svc #SYS_exit 741.1Sriastrad brk #0xffff /* paranoia */ 751.1Sriastrad 761.1Sriastrad2: /* call exit(127) */ 771.1Sriastrad mov x0, #127 /* arg0 := 127 */ 781.1Sriastrad b 1b 791.1SriastradEND(execregs_start) 801.1Sriastrad 811.1Sriastrad/* main stub to simplify linking */ 821.1SriastradENTRY(main) 831.1Sriastrad brk #0xffff 841.1SriastradEND(main) 85