Add boards/ && cargo clippy

ch4
Yifan Wu 3 years ago
parent fadc203e4a
commit badc110584

@ -0,0 +1,2 @@
pub const CLOCK_FREQ: usize = 403000000 / 62;

@ -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)
}
#[cfg(feature = "board_k210")]
pub const CLOCK_FREQ: usize = 403000000 / 62;
#[cfg(feature = "board_qemu")]
pub const CLOCK_FREQ: usize = 12500000;
pub use crate::board::CLOCK_FREQ;

@ -8,6 +8,13 @@ extern crate alloc;
#[macro_use]
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]
mod console;
mod config;

@ -153,15 +153,15 @@ impl VirtPageNum {
impl PhysPageNum {
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) }
}
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) }
}
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() }
}
}

@ -71,7 +71,7 @@ impl FrameAllocator for StackFrameAllocator {
fn dealloc(&mut self, ppn: PhysPageNum) {
let ppn = ppn.0;
// 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);
}
// recycle
@ -100,7 +100,7 @@ pub fn frame_alloc() -> Option<FrameTracker> {
FRAME_ALLOCATOR
.exclusive_access()
.alloc()
.map(|ppn| FrameTracker::new(ppn))
.map(FrameTracker::new)
}
fn frame_dealloc(ppn: PhysPageNum) {

@ -36,8 +36,8 @@ pub fn heap_test() {
for i in 0..500 {
v.push(i);
}
for i in 0..500 {
assert_eq!(v[i], i);
for (i, val) in v.iter().take(500).enumerate() {
assert_eq!(*val, i);
}
assert!(bss_range.contains(&(v.as_ptr() as usize)));
drop(v);

@ -256,11 +256,8 @@ impl MapArea {
}
#[allow(unused)]
pub fn unmap_one(&mut self, page_table: &mut PageTable, vpn: VirtPageNum) {
match self.map_type {
MapType::Framed => {
self.data_frames.remove(&vpn);
}
_ => {}
if self.map_type == MapType::Framed {
self.data_frames.remove(&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_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
assert_eq!(
kernel_space
assert!(
!kernel_space
.page_table
.translate(mid_text.floor())
.unwrap()
.writable(),
false
);
assert_eq!(
kernel_space
assert!(
!kernel_space
.page_table
.translate(mid_rodata.floor())
.unwrap()
.writable(),
false,
);
assert_eq!(
kernel_space
assert!(
!kernel_space
.page_table
.translate(mid_data.floor())
.unwrap()
.executable(),
false,
);
println!("remap_test passed!");
}

@ -76,8 +76,8 @@ impl PageTable {
let idxs = vpn.indexes();
let mut ppn = self.root_ppn;
let mut result: Option<&mut PageTableEntry> = None;
for i in 0..3 {
let pte = &mut ppn.get_pte_array()[idxs[i]];
for (i, idx) in idxs.iter().enumerate() {
let pte = &mut ppn.get_pte_array()[*idx];
if i == 2 {
result = Some(pte);
break;
@ -95,8 +95,8 @@ impl PageTable {
let idxs = vpn.indexes();
let mut ppn = self.root_ppn;
let mut result: Option<&mut PageTableEntry> = None;
for i in 0..3 {
let pte = &mut ppn.get_pte_array()[idxs[i]];
for (i, idx) in idxs.iter().enumerate() {
let pte = &mut ppn.get_pte_array()[*idx];
if i == 2 {
result = Some(pte);
break;
@ -121,7 +121,7 @@ impl PageTable {
*pte = PageTableEntry::empty();
}
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 {
8usize << 60 | self.root_ppn.0

@ -1,5 +1,6 @@
mod context;
mod switch;
#[allow(clippy::module_inception)]
mod task;
use crate::loader::{get_app_data, get_num_app};
@ -83,7 +84,7 @@ impl TaskManager {
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();
inner.tasks[inner.current_task].get_trap_cx()
}

Loading…
Cancel
Save