mirror of
https://github.com/ksherlock/merlin-utils.git
synced 2025-01-02 05:29:45 +00:00
fixes so omf version 1 support works
This commit is contained in:
parent
9ccab300f2
commit
471c4d4151
18
link.cpp
18
link.cpp
@ -798,7 +798,7 @@ void finish(void) {
|
||||
if (lkv == 0)
|
||||
save_bin(path, segments.back());
|
||||
else
|
||||
save_omf(path, segments, compress, express);
|
||||
save_omf(path, segments, compress, express, ver);
|
||||
|
||||
set_file_type(path, ftype, atype);
|
||||
} catch (std::exception &ex) {
|
||||
@ -903,7 +903,11 @@ void finish3(void) {
|
||||
|
||||
push(buffer, omf::opcode::GEQU);
|
||||
push(buffer, sym.name);
|
||||
push(buffer, static_cast<uint16_t>(0x00)); /* length attr */
|
||||
if (ver == 1) {
|
||||
push(buffer, static_cast<uint8_t>(0x00)); /* length attr */
|
||||
} else {
|
||||
push(buffer, static_cast<uint16_t>(0x00)); /* length attr */
|
||||
}
|
||||
push(buffer, static_cast<uint8_t>('G')); /* type attr */
|
||||
push(buffer, static_cast<uint32_t>(sym.value));
|
||||
} else {
|
||||
@ -969,7 +973,11 @@ void finish3(void) {
|
||||
/* add global record */
|
||||
push(buffer, omf::opcode::GLOBAL);
|
||||
push(buffer, iter1->second); /* name */
|
||||
push(buffer, static_cast<uint16_t>(0x00)); /* length attr */
|
||||
if (ver == 1) {
|
||||
push(buffer, static_cast<uint8_t>(0x00)); /* length attr */
|
||||
} else {
|
||||
push(buffer, static_cast<uint16_t>(0x00)); /* length attr */
|
||||
}
|
||||
push(buffer, static_cast<uint8_t>('N')); /* type attr */
|
||||
push(buffer, static_cast<uint8_t>(0x00)); /* public */
|
||||
++iter1;
|
||||
@ -1006,7 +1014,7 @@ void finish3(void) {
|
||||
if (iter3 != resolved.end())
|
||||
throw std::runtime_error("relocation offset error");
|
||||
|
||||
void save_object(const std::string &path, omf::segment &s, uint32_t length);
|
||||
void save_object(const std::string &path, omf::segment &s, uint32_t length, unsigned version);
|
||||
|
||||
|
||||
std::string path = save_file;
|
||||
@ -1014,7 +1022,7 @@ void finish3(void) {
|
||||
if (verbose) printf("Saving %s\n", path.c_str());
|
||||
|
||||
try {
|
||||
save_object(path, seg, pc);
|
||||
save_object(path, seg, pc, ver);
|
||||
set_file_type(path, 0xb1, 0x0000);
|
||||
} catch (std::exception &ex) {
|
||||
errx(EX_OSERR, "%s: %s", path.c_str(), ex.what());
|
||||
|
9
omf.cpp
9
omf.cpp
@ -490,7 +490,7 @@ void save_bin(const std::string &path, omf::segment &segment) {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void save_object(const std::string &path, omf::segment &s, uint32_t length) {
|
||||
void save_object(const std::string &path, omf::segment &s, uint32_t length, unsigned version) {
|
||||
|
||||
/* data is already in OMF format. */
|
||||
|
||||
@ -521,6 +521,7 @@ void save_object(const std::string &path, omf::segment &s, uint32_t length) {
|
||||
h.bytecount = sizeof(omf_header) + data.size() + s.data.size();
|
||||
|
||||
unsigned offset = 0;
|
||||
if (version == 1) to_v1(h);
|
||||
to_little(h);
|
||||
offset += write(fd, &h, sizeof(h));
|
||||
offset += write(fd, data.data(), data.size());
|
||||
@ -669,6 +670,12 @@ void save_omf(const std::string &path, std::vector<omf::segment> &segments, bool
|
||||
to_little(h);
|
||||
offset += write(fd, &h, sizeof(h));
|
||||
offset += write(fd, data.data(), data.size());
|
||||
|
||||
// version 1 needs 512-byte padding for all but final segment.
|
||||
if (version == 1 && &s != &segments.back()) {
|
||||
static uint8_t zero[512];
|
||||
offset += write(fd, zero, 512 - (offset & 511) );
|
||||
}
|
||||
}
|
||||
|
||||
if (expressload) {
|
||||
|
Loading…
Reference in New Issue
Block a user