cargo fmt

This commit is contained in:
Yu Chen 2022-05-14 22:53:45 +08:00
parent babcd45c9c
commit 4e2436f757
11 changed files with 47 additions and 38 deletions

View file

@ -20,7 +20,8 @@ pub struct VirtIOBlock {
}
lazy_static! {
static ref QUEUE_FRAMES: UPIntrFreeCell<Vec<FrameTracker>> = unsafe { UPIntrFreeCell::new(Vec::new()) };
static ref QUEUE_FRAMES: UPIntrFreeCell<Vec<FrameTracker>> =
unsafe { UPIntrFreeCell::new(Vec::new()) };
}
impl BlockDevice for VirtIOBlock {

View file

@ -1,7 +1,6 @@
///! Ref: https://www.lammertbies.nl/comm/info/serial-uart
///! Ref: ns16550a datasheet: https://datasheetspdf.com/pdf-file/605590/NationalSemiconductor/NS16550A/1
///! Ref: ns16450 datasheet: https://datasheetspdf.com/pdf-file/1311818/NationalSemiconductor/NS16450/1
use super::CharDevice;
use crate::sync::{Condvar, UPIntrFreeCell};
use crate::task::schedule;

View file

@ -46,7 +46,8 @@ use lazy_static::*;
use sync::UPIntrFreeCell;
lazy_static! {
pub static ref DEV_NON_BLOCKING_ACCESS: UPIntrFreeCell<bool> = unsafe { UPIntrFreeCell::new(false) };
pub static ref DEV_NON_BLOCKING_ACCESS: UPIntrFreeCell<bool> =
unsafe { UPIntrFreeCell::new(false) };
}
#[no_mangle]

View file

@ -1,5 +1,8 @@
use crate::sync::{Mutex, UPIntrFreeCell};
use crate::task::{add_task, block_current_task, block_current_and_run_next, current_task, TaskControlBlock, TaskContext};
use crate::task::{
add_task, block_current_and_run_next, block_current_task, current_task, TaskContext,
TaskControlBlock,
};
use alloc::{collections::VecDeque, sync::Arc};
pub struct Condvar {

View file

@ -1,7 +1,7 @@
use core::cell::{RefCell, RefMut, UnsafeCell};
use core::ops::{Deref, DerefMut};
use riscv::register::sstatus;
use lazy_static::*;
use riscv::register::sstatus;
/*
/// Wrap a static data structure inside it so that we are
@ -56,9 +56,8 @@ pub struct IntrMaskingInfo {
}
lazy_static! {
static ref INTR_MASKING_INFO: UPSafeCellRaw<IntrMaskingInfo> = unsafe {
UPSafeCellRaw::new(IntrMaskingInfo::new())
};
static ref INTR_MASKING_INFO: UPSafeCellRaw<IntrMaskingInfo> =
unsafe { UPSafeCellRaw::new(IntrMaskingInfo::new()) };
}
impl IntrMaskingInfo {
@ -71,7 +70,9 @@ impl IntrMaskingInfo {
pub fn enter(&mut self) {
let sie = sstatus::read().sie();
unsafe { sstatus::clear_sie(); }
unsafe {
sstatus::clear_sie();
}
if self.nested_level == 0 {
self.sie_before_masking = sie;
}
@ -81,7 +82,9 @@ impl IntrMaskingInfo {
pub fn exit(&mut self) {
self.nested_level -= 1;
if self.nested_level == 0 && self.sie_before_masking {
unsafe { sstatus::set_sie(); }
unsafe {
sstatus::set_sie();
}
}
}
}
@ -101,14 +104,17 @@ impl<T> UPIntrFreeCell<T> {
inner: RefCell::new(value),
}
}
/// Panic if the data has been borrowed.
pub fn exclusive_access(&self) -> UPIntrRefMut<'_, T> {
INTR_MASKING_INFO.get_mut().enter();
UPIntrRefMut(Some(self.inner.borrow_mut()))
}
pub fn exclusive_session<F, V>(&self, f: F) -> V where F: FnOnce(&mut T) -> V {
pub fn exclusive_session<F, V>(&self, f: F) -> V
where
F: FnOnce(&mut T) -> V,
{
let mut inner = self.exclusive_access();
f(inner.deref_mut())
}
@ -132,4 +138,3 @@ impl<'a, T> DerefMut for UPIntrRefMut<'a, T> {
self.0.as_mut().unwrap().deref_mut()
}
}

View file

@ -26,7 +26,6 @@ pub use processor::{
pub use signal::SignalFlags;
pub use task::{TaskControlBlock, TaskStatus};
pub fn suspend_current_and_run_next() {
// There must be an application running.
let task = take_current_task().unwrap();
@ -54,7 +53,7 @@ pub fn block_current_task() -> *mut TaskContext {
}
pub fn block_current_and_run_next() {
let task_cx_ptr = block_current_task();
let task_cx_ptr = block_current_task();
schedule(task_cx_ptr);
}

View file

@ -30,7 +30,8 @@ impl Processor {
}
lazy_static! {
pub static ref PROCESSOR: UPIntrFreeCell<Processor> = unsafe { UPIntrFreeCell::new(Processor::new()) };
pub static ref PROCESSOR: UPIntrFreeCell<Processor> =
unsafe { UPIntrFreeCell::new(Processor::new()) };
}
pub fn run_tasks() {
@ -94,9 +95,8 @@ pub fn current_kstack_top() -> usize {
}
pub fn schedule(switched_task_cx_ptr: *mut TaskContext) {
let idle_task_cx_ptr = PROCESSOR.exclusive_session(|processor| {
processor.get_idle_task_cx_ptr()
});
let idle_task_cx_ptr =
PROCESSOR.exclusive_session(|processor| processor.get_idle_task_cx_ptr());
unsafe {
__switch(switched_task_cx_ptr, idle_task_cx_ptr);
}

View file

@ -1,7 +1,10 @@
use super::id::TaskUserRes;
use super::{kstack_alloc, KernelStack, ProcessControlBlock, TaskContext};
use crate::trap::TrapContext;
use crate::{mm::PhysPageNum, sync::{UPIntrFreeCell, UPIntrRefMut}};
use crate::{
mm::PhysPageNum,
sync::{UPIntrFreeCell, UPIntrRefMut},
};
use alloc::sync::{Arc, Weak};
pub struct TaskControlBlock {

View file

@ -11,7 +11,7 @@ use core::arch::{asm, global_asm};
use riscv::register::{
mtvec::TrapMode,
scause::{self, Exception, Interrupt, Trap},
sie, stval, stvec, sstatus, sscratch,
sie, sscratch, sstatus, stval, stvec,
};
global_asm!(include_str!("trap.S"));
@ -23,7 +23,7 @@ pub fn init() {
fn set_kernel_trap_entry() {
extern "C" {
fn __alltraps();
fn __alltraps_k();
fn __alltraps_k();
}
let __alltraps_k_va = __alltraps_k as usize - __alltraps as usize + TRAMPOLINE;
unsafe {
@ -52,7 +52,7 @@ fn enable_supervisor_interrupt() {
fn disable_supervisor_interrupt() {
unsafe {
sstatus::clear_sie();
sstatus::clear_sie();
}
}
@ -67,7 +67,7 @@ pub fn trap_handler() -> ! {
// jump to next instruction anyway
let mut cx = current_trap_cx();
cx.sepc += 4;
enable_supervisor_interrupt();
// get system call return value
@ -150,19 +150,19 @@ pub fn trap_from_kernel(_trap_cx: &TrapContext) {
match scause.cause() {
Trap::Interrupt(Interrupt::SupervisorExternal) => {
crate::board::irq_handler();
},
}
Trap::Interrupt(Interrupt::SupervisorTimer) => {
set_next_trigger();
check_timer();
// do not schedule now
},
}
_ => {
panic!(
"Unsupported trap from kernel: {:?}, stval = {:#x}!",
scause.cause(),
stval
);
},
}
}
}