srt0_pwr.s revision 1.1 1 1.1 garbled /* $NetBSD: srt0_pwr.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_DR (1<<4)
36 1.1 garbled #define MSR_IP (1<<6)
37 1.1 garbled #define MSR_AL (1<<7)
38 1.1 garbled #define MSR_ME (1<<12)
39 1.1 garbled
40 1.1 garbled #define HID0_DCI (1<<10)
41 1.1 garbled #define HID0_ICFI (1<<11)
42 1.1 garbled #define HID0_DCE (1<<14)
43 1.1 garbled #define HID0_ICE (1<<15)
44 1.1 garbled
45 1.1 garbled /* when we start, the IPLCB pointer is in r3, and the extended one is in r4 */
46 1.1 garbled
47 1.1 garbled .machine "com"
48 1.1 garbled .text
49 1.1 garbled
50 1.1 garbled .globl _start
51 1.1 garbled _start:
52 1.1 garbled bl start
53 1.1 garbled start:
54 1.1 garbled li 2,MSR_ME|MSR_AL /* Establish default MSR value */
55 1.1 garbled mtmsr 2
56 1.1 garbled isync
57 1.1 garbled #if 0
58 1.1 garbled /*
59 1.1 garbled mflr 7
60 1.1 garbled bl flush_icache
61 1.1 garbled mfspr 3,1008
62 1.1 garbled lis 4,~(HID0_ICE|HID0_DCE)@h
63 1.1 garbled ori 4,4,~(HID0_ICE|HID0_DCE)@l
64 1.1 garbled andc 3,3,4
65 1.1 garbled mtspr 1008,3
66 1.1 garbled mtlr 7
67 1.1 garbled */
68 1.1 garbled /*
69 1.1 garbled * check if we need to relocate ourselves to the link addr or were we
70 1.1 garbled * loaded there to begin with -- Cort
71 1.1 garbled */
72 1.1 garbled lis 4,_start@h
73 1.1 garbled ori 4,4,_start@l
74 1.1 garbled mflr 3
75 1.1 garbled subi 3,3,4 /* we get the nip, not the ip of the branch */
76 1.1 garbled mr 8,3
77 1.1 garbled cmpw 3,4
78 1.1 garbled bne relocate
79 1.1 garbled b start_ldr
80 1.1 garbled
81 1.1 garbled /*
82 1.1 garbled * no matter where we're loaded, move ourselves to -Ttext address
83 1.1 garbled */
84 1.1 garbled relocate:
85 1.1 garbled lis 4,_start@h
86 1.1 garbled ori 4,4,_start@l
87 1.1 garbled lis 5,end@h
88 1.1 garbled ori 5,5,end@l
89 1.1 garbled addi 5,5,3 /* Round up - just in case */
90 1.1 garbled sub 5,5,4 /* Compute # longwords to move */
91 1.1 garbled srwi 5,5,2
92 1.1 garbled mtctr 5
93 1.1 garbled subi 3,3,4 /* Set up for loop */
94 1.1 garbled subi 4,4,4
95 1.1 garbled 2:
96 1.1 garbled lwzu 5,4(3)
97 1.1 garbled stwu 5,4(4)
98 1.1 garbled bdnz 2b
99 1.1 garbled lis 3,start_ldr@h
100 1.1 garbled ori 3,3,start_ldr@l
101 1.1 garbled mtlr 3 /* Easiest way to do an absolute jump */
102 1.1 garbled blr
103 1.1 garbled #endif /* no good */
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 #if 0
112 1.1 garbled mr 3,11 /* arg1: residual/board data */
113 1.1 garbled mr 4,8 /* arg2: loadaddr */
114 1.1 garbled #endif
115 1.1 garbled bl boot
116 1.1 garbled hang:
117 1.1 garbled b hang
118 1.1 garbled
119 1.1 garbled /*
120 1.1 garbled * Execute
121 1.1 garbled * run(startsym, endsym, args, bootinfo, entry)
122 1.1 garbled */
123 1.1 garbled .globl run
124 1.1 garbled run:
125 1.1 garbled mtctr 7 /* Entry point */
126 1.1 garbled bctr
127 1.1 garbled
128 1.1 garbled /*
129 1.1 garbled * Flush instruction cache
130 1.1 garbled */
131 1.1 garbled .globl flush_icache
132 1.1 garbled flush_icache:
133 1.1 garbled mflr 5
134 1.1 garbled bl flush_dcache
135 1.1 garbled mfspr 4,1008
136 1.1 garbled li 4,0
137 1.1 garbled ori 4,4,HID0_ICE|HID0_ICFI
138 1.1 garbled or 3,3,4
139 1.1 garbled mtspr 1008,3
140 1.1 garbled andc 3,3,4
141 1.1 garbled ori 3,3,HID0_ICE
142 1.1 garbled mtspr 1008,3
143 1.1 garbled mtlr 5
144 1.1 garbled blr
145 1.1 garbled
146 1.1 garbled /*
147 1.1 garbled * Flush data cache
148 1.1 garbled */
149 1.1 garbled .globl flush_dcache
150 1.1 garbled flush_dcache:
151 1.1 garbled lis 3,0x1000@h
152 1.1 garbled ori 3,3,0x1000@l
153 1.1 garbled li 4,1024
154 1.1 garbled mtctr 4
155 1.1 garbled 1:
156 1.1 garbled lwz 4,0(3)
157 1.1 garbled addi 3,3,32
158 1.1 garbled bdnz 1b
159 1.1 garbled blr
160 1.1 garbled
161 1.1 garbled #if 0
162 1.1 garbled /*
163 1.1 garbled * write LEDS
164 1.1 garbled */
165 1.1 garbled
166 1.1 garbled .globl led
167 1.1 garbled led:
168 1.1 garbled mfmsr 5 /* save MSR to r5 */
169 1.1 garbled lis 7,0xffff
170 1.1 garbled ori 7,7,~(MSR_DR)
171 1.1 garbled and 6,5,7
172 1.1 garbled mtmsr 6
173 1.1 garbled isync
174 1.1 garbled
175 1.1 garbled #endif
176 1.1 garbled /*
177 1.1 garbled * local stack
178 1.1 garbled */
179 1.1 garbled .comm .stack,8192,4
180