Wrote new Multiboot2 table reader
This commit is contained in:
78
src/x86/multiboot2.cpp
Normal file
78
src/x86/multiboot2.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "multiboot2.hpp"
|
||||
|
||||
using namespace kernel;
|
||||
|
||||
Multiboot2Info::Multiboot2Info(void* tableLocation)
|
||||
{
|
||||
m_commandLine = NULL;
|
||||
m_bootloader = NULL;
|
||||
m_moduleCount = 0;
|
||||
uint32_t* ptr = (uint32_t*) tableLocation;
|
||||
ptr += 2;
|
||||
while(*ptr != 0)
|
||||
{
|
||||
if(*ptr == T_BootCommand)
|
||||
{
|
||||
m_commandLine = &reinterpret_cast<TagString*>(ptr)->str;
|
||||
}
|
||||
else if(*ptr == T_Bootloader)
|
||||
{
|
||||
m_bootloader = &reinterpret_cast<TagString*>(ptr)->str;
|
||||
}
|
||||
else if(*ptr == T_MemoryMap)
|
||||
{
|
||||
unsigned int tagSize = reinterpret_cast<TagMemoryMap*>(ptr)->size - 16;
|
||||
unsigned int entrySize = reinterpret_cast<TagMemoryMap*>(ptr)->entrySize;
|
||||
MemoryMapEntry* entry = &reinterpret_cast<TagMemoryMap*>(ptr)->entries;
|
||||
while(tagSize > 0)
|
||||
{
|
||||
m_memmap.insertEntry(entry->base, entry->length, (MemoryMap::Type) entry->type);
|
||||
entry = (MemoryMapEntry*) (reinterpret_cast<char*>(entry) + entrySize);
|
||||
tagSize -= entrySize;
|
||||
}
|
||||
}
|
||||
else if(*ptr == T_Module)
|
||||
{
|
||||
TagModule* moduleTag = reinterpret_cast<TagModule*>(ptr);
|
||||
m_modules[m_moduleCount] = Module(moduleTag->start, moduleTag->end, &moduleTag->str);
|
||||
m_memmap.insertEntry(moduleTag->start, moduleTag->end - moduleTag->start, MemoryMap::UNAVAILABLE);
|
||||
}
|
||||
unsigned int size = (ptr[1] + 7) - ((ptr[1] + 7) % 8);
|
||||
ptr += size / sizeof(uint32_t);
|
||||
}
|
||||
}
|
||||
|
||||
Multiboot2Info::~Multiboot2Info()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Multiboot2Info::isValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
MemoryMap& Multiboot2Info::getMemoryMap()
|
||||
{
|
||||
return m_memmap;
|
||||
}
|
||||
|
||||
const Module* Multiboot2Info::getModules() const
|
||||
{
|
||||
return m_modules;
|
||||
}
|
||||
|
||||
unsigned int Multiboot2Info::getModuleCount() const
|
||||
{
|
||||
return m_moduleCount;
|
||||
}
|
||||
|
||||
const char* Multiboot2Info::getCommandLine() const
|
||||
{
|
||||
return m_commandLine;
|
||||
}
|
||||
|
||||
const char* Multiboot2Info::getBootloaderName() const
|
||||
{
|
||||
return m_bootloader;
|
||||
}
|
||||
105
src/x86/multiboot2.hpp
Normal file
105
src/x86/multiboot2.hpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#ifndef MULTIBOOT2_H
|
||||
#define MULTIBOOT2_H
|
||||
|
||||
#include "../memorymap.hpp"
|
||||
#include "../module.hpp"
|
||||
|
||||
namespace kernel
|
||||
{
|
||||
|
||||
class Multiboot2Info
|
||||
{
|
||||
public:
|
||||
|
||||
enum TagType
|
||||
{
|
||||
T_BootCommand = 1,
|
||||
T_Bootloader = 2,
|
||||
T_Module = 3,
|
||||
T_MemoryInfo = 4,
|
||||
T_BIOSBootDevice = 5,
|
||||
T_MemoryMap = 6,
|
||||
T_VBE = 7,
|
||||
T_Framebuffer = 8,
|
||||
T_ELFSymbols = 9,
|
||||
T_APM = 10,
|
||||
T_EFI32SystemTable = 11,
|
||||
T_EFI64SystemTable = 12,
|
||||
T_SMBIOS = 13,
|
||||
T_ACPI10RSDP = 14,
|
||||
T_ACPT20RSDP = 15,
|
||||
T_Network = 16,
|
||||
T_EFIMemoryMap = 17,
|
||||
T_EFIBootServices = 18,
|
||||
T_EFI32Image = 19,
|
||||
T_EFI64Image = 20,
|
||||
T_LoadAddress = 21
|
||||
};
|
||||
|
||||
struct TagString
|
||||
{
|
||||
uint32_t type;
|
||||
uint32_t size;
|
||||
char str;
|
||||
};
|
||||
|
||||
struct TagModule
|
||||
{
|
||||
uint32_t type;
|
||||
uint32_t size;
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
char str;
|
||||
};
|
||||
|
||||
struct MemoryMapEntry
|
||||
{
|
||||
uint64_t base;
|
||||
uint64_t length;
|
||||
uint32_t type;
|
||||
};
|
||||
|
||||
struct TagMemoryMap
|
||||
{
|
||||
uint32_t type;
|
||||
uint32_t size;
|
||||
uint32_t entrySize;
|
||||
uint32_t entryVersion;
|
||||
MemoryMapEntry entries;
|
||||
};
|
||||
|
||||
Multiboot2Info(void* tableLocation);
|
||||
|
||||
~Multiboot2Info();
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
MemoryMap& getMemoryMap();
|
||||
|
||||
const Module* getModules() const;
|
||||
|
||||
unsigned int getModuleCount() const;
|
||||
|
||||
const char* getCommandLine() const;
|
||||
|
||||
const char* getBootloaderName() const;
|
||||
|
||||
private:
|
||||
|
||||
Module m_modules[16];
|
||||
|
||||
unsigned int m_moduleCount;
|
||||
|
||||
MemoryMap m_memmap;
|
||||
|
||||
char* m_commandLine;
|
||||
|
||||
char* m_bootloader;
|
||||
|
||||
void* m_tableLocation;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user