mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add changes to work around BIO code issue
there is either a code bug or a compiler issue that is causing something on stack to be smashed that is causing trouble for the code base as a whole. Or it could be improperly initialized statics? unclear. this needs to be worked through. however, a series of changes were made that make the code work. The biggest tell is that the code generally works perfectly when optimizations are off, but when optimizations are on some shenanigans have to happen to convince the compiler to not split constant values across the entire arc of the function. More diagnostics to follow.
This commit is contained in:
parent
7cf23c41e7
commit
cb1f82ecc8
4 changed files with 206 additions and 103 deletions
|
|
@ -11,16 +11,16 @@ pub fn stack_test() -> usize {
|
|||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x0);
|
||||
bio_ss.load_code(stack_test0_code(), 0, BioCore::Core0);
|
||||
bio_ss.load_code(stack_test1_code(), 0, BioCore::Core1);
|
||||
bio_ss.load_code(stack_test2_code(), 0, BioCore::Core3);
|
||||
bio_ss.load_code(stack_test2_code(), 0, BioCore::Core2);
|
||||
|
||||
// These actually "don't matter" because there are no synchronization instructions in the code
|
||||
// Everything runs at "full tilt"
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x10_0000);
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV1, 0x5_8000);
|
||||
// bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV2, 0x1_0000); // this machine not used in this test
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV3, 0x1_0000);
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV2, 0x1_0000);
|
||||
// bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV3, 0x1_0000); // this machine not used in this test
|
||||
// start the machine
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0xBBB);
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x777);
|
||||
|
||||
// pass two values in
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_TXF0, 3);
|
||||
|
|
@ -33,6 +33,13 @@ pub fn stack_test() -> usize {
|
|||
timeout += 1;
|
||||
if timeout > TIMEOUT {
|
||||
println!("Timed out waiting for result (#1)");
|
||||
crate::println!(
|
||||
"{:04x} {:04x} {:04x} {:04x}",
|
||||
bio_ss.bio.r(utra::bio_bdma::SFR_DBG0),
|
||||
bio_ss.bio.r(utra::bio_bdma::SFR_DBG1),
|
||||
bio_ss.bio.r(utra::bio_bdma::SFR_DBG2),
|
||||
bio_ss.bio.r(utra::bio_bdma::SFR_DBG3),
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -47,7 +54,14 @@ pub fn stack_test() -> usize {
|
|||
while bio_ss.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL3) == 0 {
|
||||
timeout += 1;
|
||||
if timeout > TIMEOUT {
|
||||
println!("Timed out waiting for result (#2)");
|
||||
println!("Timed out waiting for result (#2) {}", bio_ss.bio.r(utra::bio_bdma::SFR_RXF3));
|
||||
crate::println!(
|
||||
"{:04x} {:04x} {:04x} {:04x}",
|
||||
bio_ss.bio.r(utra::bio_bdma::SFR_DBG0),
|
||||
bio_ss.bio.r(utra::bio_bdma::SFR_DBG1),
|
||||
bio_ss.bio.r(utra::bio_bdma::SFR_DBG2),
|
||||
bio_ss.bio.r(utra::bio_bdma::SFR_DBG3),
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -88,6 +102,7 @@ fn test_sum(a: u32) -> u32 { if a == 0 { 0 } else { a + test_sum(a - 1) } }
|
|||
bio_code!(stack_test0_code, STACK_TEST0_START, STACK_TEST0_END,
|
||||
// number to sum to comes into x16
|
||||
// compute sum = N + N-1 + N-2 + ... 0
|
||||
"li sp, 0x800",
|
||||
"20:",
|
||||
"mv a0, x16", // get the argument
|
||||
"jal ra, 30f",
|
||||
|
|
@ -114,6 +129,7 @@ bio_code!(stack_test0_code, STACK_TEST0_START, STACK_TEST0_END,
|
|||
bio_code!(stack_test1_code, STACK_TEST1_START, STACK_TEST1_END,
|
||||
// number to sum to comes into x16
|
||||
// compute sum = N + N-1 + N-2 + ... 0
|
||||
"li sp, 0x800",
|
||||
"20:",
|
||||
"mv a0, x17", // get the argument
|
||||
"jal ra, 30f",
|
||||
|
|
@ -140,6 +156,7 @@ bio_code!(stack_test1_code, STACK_TEST1_START, STACK_TEST1_END,
|
|||
bio_code!(stack_test2_code, STACK_TEST2_START, STACK_TEST2_END,
|
||||
// number to sum to comes into x16
|
||||
// compute sum = N + N-1 + N-2 + ... 0
|
||||
"li sp, 0x800",
|
||||
"20:",
|
||||
"mv a0, x18", // get the argument
|
||||
"jal ra, 30f",
|
||||
|
|
|
|||
|
|
@ -48,25 +48,12 @@ pub fn dma_filter_off() {
|
|||
bio_ss.bio.rmwf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_PERI, 1);
|
||||
}
|
||||
|
||||
pub fn filter_test() -> usize {
|
||||
println!("==Filter test==");
|
||||
// clear any prior test config state
|
||||
let mut test_cfg = CSR::new(utra::csrtest::HW_CSRTEST_BASE as *mut u32);
|
||||
test_cfg.wo(utra::csrtest::WTEST, 0);
|
||||
|
||||
let mut passing = true;
|
||||
#[inline(never)]
|
||||
fn setup_filter() {
|
||||
use utralib::generated::HW_SRAM_MEM as RAM_BASE;
|
||||
use utralib::generated::HW_SRAM_MEM_LEN as RAM_SIZE;
|
||||
|
||||
let mut bio_ss = BioSharedState::new();
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x0);
|
||||
// reset all the fifos
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_FIFO_CLR, 0xF);
|
||||
|
||||
// enable the filters
|
||||
bio_ss.bio.rmwf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_MEM, 0);
|
||||
bio_ss.bio.rmwf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_PERI, 0);
|
||||
|
||||
// "standard filter" setup
|
||||
// the gutter for memory is the highest location of RAM
|
||||
// the gutter for peripherals is the reporting test register
|
||||
|
|
@ -84,6 +71,31 @@ pub fn filter_test() -> usize {
|
|||
bio_ss.bio.wo(utra::bio_bdma::SFR_FILTER_BASE_2, (HW_IOX_BASE as u32) >> 12);
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_FILTER_BOUNDS_2, (0x6000_0000 - HW_IOX_BASE as u32) >> 12);
|
||||
|
||||
for i in (0..2).into_iter().chain((40..42).into_iter().chain((56..64).into_iter())) {
|
||||
crate::println!("{}: {:08x}", i, unsafe { ((0x50124000) as *const u32).add(i).read_volatile() })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filter_test() -> usize {
|
||||
println!("==Filter test==");
|
||||
// clear any prior test config state
|
||||
let mut test_cfg = CSR::new(utra::csrtest::HW_CSRTEST_BASE as *mut u32);
|
||||
test_cfg.wo(utra::csrtest::WTEST, 0);
|
||||
|
||||
let mut passing = true;
|
||||
|
||||
let mut bio_ss = BioSharedState::new();
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x0);
|
||||
// reset all the fifos
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_FIFO_CLR, 0xF);
|
||||
|
||||
setup_filter();
|
||||
|
||||
// enable the filters
|
||||
bio_ss.bio.rmwf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_MEM, 0);
|
||||
bio_ss.bio.rmwf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_PERI, 0);
|
||||
crate::println!("config: {:x}", bio_ss.bio.r(utra::bio_bdma::SFR_CONFIG));
|
||||
|
||||
// with the filters so set, test some transactions that "should" pass
|
||||
if dma_basic(false, 0) != 4 {
|
||||
passing = false;
|
||||
|
|
@ -94,11 +106,13 @@ pub fn filter_test() -> usize {
|
|||
// *** increments 3 ret values total
|
||||
// - access to the BIO_BDMA registers: try to disable the filters.
|
||||
println!("attempt to violate peri filter");
|
||||
if bio_ss.bio.rf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_MEM) != 0 {
|
||||
let cfg = unsafe { ((0x50124000 + 8) as *const u32).read_volatile() };
|
||||
crate::println!("config: {:x}", cfg);
|
||||
if cfg as usize & utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_MEM.mask() != 0 {
|
||||
passing = false;
|
||||
println!("peri range filter pre-condition fail A");
|
||||
}
|
||||
if bio_ss.bio.rf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_PERI) != 0 {
|
||||
if cfg as usize & utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_PERI.mask() != 0 {
|
||||
passing = false;
|
||||
println!("peri range filter pre-condition fail B");
|
||||
}
|
||||
|
|
@ -117,14 +131,20 @@ pub fn filter_test() -> usize {
|
|||
while bio_ss.bio.r(utra::bio_bdma::SFR_EVENT_STATUS) & 0x1 == 0 {}
|
||||
cache_flush();
|
||||
// check that the values did not change
|
||||
if bio_ss.bio.rf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_MEM) != 0 {
|
||||
let cfg = unsafe { ((0x5012_4008) as *const u32).read_volatile() };
|
||||
crate::println!("config2: {:x}", cfg);
|
||||
if cfg as usize & (1 << utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_MEM.offset()) != 0 {
|
||||
passing = false;
|
||||
println!("peri range filter FAIL A");
|
||||
}
|
||||
if bio_ss.bio.rf(utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_PERI) != 0 {
|
||||
if cfg as usize & (1 << utra::bio_bdma::SFR_CONFIG_DISABLE_FILTER_PERI.offset()) != 0 {
|
||||
passing = false;
|
||||
println!("peri range filter FAIL B");
|
||||
}
|
||||
unsafe {
|
||||
((0x5012_4008) as *mut u32).write_volatile(0x0);
|
||||
crate::println!("config3: {:x}", ((0x50124000 + 8) as *const u32).read_volatile());
|
||||
}
|
||||
// attempt to read the config word
|
||||
bio_ss.bio.wo(
|
||||
utra::bio_bdma::SFR_TXF2,
|
||||
|
|
@ -226,7 +246,8 @@ pub fn dma_basic(concurrent: bool, clkmode: u8) -> usize {
|
|||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV2, 0x1_0000);
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV3, 0x1_0000);
|
||||
// start the machine
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x888);
|
||||
// bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x888);
|
||||
bio_ss.set_core_run_states([false, false, false, true]);
|
||||
|
||||
let mut main_mem_src: [u32; TEST_LEN] = [0u32; TEST_LEN];
|
||||
let mut main_mem_dst: [u32; TEST_LEN] = [0u32; TEST_LEN];
|
||||
|
|
@ -345,7 +366,7 @@ bio_code!(dma_basic_code, DMA_BASIC_START, DMA_BASIC_END,
|
|||
"mv a1, x16", // wait for # of bytes to move
|
||||
|
||||
"sw x0, 0(a2)", // make sure write pipeline is in a good state
|
||||
"sw x0, 0(a2)", // make sure write pipeline is in a good state
|
||||
// "sw x0, 0(a2)", // make sure write pipeline is in a good state - maybe required due to hw issue in some clock modes, needs more testing
|
||||
|
||||
"add a4, a1, a3", // a4 <- end condition based on source address increment
|
||||
|
||||
|
|
@ -479,7 +500,8 @@ pub fn dma_u16() -> usize {
|
|||
// Everything runs at "full tilt"
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV3, 0x1_0000);
|
||||
// start the machine
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x888);
|
||||
// bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x888);
|
||||
bio_ss.set_core_run_states([false, false, false, true]);
|
||||
|
||||
let mut main_mem_src: [u16; 64] = [0u16; 64];
|
||||
let mut main_mem_dst: [u16; 64] = [0u16; 64];
|
||||
|
|
@ -596,8 +618,8 @@ pub fn dma_multicore(clkmode: u8) -> usize {
|
|||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV1, 0x1_0000);
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV2, 0x1_0000);
|
||||
// start the machine
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x777);
|
||||
|
||||
// bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x777);
|
||||
bio_ss.set_core_run_states([true, true, true, false]);
|
||||
let mut tp = TestPattern::new(Some(0x100));
|
||||
let mut main_mem_src: [u32; 16] = [0u32; 16];
|
||||
let mut main_mem_dst: [u32; 16] = [0u32; 16];
|
||||
|
|
@ -611,11 +633,23 @@ pub fn dma_multicore(clkmode: u8) -> usize {
|
|||
bio_ss.bio.wo(utra::bio_bdma::SFR_TXF2, (main_mem_src.len() * size_of::<u32>()) as u32); // bytes to move
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_TXF3, main_mem_dst.as_ptr() as u32); // dst address
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_TXF3, (main_mem_src.len() * size_of::<u32>()) as u32); // bytes to move
|
||||
while bio_ss.bio.r(utra::bio_bdma::SFR_EVENT_STATUS) & 0xF00 != 0x500 {} // trying some creative bit patterns
|
||||
// wait for the fifo to clear, which means all copies are done
|
||||
// this line has to be replaced with the loop below because there is a bug somewhere in the rust
|
||||
// code causing some stack data to be overwritten? maybe?
|
||||
// while bio_ss.bio.r(utra::bio_bdma::SFR_EVENT_STATUS) & 0xF00 != 0x500 {} // trying some creative bit
|
||||
// START HERE for figuring out stack issue
|
||||
loop {
|
||||
let stat = bio_ss.bio.r(utra::bio_bdma::SFR_EVENT_STATUS);
|
||||
let digit_of_interest = (stat >> 8) & 0xF;
|
||||
println!("stat: {:x}-> {:x}", stat, digit_of_interest);
|
||||
if digit_of_interest == 5 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// patterns wait for the fifo to clear, which means all copies are done
|
||||
while bio_ss.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL0) != 0 {}
|
||||
cache_flush();
|
||||
let mut pass = 1;
|
||||
println!("here5");
|
||||
for (i, &d) in main_mem_src.iter().enumerate() {
|
||||
let rbk = unsafe { main_mem_dst.as_ptr().add(i).read_volatile() };
|
||||
if rbk != d {
|
||||
|
|
@ -701,7 +735,8 @@ pub fn dma_coincident(clkmode: u8) -> usize {
|
|||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV2, 0x1_0000);
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV3, 0x1_0000);
|
||||
// start the machine
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0xFFF);
|
||||
bio_ss.set_core_run_states([true, true, true, true]);
|
||||
//bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0xFFF);
|
||||
|
||||
let mut main_mem_src: [u32; 16 * 4] = [0u32; 16 * 4];
|
||||
let mut main_mem_dst: [u32; 16 * 4] = [0u32; 16 * 4];
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use crate::*;
|
|||
pub fn hello_world() -> usize {
|
||||
println!("hello world test");
|
||||
let mut bio_ss = BioSharedState::new();
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x0);
|
||||
let simple_test_code = hello_world_code();
|
||||
// copy code to reset vector for 0th machine
|
||||
bio_ss.load_code(simple_test_code, 0, BioCore::Core0);
|
||||
|
|
@ -1023,8 +1024,10 @@ pub fn aclk_tests() -> usize {
|
|||
|
||||
// start machine 1
|
||||
bio_ss.bio.wo(utra::bio_bdma::SFR_CTRL, 0x222);
|
||||
while bio_ss.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1) < 7 {
|
||||
let mut timeout = 0;
|
||||
while bio_ss.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1) < 7 && timeout < 100 {
|
||||
println!("waiting {}", bio_ss.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1));
|
||||
timeout += 1;
|
||||
// wait
|
||||
}
|
||||
let mut results = [0u32; 7];
|
||||
|
|
|
|||
|
|
@ -49,6 +49,18 @@ pub enum BioCore {
|
|||
Core3 = 3,
|
||||
}
|
||||
|
||||
impl From<usize> for BioCore {
|
||||
fn from(value: usize) -> Self {
|
||||
match value {
|
||||
0 => BioCore::Core0,
|
||||
1 => BioCore::Core1,
|
||||
2 => BioCore::Core2,
|
||||
3 => BioCore::Core3,
|
||||
_ => panic!("Invalid BioCore value: {}", value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum BioError {
|
||||
/// specified state machine is not valid
|
||||
|
|
@ -165,7 +177,76 @@ impl BioSharedState {
|
|||
}
|
||||
}
|
||||
|
||||
/// This will overwrite *all* of the current core states with
|
||||
/// the states specified in the `cores` argument, such that
|
||||
/// `true` indicates the core should be enabled and running.
|
||||
///
|
||||
/// Notably, this will also turn off any cores that are marked
|
||||
/// as `false`. A different method needs to be written if
|
||||
/// we want to independently manipulate core states without
|
||||
/// affecting others. However, it's envisioned to be mostly
|
||||
/// the case that users will manage the full set of programs
|
||||
/// running on all four cores and not necessarily have a
|
||||
/// dynamically-loaded, multi-tenant situation, so this simpler
|
||||
/// API is more ergonomic to use than e.g. the generic case
|
||||
/// of passing Option<bool> for every core state to additionally
|
||||
/// specify if the core should be changed or left alone.
|
||||
#[inline(never)]
|
||||
pub fn set_core_run_states(&mut self, cores: [bool; 4]) {
|
||||
self.bio.wo(utra::bio_bdma::SFR_CTRL, 0); // turn off all the cores first
|
||||
let mut core_code = 0;
|
||||
for (i, &core) in cores.iter().enumerate() {
|
||||
if core {
|
||||
core_code |= 1 << i;
|
||||
}
|
||||
}
|
||||
let core_mask = core_code | core_code << 4 | core_code << 8;
|
||||
self.bio.wo(utra::bio_bdma::SFR_CTRL, core_mask);
|
||||
let mut timeout = 0;
|
||||
loop {
|
||||
let ctrl = self.bio.r(utra::bio_bdma::SFR_CTRL) & 0xFF0;
|
||||
if ctrl == 0 {
|
||||
break;
|
||||
}
|
||||
timeout += 1;
|
||||
if timeout > 1000 {
|
||||
crate::println!("Timeout on set_core_run_states: req {:x} != rbk {:x}", core_code, ctrl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
let check = self.bio.r(utra::bio_bdma::SFR_CTRL);
|
||||
if check != core_code {
|
||||
crate::println!("run-state check failed: {:x}", check);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(&mut self) {
|
||||
// set clocking mode to 3
|
||||
self.bio.wfo(utra::bio_bdma::SFR_CONFIG_CLOCKING_MODE, 3);
|
||||
self.bio.wo(utra::bio_bdma::SFR_EXTCLOCK, 0);
|
||||
self.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x0_0000);
|
||||
self.bio.wo(utra::bio_bdma::SFR_QDIV1, 0x0_0000);
|
||||
self.bio.wo(utra::bio_bdma::SFR_QDIV2, 0x0_0000);
|
||||
self.bio.wo(utra::bio_bdma::SFR_QDIV3, 0x0_0000);
|
||||
|
||||
for core in 0..4 {
|
||||
// crate::println!("ldst trial");
|
||||
let core_num = 1 << (core as usize);
|
||||
self.load_code(mem_init_code(), 0, BioCore::from(core));
|
||||
self.bio.wo(
|
||||
utra::bio_bdma::SFR_CTRL,
|
||||
self.bio.r(utra::bio_bdma::SFR_CTRL) | (core_num | core_num << 4 | core_num << 8),
|
||||
);
|
||||
for _ in 0..16 {
|
||||
let _ = self.bio.r(utra::bio_bdma::SFR_RXF0);
|
||||
let _ = self.bio.r(utra::bio_bdma::SFR_RXF1);
|
||||
let _ = self.bio.r(utra::bio_bdma::SFR_RXF2);
|
||||
let _ = self.bio.r(utra::bio_bdma::SFR_RXF3);
|
||||
}
|
||||
// crate::println!("ldst trial end");
|
||||
}
|
||||
self.bio.wfo(utra::bio_bdma::SFR_FIFO_CLR_SFR_FIFO_CLR, 0xf);
|
||||
|
||||
self.bio.wo(utra::bio_bdma::SFR_CTRL, 0x0);
|
||||
for imem in self.imem_slice.iter_mut() {
|
||||
// jump to current location
|
||||
|
|
@ -179,41 +260,8 @@ impl BioSharedState {
|
|||
}
|
||||
}
|
||||
|
||||
// This may not scale to e.g. shared memory model but trying to see its impact
|
||||
let fifo_slice = unsafe {
|
||||
[
|
||||
core::slice::from_raw_parts_mut(
|
||||
utralib::generated::HW_BIO_FIFO0_MEM as *mut u32,
|
||||
HW_BIO_FIFO0_MEM_LEN / size_of::<u32>(),
|
||||
),
|
||||
core::slice::from_raw_parts_mut(
|
||||
utralib::generated::HW_BIO_FIFO1_MEM as *mut u32,
|
||||
HW_BIO_FIFO1_MEM_LEN / size_of::<u32>(),
|
||||
),
|
||||
core::slice::from_raw_parts_mut(
|
||||
utralib::generated::HW_BIO_FIFO2_MEM as *mut u32,
|
||||
HW_BIO_FIFO2_MEM_LEN / size_of::<u32>(),
|
||||
),
|
||||
core::slice::from_raw_parts_mut(
|
||||
utralib::generated::HW_BIO_FIFO3_MEM as *mut u32,
|
||||
HW_BIO_FIFO3_MEM_LEN / size_of::<u32>(),
|
||||
),
|
||||
]
|
||||
};
|
||||
for (i, fifo) in fifo_slice.iter().enumerate() {
|
||||
crate::println!("fifo{}: {:x}", i, fifo[0]);
|
||||
}
|
||||
|
||||
// set clocking mode to 3
|
||||
self.bio.wfo(utra::bio_bdma::SFR_CONFIG_CLOCKING_MODE, 3);
|
||||
self.bio.wo(utra::bio_bdma::SFR_EXTCLOCK, 0);
|
||||
self.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x0_0000);
|
||||
self.bio.wo(utra::bio_bdma::SFR_QDIV1, 0x0_0000);
|
||||
self.bio.wo(utra::bio_bdma::SFR_QDIV2, 0x0_0000);
|
||||
self.bio.wo(utra::bio_bdma::SFR_QDIV3, 0x0_0000);
|
||||
self.bio.wo(utra::bio_bdma::SFR_CTRL, 0xFFF);
|
||||
self.bio.wfo(utra::bio_bdma::SFR_FIFO_CLR_SFR_FIFO_CLR, 0xf);
|
||||
for _ in 0..8 {
|
||||
for _ in 0..16 {
|
||||
let _ = self.bio.r(utra::bio_bdma::SFR_RXF0);
|
||||
let _ = self.bio.r(utra::bio_bdma::SFR_RXF1);
|
||||
let _ = self.bio.r(utra::bio_bdma::SFR_RXF2);
|
||||
|
|
@ -221,29 +269,16 @@ impl BioSharedState {
|
|||
}
|
||||
self.bio.wfo(utra::bio_bdma::SFR_FIFO_CLR_SFR_FIFO_CLR, 0xf);
|
||||
self.bio.wo(utra::bio_bdma::SFR_CTRL, 0x0);
|
||||
crate::println!(
|
||||
"{:04x} {:04x} {:04x} {:04x}",
|
||||
self.bio.r(utra::bio_bdma::SFR_DBG0),
|
||||
self.bio.r(utra::bio_bdma::SFR_DBG1),
|
||||
self.bio.r(utra::bio_bdma::SFR_DBG2),
|
||||
self.bio.r(utra::bio_bdma::SFR_DBG3),
|
||||
);
|
||||
|
||||
/*
|
||||
crate::println!("ldst trial");
|
||||
self.bio.wo(utra::bio_bdma::SFR_CTRL, 0x000);
|
||||
self.load_code(ldst_code(), 0, BioCore::Core0);
|
||||
self.load_code(ldst_code(), 0, BioCore::Core1);
|
||||
self.load_code(ldst_code(), 0, BioCore::Core2);
|
||||
self.load_code(ldst_code(), 0, BioCore::Core3);
|
||||
self.bio.wo(utra::bio_bdma::SFR_CTRL, 0xFFF);
|
||||
crate::println!("ldst trial end");
|
||||
self.bio.wo(utra::bio_bdma::SFR_CTRL, 0x000);
|
||||
*/
|
||||
}
|
||||
|
||||
pub fn load_code(&mut self, prog: &[u8], offset_bytes: usize, core: BioCore) {
|
||||
crate::println!("load code from {:x}", prog.as_ptr() as usize);
|
||||
// turn off just the target core
|
||||
let core_num = 1 << (core as usize);
|
||||
self.bio.wo(
|
||||
utra::bio_bdma::SFR_CTRL,
|
||||
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() {
|
||||
if chunk.len() == 4 {
|
||||
|
|
@ -264,7 +299,6 @@ impl BioSharedState {
|
|||
}
|
||||
_ => (),
|
||||
}
|
||||
cache_flush();
|
||||
}
|
||||
|
||||
pub fn verify_code(&mut self, prog: &[u8], offset_bytes: usize, core: BioCore) -> Result<(), BioError> {
|
||||
|
|
@ -290,6 +324,26 @@ impl BioSharedState {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn debug_pc(&self) {
|
||||
crate::println!(
|
||||
"c0:{:04x} c1:{:04x} c2:{:04x} c3:{:04x}",
|
||||
self.bio.r(utra::bio_bdma::SFR_DBG0),
|
||||
self.bio.r(utra::bio_bdma::SFR_DBG1),
|
||||
self.bio.r(utra::bio_bdma::SFR_DBG2),
|
||||
self.bio.r(utra::bio_bdma::SFR_DBG3),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn debug_fifo(&self) {
|
||||
crate::println!(
|
||||
"f0:{:04x} f1:{:04x} f2:{:04x} f3:{:04x}",
|
||||
self.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL0),
|
||||
self.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL1),
|
||||
self.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL2),
|
||||
self.bio.rf(utra::bio_bdma::SFR_FLEVEL_PCLK_REGFIFO_LEVEL3),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
@ -335,18 +389,12 @@ macro_rules! bio_code {
|
|||
};
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn cache_flush() {
|
||||
unsafe {
|
||||
// cache flush
|
||||
#[rustfmt::skip]
|
||||
core::arch::asm!(
|
||||
"fence.i",
|
||||
".word 0x500F",
|
||||
"nop",
|
||||
"nop",
|
||||
"nop",
|
||||
"nop",
|
||||
);
|
||||
}
|
||||
}
|
||||
#[rustfmt::skip]
|
||||
bio_code!(mem_init_code, MEM_INIT_START, MEM_INIT_END,
|
||||
"sw x0, 0x20(x0)",
|
||||
"li sp, 0x61200000",
|
||||
"addi sp, sp, -4",
|
||||
"sw x0, 0(sp)",
|
||||
"10:",
|
||||
"j 10b"
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue