Skip to content

Commit

Permalink
Merge pull request #185 from rcore-os/simple-vmo
Browse files Browse the repository at this point in the history
Minor refactor VMO
  • Loading branch information
benpigchu authored Apr 5, 2021
2 parents 58e4f6b + 1207746 commit 9290158
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 288 deletions.
19 changes: 9 additions & 10 deletions kernel-hal-bare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ pub fn pmem_write(paddr: PhysAddr, buf: &[u8]) {
}
}

/// Zero physical memory at `[paddr, paddr + len)`
#[export_name = "hal_pmem_zero"]
pub fn pmem_zero(paddr: PhysAddr, len: usize) {
trace!("pmem_zero: addr={:#x}, len={:#x}", paddr, len);
unsafe {
core::ptr::write_bytes(phys_to_virt(paddr) as *mut u8, 0, len);
}
}

/// Copy content of `src` frame to `target` frame
#[export_name = "hal_frame_copy"]
pub fn frame_copy(src: PhysAddr, target: PhysAddr) {
Expand All @@ -166,16 +175,6 @@ pub fn frame_copy(src: PhysAddr, target: PhysAddr) {
}
}

/// Zero `target` frame.
#[export_name = "hal_frame_zero"]
pub fn frame_zero_in_range(target: PhysAddr, start: usize, end: usize) {
assert!(start < PAGE_SIZE && end <= PAGE_SIZE);
trace!("frame_zero: {:#x}", target);
unsafe {
core::ptr::write_bytes(phys_to_virt(target + start) as *mut u8, 0, end - start);
}
}

lazy_static! {
pub static ref NAIVE_TIMER: Mutex<Timer> = Mutex::new(Timer::default());
}
Expand Down
22 changes: 11 additions & 11 deletions kernel-hal-unix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ pub fn pmem_write(paddr: PhysAddr, buf: &[u8]) {
}
}

/// Zero physical memory at `[paddr, paddr + len)`
#[export_name = "hal_pmem_zero"]
pub fn pmem_zero(paddr: PhysAddr, len: usize) {
trace!("pmem_zero: addr={:#x}, len={:#x}", paddr, len);
assert!(paddr + len <= PMEM_SIZE);
ensure_mmap_pmem();
unsafe {
core::ptr::write_bytes(phys_to_virt(paddr) as *mut u8, 0, len);
}
}

/// Copy content of `src` frame to `target` frame
#[export_name = "hal_frame_copy"]
pub fn frame_copy(src: PhysAddr, target: PhysAddr) {
Expand All @@ -224,17 +235,6 @@ pub fn frame_copy(src: PhysAddr, target: PhysAddr) {
}
}

/// Zero `target` frame.
#[export_name = "hal_frame_zero"]
pub fn frame_zero(target: PhysAddr) {
trace!("frame_zero: {:#x}", target);
assert!(target + PAGE_SIZE < PMEM_SIZE);
ensure_mmap_pmem();
unsafe {
core::ptr::write_bytes(phys_to_virt(target) as *mut u8, 0, PAGE_SIZE);
}
}

/// Flush the physical frame.
#[export_name = "hal_frame_flush"]
pub fn frame_flush(_target: PhysAddr) {
Expand Down
12 changes: 6 additions & 6 deletions kernel-hal/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ pub fn pmem_write(_paddr: PhysAddr, _buf: &[u8]) {
unimplemented!()
}

/// Copy content of `src` frame to `target` frame.
/// Zero physical memory at `[paddr, paddr + len)`
#[linkage = "weak"]
#[export_name = "hal_frame_copy"]
pub fn frame_copy(_src: PhysAddr, _target: PhysAddr) {
#[export_name = "hal_pmem_zero"]
pub fn pmem_zero(_paddr: PhysAddr, _len: usize) {
unimplemented!()
}

/// Zero `target` frame.
/// Copy content of `src` frame to `target` frame.
#[linkage = "weak"]
#[export_name = "hal_frame_zero"]
pub fn frame_zero_in_range(_target: PhysAddr, _start: usize, _end: usize) {
#[export_name = "hal_frame_copy"]
pub fn frame_copy(_src: PhysAddr, _target: PhysAddr) {
unimplemented!()
}

Expand Down
Loading

0 comments on commit 9290158

Please sign in to comment.