mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-25 09:50:52 +00:00
- hosted mode uses an awful, horrific hack to simulate FLASH: it makes a global singleton that is freely mutable. Oh but wait! that's actually how the hardware behaves. It's up to the code around the hardware to create those primitives. So, maybe it makes sense that the simulation model for the hardware is terribly unsafe and unprotected. - the format routine at least doesn't crash and creates some semblance of a result that looks right-ish. Need to write a utility that helps to explore the "disk image" so we can understand what's going on.
67 lines
No EOL
1.8 KiB
Rust
67 lines
No EOL
1.8 KiB
Rust
#![allow(dead_code)]
|
|
use crate::api::*;
|
|
|
|
use std::sync::Once;
|
|
use std::mem::MaybeUninit;
|
|
|
|
// This is considered bad practice for Rust to use a global singleton.
|
|
// However, this hack puts the burden of emulation on the emulator, while
|
|
// keeping the production code clean (otherwise we'd have large sections
|
|
// of production code with #cfg regions to deal with lifetime differences).
|
|
// Besides, in reality, FLASH memory is a static, globally mutable pool of data.
|
|
//
|
|
// Note that this is a concurrently accessed, unsafe, unchecked vector.
|
|
struct FlashSingleton {
|
|
memory: Vec::<u8>,
|
|
}
|
|
|
|
fn flashmem() -> &'static mut FlashSingleton {
|
|
static mut SINGLETON: MaybeUninit<FlashSingleton> = MaybeUninit::uninit();
|
|
static ONCE: Once = Once::new();
|
|
|
|
unsafe {
|
|
ONCE.call_once(|| {
|
|
let mut memory = Vec::<u8>::with_capacity(PDDB_A_LEN);
|
|
for _ in 0..PDDB_A_LEN {
|
|
memory.push(0xFF);
|
|
}
|
|
let flashmem = FlashSingleton {
|
|
memory,
|
|
};
|
|
SINGLETON.write(flashmem);
|
|
});
|
|
SINGLETON.assume_init_mut()
|
|
}
|
|
}
|
|
|
|
pub struct EmuStorage {
|
|
}
|
|
impl EmuStorage {
|
|
pub fn new() -> Self {
|
|
EmuStorage {
|
|
}
|
|
}
|
|
pub fn as_slice(&self) -> &[u8] {
|
|
flashmem().memory.as_slice()
|
|
}
|
|
pub fn as_mut_slice(&mut self) -> &mut [u8] {
|
|
flashmem().memory.as_mut_slice()
|
|
}
|
|
}
|
|
|
|
pub struct HostedSpinor {
|
|
}
|
|
impl HostedSpinor {
|
|
pub fn new() -> Self {
|
|
HostedSpinor {
|
|
}
|
|
}
|
|
pub fn patch(&self, _region: &[u8], _region_base: u32, data: &[u8], offset: u32) -> Result<(), xous::Error> {
|
|
for (&src, dst) in data.iter().zip(
|
|
flashmem().memory.as_mut_slice()[offset as usize..offset as usize + data.len()].iter_mut()
|
|
) {
|
|
*dst = src;
|
|
}
|
|
Ok(())
|
|
}
|
|
} |