Cleanup some

This commit is contained in:
Jeremy Soller
2017-04-03 21:16:50 -06:00
parent be7f8d64e6
commit ff93e9cb82
14 changed files with 308 additions and 336 deletions
+70
View File
@@ -0,0 +1,70 @@
/// Memcpy
///
/// Copy N bytes of memory from one location to another.
#[no_mangle]
pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8,
n: usize) -> *mut u8 {
let mut i = 0;
while i < n {
*((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
i += 1;
}
dest
}
/// Memmove
///
/// Copy N bytes of memory from src to dest. The memory areas may overlap.
#[no_mangle]
pub unsafe extern fn memmove(dest: *mut u8, src: *const u8,
n: usize) -> *mut u8 {
if src < dest as *const u8 {
let mut i = n;
while i != 0 {
i -= 1;
*((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
}
} else {
let mut i = 0;
while i < n {
*((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8);
i += 1;
}
}
dest
}
/// Memset
///
/// Fill a block of memory with a specified value.
#[no_mangle]
pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 {
let mut i = 0;
while i < n {
*((dest as usize + i) as *mut u8) = c as u8;
i += 1;
}
dest
}
/// Memcmp
///
/// Compare two blocks of memory.
#[no_mangle]
pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
let mut i = 0;
while i < n {
let a = *((s1 as usize + i) as *const u8);
let b = *((s2 as usize + i) as *const u8);
if a != b {
return a as i32 - b as i32
}
i += 1;
}
0
}
+4 -9
View File
@@ -54,6 +54,9 @@ pub mod context;
/// ELF file parsing
pub mod elf;
/// External functions
pub mod externs;
/// Schemes, filesystem handlers
pub mod scheme;
@@ -150,14 +153,7 @@ pub extern fn kmain(cpus: usize) {
/// This is the main kernel entry point for secondary CPUs
#[no_mangle]
pub extern fn kmain_ap(_id: usize) {
// Disable APs for now
loop {
unsafe { interrupt::disable(); }
unsafe { interrupt::halt(); }
}
/*
pub extern fn kmain_ap(id: usize) {
CPU_ID.store(id, Ordering::SeqCst);
context::init();
@@ -176,5 +172,4 @@ pub extern fn kmain_ap(_id: usize) {
}
}
}
*/
}
+2 -2
View File
@@ -7,7 +7,7 @@ use core::ops::DerefMut;
use spin::Mutex;
use arch;
use arch::memory::allocate_frame;
use arch::memory::allocate_frames;
use arch::paging::{ActivePageTable, InactivePageTable, Page, VirtualAddress, entry};
use arch::paging::temporary_page::TemporaryPage;
use arch::start::usermode;
@@ -324,7 +324,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> {
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(arch::USER_TMP_MISC_OFFSET)));
let mut new_table = {
let frame = allocate_frame().expect("no more frames in syscall::clone new_table");
let frame = allocate_frames(1).expect("no more frames in syscall::clone new_table");
InactivePageTable::new(frame, &mut active_table, &mut temporary_page)
};