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