Skip to content

Commit

Permalink
examples: add 'Hello World' no-std example
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Jan 16, 2025
1 parent af0b8fe commit dde7327
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions examples/no-std/hello-world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions examples/no-std/hello-world/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
::oro::build();
}
51 changes: 51 additions & 0 deletions examples/no-std/hello-world/src/main.rs
Original file line number Diff line number Diff line change
@@ -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");
}

0 comments on commit dde7327

Please sign in to comment.