1 1.1 uwe /* $NetBSD: h_execregs.S,v 1.1 2025/04/27 02:24:07 uwe Exp $ */ 2 1.1 uwe 3 1.1 uwe /*- 4 1.1 uwe * Copyright (c) 2025 The NetBSD Foundation, Inc. 5 1.1 uwe * All rights reserved. 6 1.1 uwe * 7 1.1 uwe * Redistribution and use in source and binary forms, with or without 8 1.1 uwe * modification, are permitted provided that the following conditions 9 1.1 uwe * are met: 10 1.1 uwe * 1. Redistributions of source code must retain the above copyright 11 1.1 uwe * notice, this list of conditions and the following disclaimer. 12 1.1 uwe * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 uwe * notice, this list of conditions and the following disclaimer in the 14 1.1 uwe * documentation and/or other materials provided with the distribution. 15 1.1 uwe * 16 1.1 uwe * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 1.1 uwe * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 1.1 uwe * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 1.1 uwe * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 1.1 uwe * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 1.1 uwe * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 1.1 uwe * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 1.1 uwe * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 1.1 uwe * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 1.1 uwe * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 1.1 uwe * POSSIBILITY OF SUCH DAMAGE. 27 1.1 uwe */ 28 1.1 uwe 29 1.1 uwe #define _LOCORE 30 1.1 uwe #include <machine/asm.h> 31 1.1 uwe #include <machine/mcontext.h> 32 1.1 uwe #include <sys/syscall.h> 33 1.1 uwe 34 1.1 uwe 35 1.1 uwe // ELF entry point 36 1.1 uwe ENTRY(execregs_start) 37 1.1 uwe // __gregset_t r; // mcontext (but general regs only) 38 1.1 uwe mov.l sp, @-sp 39 1.1 uwe mov.l r0, @-sp 40 1.1 uwe mov.l r1, @-sp 41 1.1 uwe mov.l r2, @-sp 42 1.1 uwe mov.l r3, @-sp 43 1.1 uwe mov.l r4, @-sp 44 1.1 uwe mov.l r5, @-sp 45 1.1 uwe mov.l r6, @-sp 46 1.1 uwe mov.l r7, @-sp 47 1.1 uwe mov.l r8, @-sp 48 1.1 uwe mov.l r9, @-sp 49 1.1 uwe mov.l r10, @-sp 50 1.1 uwe mov.l r11, @-sp 51 1.1 uwe mov.l r12, @-sp 52 1.1 uwe mov.l r13, @-sp 53 1.1 uwe mov.l r14, @-sp 54 1.1 uwe sts.l pr, @-sp 55 1.1 uwe sts.l mach, @-sp 56 1.1 uwe sts.l macl, @-sp 57 1.1 uwe mov #0, r0 58 1.1 uwe mov.l r0, @-sp // _REG_SR is privileged 59 1.1 uwe mova .Lend, r0 // _REG_PC 60 1.1 uwe mov.l @r0, r1 61 1.1 uwe sub r1, r0 62 1.1 uwe mov.l r0, @-sp 63 1.1 uwe stc.l gbr, @-sp 64 1.1 uwe 65 1.1 uwe // write(STDOUT_FILENO, &r, sizeof(__gregset_t)) 66 1.1 uwe mov #1, r4 67 1.1 uwe mov sp, r5 68 1.1 uwe mov #(_NGREG * 4), r6 69 1.1 uwe mov #SYS_write, r0 70 1.1 uwe trapa #0x80 71 1.1 uwe 72 1.1 uwe // _exit(0) 73 1.1 uwe mov #0, r4 74 1.1 uwe mov #SYS_exit, r0 75 1.1 uwe trapa #0x80 76 1.1 uwe 77 1.1 uwe .p2align 2 78 1.1 uwe .Lend: .long .Lend - execregs_start 79 1.1 uwe SET_ENTRY_SIZE(execregs_start) 80 1.1 uwe 81 1.1 uwe 82 1.1 uwe // main stub to simplify linking 83 1.1 uwe ENTRY(main) 84 1.1 uwe rts 85 1.1 uwe mov #0, r0 86 1.1 uwe SET_ENTRY_SIZE(main) 87