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