Skip to content

Commit d06102e

Browse files
committed
examples: add initial video buffer no-std demo
1 parent 3c4d00c commit d06102e

File tree

6 files changed

+130
-1
lines changed

6 files changed

+130
-1
lines changed

.cargo/config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ oro-ra-x86_64 = "check --quiet --message-format=json --keep-going --target ./oro
2222
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"
2323

2424
# NOTE: Does not need the unstable flags / building std / etc.
25-
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"
25+
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"

Cargo.lock

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ members = [
3636
"examples/no-std/noop",
3737
"examples/no-std/spin",
3838
"examples/no-std/hello-world",
39+
"examples/no-std/root-vbuf-demo",
3940
"examples/std/noop",
4041
"examples/std/noop-nightly",
4142
"examples/std/spin",
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "example-root-vbuf-demo"
3+
description = "Example module that shows how to work with the ROOT_BOOT_VBUF_V0 interface."
4+
version = "0.0.0"
5+
publish = false
6+
edition = "2021"
7+
8+
build = "build.rs"
9+
10+
[dependencies.oro]
11+
path = "../../../oro"
12+
features = ["runtime"]
13+
14+
[build-dependencies.oro]
15+
path = "../../../oro"
16+
features = ["build"]
17+
default-features = false
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
::oro::build();
3+
}
+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
use oro::{
5+
id::kernel::iface::{ROOT_BOOT_VBUF_V0, ROOT_DEBUG_OUT_V0},
6+
syscall,
7+
};
8+
9+
fn write_bytes(bytes: &[u8]) {
10+
if bytes.len() == 0 {
11+
return;
12+
}
13+
14+
for chunk in bytes.chunks(8) {
15+
let mut word = 0u64;
16+
for b in chunk {
17+
word = (word << 8) | *b as u64;
18+
}
19+
20+
// XXX(qix-): Hard coding the ID for a moment, bear with.
21+
syscall::set!(
22+
ROOT_DEBUG_OUT_V0,
23+
4294967296,
24+
0,
25+
syscall::key!("write"),
26+
word
27+
)
28+
.unwrap();
29+
}
30+
}
31+
32+
fn write_str(s: &str) {
33+
write_bytes(s.as_bytes());
34+
}
35+
36+
struct Vbuf {
37+
width: u64,
38+
height: u64,
39+
stride: u64,
40+
bits_per_pixel: u64,
41+
data: *mut u8,
42+
}
43+
44+
fn find_video_buffer(idx: u64) -> Result<Vbuf, (oro::sysabi::syscall::Error, u64)> {
45+
macro_rules! get_vbuf_field {
46+
($field:literal) => {{
47+
syscall::get!(
48+
ROOT_BOOT_VBUF_V0,
49+
// XXX(qix-): Hardcoding the ID for now, bear with.
50+
4294967297,
51+
idx,
52+
syscall::key!($field),
53+
)?
54+
}};
55+
}
56+
57+
let vbuf_addr: u64 = 0x60000000000 + (idx as u64) * 0x100000000;
58+
59+
Ok(Vbuf {
60+
width: get_vbuf_field!("width"),
61+
height: get_vbuf_field!("height"),
62+
stride: get_vbuf_field!("pitch"),
63+
bits_per_pixel: get_vbuf_field!("bit_pp"),
64+
data: {
65+
syscall::set!(
66+
ROOT_BOOT_VBUF_V0,
67+
// XXX(qix-): Hardcoding the ID for now, bear with.
68+
4294967297,
69+
idx,
70+
syscall::key!("!vmbase!"),
71+
vbuf_addr
72+
)?;
73+
74+
vbuf_addr as *mut u8
75+
},
76+
})
77+
}
78+
79+
#[no_mangle]
80+
fn main() {
81+
write_str("looking for vbuf 0...\n");
82+
if let Ok(vbuf) = find_video_buffer(0) {
83+
write_str("found vbuf 0\n");
84+
let bytes_per_pixel = vbuf.bits_per_pixel / 8;
85+
for y in 0..vbuf.height {
86+
for x in 0..(vbuf.width * bytes_per_pixel) {
87+
unsafe {
88+
*vbuf.data.offset(((y * vbuf.stride) + x) as isize) =
89+
if (((x + y) % 5) as u8) == 0 {
90+
0xFF
91+
} else {
92+
0x00
93+
};
94+
}
95+
}
96+
}
97+
} else {
98+
write_str("failed to find vbuf 0\n");
99+
}
100+
}

0 commit comments

Comments
 (0)