Skip to content

Commit

Permalink
Cleanup boot info
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Łukasik committed Oct 11, 2024
1 parent ad06f96 commit f165517
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
20 changes: 9 additions & 11 deletions src/impl/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ boot_framebuffer* BootInfo::get_framebuffer() const {

memory_map_entry** BootInfo::get_memory_maps()
{
if (memory_entry == nullptr) kernel_panic("BootInfo not parsed!", BootInfoNotParsed);

return memory_entry;
}

Expand Down Expand Up @@ -82,11 +80,11 @@ void BootInfo::log()
}
}

void BootInfo::parse(boot_info* boot_info)
BootInfo::BootInfo(boot_info* boot_info)
{
const auto start = reinterpret_cast<pt::uintptr_t>(boot_info);
this->size = boot_info->size;
const pt::uintptr_t end = start + size;
const pt::uintptr_t end = start + this->size;
pt::uintptr_t ptr = start + 8;

while (ptr < end)
Expand All @@ -101,30 +99,30 @@ void BootInfo::parse(boot_info* boot_info)
{
case BOOT_CMDLINE:
{
cmd_line = reinterpret_cast<boot_command_line *>(ptr);
this->cmd_line = reinterpret_cast<boot_command_line *>(ptr);
break;
}
case BOOT_LOADER_NAME:
{
loader_name = reinterpret_cast<boot_loader_name *>(ptr);
this->loader_name = reinterpret_cast<boot_loader_name *>(ptr);
break;
}
case BOOT_BASIC_MEM:
{
basic_mem = reinterpret_cast<boot_basic_memory *>(ptr);
this->basic_mem = reinterpret_cast<boot_basic_memory *>(ptr);
break;
}
case BOOT_BIOS:
{
bios = reinterpret_cast<boot_bios_device *>(ptr);
this->bios = reinterpret_cast<boot_bios_device *>(ptr);
break;
}
case BOOT_MMAP:
{
mmap = reinterpret_cast<boot_memory_map *>(ptr);
this->mmap = reinterpret_cast<boot_memory_map *>(ptr);
auto mem_current = reinterpret_cast<pt::uintptr_t>(&mmap->entries);
const pt::uintptr_t mem_end = mem_current + mmap->size - 4*sizeof(pt::uint32_t);
for (auto & map_entry : memory_entry)
for (auto & map_entry : this->memory_entry)
{
map_entry = nullptr;
}
Expand All @@ -133,7 +131,7 @@ void BootInfo::parse(boot_info* boot_info)
{
if (i >= MEMORY_ENTRIES_LIMIT) kernel_panic("Memory entries limit reached", MemEntriesLimitReached);
auto* entry = reinterpret_cast<memory_map_entry *>(mem_current);
memory_entry[i] = entry;
this->memory_entry[i] = entry;
i++;
mem_current += mmap->entry_size;
}
Expand Down
3 changes: 1 addition & 2 deletions src/impl/kernel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
extern const char Logo[];
extern const unsigned char PotatoLogo[];
extern char get_char();
static BootInfo bi;
static IDT idt;
VMM vmm;

Expand Down Expand Up @@ -63,7 +62,7 @@ constexpr char pci_cmd[] = "pci";
ASMCALL void kernel_main(boot_info* boot_info, void* l4_page_table) {
klog("[MAIN] Welcome to 64-bit potat OS\n");

bi.parse(boot_info);
auto bi = BootInfo(boot_info);

const auto boot_fb = bi.get_framebuffer();

Expand Down
6 changes: 3 additions & 3 deletions src/intf/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ struct boot_vbe_info
} __attribute__((packed));

#define MEMORY_ENTRIES_LIMIT 7

class BootInfo
{
pt::size_t size;
Expand All @@ -154,10 +153,11 @@ class BootInfo
boot_apm_table* apm_table;
boot_acpi* acpi;
boot_loader_physical_address* physical;
memory_map_entry* memory_entry[MEMORY_ENTRIES_LIMIT];
memory_map_entry* memory_entry[MEMORY_ENTRIES_LIMIT]{};
void log();
BootInfo() = default;
public:
void parse(boot_info *boot_info);
explicit BootInfo(boot_info *boot_info);
[[nodiscard]] boot_framebuffer* get_framebuffer() const;
memory_map_entry** get_memory_maps();
};
2 changes: 1 addition & 1 deletion src/intf/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Framebuffer
pt::uint32_t x, pt::uint32_t y) const;
public:
Framebuffer()=default;
Framebuffer(const boot_framebuffer *fb) : Framebuffer(
explicit Framebuffer(const boot_framebuffer *fb) : Framebuffer(
fb->framebuffer_addr,
fb->framebuffer_width,
fb->framebuffer_height,
Expand Down

0 comments on commit f165517

Please sign in to comment.