diff --git a/.cargo/config.toml b/.cargo/config.toml index 344dc29..1b4049f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -21,4 +21,5 @@ oro-ra-x86_64 = "check --quiet --message-format=json --keep-going --target ./oro oro-ra-aarch64 = "check --quiet --message-format=json --keep-going --target ./oro-arch-aarch64/aarch64-unknown-oro.json --bin oro-kernel-aarch64 --bin oro-limine-aarch64 -Zunstable-options -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem" -oro-examples = "build --target=x86_64-unknown-none --target=aarch64-unknown-none -p example-noop -p example-spin -p example-std-noop -p example-std-noop-nightly -p example-std-spin" +# NOTE: Does not need the unstable flags / building std / etc. +oro-examples = "build --target=x86_64-unknown-none --target=aarch64-unknown-none -p example-noop -p example-spin -p example-std-noop -p example-std-noop-nightly -p example-std-spin -p example-hello-world" diff --git a/Cargo.lock b/Cargo.lock index 70e112c..9a13c55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,6 +110,13 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "example-hello-world" +version = "0.0.0" +dependencies = [ + "oro", +] + [[package]] name = "example-noop" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 6708051..d6835c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ members = [ # Examples "examples/no-std/noop", "examples/no-std/spin", + "examples/no-std/hello-world", "examples/std/noop", "examples/std/noop-nightly", "examples/std/spin", diff --git a/examples/no-std/hello-world/Cargo.toml b/examples/no-std/hello-world/Cargo.toml new file mode 100644 index 0000000..78120ec --- /dev/null +++ b/examples/no-std/hello-world/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "example-hello-world" +description = "Example module that prints Hello World to the kernel logger." +version = "0.0.0" +publish = false +edition = "2021" + +build = "build.rs" + +[dependencies.oro] +path = "../../../oro" +features = ["runtime"] + +[build-dependencies.oro] +path = "../../../oro" +features = ["build"] +default-features = false diff --git a/examples/no-std/hello-world/build.rs b/examples/no-std/hello-world/build.rs new file mode 100644 index 0000000..c43c5af --- /dev/null +++ b/examples/no-std/hello-world/build.rs @@ -0,0 +1,3 @@ +fn main() { + ::oro::build(); +} diff --git a/examples/no-std/hello-world/src/main.rs b/examples/no-std/hello-world/src/main.rs new file mode 100644 index 0000000..d328714 --- /dev/null +++ b/examples/no-std/hello-world/src/main.rs @@ -0,0 +1,51 @@ +#![no_std] +#![no_main] + +use oro::{id::kernel::iface::ROOT_DEBUG_OUT_V0, syscall}; + +fn write_bytes(bytes: &[u8]) { + if bytes.len() == 0 { + return; + } + + let mut word = bytes[0] as u64; + + for i in 1..bytes.len() { + if i % 8 == 0 { + // XXX(qix-): Hard coding the ID for a moment, bear with. + syscall::set!( + ROOT_DEBUG_OUT_V0, + 4294967296, + 0, + syscall::key!("write"), + word + ) + .unwrap(); + word = 0; + } + + word = (word << 8) | bytes[i] as u64; + } + + if bytes.len() % 8 != 0 { + // Shift it the remaining bits. + word <<= 8 * (8 - (bytes.len() % 8)); + syscall::set!( + ROOT_DEBUG_OUT_V0, + 4294967296, + 0, + syscall::key!("write"), + word + ) + .unwrap(); + } +} + +fn write_str(s: &str) { + write_bytes(s.as_bytes()); +} + +#[no_mangle] +fn main() { + write_str("Hello, Oro!\n"); +}