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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [drivers/] [or1200/] [crt0.S] - Blame information for rev 522

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 349 julius
#include "spr-defs.h"
2
#include "board.h"
3
 
4
/* ======================================================= [ macros ] === */
5
 
6 470 julius
#define REDZONE 128
7
#define EXCEPTION_STACK_SIZE (128 + REDZONE)
8
 
9 349 julius
#define CLEAR_GPR(gpr) \
10
        l.or    gpr, r0, r0
11
 
12
#define ENTRY(symbol)    \
13
        .global symbol ; \
14
symbol:
15
 
16
#define LOAD_SYMBOL_2_GPR(gpr,symbol)  \
17
        .global symbol ;               \
18
        l.movhi gpr, hi(symbol) ;      \
19
        l.ori   gpr, gpr, lo(symbol)
20
 
21
        // Really goes to configurable interrupt handler
22 470 julius
#define EXCEPTION_HANDLER            \
23
        l.addi  r1, r1, -EXCEPTION_STACK_SIZE;          \
24 349 julius
        l.sw    4(r1), r3;             \
25
        l.sw    8(r1), r4;             \
26
        l.mfspr r3,r0,SPR_NPC;          \
27
        l.mfspr r4,r0,SPR_EPCR_BASE;   \
28
        l.j default_exception_handler; \
29
        l.nop
30
 
31
/* =================================================== [ exceptions ] === */
32
        .section .vectors, "ax"
33
 
34
/* ---[ 0x100: RESET exception ]----------------------------------------- */
35
        .org 0x100
36
        l.movhi r0, 0
37 485 julius
        l.movhi r1, 0
38
        l.movhi r2, 0
39
        l.movhi r3, 0
40
        l.movhi r4, 0
41
        l.movhi r5, 0
42
        l.movhi r6, 0
43
        l.movhi r7, 0
44
        l.movhi r8, 0
45
        l.movhi r9, 0
46
        l.movhi r10, 0
47
        l.movhi r11, 0
48
        l.movhi r12, 0
49
        l.movhi r13, 0
50
        l.movhi r14, 0
51
        l.movhi r15, 0
52
        l.movhi r16, 0
53
        l.movhi r17, 0
54
        l.movhi r18, 0
55
        l.movhi r19, 0
56
        l.movhi r20, 0
57
        l.movhi r21, 0
58
        l.movhi r22, 0
59
        l.movhi r23, 0
60
        l.movhi r24, 0
61
        l.movhi r25, 0
62
        l.movhi r26, 0
63
        l.movhi r27, 0
64
        l.movhi r28, 0
65
        l.movhi r29, 0
66
        l.movhi r30, 0
67
        l.movhi r31, 0
68 349 julius
        /* Clear status register, set supervisor mode */
69
        l.ori r1, r0, SPR_SR_SM
70
        l.mtspr r0, r1, SPR_SR
71
        /* Clear timer  */
72
        l.mtspr r0, r0, SPR_TTMR
73
        /* Early Stack initilization */
74
        LOAD_SYMBOL_2_GPR(r1, _stack)
75
        l.addi  r2, r0, -3
76
        l.and   r1, r1, r2
77
 
78
        /* Jump to program initialisation code */
79
        LOAD_SYMBOL_2_GPR(r4, _start)
80
        l.jr    r4
81
        l.nop
82
 
83
/* ---[ 0x200: BUS exception ]------------------------------------------- */
84
        .org 0x200
85 470 julius
        EXCEPTION_HANDLER
86 349 julius
 
87
/* ---[ 0x300: Data Page Fault exception ]------------------------------- */
88
        .org 0x300
89 470 julius
        EXCEPTION_HANDLER
90 349 julius
 
91
/* ---[ 0x400: Insn Page Fault exception ]------------------------------- */
92
        .org 0x400
93 470 julius
        EXCEPTION_HANDLER
94 349 julius
 
95
/* ---[ 0x500: Timer exception ]----------------------------------------- */
96
        .org 0x500
97 488 julius
        EXCEPTION_HANDLER
98
 
99 349 julius
/* ---[ 0x600: Aligment exception ]-------------------------------------- */
100
        .org 0x600
101 470 julius
        EXCEPTION_HANDLER
102 349 julius
 
103
/* ---[ 0x700: Illegal insn exception ]---------------------------------- */
104
        .org 0x700
105 470 julius
        EXCEPTION_HANDLER
106 349 julius
 
107
/* ---[ 0x800: External interrupt exception ]---------------------------- */
108
        .org 0x800
109 470 julius
        EXCEPTION_HANDLER
110 349 julius
 
111
/* ---[ 0x900: DTLB miss exception ]------------------------------------- */
112
        .org 0x900
113 470 julius
        EXCEPTION_HANDLER
114 349 julius
 
115
/* ---[ 0xa00: ITLB miss exception ]------------------------------------- */
116
        .org 0xa00
117 470 julius
        EXCEPTION_HANDLER
118
 
119 349 julius
/* ---[ 0xb00: Range exception ]----------------------------------------- */
120
        .org 0xb00
121 470 julius
        EXCEPTION_HANDLER
122 349 julius
 
123
/* ---[ 0xc00: Syscall exception ]--------------------------------------- */
124
        .org 0xc00
125 470 julius
        EXCEPTION_HANDLER
126 349 julius
 
127 470 julius
/* ---[ 0xd00: FPU exception ]------------------------------------------- */
128 349 julius
        .org 0xd00
129 470 julius
        EXCEPTION_HANDLER
130 349 julius
 
131
/* ---[ 0xe00: Trap exception ]------------------------------------------ */
132
        .org 0xe00
133 470 julius
        EXCEPTION_HANDLER
134 349 julius
 
135 470 julius
/* ---[ 0xf00 - 0x1400: Reserved exceptions ]---------------------------- */
136
/*
137 349 julius
        .org 0xf00
138 470 julius
        EXCEPTION_HANDLER
139
 
140 349 julius
        .org 0x1000
141 470 julius
        EXCEPTION_HANDLER
142 349 julius
 
143
        .org 0x1100
144 470 julius
        EXCEPTION_HANDLER
145 349 julius
 
146
        .org 0x1200
147 470 julius
        EXCEPTION_HANDLER
148 349 julius
 
149
        .org 0x1300
150 470 julius
        EXCEPTION_HANDLER
151 349 julius
 
152
        .org 0x1400
153 470 julius
        EXCEPTION_HANDLER
154 349 julius
 
155 470 julius
*/
156
/* ---[ 0x1500 - 0x1800: Implementation-specific exceptions ]------------ */
157
/*
158 349 julius
        .org 0x1500
159 470 julius
        EXCEPTION_HANDLER
160 349 julius
 
161
        .org 0x1600
162 470 julius
        EXCEPTION_HANDLER
163 349 julius
 
164
        .org 0x1700
165 470 julius
        EXCEPTION_HANDLER
166 349 julius
 
167
        .org 0x1800
168 470 julius
        EXCEPTION_HANDLER
169
*/
170
/* ---[ 0x1500 - 0x1F00: Custom exceptions ]----------------------------- */
171
/*
172 349 julius
        .org 0x1900
173 470 julius
        EXCEPTION_HANDLER
174 349 julius
 
175
        .org 0x1a00
176 470 julius
        EXCEPTION_HANDLER
177 349 julius
 
178
        .org 0x1b00
179 470 julius
        EXCEPTION_HANDLER
180 349 julius
 
181
        .org 0x1c00
182 470 julius
        EXCEPTION_HANDLER
183 349 julius
 
184
        .org 0x1d00
185 470 julius
        EXCEPTION_HANDLER
186 349 julius
 
187
        .org 0x1e00
188 470 julius
        EXCEPTION_HANDLER
189 349 julius
 
190
        .org 0x1f00
191 470 julius
        EXCEPTION_HANDLER
192 349 julius
*/
193
 
194
/* ========================================================= [ entry ] === */
195
        .section .text
196
 
197
ENTRY(_start)
198
 
199 489 julius
 
200
 
201 349 julius
        /* Instruction cache enable */
202
        /* Check if IC present and skip enabling otherwise */
203
        l.mfspr r24,r0,SPR_UPR
204
        l.andi  r26,r24,SPR_UPR_ICP
205
        l.sfeq  r26,r0
206
        l.bf    .L8
207
        l.nop
208
 
209
        /* Disable IC */
210
        l.mfspr r6,r0,SPR_SR
211
        l.addi  r5,r0,-1
212
        l.xori  r5,r5,SPR_SR_ICE
213
        l.and   r5,r6,r5
214
        l.mtspr r0,r5,SPR_SR
215
 
216
        /* Establish cache block size
217
        If BS=0, 16;
218
        If BS=1, 32;
219
        r14 contain block size
220
        */
221
        l.mfspr r24,r0,SPR_ICCFGR
222
        l.andi  r26,r24,SPR_ICCFGR_CBS
223
        l.srli  r28,r26,7
224
        l.ori   r30,r0,16
225
        l.sll   r14,r30,r28
226
 
227
        /* Establish number of cache sets
228
        r16 contains number of cache sets
229
        r28 contains log(# of cache sets)
230
        */
231
        l.andi  r26,r24,SPR_ICCFGR_NCS
232
        l.srli  r28,r26,3
233
        l.ori   r30,r0,1
234
        l.sll   r16,r30,r28
235
 
236
        /* Invalidate IC */
237
        l.addi  r6,r0,0
238
        l.sll   r5,r14,r28
239
 
240
.L7:
241
        l.mtspr r0,r6,SPR_ICBIR
242
        l.sfne  r6,r5
243
        l.bf    .L7
244
        l.add   r6,r6,r14
245
 
246
        /* Enable IC */
247
        l.mfspr r6,r0,SPR_SR
248
        l.ori   r6,r6,SPR_SR_ICE
249
        l.mtspr r0,r6,SPR_SR
250
        l.nop
251
        l.nop
252
        l.nop
253
        l.nop
254
        l.nop
255
        l.nop
256
        l.nop
257
        l.nop
258
 
259
.L8:
260
        /* Data cache enable */
261
        /* Check if DC present and skip enabling otherwise */
262
        l.mfspr r24,r0,SPR_UPR
263
        l.andi  r26,r24,SPR_UPR_DCP
264
        l.sfeq  r26,r0
265
        l.bf    .L10
266
        l.nop
267
        /* Disable DC */
268
        l.mfspr r6,r0,SPR_SR
269
        l.addi  r5,r0,-1
270
        l.xori  r5,r5,SPR_SR_DCE
271
        l.and   r5,r6,r5
272
        l.mtspr r0,r5,SPR_SR
273
        /* Establish cache block size
274
           If BS=0, 16;
275
           If BS=1, 32;
276
           r14 contain block size
277
        */
278
        l.mfspr r24,r0,SPR_DCCFGR
279
        l.andi  r26,r24,SPR_DCCFGR_CBS
280
        l.srli  r28,r26,7
281
        l.ori   r30,r0,16
282
        l.sll   r14,r30,r28
283
        /* Establish number of cache sets
284
           r16 contains number of cache sets
285
           r28 contains log(# of cache sets)
286
        */
287
        l.andi  r26,r24,SPR_DCCFGR_NCS
288
        l.srli  r28,r26,3
289
        l.ori   r30,r0,1
290
        l.sll   r16,r30,r28
291
        /* Invalidate DC */
292
        l.addi  r6,r0,0
293
        l.sll   r5,r14,r28
294
.L9:
295
        l.mtspr r0,r6,SPR_DCBIR
296
        l.sfne  r6,r5
297
        l.bf    .L9
298
        l.add   r6,r6,r14
299
        /* Enable DC */
300
        l.mfspr r6,r0,SPR_SR
301
        l.ori   r6,r6,SPR_SR_DCE
302
        l.mtspr r0,r6,SPR_SR
303
 
304
.L10:
305
 
306
        /* Clear BSS */
307 475 julius
        LOAD_SYMBOL_2_GPR(r28, _bss_start)
308
        LOAD_SYMBOL_2_GPR(r30, _bss_end)
309 349 julius
1:
310
        l.sw    (0)(r28), r0
311
        l.sfltu r28, r30
312
        l.bf    1b
313
        l.addi  r28, r28, 4
314
 
315
        /* Initialise UART in a C function */
316
        /*l.jal    _uart_init
317
        l.nop*/
318
 
319
        /* Jump to main program entry point (argc = argv = 0) */
320
        CLEAR_GPR(r3)
321
        CLEAR_GPR(r4)
322 373 julius
        l.jal   main
323 349 julius
        l.nop
324
 
325
        /* If program exits, call exit routine */
326
        l.addi  r3, r11, 0
327 373 julius
        l.jal   exit
328 349 julius
        l.nop
329
 
330
 
331
/* ====================================== [ default exception handler ] === */
332
 
333
default_exception_handler:
334
        l.sw    0x00(r1), r2
335
        l.sw    0x0c(r1), r5
336
        l.sw    0x10(r1), r6
337
        l.sw    0x14(r1), r7
338
        l.sw    0x18(r1), r8
339
        l.sw    0x1c(r1), r9
340
        l.sw    0x20(r1), r10
341
        l.sw    0x24(r1), r11
342
        l.sw    0x28(r1), r12
343
        l.sw    0x2c(r1), r13
344
        l.sw    0x30(r1), r14
345
        l.sw    0x34(r1), r15
346
        l.sw    0x38(r1), r16
347
        l.sw    0x3c(r1), r17
348
        l.sw    0x40(r1), r18
349
        l.sw    0x44(r1), r19
350
        l.sw    0x48(r1), r20
351
        l.sw    0x4c(r1), r21
352
        l.sw    0x50(r1), r22
353
        l.sw    0x54(r1), r23
354
        l.sw    0x58(r1), r24
355
        l.sw    0x5c(r1), r25
356
        l.sw    0x60(r1), r26
357
        l.sw    0x64(r1), r27
358
        l.sw    0x68(r1), r28
359
        l.sw    0x6c(r1), r29
360
        l.sw    0x70(r1), r30
361
        l.sw    0x74(r1), r31
362
        l.sw    0x78(r1), r32
363
 
364 373 julius
        l.jal   default_exception_handler_c
365 349 julius
        l.nop
366
 
367
        l.lwz    r2, 0x00(r1)
368
        l.lwz    r3, 0x04(r1)
369
        l.lwz    r4, 0x08(r1)
370
        l.lwz    r5, 0x0c(r1)
371
        l.lwz    r6, 0x10(r1)
372
        l.lwz    r7, 0x14(r1)
373
        l.lwz    r8, 0x18(r1)
374
        l.lwz    r9, 0x1c(r1)
375
        l.lwz    r10, 0x20(r1)
376
        l.lwz    r11, 0x24(r1)
377
        l.lwz    r12, 0x28(r1)
378
        l.lwz    r13, 0x2c(r1)
379
        l.lwz    r14, 0x30(r1)
380
        l.lwz    r15, 0x34(r1)
381
        l.lwz    r16, 0x38(r1)
382
        l.lwz    r17, 0x3c(r1)
383
        l.lwz    r18, 0x40(r1)
384
        l.lwz    r19, 0x44(r1)
385
        l.lwz    r20, 0x48(r1)
386
        l.lwz    r21, 0x4c(r1)
387
        l.lwz    r22, 0x50(r1)
388
        l.lwz    r23, 0x54(r1)
389
        l.lwz    r24, 0x58(r1)
390
        l.lwz    r25, 0x5c(r1)
391
        l.lwz    r26, 0x60(r1)
392
        l.lwz    r27, 0x64(r1)
393
        l.lwz    r28, 0x68(r1)
394
        l.lwz    r29, 0x6c(r1)
395
        l.lwz    r30, 0x70(r1)
396
        l.lwz    r31, 0x74(r1)
397
        l.lwz    r32, 0x78(r1)
398
 
399 470 julius
        l.addi  r1, r1, EXCEPTION_STACK_SIZE
400 349 julius
 
401
        l.rfe
402
        l.nop
403
 

powered by: WebSVN 2.1.0

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