From f7d70702f98634658921fc2377abfcd8a6832bdb Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 12 Nov 2020 19:24:28 -0500 Subject: [PATCH] ORG support. --- link.cpp | 5 +++-- omf.cpp | 5 ++++- omf.h | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/link.cpp b/link.cpp index 51702e5..8ddbed2 100644 --- a/link.cpp +++ b/link.cpp @@ -31,7 +31,7 @@ #include "script.h" void save_omf(const std::string &path, std::vector &segments, bool compress, bool expressload); -void save_bin(const std::string &path, omf::segment &segment, uint32_t org); +void save_bin(const std::string &path, omf::segment &segment); int set_file_type(const std::string &path, uint16_t file_type, uint32_t aux_type, std::error_code &ec); void set_file_type(const std::string &path, uint16_t file_type, uint32_t aux_type); @@ -796,7 +796,7 @@ void finish(void) { if (verbose) printf("Saving %s\n", path.c_str()); try { if (lkv == 0) - save_bin(path, segments.back(), org); + save_bin(path, segments.back()); else save_omf(path, segments, compress, express); @@ -1205,6 +1205,7 @@ void evaluate(label_t label, opcode_t opcode, const char *cursor) { case OP_ORG: org = number_operand(cursor, local_symbol_table); + segments.back().org = org; atype = org; break; diff --git a/omf.cpp b/omf.cpp index 5c3024d..91a7ec1 100644 --- a/omf.cpp +++ b/omf.cpp @@ -446,7 +446,7 @@ uint32_t add_relocs(std::vector &data, size_t data_offset, omf::segment return reloc_size; } -void save_bin(const std::string &path, omf::segment &segment, uint32_t org) { +void save_bin(const std::string &path, omf::segment &segment) { int fd; fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); @@ -454,6 +454,7 @@ void save_bin(const std::string &path, omf::segment &segment, uint32_t org) { err(EX_CANTCREAT, "Unable to open %s", path.c_str()); } + uint32_t org = segment.org; auto &data = segment.data; for (auto &r : segment.relocs) { @@ -494,6 +495,7 @@ void save_object(const std::string &path, omf::segment &s, uint32_t length) { h.segnum = 0; h.alignment = s.alignment; h.reserved_space = s.reserved_space; + h.org = s.org; std::vector data; @@ -560,6 +562,7 @@ void save_omf(const std::string &path, std::vector &segments, bool h.segnum = s.segnum; h.alignment = s.alignment; h.reserved_space = s.reserved_space; + h.org = s.org; uint32_t reserved_space = 0; if (expressload) { diff --git a/omf.h b/omf.h index 79d02bf..da0ed48 100644 --- a/omf.h +++ b/omf.h @@ -66,6 +66,7 @@ namespace omf { uint16_t kind = 0; uint32_t alignment = 0; uint32_t reserved_space = 0; + uint32_t org = 0; std::string loadname; std::string segname;