Max OS 0.3
Loading...
Searching...
No Matches
multiboot.cpp
Go to the documentation of this file.
1
9#include <system/multiboot.h>
10#include <common/logger.h>
12
13using namespace MaxOS;
14using namespace MaxOS::system;
15using namespace MaxOS::memory;
16using namespace MaxOS::common;
17
24Multiboot::Multiboot(unsigned long address, unsigned long magic)
25: start_address(address)
26{
27
28 // Confirm the bootloader
29 ASSERT(magic == MULTIBOOT2_BOOTLOADER_MAGIC, "Multiboot2 Bootloader Not Detected");
30 Logger::DEBUG() << "Multiboot2 Bootloader Detected at 0x" << (uint64_t) address << "\n";
31
33
34 // Loop through the tags and load them
35 while (true) {
36
37 // Handle the tag
38 switch (tag->type) {
39
40 case MULTIBOOT_TAG_TYPE_END:
42 return;
43
44 case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
45 m_framebuffer = (multiboot_tag_framebuffer*) tag;
46 break;
47
48 case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
49 m_basic_meminfo = (multiboot_tag_basic_meminfo*) tag;
50 break;
51
52 case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME:
53 m_bootloader_name = (multiboot_tag_string*) tag;
54 Logger::DEBUG() << "Bootloader: " << m_bootloader_name->string << "\n";
55 break;
56
57 case MULTIBOOT_TAG_TYPE_BOOTDEV:
60 Logger::DEBUG() << "Boot device: drive=0x" << (uint64_t) bootdev->biosdev << ", partition=0x" << (uint64_t) bootdev->part << "\n";
61 break;
62
63 case MULTIBOOT_TAG_TYPE_MMAP:
64
65 // If there is not already a mmap tag, set it
66 if (m_mmap == nullptr)
67 m_mmap = (multiboot_tag_mmap*) tag;
68
69 break;
70
71 case MULTIBOOT_TAG_TYPE_ACPI_OLD:
72 m_old_acpi = (multiboot_tag_old_acpi*) tag;
73 break;
74
75
76 case MULTIBOOT_TAG_TYPE_ACPI_NEW:
77 m_new_acpi = (multiboot_tag_new_acpi*) tag;
78 break;
79
80 case MULTIBOOT_TAG_TYPE_MODULE:
82 module = (multiboot_tag_module*) tag;
83 Logger::DEBUG() << "Module: start=0x" << (uint64_t) module->mod_start << ", end=0x" << (uint64_t) module->mod_end << ", cmdline=" << module->cmdline << "\n";
84 m_module = module;
85 break;
86 }
87
88 // Move to the next tag
89 tag = (struct multiboot_tag*) ((multiboot_uint8_t*) tag + ((tag->size + 7) & ~7));
90 }
91}
92
93Multiboot::~Multiboot() = default;
94
100
101 return m_framebuffer;
102}
103
109
110 return m_basic_meminfo;
111}
112
118
119 return m_bootloader_name;
120}
121
127
128 return m_mmap;
129}
130
136
137 return m_old_acpi;
138}
139
145
146 return m_new_acpi;
147}
148
154bool Multiboot::is_reserved(multiboot_uint64_t address) const {
155
156 // Loop through the tags checking if the address is reserved
157 for (multiboot_tag* tag = start_tag(); tag->type != MULTIBOOT_TAG_TYPE_END; tag = (struct multiboot_tag*) ((multiboot_uint8_t*) tag + ((tag->size + 7) & ~7))) {
158
159 // Check if the tag is a module or mmap
160 if (tag->type != MULTIBOOT_TAG_TYPE_MODULE && tag->type != MULTIBOOT_TAG_TYPE_MMAP)
161 continue;
162
163 // Get the module tag
164 auto* module = (struct multiboot_tag_module*) tag;
165
166 // Check if the address is within the module
167 if (address >= module->mod_start && address < module->mod_end)
168 return true;
169 }
170
171
172 // Not part of multiboot
173 return false;
174
175}
176
static Logger DEBUG()
Gets active logger set to DEBUG level.
Definition logger.cpp:193
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
static void * to_lower_region(uintptr_t virtual_address)
Converts a virtual address to a lower region address if it is in the higher region using the higher h...
Definition physical.cpp:899
bool is_reserved(multiboot_uint64_t address) const
Check if an address is reserved by a multiboot module.
unsigned long end_address
The end address of the multiboot info struct.
Definition multiboot.h:540
multiboot_tag * start_tag() const
multiboot_tag_basic_meminfo * basic_meminfo()
Get the basic memory info tag.
multiboot_tag_string * bootloader_name()
Get the bootloader name tag.
multiboot_tag_framebuffer * framebuffer()
Get the framebuffer tag.
Definition multiboot.cpp:99
Multiboot(unsigned long address, unsigned long magic)
Constructor for the Multiboot class. Parses the multiboot info struct and loads the tags.
Definition multiboot.cpp:24
multiboot_tag_old_acpi * old_acpi()
Get the old ACPI tag.
multiboot_tag_new_acpi * new_acpi()
Get the new ACPI tag.
multiboot_tag_mmap * mmap()
Get the module tag.
unsigned long start_address
The start address of the multiboot info struct.
Definition multiboot.h:539
Defines a Logger class for logging messages with different severity levels to multiple output streams...
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
Definition logger.h:100
Defines a MemoryManager class for handling memory allocation and deallocation.
constexpr uint64_t HIGHER_HALF_KERNEL_OFFSET
Where the kernel is mapped in higher half memory.
Definition physical.h:94
A tag containing basic (legacy) memory information.
Definition multiboot.h:265
A tag containing information about the device the OS image was loaded from.
Definition multiboot.h:276
A tag containing information about the framebuffer.
Definition multiboot.h:356
A tag containing the collection of memory map entries that outline the memory layout.
Definition multiboot.h:288
A tag containing information about a loaded module.
Definition multiboot.h:253
A tag containing information about the new ACPI RSDP.
Definition multiboot.h:453
A tag containing information about the old ACPI RSDP.
Definition multiboot.h:443
A tag containing a null-terminated string.
Definition multiboot.h:243
char string[0]
The string.
Definition multiboot.h:246
Common header for all multiboot info tags.
Definition multiboot.h:234