use crate::TagType;
use crate::TagTypeId;
use core::convert::TryInto;
use core::mem::size_of;
#[cfg(feature = "builder")]
use crate::builder::traits::StructAsBytes;
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct EFISdt32Tag {
typ: TagTypeId,
size: u32,
pointer: u32,
}
impl EFISdt32Tag {
pub fn new(pointer: u32) -> Self {
Self {
typ: TagType::Efi32.into(),
size: size_of::<Self>().try_into().unwrap(),
pointer,
}
}
pub fn sdt_address(&self) -> usize {
self.pointer as usize
}
}
#[cfg(feature = "builder")]
impl StructAsBytes for EFISdt32Tag {
fn byte_size(&self) -> usize {
size_of::<Self>()
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct EFISdt64Tag {
typ: TagTypeId,
size: u32,
pointer: u64,
}
impl EFISdt64Tag {
pub fn new(pointer: u64) -> Self {
Self {
typ: TagType::Efi64.into(),
size: size_of::<Self>().try_into().unwrap(),
pointer,
}
}
pub fn sdt_address(&self) -> usize {
self.pointer as usize
}
}
#[cfg(feature = "builder")]
impl StructAsBytes for EFISdt64Tag {
fn byte_size(&self) -> usize {
size_of::<Self>()
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct EFIImageHandle32Tag {
typ: TagTypeId,
size: u32,
pointer: u32,
}
impl EFIImageHandle32Tag {
#[cfg(feature = "builder")]
pub fn new(pointer: u32) -> Self {
Self {
typ: TagType::Efi32Ih.into(),
size: size_of::<Self>().try_into().unwrap(),
pointer,
}
}
pub fn image_handle(&self) -> usize {
self.pointer as usize
}
}
#[cfg(feature = "builder")]
impl StructAsBytes for EFIImageHandle32Tag {
fn byte_size(&self) -> usize {
size_of::<Self>()
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct EFIImageHandle64Tag {
typ: TagTypeId,
size: u32,
pointer: u64,
}
impl EFIImageHandle64Tag {
#[cfg(feature = "builder")]
pub fn new(pointer: u64) -> Self {
Self {
typ: TagType::Efi64Ih.into(),
size: size_of::<Self>().try_into().unwrap(),
pointer,
}
}
pub fn image_handle(&self) -> usize {
self.pointer as usize
}
}
#[cfg(feature = "builder")]
impl StructAsBytes for EFIImageHandle64Tag {
fn byte_size(&self) -> usize {
size_of::<Self>()
}
}
#[cfg(all(test, feature = "builder"))]
mod tests {
use super::{EFIImageHandle32Tag, EFIImageHandle64Tag, EFISdt32Tag, EFISdt64Tag};
const ADDR: usize = 0xABCDEF;
#[test]
fn test_build_eftsdt32() {
let tag = EFISdt32Tag::new(ADDR.try_into().unwrap());
assert_eq!(tag.sdt_address(), ADDR);
}
#[test]
fn test_build_eftsdt64() {
let tag = EFISdt64Tag::new(ADDR.try_into().unwrap());
assert_eq!(tag.sdt_address(), ADDR);
}
#[test]
fn test_build_eftih32() {
let tag = EFIImageHandle32Tag::new(ADDR.try_into().unwrap());
assert_eq!(tag.image_handle(), ADDR);
}
#[test]
fn test_build_eftih64() {
let tag = EFIImageHandle64Tag::new(ADDR.try_into().unwrap());
assert_eq!(tag.image_handle(), ADDR);
}
}