examples: fix shell running on hardware

Previously, the `baremetal.rs` library was removed. This resulted in
this program no longer running on hardware.

Add this library back in.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-08-18 17:00:48 +08:00
parent 965696df8b
commit 179623e083
3 changed files with 43 additions and 86 deletions

View file

@ -1,69 +0,0 @@
use core::panic::PanicInfo;
#[panic_handler]
fn handle_panic(arg: &PanicInfo) -> ! {
println!("PANIC!");
println!("Details: {:?}", arg);
xous::syscall::wait_event();
loop {}
}
fn handle_irq(irq_no: usize, arg: *mut usize) {
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
while let Some(c) = crate::debug::DEFAULT.getc() {
print!("0x{:02x}", c);
}
println!();
}
/// Rust entry point (_start_rust)
///
/// Zeros bss section, initializes data section and calls main. This function
/// never returns.
#[link_section = ".init.rust"]
#[export_name = "_start"]
pub unsafe extern "C" fn start_rust() -> ! {
extern "Rust" {
// This symbol will be provided by the kernel
fn main();
}
let uart = xous::syscall::map_memory(
xous::MemoryAddress::new(0xf000_1000),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't map uart");
crate::debug::DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
println!("Mapped UART @ {:08x}", uart.addr.get());
xous::syscall::map_memory(
xous::MemoryAddress::new(0xf000_2000),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.map(|_| println!("!!!WARNING: managed to steal kernel's memory"))
.ok();
println!("Process: map success!");
crate::debug::DEFAULT.enable_rx();
println!("Allocating IRQ...");
xous::claim_interrupt(2, handle_irq, core::ptr::null_mut::<usize>())
// xous::rsyscall(xous::SysCall::ClaimInterrupt(
// 2,
// handle_irq as *mut usize,
// core::ptr::null_mut::<usize>(),
// ))
.expect("couldn't claim interrupt");
main();
panic!("exited main");
}
#[export_name = "abort"]
pub extern "C" fn abort() -> ! {
panic!("aborted");
}

View file

@ -22,6 +22,16 @@ macro_rules! println
});
}
fn handle_irq(irq_no: usize, arg: *mut usize) {
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
while let Some(c) = crate::debug::DEFAULT.getc() {
print!("0x{:02x}", c);
}
println!();
}
pub struct Uart {}
pub static mut DEFAULT_UART_ADDR: *mut usize = 0x0000_0000 as *mut usize;
@ -31,14 +41,31 @@ pub const DEFAULT: Uart = Uart {};
impl Uart {
pub fn putc(&self, c: u8) {
unsafe {
if DEFAULT_UART_ADDR as usize == 0 {
let uart = xous::syscall::map_memory(
xous::MemoryAddress::new(0xf000_1000),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't map uart");
DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
println!("Mapped UART @ {:08x}", uart.addr.get());
// core::mem::forget(uart);
println!("Allocating IRQ...");
xous::claim_interrupt(2, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
self.enable_rx();
}
let base = DEFAULT_UART_ADDR;
// Wait until TXFULL is `0`
while base.add(1).read_volatile() != 0 {}
base.add(0).write_volatile(c as usize)
};
}
pub fn enable_rx(self) {
pub fn enable_rx(&self) {
unsafe {
let base = DEFAULT_UART_ADDR;
base.add(5).write_volatile(base.add(5).read_volatile() | 2)

View file

@ -5,9 +5,6 @@
#[macro_use]
mod debug;
#[cfg(baremetal)]
mod baremetal;
mod timer;
// mod logstr;
@ -19,11 +16,8 @@ mod timer;
// }
// }
#[cfg_attr(baremetal, no_mangle)]
fn main() {
println!("Starting to initialize the timer");
#[cfg(not(baremetal))]
xous::arch::ensure_connection().unwrap();
#[xous::xous_main]
fn shell_main() -> ! {
timer::init();
let mut connection = None;
@ -45,7 +39,7 @@ fn main() {
// let ls = logstr::LogStr::new();
loop {
println!("Sending a scalar message with id {}...", counter + 4096);
xous::syscall::send_message(
match xous::syscall::send_message(
connection,
xous::Message::Scalar(xous::ScalarMessage {
id: counter + 4096,
@ -54,15 +48,20 @@ fn main() {
arg3: !counter,
arg4: counter + 1,
}),
)
.expect("couldn't send scalar message");
if counter.trailing_zeros() >= 12 {
println!("Loop {}", counter);
) {
Err(xous::Error::ServerQueueFull) => {
println!("Server queue is full... retrying");
continue;
},
Ok(_) => {
println!("Loop {}", counter);
counter += 1;
},
Err(e) => panic!("Unable to send message: {:?}", e),
}
counter += 1;
#[cfg(not(baremetal))]
std::thread::sleep(std::time::Duration::from_millis(500));
// #[cfg(not(target_os = "none"))]
// std::thread::sleep(std::time::Duration::from_millis(500));
// if counter & 2 == 0 {
// xous::syscall::yield_slice();
// }