fix compile on riscv & aarch64

toolchain_update
WangRunji 6 years ago
parent 09588d7a1f
commit 40ac510ecd

@ -21,8 +21,9 @@ pub fn console_getchar() -> usize {
sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0) sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
} }
pub fn shutdown() { pub fn shutdown() -> ! {
sbi_call(SBI_SHUTDOWN, 0, 0, 0); sbi_call(SBI_SHUTDOWN, 0, 0, 0);
unreachable!()
} }
pub fn set_timer(stime_value: u64) { pub fn set_timer(stime_value: u64) {

4
kernel/Cargo.lock generated

@ -282,12 +282,12 @@ dependencies = [
[[package]] [[package]]
name = "rcore-fs" name = "rcore-fs"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/wangrunji0408/rcore-fs?branch=sefs#af02ecfb3fb0da641ebe07c37af094c42dd60c2e" source = "git+https://github.com/wangrunji0408/rcore-fs?branch=sefs#0eba40886d36311b28d42ff2a27a0f4292e2ad9f"
[[package]] [[package]]
name = "rcore-fs-sfs" name = "rcore-fs-sfs"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/wangrunji0408/rcore-fs?branch=sefs#af02ecfb3fb0da641ebe07c37af094c42dd60c2e" source = "git+https://github.com/wangrunji0408/rcore-fs?branch=sefs#0eba40886d36311b28d42ff2a27a0f4292e2ad9f"
dependencies = [ dependencies = [
"bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",

@ -6,3 +6,7 @@ pub fn id() -> usize {
// TODO: cpu id // TODO: cpu id
0 0
} }
pub fn exit_in_qemu(error_code: u8) -> ! {
unimplemented!()
}

@ -166,6 +166,18 @@ impl Context {
}, },
}.push_at(kstack_top, ttbr) }.push_at(kstack_top, ttbr)
} }
pub unsafe fn new_clone(tf: &TrapFrame, ustack_top: usize, kstack_top: usize, ttbr: usize, tls: usize) -> Self {
InitStack {
context: ContextData::new(),
tf: {
let mut tf = tf.clone();
tf.sp = ustack_top;
tf.tpidr = tls;
tf.x0 = 0;
tf
},
}.push_at(kstack_top, ttbr)
}
/// Called at a new user context /// Called at a new user context
/// To get the init TrapFrame in sys_exec /// To get the init TrapFrame in sys_exec
pub unsafe fn get_init_tf(&self) -> TrapFrame { pub unsafe fn get_init_tf(&self) -> TrapFrame {

@ -7,6 +7,7 @@ pub mod interrupt;
pub mod consts; pub mod consts;
pub mod cpu; pub mod cpu;
pub mod driver; pub mod driver;
pub mod timer;
#[cfg(feature = "board_raspi3")] #[cfg(feature = "board_raspi3")]
#[path = "board/raspi3/mod.rs"] #[path = "board/raspi3/mod.rs"]

@ -50,13 +50,13 @@ impl PageTable for ActivePageTable {
fn map(&mut self, addr: usize, target: usize) -> &mut Entry { fn map(&mut self, addr: usize, target: usize) -> &mut Entry {
let flags = EF::default(); let flags = EF::default();
let attr = MairNormal::attr_value(); let attr = MairNormal::attr_value();
self.0.map_to(Page::of_addr(addr), Frame::of_addr(target), flags, attr, &mut FrameAllocatorForAarch64) self.0.map_to(Page::of_addr(addr as u64), Frame::of_addr(target as u64), flags, attr, &mut FrameAllocatorForAarch64)
.unwrap().flush(); .unwrap().flush();
self.get_entry(addr).expect("fail to get entry") self.get_entry(addr).expect("fail to get entry")
} }
fn unmap(&mut self, addr: usize) { fn unmap(&mut self, addr: usize) {
let (_frame, flush) = self.0.unmap(Page::of_addr(addr)).unwrap(); let (_frame, flush) = self.0.unmap(Page::of_addr(addr as u64)).unwrap();
flush.flush(); flush.flush();
} }
@ -191,7 +191,7 @@ impl InactivePageTable for InactivePageTable0 {
fn new_bare() -> Self { fn new_bare() -> Self {
let target = alloc_frame().expect("failed to allocate frame"); let target = alloc_frame().expect("failed to allocate frame");
let frame = Frame::of_addr(target); let frame = Frame::of_addr(target as u64);
active_table().with_temporary_map(target, |_, table: &mut Aarch64PageTable| { active_table().with_temporary_map(target, |_, table: &mut Aarch64PageTable| {
table.zero(); table.zero();
// set up recursive mapping for the table // set up recursive mapping for the table
@ -274,7 +274,7 @@ struct FrameAllocatorForAarch64;
impl FrameAllocator<Size4KiB> for FrameAllocatorForAarch64 { impl FrameAllocator<Size4KiB> for FrameAllocatorForAarch64 {
fn alloc(&mut self) -> Option<Frame> { fn alloc(&mut self) -> Option<Frame> {
alloc_frame().map(|addr| Frame::of_addr(addr)) alloc_frame().map(|addr| Frame::of_addr(addr as u64))
} }
} }

@ -0,0 +1,3 @@
pub fn read_epoch() -> u64 {
0
}

@ -284,6 +284,20 @@ impl Context {
}, },
}.push_at(kstack_top) }.push_at(kstack_top)
} }
pub unsafe fn new_clone(tf: &TrapFrame, ustack_top: usize, kstack_top: usize, cr3: usize, tls: usize) -> Self {
InitStack {
context: ContextData::new(cr3),
tf: {
let mut tf = tf.clone();
tf.x[2] = ustack_top; // sp
tf.x[4] = tls; // tp
tf.x[10] = 0; // a0
tf
},
}.push_at(kstack_top)
}
/// Called at a new user context /// Called at a new user context
/// To get the init TrapFrame in sys_exec /// To get the init TrapFrame in sys_exec
pub unsafe fn get_init_tf(&self) -> TrapFrame { pub unsafe fn get_init_tf(&self) -> TrapFrame {

@ -35,3 +35,7 @@ pub unsafe fn start_others(hart_mask: usize) {
pub fn halt() { pub fn halt() {
unsafe { riscv::asm::wfi() } unsafe { riscv::asm::wfi() }
} }
pub fn exit_in_qemu(error_code: u8) -> ! {
bbl::sbi::shutdown()
}

@ -138,8 +138,7 @@ fn try_process_serial() -> bool {
} }
fn try_process_drivers() -> bool { fn try_process_drivers() -> bool {
let mut drivers = DRIVERS.lock(); for driver in DRIVERS.read().iter() {
for driver in drivers.iter_mut() {
if driver.try_handle_interrupt() == true { if driver.try_handle_interrupt() == true {
return true return true
} }

@ -27,6 +27,11 @@ pub fn get_cycle() -> u64 {
} }
} }
pub fn read_epoch() -> u64 {
// TODO: support RTC
0
}
/* /*
* @brief: * @brief:
* enable supervisor timer interrupt and set next timer interrupt * enable supervisor timer interrupt and set next timer interrupt

@ -95,5 +95,3 @@ pub const USER_TMP_TLS_PML4: usize = (USER_TMP_TLS_OFFSET & PML4_MASK) / PML4_SI
/// Offset for usage in other temporary pages /// Offset for usage in other temporary pages
pub const USER_TMP_MISC_OFFSET: usize = USER_TMP_TLS_OFFSET + PML4_SIZE; pub const USER_TMP_MISC_OFFSET: usize = USER_TMP_TLS_OFFSET + PML4_SIZE;
pub const USER_TMP_MISC_PML4: usize = (USER_TMP_MISC_OFFSET & PML4_MASK) / PML4_SIZE; pub const USER_TMP_MISC_PML4: usize = (USER_TMP_MISC_OFFSET & PML4_MASK) / PML4_SIZE;
pub const USEC_PER_TICK: usize = 10000;

@ -11,6 +11,7 @@ pub mod idt;
pub mod memory; pub mod memory;
pub mod io; pub mod io;
pub mod consts; pub mod consts;
pub mod timer;
static AP_CAN_INIT: AtomicBool = ATOMIC_BOOL_INIT; static AP_CAN_INIT: AtomicBool = ATOMIC_BOOL_INIT;

@ -0,0 +1,3 @@
pub fn read_epoch() -> u64 {
super::driver::rtc_cmos::read_epoch()
}

@ -4,3 +4,5 @@ pub use crate::arch::consts::*;
pub const MAX_CPU_NUM: usize = 8; pub const MAX_CPU_NUM: usize = 8;
pub const MAX_PROCESS_NUM: usize = 128; pub const MAX_PROCESS_NUM: usize = 128;
pub const USEC_PER_TICK: usize = 10000;

@ -17,7 +17,7 @@ use rcore_fs::dev::BlockDevice;
use crate::memory::active_table; use crate::memory::active_table;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;
use super::super::{DeviceType, Driver, DRIVERS}; use super::super::{DeviceType, Driver, DRIVERS, BLK_DRIVERS};
use super::super::bus::virtio_mmio::*; use super::super::bus::virtio_mmio::*;
pub struct VirtIOBlk { pub struct VirtIOBlk {
@ -176,5 +176,7 @@ pub fn virtio_blk_init(node: &Node) {
header.status.write(VirtIODeviceStatus::DRIVER_OK.bits()); header.status.write(VirtIODeviceStatus::DRIVER_OK.bits());
DRIVERS.write().push(Arc::new(driver)); let driver = Arc::new(driver);
DRIVERS.write().push(driver.clone());
BLK_DRIVERS.write().push(driver);
} }

@ -7,6 +7,7 @@ use smoltcp::socket::SocketSet;
use spin::RwLock; use spin::RwLock;
use crate::sync::{Condvar, MutexGuard, SpinNoIrq}; use crate::sync::{Condvar, MutexGuard, SpinNoIrq};
use self::block::virtio_blk::VirtIOBlkDriver;
mod device_tree; mod device_tree;
pub mod bus; pub mod bus;
@ -15,6 +16,7 @@ pub mod block;
mod gpu; mod gpu;
mod input; mod input;
#[derive(Debug, Eq, PartialEq)]
pub enum DeviceType { pub enum DeviceType {
Net, Net,
Gpu, Gpu,
@ -52,11 +54,8 @@ pub trait NetDriver : Driver {
lazy_static! { lazy_static! {
// NOTE: RwLock only write when initializing drivers // NOTE: RwLock only write when initializing drivers
pub static ref DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new()); pub static ref DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new());
}
lazy_static! {
// NOTE: RwLock only write when initializing drivers
pub static ref NET_DRIVERS: RwLock<Vec<Arc<NetDriver>>> = RwLock::new(Vec::new()); pub static ref NET_DRIVERS: RwLock<Vec<Arc<NetDriver>>> = RwLock::new(Vec::new());
pub static ref BLK_DRIVERS: RwLock<Vec<Arc<VirtIOBlkDriver>>> = RwLock::new(Vec::new());
} }
lazy_static!{ lazy_static!{

@ -1,6 +1,4 @@
use alloc::{boxed::Box, collections::VecDeque, string::String, sync::Arc, vec::Vec}; use alloc::{boxed::Box, collections::VecDeque, string::String, sync::Arc, vec::Vec};
use core::any::Any;
use core::ops::Deref;
use rcore_fs::vfs::*; use rcore_fs::vfs::*;
use rcore_fs_sfs::SimpleFileSystem; use rcore_fs_sfs::SimpleFileSystem;
@ -25,15 +23,13 @@ lazy_static! {
let device = { let device = {
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
{ {
Box::new(crate::drivers::DRIVERS.lock().iter() crate::drivers::BLK_DRIVERS.read().iter()
.map(|device| device.deref().as_any().downcast_ref::<VirtIOBlkDriver>()) .next().expect("VirtIOBlk not found")
.find(|maybe_blk| maybe_blk.is_some()) .clone()
.expect("VirtIOBlk not found")
.unwrap().clone())
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
{ {
Box::new(ide::IDE::new(1)) Arc::new(ide::IDE::new(1))
} }
}; };
#[cfg(feature = "link_user")] #[cfg(feature = "link_user")]
@ -42,7 +38,7 @@ lazy_static! {
fn _user_img_start(); fn _user_img_start();
fn _user_img_end(); fn _user_img_end();
} }
Box::new(unsafe { device::MemBuf::new(_user_img_start, _user_img_end) }) Arc::new(unsafe { device::MemBuf::new(_user_img_start, _user_img_end) })
}; };
let sfs = SimpleFileSystem::open(device).expect("failed to open SFS"); let sfs = SimpleFileSystem::open(device).expect("failed to open SFS");

@ -1,14 +1,13 @@
//! Syscalls for time //! Syscalls for time
use super::*; use super::*;
use crate::arch::consts::USEC_PER_TICK; use crate::consts::USEC_PER_TICK;
use crate::arch::driver::rtc_cmos;
use core::time::Duration; use core::time::Duration;
use lazy_static::lazy_static; use lazy_static::lazy_static;
/// should be initialized together /// should be initialized together
lazy_static! { lazy_static! {
pub static ref EPOCH_BASE: u64 = rtc_cmos::read_epoch(); pub static ref EPOCH_BASE: u64 = crate::arch::timer::read_epoch();
pub static ref TICK_BASE: u64 = unsafe { crate::trap::TICK as u64 }; pub static ref TICK_BASE: u64 = unsafe { crate::trap::TICK as u64 };
} }

@ -1 +1 @@
Subproject commit 5b6efc54fbecf5f08517be0e03c434484f7efe90 Subproject commit 7db2bd11e523f6c176d8aa278a57e5412bc448fa
Loading…
Cancel
Save