1 // Copyright (c) 2017-2019 Linaro LTD 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 mod area; 6 pub mod c; 7 8 // The API needs to be public, even though it isn't intended to be called by Rust code, but the 9 // functions are exported to C code. 10 pub mod api; 11 12 pub use crate::area::{AreaDesc, FlashId}; 13 14 /// For testing the ram load feature, we need to emulate a block of RAM and be able to pass that 15 /// down to the C code. The call down to boot_go should go through this object so that the buffer 16 /// itself is managed properly. 17 pub struct RamBlock { 18 ram: Vec<u8>, 19 offset: u32, // 32-bit offset. 20 } 21 22 impl RamBlock { new(size: u32, offset: u32) -> RamBlock23 pub fn new(size: u32, offset: u32) -> RamBlock { 24 RamBlock { 25 ram: vec![0; size as usize], 26 offset: offset, 27 } 28 } 29 30 /// Borrow the RAM buffer, with 'offset' being the beginning of the buffer. borrow(&self) -> &[u8]31 pub fn borrow(&self) -> &[u8] { 32 &self.ram 33 } 34 35 /// Borrow a piece of the ram, with 'offset' being the beginning of the buffer. borrow_part(&self, base: usize, size: usize) -> &[u8]36 pub fn borrow_part(&self, base: usize, size: usize) -> &[u8] { 37 &self.ram[base..base+size] 38 } 39 invoke<F, R>(&self, act: F) -> R where F: FnOnce() -> R40 pub fn invoke<F, R>(&self, act: F) -> R 41 where F: FnOnce() -> R 42 { 43 api::set_ram_info(api::BootsimRamInfo { 44 start: self.offset, 45 size: self.ram.len() as u32, 46 base: &self.ram[0] as *const u8 as usize - self.offset as usize, 47 }); 48 let result = act(); 49 api::clear_ram_info(); 50 result 51 } 52 } 53