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