FINALLY PAGING AND HEAP WORK WITH REALLY BAD CODE

This commit is contained in:
Bryan McShea
2024-01-28 19:11:27 -05:00
parent 260c5c223a
commit f9e7f85a8c
15 changed files with 472 additions and 274 deletions
+46
View File
@@ -0,0 +1,46 @@
use core::mem::transmute;
macro_rules! get_bits {
($name:ident[$high:expr,$low:expr]) => {{
($name & ((($name - $name + 2).pow($high - $low + 1) - 1) << $low)) >> $low
}};
}
pub(crate) use get_bits;
pub trait BeRep {
fn _from_be(&self) -> Self;
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Be<T: BeRep>(T);
impl<T: BeRep> Be<T> {
pub fn get(&self) -> T {
self.0._from_be()
}
}
impl BeRep for u32 {
fn _from_be(&self) -> Self {
self.to_be()
}
}
impl BeRep for u64 {
fn _from_be(&self) -> Self {
self.to_be()
}
}
impl BeRep for usize {
fn _from_be(&self) -> Self {
self.to_be()
}
}
pub fn u32_from_bytes(bytes: &[u8]) -> Option<u32> {
if bytes.len() < 4 {
return None;
}
unsafe { Some(transmute([bytes[0], bytes[1], bytes[2], bytes[3]])) }
}
+1
View File
@@ -0,0 +1 @@
pub mod bits;