Skip to content

Commit

Permalink
examples: add initial video buffer no-std demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Jan 16, 2025
1 parent 3c4d00c commit d06102e
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ 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"

# 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"
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 -p example-root-vbuf-demo"
8 changes: 8 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 @@ -36,6 +36,7 @@ members = [
"examples/no-std/noop",
"examples/no-std/spin",
"examples/no-std/hello-world",
"examples/no-std/root-vbuf-demo",
"examples/std/noop",
"examples/std/noop-nightly",
"examples/std/spin",
Expand Down
17 changes: 17 additions & 0 deletions examples/no-std/root-vbuf-demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "example-root-vbuf-demo"
description = "Example module that shows how to work with the ROOT_BOOT_VBUF_V0 interface."
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/root-vbuf-demo/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
::oro::build();
}
100 changes: 100 additions & 0 deletions examples/no-std/root-vbuf-demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#![no_std]
#![no_main]

use oro::{
id::kernel::iface::{ROOT_BOOT_VBUF_V0, ROOT_DEBUG_OUT_V0},
syscall,
};

fn write_bytes(bytes: &[u8]) {
if bytes.len() == 0 {
return;
}

for chunk in bytes.chunks(8) {
let mut word = 0u64;
for b in chunk {
word = (word << 8) | *b as u64;
}

// XXX(qix-): Hard coding the ID for a moment, bear with.
syscall::set!(
ROOT_DEBUG_OUT_V0,
4294967296,
0,
syscall::key!("write"),
word
)
.unwrap();
}
}

fn write_str(s: &str) {
write_bytes(s.as_bytes());
}

struct Vbuf {
width: u64,
height: u64,
stride: u64,
bits_per_pixel: u64,
data: *mut u8,
}

fn find_video_buffer(idx: u64) -> Result<Vbuf, (oro::sysabi::syscall::Error, u64)> {
macro_rules! get_vbuf_field {
($field:literal) => {{
syscall::get!(
ROOT_BOOT_VBUF_V0,
// XXX(qix-): Hardcoding the ID for now, bear with.
4294967297,
idx,
syscall::key!($field),
)?
}};
}

let vbuf_addr: u64 = 0x60000000000 + (idx as u64) * 0x100000000;

Ok(Vbuf {
width: get_vbuf_field!("width"),
height: get_vbuf_field!("height"),
stride: get_vbuf_field!("pitch"),
bits_per_pixel: get_vbuf_field!("bit_pp"),
data: {
syscall::set!(
ROOT_BOOT_VBUF_V0,
// XXX(qix-): Hardcoding the ID for now, bear with.
4294967297,
idx,
syscall::key!("!vmbase!"),
vbuf_addr
)?;

vbuf_addr as *mut u8
},
})
}

#[no_mangle]
fn main() {
write_str("looking for vbuf 0...\n");
if let Ok(vbuf) = find_video_buffer(0) {
write_str("found vbuf 0\n");
let bytes_per_pixel = vbuf.bits_per_pixel / 8;
for y in 0..vbuf.height {
for x in 0..(vbuf.width * bytes_per_pixel) {
unsafe {
*vbuf.data.offset(((y * vbuf.stride) + x) as isize) =
if (((x + y) % 5) as u8) == 0 {
0xFF
} else {
0x00
};
}
}
}
} else {
write_str("failed to find vbuf 0\n");
}
}

0 comments on commit d06102e

Please sign in to comment.