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