]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/aim/swtch.S
This commit was generated by cvs2svn to compensate for changes in r80357,
[FreeBSD/FreeBSD.git] / sys / powerpc / aim / swtch.S
1 /* $FreeBSD$ */
2 /* $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $ */
3
4 /*
5  * Copyright (C) 2001 Benno Rice
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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.
16  *
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.
27 */
28 /*
29  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
30  * Copyright (C) 1995, 1996 TooLs GmbH.
31  * All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
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.
46  *
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.
57  */
58
59 #include "assym.s"
60
61 #include <sys/syscall.h>
62
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>
68
69 /*
70  * Some instructions gas doesn't understand (yet?)
71  */
72 #define bdneq   bdnzf 2,
73
74 /*
75  * No processes are runnable, so loop waiting for one.
76  * Separate label here for accounting purposes.
77  */
78 #if 0 /* XXX: I think this is now unneeded.  Leaving it in just in case. */
79 ASENTRY(Idle)
80         mfmsr   3
81         andi.   3,3,~PSL_EE@l           /* disable interrupts while
82                                            manipulating runque */
83         mtmsr   3
84
85         lis     8,sched_whichqs@ha
86         lwz     9,sched_whichqs@l(8)
87
88         or.     9,9,9
89         bne-    .Lsw1                   /* at least one queue non-empty */
90         
91         ori     3,3,PSL_EE@l            /* reenable ints again */
92         mtmsr   3
93         isync
94
95 /* Check if we can use power saving mode */
96         lis     8,powersave@ha
97         lwz     9,powersave@l(8)
98
99         or.     9,9,9
100         beq     1f
101
102         sync
103         oris    3,3,PSL_POW@h           /* enter power saving mode */
104         mtmsr   3
105         isync
106 1:
107         b       _ASM_LABEL(Idle)
108 #endif /* XXX */
109
110 /*
111  * switchexit gets called from cpu_exit to complete the exit procedure.
112  */
113 ENTRY(switchexit)
114 /* First switch to the idle pcb/kernel stack */
115 #if 0 /* XXX */
116         lis     6,idle_u@ha
117         lwz     6,idle_u@l(6)
118         mfsprg  7,0
119         stw     6,GD_CURPCB(7)
120 #endif
121         addi    1,6,USPACE-16           /* 16 bytes are reserved at stack top */
122         /*
123          * Schedule the vmspace and stack to be freed (the proc arg is
124          * already in r3).
125          */
126         bl      sys_exit
127
128 /* Fall through to cpu_switch to actually select another proc */
129         li      3,0                     /* indicate exited process */
130
131 /*
132  * void cpu_switch(struct proc *p)
133  * Find a runnable process and switch to it.
134  */
135 /* XXX noprofile?  --thorpej@netbsd.org */
136 ENTRY(cpu_switch)
137         mflr    0                       /* save lr */
138         stw     0,4(1)
139         stwu    1,-16(1)
140         stw     31,12(1)
141         stw     30,8(1)
142
143         mr      30,3
144         mfsprg  3,0
145         xor     31,31,31
146         stw     31,GD_CURPROC(3)        /* Zero to not accumulate cpu time */
147         mfsprg  3,0
148         lwz     31,GD_CURPCB(3)
149
150         xor     3,3,3
151 #if 0 /* XXX */
152         bl      lcsplx
153 #endif
154         stw     3,PCB_SPL(31)           /* save spl */
155
156 /* Find a new process */
157         bl      chooseproc
158
159 1:
160         /* just did this resched thing */
161         xor     3,3,3
162         lis     4,want_resched@ha
163         stw     3,want_resched@l(4)
164
165         /* record new process */
166         mfsprg  4,0
167         stw     3,GD_CURPROC(4)
168
169         cmpl    0,31,30                 /* is it the same process? */
170         beq     switch_return
171
172         or.     30,30,30                /* old process was exiting? */
173         beq     switch_exited
174
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 */
179         stmw    10,8(1)
180         lwz     3,P_ADDR(30)
181         stw     1,PCB_SP(3)             /* save SP */
182
183 switch_exited:
184         mfmsr   3
185         andi.   3,3,~PSL_EE@l           /* disable interrupts while
186                                            actually switching */
187         mtmsr   3
188
189         /* indicate new pcb */
190         lwz     4,P_ADDR(31)
191         mfsprg  5,0
192         stw     4,GD_CURPCB(5)
193
194 #if 0 /* XXX */
195         /* save real pmap pointer for spill fill */
196         lwz     5,PCB_PMR(4)
197         lis     6,curpm@ha
198         stwu    5,curpm@l(6)
199         stwcx.  5,0,6                   /* clear possible reservation */
200 #endif
201
202         addic.  5,5,64
203         li      6,0
204         mfsr    8,KERNEL_SR             /* save kernel SR */
205 1:
206         addis   6,6,-0x10000000@ha      /* set new procs segment registers */
207         or.     6,6,6                   /* This is done from the real
208                                            address pmap */
209         lwzu    7,-4(5)                 /* so we don't have to worry */
210         mtsrin  7,6                     /* about accessibility */
211         bne     1b
212         mtsr    KERNEL_SR,8             /* restore kernel SR */
213         isync
214
215         lwz     1,PCB_SP(4)             /* get new procs SP */
216
217         ori     3,3,PSL_EE@l            /* interrupts are okay again */
218         mtmsr   3
219
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 */
224         isync
225         mtsr    USER_SR,10              /* get saved USER_SR */
226         isync
227
228 switch_return:
229         mr      30,7                    /* save proc pointer */
230         lwz     3,PCB_SPL(4)
231 #if 0 /* XXX */
232         bl      lcsplx
233 #endif
234
235         mr      3,30                    /* get curproc for special fork
236                                            returns */
237
238         lwz     31,12(1)
239         lwz     30,8(1)
240         addi    1,1,16
241         lwz     0,4(1)
242         mtlr    0
243         blr
244
245 /*
246  * Fake savectx for the time being.
247  */
248 ENTRY(savectx)
249         blr