mirror of
https://github.com/ksherlock/merlin-utils.git
synced 2025-02-04 23:34:15 +00:00
ALI and DS support
This commit is contained in:
parent
c341d9a54f
commit
34523bbecf
14
link.cpp
14
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;
|
||||
}
|
||||
|
||||
|
29
omf.cpp
29
omf.cpp
@ -92,6 +92,12 @@ void push(std::vector<uint8_t> &v, const std::string &s) {
|
||||
v.insert(v.end(), s.begin(), s.begin() + count);
|
||||
}
|
||||
|
||||
void push(std::vector<uint8_t> &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<uint8_t> _data;
|
||||
@ -385,15 +391,26 @@ void save_omf(const std::string &path, std::vector<omf::segment> &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<uint8_t> 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<omf::segment> &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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user