2 * Copyright (C) 2001 Benno Rice
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
25 * from: $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $
31 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
32 * Copyright (C) 1995, 1996 TooLs GmbH.
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
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.
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.
63 #include <sys/syscall.h>
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>
72 * void cpu_throw(struct thread *old, struct thread *new)
79 * void cpu_switch(struct thread *old, struct thread *new, struct mutex *mtx);)
81 * Switch to a new thread saving the current state in the old thread.
86 lwz %r5, TD_PCB(%r3) /* Get the old thread's PCB ptr */
89 stmw %r12, PCB_CONTEXT(%r5) /* Save the non-volatile GP regs.
90 These can now be used for scratch */
92 mfcr %r16 /* Save the condition register */
94 mflr %r16 /* Save the link register */
97 stw %r16, PCB_BOOKE_CTR(%r5)
99 stw %r16, PCB_BOOKE_XER(%r5)
100 mfspr %r16, SPR_DBCR0
101 stw %r16, PCB_BOOKE_DBCR0(%r5)
103 stw %r1, PCB_SP(%r5) /* Save the stack pointer */
105 mr %r14, %r3 /* Copy the old thread ptr... */
106 mr %r15, %r4 /* and the new thread ptr in scratch */
108 bl pmap_deactivate /* Deactivate the current pmap */
111 mr %r3, %r15 /* Get new thread ptr */
112 bl pmap_activate /* Activate the new address space */
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)
119 mr %r3, %r17 /* Recover PCB ptr */
120 lmw %r12, PCB_CONTEXT(%r3) /* Load the non-volatile GP regs */
122 lwz %r5, PCB_CR(%r3) /* Load the condition register */
124 lwz %r5, PCB_LR(%r3) /* Load the link register */
126 lwz %r5, PCB_BOOKE_CTR(%r3)
128 lwz %r5, PCB_BOOKE_XER(%r3)
130 lwz %r5, PCB_BOOKE_DBCR0(%r3)
133 lwz %r1, PCB_SP(%r3) /* Load the stack pointer */
138 * Update pcb, saving current processor state
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)
149 * Set up the return from cpu_fork()
151 ENTRY(fork_trampoline)
152 lwz %r3, CF_FUNC(%r1)
153 lwz %r4, CF_ARG0(%r1)
154 lwz %r5, CF_ARG1(%r1)
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 */