From 20c8541e362af1858e23027c0de5494bfee6734a Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Fri, 16 Apr 2021 05:23:38 +0100 Subject: [PATCH] support for using ewram --- crt0.s | 6 ++++++ gba.ld | 16 +++++++++++++++- src/lib.rs | 44 +++++++++++++++++++++++++++++++------------- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/crt0.s b/crt0.s index 3b5b9e4d..8e043a69 100644 --- a/crt0.s +++ b/crt0.s @@ -24,6 +24,12 @@ __start: @ @ see: https://mgba-emu.github.io/gbatek/#swi-0bh-gbands7nds9dsi7dsi9---cpuset + @ copies ewram section in rom to ewram in ram + ldr r0, =__ewram_rom_start + ldr r1, =__ewram_data_start + ldr r2, =__ewram_rom_length_halfwords + swi 0x000B0000 + @ load main and branch ldr r0, =main bx r0 diff --git a/gba.ld b/gba.ld index 2b7e72df..c710cdbc 100644 --- a/gba.ld +++ b/gba.ld @@ -42,8 +42,19 @@ SECTIONS { __iwram_data_end = ABSOLUTE(.); } > iwram AT>rom - + . = __iwram_rom_start + (__iwram_data_end - __iwram_data_start); + + __ewram_rom_start = .; + .ewram : { + __ewram_data_start = ABSOLUTE(.); + + *(.ewram .ewram.*); + . = ALIGN(4); + + __ewram_data_end = ABSOLUTE(.); + } > ewram AT>rom + .bss : { *(.bss .bss.*); . = ALIGN(4); @@ -52,6 +63,9 @@ SECTIONS { __iwram_rom_length_bytes = __iwram_data_end - __iwram_data_start; __iwram_rom_length_halfwords = (__iwram_rom_length_bytes + 1) / 2; + __ewram_rom_length_bytes = __ewram_data_end - __ewram_data_start; + __ewram_rom_length_halfwords = (__ewram_rom_length_bytes + 1) / 2; + /* discard anything not already mentioned */ /DISCARD/ : { *(*) } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 8a91ce5e..8e193400 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,20 +122,38 @@ pub extern "C" fn main() -> ! { loop {} } -#[test_case] -fn trivial_test(_gba: &mut Gba) { - assert_eq!(1, 1); -} +#[cfg(test)] +mod test { + use super::Gba; -#[test_case] -fn wait_30_frames(gba: &mut Gba) { - let vblank = gba.display.vblank.get(); - let mut counter = 0; - loop { - if counter > 30 { - break; + #[test_case] + fn trivial_test(_gba: &mut Gba) { + assert_eq!(1, 1); + } + + #[test_case] + fn wait_30_frames(gba: &mut Gba) { + let vblank = gba.display.vblank.get(); + let mut counter = 0; + loop { + if counter > 30 { + break; + } + vblank.wait_for_VBlank(); + counter += 1 + } + } + + #[link_section = ".ewram"] + static mut EWRAM_TEST: u32 = 5; + #[test_case] + fn ewram_static_test(_gba: &mut Gba) { + unsafe { + let content = (&EWRAM_TEST as *const u32).read_volatile(); + assert_eq!(content, 5, "expected data in ewram to be 5"); + (&mut EWRAM_TEST as *mut u32).write_volatile(content + 1); + let content = (&EWRAM_TEST as *const u32).read_volatile(); + assert_eq!(content, 6, "expected data to have increased by one") } - vblank.wait_for_VBlank(); - counter += 1 } }