IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
multiboot.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// C++
17#include <array>
18#include <bit>
19// IgrOS-Kernel arch
20#include <arch/types.hpp>
21// IgrOS-Kernel library
22#include <klib/kFlags.hpp>
23// IgrOS-Kernel memory
24#include <mem/direct.hpp>
25
26
27// Multiboot code zone
28namespace igros::multiboot {
29
30
32 constexpr static auto HEADER_MAGIC {0x1BADB002_u32};
34 constexpr static auto BOOTLOADER_MAGIC {0x2BADB002_u32};
35
36
40 [[nodiscard]]
41 inline auto check(const igros_dword_t signature) noexcept -> bool {
42 return (BOOTLOADER_MAGIC == signature);
43 }
44
45
47 enum class flags_t : igros_dword_t {
48 MEM = (1_u32 << 0),
49 BOOT_DEV = (1_u32 << 1),
50 CMD = (1_u32 << 2),
51 MODULES = (1_u32 << 3),
52 SYMS_AOUT = (1_u32 << 4),
53 SYMS_ELF = (1_u32 << 5),
54 MEM_MAP = (1_u32 << 6),
55 DRIVES = (1_u32 << 7),
56 TABLE_CONFIG = (1_u32 << 8),
57 LOADER_NAME = (1_u32 << 9),
58 TABLE_APM = (1_u32 << 10),
59 VBE = (1_u32 << 11),
60 FRAME_BUF = (1_u32 << 12),
61 };
62
63
64#pragma pack(push, 1)
65
74
82
91
92
94 class memoryMap_t;
95
97 struct info_t final {
98
100
103
105
107
110
111 std::array<igros_dword_t, 4_usize> syms;
112
115
118
120
122
124
131
138 std::array<igros_byte_t, 6_usize> fbColorInfo;
139
140
143 void test(const igros_dword_t magic) const noexcept;
144
147 [[nodiscard]]
148 auto hasInfoMemory() const noexcept -> bool;
151 [[nodiscard]]
152 auto hasInfoBootDevice() const noexcept -> bool;
154 [[nodiscard]]
155 auto hasInfoCommandLine() const noexcept -> bool;
158 [[nodiscard]]
159 auto hasInfoModules() const noexcept -> bool;
162 [[nodiscard]]
163 auto hasInfoAOUT() const noexcept -> bool;
166 [[nodiscard]]
167 auto hasInfoELF() const noexcept -> bool;
170 [[nodiscard]]
171 auto hasInfoMemoryMap() const noexcept -> bool;
174 [[nodiscard]]
175 auto hasInfoDrives() const noexcept -> bool;
178 [[nodiscard]]
179 auto hasInfoConfig() const noexcept -> bool;
182 [[nodiscard]]
183 auto hasInfoBootloaderName() const noexcept -> bool;
186 [[nodiscard]]
187 auto hasInfoAPM() const noexcept -> bool;
190 [[nodiscard]]
191 auto hasInfoVBE() const noexcept -> bool;
194 [[nodiscard]]
195 auto hasInfoFrameBuffer() const noexcept -> bool;
196
198 [[nodiscard]]
199 auto commandLine() const noexcept -> const char*;
201 [[nodiscard]]
202 auto loaderName() const noexcept -> const char*;
204 [[nodiscard]]
205 auto memoryMap() const noexcept -> memoryMap_t;
206
208 void printFlags() const noexcept;
210 void printMemInfo() const noexcept;
212 void printMemMap() const noexcept;
214 void printVBEInfo() const noexcept;
216 void printFBInfo() const noexcept;
217
219 void printHeader() const noexcept;
220 };
221
223 [[nodiscard]]
224 inline auto info_t::hasInfoMemory() const noexcept -> bool {
225 return flags.isSet(flags_t::MEM);
226 }
227
229 [[nodiscard]]
230 inline auto info_t::hasInfoBootDevice() const noexcept -> bool {
231 return flags.isSet(flags_t::BOOT_DEV);
232 }
233
236 [[nodiscard]]
237 inline auto info_t::hasInfoCommandLine() const noexcept -> bool {
238 return flags.isSet(flags_t::CMD);
239 }
240
242 [[nodiscard]]
243 inline auto info_t::hasInfoModules() const noexcept -> bool {
244 return flags.isSet(flags_t::MODULES);
245 }
246
248 [[nodiscard]]
249 inline auto info_t::hasInfoAOUT() const noexcept -> bool {
250 // A.OUT but not ELF
251 return flags.isSet(flags_t::SYMS_AOUT) && !flags.isSet(flags_t::SYMS_ELF);
252 }
253
255 [[nodiscard]]
256 inline auto info_t::hasInfoELF() const noexcept -> bool {
257 // ELF but not A.OUT
258 return flags.isSet(flags_t::SYMS_ELF) && !flags.isSet(flags_t::SYMS_AOUT);
259 }
260
262 [[nodiscard]]
263 inline auto info_t::hasInfoMemoryMap() const noexcept -> bool {
264 return flags.isSet(flags_t::MEM_MAP);
265 }
266
268 [[nodiscard]]
269 inline auto info_t::hasInfoDrives() const noexcept -> bool {
270 return flags.isSet(flags_t::DRIVES);
271 }
272
274 [[nodiscard]]
275 inline auto info_t::hasInfoConfig() const noexcept -> bool {
276 return flags.isSet(flags_t::TABLE_CONFIG);
277 }
278
280 [[nodiscard]]
281 inline auto info_t::hasInfoBootloaderName() const noexcept -> bool {
282 return flags.isSet(flags_t::LOADER_NAME);
283 }
284
286 [[nodiscard]]
287 inline auto info_t::hasInfoAPM() const noexcept -> bool {
288 return flags.isSet(flags_t::TABLE_APM);
289 }
290
292 [[nodiscard]]
293 inline auto info_t::hasInfoVBE() const noexcept -> bool {
294 return flags.isSet(flags_t::VBE);
295 }
296
298 [[nodiscard]]
299 inline auto info_t::hasInfoFrameBuffer() const noexcept -> bool {
300 return flags.isSet(flags_t::FRAME_BUF);
301 }
302
303
306 [[nodiscard]]
307 inline auto info_t::commandLine() const noexcept -> const char* {
308 return hasInfoCommandLine() ? mem::direct::string(cmdLine) : nullptr;
309 }
310
313 [[nodiscard]]
314 inline auto info_t::loaderName() const noexcept -> const char* {
316 }
317
318
321 AVAILABLE = 1_u32,
322 RESERVED = 2_u32,
323 ACPI = 3_u32,
324 NVS = 4_u32,
325 BAD = 5_u32,
326 };
327
335
343
344
360
396
397#pragma pack(pop)
398
399
401 class memoryMap_t final {
402
403 const igros_byte_t* mBegin {nullptr};
404 const igros_byte_t* mEnd {nullptr};
405
406
407 public:
408
410 struct sentinel_t final {
412 };
413
415 class iterator_t final {
416
418
419 public:
420
423 constexpr explicit iterator_t(const igros_byte_t* const entry) noexcept : mEntry {entry} {}
424
427 [[nodiscard]]
428 auto operator*() const noexcept -> const memoryMapEntry & {
429 return *std::bit_cast<const memoryMapEntry*>(mEntry);
430 }
431
434 auto operator++() noexcept -> iterator_t & {
435 const auto size {std::bit_cast<const memoryMapEntry*>(mEntry)->size};
436 // Zero size would never advance - assume standard entry size
437 mEntry += sizeof(memoryMapEntry::size) + ((0_u32 != size) ? size : (sizeof(memoryMapEntry) - sizeof(memoryMapEntry::size)));
438 return *this;
439 }
440
444 [[nodiscard]]
445 auto operator==(const sentinel_t &sentinel) const noexcept -> bool {
446 return (mEntry + sizeof(memoryMapEntry)) > sentinel.end;
447 }
448 };
449
451 constexpr memoryMap_t() noexcept = default;
455 constexpr memoryMap_t(const igros_byte_t* const begin, const igros_usize_t length) noexcept :
456 mBegin {begin},
457 mEnd {begin + length} {}
458
461 [[nodiscard]]
462 constexpr auto begin() const noexcept -> iterator_t {
463 return iterator_t {mBegin};
464 }
465
467 [[nodiscard]]
468 constexpr auto end() const noexcept -> sentinel_t {
469 return sentinel_t {mEnd};
470 }
471 };
472
473
476 [[nodiscard]]
477 inline auto info_t::memoryMap() const noexcept -> memoryMap_t {
478 // Check if memory map provided
479 if (!hasInfoMemoryMap()) [[unlikely]] {
480 return memoryMap_t {};
481 }
482 // Memory map at physical address
484 if (nullptr == entries) [[unlikely]] {
485 return memoryMap_t {};
486 }
487 return memoryMap_t {entries, mmapLength};
488 }
489
490
491} // namespace igros::multiboot
492
Bit flags of enum type.
Definition kFlags.hpp:29
static auto string(const phys_t phys) noexcept -> const char *
String at physical memory (nullptr if not directly mapped up to null terminator).
Definition direct.hpp:121
static auto pointer(const phys_t phys, const phys_t size=sizeof(T)) noexcept -> T *
Pointer to physical memory (nullptr if range is not directly mapped).
Definition direct.hpp:112
Memory map entries iterator.
auto operator++() noexcept -> iterator_t &
Move to next entry ("size" field doesn't count itself).
auto operator==(const sentinel_t &sentinel) const noexcept -> bool
Check if whole entry no longer fits into memory map.
const igros_byte_t * mEntry
Current entry.
auto operator*() const noexcept -> const memoryMapEntry &
Get current entry.
constexpr iterator_t(const igros_byte_t *const entry) noexcept
C-tor.
Multiboot 1 memory map view (entries have variable size).
constexpr auto end() const noexcept -> sentinel_t
Memory map end.
const igros_byte_t * mEnd
Memory map end.
constexpr auto begin() const noexcept -> iterator_t
First entry.
const igros_byte_t * mBegin
First entry.
constexpr memoryMap_t() noexcept=default
Empty memory map.
Direct map of physical memory.
std::uint16_t igros_word_t
16-bit unsigned integer
Definition types.hpp:42
std::size_t igros_usize_t
Unsigned size.
Definition types.hpp:51
std::uint8_t igros_byte_t
8-bit unsigned integer
Definition types.hpp:41
std::uint32_t igros_dword_t
32-bit unsigned integer
Definition types.hpp:43
std::uint64_t igros_quad_t
64-bit unsigned integer
Definition types.hpp:44
Bit flags template datatype.
Multiboot 1 information passed by the bootloader.
auto check(const igros_dword_t signature) noexcept -> bool
Multiboot 1 header signature check function.
Definition multiboot.hpp:41
static constexpr auto BOOTLOADER_MAGIC
Multiboot 1 bootloader magic.
Definition multiboot.hpp:34
MEMORY_MAP_TYPE
Multiboot 1 memory entry type.
@ ACPI
Memory is ACPI reclaimable.
flags_t
Multiboot header flags enumeration.
Definition multiboot.hpp:47
@ MEM_MAP
Memory map available.
Definition multiboot.hpp:54
@ MODULES
Kernel modules available.
Definition multiboot.hpp:51
@ MEM
Memory info available.
Definition multiboot.hpp:48
@ TABLE_CONFIG
Configuration table available.
Definition multiboot.hpp:56
@ DRIVES
Drives info available.
Definition multiboot.hpp:55
@ BOOT_DEV
Boot device info available.
Definition multiboot.hpp:49
@ VBE
VBE table available.
Definition multiboot.hpp:59
@ SYMS_AOUT
A.OUT info available.
Definition multiboot.hpp:52
@ FRAME_BUF
Frame buffer info available.
Definition multiboot.hpp:60
@ CMD
Kernel command line available.
Definition multiboot.hpp:50
@ TABLE_APM
APM table available.
Definition multiboot.hpp:58
@ SYMS_ELF
ELF info available.
Definition multiboot.hpp:53
@ LOADER_NAME
Bootloader name available.
Definition multiboot.hpp:57
static constexpr auto HEADER_MAGIC
Multiboot 1 header magic.
Definition multiboot.hpp:32
Multiboot 1 header.
Definition multiboot.hpp:84
infoVideo video
Video mode data.
Definition multiboot.hpp:89
infoSections sections
Executable sections data.
Definition multiboot.hpp:88
igros_dword_t checksum
Multiboot header checksum.
Definition multiboot.hpp:87
igros_dword_t flags
Multiboot header flag.
Definition multiboot.hpp:86
igros_dword_t magic
Multiboot header magic - must be equal to HEADER_MAGIC.
Definition multiboot.hpp:85
Kernel sections info.
Definition multiboot.hpp:67
igros_dword_t bssEnd
Kernel BSS section end.
Definition multiboot.hpp:71
igros_dword_t loadEnd
Kernel load address end.
Definition multiboot.hpp:70
igros_dword_t entry
Kernel entry point.
Definition multiboot.hpp:72
igros_dword_t loadStart
Kernel load address start.
Definition multiboot.hpp:69
igros_dword_t header
Kernel header section address.
Definition multiboot.hpp:68
Multiboot video info.
Definition multiboot.hpp:76
igros_dword_t depth
Video mode depth.
Definition multiboot.hpp:80
igros_dword_t mode
Video mode.
Definition multiboot.hpp:77
igros_dword_t width
Video mode width.
Definition multiboot.hpp:78
igros_dword_t height
Video mode height.
Definition multiboot.hpp:79
Multiboot 1 information from bootloader.
Definition multiboot.hpp:97
auto hasInfoBootDevice() const noexcept -> bool
Multiboot contains valid boot device info.
void printVBEInfo() const noexcept
Print multiboot VBE info.
auto hasInfoConfig() const noexcept -> bool
Multiboot contains valid config table info.
igros_quad_t fbAddress
Multiboot FB address.
igros_dword_t mmapAddr
Multiboot memory map start address.
igros_dword_t vbeControlInfo
Multiboot VBE control info.
igros_dword_t memLow
Multiboot bios memory low info.
auto hasInfoModules() const noexcept -> bool
Multiboot contains valid kernel modules info.
void printFBInfo() const noexcept
Print multiboot FB info.
igros_dword_t fbPitch
Multiboot FB pitch.
klib::kFlags< flags_t > flags
Multiboot present features flag.
Definition multiboot.hpp:99
igros_byte_t fbBpp
Multiboot FB bpp.
auto hasInfoAOUT() const noexcept -> bool
Multiboot contains valid A.OUT sections info.
igros_byte_t fbType
Multiboot FB type.
auto hasInfoAPM() const noexcept -> bool
Multiboot contains valid APM table info.
auto loaderName() const noexcept -> const char *
Get multiboot bootloader name.
igros_dword_t bootDevice
Multiboot boot device.
igros_dword_t apmTable
Multiboot APM table.
igros_dword_t configTable
Multiboot config table.
auto hasInfoELF() const noexcept -> bool
Multiboot contains valid ELF sections info.
igros_word_t vbeInterfaceLen
Multiboot VBE interface length.
auto hasInfoFrameBuffer() const noexcept -> bool
Multiboot contains valid FrameBuffer info.
void printMemMap() const noexcept
Print multiboot memory map.
igros_dword_t mmapLength
Multiboot memory map length.
igros_dword_t drivesLength
Multiboot drives info length.
auto hasInfoCommandLine() const noexcept -> bool
Multiboot contains valid kernel command line info.
igros_dword_t drivesAddr
Multiboot drives info start address.
igros_dword_t bootloaderName
Multiboot bootloader name.
igros_word_t vbeModeCurrent
Multiboot VBE current mode.
void printHeader() const noexcept
Print kernel header.
auto hasInfoMemory() const noexcept -> bool
Multiboot contains valid memory info.
std::array< igros_byte_t, 6_usize > fbColorInfo
Multiboot FB color info.
igros_dword_t modulesAddr
Multiboot kernel modules address.
auto commandLine() const noexcept -> const char *
Get multiboot command line.
std::array< igros_dword_t, 4_usize > syms
Multiboot kernel symbols.
igros_word_t vbeInterfaceOffset
Multiboot VBE interface offset.
auto hasInfoMemoryMap() const noexcept -> bool
Multiboot contains valid memory map info.
igros_dword_t vbeModeInfo
Multiboot VBE mode info.
void test(const igros_dword_t magic) const noexcept
Test multiboot.
Definition multiboot.cpp:63
igros_dword_t fbHeight
Multiboot FB height.
auto memoryMap() const noexcept -> memoryMap_t
Get multiboot memory map (empty if not provided).
igros_dword_t fbWidth
Multiboot FB width.
void printMemInfo() const noexcept
Print multiboot memory info.
Definition multiboot.cpp:98
auto hasInfoVBE() const noexcept -> bool
Multiboot contains valid VBE info.
igros_word_t vbeInterfaceSeg
Multiboot VBE interface segment.
igros_dword_t modulesCount
Multiboot kernel modules count.
auto hasInfoBootloaderName() const noexcept -> bool
Multiboot contains valid bootloader name info.
void printFlags() const noexcept
Print multiboot flags.
Definition multiboot.cpp:78
auto hasInfoDrives() const noexcept -> bool
Multiboot contains valid drives info.
igros_dword_t memHigh
Multiboot bios memory high info.
igros_dword_t cmdLine
Multiboot bootloader command line.
Multiboot 1 memory map entry.
igros_dword_t size
Memory entry size.
igros_quad_t length
Memory entry length.
MEMORY_MAP_TYPE type
Memory entry type.
igros_quad_t address
Memory entry address.
const igros_byte_t * end
Memory map end.
Multiboot 1 module entry.
igros_dword_t end
Module end address.
igros_dword_t name
Module name string.
igros_dword_t start
Module start address.
igros_dword_t reserved
Reserved.
igros_dword_t oem
OEM string.
igros_word_t memory
VBE video memory size in 64 Kb. blocks.
igros_word_t rev
VBE revision string.
igros_dword_t productRev
VBE product revision string.
igros_word_t version
VBE version (e.g. 0x0300 = 3.0).
igros_dword_t modes
VBE modes pointer.
std::array< igros_sbyte_t, 4_usize > signature
VBE signature ("VESA").
igros_dword_t caps
VBE capabilities.
igros_dword_t vendor
VBE vendor string.
igros_dword_t productName
VBE product name string.
std::array< std::byte, 256_usize > oemData
VBE OEM data.
std::array< std::byte, 222_usize > reserved
VBE reserved.
igros_word_t segmentA
Window A segment.
igros_byte_t banks
Number of banks.
igros_word_t segmentB
Window B segment.
igros_byte_t blueMask
Blue mask size.
igros_dword_t reserved1
Reserved.
igros_byte_t bankSize
Bank size in KB.
igros_word_t pitch
Bytes per scan line.
igros_byte_t reservedMask
Reserved mask size.
igros_byte_t greenPosition
Green field position.
igros_byte_t memoryModel
Memory model (6 - direct color).
igros_byte_t redMask
Red mask size.
igros_word_t height
Height in pixels (characters in text modes).
igros_dword_t funcPtr
Window positioning function (real mode).
igros_dword_t physbase
Linear frame buffer physical address.
igros_word_t windowSize
Window size in KB.
igros_byte_t reservedPosition
Reserved field position.
igros_byte_t imagePages
Number of extra image pages.
igros_word_t width
Width in pixels (characters in text modes).
igros_byte_t charW
Character cell width.
igros_byte_t windowA
Window A attributes.
igros_byte_t directColorAttributes
Direct color mode attributes.
igros_byte_t charH
Character cell height.
igros_word_t attributes
Mode attributes (bit 7 - linear frame buffer).
igros_byte_t reserved0
Reserved.
igros_byte_t redPosition
Red field position.
igros_byte_t planes
Number of memory planes.
igros_word_t reserved2
Reserved.
igros_byte_t greenMask
Green mask size.
igros_byte_t bluePosition
Blue field position.
igros_word_t granularity
Window granularity in KB.
igros_byte_t bpp
Bits per pixel.
igros_byte_t windowB
Window B attributes.
Common C++ types redefinition.