]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/T-HEAD_CB2201_CDK/RTOSDemo_CDK/RTOSDemo/crt0.S
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Demo / T-HEAD_CB2201_CDK / RTOSDemo_CDK / RTOSDemo / crt0.S
1 /*\r
2  * crt0.S\r
3  * 1 define and initial the stack pointer\r
4  * 2 exception handler table\r
5  * 3 call SystemInit\r
6  * 4 go to __main in entry.o\r
7  *\r
8  * Copyright (C) 2016~2017  Hangzhou C-SKY Microsystems Co., Ltd\r
9  * Modify by Jiang Long  on 2016-09-14\r
10  */\r
11 // <<< Use Configuration Wizard in Context Menu >>>\r
12 \r
13 /*\r
14  * For importing variable or functions from other c or assemble files.\r
15  */\r
16 .import main\r
17 \r
18 /*\r
19  * default service routine\r
20  */\r
21 .global Reset_Handler\r
22 .global Misaligned_Access_Handler\r
23 .global Access_Error_Handler\r
24 .global Divided_By_Zero_Handler\r
25 .global Illegal_Handler\r
26 .global Privlege_Violation_Handler\r
27 .global Trace_Exection_Handler\r
28 .global Breakpoint_Exception_Handler\r
29 .global Unrecoverable_Error_Handler\r
30 .global Idly4_Error_Handler\r
31 .global Auto_INT_Handler\r
32 .global Auto_FINT_Handler\r
33 .global Reserved_HAI_Handler\r
34 .global Reserved_FP_Handler\r
35 .global TLB_Ins_Empty_Handler\r
36 .global TLB_Data_Empty_Handler\r
37 .global Default_handler\r
38 \r
39 .weak Reset_Handler\r
40 .weak Misaligned_Access_Handler\r
41 .weak Access_Error_Handler\r
42 .weak Divided_By_Zero_Handler\r
43 .weak Illegal_Handler\r
44 .weak Privlege_Violation_Handler\r
45 .weak Trace_Exection_Handler\r
46 .weak Breakpoint_Exception_Handler\r
47 .weak Unrecoverable_Error_Handler\r
48 .weak Idly4_Error_Handler\r
49 .weak Auto_INT_Handler\r
50 .weak Auto_FINT_Handler\r
51 .weak Reserved_HAI_Handler\r
52 .weak Reserved_FP_Handler\r
53 .weak TLB_Ins_Empty_Handler\r
54 .weak TLB_Data_Empty_Handler\r
55 .weak Default_handler\r
56 \r
57 \r
58 .export ckcpu_vsr_table /* Vector table base address. */\r
59 .section .exp_table,"ax",@progbits\r
60 /* Vector table space. */\r
61 $d:\r
62 .align 10\r
63 ckcpu_vsr_table:\r
64         .long Reset_Handler\r
65         .long Misaligned_Access_Handler\r
66         .long Access_Error_Handler\r
67         .long Divided_By_Zero_Handler\r
68         .long Illegal_Handler\r
69         .long Privlege_Violation_Handler\r
70         .long Trace_Exection_Handler\r
71         .long Breakpoint_Exception_Handler\r
72         .long Unrecoverable_Error_Handler\r
73         .long Idly4_Error_Handler\r
74         .long Auto_INT_Handler\r
75         .long Auto_FINT_Handler\r
76         .long Reserved_HAI_Handler\r
77         .long Reserved_FP_Handler\r
78         .long TLB_Ins_Empty_Handler\r
79         .long TLB_Data_Empty_Handler\r
80 \r
81 .rept 32\r
82         .long NOVIC_IRQ_Default_Handler\r
83 .endr\r
84 $t:\r
85 /* The ckcpu startup codes. */\r
86 .text\r
87 .align 2\r
88         /*\r
89          * This is the codes first entry point. This is where it all begins...\r
90          */\r
91 Reset_Handler:\r
92         /*\r
93          * Init psr value, enable exception, disable interrupt and fast interrupt.\r
94          * psr = 0x80000100\r
95          */\r
96         bgeni   r7, 31\r
97         bseti   r7, 30\r
98         bseti   r7, 29\r
99         bseti   r7, 8\r
100         mtcr    r7, psr\r
101 \r
102         /*\r
103          * Setup initial vector base table for interrupts and exceptions\r
104          */\r
105         lrw     a3, ckcpu_vsr_table\r
106         mtcr    a3, vbr\r
107         \r
108         /* Initialize the normal stack pointer from the linker definition. */\r
109     lrw     r0, g_top_irqstack\r
110     mov     sp, r0\r
111 \r
112 /*\r
113  *  The ranges of copy from/to are specified by following symbols\r
114  *    __etext: LMA of start of the section to copy from. Usually end of text\r
115  *    __data_start__: VMA of start of the section to copy to\r
116  *    __data_end__: VMA of end of the section to copy to\r
117  *\r
118  *  All addresses must be aligned to 4 bytes boundary.\r
119  */\r
120     lrw     r1, __erodata\r
121     lrw     r2, __data_start__\r
122     lrw     r3, __data_end__\r
123 \r
124     subu    r3, r2\r
125     cmpnei  r3, 0\r
126     bf      .L_loop0_done\r
127 \r
128 .L_loop0:\r
129     ldw     r0, (r1, 0)\r
130     stw     r0, (r2, 0)\r
131     addi    r1, 4\r
132     addi    r2, 4\r
133     subi    r3, 4\r
134     cmpnei  r3, 0\r
135     bt      .L_loop0\r
136 \r
137 .L_loop0_done:\r
138 \r
139 /*\r
140  *  The BSS section is specified by following symbols\r
141  *    __bss_start__: start of the BSS section.\r
142  *    __bss_end__: end of the BSS section.\r
143  *\r
144  *  Both addresses must be aligned to 4 bytes boundary.\r
145  */\r
146     lrw     r1, __bss_start__\r
147     lrw     r2, __bss_end__\r
148 \r
149     movi    r0, 0\r
150 \r
151     subu    r2, r1\r
152     cmpnei  r2, 0\r
153     bf      .L_loop1_done\r
154 \r
155 .L_loop1:\r
156     stw     r0, (r1, 0)\r
157     addi    r1, 4\r
158     subi    r2, 4\r
159     cmpnei  r2, 0\r
160     bt      .L_loop1\r
161 .L_loop1_done:\r
162         \r
163         jbsr    main\r
164         /* Should never get here. */\r
165 1:\r
166         br 1b\r
167 Misaligned_Access_Handler:\r
168 Access_Error_Handler:\r
169 Divided_By_Zero_Handler:\r
170 Illegal_Handler:\r
171 Privlege_Violation_Handler:\r
172 Trace_Exection_Handler:\r
173 Breakpoint_Exception_Handler:\r
174 Unrecoverable_Error_Handler:\r
175 Idly4_Error_Handler:\r
176 Auto_INT_Handler:\r
177 Auto_FINT_Handler:\r
178 Reserved_HAI_Handler:\r
179 Reserved_FP_Handler:\r
180 TLB_Ins_Empty_Handler:\r
181 TLB_Data_Empty_Handler:\r
182 Default_handler:\r
183         br Default_handler\r
184         rte\r
185 \r
186 .section .bss\r
187 \r
188     .align  2\r
189     .global g_intstackalloc\r
190     .global g_intstackbase\r
191     .global g_top_irqstack\r
192 g_intstackalloc:\r
193 g_intstackbase:\r
194     .space  4096\r
195 g_top_irqstack: