OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [libgloss/] [or32/] [crt0.S] - Blame information for rev 829

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 507 julius
/* crt0.S. C design runtime startup file.
2 207 jeremybenn
 
3
   Copyright (C) 2004, Jacob Bower
4
   Copyright (C) 2010, Embecosm Limited 
5 507 julius
   Copyright (C) 2011, ORSoC AB
6 207 jeremybenn
 
7
   Contributor Jeremy Bennett 
8 507 julius
   Contributor Julius Baxter  
9 207 jeremybenn
 
10
   This file is part of Newlib.
11
 
12
   The original work by Jacob Bower is provided as-is without any kind of
13
   warranty. Use it at your own risk!
14
 
15
   All subsequent work is bound by version 3 of the GPL as follows.
16
 
17
   This program is free software; you can redistribute it and/or modify it
18
   under the terms of the GNU General Public License as published by the Free
19
   Software Foundation; either version 3 of the License, or (at your option)
20
   any later version.
21
 
22
   This program is distributed in the hope that it will be useful, but WITHOUT
23
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
25
   more details.
26
 
27
   You should have received a copy of the GNU General Public License along
28
   with this program.  If not, see .            */
29
/* -------------------------------------------------------------------------- */
30
/* This program is commented throughout in a fashion suitable for processing
31
   with Doxygen.                                                              */
32
/* -------------------------------------------------------------------------- */
33
 
34
#include "spr-defs.h"
35
 
36
/* -------------------------------------------------------------------------- */
37 507 julius
/*!Macro to load a symbol's address into a register.
38 207 jeremybenn
 
39 507 julius
  @param[in] gpr  General purpose register to load address into.
40
  @param[in] symbol Name of symbol to load.                                   */
41 207 jeremybenn
/* -------------------------------------------------------------------------- */
42 507 julius
#define LOAD_SYMBOL_2_GPR(gpr,symbol)  \
43
        .global symbol ;               \
44
        l.movhi gpr, hi(symbol) ;      \
45
        l.ori   gpr, gpr, lo(symbol)
46 207 jeremybenn
 
47 507 julius
/* -------------------------------------------------------------------------- */
48
/*!Macro to handle exceptions.
49 207 jeremybenn
 
50 507 julius
  Load NPC into r3, EPCR into r4
51
                                                                              */
52 207 jeremybenn
/* -------------------------------------------------------------------------- */
53 507 julius
// Size of redzone + size of space required to store state
54 539 julius
// This value must match that in the support library or1k_exception_handler
55
// function
56
#define EXCEPTION_STACK_SIZE (128+128)
57 507 julius
 
58
#define CALL_EXCEPTION_HANDLER                          \
59
        l.addi  r1, r1, -EXCEPTION_STACK_SIZE;          \
60
        l.sw    4(r1), r3;                              \
61
        l.sw    8(r1), r4;                              \
62
        l.mfspr r3,r0,SPR_NPC;                          \
63 517 julius
        l.j     or1k_exception_handler;                 \
64 507 julius
        l.mfspr r4,r0,SPR_EPCR_BASE
65 207 jeremybenn
 
66
/* -------------------------------------------------------------------------- */
67
/*!Exception vectors                                                          */
68
/* -------------------------------------------------------------------------- */
69
        .section .vectors,"ax"
70
 
71
        /* 0x100: RESET exception */
72
        .org    0x100
73 399 jeremybenn
__reset:
74 507 julius
        l.movhi r0, 0
75
        l.movhi r1, 0
76
        l.movhi r2, 0
77
        l.movhi r3, 0
78
        l.movhi r4, 0
79
        l.movhi r5, 0
80
        l.movhi r6, 0
81
        l.movhi r7, 0
82
        l.movhi r8, 0
83
        l.movhi r9, 0
84
        l.movhi r10, 0
85
        l.movhi r11, 0
86
        l.movhi r12, 0
87
        l.movhi r13, 0
88
        l.movhi r14, 0
89
        l.movhi r15, 0
90
        l.movhi r16, 0
91
        l.movhi r17, 0
92
        l.movhi r18, 0
93
        l.movhi r19, 0
94
        l.movhi r20, 0
95
        l.movhi r21, 0
96
        l.movhi r22, 0
97
        l.movhi r23, 0
98
        l.movhi r24, 0
99
        l.movhi r25, 0
100
        l.movhi r26, 0
101
        l.movhi r27, 0
102
        l.movhi r28, 0
103
        l.movhi r29, 0
104
        l.movhi r30, 0
105
        l.movhi r31, 0
106
 
107
        /* Clear status register, set supervisor mode */
108
        l.ori r1, r0, SPR_SR_SM
109
        l.mtspr r0, r1, SPR_SR
110
        /* Clear timer mode register*/
111
        l.mtspr r0, r0, SPR_TTMR
112 207 jeremybenn
        /* Jump to program initialisation code */
113 507 julius
        LOAD_SYMBOL_2_GPR(r4, _start)
114
        l.jr    r4
115 207 jeremybenn
        l.nop
116
 
117
        .org    0x200
118 507 julius
        CALL_EXCEPTION_HANDLER
119 243 jeremybenn
 
120 207 jeremybenn
        /* 0x300: Data Page Fault exception */
121
        .org    0x300
122 507 julius
        CALL_EXCEPTION_HANDLER
123 207 jeremybenn
 
124
        /* 0x400: Insn Page Fault exception */
125
        .org    0x400
126 507 julius
        CALL_EXCEPTION_HANDLER
127 207 jeremybenn
 
128
        /* 0x500: Timer exception */
129
        .org    0x500
130 507 julius
        CALL_EXCEPTION_HANDLER
131 207 jeremybenn
 
132
        /* 0x600: Aligment exception */
133
        .org    0x600
134 507 julius
        CALL_EXCEPTION_HANDLER
135 207 jeremybenn
 
136
        /* 0x700: Illegal insn exception */
137
        .org    0x700
138 507 julius
        CALL_EXCEPTION_HANDLER
139 207 jeremybenn
 
140
        /* 0x800: External interrupt exception */
141
        .org    0x800
142 507 julius
        CALL_EXCEPTION_HANDLER
143 207 jeremybenn
 
144
        /* 0x900: DTLB miss exception */
145
        .org    0x900
146 507 julius
        CALL_EXCEPTION_HANDLER
147 207 jeremybenn
 
148
        /* 0xa00: ITLB miss exception */
149
        .org    0xa00
150 507 julius
        CALL_EXCEPTION_HANDLER
151 207 jeremybenn
 
152
        /* 0xb00: Range exception */
153
        .org    0xb00
154 507 julius
        CALL_EXCEPTION_HANDLER
155 207 jeremybenn
 
156
        /* 0xc00: Syscall exception */
157
        .org    0xc00
158 507 julius
        CALL_EXCEPTION_HANDLER
159 207 jeremybenn
 
160
        /* 0xd00: floating point exception */
161
        .org    0xd00
162 507 julius
        CALL_EXCEPTION_HANDLER
163 207 jeremybenn
 
164
        /* 0xe00: Trap exception */
165
        .org    0xe00
166 507 julius
        CALL_EXCEPTION_HANDLER
167 207 jeremybenn
 
168
        /* 0xf00: Reserved exceptions */
169
        .org    0xf00
170 507 julius
        CALL_EXCEPTION_HANDLER
171 207 jeremybenn
 
172
        .org    0x1000
173 507 julius
        CALL_EXCEPTION_HANDLER
174 207 jeremybenn
 
175
        .org    0x1100
176 507 julius
        CALL_EXCEPTION_HANDLER
177 207 jeremybenn
 
178
        .org    0x1200
179 507 julius
        CALL_EXCEPTION_HANDLER
180 207 jeremybenn
 
181
        .org    0x1300
182 507 julius
        CALL_EXCEPTION_HANDLER
183 207 jeremybenn
 
184
        .org    0x1400
185 507 julius
        CALL_EXCEPTION_HANDLER
186 207 jeremybenn
 
187
        .org    0x1500
188 507 julius
        CALL_EXCEPTION_HANDLER
189 207 jeremybenn
 
190
        .org    0x1600
191 507 julius
        CALL_EXCEPTION_HANDLER
192 207 jeremybenn
 
193
        .org    0x1700
194 507 julius
        CALL_EXCEPTION_HANDLER
195 207 jeremybenn
 
196
        .org    0x1800
197 507 julius
        CALL_EXCEPTION_HANDLER
198 207 jeremybenn
 
199
        .org    0x1900
200 507 julius
        CALL_EXCEPTION_HANDLER
201 207 jeremybenn
 
202
        .org    0x1a00
203 507 julius
        CALL_EXCEPTION_HANDLER
204 207 jeremybenn
 
205
        .org    0x1b00
206 507 julius
        CALL_EXCEPTION_HANDLER
207 207 jeremybenn
 
208
        .org    0x1c00
209 507 julius
        CALL_EXCEPTION_HANDLER
210 207 jeremybenn
 
211
        .org    0x1d00
212 507 julius
        CALL_EXCEPTION_HANDLER
213 207 jeremybenn
 
214
        .org    0x1e00
215 507 julius
        CALL_EXCEPTION_HANDLER
216 207 jeremybenn
 
217
        .org    0x1f00
218 507 julius
        CALL_EXCEPTION_HANDLER
219 207 jeremybenn
 
220
        /* Pad to the end */
221
        .org    0x1ffc
222
        l.nop
223
 
224
/* -------------------------------------------------------------------------- */
225
/*!Main entry point
226
 
227
   We initialise the stack and frame pointer first, before we set up the
228
   caches, since otherwise we'll need to disable the instruction cache when
229
   patching the bus error vector code.
230
 
231
   The remaining tasks are then:
232
   - optionally set up instruction and/or data caches
233
   - clear BSS
234
   - call global and static constructors
235
   - set up destructors to be called from exit
236
   - jump to the main function
237
   - call exit if the main function ever returns.
238
   - loop forever (should never get here)                                     */
239
/* -------------------------------------------------------------------------- */
240
        /* The stack grows down from the top of writable memory. */
241
        .section .data
242 507 julius
        .global stack
243
stack:  .space  4,0
244 207 jeremybenn
 
245
        .section .text
246
        .global _start
247
        .type   _start,@function
248
 
249 243 jeremybenn
 
250 507 julius
        /* Following externs from board-specific object passed at link time */
251
        .extern _board_mem_base
252
        .extern _board_mem_size
253
        .extern _board_uart_base
254 243 jeremybenn
 
255 507 julius
_start:
256
        /* Initialise stack and frame pointer (set to same value) */
257
        l.movhi r1,hi(_board_mem_base)
258
        l.ori   r1,r1,lo(_board_mem_base)
259
        l.lwz   r1,0(r1)
260
        l.movhi r2,hi(_board_mem_size)
261
        l.ori   r2,r2,lo(_board_mem_size)
262
        l.lwz   r2,0(r2)
263
        l.add   r1,r1,r2
264
        l.or    r2,r1,r1
265 207 jeremybenn
 
266 507 julius
        /* Store stack address in stack variable */
267 517 julius
        l.movhi r3,hi(stack)
268
        l.ori   r3,r3,lo(stack)
269
        l.sw    0(r3),r1
270 507 julius
 
271
        /* Initialise cache */
272
        /* TODO - potentially make this optional for simulation targets to save
273
        time during startup */
274 517 julius
        l.jal   or1k_cache_init
275 207 jeremybenn
        l.nop
276 226 julius
 
277 207 jeremybenn
        /* Clear BSS */
278 517 julius
.L10:   l.movhi r3,hi(__bss_start)
279
        l.ori   r3,r3,lo(__bss_start)
280
        l.movhi r4,hi(end)
281
        l.ori   r4,r4,lo(end)
282 207 jeremybenn
 
283 517 julius
.L1:    l.sw    (0)(r3),r0
284
        l.sfltu r3,r4
285 207 jeremybenn
        l.bf    .L1
286 517 julius
        l.addi  r3,r3,4         /* Delay slot */
287 207 jeremybenn
 
288 540 jeremybenn
        /* Reinitialize the reentrancy structure */
289
        l.jal   __impure_init
290
        l.nop
291
 
292 207 jeremybenn
        /* Call global and static constructors */
293 399 jeremybenn
        l.jal   __init
294 207 jeremybenn
        l.nop
295
 
296 517 julius
        /* Set up destructors to be called from exit if main ever returns */
297 399 jeremybenn
        l.movhi r3,hi(__fini)
298 243 jeremybenn
        l.jal   atexit
299 399 jeremybenn
        l.ori   r3,r3,lo(__fini)        /* Delay slot */
300 207 jeremybenn
 
301 507 julius
        /* Check if UART is to be initialised */
302
        l.movhi r4,hi(_board_uart_base)
303
        l.ori   r4,r4,lo(_board_uart_base)
304
        l.lwz   r4,0(r4)
305
        l.sfne  r4,r0           /* Is base set? If not, no UART */
306
        l.bnf   .L2
307
        l.or    r3,r0,r0
308
        l.jal   __uart_init
309 207 jeremybenn
        l.nop
310
 
311 507 julius
.L2:
312 207 jeremybenn
        /* Jump to main program entry point (argc = argv = envp = 0) */
313
        l.or    r3,r0,r0
314
        l.or    r4,r0,r0
315 243 jeremybenn
        l.jal   main
316 207 jeremybenn
        l.or    r5,r0,r0                /* Delay slot */
317
 
318
        /* If program exits, call exit routine */
319 399 jeremybenn
        l.jal   exit
320 207 jeremybenn
        l.addi  r3,r11,0                /* Delay slot */
321
 
322
        /* Loop forever */
323 507 julius
.L3:    l.j     .L3
324 207 jeremybenn
        l.nop
325
 
326
        .size   _start, .-_start

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.