-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add initial video buffer no-std demo
- Loading branch information
Showing
6 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
::oro::build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |