1719fd7103e04b0878104e0ee196040603a8df17
[coreboot.git] / src / arch / ppc / lib / c_start.S
1 /* $Id$ */
2 /* Copyright 2000  AG Electronics Ltd. */
3 /* This code is distributed without warranty under the GPL v2 (see COPYING) */
4
5 /*
6  * The assumption is that we're located in ROM and we have a fake stack
7  * located in cache. Our task is to turn on memory proper, the finish
8  * configuring the machine.
9  */
10
11 #define ASM
12 #include "ppcreg.h"
13 #include <ppc_asm.tmpl>
14
15 .section ".text"
16 .globl _start
17
18 _start:
19         /* 
20          * init stack pointer to real ram now that memory is on
21          */
22         lis     r1, _estack@ha
23         addi    r1, r1, _estack@l
24         stwu    r0,-64(r1) 
25         stwu    r1,-24(r1) 
26
27         /*
28          * Clear stack
29          */
30         lis     r4, _stack@ha
31         addi    r4, r4, _stack@l
32         lis     r7, _estack@ha
33         addi    r7, r7, _estack@l
34         lis     r5, 0
35 1:      stwx    r5, 0, r4
36         addi    r4, r4, 4
37         cmp     0, 0, r4, r7
38         ble     1b
39         sync
40
41         /*
42          * Clear bss
43          */
44         lis     r4, _bss@ha
45         addi    r4, r4, _bss@l
46         lis     r7, _ebss@ha
47         addi    r7, r7, _ebss@l
48         lis     r5, 0
49 1:      stwx    r5, 0, r4
50         addi    r4, r4, 4
51         cmp     0, 0, r4, r7
52         ble     1b
53         sync
54
55         /*
56          * Set up the EABI pointers, before we enter any C code
57          */
58         lis     r13, _SDA_BASE_@ha
59         addi    r13, r13, _SDA_BASE_@l
60         lis     r2, _SDA2_BASE_@ha
61         addi    r2, r2, _SDA2_BASE_@l
62
63         /*
64          * load start address into SRR0 for rfi
65          */
66         lis     r3, hardwaremain@ha
67         addi    r3, r3, hardwaremain@l
68         mtspr   SRR0, r3
69
70         /*
71          * load the current MSR into SRR1 so that it will be copied 
72          * back into MSR on rfi
73          */
74         mfmsr   r4
75         mtspr   SRR1, r4        // load SRR1 with r4
76
77         /*
78          * If something returns after rfi then die
79          */
80         lis     r3, dead@ha
81         addi    r3, r3, dead@l
82         mtlr    r3
83
84         /*
85          * Complete rest of initialization in C (hardwaremain)
86          */
87         rfi
88
89         /*
90          * Stop here if something goes wrong
91          */
92 dead:
93         b       dead
94         /*NOTREACHED*/
95
96 /* Remove need for ecrti.o and ectrn.o */
97 .globl __init
98 __init:
99 .globl __fini
100 __fini:
101 .globl __CTOR_LIST__
102 __CTOR_LIST__:
103 .globl __CTOR_END__
104 __CTOR_END__:
105 .globl __DTOR_LIST__
106 __DTOR_LIST__:
107 .globl __DTOR_END__
108 __DTOR_END__:
109         blr