-
Notifications
You must be signed in to change notification settings - Fork 0
/
omf.h
97 lines (76 loc) · 1.56 KB
/
omf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef __omf_h__
#define __omf_h__
#include <stdint.h>
#include <vector>
#include <string>
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;
uint32_t offset = 0;
uint32_t value = 0;
constexpr bool can_compress() const {
return offset <= 0xffff && value <= 0xffff;
}
};
struct interseg {
uint8_t size = 0;
uint8_t shift = 0;
uint32_t offset = 0;
uint16_t file = 1;
uint16_t segment = 0;
uint32_t segment_offset = 0;
constexpr bool can_compress() const {
return file == 1 && segment <= 255 && offset <= 0xffff && segment_offset <= 0xffff;
}
};
struct segment {
uint16_t segnum = 0;
uint16_t kind = 0;
uint32_t alignment = 0;
uint32_t reserved_space = 0;
uint32_t org = 0;
std::string loadname;
std::string segname;
std::vector<uint8_t> data;
std::vector<interseg> intersegs;
std::vector<reloc> relocs;
};
}
enum {
// flags
OMF_V1 = 1,
OMF_V2 = 0,
OMF_NO_SUPER = 2,
OMF_NO_COMPRESS = 4,
OMF_NO_EXPRESS = 8
};
void save_omf(const std::string &path, std::vector<omf::segment> &segments, unsigned flags);
void save_bin(const std::string &path, omf::segment &segment);
#endif