Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arceos/modules/axhal/src/arch/riscv/context.rs
Original file line number Diff line number Diff line change
@@ -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!();

Expand Down
6 changes: 3 additions & 3 deletions arceos/modules/axhal/src/misc.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
pub use super::platform::misc::*;

use kspin::SpinNoIrq;
use crate::time;
use kspin::SpinNoIrq;

static PARK_MILLER_LEHMER_SEED: SpinNoIrq<u32> = 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
Expand Down
6 changes: 3 additions & 3 deletions arceos/modules/axmm/src/aspace.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions arceos/payload/skernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
30 changes: 18 additions & 12 deletions arceos/tour/h_1_0/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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()
Expand All @@ -56,9 +63,8 @@ fn main() {
let ept_root = uspace.page_table_root();
let mut ctx = VmCpuRegisters::default();
// Set hstatus
let mut hstatus = LocalRegisterCopy::<usize, hstatus::Register>::new(
riscv::register::hstatus::read().bits(),
);
let mut hstatus =
LocalRegisterCopy::<usize, hstatus::Register>::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);
Expand Down
7 changes: 2 additions & 5 deletions arceos/tour/h_1_0/src/task.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,10 +15,7 @@ pub struct TaskExt {

impl TaskExt {
pub const fn new(vcpu: VmCpuRegisters, aspace: Arc<Mutex<AddrSpace>>) -> Self {
Self {
vcpu,
aspace,
}
Self { vcpu, aspace }
}
}

Expand Down
2 changes: 1 addition & 1 deletion arceos/tour/h_1_0/src/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub struct RISCVVCpu {
regs: VmCpuRegisters,
}

/*
/*
impl RISCVVCpu {
type CreateConfig = ();

Expand Down
35 changes: 22 additions & 13 deletions arceos/tour/m_1_0/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion arceos/tour/m_1_0/src/syscall.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
37 changes: 23 additions & 14 deletions arceos/tour/m_2_0/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion arceos/tour/m_2_0/src/syscall.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 2 additions & 4 deletions arceos/tour/u_4_0/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<u32, [u8; 4]>(*ptr)
};
let magic = unsafe { mem::transmute::<u32, [u8; 4]>(*ptr) };
if let Ok(s) = str::from_utf8(&magic) {
println!("Got pflash magic: {s}");
0
Expand Down
4 changes: 2 additions & 2 deletions arceos/tour/u_5_0/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions arceos/tour/u_6_0/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions arceos/tour/u_6_1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 7 additions & 8 deletions arceos/tour/u_7_0/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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!");
});
Expand Down
Loading