forked from dolphin-emu/dolphin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump_roms.ds
186 lines (166 loc) · 4.26 KB
/
dump_roms.ds
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
; This ucode can copy the dsp instruction rom and coefficient table.
; irom:
; 0x8000 in instruction space
; coef:
; 0x1000 in data space
;
; Both irom and coef are 0x1000 words in length - remember, DSP
; uses 16bit words
;
; The DSP has two address spaces, to load data from instruction
; space you need to use 'i'-prefixed instructions.
/********************************/
/** HANDY THANGERS **/
/********************************/
; External
MEM_BASE: equ 0x0000
MEM_HI: equ MEM_BASE
MEM_LO: equ MEM_BASE+1
; DSP
DRAM_BASE: equ 0x0000
; Config reg controls dma behavior
CR_TO_DSP: equ 0
CR_TO_CPU: equ 1
CR_IRAM: equ 2
CR_DRAM: equ 0
IROM_BASE: equ 0x8000
COEF_BASE: equ 0x1000
DUMP_SIZE: equ 0x2000 ; in bytes!
/**************************************************************/
/* CODE START */
/**************************************************************/
; iram 0x00 - Exception vectors
; 8 vectors, 2 opcodes each
jmp exception0
jmp exception1
jmp exception2
jmp exception3
jmp exception4
jmp exception5
jmp exception6
jmp exception7
; iram 0x10 - Our entry point
sbset #0x02
sbset #0x03
sbclr #0x04
sbset #0x05
sbset #0x06
; ???
s16
lri $CR, #0x00ff
/**************************************************************/
/* MAIN */
/**************************************************************/
; This ucode is meant only to dump the ROMs, and as such is
; self-contained and skimpy
main:
clr $acc1
clr $acc0
; This consumes ALL of dram! We must be careful until we dma it!
call copy_irom_to_dram
; Send mail saying irom dump is done
call wait_for_dsp_mbox
si @DMBH, #0x8888
si @DMBL, #0xc0de
si @DIRQ, #0x0001
; Get address to dma to, dma, and wait till done
call dma_dram_to_cmbl
; Now we can start over for the coef
call copy_coef_to_dram
; Send mail saying coef dump is done
call wait_for_dsp_mbox
si @DMBH, #0x8888
si @DMBL, #0xda7a
si @DIRQ, #0x0001
; Get address to dma to, dma, and wait till done
call dma_dram_to_cmbl
; Die
do_halt:
halt
/**************************************************************/
/* HELPER FUNCTIONS */
/**************************************************************/
/********************************/
/** DUMPING FUNCTIONS **/
/********************************/
; Dump irom from 0x8000 in instruction space
copy_irom_to_dram:
lri $ar0, #IROM_BASE
lri $ar1, #DRAM_BASE
lri $ar2, #DUMP_SIZE/2 ; each iteration copies a word
bloop $ar2, copy_irom_to_dram_end
ilrri $ac0.m, @$ar0
; Now ac0.m is 16bits of irom!
srri @$ar1, $ac0.m
copy_irom_to_dram_end:
nop
ret
; Dump coef from 0x1000 in data space
copy_coef_to_dram:
lri $ar0, #COEF_BASE
lri $ar1, #DRAM_BASE
lri $ar2, #DUMP_SIZE/2 ; each iteration copies a word
bloop $ar2, copy_coef_to_dram_end
lrri $ac0.m, @$ar0
; Now ac0.m is 16bits of coef!
srri @$ar1, $ac0.m
copy_coef_to_dram_end:
nop
ret
/********************************/
/** DMA **/
/********************************/
; DMA implementation which does not write to dram
; We take advantage of the fact that we know the mail is going to
; contain the address which we should dma to
dma_dram_to_cmbl:
call wait_for_cpu_mbox
lrs $ac0.m, @CMBL
andi $ac1.m, #0x7fff
; Directly do dma; writing the length kicks it off
sr @DSMAH, $ac1.m
sr @DSMAL, $ac0.m
si @DSPA, #DRAM_BASE
si @DSCR, #(CR_TO_CPU|CR_DRAM)
si @DSBL, #DUMP_SIZE
; Waits for previous DMA to complete by watching a bit in DSCR.
wait_dma:
lrs $ac1.m, @DSCR
andcf $ac1.m, #0x0004
jlz wait_dma
ret
/********************************/
/** MAILBOX **/
/********************************/
; Waits for a mail to arrive in the DSP in-mailbox.
wait_for_dsp_mbox:
lrs $ac1.m, @DMBH
andcf $ac1.m, #0x8000
jlz wait_for_dsp_mbox
ret
; Waits for the CPU to grab a mail that we just sent from the DSP.
wait_for_cpu_mbox:
lrs $ac1.m, @CMBH
andcf $ac1.m, #0x8000
jlnz wait_for_cpu_mbox
ret
/********************************/
/** EXCEPTION HANDLERS **/
/********************************/
; ...zey do nutzing!
exception0:
rti
exception1:
rti
exception2:
rti
exception3:
rti
exception4:
rti
exception5:
rti
exception6:
rti
exception7:
rti