aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/programloader.h
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_machine/programloader.h')
-rw-r--r--qtmips_machine/programloader.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/qtmips_machine/programloader.h b/qtmips_machine/programloader.h
new file mode 100644
index 0000000..058e5c1
--- /dev/null
+++ b/qtmips_machine/programloader.h
@@ -0,0 +1,28 @@
+#ifndef PROGRAM_H
+#define PROGRAM_H
+
+#include <unistd.h>
+#include <libelf.h>
+#include <gelf.h>
+#include <cstdint>
+#include <vector>
+
+
+class ProgramLoader {
+public:
+ ProgramLoader(char *file);
+ ~ProgramLoader();
+
+ size_t get_nsec(); // Returns number of loadable sections
+ std::uint32_t get_address(size_t sec); // Get target address for given section
+ std::vector<std::uint8_t> get_data(size_t sec); // Returns bytes of given section
+private:
+ int fd;
+ Elf *elf;
+ GElf_Ehdr hdr; // elf file header
+ size_t n_secs; // number of sections in elf program header
+ Elf32_Phdr *phdrs; // program section headers
+ std::vector<size_t> map; // external index to phdrs index
+};
+
+#endif // PROGRAM_H