diff --git a/src/lib.rs b/src/lib.rs index 36f0969..79dcdf6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] +mod nanolibc; mod sys; pub use sys::*; diff --git a/src/nanolibc.rs b/src/nanolibc.rs new file mode 100644 index 0000000..7993018 --- /dev/null +++ b/src/nanolibc.rs @@ -0,0 +1,33 @@ +#[no_mangle] +pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { + for i in 0..n { + *dest.add(i) = *src.add(i); + } + + dest +} + +#[no_mangle] +pub unsafe extern "C" fn memset(s: *mut u8, x: i32, n: usize) -> *mut u8 { + for i in 0..n { + *s.add(i) = x as u8; + } + + s +} + +#[no_mangle] +pub unsafe extern "C" fn memcmp(s1: *mut u8, s2: *const u8, n: usize) -> i32 { + for i in 0..n { + let x = *s1.add(i); + let y = *s2.add(i); + if x == y { + continue; + } + + let (x, y) = (i32::from(x), i32::from(y)); + return x - y; + } + + 0 +} diff --git a/src/syscalls.o b/src/syscalls.o deleted file mode 100644 index bb7de80..0000000 Binary files a/src/syscalls.o and /dev/null differ