From 34523bbecfaa33ba4173ef1afb8575e983f76750 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 15 Dec 2019 13:03:43 -0500 Subject: [PATCH] ALI and DS support --- link.cpp | 14 ++++++++++---- omf.cpp | 29 +++++++++++++++++++++++++---- omf.h | 2 ++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/link.cpp b/link.cpp index aaff80a..cb2564a 100644 --- a/link.cpp +++ b/link.cpp @@ -752,11 +752,17 @@ void evaluate(label_t label, opcode_t opcode, const char *cursor) { case OP_ALI: { uint32_t align = number_operand(cursor, local_symbol_table); // must be power of 2 or 0 - if ((align & (align-1)) == 0) { - // not yet supported. - } else { + if (align & (align-1)) throw std::runtime_error("Bad alignment"); - } + + segments.back().alignment = align; + break; + } + + case OP_DS: { + // todo - how is this handled in binary linker? + uint32_t ds = number_operand(cursor, local_symbol_table); + segments.back().reserved_space = ds; break; } diff --git a/omf.cpp b/omf.cpp index 6ab1ba5..65af576 100644 --- a/omf.cpp +++ b/omf.cpp @@ -92,6 +92,12 @@ void push(std::vector &v, const std::string &s) { v.insert(v.end(), s.begin(), s.begin() + count); } +void push(std::vector &v, const std::string &s, size_t count) { + std::string tmp(s, 0, count); + tmp.resize(count, ' '); + v.insert(v.end(), tmp.begin(), tmp.end()); +} + class super_helper { std::vector _data; @@ -385,15 +391,26 @@ void save_omf(const std::string &path, std::vector &segments, bool for (auto &s : segments) { omf_header h; - h.length = s.data.size(); + h.length = s.data.size() + s.reserved_space; h.kind = s.kind; h.banksize = s.data.size() > 0xffff ? 0x0000 : 0x010000; h.segnum = s.segnum; + h.alignment = s.alignment; + h.reserved_space = s.reserved_space; + + uint32_t reserved_space = 0; + if (expressload) { + std::swap(reserved_space, h.reserved_space); + } + + // length field INCLUDES reserved space. Express expand reserved space. + std::vector data; // push segname and load name onto data. - data.insert(data.end(), 10, ' '); + // data.insert(data.end(), 10, ' '); + push(data, s.loadname, 10); push(data, s.segname); h.dispname = sizeof(omf_header); @@ -402,16 +419,20 @@ void save_omf(const std::string &path, std::vector &segments, bool uint32_t lconst_offset = offset + sizeof(omf_header) + data.size() + 5; - uint32_t lconst_size = h.length; + uint32_t lconst_size = s.data.size() + reserved_space; + //lconst record push(data, (uint8_t)omf::LCONST); - push(data, (uint32_t)h.length); + push(data, (uint32_t)lconst_size); size_t data_offset = data.size(); data.insert(data.end(), s.data.begin(), s.data.end()); + if (reserved_space) { + data.insert(data.end(), reserved_space, 0); + } uint32_t reloc_offset = offset + sizeof(omf_header) + data.size(); uint32_t reloc_size = 0; diff --git a/omf.h b/omf.h index 5580118..79d02bf 100644 --- a/omf.h +++ b/omf.h @@ -64,6 +64,8 @@ namespace omf { uint16_t segnum = 0; uint16_t kind = 0; + uint32_t alignment = 0; + uint32_t reserved_space = 0; std::string loadname; std::string segname;