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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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