#[repr(C)]
pub struct Header {
marker_start: u32,
entries_start: *const EntryAddr,
entries_end: *const EntryAddr,
mapping_table: *const MappingTableEntry,
marker_end: u32,
}
impl Header {
const MARKER_START: u32 = 0x7188ebf2;
const MARKER_END: u32 = 0xe71aa390;
pub const fn new(
entries_start: *const EntryAddr,
entries_end: *const EntryAddr,
mapping_table: &'static [MappingTableEntry],
) -> Self {
let mapping_table = mapping_table.as_ptr();
Self {
marker_start: Self::MARKER_START,
entries_start,
entries_end,
mapping_table,
marker_end: Self::MARKER_END,
}
}
}
unsafe impl Sync for Header {}
#[repr(transparent)]
pub struct EntryAddr(*const u32);
unsafe impl Sync for EntryAddr {}
#[repr(C)]
pub struct MappingTableEntry {
pub source_addr_start: *const u32,
pub dest_addr_start: *const u32,
pub dest_addr_end: *const u32,
}
impl MappingTableEntry {
pub const fn null() -> MappingTableEntry {
MappingTableEntry {
source_addr_start: core::ptr::null(),
dest_addr_start: core::ptr::null(),
dest_addr_end: core::ptr::null(),
}
}
}
unsafe impl Sync for MappingTableEntry {}
#[repr(u16)]
pub enum DataType {
Raw = 1,
SizedData = 2,
BinaryInfoListZeroTerminated = 3,
Bson = 4,
IdAndInt = 5,
IdAndString = 6,
BlockDevice = 7,
PinsWithFunction = 8,
PinsWithName = 9,
PinsWithNames = 10,
}
#[repr(C)]
struct EntryCommon {
data_type: DataType,
tag: u16,
}
#[repr(C)]
pub struct StringEntry {
header: EntryCommon,
id: u32,
value: *const core::ffi::c_char,
}
impl StringEntry {
pub const fn new(tag: u16, id: u32, value: &'static core::ffi::CStr) -> StringEntry {
StringEntry {
header: EntryCommon {
data_type: DataType::IdAndString,
tag,
},
id,
value: value.as_ptr(),
}
}
pub const fn addr(&self) -> EntryAddr {
EntryAddr(self as *const Self as *const u32)
}
}
unsafe impl Sync for StringEntry {}
#[repr(C)]
pub struct IntegerEntry {
header: EntryCommon,
id: u32,
value: u32,
}
impl IntegerEntry {
pub const fn new(tag: u16, id: u32, value: u32) -> IntegerEntry {
IntegerEntry {
header: EntryCommon {
data_type: DataType::IdAndInt,
tag,
},
id,
value,
}
}
pub const fn addr(&self) -> EntryAddr {
EntryAddr(self as *const Self as *const u32)
}
}
#[repr(C)]
pub struct PointerEntry {
header: EntryCommon,
id: u32,
value: *const (),
}
impl PointerEntry {
pub const fn new(tag: u16, id: u32, value: *const ()) -> PointerEntry {
PointerEntry {
header: EntryCommon {
data_type: DataType::IdAndInt,
tag,
},
id,
value,
}
}
pub const fn addr(&self) -> EntryAddr {
EntryAddr(self as *const Self as *const u32)
}
}
unsafe impl Sync for PointerEntry {}