diff --git a/libs/blitstr2/codegen/lib/templates.go b/libs/blitstr2/codegen/lib/templates.go index 5f34b6368..c06e67fc0 100644 --- a/libs/blitstr2/codegen/lib/templates.go +++ b/libs/blitstr2/codegen/lib/templates.go @@ -129,7 +129,7 @@ pub const GLYPH_LEN: usize = {{.GS.GlyphsLen}}; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/bold.rs b/libs/blitstr2/src/fonts/bold.rs index 002abe7c9..ce5c5ee7e 100644 --- a/libs/blitstr2/src/fonts/bold.rs +++ b/libs/blitstr2/src/fonts/bold.rs @@ -237,7 +237,7 @@ pub const GLYPH_LEN: usize = 1656; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/emoji.rs b/libs/blitstr2/src/fonts/emoji.rs index 0089f7639..12f8c95a0 100644 --- a/libs/blitstr2/src/fonts/emoji.rs +++ b/libs/blitstr2/src/fonts/emoji.rs @@ -1550,7 +1550,7 @@ pub const GLYPH_LEN: usize = 10944; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/ja.rs b/libs/blitstr2/src/fonts/ja.rs index 485438c5e..16199d283 100644 --- a/libs/blitstr2/src/fonts/ja.rs +++ b/libs/blitstr2/src/fonts/ja.rs @@ -11138,7 +11138,7 @@ pub const GLYPH_LEN: usize = 88648; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/kr.rs b/libs/blitstr2/src/fonts/kr.rs index 0db4b8a8a..73e3a950a 100644 --- a/libs/blitstr2/src/fonts/kr.rs +++ b/libs/blitstr2/src/fonts/kr.rs @@ -12593,7 +12593,7 @@ pub const GLYPH_LEN: usize = 99712; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/mono.rs b/libs/blitstr2/src/fonts/mono.rs index 225b41b27..5470d1240 100644 --- a/libs/blitstr2/src/fonts/mono.rs +++ b/libs/blitstr2/src/fonts/mono.rs @@ -237,7 +237,7 @@ pub const GLYPH_LEN: usize = 1656; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/regular.rs b/libs/blitstr2/src/fonts/regular.rs index 775329a19..d09df5d0b 100644 --- a/libs/blitstr2/src/fonts/regular.rs +++ b/libs/blitstr2/src/fonts/regular.rs @@ -237,7 +237,7 @@ pub const GLYPH_LEN: usize = 1656; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/small.rs b/libs/blitstr2/src/fonts/small.rs index 0348ad227..8ab4f022c 100644 --- a/libs/blitstr2/src/fonts/small.rs +++ b/libs/blitstr2/src/fonts/small.rs @@ -237,7 +237,7 @@ pub const GLYPH_LEN: usize = 1656; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/tall.rs b/libs/blitstr2/src/fonts/tall.rs index fd02a5345..f96d0fa03 100644 --- a/libs/blitstr2/src/fonts/tall.rs +++ b/libs/blitstr2/src/fonts/tall.rs @@ -235,7 +235,7 @@ pub const GLYPH_LEN: usize = 6624; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/libs/blitstr2/src/fonts/zh.rs b/libs/blitstr2/src/fonts/zh.rs index cd1977d56..4b24b0f1e 100644 --- a/libs/blitstr2/src/fonts/zh.rs +++ b/libs/blitstr2/src/fonts/zh.rs @@ -8364,7 +8364,7 @@ pub const GLYPH_LEN: usize = 65448; pub fn glyphs() -> &'static [u32] { #[cfg(any(feature="precursor", feature="renode"))] unsafe { - let data: *const u32 = core::mem::transmute(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst)); + let data: *const u32 = core::ptr::with_exposed_provenance::(GLYPH_LOCATION.load(core::sync::atomic::Ordering::SeqCst) as usize); core::slice::from_raw_parts(data, GLYPH_LEN) } diff --git a/loader/src/main.rs b/loader/src/main.rs index eeca134a1..2e12bade1 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -66,6 +66,7 @@ use alloc::vec::Vec; #[macro_use] mod args; use args::{KernelArgument, KernelArguments}; +#[cfg(feature = "bao1x")] use bao1x_api::UUID; #[cfg_attr(feature = "atsama5d27", path = "platform/atsama5d27/debug.rs")] @@ -121,14 +122,11 @@ mod test; // somewhat dangerously tell the loader to go ahead and allocate over this region by // telling it has the whole rest of SRAM to stick initial process pages in. #[global_allocator] -#[cfg(feature = "bao1x")] static ALLOCATOR: linked_list_allocator::LockedHeap = linked_list_allocator::LockedHeap::empty(); // heap start is selected by looking at the total reserved .data + .bss region in the compiled loader. // it hovers at 0x5000 unless I start adding lots of statics to the loader (which there are not). -#[cfg(feature = "bao1x")] pub const HEAP_OFFSET: usize = 0x5000; // just a small heap, big enough for us to use alloc to simplify argument processing -#[cfg(feature = "bao1x")] pub const HEAP_LEN: usize = 0x1000; #[repr(C)] @@ -245,14 +243,23 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) // Initialize the allocator with heap memory range. The heap memory is "throw-away" // so we stick it near the bottom of RAM, with the assumption that the loader process // won't smash over it. - #[cfg(any(feature = "bao1x"))] + #[cfg(feature = "bao1x")] + let heap_start = utralib::HW_SRAM_MEM + HEAP_OFFSET; + #[cfg(not(feature = "bao1x"))] + let heap_start = utralib::HW_SRAM_EXT_MEM + HEAP_OFFSET; + #[cfg(not(feature = "bao1x"))] { - let heap_start = utralib::HW_SRAM_MEM + HEAP_OFFSET; - crate::println!("Setting up heap @ {:x}-{:x}", heap_start, heap_start + HEAP_LEN); - unsafe { - ALLOCATOR.lock().init(heap_start as *mut u8, HEAP_LEN); + // for precursor, clear this region, as it is only cleared later in the boot process + let ram_init = utralib::HW_SRAM_EXT_MEM as *mut u32; + for i in 0..(HEAP_LEN + HEAP_OFFSET) / size_of::() { + unsafe { ram_init.add(i).write_volatile(0) }; } } + println!("Setting up heap @ {:x}-{:x}", heap_start, heap_start + HEAP_LEN); + unsafe { + ALLOCATOR.lock().init(heap_start as *mut u8, HEAP_LEN); + } + println!("done"); // Run kernel image validation now that the heap is set up. #[cfg(feature = "bao1x")] @@ -787,9 +794,6 @@ fn clear_ram(cfg: &mut BootConfig) { if VDBG { println!("Stack clearing limit: {:x}", clear_limit); } - #[cfg(not(feature = "bao1x"))] - let clear_start = 0; - #[cfg(feature = "bao1x")] let clear_start = HEAP_OFFSET + HEAP_LEN; unsafe { for addr in clear_start..(cfg.sram_size - clear_limit) / 4 {