From 0f574286461c8db4e76618e435007af2847a2e5a Mon Sep 17 00:00:00 2001 From: Linwei Zhang Date: Tue, 12 Nov 2024 11:17:24 +0800 Subject: [PATCH] Format code --- .../modules/axhal/src/arch/riscv/context.rs | 2 +- arceos/modules/axhal/src/misc.rs | 6 +-- arceos/modules/axmm/src/aspace.rs | 6 +-- arceos/payload/skernel/src/main.rs | 6 +-- arceos/tour/h_1_0/src/main.rs | 30 +++++++++------ arceos/tour/h_1_0/src/task.rs | 7 +--- arceos/tour/h_1_0/src/vcpu.rs | 2 +- arceos/tour/m_1_0/src/main.rs | 35 +++++++++++------- arceos/tour/m_1_0/src/syscall.rs | 2 +- arceos/tour/m_2_0/src/main.rs | 37 ++++++++++++------- arceos/tour/m_2_0/src/syscall.rs | 2 +- arceos/tour/u_4_0/src/main.rs | 6 +-- arceos/tour/u_5_0/src/main.rs | 4 +- arceos/tour/u_6_0/src/main.rs | 4 +- arceos/tour/u_6_1/src/main.rs | 4 +- arceos/tour/u_7_0/src/main.rs | 15 ++++---- arceos/tour/u_8_0/src/main.rs | 4 +- 17 files changed, 93 insertions(+), 79 deletions(-) diff --git a/arceos/modules/axhal/src/arch/riscv/context.rs b/arceos/modules/axhal/src/arch/riscv/context.rs index 6542ca4be..1735460fa 100644 --- a/arceos/modules/axhal/src/arch/riscv/context.rs +++ b/arceos/modules/axhal/src/arch/riscv/context.rs @@ -1,7 +1,7 @@ use core::arch::asm; -use memory_addr::VirtAddr; #[cfg(feature = "uspace")] use memory_addr::PhysAddr; +use memory_addr::VirtAddr; include_asm_marcos!(); diff --git a/arceos/modules/axhal/src/misc.rs b/arceos/modules/axhal/src/misc.rs index 9a91ba110..3cac9e05c 100644 --- a/arceos/modules/axhal/src/misc.rs +++ b/arceos/modules/axhal/src/misc.rs @@ -1,20 +1,20 @@ pub use super::platform::misc::*; -use kspin::SpinNoIrq; use crate::time; +use kspin::SpinNoIrq; static PARK_MILLER_LEHMER_SEED: SpinNoIrq = SpinNoIrq::new(0); const RAND_MAX: u64 = 2_147_483_647; pub fn random() -> u128 { - let mut seed = PARK_MILLER_LEHMER_SEED.lock(); + let mut seed = PARK_MILLER_LEHMER_SEED.lock(); if *seed == 0 { *seed = time::current_ticks() as u32; } let mut ret: u128 = 0; for _ in 0..4 { - *seed = ((u64::from(*seed) * 48271) % RAND_MAX) as u32; + *seed = ((u64::from(*seed) * 48271) % RAND_MAX) as u32; ret = (ret << 32) | (*seed as u128); } ret diff --git a/arceos/modules/axmm/src/aspace.rs b/arceos/modules/axmm/src/aspace.rs index fd851723c..d1c35f8cf 100644 --- a/arceos/modules/axmm/src/aspace.rs +++ b/arceos/modules/axmm/src/aspace.rs @@ -1,5 +1,8 @@ use core::fmt; +use crate::backend::Backend; +use crate::mapping_err_to_ax_err; +use crate::paging_err_to_ax_err; use axerrno::{ax_err, AxError, AxResult}; use axhal::{ mem::phys_to_virt, @@ -9,9 +12,6 @@ use memory_addr::{ is_aligned_4k, pa, MemoryAddr, PageIter4K, PhysAddr, VirtAddr, VirtAddrRange, PAGE_SIZE_4K, }; use memory_set::{MemoryArea, MemorySet}; -use crate::backend::Backend; -use crate::paging_err_to_ax_err; -use crate::mapping_err_to_ax_err; /// The virtual memory address space. pub struct AddrSpace { diff --git a/arceos/payload/skernel/src/main.rs b/arceos/payload/skernel/src/main.rs index b0e170b2b..401476e3d 100644 --- a/arceos/payload/skernel/src/main.rs +++ b/arceos/payload/skernel/src/main.rs @@ -5,11 +5,7 @@ use core::panic::PanicInfo; #[no_mangle] unsafe extern "C" fn _start() -> ! { - core::arch::asm!( - "li a7, 8", - "ecall", - options(noreturn) - ) + core::arch::asm!("li a7, 8", "ecall", options(noreturn)) } #[panic_handler] diff --git a/arceos/tour/h_1_0/src/main.rs b/arceos/tour/h_1_0/src/main.rs index babb17d66..d02adf7b2 100644 --- a/arceos/tour/h_1_0/src/main.rs +++ b/arceos/tour/h_1_0/src/main.rs @@ -8,20 +8,20 @@ extern crate axstd as std; extern crate alloc; +mod csrs; +mod regs; mod task; mod vcpu; -mod regs; -mod csrs; -use std::io::{self, Read}; -use std::fs::File; +use axhal::mem::{phys_to_virt, PAGE_SIZE_4K}; use axhal::paging::MappingFlags; -use axhal::mem::{PAGE_SIZE_4K, phys_to_virt}; -use vcpu::VmCpuRegisters; -use riscv::register::{htinst, htval, scause, sstatus, stval}; use csrs::defs::hstatus; -use tock_registers::LocalRegisterCopy; use csrs::{traps, RiscvCsrTrait, CSR}; +use riscv::register::{htinst, htval, scause, sstatus, stval}; +use std::fs::File; +use std::io::{self, Read}; +use tock_registers::LocalRegisterCopy; +use vcpu::VmCpuRegisters; use vcpu::_run_guest; #[cfg_attr(feature = "axstd", no_mangle)] @@ -34,7 +34,14 @@ fn main() { let entry = 0x8020_0000; let mut uspace = axmm::new_user_aspace().unwrap(); - uspace.map_alloc(entry.into(), PAGE_SIZE_4K, MappingFlags::READ|MappingFlags::WRITE|MappingFlags::EXECUTE|MappingFlags::USER, true).unwrap(); + uspace + .map_alloc( + entry.into(), + PAGE_SIZE_4K, + MappingFlags::READ | MappingFlags::WRITE | MappingFlags::EXECUTE | MappingFlags::USER, + true, + ) + .unwrap(); let (paddr, _, _) = uspace .page_table() @@ -56,9 +63,8 @@ fn main() { let ept_root = uspace.page_table_root(); let mut ctx = VmCpuRegisters::default(); // Set hstatus - let mut hstatus = LocalRegisterCopy::::new( - riscv::register::hstatus::read().bits(), - ); + let mut hstatus = + LocalRegisterCopy::::new(riscv::register::hstatus::read().bits()); hstatus.modify(hstatus::spv::Guest); // Set SPVP bit in order to accessing VS-mode memory from HS-mode. hstatus.modify(hstatus::spvp::Supervisor); diff --git a/arceos/tour/h_1_0/src/task.rs b/arceos/tour/h_1_0/src/task.rs index ffe8f2cae..fc8f07812 100644 --- a/arceos/tour/h_1_0/src/task.rs +++ b/arceos/tour/h_1_0/src/task.rs @@ -1,9 +1,9 @@ use alloc::sync::Arc; +use crate::vcpu::VmCpuRegisters; use axmm::AddrSpace; use axsync::Mutex; use axtask::{AxTaskRef, TaskExtRef, TaskInner}; -use crate::vcpu::VmCpuRegisters; /// Task extended data for the monolithic kernel. pub struct TaskExt { @@ -15,10 +15,7 @@ pub struct TaskExt { impl TaskExt { pub const fn new(vcpu: VmCpuRegisters, aspace: Arc>) -> Self { - Self { - vcpu, - aspace, - } + Self { vcpu, aspace } } } diff --git a/arceos/tour/h_1_0/src/vcpu.rs b/arceos/tour/h_1_0/src/vcpu.rs index 95083fa47..3dd951f90 100644 --- a/arceos/tour/h_1_0/src/vcpu.rs +++ b/arceos/tour/h_1_0/src/vcpu.rs @@ -212,7 +212,7 @@ pub struct RISCVVCpu { regs: VmCpuRegisters, } - /* +/* impl RISCVVCpu { type CreateConfig = (); diff --git a/arceos/tour/m_1_0/src/main.rs b/arceos/tour/m_1_0/src/main.rs index 6a9bff2b8..54aa9273c 100644 --- a/arceos/tour/m_1_0/src/main.rs +++ b/arceos/tour/m_1_0/src/main.rs @@ -6,16 +6,16 @@ extern crate axstd as std; extern crate alloc; -mod task; mod syscall; +mod task; -use std::io::{self, Read}; -use std::fs::File; -use axhal::paging::MappingFlags; -use axhal::mem::{PAGE_SIZE_4K, phys_to_virt}; +use alloc::sync::Arc; use axhal::arch::UspaceContext; +use axhal::mem::{phys_to_virt, PAGE_SIZE_4K}; +use axhal::paging::MappingFlags; use axsync::Mutex; -use alloc::sync::Arc; +use std::fs::File; +use std::io::{self, Read}; const USER_STACK_SIZE: usize = 0x10000; const KERNEL_STACK_SIZE: usize = 0x40000; // 256 KiB @@ -29,7 +29,14 @@ fn main() { let entry = 0x1000; let mut uspace = axmm::new_user_aspace().unwrap(); - uspace.map_alloc(entry.into(), PAGE_SIZE_4K, MappingFlags::READ|MappingFlags::WRITE|MappingFlags::EXECUTE|MappingFlags::USER, true).unwrap(); + uspace + .map_alloc( + entry.into(), + PAGE_SIZE_4K, + MappingFlags::READ | MappingFlags::WRITE | MappingFlags::EXECUTE | MappingFlags::USER, + true, + ) + .unwrap(); let (paddr, _, _) = uspace .page_table() @@ -52,12 +59,14 @@ fn main() { "Mapping user stack: {:#x?} -> {:#x?}", ustack_vaddr, ustack_top ); - uspace.map_alloc( - ustack_vaddr, - crate::USER_STACK_SIZE, - MappingFlags::READ | MappingFlags::WRITE | MappingFlags::USER, - true, - ).unwrap(); + uspace + .map_alloc( + ustack_vaddr, + crate::USER_STACK_SIZE, + MappingFlags::READ | MappingFlags::WRITE | MappingFlags::USER, + true, + ) + .unwrap(); println!("New user address space: {:#x?}", uspace); let user_task = task::spawn_user_task( diff --git a/arceos/tour/m_1_0/src/syscall.rs b/arceos/tour/m_1_0/src/syscall.rs index 01205a72e..edf377fcb 100644 --- a/arceos/tour/m_1_0/src/syscall.rs +++ b/arceos/tour/m_1_0/src/syscall.rs @@ -1,8 +1,8 @@ #![allow(dead_code)] +use axerrno::LinuxError; use axhal::arch::TrapFrame; use axhal::trap::{register_trap_handler, SYSCALL}; -use axerrno::LinuxError; const SYS_EXIT: usize = 93; diff --git a/arceos/tour/m_2_0/src/main.rs b/arceos/tour/m_2_0/src/main.rs index b643f7ba3..ae1ce4f65 100644 --- a/arceos/tour/m_2_0/src/main.rs +++ b/arceos/tour/m_2_0/src/main.rs @@ -6,18 +6,18 @@ extern crate axstd as std; extern crate alloc; -mod task; mod syscall; +mod task; -use std::io::{self, Read}; -use std::fs::File; -use axhal::paging::MappingFlags; -use axhal::mem::{PAGE_SIZE_4K, phys_to_virt, VirtAddr}; -use axhal::arch::UspaceContext; -use axsync::Mutex; use alloc::sync::Arc; +use axhal::arch::UspaceContext; +use axhal::mem::{phys_to_virt, VirtAddr, PAGE_SIZE_4K}; +use axhal::paging::MappingFlags; use axhal::trap::{register_trap_handler, PAGE_FAULT}; +use axsync::Mutex; use axtask::TaskExtRef; +use std::fs::File; +use std::io::{self, Read}; const USER_STACK_SIZE: usize = 0x10000; const KERNEL_STACK_SIZE: usize = 0x40000; // 256 KiB @@ -32,7 +32,14 @@ fn main() { let entry = 0x1000; let mut uspace = axmm::new_user_aspace().unwrap(); - uspace.map_alloc(entry.into(), PAGE_SIZE_4K, MappingFlags::READ|MappingFlags::WRITE|MappingFlags::EXECUTE|MappingFlags::USER, true).unwrap(); + uspace + .map_alloc( + entry.into(), + PAGE_SIZE_4K, + MappingFlags::READ | MappingFlags::WRITE | MappingFlags::EXECUTE | MappingFlags::USER, + true, + ) + .unwrap(); let (paddr, _, _) = uspace .page_table() @@ -55,12 +62,14 @@ fn main() { "Mapping user stack: {:#x?} -> {:#x?}", ustack_vaddr, ustack_top ); - uspace.map_alloc( - ustack_vaddr, - crate::USER_STACK_SIZE, - MappingFlags::READ | MappingFlags::WRITE | MappingFlags::USER, - false, - ).unwrap(); + uspace + .map_alloc( + ustack_vaddr, + crate::USER_STACK_SIZE, + MappingFlags::READ | MappingFlags::WRITE | MappingFlags::USER, + false, + ) + .unwrap(); println!("New user address space: {:#x?}", uspace); let user_task = task::spawn_user_task( diff --git a/arceos/tour/m_2_0/src/syscall.rs b/arceos/tour/m_2_0/src/syscall.rs index 01205a72e..edf377fcb 100644 --- a/arceos/tour/m_2_0/src/syscall.rs +++ b/arceos/tour/m_2_0/src/syscall.rs @@ -1,8 +1,8 @@ #![allow(dead_code)] +use axerrno::LinuxError; use axhal::arch::TrapFrame; use axhal::trap::{register_trap_handler, SYSCALL}; -use axerrno::LinuxError; const SYS_EXIT: usize = 93; diff --git a/arceos/tour/u_4_0/src/main.rs b/arceos/tour/u_4_0/src/main.rs index a85c60eef..c5fd6cab8 100644 --- a/arceos/tour/u_4_0/src/main.rs +++ b/arceos/tour/u_4_0/src/main.rs @@ -6,8 +6,8 @@ extern crate axstd as std; use core::{mem, str}; -use std::thread; use std::os::arceos::modules::axhal::mem::phys_to_virt; +use std::thread; /// Physical address for pflash#1 const PFLASH_START: usize = 0x2200_0000; @@ -22,9 +22,7 @@ fn main() { // Makesure that we can access pflash region. let va = phys_to_virt(PFLASH_START.into()).as_usize(); let ptr = va as *const u32; - let magic = unsafe { - mem::transmute::(*ptr) - }; + let magic = unsafe { mem::transmute::(*ptr) }; if let Ok(s) = str::from_utf8(&magic) { println!("Got pflash magic: {s}"); 0 diff --git a/arceos/tour/u_5_0/src/main.rs b/arceos/tour/u_5_0/src/main.rs index c87586ada..b2120cc2a 100644 --- a/arceos/tour/u_5_0/src/main.rs +++ b/arceos/tour/u_5_0/src/main.rs @@ -5,10 +5,10 @@ #[cfg(feature = "axstd")] extern crate axstd as std; -use std::thread; use std::collections::VecDeque; -use std::sync::Arc; use std::os::arceos::modules::axsync::spin::SpinNoIrq; +use std::sync::Arc; +use std::thread; const LOOP_NUM: usize = 64; diff --git a/arceos/tour/u_6_0/src/main.rs b/arceos/tour/u_6_0/src/main.rs index 87c468f6d..8c864f3c5 100644 --- a/arceos/tour/u_6_0/src/main.rs +++ b/arceos/tour/u_6_0/src/main.rs @@ -6,10 +6,10 @@ extern crate axstd as std; #[macro_use] extern crate axlog; -use std::thread; use std::collections::VecDeque; -use std::sync::Arc; use std::os::arceos::modules::axsync::spin::SpinNoIrq; +use std::sync::Arc; +use std::thread; const LOOP_NUM: usize = 256; diff --git a/arceos/tour/u_6_1/src/main.rs b/arceos/tour/u_6_1/src/main.rs index 0ab900d0b..585df7080 100644 --- a/arceos/tour/u_6_1/src/main.rs +++ b/arceos/tour/u_6_1/src/main.rs @@ -6,11 +6,11 @@ extern crate axstd as std; #[macro_use] extern crate axlog; -use std::thread; use std::collections::VecDeque; +use std::os::arceos::modules::axtask::WaitQueue; use std::sync::Arc; use std::sync::Mutex; -use std::os::arceos::modules::axtask::WaitQueue; +use std::thread; const LOOP_NUM: usize = 256; static WQ: WaitQueue = WaitQueue::new(); diff --git a/arceos/tour/u_7_0/src/main.rs b/arceos/tour/u_7_0/src/main.rs index 8f1725dda..d570cbd25 100644 --- a/arceos/tour/u_7_0/src/main.rs +++ b/arceos/tour/u_7_0/src/main.rs @@ -5,11 +5,11 @@ #[cfg(feature = "axstd")] extern crate axstd as std; +use axdriver::prelude::{BaseDriverOps, BlockDriverOps, DeviceType}; use std::thread; -use axdriver::prelude::{DeviceType, BaseDriverOps, BlockDriverOps}; -const DISK_SIZE: usize = 0x400_0000; // 64M -const BLOCK_SIZE: usize = 0x200; // 512-bytes in default +const DISK_SIZE: usize = 0x400_0000; // 64M +const BLOCK_SIZE: usize = 0x200; // 512-bytes in default #[cfg_attr(feature = "axstd", no_mangle)] fn main() { @@ -21,17 +21,16 @@ fn main() { assert_eq!(disk.device_type(), DeviceType::Block); assert_eq!(disk.device_name(), "virtio-blk"); assert_eq!(disk.block_size(), BLOCK_SIZE); - assert_eq!(disk.num_blocks() as usize, DISK_SIZE/BLOCK_SIZE); + assert_eq!(disk.num_blocks() as usize, DISK_SIZE / BLOCK_SIZE); let mut buf = vec![0u8; BLOCK_SIZE]; assert!(disk.read_block(0, &mut buf).is_ok()); let worker1 = thread::spawn(move || { println!("worker1 checks head:"); - let head = core::str::from_utf8(&buf[3..11]) - .unwrap_or_else(|e| { - panic!("bad disk head: {:?}. err {:?}", &buf[0..16], e); - }); + let head = core::str::from_utf8(&buf[3..11]).unwrap_or_else(|e| { + panic!("bad disk head: {:?}. err {:?}", &buf[0..16], e); + }); println!("[{}]", head); println!("\nworker1 ok!"); }); diff --git a/arceos/tour/u_8_0/src/main.rs b/arceos/tour/u_8_0/src/main.rs index 3de8407ce..f8b9b4e2f 100644 --- a/arceos/tour/u_8_0/src/main.rs +++ b/arceos/tour/u_8_0/src/main.rs @@ -5,9 +5,9 @@ #[cfg(feature = "axstd")] extern crate axstd as std; -use std::thread; -use std::io::{self, prelude::*}; use std::fs::File; +use std::io::{self, prelude::*}; +use std::thread; #[cfg_attr(feature = "axstd", no_mangle)] fn main() {