Renamed elf.cpp to module.cpp, started Module class
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
#include "elf.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
kernel::ELF::ELF()
|
||||
{
|
||||
this->m_fileLocation = (void*) NULL;
|
||||
}
|
||||
|
||||
kernel::ELF::ELF(void* location)
|
||||
{
|
||||
this->location = location;
|
||||
this->m_fileLocation = location;
|
||||
}
|
||||
|
||||
void* kernel::ELF::entry()
|
||||
{
|
||||
Header* fileHeader = (Header*) location;
|
||||
Header* fileHeader = (Header*) m_fileLocation;
|
||||
return fileHeader->entry;
|
||||
}
|
||||
|
||||
int kernel::ELF::validate()
|
||||
{
|
||||
Header* fileHeader = (Header*) location;
|
||||
Header* fileHeader = (Header*) m_fileLocation;
|
||||
if(fileHeader->magic != 0x464c457f)
|
||||
return -1;
|
||||
else if((ISA) fileHeader->machine != HOST_ISA)
|
||||
@@ -26,14 +31,14 @@ int kernel::ELF::validate()
|
||||
|
||||
int kernel::ELF::load()
|
||||
{
|
||||
Header* fileHeader = (Header*) location;
|
||||
ProgramHeader* programHeader = (ProgramHeader*) ((size_t) location + fileHeader->phoffset);
|
||||
Header* fileHeader = (Header*) m_fileLocation;
|
||||
ProgramHeader* programHeader = (ProgramHeader*) ((size_t) m_fileLocation + fileHeader->phoffset);
|
||||
int count = (int) fileHeader->phcount;
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
if((SegmentType) programHeader->type != Load)
|
||||
continue;
|
||||
memcpy(programHeader->vaddr, location + programHeader->offset, programHeader->filesize);
|
||||
memcpy(programHeader->vaddr, m_fileLocation + programHeader->offset, programHeader->filesize);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -123,6 +123,8 @@ public:
|
||||
static const ISA HOST_ISA = aarch64;
|
||||
#endif
|
||||
|
||||
ELF();
|
||||
|
||||
ELF(void* location);
|
||||
|
||||
void* entry();
|
||||
@@ -133,7 +135,25 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void* location;
|
||||
void* m_fileLocation;
|
||||
|
||||
};
|
||||
|
||||
class Module
|
||||
{
|
||||
public:
|
||||
|
||||
Module();
|
||||
|
||||
Module(physaddr_t start, physaddr_t end);
|
||||
|
||||
private:
|
||||
|
||||
physaddr_t m_start;
|
||||
|
||||
physaddr_t m_end;
|
||||
|
||||
ELF binary;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user