Skip to content

Commit

Permalink
debug fs
Browse files Browse the repository at this point in the history
  • Loading branch information
buhe committed Nov 23, 2021
1 parent 1d933f9 commit 38b3c1a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
11 changes: 10 additions & 1 deletion os/src/mmu/address.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use crate::config::{PAGE_SIZE, PAGE_SIZE_BITS};

use super::PageTableEntry;
use core::fmt::{self, Debug, Formatter};

/// Definitions
#[repr(C)]
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct PhysAddr(pub usize);

#[repr(C)]
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct VirtAddr(pub usize);

#[repr(C)]
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct PhysPageNum(pub usize);

#[repr(C)]
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct VirtPageNum(pub usize);

Expand Down Expand Up @@ -181,6 +184,12 @@ impl StepByOne for VirtPageNum {
}
}

impl StepByOne for PhysPageNum {
fn step(&mut self) {
self.0 += 1;
}
}

#[derive(Copy, Clone)]
pub struct SimpleRange<T>
where
Expand Down
1 change: 1 addition & 0 deletions os/src/mmu/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl PageTableEntry {
}
}

#[derive(Debug)]
pub struct PageTable {
root_ppn: PhysPageNum,
frames: Vec<FrameTracker>,
Expand Down
1 change: 1 addition & 0 deletions user/src/bin/initproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use user::{
#[no_mangle]
fn main() -> i32 {
if fork() == 0 {
// child process
exec("user_shell\0");
} else {
loop {
Expand Down
27 changes: 2 additions & 25 deletions user/src/bin/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,9 @@

#[macro_use]
extern crate user;
extern crate alloc;

use user::{
open,
OpenFlags,
close,
read,
};
use alloc::string::String;

#[no_mangle]
pub fn main(argc: usize, argv: &[&str]) -> i32 {
assert!(argc == 2);
let fd = open(argv[1], OpenFlags::RDONLY);
if fd == -1 {
panic!("Error occured when opening file");
}
let fd = fd as usize;
let mut buf = [0u8; 16];
let mut s = String::new();
loop {
let size = read(fd, &mut buf) as usize;
if size == 0 { break; }
s.push_str(core::str::from_utf8(&buf[..size]).unwrap());
}
println!("{}", s);
close(fd);
pub fn main() -> i32 {
println!("Hello OS from app@v-mem");
0
}

0 comments on commit 38b3c1a

Please sign in to comment.