From 62e8183d33ae159b9e984d2ef5b4a83656d56a16 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 16 Jul 2016 22:59:28 +0200 Subject: o Working version that can take the data from the LD script. Only tested with the Intel Quark D2000 LD script. lexer: Allowing capital X in hex numbers too. --- includes/trygvis/elfinfo/Ld.h | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 includes/trygvis/elfinfo/Ld.h (limited to 'includes') diff --git a/includes/trygvis/elfinfo/Ld.h b/includes/trygvis/elfinfo/Ld.h new file mode 100644 index 0000000..cab466d --- /dev/null +++ b/includes/trygvis/elfinfo/Ld.h @@ -0,0 +1,70 @@ +#pragma once + +#include +#include +#include +#include + +namespace trygvis { +namespace elfinfo { + +enum class MemoryAttribute { + R, W, X +}; + +static char to_str(const MemoryAttribute &type) { + switch (type) { + case MemoryAttribute::R: + return 'r'; + case MemoryAttribute::W: + return 'w'; + case MemoryAttribute::X: + return 'x'; + } +} + +struct Section { + std::string name; +}; + +struct MemoryArea { + std::string name; + uint64_t origin; + uint64_t length; + std::set attributes; + + bool contains(uint64_t address, uint64_t size) const { + return contains(address) && contains(address + size); + } + + bool contains(uint64_t address) const { + return origin <= address && address < origin + length; + } + + std::string attributes_string() const { + char buf[4]; + buf[0] = attributes.find(MemoryAttribute::R) == attributes.end() ? '-' : 'r'; + buf[1] = attributes.find(MemoryAttribute::W) == attributes.end() ? '-' : 'w'; + buf[2] = attributes.find(MemoryAttribute::X) == attributes.end() ? '-' : 'x'; + buf[3] = '\0'; + return std::string(buf); + } +}; + +struct LdScript { + std::vector memoryAreas; +}; + +class LdScriptLoader { +public: + LdScriptLoader(); + + LdScript load(std::string path); + + void setDebug(bool debug); +private: + bool debug_; +}; + +} // namespace elfinfo +} // namespace trygvis -- cgit v1.2.3