OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [reset.S] - Blame information for rev 390

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

Line No. Rev Author Line
1 246 julius
#include "spr-defs.h"
2 2 marcus.erl
#include "board.h"
3
#include "mc.h"
4
 
5
        .extern _src_beg
6
        .extern _dst_beg
7
        .extern _dst_end
8 375 julius
        .extern int_main
9
        .extern tick_interrupt
10 2 marcus.erl
        .extern _crc32
11
 
12
        .global _align
13
        .global _calc_mycrc32
14
        .global _mycrc32
15
        .global _mysize
16
 
17
        .section .stack, "aw", @nobits
18
.space  STACK_SIZE
19
_stack:
20
        .section .crc
21
_mycrc32:
22
        .word   0xcccccccc
23
_mysize:
24
        .word 0xdddddddd
25
 
26
.if SELF_CHECK
27
_calc_mycrc32:
28
        l.addi  r3,r0,0
29
        l.movhi r4,hi(_calc_mycrc32)
30
        l.ori   r4,r4,lo(_calc_mycrc32)
31
        l.movhi r5,hi(_mysize)
32
        l.ori   r5,r5,lo(_mysize)
33
        l.lwz   r5,0(r5)
34
        l.addi  r1,r1,-4
35
        l.sw    0(r1),r9
36
 
37
        /* unsigned long crc32 (unsigned long crc, const unsigned char *buf, unsigned long len); */
38
        l.jal           _crc32
39
        l.nop
40
 
41
        l.movhi r3,hi(_mycrc32)
42
        l.ori   r3,r3,lo(_mycrc32)
43
        l.lwz   r3,0(r3)
44
 
45
        l.xor     r11,r3,r11
46
        l.lwz   r9,0(r1)
47
        l.jr    r9
48
        l.addi  r1,r1,4
49
.endif
50
 
51
        .org 0x100
52 140 julius
 
53 2 marcus.erl
.if IN_FLASH
54
        .section .reset, "ax"
55
.else
56
        .section .vectors, "ax"
57
.endif
58
 
59
_reset:
60
.if IN_FLASH
61
        l.movhi r3,hi(MC_BASE_ADDR)
62
        l.ori   r3,r3,MC_BA_MASK
63
        l.addi  r5,r0,0x00
64
        l.sw    0(r3),r5
65
.endif
66 246 julius
        l.movhi r0, 0
67
        /* Clear status register, set supervisor mode */
68
        l.ori r1, r0, SPR_SR_SM
69
        l.mtspr r0, r1, SPR_SR
70
        /* Clear timer  */
71
        l.mtspr r0, r0, SPR_TTMR
72
        /* Jump to start routine */
73 2 marcus.erl
        l.movhi r3,hi(_start)
74
        l.ori   r3,r3,lo(_start)
75
        l.jr    r3
76
        l.nop
77
 
78
.if IN_FLASH
79
        .section .vectors, "ax"
80 140 julius
        .org 0x200
81
.else
82
        .org (0x200 - 0x100 + _reset)
83
.endif
84
_buserr:
85 246 julius
.if 0
86
        /* Just trap */
87 140 julius
        l.trap 0
88 246 julius
.endif
89
        l.nop 0x1
90 140 julius
        l.j 0
91
        l.nop
92
 
93
 
94
.if IN_FLASH
95
        .section .vectors, "ax"
96 2 marcus.erl
        .org 0x500
97
.else
98
        .org (0x500 - 0x100 + _reset)
99
.endif
100 355 julius
_tickint:
101
#define TIMER_RELOAD_VALUE (SPR_TTMR_IE | SPR_TTMR_RT | ((IN_CLK/TICKS_PER_SEC) & SPR_TTMR_PERIOD))
102
        /* Simply load timer_ticks variable and increment */
103
        .extern _timer_ticks
104
        l.addi  r1, r1, -8
105
        l.sw    0(r1), r25
106
        l.sw    4(r1), r26
107 375 julius
        l.movhi r25, hi(timestamp)
108
        l.ori   r25, r25, lo(timestamp)
109 355 julius
        l.lwz   r26, 0(r25)                     /* Load variable addr.*/
110
        l.addi  r26, r26, 1                     /* Increment variable */
111
        l.sw    0(r25), r26                     /* Store variable */
112
        l.movhi r25, hi(TIMER_RELOAD_VALUE)     /* Load timer value */
113
        l.ori   r25, r25, lo(TIMER_RELOAD_VALUE)
114
        l.mtspr r0, r25, SPR_TTMR               /* Reset timer */
115
        l.lwz   r25, 0(r1)
116
        l.lwz   r26, 4(r1)
117
        l.addi  r1, r1, 8
118
        l.rfe
119 375 julius
 
120 2 marcus.erl
.if IN_FLASH
121
        .section .vectors, "ax"
122
        .org 0x600
123
.else
124
        .org (0x600 - 0x100 + _reset)
125
.endif
126 140 julius
_alignerr:
127 246 julius
.if 0
128 140 julius
        l.trap 0
129 246 julius
.endif
130
        l.nop 0x1
131 140 julius
        l.j 0
132
        l.nop
133
 
134
.if IN_FLASH
135
        .org 0x700
136
.else
137
        .org (0x700 - 0x100 + _reset)
138
.endif
139 246 julius
_illinsn:
140
.if 0
141 140 julius
        /* Just trap */
142
        l.trap 0
143 246 julius
.endif
144
        l.nop 0x1
145 140 julius
        l.j 0
146
        l.nop
147 2 marcus.erl
 
148 140 julius
 
149 2 marcus.erl
.if IN_FLASH
150
        .org 0x800
151
.else
152
        .org (0x800 - 0x100 + _reset)
153
.endif
154 140 julius
_userint:
155 2 marcus.erl
        l.addi  r1,r1,-128
156 246 julius
        l.sw    0x0(r1),r2
157
        l.addi  r2, r1, 128
158
        l.sw    0x4(r1), r3
159
        l.movhi r3,hi(_int_wrapper)
160
        l.ori   r3,r3,lo(_int_wrapper)
161
        l.jr    r3
162 2 marcus.erl
        l.nop
163
 
164
        .section .text
165
_start:
166
.if IN_FLASH
167 140 julius
/*        l.jal   _init_mc
168 2 marcus.erl
        l.nop
169 140 julius
*/
170 2 marcus.erl
        /* Wait for SDRAM */
171
        l.addi  r3,r0,0x1000
172
1:      l.sfeqi r3,0
173
        l.bnf   1b
174
        l.addi  r3,r3,-1
175
.endif
176
        /* Copy form flash to sram */
177
.if IN_FLASH
178
        l.movhi r3,hi(_src_beg)
179
        l.ori   r3,r3,lo(_src_beg)
180
        l.movhi r4,hi(_vec_start)
181
        l.ori   r4,r4,lo(_vec_start)
182
        l.movhi r5,hi(_vec_end)
183
        l.ori   r5,r5,lo(_vec_end)
184
        l.sub   r5,r5,r4
185
        l.sfeqi r5,0
186
        l.bf    2f
187
        l.nop
188
1:      l.lwz   r6,0(r3)
189
        l.sw    0(r4),r6
190
        l.addi  r3,r3,4
191
        l.addi  r4,r4,4
192
        l.addi  r5,r5,-4
193
        l.sfgtsi r5,0
194
        l.bf    1b
195
        l.nop
196
2:
197
        l.movhi r4,hi(_dst_beg)
198
        l.ori   r4,r4,lo(_dst_beg)
199
        l.movhi r5,hi(_dst_end)
200
        l.ori   r5,r5,lo(_dst_end)
201
1:      l.sfgeu r4,r5
202
        l.bf    1f
203
        l.nop
204
        l.lwz   r8,0(r3)
205
        l.sw    0(r4),r8
206
        l.addi  r3,r3,4
207
        l.bnf   1b
208
        l.addi  r4,r4,4
209
1:
210
        l.addi  r3,r0,0
211
        l.addi  r4,r0,0
212
3:
213
.endif
214
 
215 246 julius
 
216
        /* Instruction cache enable */
217
        /* Check if IC present and skip enabling otherwise */
218
        l.mfspr r24,r0,SPR_UPR
219
        l.andi  r26,r24,SPR_UPR_ICP
220
        l.sfeq  r26,r0
221
        l.bf    .L8
222
        l.nop
223
 
224
        /* Disable IC */
225
        l.mfspr r6,r0,SPR_SR
226
        l.addi  r5,r0,-1
227
        l.xori  r5,r5,SPR_SR_ICE
228
        l.and   r5,r6,r5
229
        l.mtspr r0,r5,SPR_SR
230
 
231
        /* Establish cache block size
232
        If BS=0, 16;
233
        If BS=1, 32;
234
        r14 contain block size
235
        */
236
        l.mfspr r24,r0,SPR_ICCFGR
237
        l.andi  r26,r24,SPR_ICCFGR_CBS
238
        l.srli  r28,r26,7
239
        l.ori   r30,r0,16
240
        l.sll   r14,r30,r28
241
 
242
        /* Establish number of cache sets
243
        r16 contains number of cache sets
244
        r28 contains log(# of cache sets)
245
        */
246
        l.andi  r26,r24,SPR_ICCFGR_NCS
247
        l.srli  r28,r26,3
248
        l.ori   r30,r0,1
249
        l.sll   r16,r30,r28
250
 
251
        /* Invalidate IC */
252
        l.addi  r6,r0,0
253
        l.sll   r5,r14,r28
254
 
255
.L7:
256
        l.mtspr r0,r6,SPR_ICBIR
257
        l.sfne  r6,r5
258
        l.bf    .L7
259
        l.add   r6,r6,r14
260
 
261
        /* Enable IC */
262
        l.mfspr r6,r0,SPR_SR
263
        l.ori   r6,r6,SPR_SR_ICE
264
        l.mtspr r0,r6,SPR_SR
265
        l.nop
266
        l.nop
267
        l.nop
268
        l.nop
269
        l.nop
270
        l.nop
271
        l.nop
272
        l.nop
273
 
274
.L8:
275
        /* Data cache enable */
276
        /* Check if DC present and skip enabling otherwise */
277
        l.mfspr r24,r0,SPR_UPR
278
        l.andi  r26,r24,SPR_UPR_DCP
279
        l.sfeq  r26,r0
280
        l.bf    .L10
281 2 marcus.erl
        l.nop
282 246 julius
        /* Disable DC */
283
        l.mfspr r6,r0,SPR_SR
284
        l.addi  r5,r0,-1
285
        l.xori  r5,r5,SPR_SR_DCE
286
        l.and   r5,r6,r5
287
        l.mtspr r0,r5,SPR_SR
288
        /* Establish cache block size
289
           If BS=0, 16;
290
           If BS=1, 32;
291
           r14 contain block size
292
        */
293
        l.mfspr r24,r0,SPR_DCCFGR
294
        l.andi  r26,r24,SPR_DCCFGR_CBS
295
        l.srli  r28,r26,7
296
        l.ori   r30,r0,16
297
        l.sll   r14,r30,r28
298
        /* Establish number of cache sets
299
           r16 contains number of cache sets
300
           r28 contains log(# of cache sets)
301
        */
302
        l.andi  r26,r24,SPR_DCCFGR_NCS
303
        l.srli  r28,r26,3
304
        l.ori   r30,r0,1
305
        l.sll   r16,r30,r28
306
        /* Invalidate DC */
307
        l.addi  r6,r0,0
308
        l.sll   r5,r14,r28
309
.L9:
310
        l.mtspr r0,r6,SPR_DCBIR
311
        l.sfne  r6,r5
312
        l.bf    .L9
313
        l.add   r6,r6,r14
314
        /* Enable DC */
315
        l.mfspr r6,r0,SPR_SR
316
        l.ori   r6,r6,SPR_SR_DCE
317
        l.mtspr r0,r6,SPR_SR
318 2 marcus.erl
 
319 246 julius
.L10:
320
        /* Set up stack */
321 2 marcus.erl
        l.movhi r1,hi(_stack-4)
322
        l.ori   r1,r1,lo(_stack-4)
323
        l.addi  r2,r0,-3
324
        l.and   r1,r1,r2
325 246 julius
/*      l.or    r2, r1, r1 - remove this helped with odd UART output problem?!*/
326 140 julius
 
327 375 julius
        l.movhi r3,hi(main)
328
        l.ori   r3,r3,lo(main)
329 246 julius
        l.jr    r3
330
        l.nop
331 140 julius
 
332 2 marcus.erl
_int_wrapper:
333
 
334 246 julius
        l.sw    0x8(r1), r4
335
        l.sw    0xc(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
 
363 375 julius
        l.movhi r3,hi(int_main)
364
        l.ori   r3,r3,lo(int_main)
365 2 marcus.erl
        l.jalr  r3
366
        l.nop
367
 
368 246 julius
        l.lwz   r3,0x4(r1)
369 2 marcus.erl
        l.lwz   r4,0x8(r1)
370
        l.lwz   r5,0xc(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 246 julius
        l.lwz   r31,0x74(r1)
397 2 marcus.erl
 
398 246 julius
        l.lwz   r2, 0x0(r1)
399 2 marcus.erl
        l.addi  r1,r1,128
400
        l.rfe
401
        l.nop
402 246 julius
 
403 2 marcus.erl
 
404
_align:
405
        l.sw    0x0c(r1),r3
406
        l.sw    0x10(r1),r4
407
        l.sw    0x14(r1),r5
408
        l.sw    0x18(r1),r6
409
        l.sw    0x1c(r1),r7
410
        l.sw    0x20(r1),r8
411
        l.sw    0x24(r1),r9
412
        l.sw    0x28(r1),r10
413
        l.sw    0x2c(r1),r11
414
        l.sw    0x30(r1),r12
415
        l.sw    0x34(r1),r13
416
        l.sw    0x38(r1),r14
417
        l.sw    0x3c(r1),r15
418
        l.sw    0x40(r1),r16
419
        l.sw    0x44(r1),r17
420
        l.sw    0x48(r1),r18
421
        l.sw    0x4c(r1),r19
422
        l.sw    0x50(r1),r20
423
        l.sw    0x54(r1),r21
424
        l.sw    0x58(r1),r22
425
        l.sw    0x5c(r1),r23
426
        l.sw    0x60(r1),r24
427
        l.sw    0x64(r1),r25
428
        l.sw    0x68(r1),r26
429
        l.sw    0x6c(r1),r27
430
        l.sw    0x70(r1),r28
431
        l.sw    0x74(r1),r29
432
        l.sw    0x78(r1),r30
433
        l.sw    0x7c(r1),r31
434
 
435
        l.mfspr r2,r0,SPR_EEAR_BASE /* Load the efective addres */
436
        l.mfspr r5,r0,SPR_EPCR_BASE /* Load the insn address */
437
 
438
        l.lwz   r3,0(r5)    /* Load insn */
439
        l.srli  r4,r3,26    /* Shift left to get the insn opcode */
440
 
441
        l.sfeqi r4,0x00     /* Check if the load/store insn is in delay slot */
442
        l.bf    jmp
443
        l.sfeqi r4,0x01
444
        l.bf    jmp
445
        l.sfeqi r4,0x03
446
        l.bf    jmp
447
        l.sfeqi r4,0x04
448
        l.bf    jmp
449
        l.sfeqi r4,0x11
450
        l.bf    jr
451
        l.sfeqi r4,0x12
452
        l.bf    jr
453
        l.nop
454
        l.j     1f
455
        l.addi  r5,r5,4     /* Increment PC to get return insn address */
456
 
457
jmp:
458
        l.slli  r4,r3,6     /* Get the signed extended jump length */
459
        l.srai  r4,r4,4
460
 
461
        l.lwz   r3,4(r5)      /* Load the real load/store insn */
462
 
463
        l.add   r5,r5,r4      /* Calculate jump target address */
464
 
465
        l.j     1f
466
        l.srli  r4,r3,26    /* Shift left to get the insn opcode */
467
 
468
jr:
469
        l.slli  r4,r3,9     /* Shift to get the reg nb */
470
        l.andi  r4,r4,0x7c
471
 
472
        l.lwz   r3,4(r5)    /* Load the real load/store insn */
473
 
474
        l.add   r4,r4,r1    /* Load the jump register value from the stack */
475
        l.lwz   r5,0(r4)
476
 
477
        l.srli  r4,r3,26    /* Shift left to get the insn opcode */
478
 
479
 
480
1:      l.mtspr r0,r5,SPR_EPCR_BASE
481
 
482
        l.sfeqi r4,0x26
483
        l.bf    lhs
484
        l.sfeqi r4,0x25
485
        l.bf    lhz
486
        l.sfeqi r4,0x22
487
        l.bf    lws
488
        l.sfeqi r4,0x21
489
        l.bf    lwz
490
        l.sfeqi r4,0x37
491
        l.bf    sh
492
        l.sfeqi r4,0x35
493
        l.bf    sw
494
        l.nop
495
 
496
1:      l.j     1b      /* I don't know what to do */
497
        l.nop
498
 
499
lhs:    l.lbs   r5,0(r2)
500
        l.slli  r5,r5,8
501
        l.lbz   r6,1(r2)
502
        l.or    r5,r5,r6
503
        l.srli  r4,r3,19
504
        l.andi  r4,r4,0x7c
505
        l.add   r4,r4,r1
506
        l.j     align_end
507
        l.sw    0(r4),r5
508
 
509
lhz:    l.lbz   r5,0(r2)
510
        l.slli  r5,r5,8
511
        l.lbz   r6,1(r2)
512
        l.or    r5,r5,r6
513
        l.srli  r4,r3,19
514
        l.andi  r4,r4,0x7c
515
        l.add   r4,r4,r1
516
        l.j     align_end
517
        l.sw    0(r4),r5
518
 
519
lws:    l.lbs   r5,0(r2)
520
        l.slli  r5,r5,24
521
        l.lbz   r6,1(r2)
522
        l.slli  r6,r6,16
523
        l.or    r5,r5,r6
524
        l.lbz   r6,2(r2)
525
        l.slli  r6,r6,8
526
        l.or    r5,r5,r6
527
        l.lbz   r6,3(r2)
528
        l.or    r5,r5,r6
529
        l.srli  r4,r3,19
530
        l.andi  r4,r4,0x7c
531
        l.add   r4,r4,r1
532
        l.j     align_end
533
        l.sw    0(r4),r5
534
 
535
lwz:    l.lbz   r5,0(r2)
536
        l.slli  r5,r5,24
537
        l.lbz   r6,1(r2)
538
        l.slli  r6,r6,16
539
        l.or    r5,r5,r6
540
        l.lbz   r6,2(r2)
541
        l.slli  r6,r6,8
542
        l.or    r5,r5,r6
543
        l.lbz   r6,3(r2)
544
        l.or    r5,r5,r6
545
        l.srli  r4,r3,19
546
        l.andi  r4,r4,0x7c
547
        l.add   r4,r4,r1
548
        l.j     align_end
549
        l.sw    0(r4),r5
550
 
551
sh:
552
        l.srli  r4,r3,9
553
        l.andi  r4,r4,0x7c
554
        l.add   r4,r4,r1
555
        l.lwz   r5,0(r4)
556
        l.sb    1(r2),r5
557
        l.srli  r5,r5,8
558
        l.j     align_end
559
        l.sb    0(r2),r5
560
 
561
sw:
562
        l.srli  r4,r3,9
563
        l.andi  r4,r4,0x7c
564
        l.add   r4,r4,r1
565
        l.lwz   r5,0(r4)
566
        l.sb    3(r2),r5
567
        l.srli  r5,r5,8
568
        l.sb    2(r2),r5
569
        l.srli  r5,r5,8
570
        l.sb    1(r2),r5
571
        l.srli  r5,r5,8
572
        l.j     align_end
573
        l.sb    0(r2),r5
574
 
575
align_end:
576
        l.lwz   r2,0x08(r1)
577
        l.lwz   r3,0x0c(r1)
578
        l.lwz   r4,0x10(r1)
579
        l.lwz   r5,0x14(r1)
580
        l.lwz   r6,0x18(r1)
581
        l.lwz   r7,0x1c(r1)
582
        l.lwz   r8,0x20(r1)
583
        l.lwz   r9,0x24(r1)
584
        l.lwz   r10,0x28(r1)
585
        l.lwz   r11,0x2c(r1)
586
        l.lwz   r12,0x30(r1)
587
        l.lwz   r13,0x34(r1)
588
        l.lwz   r14,0x38(r1)
589
        l.lwz   r15,0x3c(r1)
590
        l.lwz   r16,0x40(r1)
591
        l.lwz   r17,0x44(r1)
592
        l.lwz   r18,0x48(r1)
593
        l.lwz   r19,0x4c(r1)
594
        l.lwz   r20,0x50(r1)
595
        l.lwz   r21,0x54(r1)
596
        l.lwz   r22,0x58(r1)
597
        l.lwz   r23,0x5c(r1)
598
        l.lwz   r24,0x60(r1)
599
        l.lwz   r25,0x64(r1)
600
        l.lwz   r26,0x68(r1)
601
        l.lwz   r27,0x6c(r1)
602
        l.lwz   r28,0x70(r1)
603
        l.lwz   r29,0x74(r1)
604
        l.lwz   r30,0x78(r1)
605
        l.mfspr r31,r0,0x40
606
        l.lwz   r31,0x7c(r1)
607
        l.addi  r1,r1,128
608
        l.rfe

powered by: WebSVN 2.1.0

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