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