ELF format now supports 32-bit. Added ability to add instructions to a respective architecture that stores the op code.
This commit is contained in:
parent
1ba2e97943
commit
ee8e4d37ff
@ -26,24 +26,31 @@ endif ()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(Arctyx
|
||||
include/arctyx/ELF_Architecture.h
|
||||
src/ELF_Sym.cpp include/arctyx/ELF_Sym.h
|
||||
src/ELF_Section.cpp include/arctyx/ELF_Section.h
|
||||
src/ELF_Program.cpp include/arctyx/ELF_Program.h
|
||||
src/ELF.cpp include/arctyx/ELF.h
|
||||
src/Linker.cpp include/arctyx/Linker.h
|
||||
src/Compiler.cpp include/arctyx/Compiler.h
|
||||
add_library(Arctyx SHARED
|
||||
include/arctyx/linker/formats/ELF_Architecture.h
|
||||
src/linker/formats/ELF_Sym.cpp include/arctyx/linker/formats/ELF_Sym.h
|
||||
src/linker/formats/ELF_Section.cpp include/arctyx/linker/formats/ELF_Section.h
|
||||
src/linker/formats/ELF_Program.cpp include/arctyx/linker/formats/ELF_Program.h
|
||||
src/linker/formats/ELF.cpp include/arctyx/linker/formats/ELF.h
|
||||
src/linker/Linker.cpp include/arctyx/linker/Linker.h
|
||||
src/compiler/Compiler.cpp include/arctyx/compiler/Compiler.h
|
||||
src/compiler/Architecture.cpp include/arctyx/compiler/Architecture.h
|
||||
src/compiler/Instruction.cpp include/arctyx/compiler/Instruction.h
|
||||
)
|
||||
|
||||
add_executable(Tools
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(Arctyx PRIVATE "${PROJECT_SOURCE_DIR}/include")
|
||||
target_include_directories(Arctyx PUBLIC "${PROJECT_SOURCE_DIR}/include")
|
||||
|
||||
if (IS_OS_LINUX)
|
||||
add_compile_definitions(LWE_WS_XCB)
|
||||
endif()
|
||||
|
||||
target_link_directories(Arctyx PRIVATE "${USER_HOME_DIRECTORY}/.local/lib")
|
||||
target_include_directories(Arctyx PRIVATE "${USER_HOME_DIRECTORY}/.local/include")
|
||||
target_link_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/lib")
|
||||
target_link_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/bin")
|
||||
target_include_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/include")
|
||||
|
||||
target_link_libraries(Arctyx PRIVATE xcb xcb-cursor xcb-xfixes xcb-xinput z asound EHS)
|
||||
target_link_libraries(Arctyx PUBLIC xcb xcb-cursor xcb-xfixes xcb-xinput z asound EHS_Dyn)
|
||||
target_link_libraries(Tools PRIVATE Arctyx)
|
40
include/arctyx/compiler/Architecture.h
Normal file
40
include/arctyx/compiler/Architecture.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <ehs/Array.h>
|
||||
|
||||
#include "Instruction.h"
|
||||
|
||||
class Architecture
|
||||
{
|
||||
private:
|
||||
ehs::UInt_64 id;
|
||||
ehs::Str_8 name;
|
||||
ehs::Array<Instruction> instructions;
|
||||
|
||||
public:
|
||||
Architecture();
|
||||
|
||||
Architecture(ehs::Str_8 name);
|
||||
|
||||
Architecture(Architecture &&arch) noexcept;
|
||||
|
||||
Architecture(const Architecture &arc);
|
||||
|
||||
Architecture &operator=(Architecture &&arc) noexcept;
|
||||
|
||||
Architecture &operator=(const Architecture &arc);
|
||||
|
||||
ehs::UInt_64 Id() const;
|
||||
|
||||
ehs::Str_8 GetName() const;
|
||||
|
||||
bool HasInstruction(const ehs::UInt_64 &id) const;
|
||||
|
||||
bool HasInstruction(const ehs::Str_8 &name) const;
|
||||
|
||||
const Instruction *GetInstruction(const ehs::UInt_64 &id) const;
|
||||
|
||||
const Instruction *GetInstruction(const ehs::Str_8 &name) const;
|
||||
|
||||
bool AddInstruction(Instruction ins);
|
||||
};
|
43
include/arctyx/compiler/Instruction.h
Normal file
43
include/arctyx/compiler/Instruction.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include <ehs/Str.h>
|
||||
#include <ehs/Types.h>
|
||||
|
||||
class Instruction
|
||||
{
|
||||
private:
|
||||
ehs::UInt_64 id;
|
||||
ehs::Str_8 name;
|
||||
ehs::UInt_8 size;
|
||||
ehs::Byte *code;
|
||||
|
||||
public:
|
||||
~Instruction();
|
||||
|
||||
Instruction();
|
||||
|
||||
Instruction(ehs::Str_8 name, const ehs::UInt_8 &size, ehs::Byte *code);
|
||||
|
||||
Instruction(ehs::Str_8 name, const ehs::UInt_64 &code);
|
||||
|
||||
Instruction(ehs::Str_8 name, const ehs::UInt_32 &code);
|
||||
|
||||
Instruction(ehs::Str_8 name, const ehs::UInt_16 &code);
|
||||
|
||||
Instruction(ehs::Str_8 name, const ehs::UInt_8 &code);
|
||||
|
||||
Instruction(Instruction &&ins) noexcept;
|
||||
|
||||
Instruction(const Instruction &ins);
|
||||
|
||||
Instruction &operator=(Instruction &&ins) noexcept;
|
||||
|
||||
Instruction &operator=(const Instruction &ins);
|
||||
|
||||
ehs::UInt_64 GetId() const;
|
||||
|
||||
ehs::Str_8 GetName() const;
|
||||
|
||||
ehs::UInt_8 GetSize() const;
|
||||
|
||||
ehs::Byte *GetCode() const;
|
||||
};
|
@ -14,7 +14,8 @@
|
||||
#define ELFH_TYPE_DYN 0x03
|
||||
|
||||
/// True header sizes.
|
||||
#define ELFH_SIZE 64
|
||||
#define ELF_64_BIT_HEADER_SIZE 64
|
||||
#define ELF_32_BIT_HEADER_SIZE 52
|
||||
|
||||
class ELF
|
||||
{
|
||||
@ -78,6 +79,10 @@ public:
|
||||
ehs::Serializer<ehs::UInt_64> Serialize() const;
|
||||
|
||||
private:
|
||||
void Serialize_64(ehs::Serializer<ehs::UInt_64> &data) const;
|
||||
|
||||
void Serialize_32(ehs::Serializer<ehs::UInt_64> &data) const;
|
||||
|
||||
void InitializeSections();
|
||||
|
||||
ehs::UInt_64 RetrieveSectionsOffset() const;
|
@ -49,5 +49,10 @@ public:
|
||||
|
||||
ehs::UInt_64 GetAlign() const;
|
||||
|
||||
void Serialize(ehs::Serializer<ehs::UInt_64>& inData) const;
|
||||
void Serialize(const ehs::UInt_8 &bitDepth, ehs::Serializer<ehs::UInt_64>& inData) const;
|
||||
|
||||
private:
|
||||
void Serialize_64(ehs::Serializer<ehs::UInt_64> &data) const;
|
||||
|
||||
void Serialize_32(ehs::Serializer<ehs::UInt_64> &data) const;
|
||||
};
|
@ -71,5 +71,10 @@ public:
|
||||
|
||||
ehs::Serializer<ehs::UInt_64>& GetData();
|
||||
|
||||
void Serialize(ehs::Serializer<ehs::UInt_64>& inData) const;
|
||||
void Serialize(const ehs::UInt_8 &bitDepth, ehs::Serializer<ehs::UInt_64>& inData) const;
|
||||
|
||||
private:
|
||||
void Serialize_64(ehs::Serializer<ehs::UInt_64> &data) const;
|
||||
|
||||
void Serialize_32(ehs::Serializer<ehs::UInt_64> &data) const;
|
||||
};
|
@ -1 +0,0 @@
|
||||
#include "arctyx/Compiler.h"
|
@ -1 +0,0 @@
|
||||
#include "arctyx/Linker.h"
|
93
src/compiler/Architecture.cpp
Normal file
93
src/compiler/Architecture.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
#include "arctyx/compiler/Architecture.h"
|
||||
|
||||
Architecture::Architecture()
|
||||
: id(0)
|
||||
{
|
||||
}
|
||||
|
||||
Architecture::Architecture(ehs::Str_8 name)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name)
|
||||
{
|
||||
}
|
||||
|
||||
Architecture::Architecture(Architecture &&arch) noexcept
|
||||
: id(arch.id), name((ehs::Str_8 &&)arch.name)
|
||||
{
|
||||
}
|
||||
|
||||
Architecture::Architecture(const Architecture &arc)
|
||||
: id(arc.id), name(arc.name)
|
||||
{
|
||||
}
|
||||
|
||||
Architecture & Architecture::operator=(Architecture &&arc) noexcept
|
||||
{
|
||||
if (this == &arc)
|
||||
return *this;
|
||||
|
||||
id = arc.id;
|
||||
name = (ehs::Str_8 &&)arc.name;
|
||||
|
||||
arc.id = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Architecture & Architecture::operator=(const Architecture &arc)
|
||||
{
|
||||
if (this == &arc)
|
||||
return *this;
|
||||
|
||||
id = arc.id;
|
||||
name = arc.name;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ehs::UInt_64 Architecture::Id() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
ehs::Str_8 Architecture::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
bool Architecture::HasInstruction(const ehs::UInt_64 &id) const
|
||||
{
|
||||
for (ehs::UInt_64 i = 0; i < instructions.Size(); ++i)
|
||||
if (instructions[i].GetId() == id)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Architecture::HasInstruction(const ehs::Str_8 &name) const
|
||||
{
|
||||
return HasInstruction(name.Hash_64());
|
||||
}
|
||||
|
||||
const Instruction *Architecture::GetInstruction(const ehs::UInt_64 &id) const
|
||||
{
|
||||
for (ehs::UInt_64 i = 0; i < instructions.Size(); ++i)
|
||||
if (instructions[i].GetId() == id)
|
||||
return &instructions[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Instruction *Architecture::GetInstruction(const ehs::Str_8 &name) const
|
||||
{
|
||||
return GetInstruction(name.Hash_64());
|
||||
}
|
||||
|
||||
bool Architecture::AddInstruction(Instruction ins)
|
||||
{
|
||||
if (HasInstruction(ins.GetId()))
|
||||
return false;
|
||||
|
||||
instructions.Push((Instruction &&)ins);
|
||||
|
||||
return true;
|
||||
}
|
1
src/compiler/Compiler.cpp
Normal file
1
src/compiler/Compiler.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "arctyx/compiler/Compiler.h"
|
106
src/compiler/Instruction.cpp
Normal file
106
src/compiler/Instruction.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
#include "arctyx/compiler/Instruction.h"
|
||||
|
||||
Instruction::~Instruction()
|
||||
{
|
||||
delete code;
|
||||
}
|
||||
|
||||
Instruction::Instruction()
|
||||
: id(0), size(0), code(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_8 &size, ehs::Byte *code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(size), code(code)
|
||||
{
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_64 &code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size])
|
||||
{
|
||||
*(ehs::UInt_64 *)this->code = code;
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_32 &code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size])
|
||||
{
|
||||
*(ehs::UInt_32 *)this->code = code;
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_16 &code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size])
|
||||
{
|
||||
*(ehs::UInt_16 *)this->code = code;
|
||||
}
|
||||
|
||||
Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_8 &code)
|
||||
: id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size])
|
||||
{
|
||||
*this->code = code;
|
||||
}
|
||||
|
||||
Instruction::Instruction(Instruction &&ins) noexcept
|
||||
: id(ins.id), name((ehs::Str_8 &&)ins.name), size(ins.size), code(ins.code)
|
||||
{
|
||||
ins.id = 0;
|
||||
ins.size = 0;
|
||||
ins.code = nullptr;
|
||||
}
|
||||
|
||||
Instruction::Instruction(const Instruction &ins)
|
||||
: id(ins.id), name(ins.name), size(ins.size), code(new ehs::Byte[size])
|
||||
{
|
||||
ehs::Util::Copy(code, ins.code, size);
|
||||
}
|
||||
|
||||
Instruction &Instruction::operator=(Instruction &&ins) noexcept
|
||||
{
|
||||
if (this == &ins)
|
||||
return *this;
|
||||
|
||||
id = ins.id;
|
||||
name = (ehs::Str_8 &&)ins.name;
|
||||
size = ins.size;
|
||||
code = ins.code;
|
||||
|
||||
ins.id = 0;
|
||||
ins.size = 0;
|
||||
ins.code = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Instruction &Instruction::operator=(const Instruction &ins)
|
||||
{
|
||||
if (this == &ins)
|
||||
return *this;
|
||||
|
||||
id = ins.id;
|
||||
name = ins.name;
|
||||
size = ins.size;
|
||||
code = new ehs::Byte[size];
|
||||
|
||||
ehs::Util::Copy(code, ins.code, size);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ehs::UInt_64 Instruction::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
ehs::Str_8 Instruction::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
ehs::UInt_8 Instruction::GetSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
ehs::Byte *Instruction::GetCode() const
|
||||
{
|
||||
return code;
|
||||
}
|
1
src/linker/Linker.cpp
Normal file
1
src/linker/Linker.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "arctyx/linker/Linker.h"
|
@ -1,4 +1,4 @@
|
||||
#include "arctyx/ELF.h"
|
||||
#include "arctyx/linker/formats/ELF.h"
|
||||
|
||||
ELF::ELF()
|
||||
: bitDepth(ELF_BIT_DEPTH_64), endianness(ELF_END_LE), abi(ELFH_ABI_SYSTEMV), type(ELFH_TYPE_EXEC),
|
||||
@ -199,7 +199,7 @@ ELF_Section* ELF::GetSection(const ehs::Str_8& sectionId) const
|
||||
|
||||
ehs::UInt_64 ELF::GetLastSegmentOffset() const
|
||||
{
|
||||
ehs::UInt_64 offset = ELFH_SIZE + PRGH_SIZE * programs.Size();
|
||||
ehs::UInt_64 offset = ELF_64_BIT_HEADER_SIZE + PRGH_SIZE * programs.Size();
|
||||
|
||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
||||
{
|
||||
@ -214,7 +214,7 @@ ehs::UInt_64 ELF::GetLastSegmentOffset() const
|
||||
|
||||
ehs::Vec2_u64 ELF::SegmentRange(ehs::UInt_64 sectionHashId)
|
||||
{
|
||||
ehs::UInt_64 offset = ELFH_SIZE + PRGH_SIZE * programs.Size();
|
||||
ehs::UInt_64 offset = ELF_64_BIT_HEADER_SIZE + PRGH_SIZE * programs.Size();
|
||||
if (sectionHashId)
|
||||
{
|
||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
||||
@ -252,35 +252,13 @@ ehs::Serializer<ehs::UInt_64> ELF::Serialize() const
|
||||
{
|
||||
ehs::Serializer<ehs::UInt_64> result(ehs::Endianness::LE);
|
||||
|
||||
// ELF magic number.
|
||||
result.Write<ehs::UInt_32>(0x7F454C46);
|
||||
|
||||
result.Write<ehs::UInt_8>(ELF_BIT_DEPTH_64);
|
||||
result.Write(endianness);
|
||||
result.Write<ehs::UInt_8>(1);
|
||||
result.Write(abi);
|
||||
result.Write<ehs::UInt_8>(0);
|
||||
|
||||
result.Resize(result.Size() + 7);
|
||||
ehs::Util::Zero(&result[result.GetOffset()], 7);
|
||||
result.SetOffset(result.GetOffset() + 7);
|
||||
|
||||
result.Write(type);
|
||||
result.Write(arch);
|
||||
result.Write<ehs::UInt_32>(1);
|
||||
result.Write(programs[entryPoint].pAddr);
|
||||
result.Write<ehs::UInt_64>(ELFH_SIZE);
|
||||
result.Write(RetrieveSectionsOffset());
|
||||
result.Write<ehs::UInt_32>(0);
|
||||
result.Write<ehs::UInt_16>(ELFH_SIZE);
|
||||
result.Write<ehs::UInt_16>(PRGH_SIZE);
|
||||
result.Write(programs.Size());
|
||||
result.Write<ehs::UInt_16>(SECH_SIZE);
|
||||
result.Write(sections.Size());
|
||||
result.Write(FindShStrTabIndex());
|
||||
if (bitDepth == ELF_BIT_DEPTH_64)
|
||||
Serialize_64(result);
|
||||
else if (bitDepth == ELF_BIT_DEPTH_32)
|
||||
Serialize_32(result);
|
||||
|
||||
for (ehs::UInt_16 i = 0; i < programs.Size(); i++)
|
||||
programs[i].Serialize(result);
|
||||
programs[i].Serialize(bitDepth, result);
|
||||
|
||||
for (ehs::UInt_16 i = 1; i < sections.Size(); i++)
|
||||
{
|
||||
@ -297,11 +275,83 @@ ehs::Serializer<ehs::UInt_64> ELF::Serialize() const
|
||||
}
|
||||
|
||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
||||
sections[i].Serialize(result);
|
||||
sections[i].Serialize(bitDepth, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ELF::Serialize_64(ehs::Serializer<ehs::UInt_64> &data) const
|
||||
{
|
||||
data.Resize(ELF_64_BIT_HEADER_SIZE);
|
||||
|
||||
// ELF magic number.
|
||||
data.Write<ehs::UInt_32>(0x464C457F);
|
||||
|
||||
data.Write<ehs::UInt_8>(bitDepth);
|
||||
data.Write(endianness);
|
||||
data.Write<ehs::UInt_8>(1);
|
||||
data.Write(abi);
|
||||
data.Write<ehs::UInt_8>(0);
|
||||
|
||||
ehs::Util::Zero(&data[data.GetOffset()], 7);
|
||||
data.SetOffset(data.GetOffset() + 7);
|
||||
|
||||
data.Write(type);
|
||||
data.Write(arch);
|
||||
data.Write<ehs::UInt_32>(1);
|
||||
data.Write(programs[entryPoint].pAddr);
|
||||
data.Write<ehs::UInt_64>(ELF_64_BIT_HEADER_SIZE);
|
||||
data.Write(RetrieveSectionsOffset());
|
||||
data.Write<ehs::UInt_32>(0);
|
||||
data.Write<ehs::UInt_16>(ELF_64_BIT_HEADER_SIZE);
|
||||
data.Write<ehs::UInt_16>(PRGH_SIZE);
|
||||
data.Write(programs.Size());
|
||||
data.Write<ehs::UInt_16>(SECH_SIZE);
|
||||
data.Write(sections.Size());
|
||||
data.Write(FindShStrTabIndex());
|
||||
}
|
||||
|
||||
void ELF::Serialize_32(ehs::Serializer<ehs::UInt_64> &data) const
|
||||
{
|
||||
data.Resize(ELF_32_BIT_HEADER_SIZE);
|
||||
|
||||
// ELF magic number.
|
||||
data.Write<ehs::UInt_32>(0x464C457F);
|
||||
|
||||
data.Write<ehs::UInt_8>(bitDepth);
|
||||
data.Write(endianness);
|
||||
data.Write<ehs::UInt_8>(1);
|
||||
data.Write(abi);
|
||||
data.Write<ehs::UInt_8>(0);
|
||||
|
||||
ehs::Util::Zero(&data[data.GetOffset()], 7);
|
||||
data.SetOffset(data.GetOffset() + 7);
|
||||
|
||||
data.Write(type);
|
||||
data.Write(arch);
|
||||
data.Write<ehs::UInt_32>(1);
|
||||
data.Write(programs[entryPoint].pAddr);
|
||||
|
||||
if (bitDepth == ELF_BIT_DEPTH_64)
|
||||
data.Write<ehs::UInt_64>(ELF_64_BIT_HEADER_SIZE);
|
||||
else if (bitDepth == ELF_BIT_DEPTH_32)
|
||||
data.Write<ehs::UInt_32>(ELF_32_BIT_HEADER_SIZE);
|
||||
|
||||
data.Write(RetrieveSectionsOffset());
|
||||
data.Write<ehs::UInt_32>(0);
|
||||
|
||||
if (bitDepth == ELF_BIT_DEPTH_64)
|
||||
data.Write<ehs::UInt_16>(ELF_64_BIT_HEADER_SIZE);
|
||||
else if (bitDepth == ELF_BIT_DEPTH_32)
|
||||
data.Write<ehs::UInt_16>(ELF_32_BIT_HEADER_SIZE);
|
||||
|
||||
data.Write<ehs::UInt_16>(PRGH_SIZE);
|
||||
data.Write(programs.Size());
|
||||
data.Write<ehs::UInt_16>(SECH_SIZE);
|
||||
data.Write(sections.Size());
|
||||
data.Write(FindShStrTabIndex());
|
||||
}
|
||||
|
||||
void ELF::InitializeSections()
|
||||
{
|
||||
ehs::Str_8 nullName = ".NULL";
|
||||
@ -332,7 +382,7 @@ void ELF::InitializeSections()
|
||||
|
||||
ehs::UInt_64 ELF::RetrieveSectionsOffset() const
|
||||
{
|
||||
ehs::UInt_64 result = ELFH_SIZE + PRGH_SIZE * programs.Size();
|
||||
ehs::UInt_64 result = ELF_64_BIT_HEADER_SIZE + PRGH_SIZE * programs.Size();
|
||||
|
||||
for (ehs::UInt_16 i = 0; i < sections.Size(); i++)
|
||||
{
|
@ -1,4 +1,5 @@
|
||||
#include "arctyx/ELF_Program.h"
|
||||
#include "arctyx/linker/formats/ELF_Program.h"
|
||||
#include "arctyx/linker/formats/ELF_Architecture.h"
|
||||
|
||||
ELF_Program::ELF_Program()
|
||||
: type(PRGH_TYPE_LOAD), flags(PRGH_FLAG_EXEC | PRGH_FLAG_READ), offset(0), vAddr(0), pAddr(0), fileSize(0),
|
||||
@ -96,14 +97,34 @@ ehs::UInt_64 ELF_Program::GetAlign() const
|
||||
return align;
|
||||
}
|
||||
|
||||
void ELF_Program::Serialize(ehs::Serializer<ehs::UInt_64>& inData) const
|
||||
void ELF_Program::Serialize(const ehs::UInt_8 &bitDepth, ehs::Serializer<ehs::UInt_64>& inData) const
|
||||
{
|
||||
inData.Write(type);
|
||||
inData.Write(flags);
|
||||
inData.Write(offset);
|
||||
inData.Write(vAddr);
|
||||
inData.Write(pAddr);
|
||||
inData.Write(fileSize);
|
||||
inData.Write(fileSize + adjustedMemSize);
|
||||
inData.Write(align);
|
||||
if (bitDepth == ELF_BIT_DEPTH_64)
|
||||
Serialize_64(inData);
|
||||
else if (bitDepth == ELF_BIT_DEPTH_32)
|
||||
Serialize_32(inData);
|
||||
}
|
||||
|
||||
void ELF_Program::Serialize_64(ehs::Serializer<ehs::UInt_64> &data) const
|
||||
{
|
||||
data.Write(type);
|
||||
data.Write(flags);
|
||||
data.Write(offset);
|
||||
data.Write(vAddr);
|
||||
data.Write(pAddr);
|
||||
data.Write(fileSize);
|
||||
data.Write(fileSize + adjustedMemSize);
|
||||
data.Write(align);
|
||||
}
|
||||
|
||||
void ELF_Program::Serialize_32(ehs::Serializer<ehs::UInt_64> &data) const
|
||||
{
|
||||
data.Write(type);
|
||||
data.Write<ehs::UInt_32>(offset);
|
||||
data.Write<ehs::UInt_32>(vAddr);
|
||||
data.Write<ehs::UInt_32>(pAddr);
|
||||
data.Write<ehs::UInt_32>(fileSize);
|
||||
data.Write<ehs::UInt_32>(fileSize + adjustedMemSize);
|
||||
data.Write(flags);
|
||||
data.Write<ehs::UInt_32>(align);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#include "arctyx/ELF_Section.h"
|
||||
#include "arctyx/linker/formats/ELF_Section.h"
|
||||
#include "arctyx/linker/formats/ELF_Architecture.h"
|
||||
|
||||
ELF_Section::ELF_Section()
|
||||
: hashId(0), nameOffset(0), fileOffset(0), type(0), flags(0), vAddr(0), segmentOffset(0), link(0),
|
||||
@ -143,7 +144,7 @@ void ELF_Section::SetEntries(ehs::UInt_64 newEntries)
|
||||
|
||||
void ELF_Section::SetData(ehs::Serializer<ehs::UInt_64> newData)
|
||||
{
|
||||
data = (ehs::Serializer<ehs::UInt_64>&&)newData;
|
||||
data = (ehs::Serializer<ehs::UInt_64> &&)newData;
|
||||
}
|
||||
|
||||
ehs::Serializer<ehs::UInt_64>& ELF_Section::GetData()
|
||||
@ -151,16 +152,38 @@ ehs::Serializer<ehs::UInt_64>& ELF_Section::GetData()
|
||||
return data;
|
||||
}
|
||||
|
||||
void ELF_Section::Serialize(ehs::Serializer<ehs::UInt_64>& inData) const
|
||||
void ELF_Section::Serialize(const ehs::UInt_8 &bitDepth, ehs::Serializer<ehs::UInt_64>& inData) const
|
||||
{
|
||||
inData.Write(nameOffset);
|
||||
inData.Write(type);
|
||||
inData.Write(flags);
|
||||
inData.Write(vAddr);
|
||||
inData.Write(segmentOffset);
|
||||
inData.Write(data.Size());
|
||||
inData.Write(link);
|
||||
inData.Write(info);
|
||||
inData.Write(align);
|
||||
inData.Write(entries);
|
||||
if (bitDepth == ELF_BIT_DEPTH_64)
|
||||
Serialize_64(inData);
|
||||
else if (bitDepth == ELF_BIT_DEPTH_32)
|
||||
Serialize_32(inData);
|
||||
}
|
||||
|
||||
void ELF_Section::Serialize_64(ehs::Serializer<ehs::UInt_64> &data) const
|
||||
{
|
||||
data.Write(nameOffset);
|
||||
data.Write(type);
|
||||
data.Write(flags);
|
||||
data.Write(vAddr);
|
||||
data.Write(segmentOffset);
|
||||
data.Write(data.Size());
|
||||
data.Write(link);
|
||||
data.Write(info);
|
||||
data.Write(align);
|
||||
data.Write(entries);
|
||||
}
|
||||
|
||||
void ELF_Section::Serialize_32(ehs::Serializer<ehs::UInt_64> &data) const
|
||||
{
|
||||
data.Write(nameOffset);
|
||||
data.Write(type);
|
||||
data.Write<ehs::UInt_32>(flags);
|
||||
data.Write<ehs::UInt_32>(vAddr);
|
||||
data.Write<ehs::UInt_32>(segmentOffset);
|
||||
data.Write<ehs::UInt_32>(data.Size());
|
||||
data.Write(link);
|
||||
data.Write(info);
|
||||
data.Write<ehs::UInt_32>(align);
|
||||
data.Write<ehs::UInt_32>(entries);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include "arctyx/ELF_Sym.h"
|
||||
#include "arctyx/linker/formats/ELF_Sym.h"
|
||||
|
||||
ELF_Sym::ELF_Sym()
|
||||
: nameOffset(0), type(0), visibility(0), section(0), value(0), size(0)
|
@ -1,5 +1,5 @@
|
||||
#include "arctyx/ELF.h"
|
||||
#include "arctyx/ELF_Sym.h"
|
||||
#include "arctyx/linker/formats/ELF.h"
|
||||
#include "arctyx/linker/formats/ELF_Sym.h"
|
||||
|
||||
#include <ehs/EHS.h>
|
||||
#include <ehs/io/Console.h>
|
||||
@ -8,6 +8,7 @@
|
||||
int main()
|
||||
{
|
||||
ehs::Initialize("Arctyx", "Alpha", {1, 0, 0});
|
||||
ehs::Log::EnableImmediateMode(true);
|
||||
|
||||
ehs::Vector<ehs::Str_8> args = ehs::Console::GetArgs_8();
|
||||
if (args.Size() <= 1)
|
||||
@ -28,7 +29,7 @@ int main()
|
||||
|
||||
ELF_Section text(".text", 0x1000, SECH_TYPE_PROGBITS, SECH_FLAG_ALLOC | SECH_FLAG_EXEC, 0x401000, 16);
|
||||
text.SetData(code);
|
||||
executable.AddSection((ELF_Section&&)text);
|
||||
executable.AddSection(text);
|
||||
|
||||
ELF_Section strTab(".strtab", 0, SECH_TYPE_STRTAB, 0, 0, 1);
|
||||
ehs::Serializer<ehs::UInt_64>& strTabData = strTab.GetData();
|
||||
|
Loading…
x
Reference in New Issue
Block a user