Add boards/ && cargo clippy
This commit is contained in:
parent
3a120122ba
commit
3731e84460
10 changed files with 33 additions and 32 deletions
2
os/src/boards/k210.rs
Normal file
2
os/src/boards/k210.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub const CLOCK_FREQ: usize = 403000000 / 62;
|
||||||
|
|
1
os/src/boards/qemu.rs
Normal file
1
os/src/boards/qemu.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub const CLOCK_FREQ: usize = 12500000;
|
|
@ -14,8 +14,4 @@ pub fn kernel_stack_position(app_id: usize) -> (usize, usize) {
|
||||||
(bottom, top)
|
(bottom, top)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "board_k210")]
|
pub use crate::board::CLOCK_FREQ;
|
||||||
pub const CLOCK_FREQ: usize = 403000000 / 62;
|
|
||||||
|
|
||||||
#[cfg(feature = "board_qemu")]
|
|
||||||
pub const CLOCK_FREQ: usize = 12500000;
|
|
||||||
|
|
|
@ -8,6 +8,13 @@ extern crate alloc;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
|
|
||||||
|
#[cfg(feature = "board_k210")]
|
||||||
|
#[path = "boards/k210.rs"]
|
||||||
|
mod board;
|
||||||
|
#[cfg(not(any(feature = "board_k210")))]
|
||||||
|
#[path = "boards/qemu.rs"]
|
||||||
|
mod board;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod console;
|
mod console;
|
||||||
mod config;
|
mod config;
|
||||||
|
|
|
@ -153,15 +153,15 @@ impl VirtPageNum {
|
||||||
|
|
||||||
impl PhysPageNum {
|
impl PhysPageNum {
|
||||||
pub fn get_pte_array(&self) -> &'static mut [PageTableEntry] {
|
pub fn get_pte_array(&self) -> &'static mut [PageTableEntry] {
|
||||||
let pa: PhysAddr = self.clone().into();
|
let pa: PhysAddr = (*self).into();
|
||||||
unsafe { core::slice::from_raw_parts_mut(pa.0 as *mut PageTableEntry, 512) }
|
unsafe { core::slice::from_raw_parts_mut(pa.0 as *mut PageTableEntry, 512) }
|
||||||
}
|
}
|
||||||
pub fn get_bytes_array(&self) -> &'static mut [u8] {
|
pub fn get_bytes_array(&self) -> &'static mut [u8] {
|
||||||
let pa: PhysAddr = self.clone().into();
|
let pa: PhysAddr = (*self).into();
|
||||||
unsafe { core::slice::from_raw_parts_mut(pa.0 as *mut u8, 4096) }
|
unsafe { core::slice::from_raw_parts_mut(pa.0 as *mut u8, 4096) }
|
||||||
}
|
}
|
||||||
pub fn get_mut<T>(&self) -> &'static mut T {
|
pub fn get_mut<T>(&self) -> &'static mut T {
|
||||||
let pa: PhysAddr = self.clone().into();
|
let pa: PhysAddr = (*self).into();
|
||||||
unsafe { (pa.0 as *mut T).as_mut().unwrap() }
|
unsafe { (pa.0 as *mut T).as_mut().unwrap() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl FrameAllocator for StackFrameAllocator {
|
||||||
fn dealloc(&mut self, ppn: PhysPageNum) {
|
fn dealloc(&mut self, ppn: PhysPageNum) {
|
||||||
let ppn = ppn.0;
|
let ppn = ppn.0;
|
||||||
// validity check
|
// validity check
|
||||||
if ppn >= self.current || self.recycled.iter().find(|&v| *v == ppn).is_some() {
|
if ppn >= self.current || self.recycled.iter().any(|&v| v == ppn) {
|
||||||
panic!("Frame ppn={:#x} has not been allocated!", ppn);
|
panic!("Frame ppn={:#x} has not been allocated!", ppn);
|
||||||
}
|
}
|
||||||
// recycle
|
// recycle
|
||||||
|
@ -100,7 +100,7 @@ pub fn frame_alloc() -> Option<FrameTracker> {
|
||||||
FRAME_ALLOCATOR
|
FRAME_ALLOCATOR
|
||||||
.exclusive_access()
|
.exclusive_access()
|
||||||
.alloc()
|
.alloc()
|
||||||
.map(|ppn| FrameTracker::new(ppn))
|
.map(FrameTracker::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn frame_dealloc(ppn: PhysPageNum) {
|
fn frame_dealloc(ppn: PhysPageNum) {
|
||||||
|
|
|
@ -36,8 +36,8 @@ pub fn heap_test() {
|
||||||
for i in 0..500 {
|
for i in 0..500 {
|
||||||
v.push(i);
|
v.push(i);
|
||||||
}
|
}
|
||||||
for i in 0..500 {
|
for (i, val) in v.iter().take(500).enumerate() {
|
||||||
assert_eq!(v[i], i);
|
assert_eq!(*val, i);
|
||||||
}
|
}
|
||||||
assert!(bss_range.contains(&(v.as_ptr() as usize)));
|
assert!(bss_range.contains(&(v.as_ptr() as usize)));
|
||||||
drop(v);
|
drop(v);
|
||||||
|
|
|
@ -256,11 +256,8 @@ impl MapArea {
|
||||||
}
|
}
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn unmap_one(&mut self, page_table: &mut PageTable, vpn: VirtPageNum) {
|
pub fn unmap_one(&mut self, page_table: &mut PageTable, vpn: VirtPageNum) {
|
||||||
match self.map_type {
|
if self.map_type == MapType::Framed {
|
||||||
MapType::Framed => {
|
self.data_frames.remove(&vpn);
|
||||||
self.data_frames.remove(&vpn);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
page_table.unmap(vpn);
|
page_table.unmap(vpn);
|
||||||
}
|
}
|
||||||
|
@ -320,29 +317,26 @@ pub fn remap_test() {
|
||||||
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
|
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
|
||||||
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
|
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
|
||||||
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
|
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
|
||||||
assert_eq!(
|
assert!(
|
||||||
kernel_space
|
!kernel_space
|
||||||
.page_table
|
.page_table
|
||||||
.translate(mid_text.floor())
|
.translate(mid_text.floor())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.writable(),
|
.writable(),
|
||||||
false
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert!(
|
||||||
kernel_space
|
!kernel_space
|
||||||
.page_table
|
.page_table
|
||||||
.translate(mid_rodata.floor())
|
.translate(mid_rodata.floor())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.writable(),
|
.writable(),
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert!(
|
||||||
kernel_space
|
!kernel_space
|
||||||
.page_table
|
.page_table
|
||||||
.translate(mid_data.floor())
|
.translate(mid_data.floor())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.executable(),
|
.executable(),
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
println!("remap_test passed!");
|
println!("remap_test passed!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,8 +76,8 @@ impl PageTable {
|
||||||
let idxs = vpn.indexes();
|
let idxs = vpn.indexes();
|
||||||
let mut ppn = self.root_ppn;
|
let mut ppn = self.root_ppn;
|
||||||
let mut result: Option<&mut PageTableEntry> = None;
|
let mut result: Option<&mut PageTableEntry> = None;
|
||||||
for i in 0..3 {
|
for (i, idx) in idxs.iter().enumerate() {
|
||||||
let pte = &mut ppn.get_pte_array()[idxs[i]];
|
let pte = &mut ppn.get_pte_array()[*idx];
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
result = Some(pte);
|
result = Some(pte);
|
||||||
break;
|
break;
|
||||||
|
@ -95,8 +95,8 @@ impl PageTable {
|
||||||
let idxs = vpn.indexes();
|
let idxs = vpn.indexes();
|
||||||
let mut ppn = self.root_ppn;
|
let mut ppn = self.root_ppn;
|
||||||
let mut result: Option<&mut PageTableEntry> = None;
|
let mut result: Option<&mut PageTableEntry> = None;
|
||||||
for i in 0..3 {
|
for (i, idx) in idxs.iter().enumerate() {
|
||||||
let pte = &mut ppn.get_pte_array()[idxs[i]];
|
let pte = &mut ppn.get_pte_array()[*idx];
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
result = Some(pte);
|
result = Some(pte);
|
||||||
break;
|
break;
|
||||||
|
@ -121,7 +121,7 @@ impl PageTable {
|
||||||
*pte = PageTableEntry::empty();
|
*pte = PageTableEntry::empty();
|
||||||
}
|
}
|
||||||
pub fn translate(&self, vpn: VirtPageNum) -> Option<PageTableEntry> {
|
pub fn translate(&self, vpn: VirtPageNum) -> Option<PageTableEntry> {
|
||||||
self.find_pte(vpn).map(|pte| pte.clone())
|
self.find_pte(vpn).map(|pte| *pte)
|
||||||
}
|
}
|
||||||
pub fn token(&self) -> usize {
|
pub fn token(&self) -> usize {
|
||||||
8usize << 60 | self.root_ppn.0
|
8usize << 60 | self.root_ppn.0
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
mod context;
|
mod context;
|
||||||
mod switch;
|
mod switch;
|
||||||
|
#[allow(clippy::module_inception)]
|
||||||
mod task;
|
mod task;
|
||||||
|
|
||||||
use crate::loader::{get_app_data, get_num_app};
|
use crate::loader::{get_app_data, get_num_app};
|
||||||
|
@ -83,7 +84,7 @@ impl TaskManager {
|
||||||
inner.tasks[inner.current_task].get_user_token()
|
inner.tasks[inner.current_task].get_user_token()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_current_trap_cx(&self) -> &mut TrapContext {
|
fn get_current_trap_cx(&self) -> &'static mut TrapContext {
|
||||||
let inner = self.inner.exclusive_access();
|
let inner = self.inner.exclusive_access();
|
||||||
inner.tasks[inner.current_task].get_trap_cx()
|
inner.tasks[inner.current_task].get_trap_cx()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue