uefi/hii/
package.rs

1use core::{mem, slice};
2
3use crate::guid::Guid;
4use crate::util::c_str_at_end;
5
6use super::StringId;
7
8#[derive(Clone, Copy, Debug)]
9#[repr(u8)]
10pub enum HiiPackageKind {
11    /// Pseudo-package type used when exporting package lists
12    All = 0x00,
13    /// Package type where the format of the data is specified using a GUID immediately following the package header
14    Guid = 0x01,
15    /// Forms package
16    Forms = 0x02,
17    /// Strings package
18    Strings = 0x04,
19    /// Fonts package
20    Fonts = 0x05,
21    /// Images package
22    Images = 0x06,
23    /// Simplified (8x19, 16x19) Fonts package
24    SimpleFonts = 0x07,
25    /// Binary-encoded device path
26    DevicePath = 0x08,
27    /// Keyboard Layout package
28    KeyboardLayout = 0x09,
29    /// Animations package
30    Animations = 0x0A,
31    /// Used to mark the end of a package list
32    End = 0xDF,
33    // Package types reserved for firmware implementations
34    //SystemBegin = 0xE0,
35    //SystemEnd = 0xFF,
36}
37
38#[derive(Debug)]
39#[repr(C)]
40pub struct HiiPackageHeader {
41    pub Length_Kind: u32,
42}
43
44impl HiiPackageHeader {
45    pub fn Length(&self) -> u32 {
46        self.Length_Kind & 0xFFFFFF
47    }
48
49    pub fn Kind(&self) -> HiiPackageKind {
50        unsafe { mem::transmute((self.Length_Kind >> 24) as u8) }
51    }
52
53    pub fn Data(&self) -> &[u8] {
54        unsafe {
55            slice::from_raw_parts(
56                (self as *const Self).add(1) as *const u8,
57                self.Length() as usize - mem::size_of::<Self>(),
58            )
59        }
60    }
61}
62
63#[derive(Debug)]
64#[repr(C)]
65pub struct HiiStringPackageHeader {
66    pub Header: HiiPackageHeader,
67    pub HdrSize: u32,
68    pub StringInfoOffset: u32,
69    pub LanguageWindow: [u16; 16],
70    pub LanguageName: StringId,
71}
72
73impl HiiStringPackageHeader {
74    pub fn Language(&self) -> &[u8] {
75        unsafe { c_str_at_end(self, 0) }
76    }
77
78    pub fn StringInfo(&self) -> &[u8] {
79        unsafe {
80            slice::from_raw_parts(
81                (self as *const Self as *const u8).add(self.StringInfoOffset as usize),
82                self.Header.Length() as usize - self.StringInfoOffset as usize,
83            )
84        }
85    }
86}
87
88#[derive(Debug)]
89#[repr(C)]
90pub struct HiiPackageListHeader {
91    pub PackageListGuid: Guid,
92    pub PackageLength: u32,
93}
94
95impl HiiPackageListHeader {
96    pub fn Data(&self) -> &[u8] {
97        unsafe {
98            slice::from_raw_parts(
99                (self as *const Self).add(1) as *const u8,
100                self.PackageLength as usize - mem::size_of::<Self>(),
101            )
102        }
103    }
104}