1 /* $OpenBSD: arm_machdep.c,v 1.7 2022/10/30 17:43:39 guenther Exp $ */
2 /* $NetBSD: arm_machdep.c,v 1.7 2003/10/25 19:44:42 scw Exp $ */
3
4 /*
5 * Copyright (c) 2001 Wasabi Systems, Inc.
6 * All rights reserved.
7 *
8 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by
21 * Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
24 * written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1994-1998 Mark Brinicombe.
41 * Copyright (c) 1994 Brini.
42 * All rights reserved.
43 *
44 * This code is derived from software written for Brini by Mark Brinicombe
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by Mark Brinicombe
57 * for the NetBSD Project.
58 * 4. The name of the company nor the name of the author may be used to
59 * endorse or promote products derived from this software without specific
60 * prior written permission.
61 *
62 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
63 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
64 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
65 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
66 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
67 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
68 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE.
73 */
74
75 #include <sys/param.h>
76
77 #include <sys/exec.h>
78 #include <sys/proc.h>
79 #include <sys/systm.h>
80 #include <sys/user.h>
81
82 #include <arm/vfp.h>
83
84 /*
85 * The ARM architecture places the vector page at address 0.
86 * Later ARM architecture versions, however, allow it to be
87 * relocated to a high address (0xffff0000). This is primarily
88 * to support the Fast Context Switch Extension.
89 *
90 * This variable contains the address of the vector page. It
91 * defaults to 0; it only needs to be initialized if we enable
92 * relocated vectors.
93 */
94 vaddr_t vector_page;
95
96 /*
97 * Clear registers on exec
98 */
99
100 void
setregs(struct proc * p,struct exec_package * pack,u_long stack,struct ps_strings * arginfo)101 setregs(struct proc *p, struct exec_package *pack, u_long stack,
102 struct ps_strings *arginfo)
103 {
104 struct trapframe *tf;
105
106 /* If we were using the FPU, forget about it. */
107 if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
108 vfp_discard(p);
109 p->p_addr->u_pcb.pcb_flags &= ~PCB_FPU;
110
111 tf = p->p_addr->u_pcb.pcb_tf;
112
113 memset(tf, 0, sizeof *tf);
114 /* tf->tf_r0 = (u_int)p->p_proc->p_psstr; */
115 tf->tf_usr_sp = stack;
116 tf->tf_usr_lr = pack->ep_entry;
117 tf->tf_svc_lr = 0x77777777; /* Something we can see */
118 tf->tf_pc = pack->ep_entry;
119 tf->tf_spsr = PSR_USR32_MODE;
120 }
121