swtch64.S revision 83682
1/* $FreeBSD: head/sys/powerpc/aim/swtch.S 83682 2001-09-20 00:47:17Z mp $ */ 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. */ 79ASENTRY(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 1061: 107 b _ASM_LABEL(Idle) 108#endif /* XXX */ 109 110/* 111 * switchexit gets called from cpu_exit to complete the exit procedure. 112 */ 113ENTRY(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 */ 136ENTRY(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_CURTHREAD(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 choosethread 158 1591: 160 /* record new process */ 161 mfsprg 4,0 162 stw 3,GD_CURTHREAD(4) 163 164 cmpl 0,31,30 /* is it the same process? */ 165 beq switch_return 166 167 or. 30,30,30 /* old process was exiting? */ 168 beq switch_exited 169 170 mfsr 10,USER_SR /* save USER_SR for copyin/copyout */ 171 mfcr 11 /* save cr */ 172 mr 12,2 /* save r2 */ 173 stwu 1,-SFRAMELEN(1) /* still running on old stack */ 174 stmw 10,8(1) 175 lwz 3,TD_PCB(30) 176 stw 1,PCB_SP(3) /* save SP */ 177 178switch_exited: 179 mfmsr 3 180 andi. 3,3,~PSL_EE@l /* disable interrupts while 181 actually switching */ 182 mtmsr 3 183 184 /* indicate new pcb */ 185 lwz 4,TD_PCB(31) 186 mfsprg 5,0 187 stw 4,GD_CURPCB(5) 188 189#if 0 /* XXX */ 190 /* save real pmap pointer for spill fill */ 191 lwz 5,PCB_PMR(4) 192 lis 6,curpm@ha 193 stwu 5,curpm@l(6) 194 stwcx. 5,0,6 /* clear possible reservation */ 195#endif 196 197 addic. 5,5,64 198 li 6,0 199 mfsr 8,KERNEL_SR /* save kernel SR */ 2001: 201 addis 6,6,-0x10000000@ha /* set new procs segment registers */ 202 or. 6,6,6 /* This is done from the real 203 address pmap */ 204 lwzu 7,-4(5) /* so we don't have to worry */ 205 mtsrin 7,6 /* about accessibility */ 206 bne 1b 207 mtsr KERNEL_SR,8 /* restore kernel SR */ 208 isync 209 210 lwz 1,PCB_SP(4) /* get new procs SP */ 211 212 ori 3,3,PSL_EE@l /* interrupts are okay again */ 213 mtmsr 3 214 215 lmw 10,8(1) /* get other regs */ 216 lwz 1,0(1) /* get saved SP */ 217 mr 2,12 /* get saved r2 */ 218 mtcr 11 /* get saved cr */ 219 isync 220 mtsr USER_SR,10 /* get saved USER_SR */ 221 isync 222 223switch_return: 224 mr 30,7 /* save proc pointer */ 225 lwz 3,PCB_SPL(4) 226#if 0 /* XXX */ 227 bl lcsplx 228#endif 229 230 mr 3,30 /* get curthread for special fork 231 returns */ 232 233 lwz 31,12(1) 234 lwz 30,8(1) 235 addi 1,1,16 236 lwz 0,4(1) 237 mtlr 0 238 blr 239 240/* 241 * Fake savectx for the time being. 242 */ 243ENTRY(savectx) 244 blr 245