]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/powerpc/booke/swtch.S
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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/asm.h>
68 #include <machine/spr.h>
69
70 /*
71  * void cpu_throw(struct thread *old, struct thread *new)
72  */
73 ENTRY(cpu_throw)
74         mr      %r15, %r4
75         b       cpu_switchin
76
77 /*
78  * void cpu_switch(struct thread *old, struct thread *new, struct mutex *mtx);)
79  *
80  * Switch to a new thread saving the current state in the old thread.
81  */
82 ENTRY(cpu_switch)
83         stw     %r5, TD_LOCK(%r3)
84
85         lwz     %r5, TD_PCB(%r3)        /* Get the old thread's PCB ptr */
86
87         mr      %r12, %r2       
88         stmw    %r12, PCB_CONTEXT(%r5)  /* Save the non-volatile GP regs.
89                                            These can now be used for scratch */
90
91         mfcr    %r16                    /* Save the condition register */
92         stw     %r16, PCB_CR(%r5)
93         mflr    %r16                    /* Save the link register */
94         stw     %r16, PCB_LR(%r5)
95         mfctr   %r16
96         stw     %r16, PCB_BOOKE_CTR(%r5)
97         mfxer   %r16
98         stw     %r16, PCB_BOOKE_XER(%r5)
99         mfspr   %r16, SPR_DBCR0
100         stw     %r16, PCB_BOOKE_DBCR0(%r5)
101
102         stw     %r1, PCB_SP(%r5)        /* Save the stack pointer */
103
104         mr      %r14, %r3               /* Copy the old thread ptr... */
105         mr      %r15, %r4               /* and the new thread ptr in scratch */
106
107         bl      pmap_deactivate         /* Deactivate the current pmap */
108
109 cpu_switchin:
110         mr      %r3, %r15               /* Get new thread ptr */
111         bl      pmap_activate           /* Activate the new address space */
112
113         mfsprg  %r7, 0                  /* Get the pcpu pointer */
114         stw     %r15, PC_CURTHREAD(%r7) /* Store new current thread */
115         lwz     %r17, TD_PCB(%r15)      /* Store new current PCB */
116         stw     %r17, PC_CURPCB(%r7)
117
118         mr      %r3, %r17               /* Recover PCB ptr */
119         lmw     %r12, PCB_CONTEXT(%r3)  /* Load the non-volatile GP regs */
120         mr      %r2, %r12
121         lwz     %r5, PCB_CR(%r3)        /* Load the condition register */
122         mtcr    %r5
123         lwz     %r5, PCB_LR(%r3)        /* Load the link register */
124         mtlr    %r5
125         lwz     %r5, PCB_BOOKE_CTR(%r3)
126         mtctr   %r5
127         lwz     %r5, PCB_BOOKE_XER(%r3)
128         mtxer   %r5
129         lwz     %r5, PCB_BOOKE_DBCR0(%r3)
130         mtspr   SPR_DBCR0, %r5
131
132         lwz     %r1, PCB_SP(%r3)        /* Load the stack pointer */
133         blr
134
135 /*
136  * savectx(pcb)
137  * Update pcb, saving current processor state
138  */
139 ENTRY(savectx)
140         mr      %r12, %r2
141         stmw    %r12, PCB_CONTEXT(%r3)  /* Save the non-volatile GP regs */
142         mfcr    %r4                     /* Save the condition register */
143         stw     %r4, PCB_CONTEXT(%r3)
144         blr
145
146 /*
147  * fork_trampoline()
148  * Set up the return from cpu_fork()
149  */
150 ENTRY(fork_trampoline)
151         lwz     %r3, CF_FUNC(%r1)
152         lwz     %r4, CF_ARG0(%r1)
153         lwz     %r5, CF_ARG1(%r1)
154         bl      fork_exit
155         addi    %r1, %r1, CF_SIZE-FSP   /* Allow 8 bytes in front of
156                                            trapframe to simulate FRAME_SETUP
157                                            does when allocating space for
158                                            a frame pointer/saved LR */
159         b       trapexit