good luck able #17

Merged
able merged 15 commits from koniifer/ableos:master into master 2024-09-14 11:44:13 -05:00
5 changed files with 40 additions and 7 deletions
Showing only changes of commit 12ee3a9b87 - Show all commits

View file

@ -226,6 +226,33 @@ pub fn hardware_random_u64() -> u64 {
}
}
pub fn hardware_random_u32() -> u32 {
use {log::trace, rdrand::RdRand};
let gen = RdRand::new();
match gen {
Ok(gen) => {
let ret = gen.try_next_u32().unwrap();
trace!("Random {}", ret);
return ret;
}
Err(err) => {
warn!("RDRand not supported.");
// Try rdseed
let gen = RdSeed::new();
match gen {
Ok(gen) => {
let ret = gen.try_next_u32().unwrap();
trace!("Random {}", ret);
return ret;
}
Err(err) => {
panic!("Neither RDRand or RDSeed are supported")
}
}
}
}
}
pub fn get_edid() {}
pub fn register_dump() {

View file

@ -133,7 +133,7 @@ pub fn handler(vm: &mut Vm) {
}
// source of rng
4 => {
vm.registers[1] = hbvm::value::Value(crate::arch::hardware_random_u64());
vm.registers[1] = hbvm::value::Value(crate::arch::hardware_random_u32() as u64);
}
buffer_id => {
let mut buffs = IPC_BUFFERS.lock();

View file

@ -1,7 +1,14 @@
SIZEOF_INT := 31
abs := fn(x: int): int {
mask := x >> 31
mask := x >> SIZEOF_INT
return (x ^ mask) - mask
}
min := fn(a: int, b: int): int {
return b + (a - b & a - b >> 31)
c := a - b
return b + (c & c >> SIZEOF_INT)
}
max := fn(a: int, b: int): int {
c := a - b
return a - (c & c >> SIZEOF_INT)
}

View file

@ -1,5 +1,5 @@
uint_64 := fn(min: uint, max: uint): uint {
rng := @eca(uint, 3, 4)
integer := fn(min: int, max: int): int {
rng := @eca(int, 3, 4)
if min != 0 | max != 0 {
return rng % (max - min + 1) + min

View file

@ -1,5 +1,4 @@
.{log, memory, string, buffer} := @use("../../../libraries/stn/src/lib.hb");
.{front_buffer_ptr, screenidx, ColorBGRA, Point} := @use("./lib.hb")
.{log, memory, string, buffer} := @use("../../../libraries/stn/src/lib.hb")
main := fn(): int {
buffer_id := buffer.create("XGraphics\0")