Update opengl.hpp, start with ELFs

This commit is contained in:
wheremyfoodat 2022-09-15 14:59:44 +03:00
parent 1a8d563041
commit 51689af51f
8 changed files with 469 additions and 392 deletions

View file

@ -9,7 +9,7 @@ CPU::CPU(Memory& mem) : mem(mem) {
// Write some code to memory.
env.MemoryWrite16(0, 0x0088); // lsls r0, r1, #2
env.MemoryWrite16(2, 0x3045); // adds r0, #69
env.MemoryWrite16(4, 0xdf45); // swi #69
env.MemoryWrite16(4, 0x3845); // subs r0, #69
env.MemoryWrite16(6, 0xE7FE); // b +#0 (infinite loop)
// Setup registers.

24
src/core/elf.cpp Normal file
View file

@ -0,0 +1,24 @@
#include "memory.hpp"
#include "elfio/elfio.hpp"
using namespace ELFIO;
std::optional<u32> Memory::loadELF(std::filesystem::path& path) {
elfio reader;
if (!reader.load(path.string())) {
printf("Woops failed to load ELF\n");
return std::nullopt;
}
auto seg_num = reader.segments.size();
printf("Number of segments: %d\n", seg_num);
for (int i = 0; i < seg_num; ++i) {
const auto pseg = reader.segments[i];
std::cout << " [" << i << "] 0x" << std::hex << pseg->get_flags()
<< "\t0x" << pseg->get_virtual_address() << "\t0x"
<< pseg->get_file_size() << "\t0x" << pseg->get_memory_size()
<< std::endl;
}
return static_cast<u32>(reader.get_entry());
}