1 | /* |
---|
2 | * This is based on the mvme-crt0.S file from libgloss/rs6000. |
---|
3 | * crt0.S -- startup file for PowerPC systems. |
---|
4 | * |
---|
5 | * Copyright (c) 1995 Cygnus Support |
---|
6 | * |
---|
7 | * The authors hereby grant permission to use, copy, modify, distribute, |
---|
8 | * and license this software and its documentation for any purpose, provided |
---|
9 | * that existing copyright notices are retained in all copies and that this |
---|
10 | * notice is included verbatim in any distributions. No written agreement, |
---|
11 | * license, or royalty fee is required for any of the authorized uses. |
---|
12 | * Modifications to this software may be copyrighted by their authors |
---|
13 | * and need not follow the licensing terms described here, provided that |
---|
14 | * the new terms are clearly indicated on the first page of each file where |
---|
15 | * they apply. |
---|
16 | */ |
---|
17 | |
---|
18 | #include <rtems/asm.h> |
---|
19 | #include <rtems/score/cpu.h> |
---|
20 | #include <libcpu/io.h> |
---|
21 | #include "ppc-asm.h" |
---|
22 | |
---|
23 | .section ".got2","aw" |
---|
24 | .align 2 |
---|
25 | |
---|
26 | .LCTOC1 = .+32768 |
---|
27 | |
---|
28 | .section ".got2","aw" |
---|
29 | .Ltable = .-.LCTOC1 |
---|
30 | .long .LCTOC1 /* address we think .LCTOC1 is loaded at */ |
---|
31 | |
---|
32 | .Lbss_start = .-.LCTOC1 |
---|
33 | .long bsp_section_sbss_begin |
---|
34 | |
---|
35 | .Lend = .-.LCTOC1 |
---|
36 | .long bsp_section_bss_end |
---|
37 | |
---|
38 | .Lstack = .-.LCTOC1 /* stack address if set by user */ |
---|
39 | .long _ISR_Stack_area_end |
---|
40 | |
---|
41 | .text |
---|
42 | .Lptr: |
---|
43 | .long .LCTOC1-.Laddr |
---|
44 | |
---|
45 | .globl __rtems_entry_point |
---|
46 | .type __rtems_entry_point,@function |
---|
47 | __rtems_entry_point: |
---|
48 | #if 1 |
---|
49 | .globl _start |
---|
50 | .type _start,@function |
---|
51 | _start: |
---|
52 | #endif |
---|
53 | bl .Laddr /* get current address */ |
---|
54 | .Laddr: |
---|
55 | mflr r4 /* real address of .Laddr */ |
---|
56 | lwz r5,(.Lptr-.Laddr)(r4) /* linker generated address of .LCTOC1 */ |
---|
57 | add r5,r5,r4 /* correct to real pointer */ |
---|
58 | lwz r4,.Ltable(r5) /* get linker's idea of where .Laddr is */ |
---|
59 | subf r4,r4,r5 /* calculate difference between where linked and current */ |
---|
60 | |
---|
61 | /* clear bss */ |
---|
62 | lwz r6,.Lbss_start(r5) /* calculate beginning of the BSS */ |
---|
63 | lwz r7,.Lend(r5) /* calculate end of the BSS */ |
---|
64 | add r6,r6,r4 /* adjust pointers */ |
---|
65 | add r7,r7,r4 |
---|
66 | |
---|
67 | cmplw 1,r6,r7 |
---|
68 | bc 4,4,.Ldone |
---|
69 | |
---|
70 | subf r8,r6,r7 /* number of bytes to zero */ |
---|
71 | srwi r9,r8,2 /* number of words to zero */ |
---|
72 | mtctr r9 |
---|
73 | li r0,0 /* zero to clear memory */ |
---|
74 | addi r6,r6,-4 /* adjust so we can use stwu */ |
---|
75 | .Lloop: |
---|
76 | stwu r0,4(r6) /* zero bss */ |
---|
77 | bdnz .Lloop |
---|
78 | |
---|
79 | .Ldone: |
---|
80 | |
---|
81 | lwz r0,.Lstack(r5) /* stack area or 0 */ |
---|
82 | cmplwi 1,r0,0 /* equal to 0? */ |
---|
83 | bc 12,6,.Lnostack /* use default stack if == 0 */ |
---|
84 | mr sp,r0 /* use user defined stack */ |
---|
85 | |
---|
86 | .Lnostack: |
---|
87 | #ifdef __ALTIVEC__ |
---|
88 | /* enable altivec; this requires the ALTIVEC user |
---|
89 | * extension to be installed in the user extension |
---|
90 | * slot 0! |
---|
91 | */ |
---|
92 | mfmsr r0 |
---|
93 | oris r0, r0, (1<<(31-16-6)) |
---|
94 | mtmsr r0 |
---|
95 | isync |
---|
96 | /* |
---|
97 | * set vscr and vrsave to known values |
---|
98 | */ |
---|
99 | li r0, 0 |
---|
100 | mtvrsave r0 |
---|
101 | vxor 0,0,0 |
---|
102 | mtvscr 0 |
---|
103 | #endif |
---|
104 | /* set up initial stack frame */ |
---|
105 | addi sp,sp,-4 /* make sure we don't overwrite debug mem */ |
---|
106 | /* align */ |
---|
107 | li r3, CPU_STACK_ALIGNMENT-1 |
---|
108 | andc sp, sp, r3 |
---|
109 | lis r0,0 |
---|
110 | stw r0,0(sp) /* clear back chain */ |
---|
111 | stwu sp,-CPU_STACK_ALIGNMENT(sp) /* push another stack frame */ |
---|
112 | bl FUNC_NAME(__eabi) |
---|
113 | |
---|
114 | /* Let her rip */ |
---|
115 | li r3, 0 /* command line */ |
---|
116 | bl FUNC_NAME(boot_card) |
---|
117 | |
---|
118 | .globl FUNC_NAME(bsp_reset) |
---|
119 | FUNC_NAME(bsp_reset): |
---|
120 | li 10,99 /* 0x63 */ |
---|
121 | sc |
---|
122 | |
---|
123 | .Lstart: |
---|
124 | .size _start,.Lstart-_start |
---|