2 /* $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $ */
5 * Copyright (C) 2001 Benno Rice
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
30 * Copyright (C) 1995, 1996 TooLs GmbH.
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by TooLs GmbH.
44 * 4. The name of TooLs GmbH may not be used to endorse or promote products
45 * derived from this software without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
52 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
53 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
54 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
55 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
56 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 #include <sys/syscall.h>
63 #include <machine/trap.h>
64 #include <machine/param.h>
65 #include <machine/pmap.h>
66 #include <machine/psl.h>
67 #include <machine/asm.h>
70 * Some instructions gas doesn't understand (yet?)
72 #define bdneq bdnzf 2,
75 * No processes are runnable, so loop waiting for one.
76 * Separate label here for accounting purposes.
78 #if 0 /* XXX: I think this is now unneeded. Leaving it in just in case. */
81 andi. 3,3,~PSL_EE@l /* disable interrupts while
82 manipulating runque */
85 lis 8,sched_whichqs@ha
86 lwz 9,sched_whichqs@l(8)
89 bne- .Lsw1 /* at least one queue non-empty */
91 ori 3,3,PSL_EE@l /* reenable ints again */
95 /* Check if we can use power saving mode */
103 oris 3,3,PSL_POW@h /* enter power saving mode */
111 * switchexit gets called from cpu_exit to complete the exit procedure.
114 /* First switch to the idle pcb/kernel stack */
121 addi 1,6,USPACE-16 /* 16 bytes are reserved at stack top */
123 * Schedule the vmspace and stack to be freed (the proc arg is
128 /* Fall through to cpu_switch to actually select another proc */
129 li 3,0 /* indicate exited process */
132 * void cpu_switch(struct proc *p)
133 * Find a runnable process and switch to it.
135 /* XXX noprofile? --thorpej@netbsd.org */
146 stw 31,GD_CURPROC(3) /* Zero to not accumulate cpu time */
154 stw 3,PCB_SPL(31) /* save spl */
156 /* Find a new process */
160 /* just did this resched thing */
162 lis 4,want_resched@ha
163 stw 3,want_resched@l(4)
165 /* record new process */
169 cmpl 0,31,30 /* is it the same process? */
172 or. 30,30,30 /* old process was exiting? */
175 mfsr 10,USER_SR /* save USER_SR for copyin/copyout */
176 mfcr 11 /* save cr */
177 mr 12,2 /* save r2 */
178 stwu 1,-SFRAMELEN(1) /* still running on old stack */
181 stw 1,PCB_SP(3) /* save SP */
185 andi. 3,3,~PSL_EE@l /* disable interrupts while
186 actually switching */
189 /* indicate new pcb */
195 /* save real pmap pointer for spill fill */
199 stwcx. 5,0,6 /* clear possible reservation */
204 mfsr 8,KERNEL_SR /* save kernel SR */
206 addis 6,6,-0x10000000@ha /* set new procs segment registers */
207 or. 6,6,6 /* This is done from the real
209 lwzu 7,-4(5) /* so we don't have to worry */
210 mtsrin 7,6 /* about accessibility */
212 mtsr KERNEL_SR,8 /* restore kernel SR */
215 lwz 1,PCB_SP(4) /* get new procs SP */
217 ori 3,3,PSL_EE@l /* interrupts are okay again */
220 lmw 10,8(1) /* get other regs */
221 lwz 1,0(1) /* get saved SP */
222 mr 2,12 /* get saved r2 */
223 mtcr 11 /* get saved cr */
225 mtsr USER_SR,10 /* get saved USER_SR */
229 mr 30,7 /* save proc pointer */
235 mr 3,30 /* get curproc for special fork
246 * Fake savectx for the time being.