Kernel: Use enums in boot info instead of magic values
This commit is contained in:
parent
4ba33175cf
commit
2b43569927
|
@ -8,28 +8,36 @@
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class FramebufferType
|
|
||||||
{
|
|
||||||
NONE,
|
|
||||||
UNKNOWN,
|
|
||||||
RGB
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FramebufferInfo
|
struct FramebufferInfo
|
||||||
{
|
{
|
||||||
|
enum class Type
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Unknown,
|
||||||
|
RGB,
|
||||||
|
};
|
||||||
|
|
||||||
paddr_t address;
|
paddr_t address;
|
||||||
uint32_t pitch;
|
uint32_t pitch;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint8_t bpp;
|
uint8_t bpp;
|
||||||
FramebufferType type = FramebufferType::NONE;
|
Type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MemoryMapEntry
|
struct MemoryMapEntry
|
||||||
{
|
{
|
||||||
uint32_t type;
|
enum class Type
|
||||||
|
{
|
||||||
|
Available,
|
||||||
|
Reserved,
|
||||||
|
ACPIReclaim,
|
||||||
|
ACPINVS,
|
||||||
|
};
|
||||||
|
|
||||||
paddr_t address;
|
paddr_t address;
|
||||||
uint64_t length;
|
uint64_t length;
|
||||||
|
Type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BootInfo
|
struct BootInfo
|
||||||
|
@ -38,6 +46,7 @@ namespace Kernel
|
||||||
FramebufferInfo framebuffer {};
|
FramebufferInfo framebuffer {};
|
||||||
RSDP rsdp {};
|
RSDP rsdp {};
|
||||||
paddr_t kernel_paddr {};
|
paddr_t kernel_paddr {};
|
||||||
|
|
||||||
BAN::Vector<MemoryMapEntry> memory_map_entries;
|
BAN::Vector<MemoryMapEntry> memory_map_entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,18 @@ namespace Kernel
|
||||||
|
|
||||||
BootInfo g_boot_info;
|
BootInfo g_boot_info;
|
||||||
|
|
||||||
|
static MemoryMapEntry::Type bios_number_to_memory_type(uint32_t number)
|
||||||
|
{
|
||||||
|
switch (number)
|
||||||
|
{
|
||||||
|
case 1: return MemoryMapEntry::Type::Available;
|
||||||
|
case 2: return MemoryMapEntry::Type::Reserved;
|
||||||
|
case 3: return MemoryMapEntry::Type::ACPIReclaim;
|
||||||
|
case 4: return MemoryMapEntry::Type::ACPINVS;
|
||||||
|
}
|
||||||
|
return MemoryMapEntry::Type::Reserved;
|
||||||
|
}
|
||||||
|
|
||||||
static void parse_boot_info_multiboot2(uint32_t info)
|
static void parse_boot_info_multiboot2(uint32_t info)
|
||||||
{
|
{
|
||||||
const auto& multiboot2_info = *reinterpret_cast<const multiboot2_info_t*>(info);
|
const auto& multiboot2_info = *reinterpret_cast<const multiboot2_info_t*>(info);
|
||||||
|
@ -27,9 +39,9 @@ namespace Kernel
|
||||||
g_boot_info.framebuffer.height = framebuffer_tag.framebuffer_height;
|
g_boot_info.framebuffer.height = framebuffer_tag.framebuffer_height;
|
||||||
g_boot_info.framebuffer.bpp = framebuffer_tag.framebuffer_bpp;
|
g_boot_info.framebuffer.bpp = framebuffer_tag.framebuffer_bpp;
|
||||||
if (framebuffer_tag.framebuffer_type == MULTIBOOT2_FRAMEBUFFER_TYPE_RGB)
|
if (framebuffer_tag.framebuffer_type == MULTIBOOT2_FRAMEBUFFER_TYPE_RGB)
|
||||||
g_boot_info.framebuffer.type = FramebufferType::RGB;
|
g_boot_info.framebuffer.type = FramebufferInfo::Type::RGB;
|
||||||
else
|
else
|
||||||
g_boot_info.framebuffer.type = FramebufferType::UNKNOWN;
|
g_boot_info.framebuffer.type = FramebufferInfo::Type::Unknown;
|
||||||
}
|
}
|
||||||
else if (tag->type == MULTIBOOT2_TAG_MMAP)
|
else if (tag->type == MULTIBOOT2_TAG_MMAP)
|
||||||
{
|
{
|
||||||
|
@ -49,7 +61,7 @@ namespace Kernel
|
||||||
);
|
);
|
||||||
g_boot_info.memory_map_entries[i].address = mmap_entry.base_addr;
|
g_boot_info.memory_map_entries[i].address = mmap_entry.base_addr;
|
||||||
g_boot_info.memory_map_entries[i].length = mmap_entry.length;
|
g_boot_info.memory_map_entries[i].length = mmap_entry.length;
|
||||||
g_boot_info.memory_map_entries[i].type = mmap_entry.type;
|
g_boot_info.memory_map_entries[i].type = bios_number_to_memory_type(mmap_entry.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (tag->type == MULTIBOOT2_TAG_OLD_RSDP)
|
else if (tag->type == MULTIBOOT2_TAG_OLD_RSDP)
|
||||||
|
@ -87,15 +99,15 @@ namespace Kernel
|
||||||
MUST(g_boot_info.command_line.append(command_line));
|
MUST(g_boot_info.command_line.append(command_line));
|
||||||
|
|
||||||
const auto& framebuffer = *reinterpret_cast<BananBootFramebufferInfo*>(banan_bootloader_info.framebuffer_addr);
|
const auto& framebuffer = *reinterpret_cast<BananBootFramebufferInfo*>(banan_bootloader_info.framebuffer_addr);
|
||||||
if (framebuffer.type == BANAN_BOOTLOADER_FB_RGB)
|
|
||||||
{
|
|
||||||
g_boot_info.framebuffer.address = framebuffer.address;
|
g_boot_info.framebuffer.address = framebuffer.address;
|
||||||
g_boot_info.framebuffer.width = framebuffer.width;
|
g_boot_info.framebuffer.width = framebuffer.width;
|
||||||
g_boot_info.framebuffer.height = framebuffer.height;
|
g_boot_info.framebuffer.height = framebuffer.height;
|
||||||
g_boot_info.framebuffer.pitch = framebuffer.pitch;
|
g_boot_info.framebuffer.pitch = framebuffer.pitch;
|
||||||
g_boot_info.framebuffer.bpp = framebuffer.bpp;
|
g_boot_info.framebuffer.bpp = framebuffer.bpp;
|
||||||
g_boot_info.framebuffer.type = FramebufferType::RGB;
|
if (framebuffer.type == BANAN_BOOTLOADER_FB_RGB)
|
||||||
}
|
g_boot_info.framebuffer.type = FramebufferInfo::Type::RGB;
|
||||||
|
else
|
||||||
|
g_boot_info.framebuffer.type = FramebufferInfo::Type::Unknown;
|
||||||
|
|
||||||
const auto& memory_map = *reinterpret_cast<BananBootloaderMemoryMapInfo*>(banan_bootloader_info.memory_map_addr);
|
const auto& memory_map = *reinterpret_cast<BananBootloaderMemoryMapInfo*>(banan_bootloader_info.memory_map_addr);
|
||||||
MUST(g_boot_info.memory_map_entries.resize(memory_map.entry_count));
|
MUST(g_boot_info.memory_map_entries.resize(memory_map.entry_count));
|
||||||
|
@ -104,7 +116,7 @@ namespace Kernel
|
||||||
const auto& mmap_entry = memory_map.entries[i];
|
const auto& mmap_entry = memory_map.entries[i];
|
||||||
g_boot_info.memory_map_entries[i].address = mmap_entry.address;
|
g_boot_info.memory_map_entries[i].address = mmap_entry.address;
|
||||||
g_boot_info.memory_map_entries[i].length = mmap_entry.length;
|
g_boot_info.memory_map_entries[i].length = mmap_entry.length;
|
||||||
g_boot_info.memory_map_entries[i].type = mmap_entry.type;
|
g_boot_info.memory_map_entries[i].type = bios_number_to_memory_type(mmap_entry.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_boot_info.kernel_paddr = banan_bootloader_info.kernel_paddr;
|
g_boot_info.kernel_paddr = banan_bootloader_info.kernel_paddr;
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Kernel
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::RefPtr<FramebufferDevice>> FramebufferDevice::create_from_boot_framebuffer()
|
BAN::ErrorOr<BAN::RefPtr<FramebufferDevice>> FramebufferDevice::create_from_boot_framebuffer()
|
||||||
{
|
{
|
||||||
if (g_boot_info.framebuffer.type != FramebufferType::RGB)
|
if (g_boot_info.framebuffer.type != FramebufferInfo::Type::RGB)
|
||||||
return BAN::Error::from_errno(ENODEV);
|
return BAN::Error::from_errno(ENODEV);
|
||||||
if (g_boot_info.framebuffer.bpp != 24 && g_boot_info.framebuffer.bpp != 32)
|
if (g_boot_info.framebuffer.bpp != 24 && g_boot_info.framebuffer.bpp != 32)
|
||||||
return BAN::Error::from_errno(ENOTSUP);
|
return BAN::Error::from_errno(ENOTSUP);
|
||||||
|
|
|
@ -26,17 +26,36 @@ namespace Kernel
|
||||||
void Heap::initialize_impl()
|
void Heap::initialize_impl()
|
||||||
{
|
{
|
||||||
if (g_boot_info.memory_map_entries.empty())
|
if (g_boot_info.memory_map_entries.empty())
|
||||||
Kernel::panic("Bootloader did not provide a memory map");
|
panic("Bootloader did not provide a memory map");
|
||||||
|
|
||||||
for (const auto& entry : g_boot_info.memory_map_entries)
|
for (const auto& entry : g_boot_info.memory_map_entries)
|
||||||
{
|
{
|
||||||
dprintln("{16H}, {16H}, {8H}",
|
const char* entry_type_string = nullptr;
|
||||||
|
switch (entry.type)
|
||||||
|
{
|
||||||
|
case MemoryMapEntry::Type::Available:
|
||||||
|
entry_type_string = "available";
|
||||||
|
break;
|
||||||
|
case MemoryMapEntry::Type::Reserved:
|
||||||
|
entry_type_string = "reserved";
|
||||||
|
break;
|
||||||
|
case MemoryMapEntry::Type::ACPIReclaim:
|
||||||
|
entry_type_string = "acpi reclaim";
|
||||||
|
break;
|
||||||
|
case MemoryMapEntry::Type::ACPINVS:
|
||||||
|
entry_type_string = "acpi nvs";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
dprintln("{16H}, {16H}, {}",
|
||||||
entry.address,
|
entry.address,
|
||||||
entry.length,
|
entry.length,
|
||||||
entry.type
|
entry_type_string
|
||||||
);
|
);
|
||||||
|
|
||||||
if (entry.type != 1)
|
if (entry.type != MemoryMapEntry::Type::Available)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
paddr_t start = entry.address;
|
paddr_t start = entry.address;
|
||||||
|
@ -79,7 +98,7 @@ namespace Kernel
|
||||||
for (auto& range : m_physical_ranges)
|
for (auto& range : m_physical_ranges)
|
||||||
if (range.contains(paddr))
|
if (range.contains(paddr))
|
||||||
return range.release_page(paddr);
|
return range.release_page(paddr);
|
||||||
ASSERT_NOT_REACHED();
|
panic("tried to free invalid paddr {16H}", paddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
paddr_t Heap::take_free_contiguous_pages(size_t pages)
|
paddr_t Heap::take_free_contiguous_pages(size_t pages)
|
||||||
|
|
Loading…
Reference in New Issue