locore32.S revision 178628
1139823Simp/* $FreeBSD: head/sys/powerpc/aim/locore.S 178628 2008-04-27 22:33:43Z marcel $ */ 252419Sjulian/* $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $ */ 352419Sjulian 470700Sjulian/*- 552419Sjulian * Copyright (C) 2001 Benno Rice 652419Sjulian * All rights reserved. 752419Sjulian * 852419Sjulian * Redistribution and use in source and binary forms, with or without 952419Sjulian * modification, are permitted provided that the following conditions 1052419Sjulian * are met: 1152419Sjulian * 1. Redistributions of source code must retain the above copyright 1252419Sjulian * notice, this list of conditions and the following disclaimer. 1352419Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1452419Sjulian * notice, this list of conditions and the following disclaimer in the 1570700Sjulian * documentation and/or other materials provided with the distribution. 1652419Sjulian * 1752419Sjulian * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR 1852419Sjulian * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1952419Sjulian * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2052419Sjulian * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2152419Sjulian * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2252419Sjulian * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2352419Sjulian * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2452419Sjulian * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2552419Sjulian * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 2652419Sjulian * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2752419Sjulian */ 2852419Sjulian/*- 2952419Sjulian * Copyright (C) 1995, 1996 Wolfgang Solfrank. 3052419Sjulian * Copyright (C) 1995, 1996 TooLs GmbH. 3152419Sjulian * All rights reserved. 3252419Sjulian * 3352419Sjulian * Redistribution and use in source and binary forms, with or without 3467506Sjulian * modification, are permitted provided that the following conditions 3567506Sjulian * are met: 3652419Sjulian * 1. Redistributions of source code must retain the above copyright 3752419Sjulian * notice, this list of conditions and the following disclaimer. 3852419Sjulian * 2. Redistributions in binary form must reproduce the above copyright 3952419Sjulian * notice, this list of conditions and the following disclaimer in the 4052419Sjulian * documentation and/or other materials provided with the distribution. 4152419Sjulian * 3. All advertising materials mentioning features or use of this software 4252419Sjulian * must display the following acknowledgement: 4352419Sjulian * This product includes software developed by TooLs GmbH. 4452419Sjulian * 4. The name of TooLs GmbH may not be used to endorse or promote products 4552419Sjulian * derived from this software without specific prior written permission. 46231766Sglebius * 47139235Sglebius * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 48231831Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 49131933Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 5052419Sjulian * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 51231760Sglebius * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 52154225Sglebius * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 53114216Skan * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 54230480Sglebius * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 5552419Sjulian * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 56139235Sglebius * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57231760Sglebius */ 5852419Sjulian 59231760Sglebius#include "assym.s" 60231760Sglebius 61231760Sglebius#include <sys/syscall.h> 6272946Sjulian 63139235Sglebius#include <machine/trap.h> 64186093Smav#include <machine/param.h> 65177953Smav#include <machine/sr.h> 6652419Sjulian#include <machine/spr.h> 6752419Sjulian#include <machine/psl.h> 68195699Srwatson#include <machine/asm.h> 6952419Sjulian 7052419Sjulian/* Locate the per-CPU data structure */ 7152419Sjulian#define GET_CPUINFO(r) \ 7253913Sarchie mfsprg0 r 7352419Sjulian 7472053Sjulian/* 7559756Speter * Compiled KERNBASE location and the kernel load address 76151974Sglebius */ 77151974Sglebius .globl kernbase 78151974Sglebius .set kernbase, KERNBASE 7970784Sjulian 80176802Smav#define TMPSTKSZ 8192 /* 8K temporary stack */ 81152451Sglebius 8270784Sjulian/* 8370784Sjulian * Globals 8470784Sjulian */ 8570784Sjulian .data 8670784Sjulian .align 4 8770784SjulianGLOBAL(tmpstk) 8870784Sjulian .space TMPSTKSZ 8970784SjulianGLOBAL(esym) 9070784Sjulian .long 0 /* end of symbol table */ 9170784Sjulian 9270784SjulianGLOBAL(ofmsr) 9370935Sjulian .long 0, 0, 0, 0, 0 /* msr/sprg0-3 used in Open Firmware */ 94152451Sglebius 95249583Sgabor#define INTRCNT_COUNT 256 /* max(HROWPIC_IRQMAX,OPENPIC_IRQMAX) */ 96152451SglebiusGLOBAL(intrnames) 9770935Sjulian .space INTRCNT_COUNT * (MAXCOMLEN + 1) * 2 9870935SjulianGLOBAL(eintrnames) 9970935Sjulian .align 4 10070935SjulianGLOBAL(intrcnt) 10170935Sjulian .space INTRCNT_COUNT * 4 * 2 10270935SjulianGLOBAL(eintrcnt) 10370935Sjulian 10470935Sjulian/* 10570935Sjulian * File-scope for locore.S 10670935Sjulian */ 10770935Sjulianidle_u: 10870935Sjulian .long 0 /* fake uarea during idle after exit */ 10970935Sjulianopenfirmware_entry: 11070935Sjulian .long 0 /* Open Firmware entry point */ 11170935Sjuliansrsave: 11270935Sjulian .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 11370784Sjulian 11470935Sjulian/* 11570935Sjulian * This symbol is here for the benefit of kvm_mkdb, and is supposed to 11670935Sjulian * mark the start of kernel text. 117132464Sjulian */ 11870935Sjulian .text 11970935Sjulian .globl kernel_text 12070935Sjuliankernel_text: 121201145Santoine 12270935Sjulian/* 12370935Sjulian * Startup entry. Note, this must be the first thing in the text 12470935Sjulian * segment! 125178228Smav */ 12670935Sjulian .text 127178228Smav .globl __start 128178228Smav__start: 12970935Sjulian#ifdef FIRMWORKSBUGS 130178228Smav mfmsr 0 131191827Szec andi. 0,0,PSL_IR|PSL_DR 13270935Sjulian beq 1f 13370935Sjulian 13470935Sjulian bl ofwr_init 13570935Sjulian1: 13670935Sjulian#endif 13770935Sjulian li 8,0 13870935Sjulian li 9,0x100 13970935Sjulian mtctr 9 14070935Sjulian1: 14170935Sjulian dcbf 0,8 14270935Sjulian icbi 0,8 14370935Sjulian addi 8,8,0x20 144148261Sglebius bdnz 1b 14570935Sjulian sync 14670935Sjulian isync 14770935Sjulian 14871885Sjulian /* Save the argument pointer and length */ 14971885Sjulian mr 20,6 150178228Smav mr 21,7 15170935Sjulian 15270935Sjulian lis 8,openfirmware_entry@ha 15370935Sjulian stw 5,openfirmware_entry@l(8) /* save client interface handler */ 15470935Sjulian mr 3,5 15570935Sjulian 15670935Sjulian lis 1,(tmpstk+TMPSTKSZ-16)@ha 15770935Sjulian addi 1,1,(tmpstk+TMPSTKSZ-16)@l 15870935Sjulian 15970935Sjulian mfmsr 0 16070935Sjulian lis 9,ofmsr@ha 16170935Sjulian stwu 0,ofmsr@l(9) 16270700Sjulian 163178228Smav mfsprg0 0 /* save SPRG0-3 */ 16471902Sjulian stw 0,4(9) /* ofmsr[1] = sprg0 */ 16570700Sjulian mfsprg1 0 16652419Sjulian stw 0,8(9) /* ofmsr[2] = sprg1 */ 16770700Sjulian mfsprg2 0 168230480Sglebius stw 0,12(9) /* ofmsr[3] = sprg2 */ 169230480Sglebius mfsprg3 0 170230480Sglebius stw 0,16(9) /* ofmsr[4] = sprg3 */ 171230480Sglebius 172230480Sglebius bl OF_init 17352419Sjulian 174231831Sglebius lis 4,end@ha 175231831Sglebius addi 4,4,end@l 176231831Sglebius mr 5,4 177231831Sglebius 178231831Sglebius lis 3,kernel_text@ha 179231831Sglebius addi 3,3,kernel_text@l 180231831Sglebius 181231831Sglebius /* Restore the argument pointer and length */ 182231831Sglebius mr 6,20 183231831Sglebius mr 7,21 184231831Sglebius 185231831Sglebius bl powerpc_init 186231831Sglebius mr %r1, %r3 187231831Sglebius li %r3, 0 188195699Srwatson stw %r3, 0(%r1) 189230480Sglebius bl mi_startup 190230480Sglebius b OF_exit 191230480Sglebius 192230480Sglebius/* 193230480Sglebius * int setfault() 194230480Sglebius * 19571354Sjulian * Similar to setjmp to setup for handling faults on accesses to user memory. 196231831Sglebius * Any routine using this may only call bcopy, either the form below, 19771354Sjulian * or the (currently used) C code optimized, so it doesn't use any non-volatile 19871354Sjulian * registers. 199230480Sglebius */ 200181803Sbz .globl setfault 20171354Sjuliansetfault: 20271354Sjulian mflr 0 20371354Sjulian mfcr 12 20471354Sjulian mfsprg 4,0 20571354Sjulian lwz 4,PC_CURTHREAD(4) 20671354Sjulian lwz 4,TD_PCB(4) 20771354Sjulian stw 3,PCB_ONFAULT(4) 20852722Sjulian stw 0,0(3) 209230480Sglebius stw 1,4(3) 210230480Sglebius stw 2,8(3) 211230480Sglebius stmw 12,12(3) 212230480Sglebius xor 3,3,3 213230480Sglebius blr 214176802Smav 21552419Sjulian#include <powerpc/aim/trap_subr.S> 21652419Sjulian