Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::system::Multiboot Class Reference

Parses and provides access to Multiboot 2 information. More...

#include <multiboot.h>

Public Member Functions

 Multiboot (unsigned long address, unsigned long magic)
 Constructor for the Multiboot class. Parses the multiboot info struct and loads the tags.
 
multiboot_tag_framebufferframebuffer ()
 Get the framebuffer tag.
 
multiboot_tag_basic_meminfobasic_meminfo ()
 Get the basic memory info tag.
 
multiboot_tag_stringbootloader_name ()
 Get the bootloader name tag.
 
multiboot_tag_mmapmmap ()
 Get the module tag.
 
multiboot_tag_old_acpiold_acpi ()
 Get the old ACPI tag.
 
multiboot_tag_new_acpinew_acpi ()
 Get the new ACPI tag.
 
multiboot_tagstart_tag () const
 
bool is_reserved (multiboot_uint64_t address) const
 Check if an address is reserved by a multiboot module.
 

Public Attributes

unsigned long start_address
 The start address of the multiboot info struct.
 
unsigned long end_address
 The end address of the multiboot info struct.
 

Detailed Description

Parses and provides access to Multiboot 2 information.

Definition at line 518 of file multiboot.h.

Constructor & Destructor Documentation

◆ Multiboot()

Multiboot::Multiboot ( unsigned long  address,
unsigned long  magic 
)

Constructor for the Multiboot class. Parses the multiboot info struct and loads the tags.

Parameters
addressThe address of the multiboot info struct
magicThe magic number to confirm the bootloader

Definition at line 24 of file multiboot.cpp.

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}
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
unsigned long end_address
The end address of the multiboot info struct.
Definition multiboot.h:540
multiboot_tag * start_tag() const
unsigned long start_address
The start address of the multiboot info struct.
Definition multiboot.h:539
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
Definition logger.h:100
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

References ASSERT, MaxOS::Logger::DEBUG(), end_address, start_tag(), multiboot_tag_string::string, and MaxOS::memory::PhysicalMemoryManager::to_lower_region().

Member Function Documentation

◆ basic_meminfo()

multiboot_tag_basic_meminfo * Multiboot::basic_meminfo ( )

Get the basic memory info tag.

Returns
The basic memory info tag

Definition at line 108 of file multiboot.cpp.

108 {
109
110 return m_basic_meminfo;
111}

◆ bootloader_name()

multiboot_tag_string * Multiboot::bootloader_name ( )

Get the bootloader name tag.

Returns
The bootloader name tag

Definition at line 117 of file multiboot.cpp.

117 {
118
119 return m_bootloader_name;
120}

◆ framebuffer()

multiboot_tag_framebuffer * Multiboot::framebuffer ( )

Get the framebuffer tag.

Returns
The framebuffer tag

Definition at line 99 of file multiboot.cpp.

99 {
100
101 return m_framebuffer;
102}

◆ is_reserved()

bool Multiboot::is_reserved ( multiboot_uint64_t  address) const

Check if an address is reserved by a multiboot module.

Parameters
addressThe address to check
Returns
True if the address is reserved

Definition at line 154 of file multiboot.cpp.

154 {
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}

References start_tag().

◆ mmap()

multiboot_tag_mmap * Multiboot::mmap ( )

Get the module tag.

Returns
The module tag

Definition at line 126 of file multiboot.cpp.

126 {
127
128 return m_mmap;
129}

Referenced by MaxOS::memory::PhysicalMemoryManager::PhysicalMemoryManager().

◆ new_acpi()

multiboot_tag_new_acpi * Multiboot::new_acpi ( )

Get the new ACPI tag.

Returns
The new ACPI tag

Definition at line 144 of file multiboot.cpp.

144 {
145
146 return m_new_acpi;
147}

◆ old_acpi()

multiboot_tag_old_acpi * Multiboot::old_acpi ( )

Get the old ACPI tag.

Returns
The old ACPI tag

Definition at line 135 of file multiboot.cpp.

135 {
136
137 return m_old_acpi;
138}

◆ start_tag()

multiboot_tag * Multiboot::start_tag ( ) const

Get the start tag of the multiboot information (useful for iterating through the tags)

Returns
The start tag

Definition at line 182 of file multiboot.cpp.

182 {
183
185}
constexpr uint64_t HIGHER_HALF_KERNEL_OFFSET
Where the kernel is mapped in higher half memory.
Definition physical.h:94

References MaxOS::memory::HIGHER_HALF_KERNEL_OFFSET, and start_address.

Referenced by is_reserved(), MaxOS::processes::GlobalScheduler::load_multiboot_elfs(), and Multiboot().

Member Data Documentation

◆ end_address

unsigned long MaxOS::system::Multiboot::end_address

The end address of the multiboot info struct.

Definition at line 540 of file multiboot.h.

Referenced by Multiboot().

◆ start_address

unsigned long MaxOS::system::Multiboot::start_address

The start address of the multiboot info struct.

Definition at line 539 of file multiboot.h.

Referenced by start_tag().


The documentation for this class was generated from the following files: