2019-12-18 01:59:00 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
extern crate xous_riscv;
|
2019-12-25 12:11:15 +00:00
|
|
|
mod definitions;
|
2019-12-19 04:17:07 +00:00
|
|
|
mod irq;
|
2019-12-24 01:33:02 +00:00
|
|
|
mod macros;
|
|
|
|
mod mem;
|
2019-12-25 12:11:15 +00:00
|
|
|
mod processtable;
|
|
|
|
mod syscalls;
|
2019-12-19 04:17:07 +00:00
|
|
|
|
|
|
|
pub use irq::sys_interrupt_claim;
|
2019-12-18 01:59:00 +00:00
|
|
|
|
|
|
|
use core::panic::PanicInfo;
|
2019-12-19 04:17:07 +00:00
|
|
|
use xous_kernel_riscv_rt::xous_kernel_entry;
|
|
|
|
use xous_riscv::register::{mcause, mstatus, mie, vmim, vmip};
|
2019-12-24 01:33:02 +00:00
|
|
|
use mem::MemoryManager;
|
2019-12-25 12:11:15 +00:00
|
|
|
use processtable::ProcessTable;
|
2019-12-19 04:17:07 +00:00
|
|
|
|
2019-12-18 01:59:00 +00:00
|
|
|
#[panic_handler]
|
2019-12-19 04:17:07 +00:00
|
|
|
fn handle_panic(_arg: &PanicInfo) -> ! {
|
2019-12-18 01:59:00 +00:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
|
2019-12-19 04:17:07 +00:00
|
|
|
fn print_str(uart: *mut usize, s: &str) {
|
|
|
|
for c in s.bytes() {
|
|
|
|
unsafe { uart.write_volatile(c as usize) };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[xous_kernel_entry]
|
2019-12-18 01:59:00 +00:00
|
|
|
fn xous_main() -> ! {
|
2019-12-19 04:17:07 +00:00
|
|
|
unsafe {
|
|
|
|
vmim::write(0); // Disable all machine interrupts
|
|
|
|
mie::set_msoft();
|
|
|
|
mie::set_mtimer();
|
|
|
|
mie::set_mext();
|
|
|
|
mstatus::set_mie(); // Enable CPU interrupts
|
|
|
|
}
|
2019-12-25 12:11:15 +00:00
|
|
|
let mut mm = MemoryManager::new();
|
|
|
|
let mut pt = ProcessTable::new(&mut mm);
|
2019-12-19 04:17:07 +00:00
|
|
|
sys_interrupt_claim(2, |_| {
|
|
|
|
let uart_ptr = 0xE000_1800 as *mut usize;
|
|
|
|
print_str(uart_ptr, "hello, world!\r\n");
|
|
|
|
// Acknowledge the IRQ
|
|
|
|
unsafe {
|
|
|
|
uart_ptr.add(0).read_volatile();
|
|
|
|
|
|
|
|
// Acknowledge the event
|
|
|
|
uart_ptr.add(4).write_volatile(3);
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Enable interrupts
|
|
|
|
let uart_ptr = 0xE000_1800 as *mut usize;
|
|
|
|
unsafe { uart_ptr.add(4).write_volatile(3) };
|
|
|
|
unsafe { uart_ptr.add(5).write_volatile(3) };
|
|
|
|
print_str(uart_ptr, "greetings!\r\n");
|
|
|
|
|
2019-12-18 01:59:00 +00:00
|
|
|
loop {
|
|
|
|
unsafe { xous_riscv::asm::wfi() };
|
|
|
|
}
|
|
|
|
}
|
2019-12-19 04:17:07 +00:00
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn trap_handler() {
|
|
|
|
let mc = mcause::read();
|
|
|
|
let irqs_pending = vmip::read();
|
|
|
|
|
|
|
|
if mc.is_exception() {}
|
|
|
|
|
|
|
|
if irqs_pending != 0 {
|
|
|
|
irq::handle(irqs_pending);
|
|
|
|
}
|
|
|
|
}
|