-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.S
executable file
·535 lines (483 loc) · 18.9 KB
/
entry.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/* $Id: entry.S,v 1.4 2001/03/01 05:02:29 honda Exp $
*
* This file is originally written by Niibe Yutaka at GNU/Linux on SuperH
* Project
*
* Modifications for the uITRON4.0 specification OS "TOPPERS" by Shinya Honda
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file "COPYING.LIB" in the main
* directory of this archive for more details.
*
* 常にバンク1のレジスタをgdbに返す。バンクr0のレジスタは破壊するが、
* スタックを使用しないため、スタックポインタの設定ミスにも対応
*
*/
/*
* gdb-sh-stub/entry.S
*
* Some code was taken from sh-stub.c of GDB 4.18.
*
* Copyright (C) 1999, 2000 Niibe Yutaka
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file "COPYING.LIB" in the main
* directory of this archive for more details.
*
*/
#include "linkage.h"
#include "config.h"
#if defined(__sh3__)
TRA = 0xffffffd0
EXPEVT = 0xffffffd4
INTEVT = 0xffffffd8
INTEVT2 = 0xa4000000
TMU0_TCR = 0xfffffe9c
#define CCR 0xffffffec /* Cache Control Register */
#define CCR_CACHE_DISABLE 0x008 /* Flush the cache, disable */
#define CCR_CACHE_INIT 0x0 /* disable */
#elif defined(__SH4__)
TRA = 0xff000020
EXPEVT = 0xff000024
INTEVT = 0xff000028
TMU0_TCR = 0xffd80010
#define CCR 0xFF00001C /* Cache Control Register */
#define CCR_CACHE_DISABLE 0x0808 /* Flush the cache, disable */
#define CCR_CACHE_INIT 0x0 /* disable */
#endif
#if defined(CONFIG_CARD_E09A)
.global _PCE_header
.section .text
.align 2
_PCE_header:
.ascii "SEIKO EPSON CARD-PCE"
.long 0
.long -1409089536
.long _start
.ident "GCC: (GNU) 2.95.1 19990816 (release)"
#endif
.align 2
.global _start
.section .text
ENTRY(start)
/* Disable cache */
mov.l CCR_A,r1 /* CCR Address */
mov.l CCR_DISABLE,r0 /* CCR Data */
mov.l r0,@r1
/* Initialize BSC */
mov.l 1f,r0
jsr @r0
nop
/* Initialize cache */
mov.l CCR_A,r1 /* CCR Address */
mov.l CCR_D,r0 /* CCR Data */
mov.l r0,@r1
/* Initialize VBR */
mov.l VBR_INIT,r0
ldc r0,vbr
/* SR: MD=1, BL=0, RB=0 */
mov.l INITIAL_SR,r0
ldc r0,sr
mov.l INITIAL_STACK,r0
mov r0,r15
/* Initialize Serial Port */
mov.l 2f,r0
jsr @r0
nop
/* Initialize BSS */
mov.l 4f,r1
add #4,r1
mov.l 5f,r2
mov #0,r0
9: cmp/hs r2,r1
bf/s 9b ! while (r1 < r2)
mov.l r0,@-r2
/* Initialize Data */
mov.l 6f,r0
mov.l 7f,r1
cmp/eq r0,r1
bt 11f
mov.l 8f,r2
mov #4,r3
10:
mov.l @r0+,r4
mov.l r4,@r2
cmp/hs r1,r0
bf/s 10b
add r3,r2
/* Jump to GDB Stub */
11: mov.l 3f,r0
jmp @r0
nop
.balign 4
1: .long SYMBOL_NAME(init_bsc)
2: .long SYMBOL_NAME(init_serial)
3: .long SYMBOL_NAME(start_gdbstub)
4: .long SYMBOL_NAME(_bss_start)
5: .long SYMBOL_NAME(_bss_end)
6: .long SYMBOL_NAME(_idata_start)
7: .long SYMBOL_NAME(_idata_end)
8: .long SYMBOL_NAME(_data_start)
CCR_A: .long CCR
CCR_DISABLE:
.long CCR_CACHE_DISABLE
CCR_D: .long CCR_CACHE_INIT
INITIAL_SR:
.long 0x40000000 /* MD=1, RD=0, BL=0 */
INITIAL_STACK:
.long SYMBOL_NAME(stub_stack)
VBR_INIT:
.long SYMBOL_NAME(_text)
#ifdef CONFIG_CARD_E09A
LED_CON:
.long 0xB1000780
LED_ADD:
.long 0xBBC00080
LED_INIT:
.long 0x00000080
LED_DATA:
.word 0xf0f0
#endif
!
!
.balign 256,0,256
general_exception:
mov.l 1f,r1
bra do_exception
mov.l @r1,r1
.balign 4
1: .long EXPEVT
!
!
.balign 1024,0,1024
tlb_miss:
mov.l 1f,r1
bra do_exception
mov.l @r1,r1
!
.balign 512,0,512
interrupt:
mov.l 2f,r1
bra do_exception
mov.l @r1,r1
.balign 4
1: .long EXPEVT
#ifdef CONFIG_SH7709
2: .long INTEVT2
#else /* CONFIG_SH77708 */
2: .long INTEVT
#endif
!
!
do_exception:
shlr2 r1
shlr2 r1
shlr r1
mov.l 1f,r0
mov.l r1,@r0
shll2 r1
mov.l 2f,r0
add r0,r1
mov.l @r1,r1
jmp @r1
nop
.balign 4
1: .long SYMBOL_NAME(exception)
2: .long _exception_handling_table
saveRegisters:
ldc r0,r0_bank
mov.l L_reg, r0
mov.l r2, @(0x08, r0) ! save R2
stc r0_bank,r2 ! pop R3
mov.l r2, @r0 ! save R0
mov.l r1, @(0x04, r0) ! save R1
mov.l r3, @(0x0c, r0) ! save R3
mov.l r4, @(0x10, r0) ! save R4
mov.l r5, @(0x14, r0) ! save R5
mov.l r6, @(0x18, r0) ! save R6
mov.l r7, @(0x1c, r0) ! save R7
mov.l r8, @(0x20, r0) ! save R8
mov.l r9, @(0x24, r0) ! save R9
mov.l r10, @(0x28, r0) ! save R10
mov.l r11, @(0x2c, r0) ! save R11
mov.l r12, @(0x30, r0) ! save R12
mov.l r13, @(0x34, r0) ! save R13
mov.l r14, @(0x38, r0) ! save R14
mov.l r15, @(0x3c, r0) ! save R15
mov.l L_exception,r1
mov.l @r1,r4 ! arg to handleException
add #92, r0 ! readjust register pointer
stc ssr, r2 ! R2 has SR
stc spc, r1 ! R1 has PC
mov.l r2, @-r0 ! save SR
sts.l macl, @-r0 ! save MACL
sts.l mach, @-r0 ! save MACH
stc.l vbr, @-r0 ! save VBR
stc.l gbr, @-r0 ! save GBR
sts.l pr, @-r0 ! save PR
mov.l L_stubstack, r2
mov.l L_hdl_except, r3
mov.l @r2, r15
jsr @r3
mov.l r1, @-r0 ! save PC
mov.l L_stubstack, r0
mov.l L_reg, r1
bra restoreRegisters
mov.l r15, @r0 ! save __stub_stack
.balign 4
L_reg:
.long SYMBOL_NAME(registers)
L_exception:
.long SYMBOL_NAME(exception)
L_stubstack:
.long SYMBOL_NAME(stub_sp)
L_hdl_except:
.long SYMBOL_NAME(handle_exception)
restoreRegisters:
add #8, r1 ! skip to R2
mov.l @r1+, r2 ! restore R2
mov.l @r1+, r3 ! restore R3
mov.l @r1+, r4 ! restore R4
mov.l @r1+, r5 ! restore R5
mov.l @r1+, r6 ! restore R6
mov.l @r1+, r7 ! restore R7
mov.l @r1+, r8 ! restore R8
mov.l @r1+, r9 ! restore R9
mov.l @r1+, r10 ! restore R10
mov.l @r1+, r11 ! restore R11
mov.l @r1+, r12 ! restore R12
mov.l @r1+, r13 ! restore R13
mov.l @r1+, r14 ! restore R14
mov.l @r1+, r15 ! restore programs stack
mov.l @r1+, r0
ldc r0, spc ! restore PC
lds.l @r1+, pr ! restore PR
ldc.l @r1+, gbr ! restore GBR
ldc.l @r1+, vbr ! restore VBR
lds.l @r1+, mach ! restore MACH
lds.l @r1+, macl ! restore MACL
mov.l @r1, r0
add #-88, r1 ! readjust reg pointer to R1
ldc r0, ssr ! restore SR
mov.l r2, @-r15
mov.l L_in_nmi, r0
mov #0, r2
mov.b r2, @r0
mov.l @r15+, r2
mov.l @r1+, r0 ! restore R0
rte
mov.l @r1, r1 ! restore R1
address_error_load:
address_error_store:
/* Exception 9 (bus errors) are disasbleable - so that you
can probe memory and get zero instead of a fault.
Because the vector table may be in ROM we don't revector
the interrupt like all the other stubs, we check in here
*/
mov.l L_dofault,r1
mov.l @r1,r1
tst r1,r1
bf 2f
mov.l 5f,r1
ldc r1,sr ! change bank RB=0,BL=0 IPM=0xf
mov.l L_handle_buserror,r0
jmp @r0
nop
.balign 4
L_dofault:
.long SYMBOL_NAME(dofault)
L_handle_buserror:
.long SYMBOL_NAME(handle_buserror)
1: .long SYMBOL_NAME(handleError)
break:
mov.l 1f,r0
jsr @r0
nop
bra 2f
nop
.balign 4
1: .long SYMBOL_NAME(handleBreak)
unconditional_trap:
reserved_instruction:
illegal_slot_instruction:
user_break:
/* Prepare for saving context, we've already pushed r0 and r1, stick
exception number into the frame */
2: mov.l 5f,r0
ldc r0,sr ! change bank RB=0 BL=0 IPM=0xf
bra saveRegisters
nop
.balign 4
5: .long 0xcfffffff ! RB=0,BL=0
nmi:
#ifdef CONFIG_DVESH3
mov.l DGR_CSR23_A,r1
mov.l DGR_CSR23_D,r0
mov.l r0,@r1
#endif
/* Special case for NMI - make sure that they don't nest */
mov.l L_in_nmi,r0
tas.b @r0 ! Fend off against addtnl NMIs
mov #0x1,r1
mov.b r1,@r0
bt 2b
rte
nop
.balign 4
L_in_nmi:
.long SYMBOL_NAME(in_nmi)
#ifdef CONFIG_DVESH3
DGR_CSR23_A:
.long 0xa480005c
DGR_CSR23_D:
.long 0x40000000 /* Abor rach clear */
#endif
do_IRQ:
rte
nop
do_timer: /* Clear flag */
mov.l 1f,r0
mov.w @r0,r1
mov.w 2f,r2
and r2,r1
mov.w r1,@r0
rte
nop
.balign 4
1: .long TMU0_TCR
2: .word 0xfeff
.global _exception_handling_table
.section .data
_exception_handling_table:
.long 0 ! 0, 0
.long 0 ! 20, 1
.long 0 ! tlb_miss_load 40, 2
.long 0 ! tlb_miss_store 60, 3
.long 0 ! initial_page_write 80, 4
.long 0 ! tlb_protection_violation_load A0, 5
.long 0 ! tlb_protection_violation_store C0, 6
.long address_error_load ! E0, 7
.long address_error_store !100, 8
.long 0 !120, 9
.long 0 !140,10
.long unconditional_trap !160,11
.long reserved_instruction !180,12
.long illegal_slot_instruction !1A0,13
.long nmi !1C0,14
.long user_break !1E0,15
ENTRY(interrupt_table)
! external hardware
.long do_IRQ ! 0000 200,16
.long do_IRQ ! 0001 220,17
.long do_IRQ ! 0010 240,18
.long do_IRQ ! 0011 260,19
.long do_IRQ ! 0100 280,20
.long do_IRQ ! 0101 2A0,21
.long do_IRQ ! 0110 2C0,22
.long do_IRQ ! 0111 2E0,23
.long do_IRQ ! 1000 300,24
.long do_IRQ ! 1001 320,25
.long do_IRQ ! 1010 340,26
.long do_IRQ ! 1011 360,27
.long do_IRQ ! 1100 380,28
.long do_IRQ ! 1101 3A0,29
.long do_IRQ ! 1110 3C0,30
.long 0 !3E0,31
! Internal hardware
.long do_timer ! TMU0 tuni0 400,32
.long do_IRQ ! TMU1 tuni1 420,33
.long do_IRQ ! TMU2 tuni2 440,34
.long do_IRQ ! ticpi2 460,35
.long do_IRQ ! RTC ati 480,36
.long do_IRQ ! pri 4A0,37
.long do_IRQ ! cui 4C0,38
.long do_IRQ ! SCI eri 4E0,39
.long break ! rxi 500,40
.long do_IRQ ! txi 520,41
.long do_IRQ ! tei 540,42
.long do_IRQ ! WDT iti 560,43
.long do_IRQ ! REF rcmi 580,44
.long do_IRQ ! rovi 5A0,45
#ifdef CONFIG_SH7709
.long do_IRQ ! 5C0,46
.long do_IRQ ! Hitachi UDI 5E0,47
.long do_IRQ ! IRQ0 600,48
.long do_IRQ ! IRQ1 620,49
.long do_IRQ ! IRQ2 640,50
.long do_IRQ ! IRQ3 660,51
.long do_IRQ ! IRQ4 680,52
.long do_IRQ ! IRQ5 6A0,53
.long do_IRQ ! 6C0,54
.long do_IRQ ! 6E0,55
.long do_IRQ ! 700,56
.long do_IRQ ! 720,57
.long do_IRQ ! 740,58
.long do_IRQ ! 760,59
.long do_IRQ ! 780,60
.long do_IRQ ! 7A0,61
.long do_IRQ ! 7C0,62
.long do_IRQ ! 7E0,63
.long do_IRQ ! DMAC dmte0 800,64
.long do_IRQ ! dmte1 820,65
.long do_IRQ ! dmte2 840,66
.long do_IRQ ! dmte3 860,67
.long do_IRQ ! IrDA eri 880,68
.long do_IRQ ! rxi 8A0,69
.long do_IRQ ! bri 8C0,70
.long do_IRQ ! txi 8E0,71
.long do_IRQ ! SCIF eri 900,72
.long break ! rxi 920,73
.long break ! bri 940,74
.long do_IRQ ! txi 960,75
.long do_IRQ ! ADC adi 980,76
#endif
#ifdef CONFIG_SH7750
.long do_IRQ ! 5C0,46
.long do_IRQ ! 5E0,47
.long do_IRQ ! Hitachi UDI 600,48
.long do_IRQ ! GPIO gpio 620,49
.long do_IRQ ! DMAC dmte0 640,50
.long do_IRQ ! DMAC dmte1 660,51
.long do_IRQ ! DMAC dmte2 680,52
.long do_IRQ ! DMAC dmte3 6A0,53
.long do_IRQ ! DMAC dmae 6C0,54
.long do_IRQ ! 6E0,55
.long do_IRQ ! SCIF eri 700,56
.long break ! rxi 720,57
.long break ! bri 740,58
.long do_IRQ ! txi 760,59
.long do_IRQ ! DMAC dmte4 780,60
.long do_IRQ ! DMAC dmte5 7A0,61
.long do_IRQ ! DMAC dmte6 7C0,62
.long do_IRQ ! DMAC dmte7 7E0,63
.long do_IRQ ! 800,64
.long do_IRQ ! 820,65
.long do_IRQ ! 840,66
.long do_IRQ ! 860,67
.long do_IRQ ! 880,68
.long do_IRQ ! 8A0,69
.long do_IRQ ! 8C0,70
.long do_IRQ ! 8E0,71
.long do_IRQ ! 900,72
.long do_IRQ ! 920,73
.long do_IRQ ! 940,74
.long do_IRQ ! 960,75
.long do_IRQ ! 980,76
.long do_IRQ ! 9A0,77
.long do_IRQ ! 9C0,78
.long do_IRQ ! 9E0,79
.long do_IRQ ! A00,80
.long do_IRQ ! A20,81
.long do_IRQ ! A40,82
.long do_IRQ ! A60,83
.long do_IRQ ! A80,84
.long do_IRQ ! AA0,85
.long do_IRQ ! AC0,86
.long do_IRQ ! AE0,87
.long do_IRQ ! TMU3 tuni3 B00,88
.long do_IRQ ! B20,89
.long do_IRQ ! B40,90
.long do_IRQ ! B60,91
.long do_IRQ ! TMU4 tuni4 B80,92
#endif
/* End of entry.S */