1 1.2 riastrad /* $NetBSD: h_execregs.S,v 1.2 2025/02/28 16:08:19 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /*- 4 1.1 riastrad * Copyright (c) 2025 The NetBSD Foundation, Inc. 5 1.1 riastrad * All rights reserved. 6 1.1 riastrad * 7 1.1 riastrad * Redistribution and use in source and binary forms, with or without 8 1.1 riastrad * modification, are permitted provided that the following conditions 9 1.1 riastrad * are met: 10 1.1 riastrad * 1. Redistributions of source code must retain the above copyright 11 1.1 riastrad * notice, this list of conditions and the following disclaimer. 12 1.1 riastrad * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 riastrad * notice, this list of conditions and the following disclaimer in the 14 1.1 riastrad * documentation and/or other materials provided with the distribution. 15 1.1 riastrad * 16 1.1 riastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 1.1 riastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 1.1 riastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 1.1 riastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 1.1 riastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 1.1 riastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 1.1 riastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 1.1 riastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 1.1 riastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 1.1 riastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 1.1 riastrad * POSSIBILITY OF SUCH DAMAGE. 27 1.1 riastrad */ 28 1.1 riastrad 29 1.1 riastrad #define _LOCORE 30 1.1 riastrad 31 1.1 riastrad #include <sys/syscall.h> 32 1.1 riastrad 33 1.1 riastrad #include <machine/asm.h> 34 1.1 riastrad #include <machine/vmparam.h> 35 1.1 riastrad 36 1.1 riastrad #include "execregs.h" 37 1.1 riastrad 38 1.1 riastrad _ENTRY(execregs_start) 39 1.1 riastrad .callinfo frame=(NEXECREGS*4), calls 40 1.1 riastrad .entry 41 1.1 riastrad 42 1.1 riastrad ldo (NEXECREGS*4)(%sp), %sp /* space for NEXECREGS */ 43 1.1 riastrad stw %t1, (4*(0 - NEXECREGS))(%sp) /* order matches execregs.h */ 44 1.1 riastrad stw %t2, (4*(1 - NEXECREGS))(%sp) 45 1.1 riastrad /* sp: stack pointer */ 46 1.1 riastrad stw %t3, (4*(2 - NEXECREGS))(%sp) 47 1.1 riastrad /* cr17/iisq_head: privileged */ 48 1.1 riastrad /* cr17/iisq_tail: privileged */ 49 1.1 riastrad /* cr18/iioq_head: privileged */ 50 1.1 riastrad /* cr18/iioq_tail: privileged */ 51 1.1 riastrad /* cr15/eiem: privileged */ 52 1.1 riastrad /* cr22/ipsw: privileged */ 53 1.1 riastrad /* sr3: privileged(?) */ 54 1.1 riastrad /* cr8/pidr1: privileged */ 55 1.1 riastrad /* cr20/isr: privileged */ 56 1.1 riastrad /* cr21/ior: privileged */ 57 1.1 riastrad /* cr19/iir: privileged */ 58 1.1 riastrad /* flags: N/A(?) */ 59 1.1 riastrad stw %sar, (4*(3 - NEXECREGS))(%sp) 60 1.1 riastrad stw %r1, (4*(4 - NEXECREGS))(%sp) 61 1.1 riastrad stw %rp, (4*(5 - NEXECREGS))(%sp) 62 1.1 riastrad /* r3: frame pointer (set to initial stack pointer) */ 63 1.1 riastrad stw %r4, (4*(6 - NEXECREGS))(%sp) 64 1.1 riastrad stw %r5, (4*(7 - NEXECREGS))(%sp) 65 1.1 riastrad stw %r6, (4*(8 - NEXECREGS))(%sp) 66 1.1 riastrad stw %r7, (4*(9 - NEXECREGS))(%sp) 67 1.1 riastrad stw %r8, (4*(10 - NEXECREGS))(%sp) 68 1.1 riastrad stw %r9, (4*(11 - NEXECREGS))(%sp) 69 1.1 riastrad stw %r10, (4*(12 - NEXECREGS))(%sp) 70 1.1 riastrad stw %r11, (4*(13 - NEXECREGS))(%sp) 71 1.1 riastrad stw %r12, (4*(14 - NEXECREGS))(%sp) 72 1.1 riastrad stw %r13, (4*(15 - NEXECREGS))(%sp) 73 1.1 riastrad stw %r14, (4*(16 - NEXECREGS))(%sp) 74 1.1 riastrad stw %r15, (4*(17 - NEXECREGS))(%sp) 75 1.1 riastrad stw %r16, (4*(18 - NEXECREGS))(%sp) 76 1.1 riastrad stw %r17, (4*(19 - NEXECREGS))(%sp) 77 1.1 riastrad stw %r18, (4*(20 - NEXECREGS))(%sp) 78 1.1 riastrad stw %t4, (4*(21 - NEXECREGS))(%sp) 79 1.1 riastrad stw %arg3, (4*(22 - NEXECREGS))(%sp) 80 1.1 riastrad stw %arg2, (4*(23 - NEXECREGS))(%sp) 81 1.1 riastrad stw %arg1, (4*(24 - NEXECREGS))(%sp) 82 1.1 riastrad /* arg0: ps_strings */ 83 1.1 riastrad stw %dp, (4*(25 - NEXECREGS))(%sp) 84 1.1 riastrad stw %ret0, (4*(26 - NEXECREGS))(%sp) 85 1.1 riastrad stw %ret1, (4*(27 - NEXECREGS))(%sp) 86 1.1 riastrad stw %r31, (4*(28 - NEXECREGS))(%sp) 87 1.1 riastrad /* sr0-sr7: space registers initialized by kernel */ 88 1.1 riastrad /* cr9/pidr2: privileged */ 89 1.1 riastrad /* cr12/pidr3: privileged */ 90 1.1 riastrad /* cr13/pidr4: privileged */ 91 1.1 riastrad /* cr0/rctr: privileged */ 92 1.1 riastrad /* cr10/ccr: privileged */ 93 1.1 riastrad /* cr23/eirr: privileged */ 94 1.1 riastrad /* cr24: privileged */ 95 1.1 riastrad /* cr25/vtop: privileged */ 96 1.1 riastrad /* cr26: ??? */ 97 1.1 riastrad stw %cr27, (4*(29 - NEXECREGS))(%sp) 98 1.1 riastrad stw %cr28, (4*(30 - NEXECREGS))(%sp) 99 1.1 riastrad /* cr30/fpregs: privileged */ 100 1.1 riastrad /* cr31: privileged */ 101 1.1 riastrad 102 1.2 riastrad addc %t1, %r0, %r0 /* t1 := PSW[C/B]{0} */ 103 1.2 riastrad zdep %t1, 23, 8, %t1 /* t1 := PSW */ 104 1.2 riastrad stw %t1, (4*(31 - NEXECREGS))(%sp) 105 1.2 riastrad 106 1.2 riastrad /* store the fp registers */ 107 1.2 riastrad ldo (4*(32 - NEXECREGS))(%sp), %t1 108 1.2 riastrad fstd,ma %fr0, 8(%t1) 109 1.2 riastrad fstd,ma %fr1, 8(%t1) 110 1.2 riastrad fstd,ma %fr2, 8(%t1) 111 1.2 riastrad fstd,ma %fr3, 8(%t1) 112 1.2 riastrad fstd,ma %fr4, 8(%t1) 113 1.2 riastrad fstd,ma %fr5, 8(%t1) 114 1.2 riastrad fstd,ma %fr6, 8(%t1) 115 1.2 riastrad fstd,ma %fr7, 8(%t1) 116 1.2 riastrad fstd,ma %fr8, 8(%t1) 117 1.2 riastrad fstd,ma %fr9, 8(%t1) 118 1.2 riastrad fstd,ma %fr10, 8(%t1) 119 1.2 riastrad fstd,ma %fr11, 8(%t1) 120 1.2 riastrad fstd,ma %fr12, 8(%t1) 121 1.2 riastrad fstd,ma %fr13, 8(%t1) 122 1.2 riastrad fstd,ma %fr14, 8(%t1) 123 1.2 riastrad fstd,ma %fr15, 8(%t1) 124 1.2 riastrad fstd,ma %fr16, 8(%t1) 125 1.2 riastrad fstd,ma %fr17, 8(%t1) 126 1.2 riastrad fstd,ma %fr18, 8(%t1) 127 1.2 riastrad fstd,ma %fr19, 8(%t1) 128 1.2 riastrad fstd,ma %fr20, 8(%t1) 129 1.2 riastrad fstd,ma %fr21, 8(%t1) 130 1.2 riastrad fstd,ma %fr22, 8(%t1) 131 1.2 riastrad fstd,ma %fr23, 8(%t1) 132 1.2 riastrad fstd,ma %fr24, 8(%t1) 133 1.2 riastrad fstd,ma %fr25, 8(%t1) 134 1.2 riastrad fstd,ma %fr26, 8(%t1) 135 1.2 riastrad fstd,ma %fr27, 8(%t1) 136 1.2 riastrad fstd,ma %fr28, 8(%t1) 137 1.2 riastrad fstd,ma %fr29, 8(%t1) 138 1.2 riastrad fstd,ma %fr30, 8(%t1) 139 1.2 riastrad fstd %fr31, 0(%t1) 140 1.2 riastrad 141 1.1 riastrad /* call write(STDOUT_FILENO, regs, sizeof(regs)) */ 142 1.1 riastrad ldi 1, %arg0 /* arg0 := STDOUT_FILENO */ 143 1.1 riastrad ldo -(4*NEXECREGS)(%sp), %arg1 /* arg1 := regs */ 144 1.1 riastrad ldi (4*NEXECREGS), %arg2 /* arg2 := sizeof(regs) */ 145 1.1 riastrad ldil L%SYSCALLGATE, %r1 146 1.1 riastrad ble 4(%sr2, %r1) 147 1.1 riastrad ldi SYS_write, %t1 148 1.1 riastrad 149 1.1 riastrad comb,<>,n %r0, %t1, 2f /* bail if write failed */ 150 1.1 riastrad ldi (4*NEXECREGS), %t1 /* bail if wrong # bytes */ 151 1.1 riastrad comb,<>,n %ret0, %t1, 2f 152 1.1 riastrad 153 1.1 riastrad /* call exit(0) */ 154 1.1 riastrad ldi 0, %arg0 155 1.1 riastrad 1: ldil L%SYSCALLGATE, %r1 156 1.1 riastrad ble 4(%sr2, %r1) 157 1.1 riastrad ldi SYS_exit, %t1 158 1.1 riastrad break 0, 0 /* paranoia */ 159 1.1 riastrad 160 1.1 riastrad 2: /* call exit(127) */ 161 1.1 riastrad b 1b 162 1.1 riastrad ldi 127, %arg0 163 1.1 riastrad EXIT(execregs_start) 164 1.1 riastrad 165 1.1 riastrad /* main stub to simplify linking */ 166 1.1 riastrad LEAF_ENTRY(main) 167 1.1 riastrad break 0, 0 /* paranoia */ 168 1.1 riastrad EXIT(main) 169