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_framebuffer * framebuffer ()
 Get the framebuffer tag.
 
multiboot_tag_basic_meminfo * basic_meminfo ()
 Get the basic memory info tag.
 
multiboot_tag_string * bootloader_name ()
 Get the bootloader name tag.
 
multiboot_tag_mmap * mmap ()
 Get the module tag.
 
multiboot_tag_old_acpi * old_acpi ()
 Get the old ACPI tag.
 
multiboot_tag_new_acpi * new_acpi ()
 Get the new ACPI tag.
 
multiboot_tag * start_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
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}
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
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
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

References multiboot_tag_bootdev::biosdev, MaxOS::Logger::DEBUG(), end_address, multiboot_tag_bootdev::part, multiboot_tag::size, start_tag(), multiboot_tag_string::string, MaxOS::memory::PhysicalMemoryManager::to_lower_region(), and multiboot_tag::type.

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 111 of file multiboot.cpp.

111 {
112
113 return m_basic_meminfo;
114}

◆ bootloader_name()

multiboot_tag_string * Multiboot::bootloader_name ( )

Get the bootloader name tag.

Returns
The bootloader name tag

Definition at line 120 of file multiboot.cpp.

120 {
121
122 return m_bootloader_name;
123}

◆ framebuffer()

multiboot_tag_framebuffer * Multiboot::framebuffer ( )

Get the framebuffer tag.

Returns
The framebuffer tag

Definition at line 102 of file multiboot.cpp.

102 {
103
104 return m_framebuffer;
105}

Referenced by kernel_main().

◆ 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 157 of file multiboot.cpp.

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

References start_tag(), and multiboot_tag::type.

◆ mmap()

multiboot_tag_mmap * Multiboot::mmap ( )

Get the module tag.

Returns
The module tag

Definition at line 129 of file multiboot.cpp.

129 {
130
131 return m_mmap;
132}

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 147 of file multiboot.cpp.

147 {
148
149 return m_new_acpi;
150}

Referenced by MaxOS::hardwarecommunication::AdvancedConfigurationAndPowerInterface::AdvancedConfigurationAndPowerInterface().

◆ old_acpi()

multiboot_tag_old_acpi * Multiboot::old_acpi ( )

Get the old ACPI tag.

Returns
The old ACPI tag

Definition at line 138 of file multiboot.cpp.

138 {
139
140 return m_old_acpi;
141}

Referenced by MaxOS::hardwarecommunication::AdvancedConfigurationAndPowerInterface::AdvancedConfigurationAndPowerInterface().

◆ 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 185 of file multiboot.cpp.

185 {
186
188}
constexpr uint64_t HIGHER_HALF_KERNEL_OFFSET
Where the kernel is mapped in higher half memory.
Definition physical.h:95

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

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

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(), and MaxOS::memory::PhysicalMemoryManager::reserve_kernel_regions().

◆ 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: