proka_bootloader/lib.rs
1//! This crate provides the struct, enums about the Proka
2//! bootloader, including the boot information, and so on.
3//!
4//! # About proka bootloader
5//! Well, this bootloader is for Proka Kernel, which will obey
6//! its standard. For more information, see <url>.
7
8#![no_std]
9#![no_main]
10#![feature(custom_test_frameworks)]
11#![test_runner(self::test_runner)]
12#![reexport_test_harness_main = "test_main"]
13
14#[cfg(feature = "loader_main")]
15pub mod loader_main;
16pub mod output;
17pub mod memory;
18use self::output::Framebuffer;
19use self::memory::MemoryMap;
20
21/// This struct is the boot information struct, which provides
22/// the basic information, *memory map*, and so on.
23#[repr(C, packed)]
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub struct BootInfo {
26 /// The boot mode, see the [`BootMode`] enum.
27 boot_mode: BootMode,
28 framebuffer: Framebuffer,
29 memmap: MemoryMap,
30}
31
32impl BootInfo {
33 /// Initialize a new boot info object.
34 ///
35 /// Note: this object will be initialized by loader
36 /// automatically, so if you are a kernel developer, do
37 /// not use this method, because you needn't and unusable.
38 #[cfg(feature = "loader_main")]
39 pub fn new(boot_mode: BootMode, memmap: MemoryMap, fb: Framebuffer) -> Self {
40 Self {
41 boot_mode,
42 memmap,
43 framebuffer: fb
44 }
45 }
46
47 /// Get the boot mode.
48 pub const fn boot_mode(&self) -> BootMode {
49 self.boot_mode
50 }
51
52 /// Get the framebuffer info.
53 pub const fn framebuffer(&self) -> Framebuffer {
54 self.framebuffer
55 }
56
57 /// Get the memory map.
58 pub const fn memory(&self) -> MemoryMap {
59 self.memmap
60 }
61}
62
63/// This is the boot mode, only support 2 modes, which are legacy(BIOS) and UEFI.
64#[repr(C)]
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66pub enum BootMode {
67 /// The Legacy boot mode, also called BIOS boot mode.
68 ///
69 /// This mode is for older machine, and we needs implement
70 /// lots of things in it.
71 Legacy,
72
73 /// The UEFI boot mode, which is the newer mode. Lots of
74 /// new machines uses it.
75 ///
76 /// Also, some machine only support it (such as mine awa).
77 Uefi,
78}
79
80#[cfg(test)]
81fn test_runner(tests: &[&dyn Fn()]) {
82 for test in tests {
83 test();
84 }
85}