]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/powerpc/booke/swtch.S
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / powerpc / booke / swtch.S
1 /*-
2  * Copyright (C) 2001 Benno Rice
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *      from: $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $
26  *      from: $FreeBSD$
27  *
28  * $FreeBSD$
29  */
30 /*-
31  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
32  * Copyright (C) 1995, 1996 TooLs GmbH.
33  * All rights reserved.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  * 1. Redistributions of source code must retain the above copyright
39  *    notice, this list of conditions and the following disclaimer.
40  * 2. Redistributions in binary form must reproduce the above copyright
41  *    notice, this list of conditions and the following disclaimer in the
42  *    documentation and/or other materials provided with the distribution.
43  * 3. All advertising materials mentioning features or use of this software
44  *    must display the following acknowledgement:
45  *      This product includes software developed by TooLs GmbH.
46  * 4. The name of TooLs GmbH may not be used to endorse or promote products
47  *    derived from this software without specific prior written permission.
48  *
49  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
50  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
58  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59  */
60
61 #include "assym.s"
62
63 #include <sys/syscall.h>
64
65 #include <machine/trap.h>
66 #include <machine/param.h>
67 #include <machine/psl.h>
68 #include <machine/asm.h>
69 #include <machine/spr.h>
70
71 /*
72  * void cpu_throw(struct thread *old, struct thread *new)
73  */
74 ENTRY(cpu_throw)
75         mr      %r15, %r4
76         b       cpu_switchin
77
78 /*
79  * void cpu_switch(struct thread *old, struct thread *new, struct mutex *mtx);)
80  *
81  * Switch to a new thread saving the current state in the old thread.
82  */
83 ENTRY(cpu_switch)
84         stw     %r5, TD_LOCK(%r3)
85
86         lwz     %r5, TD_PCB(%r3)        /* Get the old thread's PCB ptr */
87
88         mr      %r12, %r2       
89         stmw    %r12, PCB_CONTEXT(%r5)  /* Save the non-volatile GP regs.
90                                            These can now be used for scratch */
91
92         mfcr    %r16                    /* Save the condition register */
93         stw     %r16, PCB_CR(%r5)
94         mflr    %r16                    /* Save the link register */
95         stw     %r16, PCB_LR(%r5)
96         mfctr   %r16
97         stw     %r16, PCB_BOOKE_CTR(%r5)
98         mfxer   %r16
99         stw     %r16, PCB_BOOKE_XER(%r5)
100         mfspr   %r16, SPR_DBCR0
101         stw     %r16, PCB_BOOKE_DBCR0(%r5)
102
103         stw     %r1, PCB_SP(%r5)        /* Save the stack pointer */
104
105         mr      %r14, %r3               /* Copy the old thread ptr... */
106         mr      %r15, %r4               /* and the new thread ptr in scratch */
107
108         bl      pmap_deactivate         /* Deactivate the current pmap */
109
110 cpu_switchin:
111         mr      %r3, %r15               /* Get new thread ptr */
112         bl      pmap_activate           /* Activate the new address space */
113
114         mfsprg  %r7, 0                  /* Get the pcpu pointer */
115         stw     %r15, PC_CURTHREAD(%r7) /* Store new current thread */
116         lwz     %r17, TD_PCB(%r15)      /* Store new current PCB */
117         stw     %r17, PC_CURPCB(%r7)
118
119         mr      %r3, %r17               /* Recover PCB ptr */
120         lmw     %r12, PCB_CONTEXT(%r3)  /* Load the non-volatile GP regs */
121         mr      %r2, %r12
122         lwz     %r5, PCB_CR(%r3)        /* Load the condition register */
123         mtcr    %r5
124         lwz     %r5, PCB_LR(%r3)        /* Load the link register */
125         mtlr    %r5
126         lwz     %r5, PCB_BOOKE_CTR(%r3)
127         mtctr   %r5
128         lwz     %r5, PCB_BOOKE_XER(%r3)
129         mtxer   %r5
130         lwz     %r5, PCB_BOOKE_DBCR0(%r3)
131         mtspr   SPR_DBCR0, %r5
132
133         lwz     %r1, PCB_SP(%r3)        /* Load the stack pointer */
134         blr
135
136 /*
137  * savectx(pcb)
138  * Update pcb, saving current processor state
139  */
140 ENTRY(savectx)
141         mr      %r12, %r2
142         stmw    %r12, PCB_CONTEXT(%r3)  /* Save the non-volatile GP regs */
143         mfcr    %r4                     /* Save the condition register */
144         stw     %r4, PCB_CONTEXT(%r3)
145         blr
146
147 /*
148  * fork_trampoline()
149  * Set up the return from cpu_fork()
150  */
151 ENTRY(fork_trampoline)
152         lwz     %r3, CF_FUNC(%r1)
153         lwz     %r4, CF_ARG0(%r1)
154         lwz     %r5, CF_ARG1(%r1)
155         bl      fork_exit
156         addi    %r1, %r1, CF_SIZE-FSP   /* Allow 8 bytes in front of
157                                            trapframe to simulate FRAME_SETUP
158                                            does when allocating space for
159                                            a frame pointer/saved LR */
160         b       trapexit