vm_machdep.c revision 86147
1/*-
2 * Copyright (c) 1982, 1986 The Regents of the University of California.
3 * Copyright (c) 1989, 1990 William Jolitz
4 * Copyright (c) 1994 John Dyson
5 * Copyright (c) 2001 Jake Burkholder.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department, and William Jolitz.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 *    must display the following acknowledgement:
22 *	This product includes software developed by the University of
23 *	California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 *    may be used to endorse or promote products derived from this software
26 *    without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 *	from: @(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
41 *	Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
42 * 	from: FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.167 2001/07/12
43 * $FreeBSD: head/sys/sparc64/sparc64/vm_machdep.c 86147 2001-11-06 20:22:18Z tmm $
44 */
45
46#include <sys/param.h>
47#include <sys/systm.h>
48#include <sys/proc.h>
49#include <sys/bio.h>
50#include <sys/buf.h>
51#include <sys/unistd.h>
52#include <sys/user.h>
53#include <sys/vmmeter.h>
54
55#include <dev/ofw/openfirm.h>
56
57#include <vm/vm.h>
58#include <vm/vm_extern.h>
59#include <vm/pmap.h>
60
61#include <machine/cpu.h>
62#include <machine/frame.h>
63#include <machine/md_var.h>
64#include <machine/ofw_machdep.h>
65#include <machine/tstate.h>
66
67void
68cpu_exit(struct thread *td)
69{
70}
71
72/*
73 * Finish a fork operation, with process p2 nearly set up.
74 * Copy and update the pcb, set up the stack so that the child
75 * ready to run and return to user mode.
76 */
77void
78cpu_fork(struct thread *td1, struct proc *p2, int flags)
79{
80	struct thread *td2;
81	struct trapframe *tf;
82	struct frame *fp;
83	struct pcb *pcb;
84
85	KASSERT(td1 == curthread || td1 == thread0,
86	    ("cpu_fork: p1 not curproc and not proc0"));
87
88	if ((flags & RFPROC) == 0)
89		return;
90
91	td2 = &p2->p_thread;
92	/* The pcb must be aligned on a 64-byte boundary. */
93	pcb = (struct pcb *)((td2->td_kstack + KSTACK_PAGES * PAGE_SIZE -
94	    sizeof(struct pcb)) & ~0x3fUL);
95	td2->td_pcb = pcb;
96
97	/*
98	 * Ensure that p1's pcb is up to date.
99	 */
100	td1->td_pcb->pcb_y = rd(y);
101	td1->td_pcb->pcb_fpstate.fp_fprs = rd(fprs);
102	if ((td1->td_frame->tf_tstate & TSTATE_PEF) != 0) {
103		mtx_lock_spin(&sched_lock);
104		savefpctx(&td1->td_pcb->pcb_fpstate);
105		mtx_unlock_spin(&sched_lock);
106	}
107	/* Make sure the copied windows are spilled. */
108	__asm __volatile("flushw");
109	/* Copy the pcb (this will copy the windows saved in the pcb, too). */
110	bcopy(td1->td_pcb, pcb, sizeof(*pcb));
111	pcb->pcb_cwp = 2;
112
113	/*
114	 * Create a new fresh stack for the new process.
115	 * Copy the trap frame for the return to user mode as if from a
116	 * syscall.  This copies most of the user mode register values.
117	 */
118	tf = (struct trapframe *)pcb - 1;
119	bcopy(td1->td_frame, tf, sizeof(*tf));
120
121	tf->tf_out[0] = 0;			/* Child returns zero */
122	tf->tf_out[1] = 1;			/* XXX i386 returns 1 in %edx */
123	tf->tf_tstate &= ~(TSTATE_XCC_C | TSTATE_CWP_MASK);	/* success */
124
125	td2->td_frame = tf;
126	fp = (struct frame *)tf - 1;
127	fp->f_local[0] = (u_long)fork_return;
128	fp->f_local[1] = (u_long)td2;
129	fp->f_local[2] = (u_long)tf;
130	pcb->pcb_cwp = 0;
131	pcb->pcb_fp = (u_long)fp - SPOFF;
132	pcb->pcb_pc = (u_long)fork_trampoline - 8;
133
134	/*
135	 * Now, cpu_switch() can schedule the new process.
136	 */
137}
138
139void
140cpu_reset(void)
141{
142	static char bspec[64] = "";
143	phandle_t chosen;
144	static struct {
145		cell_t	name;
146		cell_t	nargs;
147		cell_t	nreturns;
148		cell_t	bootspec;
149	} args = {
150		(cell_t)"boot",
151		1,
152		0,
153		(cell_t)bspec
154	};
155	if ((chosen = OF_finddevice("/chosen")) != 0) {
156		if (OF_getprop(chosen, "bootpath", bspec, sizeof(bspec)) == -1)
157			bspec[0] = '\0';
158		bspec[sizeof(bspec) - 1] = '\0';
159	}
160
161	openfirmware_exit(&args);
162}
163
164/*
165 * Intercept the return address from a freshly forked process that has NOT
166 * been scheduled yet.
167 *
168 * This is needed to make kernel threads stay in kernel mode.
169 */
170void
171cpu_set_fork_handler(struct thread *td, void (*func)(void *), void *arg)
172{
173	struct frame *fp;
174	struct pcb *pcb;
175
176	pcb = td->td_pcb;
177	fp = (struct frame *)(pcb->pcb_fp + SPOFF);
178	fp->f_local[0] = (u_long)func;
179	fp->f_local[1] = (u_long)arg;
180}
181
182void
183cpu_wait(struct proc *p)
184{
185}
186
187int
188is_physical_memory(vm_offset_t addr)
189{
190
191	TODO;
192}
193
194void
195swi_vm(void *v)
196{
197	TODO;
198}
199
200int
201vm_fault_quick(caddr_t v, int prot)
202{
203	TODO;
204	return (0);
205}
206
207void
208vmapbuf(struct buf *bp)
209{
210	TODO;
211}
212
213void
214vunmapbuf(struct buf *bp)
215{
216	TODO;
217}
218