xref: /netbsd-src/sys/arch/m68k/m68k/m68k_machdep.c (revision 4aa16837d6c5a854ea7598ac4deb33c3d4a4f074)
1 /*	$NetBSD: m68k_machdep.c,v 1.11 2023/09/26 12:46:30 tsutsui Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * Copyright (c) 1988 University of Utah.
31  * Copyright (c) 1982, 1986, 1990, 1993
32  *	The Regents of the University of California.  All rights reserved.
33  *
34  * This code is derived from software contributed to Berkeley by
35  * the Systems Programming Group of the University of Utah Computer
36  * Science Department.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. Neither the name of the University nor the names of its contributors
47  *    may be used to endorse or promote products derived from this software
48  *    without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60  * SUCH DAMAGE.
61  *
62  * from: Utah $Hdr: machdep.c 1.74 92/12/20$
63  *
64  *	@(#)machdep.c	8.10 (Berkeley) 4/20/94
65  */
66 
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: m68k_machdep.c,v 1.11 2023/09/26 12:46:30 tsutsui Exp $");
69 
70 #include "opt_compat_sunos.h"
71 
72 #include <sys/param.h>
73 #include <sys/exec.h>
74 #include <sys/lwp.h>
75 #include <sys/proc.h>
76 
77 #include <m68k/m68k.h>
78 #include <m68k/frame.h>
79 #include <m68k/pcb.h>
80 #include <m68k/reg.h>
81 
82 /* the following is used externally (sysctl_hw) */
83 char	machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
84 
85 extern short exframesize[];
86 
87 /*
88  * Set registers on exec.
89  */
90 void
setregs(struct lwp * l,struct exec_package * pack,vaddr_t stack)91 setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)
92 {
93 	struct trapframe *tf = (struct trapframe *)l->l_md.md_regs;
94 	struct pcb *pcb = lwp_getpcb(l);
95 
96 	tf->tf_sr = PSL_USERSET;
97 	tf->tf_pc = pack->ep_entry & ~1;
98 	tf->tf_regs[D0] = 0;
99 	tf->tf_regs[D1] = 0;
100 	tf->tf_regs[D2] = 0;
101 	tf->tf_regs[D3] = 0;
102 	tf->tf_regs[D4] = 0;
103 	tf->tf_regs[D5] = 0;
104 	tf->tf_regs[D6] = 0;
105 	tf->tf_regs[D7] = 0;
106 	tf->tf_regs[A0] = 0;
107 	tf->tf_regs[A1] = 0;
108 	tf->tf_regs[A2] = l->l_proc->p_psstrp;
109 	tf->tf_regs[A3] = 0;
110 	tf->tf_regs[A4] = 0;
111 	tf->tf_regs[A5] = 0;
112 	tf->tf_regs[A6] = 0;
113 	tf->tf_regs[SP] = stack;
114 
115 	/* restore a null state frame */
116 	pcb->pcb_fpregs.fpf_null = 0;
117 #if !defined(__mc68010__)
118 	if (fputype)
119 		m68881_restore(&pcb->pcb_fpregs);
120 #endif
121 
122 #ifdef COMPAT_SUNOS
123 	/* see m68k/sunos_syscall.c */
124 	l->l_md.md_flags = 0;
125 #endif
126 }
127