alloc: support initializing from linker information

This commit is contained in:
Sebastien Bourdeauducq 2020-04-27 10:06:55 +08:00
parent aa93794632
commit dfcdeb09ca
2 changed files with 16 additions and 2 deletions

View File

@ -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);

View File

@ -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::<u8>() 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) -> ! {