proka_exec/header.rs
1//! The header definitions.
2
3/// The magic number, fixed to 'PKEX'
4pub const PKEX_MAGIC: u32 = 0x58454B50;
5
6/// The main header struct, which contains the metadata of the PKE file.
7#[repr(C)]
8#[derive(Debug, Clone, Copy)]
9pub struct Header {
10 /// The magic number, fixed to 'PKEX'
11 pub magic: u32,
12
13 /// The minimal kernel version supported.
14 ///
15 /// # Note
16 /// As the `proka-bootloader`'s definitions, its format is similar
17 /// like `[major, minor, fix]`. See `proka-bootloader` crate for more informations.
18 pub min: [u16; 3],
19
20 /// The maximum kernel supported.
21 ///
22 /// For notes, see above.
23 pub max: [u16; 3],
24
25 /// Signates is this executable run as `userapp` or `coredrv`.
26 pub mode: ExecMode,
27
28 /// The section table count.
29 pub sections: u16,
30
31 /// The author name (max length is 32 bytes).
32 pub author: [u8; 32],
33
34 /// The executable/project name.
35 pub name: [u8; 32],
36
37 /// Extended bits for different mode parsing.
38 pub extended: [u8; 48],
39}
40
41impl Default for Header {
42 fn default() -> Self {
43 Self::new()
44 }
45}
46
47impl Header {
48 /// Create a header object.
49 pub fn new() -> Self {
50 Self {
51 magic: PKEX_MAGIC,
52 author: [0u8; 32],
53 name: [0u8; 32],
54 ..Default::default()
55 }
56 }
57
58 /// Validate is this a valid proka executable.
59 #[inline]
60 pub fn validate(&self) -> bool {
61 self.magic == PKEX_MAGIC
62 }
63}
64
65/// The executable mode.
66#[repr(C)]
67#[derive(Debug, Clone, Copy)]
68pub enum ExecMode {
69 /// Run in `userapp` mode (Ring 3).
70 UserApp,
71
72 /// Run in `coredrv` mode (Ring 0).
73 CoreDrv,
74}