aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/programloader.h
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-08-30 21:37:53 +0200
committerKarel Kočí <cynerd@email.cz>2017-08-30 21:42:02 +0200
commit9cf92379d5fcf0076c25dae0935daab446c992cd (patch)
treedd09a2e996db1e5a8117f01bec76f1e93eaca6e1 /qtmips_machine/programloader.h
downloadqtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.tar.gz
qtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.tar.bz2
qtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.zip
Initial commit
Adding work done so far.
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