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
32 multiboot_tag* tag = start_tag();
33
34
35
36 // Loop through the tags and load them
37 while (true) {
38
39 // Handle the tag
40 switch (tag->type) {
41
42 case MULTIBOOT_TAG_TYPE_END:
43 end_address = (unsigned long) PhysicalMemoryManager::to_lower_region((uint64_t) tag);
44 return;
45
46 case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
47 m_framebuffer = (multiboot_tag_framebuffer*) tag;
48 Logger::DEBUG() << "Framebuffer: addr=0x" << (uint64_t) m_framebuffer -> common.framebuffer_addr << ", screen=" << (uint64_t) m_framebuffer -> common.framebuffer_height<< "x" << (uint64_t) m_framebuffer -> common.framebuffer_width << "\n";
49 break;
50
51 case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
52 m_basic_meminfo = (multiboot_tag_basic_meminfo*) tag;
53 break;
54
55 case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME:
56 m_bootloader_name = (multiboot_tag_string*) tag;
57 Logger::DEBUG() << "Bootloader: " << m_bootloader_name->string << "\n";
58 break;
59
60 case MULTIBOOT_TAG_TYPE_BOOTDEV:
61 multiboot_tag_bootdev* bootdev;
62 bootdev = (multiboot_tag_bootdev*) tag;
63 Logger::DEBUG() << "Boot device: drive=0x" << (uint64_t) bootdev->biosdev << ", partition=0x" << (uint64_t) bootdev->part << "\n";
64 break;
65
66 case MULTIBOOT_TAG_TYPE_MMAP:
67
68 // If there is not already a mmap tag, set it
69 if (m_mmap == nullptr)
70 m_mmap = (multiboot_tag_mmap*) tag;
71
72 break;
73
74 case MULTIBOOT_TAG_TYPE_ACPI_OLD:
75 m_old_acpi = (multiboot_tag_old_acpi*) tag;
76 break;
77
78
79 case MULTIBOOT_TAG_TYPE_ACPI_NEW:
80 m_new_acpi = (multiboot_tag_new_acpi*) tag;
81 break;
82
83 case MULTIBOOT_TAG_TYPE_MODULE:
85 module = (multiboot_tag_module*) tag;
86 Logger::DEBUG() << "Module: start=0x" << (uint64_t) module->mod_start << ", end=0x" << (uint64_t) module->mod_end << ", cmdline=" << module->cmdline << "\n";
87 m_module = module;
88 break;
89 }
90
91 // Move to the next tag
92 tag = (struct multiboot_tag*) ((multiboot_uint8_t*) tag + ((tag->size + 7) & ~7));
93 }
94}
95
96Multiboot::~Multiboot() = default;
97
103
104 return m_framebuffer;
105}
106
112
113 return m_basic_meminfo;
114}
115
121
122 return m_bootloader_name;
123}
124
130
131 return m_mmap;
132}
133
139
140 return m_old_acpi;
141}
142
148
149 return m_new_acpi;
150}
151
157bool Multiboot::is_reserved(multiboot_uint64_t address) const {
158
159 // Loop through the tags checking if the address is reserved
160 for (multiboot_tag* tag = start_tag(); tag->type != MULTIBOOT_TAG_TYPE_END; tag = (struct multiboot_tag*) ((multiboot_uint8_t*) tag + ((tag->size + 7) & ~7))) {
161
162 // Check if the tag is a module or mmap
163 if (tag->type != MULTIBOOT_TAG_TYPE_MODULE && tag->type != MULTIBOOT_TAG_TYPE_MMAP)
164 continue;
165
166 // Get the module tag
167 auto* module = (struct multiboot_tag_module*) tag;
168
169 // Check if the address is within the module
170 if (address >= module->mod_start && address < module->mod_end)
171 return true;
172 }
173
174
175 // Not part of multiboot
176 return false;
177
178}
179
static LogRecord DEBUG()
Gets the active logger for debug logs.
Definition logger.cpp:204
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:898
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.
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...
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:95
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
multiboot_uint32_t biosdev
The BIOS disk device the OS image was loaded from.
Definition multiboot.h:279
multiboot_uint32_t part
The partition number of the disk device.
Definition multiboot.h:281
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
multiboot_uint32_t size
The size of the tag including this header.
Definition multiboot.h:236
multiboot_uint32_t type
The type of the tag.
Definition multiboot.h:235