From 60f90429022683cd1229b11d139bdf3fd1271963 Mon Sep 17 00:00:00 2001 From: Zeal8bit Date: Sat, 25 May 2024 23:15:00 +0800 Subject: [PATCH] tester: fix a bug where the RAM size was wrongly reported 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. --- src/boot.asm | 6 ++++++ src/tester.asm | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/boot.asm b/src/boot.asm index 38b72f8..19f86ab 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -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 \ No newline at end of file diff --git a/src/tester.asm b/src/tester.asm index 060e0fb..82ce327 100644 --- a/src/tester.asm +++ b/src/tester.asm @@ -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: @@ -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: