diff --git a/Cargo.lock b/Cargo.lock index fa52ee70e..5df89ca82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1018,6 +1018,7 @@ dependencies = [ name = "cram-mbox1" version = "0.1.0" dependencies = [ + "aes 0.8.3", "log", "num-derive 0.4.2", "num-traits", diff --git a/kernel/src/arch/riscv/irq.rs b/kernel/src/arch/riscv/irq.rs index a3800a747..b7b2cbe4d 100644 --- a/kernel/src/arch/riscv/irq.rs +++ b/kernel/src/arch/riscv/irq.rs @@ -50,22 +50,35 @@ fn sip_read() -> usize { existing } +// using verilator-only as a proxy for the cramium-soc config; +// when the flag is off, assume precursor config +#[cfg(all(feature = "vexii-test", feature = "verilator-only"))] +use crate::platform::cramium::{ + LEGACY_INT_VMEM, + legacy_int::{SUPER_MASK, SUPER_PENDING}, +}; +#[cfg(all(feature = "vexii-test", not(feature = "verilator-only")))] +use crate::platform::precursor::{ + LEGACY_INT_VMEM, + legacy_int::{SUPER_MASK, SUPER_PENDING}, +}; + #[cfg(feature = "vexii-test")] fn sim_read() -> usize { - let legacy_int = utralib::CSR::new(crate::platform::precursor::LEGACY_INT_VMEM as *mut u32); - legacy_int.r(crate::platform::precursor::legacy_int::SUPER_MASK) as usize + let legacy_int = utralib::CSR::new(LEGACY_INT_VMEM as *mut u32); + legacy_int.r(SUPER_MASK) as usize } #[cfg(feature = "vexii-test")] fn sim_write(new: usize) { - let mut legacy_int = utralib::CSR::new(crate::platform::precursor::LEGACY_INT_VMEM as *mut u32); - legacy_int.wo(crate::platform::precursor::legacy_int::SUPER_MASK, new as u32); + let mut legacy_int = utralib::CSR::new(LEGACY_INT_VMEM as *mut u32); + legacy_int.wo(SUPER_MASK, new as u32); } #[cfg(feature = "vexii-test")] fn sip_read() -> usize { - let legacy_int = utralib::CSR::new(crate::platform::precursor::LEGACY_INT_VMEM as *mut u32); - legacy_int.r(crate::platform::precursor::legacy_int::SUPER_PENDING) as usize + let legacy_int = utralib::CSR::new(LEGACY_INT_VMEM as *mut u32); + legacy_int.r(SUPER_PENDING) as usize } /// Disable external interrupts diff --git a/kernel/src/platform/cramium/mod.rs b/kernel/src/platform/cramium/mod.rs index f38f9e7e1..c2bc5f633 100644 --- a/kernel/src/platform/cramium/mod.rs +++ b/kernel/src/platform/cramium/mod.rs @@ -12,8 +12,56 @@ pub use rand_fake as rand; #[cfg(any(feature = "debug-print", feature = "print-panics"))] pub mod uart; +#[cfg(feature = "vexii-test")] +use crate::{MemoryFlags, MemoryType, PID, mem::MemoryManager}; +#[cfg(feature = "vexii-test")] +pub const LEGACY_INT_VMEM: usize = 0xffcf_1000; // see https://github.com/betrusted-io/xous-core/blob/master/docs/memory.md + +#[allow(dead_code)] +#[cfg(feature = "vexii-test")] +pub mod legacy_int { + // this enum is vestigal, and currently not used by anything + #[derive(Debug, Copy, Clone)] + pub enum LegacyIntOffset { + MachMask = 0, + MachPending = 1, + SuperMask = 2, + SuperPending = 3, + } + pub const LEGACY_INT_NUMREGS: usize = 4; + + pub const MACH_MASK: utralib::Register = utralib::Register::new(0, 0xffffffff); + pub const MACH_MASK_MACH_MASK: utralib::Field = utralib::Field::new(32, 0, MACH_MASK); + + pub const MACH_PENDING: utralib::Register = utralib::Register::new(1, 0xffffffff); + pub const MACH_PENDING_MACH_PENDING: utralib::Field = utralib::Field::new(32, 0, MACH_PENDING); + + pub const SUPER_MASK: utralib::Register = utralib::Register::new(2, 0xffffffff); + pub const SUPER_MASK_SUPER_MASK: utralib::Field = utralib::Field::new(32, 0, SUPER_MASK); + + pub const SUPER_PENDING: utralib::Register = utralib::Register::new(3, 0xffffffff); + pub const SUPER_PENDING_SUPER_PENDING: utralib::Field = utralib::Field::new(32, 0, SUPER_PENDING); + + pub const HW_LEGACY_INT_BASE: usize = 0xe001d000; +} + /// Precursor specific initialization. pub fn init() { + #[cfg(feature = "vexii-test")] + // Map the interrupt manager shim + MemoryManager::with_mut(|memory_manager| { + memory_manager + .map_range( + legacy_int::HW_LEGACY_INT_BASE as *mut u8, + (LEGACY_INT_VMEM & !4095) as *mut u8, + 4096, + PID::new(1).unwrap(), + MemoryFlags::R | MemoryFlags::W, + MemoryType::Default, + ) + .expect("unable to map legacy interrupt shim for vexii CPU") + }); + self::rand::init(); #[cfg(any(feature = "debug-print", feature = "print-panics"))] self::uart::init(); diff --git a/loader/Cargo.toml b/loader/Cargo.toml index ece31a285..ab23348d7 100644 --- a/loader/Cargo.toml +++ b/loader/Cargo.toml @@ -101,7 +101,7 @@ board-baosec = [ ] board-baosor = ["cramium-hal/loader-baosor"] board-dabao = ["cramium-hal/loader-dabao"] -cramium-fpga = ["utralib/cramium-fpga", "debug-print"] +cramium-fpga = ["utralib/cramium-fpga", "debug-print", "linked_list_allocator"] atsama5d27 = ["utralib/atsama5d27", "armv7", "dep:atsama5d27"] # precursor flags diff --git a/loader/build.rs b/loader/build.rs index 19d75180d..f41eab36d 100644 --- a/loader/build.rs +++ b/loader/build.rs @@ -13,7 +13,7 @@ fn main() { #[cfg(feature = "cramium-soc")] let p = PathBuf::from("src/platform/cramium/link-soc.x"); #[cfg(feature = "cramium-fpga")] - let p = PathBuf::from("src/platform/cramium/link-soc.x"); // note deviation -- this is because we are still simulating the FPGA model and offsets are not yet settled for that + let p = PathBuf::from("src/platform/cramium/link-fpga.x"); #[cfg(not(any(feature = "cramium-soc", feature = "cramium-fpga")))] let p = PathBuf::from("src/platform/precursor/link.x"); diff --git a/loader/src/main.rs b/loader/src/main.rs index 0a4b897d5..976041287 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -167,7 +167,7 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) loop {} }; - #[cfg(feature = "vexii-test")] + #[cfg(all(feature = "vexii-test", not(feature = "verilator-only")))] { // fake the prehash use ed25519_dalek_loader::Digest; diff --git a/loader/src/phase2.rs b/loader/src/phase2.rs index eb2e67607..16a6c1c2e 100644 --- a/loader/src/phase2.rs +++ b/loader/src/phase2.rs @@ -339,7 +339,7 @@ pub fn phase_2(cfg: &mut BootConfig, fs_prehash: &[u8; 64]) { 1, // Kernel is PID 1 ); } - #[cfg(feature = "debug-print")] + #[cfg(all(feature = "debug-print", not(feature = "verilator-only")))] // print the kernel's page table mappings as a sanity check on the loader debug::print_pagetable(cfg.processes[0].satp); diff --git a/loader/src/platform/cramium/link-fpga.x b/loader/src/platform/cramium/link-fpga.x index 8b0e921ca..12b341504 100644 --- a/loader/src/platform/cramium/link-fpga.x +++ b/loader/src/platform/cramium/link-fpga.x @@ -1,12 +1,11 @@ MEMORY { /* we are using an unsigned loader, so the offset is not 1k offset */ - FLASH : ORIGIN = 0x60500000, LENGTH = 32k - RAM : ORIGIN = 0x61000000, LENGTH = 16M + /* if the font location is adjusted, this needs to be updated in libs/blitstr2 codegen templates.go FONT_BASE value */ + FONTS : ORIGIN = 0x60040000, LENGTH = 128k + FLASH : ORIGIN = 0x60001000, LENGTH = 252k + RAM : ORIGIN = 0x61000000, LENGTH = 2M } -/* -Fonts go from 0x2053_0000 to 0x2097_0000 -*/ REGION_ALIAS("REGION_TEXT", FLASH); REGION_ALIAS("REGION_RODATA", FLASH); @@ -88,12 +87,12 @@ SECTIONS . = ALIGN(4); _edata = .; } > REGION_DATA AT > REGION_RODATA - - /* .fonts : ALIGN(65536) +/* + .fonts : ALIGN(65536) { KEEP(*(.fontdata)); - } > FONTS */ - + } > FONTS +*/ .bss (NOLOAD) : { _sbss = .; diff --git a/services/cram-mbox1/Cargo.toml b/services/cram-mbox1/Cargo.toml index 2e5b8506a..2b11503ff 100644 --- a/services/cram-mbox1/Cargo.toml +++ b/services/cram-mbox1/Cargo.toml @@ -14,10 +14,14 @@ log-server = { package = "xous-api-log", version = "0.1.65" } log = "0.4.14" num-derive = { version = "0.4.2", default-features = false } num-traits = { version = "0.2.14", default-features = false } +aes = { path = "../aes" } [features] "cramium" = ["utralib/cramium-fpga"] +"vexii-test" = ["aes/vexii-test"] +"aestests" = [] "hwsim" = [] +"message-test" = [] # ext specifies to use the APB client, instead of the loopback local "ext" = [] # must match setting in cram-mbox2 default = ["cramium"] diff --git a/services/cram-mbox1/src/main.rs b/services/cram-mbox1/src/main.rs index da9d4f748..c9c7eb170 100644 --- a/services/cram-mbox1/src/main.rs +++ b/services/cram-mbox1/src/main.rs @@ -168,6 +168,104 @@ fn main() { // enable the interrupt mailbox.csr.wo(utra::mailbox::EV_ENABLE, !0); // enable everything + #[cfg(feature = "message-test")] + { + #[cfg(feature = "hwsim")] + let c_csr = xous::syscall::map_memory( + xous::MemoryAddress::new(utra::main::HW_MAIN_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map Core Control CSR range"); + #[cfg(feature = "hwsim")] + let mut core_csr = CSR::new(c_csr.as_mut_ptr() as *mut u32); + + #[cfg(feature = "aestests")] + { + use aes::cipher::generic_array::GenericArray; + use aes::cipher::{BlockDecrypt, BlockEncrypt, KeyInit}; + log::info!("AES"); + const TEST_MAX_LEN: usize = 4096; + let mut dataset_op = [0u8; TEST_MAX_LEN]; + for (i, d) in dataset_op.iter_mut().enumerate() { + *d = i as u8; + } + log::info!("key"); + let key_array: [u8; 32] = [0; 32]; + let key = GenericArray::from_slice(&key_array); + let cipher_hw = aes::Aes256::new(&key); + log::info!("round"); + for iter in 0..2 { + core_csr.wfo(utra::main::REPORT_REPORT, 0xae50_0000 + iter); + for (i, mut chunk) in dataset_op.chunks_exact_mut(aes::BLOCK_SIZE).enumerate() { + let mut block = GenericArray::clone_from_slice(&mut chunk); + core_csr.wfo(utra::main::REPORT_REPORT, 0xae5e_0000 + iter + ((i as u32) << 16)); + cipher_hw.encrypt_block(&mut block); + core_csr.wfo(utra::main::REPORT_REPORT, 0xae5e_1000 + iter + ((i as u32) << 16)); + for (&src, dst) in block.iter().zip(chunk.iter_mut()) { + *dst = src; + } + } + for (i, mut chunk) in dataset_op.chunks_exact_mut(aes::BLOCK_SIZE).enumerate() { + let mut block = GenericArray::clone_from_slice(&mut chunk); + core_csr.wfo(utra::main::REPORT_REPORT, 0xae5d_0000 + iter + ((i as u32) << 16)); + cipher_hw.decrypt_block(&mut block); + core_csr.wfo(utra::main::REPORT_REPORT, 0xae5d_1000 + iter + ((i as u32) << 16)); + for (&src, dst) in block.iter().zip(chunk.iter_mut()) { + *dst = src; + } + } + if iter == 0 { + log::info!("0 done"); + } + } + log::info!("done"); + } + + let tt = xous_api_ticktimer::Ticktimer::new().unwrap(); + let mut total = 0; + let mut iter = 0; + log::info!("running message passing test"); + loop { + // this conjures a scalar message + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x1111_0000 + iter); + let now = tt.elapsed_ms(); + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x2222_0000 + iter); + total += now; + + if iter >= 8 && iter < 12 { + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D001); + tt.sleep_ms(1).ok(); + } else if iter >= 12 && iter < 13 { + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002); + tt.sleep_ms(2).ok(); + } else if iter >= 13 && iter < 14 { + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002); + tt.sleep_ms(3).ok(); + } else if iter >= 14 { + break; + } + + // something lame to just conjure a memory message + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x3333_0000 + iter); + let version = tt.get_version(); + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, 0x4444_0000 + iter); + total += version.len() as u64; + iter += 1; + #[cfg(feature = "hwsim")] + core_csr.wfo(utra::main::REPORT_REPORT, now as u32); + log::info!("message passing test progress: {}ms", tt.elapsed_ms()); + } + log::info!("total: {}", total); // consume the total value so it's not optimized out + } // tests to run: // all tests take the form of loopback, data transmit -> data receive ^ 0xaaaa_0000 // diff --git a/utralib/cramium/soc.svd b/utralib/cramium/soc.svd index 3612be918..d2a669edd 100644 --- a/utralib/cramium/soc.svd +++ b/utralib/cramium/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -75,10 +75,25 @@ + + REPORT + 0x0008 + 0x00 + 32 + + + report + 31 + [31:0] + 0 + + + + 0 - 0x8 + 0xc registers diff --git a/utralib/src/generated/cramium_fpga.rs b/utralib/src/generated/cramium_fpga.rs index 2ab8da9cc..54f5118ca 100644 --- a/utralib/src/generated/cramium_fpga.rs +++ b/utralib/src/generated/cramium_fpga.rs @@ -458,7 +458,7 @@ pub mod utra { } pub mod main { - pub const MAIN_NUMREGS: usize = 2; + pub const MAIN_NUMREGS: usize = 3; pub const DONE: crate::Register = crate::Register::new(0, 0x1); pub const DONE_DONE: crate::Field = crate::Field::new(1, 0, DONE); @@ -466,6 +466,9 @@ pub mod utra { pub const IRQTEST0: crate::Register = crate::Register::new(1, 0xffff); pub const IRQTEST0_TRIGGER: crate::Field = crate::Field::new(16, 0, IRQTEST0); + pub const REPORT: crate::Register = crate::Register::new(2, 0xffffffff); + pub const REPORT_REPORT: crate::Field = crate::Field::new(32, 0, REPORT); + pub const HW_MAIN_BASE: usize = 0x40081000; } @@ -5676,6 +5679,14 @@ mod tests { let mut baz = main_csr.zf(utra::main::IRQTEST0_TRIGGER, bar); baz |= main_csr.ms(utra::main::IRQTEST0_TRIGGER, 1); main_csr.wfo(utra::main::IRQTEST0_TRIGGER, baz); + + let foo = main_csr.r(utra::main::REPORT); + main_csr.wo(utra::main::REPORT, foo); + let bar = main_csr.rf(utra::main::REPORT_REPORT); + main_csr.rmwf(utra::main::REPORT_REPORT, bar); + let mut baz = main_csr.zf(utra::main::REPORT_REPORT, bar); + baz |= main_csr.ms(utra::main::REPORT_REPORT, 1); + main_csr.wfo(utra::main::REPORT_REPORT, baz); } #[test] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 8ef94547a..ad6af81e7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -560,17 +560,25 @@ fn main() -> Result<(), Box> { // placement in flash is a tension between dev convenience and RAM usage. Things in flash // are resident, non-swapable, but end up making the slow kernel burn process take longer. - let cramium_flash_pkgs = - ["xous-log", "xous-names", "cram-mbox1", "cram-mbox2" /* "cram-hal-service" */].to_vec(); + let cramium_flash_pkgs = [ + "xous-log", + "xous-names", + "xous-ticktimer", + "cram-mbox1", + "cram-mbox2", /* "cram-hal-service" */ + ] + .to_vec(); let cramium_swap_pkgs = [].to_vec(); builder.add_loader_feature("debug-print"); + builder.add_loader_feature("verilator-only"); // builder.add_kernel_feature("debug-print"); // builder.add_kernel_feature("debug-swap-verbose"); // builder.add_feature("quantum-timer"); // builder.add_feature("auto-trng"); // automatically initialize TRNG tester inside USB stack builder.add_kernel_feature("v2p"); + builder.add_kernel_feature("verilator-only"); // builder.add_feature("mass-storage"); // builder.add_feature("ditherpunk");