20#include "pedigree/kernel/BootstrapInfo.h"
21#include "pedigree/kernel/compiler.h"
22#include "pedigree/kernel/processor/types.h"
25 "bootstrap memory-map entries must match the UEFI wire format");
26static_assert(
sizeof(
BootstrapStruct_t) == 108,
"bootstrap wire layout must match the UEFI loader");
28BootstrapStruct_t::BootstrapStruct_t() {
33void BootstrapStruct_t::setMemoryMap(
const MemoryMapEntry* entries,
size_t count) {
34 mmap_addr =
reinterpret_cast<uintptr_t
>(entries);
35 mmap_entry_size =
sizeof(MemoryMapEntry);
36 mmap_length = count * mmap_entry_size;
37 flags |= BOOTSTRAP_FLAG_MEMORY_MAP;
40void BootstrapStruct_t::setModules(
const Module* modules,
size_t count) {
41 mods_addr =
reinterpret_cast<uintptr_t
>(modules);
43 flags |= BOOTSTRAP_FLAG_MODULES;
46void BootstrapStruct_t::setCommandLine(
const char* text) {
47 cmdline =
reinterpret_cast<uintptr_t
>(text);
48 flags |= BOOTSTRAP_FLAG_CMDLINE;
51void BootstrapStruct_t::setUefi() {
52 flags |= BOOTSTRAP_FLAG_UEFI;
55void BootstrapStruct_t::setAcpiRsdp(uintptr_t address) {
57 flags |= BOOTSTRAP_FLAG_ACPI;
60bool BootstrapStruct_t::isInitrdLoaded()
const {
61 if (flags & BOOTSTRAP_FLAG_MODULES)
62 return (mods_count != 0) && mods_addr;
67uint8_t* BootstrapStruct_t::getInitrdAddress()
const {
68 const Module* modules = getModuleArray();
69 if (isInitrdLoaded() && modules)
70 return reinterpret_cast<uint8_t*
>(modules[0].base);
75size_t BootstrapStruct_t::getInitrdSize()
const {
76 const Module* modules = getModuleArray();
77 if (isInitrdLoaded() && modules)
78 return modules[0].end - modules[0].base;
83char* BootstrapStruct_t::getCommandLine()
const {
84 if (flags & BOOTSTRAP_FLAG_CMDLINE)
85 return reinterpret_cast<char*
>(cmdline);
90size_t BootstrapStruct_t::getSectionHeaderCount()
const {
91 if (flags & BOOTSTRAP_FLAG_ELF)
97size_t BootstrapStruct_t::getSectionHeaderEntrySize()
const {
98 if (flags & BOOTSTRAP_FLAG_ELF)
104size_t BootstrapStruct_t::getSectionHeaderStringTableIndex()
const {
105 if (flags & BOOTSTRAP_FLAG_ELF)
111uintptr_t BootstrapStruct_t::getSectionHeaders()
const {
112 if (flags & BOOTSTRAP_FLAG_ELF)
118void* BootstrapStruct_t::getMemoryMap()
const {
119 if (flags & BOOTSTRAP_FLAG_MEMORY_MAP)
120 return reinterpret_cast<void*
>(mmap_addr);
125uint64_t BootstrapStruct_t::getMemoryMapEntryAddress(
void* opaque)
const {
129 MemoryMapEntry* entry =
reinterpret_cast<MemoryMapEntry*
>(opaque);
130 return entry->address;
133uint64_t BootstrapStruct_t::getMemoryMapEntryLength(
void* opaque)
const {
137 MemoryMapEntry* entry =
reinterpret_cast<MemoryMapEntry*
>(opaque);
138 return entry->length;
141uint32_t BootstrapStruct_t::getMemoryMapEntryType(
void* opaque)
const {
145 MemoryMapEntry* entry =
reinterpret_cast<MemoryMapEntry*
>(opaque);
149void* BootstrapStruct_t::nextMemoryMapEntry(
void* opaque)
const {
153 MemoryMapEntry* entry =
reinterpret_cast<MemoryMapEntry*
>(opaque);
154 uintptr_t entry_addr =
reinterpret_cast<uintptr_t
>(opaque);
155 const uintptr_t entry_size = mmap_entry_size ? mmap_entry_size :
sizeof(MemoryMapEntry);
156 void* new_opaque =
reinterpret_cast<void*
>(entry_addr + entry_size);
158 if (
reinterpret_cast<uintptr_t
>(new_opaque) >= (mmap_addr + mmap_length))
164size_t BootstrapStruct_t::getModuleCount()
const {
165 if (flags & BOOTSTRAP_FLAG_MODULES)
171void* BootstrapStruct_t::getModuleBase()
const {
172 if (flags & BOOTSTRAP_FLAG_MODULES)
173 return reinterpret_cast<void*
>(mods_addr);
178uintptr_t BootstrapStruct_t::getAcpiRsdp()
const {
179 return (flags & BOOTSTRAP_FLAG_ACPI) ? acpi_rsdp : 0;
182uintptr_t BootstrapStruct_t::getSmbios()
const {
183 return (flags & BOOTSTRAP_FLAG_SMBIOS) ? smbios : 0;
186bool BootstrapStruct_t::isUefi()
const {
187 return (flags & BOOTSTRAP_FLAG_UEFI) != 0;
190bool BootstrapStruct_t::getFramebuffer(FramebufferInfo& info)
const {
191 if (!(flags & BOOTSTRAP_FLAG_FRAMEBUFFER) || !framebuffer || !framebuffer_width ||
192 !framebuffer_height || framebuffer_bpp != 32 || framebuffer_format > 1 ||
193 framebuffer_width > ~uint32_t(0) / 4 || framebuffer_pitch < framebuffer_width * 4 ||
194 (framebuffer_pitch & 3) ||
195 static_cast<uint64_t
>(framebuffer_pitch) * framebuffer_height > ~uint64_t(0) - framebuffer)
197 info = {framebuffer, framebuffer_width, framebuffer_height,
198 framebuffer_pitch, framebuffer_bpp, framebuffer_format};