update riscv crate

master
WangRunji 6 years ago
parent edbf07f914
commit d9bb072cbd

8
kernel/Cargo.lock generated

@ -320,7 +320,7 @@ dependencies = [
"rcore-fs-sfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?branch=sefs)",
"rcore-memory 0.1.0",
"rcore-thread 0.1.0",
"riscv 0.3.0 (git+https://github.com/rcore-os/riscv)",
"riscv 0.5.0 (git+https://github.com/rcore-os/riscv)",
"smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -388,8 +388,8 @@ dependencies = [
[[package]]
name = "riscv"
version = "0.3.0"
source = "git+https://github.com/rcore-os/riscv#26f9a05dc82c747f0ca5e01174abfae3aa6e82c1"
version = "0.5.0"
source = "git+https://github.com/rcore-os/riscv#e8be9f93513225596709a2dccd9064324591fc3c"
dependencies = [
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -625,7 +625,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum riscv 0.3.0 (git+https://github.com/rcore-os/riscv)" = "<none>"
"checksum riscv 0.5.0 (git+https://github.com/rcore-os/riscv)" = "<none>"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"

@ -66,7 +66,7 @@ uart_16550 = "0.1"
pc-keyboard = "0.5"
[target.'cfg(any(target_arch = "riscv32", target_arch = "riscv64"))'.dependencies]
riscv = { git = "https://github.com/rcore-os/riscv" }
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
bbl = { path = "../crate/bbl" }
[target.'cfg(target_arch = "aarch64")'.dependencies]

@ -41,12 +41,19 @@ impl TrapFrame {
tf.x[2] = sp;
tf.sepc = entry as usize;
tf.sstatus = xstatus::read();
tf.sstatus.set_xpie(true);
tf.sstatus.set_xie(false);
#[cfg(feature = "m_mode")]
tf.sstatus.set_mpp(xstatus::MPP::Machine);
{
tf.sstatus.set_mpie(true);
tf.sstatus.set_mie(false);
tf.sstatus.set_mpp(xstatus::MPP::Machine);
}
#[cfg(not(feature = "m_mode"))]
tf.sstatus.set_spp(xstatus::SPP::Supervisor);
{
tf.sstatus.set_spie(true);
tf.sstatus.set_sie(false);
tf.sstatus.set_spp(xstatus::SPP::Supervisor);
}
tf
}
@ -65,12 +72,18 @@ impl TrapFrame {
tf.x[2] = sp;
tf.sepc = entry_addr;
tf.sstatus = xstatus::read();
tf.sstatus.set_xpie(true);
tf.sstatus.set_xie(false);
#[cfg(feature = "m_mode")]
tf.sstatus.set_mpp(xstatus::MPP::User);
{
tf.sstatus.set_mpie(true);
tf.sstatus.set_mie(false);
tf.sstatus.set_mpp(xstatus::MPP::User);
}
#[cfg(not(feature = "m_mode"))]
tf.sstatus.set_spp(xstatus::SPP::User);
{
tf.sstatus.set_spie(true);
tf.sstatus.set_sie(false);
tf.sstatus.set_spp(xstatus::SPP::User);
}
tf
}
}

@ -50,9 +50,12 @@ pub fn init() {
* @brief:
* enable interrupt
*/
#[inline(always)]
#[inline]
pub unsafe fn enable() {
xstatus::set_xie();
#[cfg(feature = "m_mode")]
xstatus::set_mie();
#[cfg(not(feature = "m_mode"))]
xstatus::set_sie();
}
/*
@ -61,10 +64,19 @@ pub unsafe fn enable() {
* @retbal:
* a usize value store the origin sie
*/
#[inline(always)]
#[inline]
#[cfg(feature = "m_mode")]
pub unsafe fn disable_and_store() -> usize {
let e = xstatus::read().mie() as usize;
xstatus::clear_mie();
e
}
#[inline]
#[cfg(not(feature = "m_mode"))]
pub unsafe fn disable_and_store() -> usize {
let e = xstatus::read().xie() as usize;
xstatus::clear_xie();
let e = xstatus::read().sie() as usize;
xstatus::clear_sie();
e
}
@ -74,10 +86,10 @@ pub unsafe fn disable_and_store() -> usize {
* @brief:
* enable interrupt if flags != 0
*/
#[inline(always)]
#[inline]
pub unsafe fn restore(flags: usize) {
if flags != 0 {
xstatus::set_xie();
enable();
}
}

@ -97,7 +97,7 @@ impl ActivePageTable {
/// implementation for the Entry trait in /crate/memory/src/paging/mod.rs
impl Entry for PageEntry {
fn update(&mut self) {
sfence_vma(0, self.1.start_address());
unsafe { sfence_vma(0, self.1.start_address().as_usize()); }
}
fn accessed(&self) -> bool { self.0.flags().contains(EF::ACCESSED) }
fn dirty(&self) -> bool { self.0.flags().contains(EF::DIRTY) }
@ -212,7 +212,7 @@ impl InactivePageTable for InactivePageTable0 {
}
fn flush_tlb() {
sfence_vma_all();
unsafe { sfence_vma_all(); }
}
/*
@ -229,14 +229,14 @@ impl InactivePageTable for InactivePageTable0 {
// overwrite recursive mapping
root_table[RECURSIVE_INDEX].set(self.root_frame.clone(), EF::VALID);
sfence_vma_all();
unsafe { sfence_vma_all(); }
// execute f in the new context
let ret = f(active_table);
// restore recursive mapping to original p2 table
root_table[RECURSIVE_INDEX] = backup;
sfence_vma_all();
unsafe { sfence_vma_all(); }
ret
})

Loading…
Cancel
Save