Skip to main content

proka_bootloader/
header.rs

1//! The definition of proka-kernel header.
2//!
3//! This module will help you to create a header, and
4//! all you need to do is put it into the head of the kernel
5//! file.
6
7use crate::version::VERSION;
8
9#[repr(C, packed)]
10#[derive(Debug, Clone, Copy)]
11pub struct Header {
12    /// The magic number of this header
13    pub magic: u32,
14
15    /// The version of this kernel.
16    ///
17    /// # Structures of this field
18    /// To create this version, this must obey this rule:
19    ///
20    /// - For bit 0~2, that's the first version number;
21    /// - For bit 3~4, that's the second version number;
22    /// - And bit 5~6, it's the last version number.
23    ///
24    /// This field has 3 u16 values, so the version
25    /// format shall like this: `X.Y.Z`
26    ///
27    /// # Example
28    /// - `0.3.1` => `0x0000_0003_0001 [0, 3, 1]`;
29    /// - `1.0.3` => `0x0001_0000_0003 [1, 0, 3]`;
30    /// - `0.1.218` => 0x0000_0001_026a [0, 1, 218].
31    pub version: [u16; 3],
32
33    /// Reserved bits
34    pub _reserved: [u8; 6],
35}
36
37impl Header {
38    pub const fn default() -> Self {
39        Self {
40            magic: 0x504b4e4c,  // PKNL
41            version: VERSION,
42            _reserved: [0u8; 6],
43        }
44    }
45}