Skip to content

Commit

Permalink
tester: fix a bug where the RAM size was wrongly reported
Browse files Browse the repository at this point in the history
The beginning of RAM is used as a pattern to detect the size of the RAM.
That part of the RAM was used by the UART FIFO, which could be filled with
zeros, making it a weak pattern.
  • Loading branch information
Zeal8bit committed May 25, 2024
1 parent 58a898c commit 60f9042
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ start_message_end:

SECTION BSS
ORG 0xC000

IF CONFIG_ENABLE_TESTER
PUBLIC tester_pattern
; Reserve the first 8 bytes for the tester
tester_pattern: DEFS 8
ENDIF
15 changes: 12 additions & 3 deletions src/tester.asm
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,21 @@ nor_flash_detected_end:
; ==================== R A M T E S T S ======================== ;
; =============================================================== ;

EXTERN tester_pattern

pattern: DEFB 0xaf, 0x41, 0xa9, 0x5e, 0xac, 0xc2, 0x1, 0x87

test_ram:
PRINT_STR(ram_start_msg)
; Fill the pattern to detect in RAM
ld bc, 8
ld de, tester_pattern
ld hl, pattern
ldir
; Try to detect the size of the RAM. The flash is mapped from 512KB to 1MB
; (excluded) on the physical memory mapping.
; If at any time, the first 8 bytes of any page is the same as the the RAM
; page (3), then, the RAM is cycling, meaning we have reached the size limit.
; If at any time, the first 8 bytes of any page is the same as the RAM page (3),
; then, the RAM is cycling, meaning we have reached the size limit.
ld a, 0x1f ; RAM starts at page 32
ld b, 0 ; Number of "fake" RAM pages, i.e., pages not writable
test_ram_size:
Expand All @@ -381,7 +390,7 @@ test_ram_size:
; Read back the result and restore data
cp (hl)
ld (hl), a ; doesn't alter flags
jp nz, test_ram_size_not_fake_page
jr nz, test_ram_size_not_fake_page
; Fake page, increment B
inc b
test_ram_size_not_fake_page:
Expand Down

0 comments on commit 60f9042

Please sign in to comment.