From 2ff8267af303d9a94d13bcfafeeaa2fcafcac9a2 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 12 Jan 2017 20:56:09 -0500 Subject: [PATCH] beginning support for SUPER relocation records. --- omf.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- omf.h | 27 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/omf.cpp b/omf.cpp index b6fcc86..6104f8d 100644 --- a/omf.cpp +++ b/omf.cpp @@ -8,7 +8,7 @@ #include #include #include - +#include #ifndef O_BINARY #define O_BINARY 0 @@ -86,6 +86,67 @@ void push(std::vector &v, const std::string &s) { v.insert(v.end(), s.begin(), s.end()); } +class super_reloc { + + std::vector _data; + uint32_t _page = 0; + int _count = 0; + + super_reloc(unsigned type) { + _data.push_back(0xf7); + _data.push_back(0x00); + _data.push_back(0x00); + _data.push_back(0x00); + _data.push_back(0x00); + _data.push_back(type); + } + + void append(uint32_t pc) { + unsigned offset = pc & 0xff; + unsigned page = pc >> 8; + assert(page >= _page); + + if (page != _page) { + unsigned skip = page - _page; + if (skip > 1) _data.push_back(0x80 | skip); + _page = page; + _count = 0; + _data.push_back(0); // count-1 place holder. + } + + _data[_data.size() - _count - 1] = _count; // count is count - 1 at this point, + _data.push_back(offset); + ++_count; + } + + std::vector &&finish() { + uint32_t size = _data.size() - 5; + _data[1] = size & 0xff; size >>= 8; + _data[2] = size & 0xff; size >>= 8; + _data[3] = size & 0xff; size >>= 8; + _data[4] = size & 0xff; size >>= 8; + + return std::move(_data); + } + +}; + +#if 0 +compress() { + + + for(auto &r : s.reloc) { + // super reloc 2 -- size = 2, shift = 0 + // super reloc 2 -- size = 3, shift = 0 + + if (r.size == 2 && r.shift == 0) { + + } + + } + +} +#endif void save_omf(std::vector &segments, bool expressload, const std::string &path) { diff --git a/omf.h b/omf.h index b048f54..5580118 100644 --- a/omf.h +++ b/omf.h @@ -7,6 +7,33 @@ namespace omf { + enum opcode : uint8_t { + END = 0x00, + // 0x01-0xdf CONST + ALIGN = 0xe0, + ORG = 0xe1, + RELOC = 0xe2, + INTERSEG = 0xe3, + USING = 0xe4, + STRONG = 0xe5, + GLOBAL = 0xe6, + GEQU = 0xe7, + MEM = 0xe8, + EXPR = 0xeb, + ZEXPR = 0xec, + BEXPR = 0xed, + RELEXPR = 0xee, + LOCAL = 0xef, + EQU = 0xf0, + DS = 0xf1, + LCONST = 0xf2, + LEXPR = 0xf3, + ENTRY = 0xf4, + cRELOC = 0xf5, + cINTERSEG = 0xf6, + SUPER = 0xf7, + }; + struct reloc { uint8_t size = 0; uint8_t shift = 0;