From dfcdeb09ca349a4e0b205ca9136792bfd6ac3552 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 27 Apr 2020 10:06:55 +0800 Subject: [PATCH] alloc: support initializing from linker information --- experiments/src/main.rs | 2 +- libsupport_zynq/src/ram.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/experiments/src/main.rs b/experiments/src/main.rs index ee22cae..67adb77 100644 --- a/experiments/src/main.rs +++ b/experiments/src/main.rs @@ -77,7 +77,7 @@ pub fn main_core0() { let mut ddr = zynq::ddr::DdrRam::new(); #[cfg(not(feature = "target_zc706"))] ddr.memtest(); - ram::init_alloc(&mut ddr); + ram::init_alloc_ddr(&mut ddr); for i in 0..=1 { let mut flash_io = flash.manual_mode(i); diff --git a/libsupport_zynq/src/ram.rs b/libsupport_zynq/src/ram.rs index 5ff4970..5a5b95a 100644 --- a/libsupport_zynq/src/ram.rs +++ b/libsupport_zynq/src/ram.rs @@ -27,13 +27,27 @@ unsafe impl GlobalAlloc for CortexA9Alloc { } } -pub fn init_alloc(ddr: &mut DdrRam) { +pub fn init_alloc_ddr(ddr: &mut DdrRam) { unsafe { ALLOCATOR.0.lock() .init(ddr.ptr::() as usize, ddr.size()); } } +extern "C" { + static __heap_start: usize; + static __heap_end: usize; +} + +pub fn init_alloc_linker() { + unsafe { + let start = &__heap_start as *const usize as usize; + let end = &__heap_end as *const usize as usize; + ALLOCATOR.0.lock() + .init(start, end - start); + } +} + #[alloc_error_handler] fn alloc_error(_: core::alloc::Layout) -> ! {