-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhyperram.asm
390 lines (328 loc) · 15 KB
/
hyperram.asm
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
; MEGA65 HyperRAM development testbed
; done by sy2002 in April to June 2020
#include "../../dist_kit/sysdef.asm"
#include "../../dist_kit/monitor.def"
.ORG 0x8000
MOVE STACK_RESTORE, R8
MOVE SP, @R8
ABRA _start, 1
; DEBUG/SIMULATION
MOVE IO$M65HRAM_LO, R0 ; lo word of the address
MOVE IO$M65HRAM_HI, R1 ; hi word of the address
MOVE IO$M65HRAM_DATA16, R2 ; 16-bit data access
MOVE 0x3333, @R0
MOVE 0x0033, @R1
MOVE 0xAAAA, @R2
MOVE @R2, R8
MOVE @R2, R8 ; system gets stuck here
SYSCALL(puthex, 1) ; this is never executed
SYSCALL(exit, 1)
MOVE 0xAAAA, R5
XOR R6, R6
_dbgloop CMP 0x0001, R6
RBRA _dbgend, Z
MOVE R5, @R2
ADD 1, R5
ADD 1, R6
ADD 1, @R0
RBRA _dbgloop, 1
_dbgend MOVE 0x3333, @R0
MOVE @R2, R8
MOVE @R2, R8
SYSCALL(puthex, 1)
SYSCALL(exit, 1)
MOVE STR_TITLE, R8
SYSCALL(puts, 1)
; DEBUG
;MOVE 0xFF66, R8
;MOVE @R8, R8
;SYSCALL(puthex, 1)
;SYSCALL(crlf, 1)
;SYSCALL(crlf, 1)
; HyperRAM registers addresses
_start MOVE IO$M65HRAM_LO, R0 ; lo word of the address
MOVE IO$M65HRAM_HI, R1 ; hi word of the address
MOVE IO$M65HRAM_DATA8, R2 ; 8-bit data access
MOVE 0xFF66, R4 ; DEBUG
;RBRA _start_16bit, 1
; check reading/writing address
MOVE 0x4321, @R0 ; lo word is full 16bit wide
MOVE 0x0678, @R1 ; hi "word" is only 11bit wide
CMP 0x4321, @R0 ; check, if lo word is correct
RBRA _rwa, Z ; yes: check hi word
_rwa_e MOVE ERR_RWADDR, R8 ; no: show error message
SYSCALL(puts, 1)
MOVE @R1, R8 ; and then: hi word value
SYSCALL(puthex, 1)
MOVE @R0, R8 ; and then: lo word value
SYSCALL(puthex, 1)
SYSCALL(crlf, 1)
RBRA _END, 1 ; exit due to error
_rwa CMP 0x0678, @R1 ; check, if hi word is correct
RBRA _readctl, Z ; yes: start HyperRAM tests
RBRA _rwa_e, 1 ; no: error out and end
; read control registers
; output should be: 0081, 000C, 00F6, 00FF
; see c/test_programs/hyperramtest.c for details
_readctl MOVE STR_CTRL, R8
SYSCALL(puts, 1)
; DEBUG
;MOVE 0xFF66, R4
;MOVE @R4, R8
;SYSCALL(puthex, 1)
;SYSCALL(crlf, 1)
; expected output of the two "DEBUG" mentioned above is
; two times 0x0000
; Some currently yet unclear magic from hyperramtest.c
; leads to more stable mass reading/writing
;MOVE 0x03FF, @R1
;MOVE 0xFFF5, @R0
;MOVE 0, @R2 ; disable read delay
;MOVE 0xFFF2, @R0
;MOVE 0x00B0, @R2 ; turn cache on
; read id0lo
MOVE 0x0001, @R0
MOVE 0x0200, @R1
MOVE @R2, R8 ; hw bug: 2 reads necessary!
MOVE @R2, R8 ; when this ctrl-reg is read
SYSCALL(puthex, 1) ; after cold start
;MOVE @R4, R8
;SYSCALL(puthex,1)
SYSCALL(crlf, 1)
; read id0hi
MOVE 0x0000, @R0
MOVE @R2, R8
SYSCALL(puthex,1)
;MOVE @R4, R8
;SYSCALL(puthex,1)
SYSCALL(crlf, 1)
; read cr0lo
MOVE 0x1001, @R0
MOVE @R2, R8
MOVE @R2, R8
SYSCALL(puthex, 1)
;MOVE @R4, R8
;SYSCALL(puthex,1)
SYSCALL(crlf, 1)
; read cr0hi
MOVE 0x1000, @R0
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R4, R8
;SYSCALL(puthex,1)
SYSCALL(crlf,1)
SYSCALL(crlf,1)
; expected output of the sequence ABOVE consisting of
; id0lo, id0hi, cr0lo, cr0hi is: $81, $0C, $F6, $FF
MOVE STR_5READs, R8
SYSCALL(puts, 1)
; read 5 times at 0x0011000
MOVE 0x1000, @R0
MOVE 0x0001, @R1
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R2, R8
SYSCALL(puthex, 1)
SYSCALL(crlf, 1)
; write 0x23 at 0x0011000
MOVE 0x23, @R2
; again, read 5 times at 0x0011000
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R2, R8
SYSCALL(puthex, 1)
MOVE @R2, R8
SYSCALL(puthex, 1)
SYSCALL(crlf, 1)
SYSCALL(crlf, 1)
MOVE STR_8BIT, R8
SYSCALL(puts, 1)
; ------------------------------------------------------------
; 8-bit test
; ------------------------------------------------------------
; fill 240 bytes (F0) starting from 0x0020003 with increasing
; values starting from 3 (3 .. 239)
MOVE 0x0002, @R1
MOVE 0x0003, R5
_wloop MOVE R5, @R0
MOVE R5, @R2
ADD 1, R5
CMP 0x00F0, R5
RBRA _wloop, !Z
; read and compare 240 bytes starting from 0x0020003:
; is the memory containing, what we wrote?
; if not, push the positions of the wrong values and the
; wrong values itself on the stack
; R6 contains the amount of errors
XOR R6, R6
MOVE 0x0003, R5
_rloop MOVE R5, @R0
MOVE @R2, R8
SYSCALL(puthex, 1)
CMP R8, R5
RBRA _rloop_cnt, Z
MOVE R5, @--SP
MOVE R8, @--SP
ADD 1, R6
_rloop_cnt ADD 1, R5
CMP 0x00F0, R5
RBRA _rloop, !Z
SYSCALL(crlf, 1)
; no errors? print "PASSED" message and jump to 16-bit test
CMP 0, R6
RBRA _print_8berr, !Z
MOVE STR_8BIT_OK, R8
SYSCALL(puts, 1)
RBRA _start_16bit, 1
; print errors
_print_8berr MOVE ERR_READ, R8
SYSCALL(puts, 1)
MOVE R6, R8
SYSCALL(puthex, 1)
SYSCALL(crlf, 1)
_show_err MOVE @SP++, R7
MOVE @SP++, R8
SYSCALL(puthex, 1)
MOVE STR_COLON_SPACE, R8
SYSCALL(puts, 1)
MOVE R7, R8
SYSCALL(puthex, 1)
SYSCALL(crlf, 1)
SUB 1, R6
RBRA _show_err, !Z
; ------------------------------------------------------------
; 16-bit test
; ------------------------------------------------------------
_start_16bit MOVE STR_16BIT, R8
SYSCALL(puts, 1)
MOVE IO$M65HRAM_DATA16, R2 ; 16-bit data access
; fill 1MB starting at 0x0333333 with changing 16-bit
; values and then read everything back and test if correct
; 0x0333333 + 1 MB = 0x4333333
MOVE 0x0033, @R1 ; hi-word of 0x0333333
MOVE 0x3333, @R0 ; lo-word
XOR R5, R5 ; repeatedly runs to 0xFFFF
_16bit_loop CMP 0x0043, @R1 ; hi-word of 1MB reached?
RBRA _16bl_write, !Z ; no: write next word
CMP 0x3333, @R0 ; yes: check if lo-word fits
RBRA _16bit_check, Z ; yes: leave loop, go checking
_16bl_write MOVE R5, @R2 ; write test value
ADD 1, R5 ; increase test value
ADD 1, @R0 ; next word (inc lo-word)
RBRA _16bit_loop, !Z ; no overflow => continue
ADD 1, @R1 ; inc hi-word
RBRA _16bit_loop, 1
; linearily check, if the 1MB data that was written above
; is now accessible in the HRAM
_16bit_check MOVE 0x0033, @R1 ; hi-word of 0x0333333
MOVE 0x3333, @R0 ; lo-word
XOR R5, R5 ; repeatedly runs to 0xFFFF
XOR R6, R6 ; R6 = error counter
_16bit_cloop CMP 0x0043, @R1 ; hi-word of 1MB reached?
RBRA _16bl_check, !Z ; no: check next word
CMP 0x3333, @R0 ; yes: check if lo-word fits
RBRA _16bit_res, Z ; yes: leave and print result
_16bl_check MOVE @R2, R12 ; due to caching problems that
; might occur, we are saving
; the value instead of
; re-reading it in the error
; recording part
CMP R5, R12 ; HRAM = test value?
RBRA _16bit_err, !Z ; no: error
_16bl_cont ADD 1, R5 ; yes: increase test value
ADD 1, @R0 ; next word (inc lo-word)
RBRA _16bit_cloop, !Z ; no overflow => continue
CMP R6, 0 ; no errors: finish program
RBRA _16bit_res, Z
MOVE ERR_16BIT, R8
SYSCALL(puts, 1)
MOVE ERR_READ, R8
SYSCALL(puts, 1)
MOVE R6, R8
SYSCALL(puthex, 1)
SYSCALL(crlf, 1)
; save the current stack pointer as the following SP math
; is moving it around and we need it for subroutine calls
; in betweem
MOVE SP, R10
MOVE STR_HEADLINE, R8
SYSCALL(puts, 1)
; jump to the first entry on the stack so that we can
; output the errors in the order of occurance
AND 0xFF01, SR ; clear SR for SHL
MOVE R6, R11
SHL 2, R11 ; multiply #errors x 4
ADD R11, SP
MOVE SP, R11
_16ble_loop MOVE R11, SP ; restore our running pointer
MOVE @--SP, R3 ; address: lo word
MOVE @--SP, R2 ; address: hi word
MOVE @--SP, R1 ; actual value
MOVE @--SP, R0 ; target value
MOVE SP, R11 ; remember new SP value
MOVE R10, SP ; store org SP for subroutines
MOVE R2, R8
SYSCALL(puthex, 1)
MOVE R3, R8
SYSCALL(puthex, 1)
MOVE STR_COLON_SPACE, R8
SYSCALL(puts, 1)
MOVE R1, R8
SYSCALL(puthex, 1)
MOVE STR_4SPACE, R8
SYSCALL(puts, 1)
MOVE R0, R8
SYSCALL(puthex, 1)
SYSCALL(crlf, 1)
SUB 1, R6
RBRA _16ble_loop, !Z
RBRA _END, 1
_16bit_res MOVE STR_16BIT_OK, R8
SYSCALL(puts, 1)
RBRA _END, 1
_16bit_err ADD 1, R6
MOVE @R0, @--SP
MOVE @R1, @--SP
MOVE R12, @--SP
MOVE R5, @--SP
RBRA _16bl_cont, 1
_END MOVE STACK_RESTORE, R8
MOVE @R8, SP
SYSCALL(exit, 1)
STACK_RESTORE .DW 0
; Function xyz
; R8 = Title
; R9 = offset lo
; R10 = offset hi
; R11: output DWORD, when R11 = 1, else output WORDs
OUTPUT_DW INCRB
DECRB
RET
;=============================================================================
; String constants
;=============================================================================
STR_TITLE .ASCII_P "MEGA65 HyperRAM development testbed - done by sy2002 in May 2020\n"
.ASCII_W "==================================================================\n\n"
STR_CTRL .ASCII_W "Control Registers: (Output should be: 0081, 000C, 00F6, 00FF)\n"
STR_5READs .ASCII_W "Read 5 times from 0x0011000, then write 0x23 there, then read 5 times:\n"
STR_8BIT .ASCII_W "8-bit test: Fill 240 bytes from 0x0020003 with increasing values, then test:\n"
STR_8BIT_OK .ASCII_W "8-bit test: PASSED\n"
STR_16BIT .ASCII_W "\n16-bit linear test: Fill 1MB from 0x0333333 with 16-bit values, then test:\n"
STR_16BIT_OK .ASCII_W "16-bit linear test: PASSED\n"
STR_HEADLINE .ASCII_W "Address Actual Expected\n"
STR_4SPACE .ASCII_W " "
STR_COLON_SPACE .ASCII_W ": "
STR_OK .ASCII_W "OK\n"
ERR_RWADDR .ASCII_W "Error: HyperRAM address register is not working: "
ERR_READ .ASCII_W "Read Errors: "
ERR_16BIT .ASCII_W "16-bit linear test: FAILED\n"