738d4b4a67f3fc8f1c2a6810affcf8f5c2d81420
[coreboot.git] / src / arch / ppc / init / crt0.S.lb
1 /* Copyright 2000  AG Electronics Ltd. */
2 /* This code is distributed without warranty under the GPL v2 (see COPYING) */
3
4 #define ASM
5 #include "ppcreg.h"
6 #include <ppc_asm.tmpl>
7
8 .section ".rom.reset", "ax", @progbits
9
10 .globl _start
11 _start:
12         b       system_reset
13
14 .section ".rom.exception_vectors", "ax", @progbits
15
16 %%EXCEPTION_VECTOR_TABLE%%
17
18 .section ".rom.data", "a", @progbits
19 .section ".rom.text", "ax", @progbits
20
21 system_reset:
22
23         /*
24          * Do processor family initialization
25          */
26 %%FAMILY_INIT%%
27
28         /*
29          * Do processor specific initialization
30          */
31 %%PROCESSOR_INIT%%
32
33 #if USE_DCACHE_RAM == 1
34 #define DCACHE_RAM_END  (DCACHE_RAM_BASE + DCACHE_RAM_SIZE - 1)
35         /*
36          * Initialize data cache blocks 
37          * (assumes cache block size of 32 bytes)
38          *
39          * NOTE: This may need to be moved to FAMILY_INIT if
40          *       dcbz is not supported on all CPU's
41          */
42         lis     r1, DCACHE_RAM_BASE@h
43         ori     r1, r1, DCACHE_RAM_BASE@l
44         li      r3, (DCACHE_RAM_SIZE / 32)
45         mtctr   r3
46 0:      dcbz    r0, r1
47         addi    r1, r1, 32
48         bdnz    0b
49
50         /*
51          * Set up stack in cache. The SP must be 16-byte (4-word) aligned
52          * for SYSV EABI or 8-byte (2-word) aligned for PPC EABI, so we make 
53          * it 16-byte aligned to cover both cases. Also we have to ensure that
54          * the first word is located within the cache.
55          */
56         lis     r1, (DCACHE_RAM_BASE+DCACHE_RAM_SIZE)@h
57         ori     r1, r1, (DCACHE_RAM_BASE+DCACHE_RAM_SIZE)@l
58         lis     r0, 0
59         stwu    r0, -4(r1)
60         stwu    r0, -4(r1)
61         stwu    r0, -4(r1)
62         stwu    r0, -4(r1)
63
64 #if 0
65         /*
66          * Clear stack
67          */
68         lis     r4, DCACHE_RAM_BASE@h
69         ori     r4, r4, DCACHE_RAM_BASE@l
70         lis     r7, DCACHE_RAM_END@h
71         ori     r7, r7, DCACHE_RAM_END@l
72         lis     r5, 0
73 1:      stwx    r5, 0, r4
74         addi    r4, r4, 4
75         cmp     0, 0, r4, r7
76         ble     1b
77         sync
78 #endif
79
80         /*
81          * Set up the EABI pointers, before we enter any C code
82          */
83         lis     r13, _SDA_BASE_@h
84         ori     r13, r13, _SDA_BASE_@l
85         lis     r2, _SDA2_BASE_@h
86         ori     r2, r2, _SDA2_BASE_@l
87
88         /*
89          * load start address into SRR0 for rfi
90          */
91         lis     r3, ppc_main@h
92         ori     r3, r3, ppc_main@l
93         mtspr   SRR0, r3
94
95         /*
96          * load the current MSR into SRR1 so that it will be copied 
97          * back into MSR on rfi
98          */
99         mfmsr   r4
100         mtspr   SRR1, r4        // load SRR1 with r4
101
102         /*
103          * If something returns after rfi then die
104          */
105         lis     r3, dead@h
106         ori     r3, r3, dead@l
107         mtlr    r3
108
109         /*
110          * Complete rest of initialization in C (ppc_main)
111          */
112         rfi
113 #endif /* USE_DCACHE_RAM */
114
115         /*
116          * Stop here if something goes wrong
117          */
118 dead:
119         b       dead
120         /*NOTREACHED*/
121
122 /* Remove need for ecrti.o and ectrn.o */
123 .globl __init
124 __init:
125 .globl __fini
126 __fini:
127 .globl __CTOR_LIST__
128 __CTOR_LIST__:
129 .globl __CTOR_END__
130 __CTOR_END__:
131 .globl __DTOR_LIST__
132 __DTOR_LIST__:
133 .globl __DTOR_END__
134 __DTOR_END__:
135         blr
136
137 %%NORTHBRIDGE_INIT%%