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(4))]
21#[derive(Debug, Clone, 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}
29
30impl BootInfo {
31 /// Initialize a new boot info object.
32 ///
33 /// Note: this object will be initialized by loader
34 /// automatically, so if you are a kernel developer, do
35 /// not use this method, because you needn't and unusable.
36 #[cfg(feature = "loader_main")]
37 pub fn new(boot_mode: BootMode, memmap: MemoryMap, fb: Framebuffer) -> Self {
38 Self {
39 boot_mode,
40 memmap,
41 framebuffer: fb
42 }
43 }
44
45 /// Put the boot information to a fixed address
46 ///
47 /// # Safety
48 /// This is unsafe because we need to operate the pointer.
49 ///
50 /// This function is for loader only.
51 pub unsafe fn put_addr(self, address: u64) {
52 let pointer = address as *mut BootInfo;
53 unsafe {
54 pointer.write_volatile(self);
55 }
56 }
57
58 /// Load the boot infomation from an address.
59 ///
60 /// # Safety
61 /// This is unsafe because we need to read from a pointer.
62 pub unsafe fn load(address: u64) -> Self {
63 let pointer = address as *const BootInfo;
64 unsafe {
65 pointer.read_volatile()
66 }
67 }
68
69 /// Get the boot mode.
70 pub const fn boot_mode(&self) -> &BootMode {
71 &self.boot_mode
72 }
73
74 /// Get the framebuffer info.
75 pub const fn framebuffer(&self) -> &Framebuffer {
76 &self.framebuffer
77 }
78
79 /// Get the memory map.
80 pub const fn memory(&self) -> &MemoryMap {
81 &self.memmap
82 }
83}
84
85/// This is the boot mode, only support 2 modes, which are legacy(BIOS) and UEFI.
86#[repr(C)]
87#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88pub enum BootMode {
89 /// The Legacy boot mode, also called BIOS boot mode.
90 ///
91 /// This mode is for older machine, and we needs implement
92 /// lots of things in it.
93 Legacy,
94
95 /// The UEFI boot mode, which is the newer mode. Lots of
96 /// new machines uses it.
97 ///
98 /// Also, some machine only support it (such as mine awa).
99 Uefi,
100}