mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
implementation of code-length & padding for BIO code segments
This commit is contained in:
parent
29437c1ae8
commit
60d0126f37
2 changed files with 22 additions and 12 deletions
|
|
@ -34,19 +34,22 @@ impl<'a> BioApi<'a> for Bio {
|
|||
fn init_core(
|
||||
&mut self,
|
||||
core: BioCore,
|
||||
code: &[u8],
|
||||
offset: usize,
|
||||
code: (&[u8], Option<u32>),
|
||||
config: CoreConfig,
|
||||
) -> Result<Option<u32>, BioError> {
|
||||
let mut config = CoreInitRkyv {
|
||||
core,
|
||||
offset,
|
||||
offset: 0,
|
||||
pad_word: None,
|
||||
actual_freq: None,
|
||||
config,
|
||||
code: [0u8; 4096],
|
||||
code_len: 0,
|
||||
result: BioError::Uninit,
|
||||
};
|
||||
config.code[..code.len()].copy_from_slice(code);
|
||||
config.code[..code.0.len()].copy_from_slice(code.0);
|
||||
config.code_len = code.0.len();
|
||||
config.pad_word = code.1;
|
||||
// this should automatically allocate 2 pages because the sizeof() type of CoreInitRkyv is over 4096
|
||||
let mut buf = Buffer::into_buf(config).unwrap();
|
||||
buf.lend_mut(self.conn, BioOp::InitCore.to_u32().unwrap())
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ impl BioSharedState {
|
|||
|
||||
for core in 0..4 {
|
||||
// crate::println!("ldst trial");
|
||||
self.load_code(mem_init_code(), 0, BioCore::from(core));
|
||||
self.load_code(mem_init_code(), BioCore::from(core));
|
||||
self.set_core_run_states([core == 0, core == 1, core == 2, core == 3]);
|
||||
for _ in 0..16 {
|
||||
let _ = self.bio.r(utra::bio_bdma::SFR_RXF0);
|
||||
|
|
@ -233,7 +233,7 @@ impl BioSharedState {
|
|||
self.set_core_run_states([false, false, false, false]);
|
||||
}
|
||||
|
||||
pub fn load_code(&mut self, prog: &[u8], offset_bytes: usize, core: BioCore) {
|
||||
pub fn load_code(&mut self, prog: (&[u8], Option<u32>), core: BioCore) {
|
||||
// turn off just the target core
|
||||
let core_num = 1 << (core as usize);
|
||||
self.bio.wo(
|
||||
|
|
@ -241,8 +241,16 @@ impl BioSharedState {
|
|||
self.bio.r(utra::bio_bdma::SFR_CTRL) & !(core_num | core_num << 4 | core_num << 8),
|
||||
);
|
||||
// crate::println!("load code from {:x}", prog.as_ptr() as usize);
|
||||
let offset = offset_bytes / core::mem::size_of::<u32>();
|
||||
for (i, chunk) in prog.chunks(4).enumerate() {
|
||||
let offset = if let Some(pad_word) = prog.1 {
|
||||
// insert the pad_word up top. This ensures the page-offsets of the code line up
|
||||
// with what the linker had specified, effectively replacing the length field with
|
||||
// a word (usually specified as a NOP instruction)
|
||||
self.imem_slice[core as usize][0] = pad_word;
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
for (i, chunk) in prog.0.chunks(4).enumerate() {
|
||||
if chunk.len() == 4 {
|
||||
let word: u32 = u32::from_le_bytes(chunk.try_into().unwrap());
|
||||
self.imem_slice[core as usize][i + offset] = word;
|
||||
|
|
@ -255,7 +263,7 @@ impl BioSharedState {
|
|||
self.imem_slice[core as usize][i + offset] = ragged_word;
|
||||
}
|
||||
}
|
||||
match self.verify_code(&prog, offset_bytes, core) {
|
||||
match self.verify_code(&prog.0, offset * size_of::<u32>(), core) {
|
||||
Err(BioError::CodeCheck(offset)) => {
|
||||
crate::println!("Code verification error at {:x}", offset)
|
||||
}
|
||||
|
|
@ -444,15 +452,14 @@ impl<'a> BioApi<'a> for BioSharedState {
|
|||
fn init_core(
|
||||
&mut self,
|
||||
core: BioCore,
|
||||
code: &[u8],
|
||||
offset: usize,
|
||||
code: (&[u8], Option<u32>),
|
||||
config: CoreConfig,
|
||||
) -> Result<Option<u32>, BioError> {
|
||||
if self.core_config[core as usize].is_some() {
|
||||
return Err(BioError::ResourceInUse);
|
||||
}
|
||||
self.core_config[core as usize] = Some(config);
|
||||
self.load_code(code, offset, core);
|
||||
self.load_code(code, core);
|
||||
Ok(self.apply_config(&config, core))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue