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