diff --git a/baremetal/Cargo.toml b/baremetal/Cargo.toml index ed67977aa..fe4a4c430 100644 --- a/baremetal/Cargo.toml +++ b/baremetal/Cargo.toml @@ -23,8 +23,8 @@ artybio = [ "xous-bio-bdma/artybio", "xous-bio-bdma/baremetal", ] +artyvexii = ["utralib/artyvexii", "linked_list_allocator"] cramium-soc = ["utralib/cramium-soc"] verilator-only = [] -debug-print = [] -default = ["artybio", "debug-print"] +default = ["artyvexii"] diff --git a/baremetal/build.rs b/baremetal/build.rs index 09be87c45..76eec3ce5 100644 --- a/baremetal/build.rs +++ b/baremetal/build.rs @@ -14,6 +14,8 @@ fn main() { let p = PathBuf::from("src/platform/cramium/link.x"); #[cfg(feature = "artybio")] let p = PathBuf::from("src/platform/artybio/link.x"); + #[cfg(feature = "artyvexii")] + let p = PathBuf::from("src/platform/artyvexii/link.x"); println!("cargo:rerun-if-changed={}", p.clone().into_os_string().into_string().unwrap()); println!("cargo:rustc-link-arg=-Tlink.x"); diff --git a/baremetal/src/main.rs b/baremetal/src/main.rs index 43fb64592..01641d785 100644 --- a/baremetal/src/main.rs +++ b/baremetal/src/main.rs @@ -13,6 +13,7 @@ use core::cell::RefCell; use critical_section::Mutex; use platform::*; use utralib::*; +#[cfg(feature = "artybio")] use xous_bio_bdma::*; use crate::delay; @@ -50,6 +51,7 @@ pub unsafe extern "C" fn rust_entry() -> ! { crate::println!("\n~~Baremetal up!~~\n"); // select a BIO test to run + #[cfg(feature = "artybio")] fifo_basic(); // hello_world(); @@ -83,6 +85,7 @@ pub unsafe extern "C" fn rust_entry() -> ! { // this test requires manual inspection of the outputs // the GPIO pins should toggle with 0x11, 0x12, 0x13... // at the specified quantum rate of the machine. +#[cfg(feature = "artybio")] pub fn hello_world() { crate::println!("hello world test"); let mut bio_ss = BioSharedState::new(); @@ -109,6 +112,7 @@ pub fn hello_world() { } #[rustfmt::skip] +#[cfg(feature = "artybio")] bio_code!(hello_world_code, HELLO_START, HELLO_END, "li t0, 0xFFFFFFFF", // set all pins to outputs "mv x24, t0", @@ -132,6 +136,7 @@ bio_code!(hello_world_code, HELLO_START, HELLO_END, // but with a glitch before major transitions. The output could // be sync'd locked, but we leave it off for this test so we have // a demo of how things look when it's off. +#[cfg(feature = "artybio")] pub fn fifo_basic() -> usize { crate::println!("FIFO basic"); let mut bio_ss = BioSharedState::new(); @@ -202,6 +207,7 @@ pub fn fifo_basic() -> usize { 1 } #[rustfmt::skip] +#[cfg(feature = "artybio")] bio_code!(fifo_basic0_code, FIFO_BASIC0_START, FIFO_BASIC0_END, "li t0, 0xFFFFFFFF", // set all pins to outputs "mv x24, t0", @@ -220,6 +226,7 @@ bio_code!(fifo_basic0_code, FIFO_BASIC0_START, FIFO_BASIC0_END, "j 11b" ); #[rustfmt::skip] +#[cfg(feature = "artybio")] bio_code!(fifo_basic1_code, FIFO_BASIC1_START, FIFO_BASIC1_END, // mach 1 code "91:", @@ -236,6 +243,7 @@ bio_code!(fifo_basic1_code, FIFO_BASIC1_START, FIFO_BASIC1_END, "j 21b" ); #[rustfmt::skip] +#[cfg(feature = "artybio")] bio_code!(fifo_basic2_code, FIFO_BASIC2_START, FIFO_BASIC2_END, // mach 2 code "92:", @@ -244,6 +252,7 @@ bio_code!(fifo_basic2_code, FIFO_BASIC2_START, FIFO_BASIC2_END, "j 92b" ); #[rustfmt::skip] +#[cfg(feature = "artybio")] bio_code!(fifo_basic3_code, FIFO_BASIC3_START, FIFO_BASIC3_END, // mach 3 code "93:", diff --git a/baremetal/src/platform.rs b/baremetal/src/platform.rs index 70da27cb8..00b9413ab 100644 --- a/baremetal/src/platform.rs +++ b/baremetal/src/platform.rs @@ -7,3 +7,8 @@ pub use cramium::*; mod artybio; #[cfg(any(feature = "artybio"))] pub use artybio::*; + +#[cfg(any(feature = "artyvexii"))] +mod artyvexii; +#[cfg(any(feature = "artyvexii"))] +pub use artyvexii::*; diff --git a/baremetal/src/platform/artyvexii.rs b/baremetal/src/platform/artyvexii.rs new file mode 100644 index 000000000..826ee789b --- /dev/null +++ b/baremetal/src/platform/artyvexii.rs @@ -0,0 +1,4 @@ +pub mod artyvexii; +pub use artyvexii::*; +pub mod debug; +pub mod irq; diff --git a/baremetal/src/platform/artyvexii/artyvexii.rs b/baremetal/src/platform/artyvexii/artyvexii.rs new file mode 100644 index 000000000..735f462ca --- /dev/null +++ b/baremetal/src/platform/artyvexii/artyvexii.rs @@ -0,0 +1,78 @@ +use utralib::*; + +#[global_allocator] +static ALLOCATOR: linked_list_allocator::LockedHeap = linked_list_allocator::LockedHeap::empty(); + +// RAM size has 2 pages taken off the top to make space for exception handlers +pub const RAM_SIZE: usize = utralib::generated::HW_MAIN_RAM_MEM_LEN - 8192; +pub const RAM_BASE: usize = utralib::generated::HW_MAIN_RAM_MEM; + +// scratch page for exceptions located at top of RAM +// NOTE: there is an additional page above this for exception stack +pub const SCRATCH_PAGE: usize = RAM_BASE + RAM_SIZE; + +// Arbitrarily placing heap at 16k into RAM, with a 32k length +// Total memory is 400k in size +// RAM starts at 256k, giving 144k RAM total +// Bottom 4k is for static data (.bss section) +// next 64k is heap; rest is stack. +pub const ROM_LEN: usize = 64 * 1024; +pub const BSS_LEN: usize = 4 * 1024; +pub const HEAP_START: usize = RAM_BASE + ROM_LEN + BSS_LEN; +pub const HEAP_LEN: usize = 1024 * 32; + +pub const SYSTEM_CLOCK_FREQUENCY: u32 = 40_000_000; +pub const SYSTEM_TICK_INTERVAL_MS: u32 = 1; + +pub fn early_init() { + // setup interrupts & enable IRQ handler for characters + crate::irq::irq_setup(); + crate::debug::Uart::enable_rx(true); + crate::irq::enable_irq(utra::uart::UART_IRQ); + + // Initialize the timer, which is needed by the delay() function. + let mut timer = CSR::new(utra::timer0::HW_TIMER0_BASE as *mut u32); + // not using interrupts, this will be polled by delay() + timer.wfo(utra::timer0::EV_ENABLE_ZERO, 0); + timer.wfo(utra::timer0::EV_PENDING_ZERO, 1); + + let ms = SYSTEM_TICK_INTERVAL_MS; + timer.wfo(utra::timer0::EN_EN, 0b0); // disable the timer + // load its values + timer.wfo(utra::timer0::LOAD_LOAD, 0); + timer.wfo(utra::timer0::RELOAD_RELOAD, (SYSTEM_CLOCK_FREQUENCY / 1_000) * ms); + // enable the timer + timer.wfo(utra::timer0::EN_EN, 0b1); + + setup_alloc(); +} + +pub fn setup_alloc() { + // Initialize the allocator with heap memory range + crate::println!("Setting up heap @ {:x}-{:x}", HEAP_START, HEAP_START + HEAP_LEN); + crate::println!("Stack @ {:x}-{:x}", HEAP_START + HEAP_LEN, RAM_BASE + RAM_SIZE); + unsafe { + ALLOCATOR.lock().init(HEAP_START as *mut u8, HEAP_LEN); + } +} + +// Install a panic handler when not running tests. +#[cfg(all(not(test)))] +mod panic_handler { + use core::panic::PanicInfo; + #[panic_handler] + fn handle_panic(_arg: &PanicInfo) -> ! { + crate::println!("{}", _arg); + loop {} + } +} + +/// Delay function that delays a given number of milliseconds. +pub fn delay(ms: usize) { + let mut timer = CSR::new(utra::timer0::HW_TIMER0_BASE as *mut u32); + timer.wfo(utra::timer0::EV_PENDING_ZERO, 1); + for _ in 0..ms { + while timer.rf(utra::timer0::EV_PENDING_ZERO) == 0 {} + timer.wfo(utra::timer0::EV_PENDING_ZERO, 1); + } +} diff --git a/baremetal/src/platform/artyvexii/debug.rs b/baremetal/src/platform/artyvexii/debug.rs new file mode 100644 index 000000000..dd4ba83ad --- /dev/null +++ b/baremetal/src/platform/artyvexii/debug.rs @@ -0,0 +1,86 @@ +use utralib::generated::*; + +/// A trait for serial like drivers which allows reading from a source. +#[allow(dead_code)] +pub trait SerialRead { + /// Read a single byte. + fn getc(&mut self) -> Option; +} + +pub struct Uart { + // pub base: *mut u32, +} + +impl Uart { + pub fn putc(&self, c: u8) { + let base = utra::uart::HW_UART_BASE as *mut u32; + let mut uart = CSR::new(base); + // Wait until TXFULL is `0` + while uart.r(utra::uart::TXFULL) != 0 {} + uart.wo(utra::uart::RXTX, c as u32) + } + + #[allow(dead_code)] + pub fn enable_rx(enable: bool) { + let base = utra::uart::HW_UART_BASE as *mut u32; + let mut uart = CSR::new(base); + if enable { + uart.rmwf(utra::uart::EV_ENABLE_RX, 1); + } else { + uart.rmwf(utra::uart::EV_ENABLE_RX, 0); + } + } +} + +use core::fmt::{Error, Write}; +impl Write for Uart { + fn write_str(&mut self, s: &str) -> Result<(), Error> { + for c in s.bytes() { + self.putc(c); + } + Ok(()) + } +} + +impl SerialRead for Uart { + fn getc(&mut self) -> Option { + let base = utra::uart::HW_UART_BASE as *mut u32; + let mut uart = CSR::new(base); + // If EV_PENDING_RX is 1, return the pending character. + // Otherwise, return None. + match uart.rf(utra::uart::RXEMPTY_RXEMPTY) { + 1 => None, + _ => { + let ret = Some(uart.r(utra::uart::RXTX) as u8); + uart.wfo(utra::uart::EV_PENDING_RX, 1); + ret + } + } + } +} + +#[macro_use] +pub mod debug_print_hardware { + #[macro_export] + macro_rules! print + { + ($($args:tt)+) => ({ + use core::fmt::Write; + let _ = write!(crate::debug::Uart {}, $($args)+); + }); + } +} + +#[macro_export] +macro_rules! println +{ + () => ({ + $crate::print!("\r\n") + }); + ($fmt:expr) => ({ + $crate::print!(concat!($fmt, "\r\n")) + }); + ($fmt:expr, $($args:tt)+) => ({ + $crate::print!(concat!($fmt, "\r\n"), $($args)+) + }); +} diff --git a/baremetal/src/platform/artyvexii/irq.rs b/baremetal/src/platform/artyvexii/irq.rs new file mode 100644 index 000000000..3ba89a869 --- /dev/null +++ b/baremetal/src/platform/artyvexii/irq.rs @@ -0,0 +1,208 @@ +use riscv::register::{mcause, mie, mstatus}; + +use crate::*; + +pub fn irq_setup() { + unsafe { + #[rustfmt::skip] + core::arch::asm!( + // Set trap handler, which will be called + // on interrupts and cpu faults + "la t0, _start_trap", // this first one forces the nop sled symbol to be generated + "la t0, _start_trap_aligned", // this is the actual target + "csrw mtvec, t0", + ); + } + + let mut legacy_int = CSR::new(HW_LEGACY_INT_BASE as *mut u32); + legacy_int.wo(utra::legacy_int::MACH_MASK, 0); // first make sure everything is disabled, so we aren't OR'ing in garbage + unsafe { + mstatus::set_mie(); + } + // must enable external interrupts on the CPU for any of the above to matter + unsafe { mie::set_mext() }; +} + +pub fn enable_irq(irq_no: usize) { + let mut legacy_int = CSR::new(HW_LEGACY_INT_BASE as *mut u32); + // Note that the vexriscv "IRQ Mask" register is inverse-logic -- + // that is, setting a bit in the "mask" register unmasks (i.e. enables) it. + legacy_int.wo(utra::legacy_int::MACH_MASK, legacy_int.r(utra::legacy_int::MACH_MASK) | (1 << irq_no)); + // must enable external interrupts on the CPU for any of the above to matter + unsafe { mie::set_mext() }; +} + +#[export_name = "_start_trap"] +// #[repr(align(4))] // can't do this yet. +#[inline(never)] +pub unsafe extern "C" fn _start_trap() -> ! { + loop { + // install a NOP sled before _start_trap() until https://github.com/rust-lang/rust/issues/82232 is stable + core::arch::asm!("nop", "nop", "nop", "nop"); + #[export_name = "_start_trap_aligned"] + pub unsafe extern "C" fn _start_trap_aligned() { + #[rustfmt::skip] + core::arch::asm!( + "csrw mscratch, sp", + "li sp, 0x4001E000", // crate::platform::SCRATCH_PAGE - has to be hard-coded + "sw x1, 0*4(sp)", + // Skip SP for now + "sw x3, 2*4(sp)", + "sw x4, 3*4(sp)", + "sw x5, 4*4(sp)", + "sw x6, 5*4(sp)", + "sw x7, 6*4(sp)", + "sw x8, 7*4(sp)", + "sw x9, 8*4(sp)", + "sw x10, 9*4(sp)", + "sw x11, 10*4(sp)", + "sw x12, 11*4(sp)", + "sw x13, 12*4(sp)", + "sw x14, 13*4(sp)", + "sw x15, 14*4(sp)", + "sw x16, 15*4(sp)", + "sw x17, 16*4(sp)", + "sw x18, 17*4(sp)", + "sw x19, 18*4(sp)", + "sw x20, 19*4(sp)", + "sw x21, 20*4(sp)", + "sw x22, 21*4(sp)", + "sw x23, 22*4(sp)", + "sw x24, 23*4(sp)", + "sw x25, 24*4(sp)", + "sw x26, 25*4(sp)", + "sw x27, 26*4(sp)", + "sw x28, 27*4(sp)", + "sw x29, 28*4(sp)", + "sw x30, 29*4(sp)", + "sw x31, 30*4(sp)", + + // Save MEPC + "csrr t0, mepc", + "sw t0, 31*4(sp)", + // Save x1, which was used to calculate the offset. Prior to + // calculating, it was stashed at 0x61006000. + //"li t0, 0x61006000", + //"lw t1, 0*4(t0)", + //"sw t1, 0*4(sp)", + + // Finally, save SP + "csrr t0, mscratch", + "sw t0, 1*4(sp)", + // Restore a default stack pointer + "li sp, 0x40020000", // last page of RAM, grows down + + // Note that registers $a0-$a7 still contain the arguments + "j _start_trap_rust", + // Note to self: trying to assign the scratch and default pages using in(reg) syntax + // clobbers the `a0` register and places the initialization outside of the handler loop + // and there seems to be no way to refer directly to a symbol? the `sym` directive wants + // to refer to an address, not a constant. + ); + } + _start_trap_aligned(); + core::arch::asm!("nop", "nop", "nop", "nop"); + } +} + +#[export_name = "_resume_context"] +#[inline(never)] +pub unsafe extern "C" fn _resume_context(registers: u32) -> ! { + #[rustfmt::skip] + core::arch::asm!( + "move sp, {registers}", + + "lw x1, 0*4(sp)", + // Skip SP for now + "lw x3, 2*4(sp)", + "lw x4, 3*4(sp)", + "lw x5, 4*4(sp)", + "lw x6, 5*4(sp)", + "lw x7, 6*4(sp)", + "lw x8, 7*4(sp)", + "lw x9, 8*4(sp)", + "lw x10, 9*4(sp)", + "lw x11, 10*4(sp)", + "lw x12, 11*4(sp)", + "lw x13, 12*4(sp)", + "lw x14, 13*4(sp)", + "lw x15, 14*4(sp)", + "lw x16, 15*4(sp)", + "lw x17, 16*4(sp)", + "lw x18, 17*4(sp)", + "lw x19, 18*4(sp)", + "lw x20, 19*4(sp)", + "lw x21, 20*4(sp)", + "lw x22, 21*4(sp)", + "lw x23, 22*4(sp)", + "lw x24, 23*4(sp)", + "lw x25, 24*4(sp)", + "lw x26, 25*4(sp)", + "lw x27, 26*4(sp)", + "lw x28, 27*4(sp)", + "lw x29, 28*4(sp)", + "lw x30, 29*4(sp)", + "lw x31, 30*4(sp)", + + // Restore SP + "lw x2, 1*4(sp)", + "mret", + registers = in(reg) registers, + ); + loop {} +} + +/// Just handles specific traps for testing CPU interactions. Doesn't do anything useful with the traps. +#[export_name = "_start_trap_rust"] +pub extern "C" fn trap_handler( + _a0: usize, + _a1: usize, + _a2: usize, + _a3: usize, + _a4: usize, + _a5: usize, + _a6: usize, + _a7: usize, +) -> ! { + let cause: mcause::Mcause = mcause::read(); + // crate::println!("cause {:x}", cause.bits()); + // 2 is illegal instruction + if cause.bits() == 2 { + // skip past the illegal instruction, in case that's what we want to do... + unsafe { + #[rustfmt::skip] + core::arch::asm!( + "csrr t0, mepc", + "addi t0, t0, 4", + "csrw mepc, t0", + ); + } + // ...but also panic. + panic!("Illegal Instruction"); + } else if cause.bits() == 4 { + let epc = riscv::register::mepc::read(); + panic!("Load address misaligned @ {:x}", epc); + } else if cause.bits() == 6 { + let epc = riscv::register::mepc::read(); + panic!("Store address misaligned @ {:x}", epc); + } else if cause.bits() == 0x8000_000b { + // external machine interrupt + // external interrupt. find out which ones triggered it, and clear the source. + let legacy_int = CSR::new(HW_LEGACY_INT_BASE as *mut u32); + let irqs_pending = legacy_int.r(utra::legacy_int::MACH_PENDING); + if (irqs_pending & (1 << utra::timer0::TIMER0_IRQ)) != 0 { + let ms = SYSTEM_TICK_INTERVAL_MS; + let mut timer0 = CSR::new(utra::timer0::HW_TIMER0_BASE as *mut u32); + timer0.wfo(utra::timer0::EV_PENDING_ZERO, 1); + timer0.wfo(utra::timer0::RELOAD_RELOAD, (SYSTEM_CLOCK_FREQUENCY / 1_000) * ms); + } else if (irqs_pending & (1 << utra::uart::UART_IRQ)) != 0 { + crate::uart_irq_handler(); + } + } + + // re-enable interrupts + unsafe { mie::set_mext() }; + + // crate::println!("restoring from {:x}", crate::platform::SCRATCH_PAGE); + unsafe { _resume_context(crate::platform::SCRATCH_PAGE as u32) }; +} diff --git a/baremetal/src/platform/artyvexii/link.x b/baremetal/src/platform/artyvexii/link.x new file mode 100644 index 000000000..abbe8008e --- /dev/null +++ b/baremetal/src/platform/artyvexii/link.x @@ -0,0 +1,179 @@ +MEMORY +{ + FLASH : ORIGIN = 0x80000000, LENGTH = 64k + RAM : ORIGIN = 0x40000000, LENGTH = 128k +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_RODATA", FLASH); +REGION_ALIAS("REGION_DATA", RAM); +REGION_ALIAS("REGION_BSS", RAM); +REGION_ALIAS("REGION_STACK", RAM); +REGION_ALIAS("REGION_HEAP", RAM); + +/* Size of the main kernel stack */ +_stack_size = 16K; +_eheap = ORIGIN(RAM) + LENGTH(RAM); + + +PROVIDE(_stext = ORIGIN(REGION_TEXT)); +PROVIDE(_stack_start = ORIGIN(REGION_STACK) + LENGTH(REGION_STACK)); +PROVIDE(_max_hart_id = 0); +PROVIDE(_hart_stack_size = 2K); +PROVIDE(_heap_size = 0); + +PROVIDE(trap_handler = default_trap_handler); + +/* # Pre-initialization function */ +/* If the user overrides this using the `#[pre_init]` attribute or by creating a `__pre_init` function, + then the function this points to will be called before the RAM is initialized. */ +PROVIDE(__pre_init = default_pre_init); + +/* # Multi-processing hook function + fn _mp_hook() -> bool; + + This function is called from all the harts and must return true only for one hart, + which will perform memory initialization. For other harts it must return false + and implement wake-up in platform-dependent way (e.g. after waiting for a user interrupt). +*/ +PROVIDE(_mp_hook = default_mp_hook); + +ENTRY(_start) + +SECTIONS +{ + .text.dummy (NOLOAD) : + { + /* This section is intended to make _stext address work */ + . = ABSOLUTE(_stext); + } > REGION_TEXT + + .text _stext : + { + /* Put reset handler first in .text section so it ends up as the entry */ + /* point of the program. */ + KEEP(*(.text.init)); + KEEP(*(.init)); + KEEP(*(.init.rust)); + . = ALIGN(4); + KEEP(*(.trap)); + KEEP(*(.trap.rust)); + + *(.text .text.*); + } > REGION_TEXT + + .rodata : ALIGN(4) + { + *(.rodata .rodata.*); + + /* 4-byte align the end (VMA) of this section. + This is required by LLD to ensure the LMA of the following .data + section will have the correct alignment. */ + . = ALIGN(4); + _etext = .; + } > REGION_RODATA + + .data : ALIGN(4) + { + _sidata = LOADADDR(.data); + _sdata = .; + /* Must be called __global_pointer$ for linker relaxations to work. */ + PROVIDE(__global_pointer$ = . + 0x800); + *(.sdata .sdata.* .sdata2 .sdata2.*); + *(.data .data.*); + . = ALIGN(4); + _edata = .; + } > REGION_DATA AT > REGION_RODATA + + .bss (NOLOAD) : + { + _sbss = .; + *(.sbss .sbss.* .bss .bss.*); + . = ALIGN(4); + _ebss = .; + } > REGION_BSS + + /* fictitious region that represents the memory available for the stack */ + .stack (NOLOAD) : + { + _sstack = .; + . += _stack_size; + . = ALIGN(4096); + _estack = .; + } > REGION_STACK + + /* fictitious region that represents the memory available for the heap */ + .heap (NOLOAD) : + { + . = ALIGN(4); + _sheap = .; + /* _eheap is defined elsewhere and is the remainder of RAM */ + } > REGION_HEAP + + /* fake output .got section */ + /* Dynamic relocations are unsupported. This section is only used to detect + relocatable code in the input files and raise an error if relocatable code + is found */ + .got (INFO) : + { + KEEP(*(.got .got.*)); + } + + /* Discard .eh_frame, we are not doing unwind on panic so it is not needed */ + /DISCARD/ : + { + *(.eh_frame); + *(.eh_frame_hdr); + } +} + +/* Do not exceed this mark in the error messages above | */ +ASSERT(ORIGIN(REGION_TEXT) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_RODATA) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_RODATA must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_DATA) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_DATA must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_HEAP) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_HEAP must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_TEXT) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_STACK) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_STACK must be 4-byte aligned"); + +ASSERT(_stext % 4 == 0, " +ERROR(riscv-rt): `_stext` must be 4-byte aligned"); + +ASSERT(_sdata % 4 == 0 && _edata % 4 == 0, " +BUG(riscv-rt): .data is not 4-byte aligned"); + +ASSERT(_sidata % 4 == 0, " +BUG(riscv-rt): the LMA of .data is not 4-byte aligned"); + +ASSERT(_sbss % 4 == 0 && _ebss % 4 == 0, " +BUG(riscv-rt): .bss is not 4-byte aligned"); + +ASSERT(_sheap % 4 == 0, " +BUG(riscv-rt): start of .heap is not 4-byte aligned"); + +ASSERT(_stext + SIZEOF(.text) < ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT), " +ERROR(riscv-rt): The .text section must be placed inside the REGION_TEXT region. +Set _stext to an address smaller than 'ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT)'"); + +ASSERT(SIZEOF(.stack) > (_max_hart_id + 1) * _hart_stack_size, " +ERROR(riscv-rt): .stack section is too small for allocating stacks for all the harts. +Consider changing `_max_hart_id` or `_hart_stack_size`."); + +ASSERT(SIZEOF(.got) == 0, " +.got section detected in the input files. Dynamic relocations are not +supported. If you are linking to C code compiled using the `gcc` crate +then modify your build script to compile the C code _without_ the +-fPIC flag. See the documentation of the `gcc::Config.fpic` method for +details."); + +/* Do not exceed this mark in the error messages above | */ diff --git a/baremetal/src/repl.rs b/baremetal/src/repl.rs index 4b670b38d..f990b0f66 100644 --- a/baremetal/src/repl.rs +++ b/baremetal/src/repl.rs @@ -2,6 +2,7 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; use utralib::*; +#[cfg(feature = "artybio")] use xous_bio_bdma::*; pub struct Repl { @@ -48,6 +49,7 @@ impl Repl { let args: Vec = parts.map(|s| s.to_string()).collect(); match cmd.as_str() { "mon" => { + #[cfg(feature = "artybio")] let bio_ss = BioSharedState::new(); let mut rgb = CSR::new(utra::rgb::HW_RGB_BASE as *mut u32); let mut count = 0; @@ -58,6 +60,7 @@ impl Repl { // Hacky logic to create a 500ms interval on prints, but improve // keyboard hit latency. if count % TICKS_PER_PRINT == 0 { + #[cfg(feature = "artybio")] crate::println!( "pc: {:04x} {:04x} {:04x} {:04x}", bio_ss.bio.r(utra::bio_bdma::SFR_DBG0),