c test program

This commit is contained in:
nora 2023-09-30 10:54:59 +02:00
parent 54e0e7604e
commit 1baf8df4a8
18 changed files with 150 additions and 68 deletions

13
rawc/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "rawc"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["staticlib", "rlib"]
[dependencies]
libuwuc = { path = "../libuwuc" }

25
rawc/src/lib.rs Normal file
View file

@ -0,0 +1,25 @@
#![no_std]
#![feature(panic_info_message)]
mod stdio;
mod string;
// libcore seems to require this symbol, even though it's unused.
#[no_mangle]
fn rust_eh_personality() {
unsafe {
libuwuc::trap!();
}
}
#[panic_handler]
#[cfg(not(test))]
fn handler(arg: &core::panic::PanicInfo) -> ! {
let args = format_args!("<no message>");
let payload = arg.message().unwrap_or(&args);
libuwuc::io::println!("panicked: {payload}");
if let Some(loc) = arg.location() {
libuwuc::io::println!(" at {}:{}:{}", loc.file(), loc.line(), loc.column());
}
libuwuc::start::exit(1);
}

6
rawc/src/stdio.rs Normal file
View file

@ -0,0 +1,6 @@
use core::ffi::c_char;
#[no_mangle]
pub unsafe extern "C" fn puts(s: *const c_char) -> i32 {
libuwuc::io::puts(s)
}

25
rawc/src/string.rs Normal file
View file

@ -0,0 +1,25 @@
#[no_mangle]
pub unsafe extern "C" fn memset(ptr: *mut u8, constant: u8, len: usize) {
libuwuc::mem::memset(ptr, constant, len)
}
#[no_mangle]
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, size: usize) -> *mut u8 {
libuwuc::mem::memcpy(dest, src, size)
}
#[no_mangle]
pub unsafe fn memcmp(s1: *const u8, s2: *const u8, size: usize) -> i32 {
libuwuc::mem::memcmp(s1, s2, size)
}
#[no_mangle]
pub unsafe fn bcmp(s1: *const u8, s2: *const u8, size: usize) -> i32 {
libuwuc::mem::memcmp(s1, s2, size)
}
#[no_mangle]
pub unsafe extern "C" fn strlen(s: *const u8) -> usize {
libuwuc::mem::strlen(s)
}