2019-12-18 01:59:00 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
2020-01-09 02:45:22 +00:00
|
|
|
extern crate vexriscv;
|
2020-01-20 06:43:11 +00:00
|
|
|
|
|
|
|
mod debug;
|
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-24 01:33:02 +00:00
|
|
|
use mem::MemoryManager;
|
2019-12-25 12:11:15 +00:00
|
|
|
use processtable::ProcessTable;
|
2020-01-20 06:43:11 +00:00
|
|
|
use vexriscv::register::{mcause, mie, mstatus, vmim, vmip};
|
|
|
|
use xous_kernel_riscv_rt::xous_kernel_entry;
|
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
|
|
|
#[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
|
|
|
|
}
|
2020-01-09 02:45:22 +00:00
|
|
|
|
2020-01-20 06:43:11 +00:00
|
|
|
let uart = debug::DEFAULT_UART;
|
|
|
|
|
|
|
|
// Enable "RX_EMPTY" interrupt
|
|
|
|
uart.enable_rx();
|
2019-12-19 04:17:07 +00:00
|
|
|
|
2020-01-20 06:43:11 +00:00
|
|
|
println!("Starting up...");
|
|
|
|
sys_interrupt_claim(2, debug::irq).unwrap();
|
|
|
|
|
|
|
|
let mut mm = MemoryManager::new();
|
|
|
|
let mut _pt = ProcessTable::new(&mut mm);
|
2019-12-19 04:17:07 +00:00
|
|
|
|
|
|
|
|
2019-12-18 01:59:00 +00:00
|
|
|
loop {
|
2020-01-20 06:43:11 +00:00
|
|
|
// unsafe { vexriscv::asm::wfi() };
|
2019-12-18 01:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-19 04:17:07 +00:00
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn trap_handler() {
|
|
|
|
let mc = mcause::read();
|
|
|
|
let irqs_pending = vmip::read();
|
|
|
|
|
2020-01-20 06:43:11 +00:00
|
|
|
if mc.is_exception() {
|
|
|
|
unsafe { vexriscv::asm::ebreak() };
|
|
|
|
loop {}
|
|
|
|
}
|
2019-12-19 04:17:07 +00:00
|
|
|
|
|
|
|
if irqs_pending != 0 {
|
|
|
|
irq::handle(irqs_pending);
|
|
|
|
}
|
|
|
|
}
|