h_execregs.S revision 1.1 1 1.1 riastrad /* $NetBSD: h_execregs.S,v 1.1 2025/02/27 00:55:32 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.1 riastrad /* call write(STDOUT_FILENO, regs, sizeof(regs)) */
103 1.1 riastrad ldi 1, %arg0 /* arg0 := STDOUT_FILENO */
104 1.1 riastrad ldo -(4*NEXECREGS)(%sp), %arg1 /* arg1 := regs */
105 1.1 riastrad ldi (4*NEXECREGS), %arg2 /* arg2 := sizeof(regs) */
106 1.1 riastrad ldil L%SYSCALLGATE, %r1
107 1.1 riastrad ble 4(%sr2, %r1)
108 1.1 riastrad ldi SYS_write, %t1
109 1.1 riastrad
110 1.1 riastrad comb,<>,n %r0, %t1, 2f /* bail if write failed */
111 1.1 riastrad ldi (4*NEXECREGS), %t1 /* bail if wrong # bytes */
112 1.1 riastrad comb,<>,n %ret0, %t1, 2f
113 1.1 riastrad
114 1.1 riastrad /* call exit(0) */
115 1.1 riastrad ldi 0, %arg0
116 1.1 riastrad 1: ldil L%SYSCALLGATE, %r1
117 1.1 riastrad ble 4(%sr2, %r1)
118 1.1 riastrad ldi SYS_exit, %t1
119 1.1 riastrad break 0, 0 /* paranoia */
120 1.1 riastrad
121 1.1 riastrad 2: /* call exit(127) */
122 1.1 riastrad b 1b
123 1.1 riastrad ldi 127, %arg0
124 1.1 riastrad EXIT(execregs_start)
125 1.1 riastrad
126 1.1 riastrad /* main stub to simplify linking */
127 1.1 riastrad LEAF_ENTRY(main)
128 1.1 riastrad break 0, 0 /* paranoia */
129 1.1 riastrad EXIT(main)
130