mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-28 11:53:24 +00:00
Update the 100-line kernel and format it as well
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
71a486b9a5
commit
20524ae64a
@ -13,7 +13,8 @@ use alloc::vec;
|
|||||||
use ostd::arch::qemu::{exit_qemu, QemuExitCode};
|
use ostd::arch::qemu::{exit_qemu, QemuExitCode};
|
||||||
use ostd::cpu::UserContext;
|
use ostd::cpu::UserContext;
|
||||||
use ostd::mm::{
|
use ostd::mm::{
|
||||||
FrameAllocOptions, PageFlags, Vaddr, VmIo, VmMapOptions, VmSpace, VmWriter, PAGE_SIZE,
|
CachePolicy, FrameAllocOptions, PageFlags, PageProperty, Vaddr, VmIo, VmSpace, VmWriter,
|
||||||
|
PAGE_SIZE,
|
||||||
};
|
};
|
||||||
use ostd::prelude::*;
|
use ostd::prelude::*;
|
||||||
use ostd::task::{Task, TaskOptions};
|
use ostd::task::{Task, TaskOptions};
|
||||||
@ -32,8 +33,8 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_user_space(program: &[u8]) -> UserSpace {
|
fn create_user_space(program: &[u8]) -> UserSpace {
|
||||||
let user_pages = {
|
|
||||||
let nframes = program.len().align_up(PAGE_SIZE) / PAGE_SIZE;
|
let nframes = program.len().align_up(PAGE_SIZE) / PAGE_SIZE;
|
||||||
|
let user_pages = {
|
||||||
let vm_frames = FrameAllocOptions::new(nframes).alloc().unwrap();
|
let vm_frames = FrameAllocOptions::new(nframes).alloc().unwrap();
|
||||||
// Phyiscal memory pages can be only accessed
|
// Phyiscal memory pages can be only accessed
|
||||||
// via the Frame abstraction.
|
// via the Frame abstraction.
|
||||||
@ -45,11 +46,15 @@ fn create_user_space(program: &[u8]) -> UserSpace {
|
|||||||
|
|
||||||
// The page table of the user space can be
|
// The page table of the user space can be
|
||||||
// created and manipulated safely through
|
// created and manipulated safely through
|
||||||
// the VmSpace abstraction.
|
// the `VmSpace` abstraction.
|
||||||
let vm_space = VmSpace::new();
|
let vm_space = VmSpace::new();
|
||||||
let mut options = VmMapOptions::new();
|
let mut cursor = vm_space
|
||||||
options.addr(Some(MAP_ADDR)).flags(PageFlags::RWX);
|
.cursor_mut(&(MAP_ADDR..MAP_ADDR + nframes * PAGE_SIZE))
|
||||||
vm_space.map(user_pages, &options).unwrap();
|
.unwrap();
|
||||||
|
let map_prop = PageProperty::new(PageFlags::RWX, CachePolicy::Writeback);
|
||||||
|
for frame in user_pages {
|
||||||
|
cursor.map(frame, map_prop);
|
||||||
|
}
|
||||||
Arc::new(vm_space)
|
Arc::new(vm_space)
|
||||||
};
|
};
|
||||||
let user_cpu_state = {
|
let user_cpu_state = {
|
||||||
|
@ -29,6 +29,14 @@ else
|
|||||||
cargo fmt
|
cargo fmt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Format the 100-line kernel demo as well
|
||||||
|
KERNEL_DEMO_FILE="$WORKSPACE_ROOT/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs"
|
||||||
|
if [ "$CHECK_MODE" = true ]; then
|
||||||
|
cargo fmt --check -- $KERNEL_DEMO_FILE
|
||||||
|
else
|
||||||
|
cargo fmt -- $KERNEL_DEMO_FILE
|
||||||
|
fi
|
||||||
|
|
||||||
for CRATE in $EXCLUDED_CRATES; do
|
for CRATE in $EXCLUDED_CRATES; do
|
||||||
CRATE_DIR="$WORKSPACE_ROOT/$CRATE"
|
CRATE_DIR="$WORKSPACE_ROOT/$CRATE"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user