Debian Codegraph @

Source/DSPSpy/util/dump_roms.ds

raw
1 ; This ucode can copy the dsp instruction rom and coefficient table.
2 ; irom:
3 ; 0x8000 in instruction space
4 ; coef:
5 ; 0x1000 in data space
6 ;
7 ; Both irom and coef are 0x1000 words in length - remember, DSP
8 ; uses 16bit words
9 ;
10 ; The DSP has two address spaces, to load data from instruction
11 ; space you need to use 'i'-prefixed instructions.
12
13
14 /********************************/
15 /** HANDY THANGERS **/
16 /********************************/
17 ; External
18 MEM_BASE: equ 0x0000
19 MEM_HI: equ MEM_BASE
20 MEM_LO: equ MEM_BASE+1
21 ; DSP
22 DRAM_BASE: equ 0x0000
23
24 ; Config reg controls dma behavior
25 CR_TO_DSP: equ 0
26 CR_TO_CPU: equ 1
27 CR_IRAM: equ 2
28 CR_DRAM: equ 0
29
30 IROM_BASE: equ 0x8000
31 COEF_BASE: equ 0x1000
32 DUMP_SIZE: equ 0x2000 ; in bytes!
33
34
35 /**************************************************************/
36 /* CODE START */
37 /**************************************************************/
38 ; iram 0x00 - Exception vectors
39 ; 8 vectors, 2 opcodes each
40 jmp exception0
41 jmp exception1
42 jmp exception2
43 jmp exception3
44 jmp exception4
45 jmp exception5
46 jmp exception6
47 jmp exception7
48
49 ; iram 0x10 - Our entry point
50 sbset #0x02
51 sbset #0x03
52 sbclr #0x04
53 sbset #0x05
54 sbset #0x06
55
56 ; ???
57 s16
58 lri $CR, #0x00ff
59
60 /**************************************************************/
61 /* MAIN */
62 /**************************************************************/
63 ; This ucode is meant only to dump the ROMs, and as such is
64 ; self-contained and skimpy
65 main:
66 clr $acc1
67 clr $acc0
68
69 ; This consumes ALL of dram! We must be careful until we dma it!
70 call copy_irom_to_dram
71 ; Send mail saying irom dump is done
72 call wait_for_dsp_mbox
73 si @DMBH, #0x8888
74 si @DMBL, #0xc0de
75 si @DIRQ, #0x0001
76 ; Get address to dma to, dma, and wait till done
77 call dma_dram_to_cmbl
78
79 ; Now we can start over for the coef
80 call copy_coef_to_dram
81 ; Send mail saying coef dump is done
82 call wait_for_dsp_mbox
83 si @DMBH, #0x8888
84 si @DMBL, #0xda7a
85 si @DIRQ, #0x0001
86 ; Get address to dma to, dma, and wait till done
87 call dma_dram_to_cmbl
88
89 ; Die
90 do_halt:
91 halt
92
93 /**************************************************************/
94 /* HELPER FUNCTIONS */
95 /**************************************************************/
96 /********************************/
97 /** DUMPING FUNCTIONS **/
98 /********************************/
99 ; Dump irom from 0x8000 in instruction space
100 copy_irom_to_dram:
101 lri $ar0, #IROM_BASE
102 lri $ar1, #DRAM_BASE
103 lri $ar2, #DUMP_SIZE/2 ; each iteration copies a word
104 bloop $ar2, copy_irom_to_dram_end
105 ilrri $ac0.m, @$ar0
106 ; Now ac0.m is 16bits of irom!
107 srri @$ar1, $ac0.m
108 copy_irom_to_dram_end:
109 nop
110 ret
111
112 ; Dump coef from 0x1000 in data space
113 copy_coef_to_dram:
114 lri $ar0, #COEF_BASE
115 lri $ar1, #DRAM_BASE
116 lri $ar2, #DUMP_SIZE/2 ; each iteration copies a word
117 bloop $ar2, copy_coef_to_dram_end
118 lrri $ac0.m, @$ar0
119 ; Now ac0.m is 16bits of coef!
120 srri @$ar1, $ac0.m
121 copy_coef_to_dram_end:
122 nop
123 ret
124
125 /********************************/
126 /** DMA **/
127 /********************************/
128 ; DMA implementation which does not write to dram
129 ; We take advantage of the fact that we know the mail is going to
130 ; contain the address which we should dma to
131 dma_dram_to_cmbl:
132 call wait_for_cpu_mbox
133 lrs $ac0.m, @CMBL
134 andi $ac1.m, #0x7fff
135
136 ; Directly do dma; writing the length kicks it off
137 sr @DSMAH, $ac1.m
138 sr @DSMAL, $ac0.m
139 si @DSPA, #DRAM_BASE
140 si @DSCR, #(CR_TO_CPU|CR_DRAM)
141 si @DSBL, #DUMP_SIZE
142
143 ; Waits for previous DMA to complete by watching a bit in DSCR.
144 wait_dma:
145 lrs $ac1.m, @DSCR
146 andcf $ac1.m, #0x0004
147 jlz wait_dma
148 ret
149
150 /********************************/
151 /** MAILBOX **/
152 /********************************/
153 ; Waits for a mail to arrive in the DSP in-mailbox.
154 wait_for_dsp_mbox:
155 lrs $ac1.m, @DMBH
156 andcf $ac1.m, #0x8000
157 jlz wait_for_dsp_mbox
158 ret
159
160 ; Waits for the CPU to grab a mail that we just sent from the DSP.
161 wait_for_cpu_mbox:
162 lrs $ac1.m, @CMBH
163 andcf $ac1.m, #0x8000
164 jlnz wait_for_cpu_mbox
165 ret
166
167 /********************************/
168 /** EXCEPTION HANDLERS **/
169 /********************************/
170 ; ...zey do nutzing!
171 exception0:
172 rti
173 exception1:
174 rti
175 exception2:
176 rti
177 exception3:
178 rti
179 exception4:
180 rti
181 exception5:
182 rti
183 exception6:
184 rti
185 exception7:
186 rti