1/* $NetBSD: srt0.s,v 1.1 2000/02/29 15:21:51 nonaka Exp $ */ 2 3/* 4 * Copyright (C) 1996-1999 Cort Dougan (cort@fsmlasb.com). 5 * Copyright (C) 1996-1999 Gary Thomas (gdt@osf.org). 6 * Copyright (C) 1996-1999 Paul Mackeras (paulus@linuxcare.com). 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by TooLs GmbH. 20 * 4. The name of TooLs GmbH may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35#define MSR_IP (1<<6) 36 37#define HID0_DCI (1<<10) 38#define HID0_ICFI (1<<11) 39#define HID0_DCE (1<<14) 40#define HID0_ICE (1<<15) 41 42 .text 43 44 .globl _start 45_start: 46 bl start 47start: 48 mr 11,3 /* Save pointer to residual/board data */ 49 li 3,MSR_IP /* Establish default MSR value */ 50 mtmsr 3 51 isync 52 53 mflr 7 54 bl flush_icache 55 mfspr 3,1008 56 lis 4,~(HID0_ICE|HID0_DCE)@h 57 ori 4,4,~(HID0_ICE|HID0_DCE)@l 58 andc 3,3,4 59 mtspr 1008,3 60 mtlr 7 61 62/* 63 * check if we need to relocate ourselves to the link addr or were we 64 * loaded there to begin with -- Cort 65 */ 66 lis 4,_start@h 67 ori 4,4,_start@l 68 mflr 3 69 subi 3,3,4 /* we get the nip, not the ip of the branch */ 70 mr 8,3 71 cmp 0,3,4 72 bne 1f 73 b start_ldr 741: 75/* 76 * no matter where we're loaded, move ourselves to -Ttext address 77 */ 78relocate: 79 mflr 3 /* Compute code bias */ 80 subi 3,3,4 81 mr 8,3 82 lis 4,_start@h 83 ori 4,4,_start@l 84 lis 5,end@h 85 ori 5,5,end@l 86 addi 5,5,3 /* Round up - just in case */ 87 sub 5,5,4 /* Compute # longwords to move */ 88 srwi 5,5,2 89 mtctr 5 90 subi 3,3,4 /* Set up for loop */ 91 subi 4,4,4 922: 93 lwzu 5,4(3) 94 stwu 5,4(4) 95 bdnz 2b 96 lis 3,start_ldr@h 97 ori 3,3,start_ldr@l 98 mtlr 3 /* Easiest way to do an absolute jump */ 99 blr 100start_ldr: 101/* Clear all of BSS */ 102 lis 3,edata@h 103 ori 3,3,edata@l 104 lis 4,end@h 105 ori 4,4,end@l 106 subi 3,3,4 107 subi 4,4,4 108 li 0,0 1093: 110 stwu 0,4(3) 111 cmp 0,3,4 112 bne 3b 113 mr 9,1 /* Save old stack pointer */ 114 lis 1,.stack@h 115 ori 1,1,.stack@l 116 addi 1,1,4096 117 li 2,0x000F 118 andc 1,1,2 119 mr 3,11 /* arg1: residual/board data */ 120 mr 4,8 /* arg2: loadaddr */ 121 bl boot 122hang: 123 b hang 124 125/* 126 * Execute 127 * run(startsym, endsym, args, bootinfo, entry) 128 */ 129 .globl run 130run: 131 mtctr 7 /* Entry point */ 132 bctr 133 134/* 135 * Flush instruction cache 136 */ 137 .globl flush_icache 138flush_icache: 139 mflr 5 140 bl flush_dcache 141 mfspr 4,1008 142 li 4,0 143 ori 4,4,HID0_ICE|HID0_ICFI 144 or 3,3,4 145 mtspr 1008,3 146 andc 3,3,4 147 ori 3,3,HID0_ICE 148 mtspr 1008,3 149 mtlr 5 150 blr 151 152/* 153 * Flush data cache 154 */ 155 .globl flush_dcache 156flush_dcache: 157 lis 3,0x1000@h 158 ori 3,3,0x1000@l 159 li 4,1024 160 mtctr 4 1611: 162 lwz 4,0(3) 163 addi 3,3,32 164 bdnz 1b 165 blr 166 167/* 168 * local stack 169 */ 170 .comm .stack,8192,4 171