From 95f0cd5b6c193b4882b84290468190b4890b6bdb Mon Sep 17 00:00:00 2001 From: gjz010 Date: Wed, 3 Mar 2021 14:55:28 +0800 Subject: [PATCH] Run cargo fmt. --- kernel/src/arch/riscv/mod.rs | 19 +++++++------- kernel/src/arch/riscv/sbi.rs | 51 +++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/kernel/src/arch/riscv/mod.rs b/kernel/src/arch/riscv/mod.rs index 7d452fd5..81caa258 100644 --- a/kernel/src/arch/riscv/mod.rs +++ b/kernel/src/arch/riscv/mod.rs @@ -22,15 +22,15 @@ pub mod syscall; pub mod timer; use crate::memory::phys_to_virt; -use core::sync::atomic::{AtomicBool, Ordering, AtomicUsize}; +use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use riscv::register::sie; -fn start_all_harts(){ +fn start_all_harts() { // simply wake up the first 64 harts. use sbi::sbi_hart_start; - for i in 0..64{ - let ret=sbi_hart_start(i, 0x80200000usize , i); - info!("Start {}: {:?}",i,ret); + for i in 0..64 { + let ret = sbi_hart_start(i, 0x80200000usize, i); + info!("Start {}: {:?}", i, ret); } } @@ -42,7 +42,10 @@ pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! { cpu::set_cpu_id(hartid); } - if FIRST_HART.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst).is_ok(){ + if FIRST_HART + .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) + .is_ok() + { LOTTERY_HART_ID.store(hartid, Ordering::SeqCst); start_all_harts(); } @@ -56,9 +59,7 @@ pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! { memory::clear_bss(); } crate::logging::init(); - - unsafe { trapframe::init(); } @@ -76,7 +77,7 @@ pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! { hartid, device_tree_vaddr ); AP_CAN_INIT.store(true, Ordering::Relaxed); - + crate::kmain(); } diff --git a/kernel/src/arch/riscv/sbi.rs b/kernel/src/arch/riscv/sbi.rs index d22dcf36..31d37df2 100644 --- a/kernel/src/arch/riscv/sbi.rs +++ b/kernel/src/arch/riscv/sbi.rs @@ -2,14 +2,14 @@ #![allow(dead_code)] #[derive(Clone, Copy, Debug)] -pub struct SBIRet{ +pub struct SBIRet { error: isize, - value: usize + value: usize, } #[derive(Clone, Copy, Debug)] -pub struct SBICall{ +pub struct SBICall { eid: usize, - fid: usize + fid: usize, } #[inline(always)] fn sbi_call(which: SBICall, arg0: usize, arg1: usize, arg2: usize) -> SBIRet { @@ -22,25 +22,47 @@ fn sbi_call(which: SBICall, arg0: usize, arg1: usize, arg2: usize) -> SBIRet { : "memory" : "volatile"); } - SBIRet{ + SBIRet { error: ret1, - value: ret2 + value: ret2, } } -pub fn sbi_hart_start(hartid: usize, start_addr: usize, opaque: usize)->SBIRet{ - sbi_call(SBICall{eid: SBI_EID_HSM, fid: SBI_FID_HSM_START}, hartid, start_addr as usize, opaque) +pub fn sbi_hart_start(hartid: usize, start_addr: usize, opaque: usize) -> SBIRet { + sbi_call( + SBICall { + eid: SBI_EID_HSM, + fid: SBI_FID_HSM_START, + }, + hartid, + start_addr as usize, + opaque, + ) } -pub fn sbi_hart_stop()->!{ - sbi_call(SBICall{eid: SBI_EID_HSM, fid: SBI_FID_HSM_STOP}, 0, 0, 0); +pub fn sbi_hart_stop() -> ! { + sbi_call( + SBICall { + eid: SBI_EID_HSM, + fid: SBI_FID_HSM_STOP, + }, + 0, + 0, + 0, + ); unreachable!(); } -pub fn sbi_hart_get_status(hartid: usize)->SBIRet{ - sbi_call(SBICall{eid: SBI_EID_HSM, fid: SBI_FID_HSM_START}, hartid, 0, 0) +pub fn sbi_hart_get_status(hartid: usize) -> SBIRet { + sbi_call( + SBICall { + eid: SBI_EID_HSM, + fid: SBI_FID_HSM_START, + }, + hartid, + 0, + 0, + ) } - - const SBI_SUCCESS: isize = 0; const SBI_ERR_FAILED: isize = -1; const SBI_ERR_NOT_SUPPORTED: isize = -2; @@ -56,7 +78,6 @@ const SBI_FID_HSM_STATUS: usize = 2; /// Legacy calls. - #[inline(always)] fn sbi_call_legacy(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize { let ret;