diff --git a/src/crt.rs b/src/crt.rs index c890166..a7db4ad 100644 --- a/src/crt.rs +++ b/src/crt.rs @@ -1,5 +1,6 @@ #[no_mangle] pub extern "C" fn strcmp(first: *const u8, second: *const u8) -> bool { + print("crt::strcmp"); todo!() } @@ -50,40 +51,60 @@ pub extern "C" fn truncf(f: f32) -> f32 { #[no_mangle] pub extern "C" fn trunc(f: f64) -> f64 { + print("crt::trunc"); todo!() } #[no_mangle] pub extern "C" fn sqrtf(f: f32) -> f32 { + print("crt::sqrtf"); todo!() } #[no_mangle] pub extern "C" fn sqrt(f: f64) -> f64 { + print("crt::sqrt"); todo!() } #[no_mangle] pub extern "C" fn rintf(f: f32) -> f32 { + print("crt::rintf"); todo!() } #[no_mangle] pub extern "C" fn rint(f: f64) -> f64 { + print("crt::rint"); todo!() } #[no_mangle] pub extern "C" fn __popcountdi2(num: u32) -> u32 { + print("crt::popcount"); todo!() } #[no_mangle] pub extern "C" fn abort() { + print("crt::abort"); todo!() } #[no_mangle] -pub extern "C" fn vsnprintf(buffer: *mut u8, count: usize, format: *const u8, args: *const u8 /* TODO: va_list */) -> f64 { +pub extern "C" fn vsnprintf(buffer: *mut u8, count: usize, format: *const u8, args: *const u8 /* TODO: va_list */) -> u32 { + print("crt::vsnprinf"); todo!() } + +fn print(s: &str) { + for c in s.as_bytes() { + outb(42, *c); + } +} + +fn outb(_port: u8, value: u8) { + unsafe { + asm!("out 42, al", /* in(reg_byte) port, */ in("al") value); + } +} diff --git a/src/main.rs b/src/main.rs index 4715dcc..98deefe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,13 @@ #![feature(alloc_error_handler)] #![feature(asm)] +#![feature(fmt_internals)] + extern crate alloc; -use core::panic::PanicInfo; +use core::{ops::Add, panic::PanicInfo}; + +use alloc::{borrow::ToOwned, format}; // use wasm3::Environment; // use wasm3::Module; @@ -37,6 +41,32 @@ pub extern "C" fn _start() -> ! { allocator::init(); print("Inited allocator\r\n"); + let mut s = "foo\r\n".to_owned(); + s.make_ascii_uppercase(); + let s1 = s.add("bar\r\n"); + print(&s1); + + let t = "arse\r\n"; + // let t1 = format!("{}:{}", s1, t); + + print("ARGING ALL THE THINGS\r\n"); + + let s1_ = ::core::fmt::ArgumentV1::new(&s1, ::core::fmt::Display::fmt); + print("made first args arg\r\n"); + let t_ = ::core::fmt::ArgumentV1::new(&t, ::core::fmt::Display::fmt); + print("made args args\r\n"); + + let slicey = [s1_, t_]; + + let fmtargs = ::core::fmt::Arguments::new_v1(&["", ":"], &slicey); + print("made args struct\r\n"); + + print("CALLING FORMAT\r\n"); + let t1 = ::alloc::fmt::format(fmtargs); + + print("PRINTING THE THING\r\n"); + print(&t1); + // let env = Environment::new() // .expect("Unable to create environment"); // let rt = env