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
11#[cfg(feature = "loader_main")]
12pub mod loader_main;
13pub mod output;
14pub mod memory;
15use self::output::Framebuffer;
16use self::memory::MemoryMap;
17
18/// This struct is the boot information struct, which provides
19/// the basic information, *memory map*, and so on.
20#[repr(C, align(8))]
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub struct BootInfo {
23 /// The boot mode, see the [`BootMode`] enum.
24 boot_mode: BootMode,
25 memmap: MemoryMap,
26 framebuffer: Framebuffer,
27}
28
29impl BootInfo {
30 /// Initialize a new boot info object.
31 ///
32 /// Note: this object will be initialized by loader
33 /// automatically, so if you are a kernel developer, do
34 /// not use this method, because you needn't and unusable.
35 #[cfg(feature = "loader_main")]
36 pub fn new(boot_mode: BootMode, memmap: MemoryMap, fb: Framebuffer) -> Self {
37 Self {
38 boot_mode,
39 memmap,
40 framebuffer: fb
41 }
42 }
43
44 /// Get the boot mode.
45 pub const fn boot_mode(&self) -> &BootMode {
46 &self.boot_mode
47 }
48
49 /// Get the framebuffer info.
50 pub const fn framebuffer(&self) -> &Framebuffer {
51 &self.framebuffer
52 }
53
54 /// Get the memory map.
55 pub const fn memory(&self) -> &MemoryMap {
56 &self.memmap
57 }
58}
59
60/// This is the boot mode, only support 2 modes, which are legacy(BIOS) and UEFI.
61#[repr(C)]
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63pub enum BootMode {
64 /// The Legacy boot mode, also called BIOS boot mode.
65 ///
66 /// This mode is for older machine, and we needs implement
67 /// lots of things in it.
68 Legacy,
69
70 /// The UEFI boot mode, which is the newer mode. Lots of
71 /// new machines uses it.
72 ///
73 /// Also, some machine only support it (such as mine awa).
74 Uefi,
75}