vm_machdep.c revision 82014
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 82014 2001-08-21 00:02:54Z jake $
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
60#include <machine/cpu.h>
61#include <machine/frame.h>
62#include <machine/md_var.h>
63#include <machine/tstate.h>
64
65/* XXX: it seems that all that is in here should really be MI... */
66void
67cpu_exit(struct proc *p)
68{
69
70	PROC_LOCK(p);
71	mtx_lock_spin(&sched_lock);
72	while (mtx_owned(&Giant))
73		mtx_unlock_flags(&Giant, MTX_NOSWITCH);
74
75	/*
76	 * We have to wait until after releasing all locks before
77	 * changing p_stat.  If we block on a mutex then we will be
78	 * back at SRUN when we resume and our parent will never
79	 * harvest us.
80	 */
81	p->p_stat = SZOMB;
82
83	wakeup(p->p_pptr);
84	PROC_UNLOCK_NOSWITCH(p);
85
86	cnt.v_swtch++;
87	cpu_throw();
88	panic("cpu_exit");
89}
90
91void
92cpu_fork(struct proc *p1, struct proc *p2, int flags)
93{
94	struct trapframe *tf;
95	struct frame *fp;
96	struct pcb *pcb;
97
98	if ((flags & RFPROC) == 0)
99		return;
100
101	pcb = &p2->p_addr->u_pcb;
102	p1->p_addr->u_pcb.pcb_y = rd(y);
103	p1->p_addr->u_pcb.pcb_fpstate.fp_fprs = rd(fprs);
104	if ((p1->p_frame->tf_tstate & TSTATE_PEF) != 0) {
105		mtx_lock_spin(&sched_lock);
106		savefpctx(&p1->p_addr->u_pcb.pcb_fpstate);
107		mtx_unlock_spin(&sched_lock);
108	}
109	/* Make sure the copied windows are spilled. */
110	__asm __volatile("flushw");
111	/* Copy the pcb (this will copy the windows saved in the pcb, too). */
112	bcopy(&p1->p_addr->u_pcb, pcb, sizeof(*pcb));
113
114	tf = (struct trapframe *)((caddr_t)p2->p_addr + UPAGES * PAGE_SIZE) - 1;
115	bcopy(p1->p_frame, tf, sizeof(*tf));
116	p2->p_frame = tf;
117	fp = (struct frame *)tf - 1;
118	fp->f_local[0] = (u_long)fork_return;
119	fp->f_local[1] = (u_long)p2;
120	fp->f_local[2] = (u_long)tf;
121	pcb->pcb_fp = (u_long)fp - SPOFF;
122	pcb->pcb_pc = (u_long)fork_trampoline - 8;
123}
124
125void
126cpu_reset(void)
127{
128	OF_exit();
129}
130
131void
132cpu_set_fork_handler(struct proc *p, void (*func)(void *), void *arg)
133{
134	struct frame *fp;
135	struct pcb *pcb;
136
137	pcb = &p->p_addr->u_pcb;
138	fp = (struct frame *)(pcb->pcb_fp + SPOFF);
139	fp->f_local[0] = (u_long)func;
140	fp->f_local[1] = (u_long)arg;
141}
142
143void
144cpu_wait(struct proc *p)
145{
146	GIANT_REQUIRED;
147
148	/* drop per-process resources */
149	pmap_dispose_proc(p);
150
151	/* and clean-out the vmspace */
152	vmspace_free(p->p_vmspace);
153}
154
155void
156swi_vm(void *v)
157{
158	TODO;
159}
160
161int
162vm_fault_quick(caddr_t v, int prot)
163{
164	TODO;
165	return (0);
166}
167
168void
169vmapbuf(struct buf *bp)
170{
171	TODO;
172}
173
174void
175vunmapbuf(struct buf *bp)
176{
177	TODO;
178}
179