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
|
|
|
|
2020-01-21 09:04:09 +00:00
|
|
|
#[macro_use]
|
2020-01-20 06:43:11 +00:00
|
|
|
mod debug;
|
2020-01-21 09:04:09 +00:00
|
|
|
|
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;
|
2020-01-21 10:14:13 +00:00
|
|
|
mod timer;
|
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-21 12:05:39 +00:00
|
|
|
use vexriscv::register::{mcause, mepc, mie, mstatus, vmim, vmip};
|
2020-01-20 06:43:11 +00:00
|
|
|
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]
|
2020-01-21 09:04:09 +00:00
|
|
|
fn handle_panic(arg: &PanicInfo) -> ! {
|
|
|
|
println!("PANIC!");
|
|
|
|
println!("Details: {:?}", arg);
|
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;
|
2020-01-21 10:14:13 +00:00
|
|
|
sys_interrupt_claim(0, timer::irq).unwrap();
|
|
|
|
timer::time_init();
|
2020-01-20 06:43:11 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2020-01-21 09:04:09 +00:00
|
|
|
println!("Creating memory manager...");
|
2020-01-21 12:05:39 +00:00
|
|
|
let mm = MemoryManager::new();
|
2019-12-19 04:17:07 +00:00
|
|
|
|
2020-01-21 09:04:09 +00:00
|
|
|
println!("Creating process table...");
|
2020-01-21 10:14:13 +00:00
|
|
|
ProcessTable::new(mm, kmain);
|
|
|
|
}
|
2019-12-19 04:17:07 +00:00
|
|
|
|
2020-01-21 10:14:13 +00:00
|
|
|
fn kmain(mm: MemoryManager, pt: ProcessTable) -> ! {
|
2020-01-21 09:04:09 +00:00
|
|
|
println!("Entering main loop");
|
2020-01-21 10:14:13 +00:00
|
|
|
let mut last_time = timer::get_time();
|
2019-12-18 01:59:00 +00:00
|
|
|
loop {
|
2020-01-21 10:14:13 +00:00
|
|
|
let new_time = timer::get_time();
|
|
|
|
if new_time >= last_time + 1000 {
|
|
|
|
last_time = new_time;
|
|
|
|
println!("Uptime: {} ms", new_time);
|
|
|
|
}
|
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() {
|
2020-01-21 12:05:39 +00:00
|
|
|
println!("CPU Exception");
|
|
|
|
println!("{:?} @ PC: {:08x}", mc.cause(), mepc::read());
|
2020-01-20 06:43:11 +00:00
|
|
|
unsafe { vexriscv::asm::ebreak() };
|
|
|
|
loop {}
|
|
|
|
}
|
2019-12-19 04:17:07 +00:00
|
|
|
|
|
|
|
if irqs_pending != 0 {
|
|
|
|
irq::handle(irqs_pending);
|
|
|
|
}
|
|
|
|
}
|