-
Notifications
You must be signed in to change notification settings - Fork 5
/
obj.h
202 lines (173 loc) · 5.82 KB
/
obj.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#ifndef _OBJ_H
#define _OBJ_H
#ifdef ARCH32
typedef uint32_t addr_t;
#define MAGIC_OBJ 0x5D1B
#define MAGIC_OBJ_SWAPPED 0x1B5D
#define NAMELEN 32
#else
typedef uint16_t addr_t;
/* Long name is used for cross building and non 8bit environments. In an
8bit environment longer names are just too expensive */
#ifdef OBJ_LONGNAME
#define MAGIC_OBJ 0x4D1B
#define MAGIC_OBJ_SWAPPED 0x1B4D
#define NAMELEN 32
#else
#define MAGIC_OBJ 0x3D1A
#define MAGIC_OBJ_SWAPPED 0x1A3D
#define NAMELEN 16
#endif
#endif
#define OSEG 14
struct objhdr
{
uint16_t o_magic;
uint8_t o_arch;
#define OA_8080 1
#define OA_6502 2
#define OA_DGNOVA 3 /* So I can test PC relative */
#define OA_6800 4
#define OA_Z8 5
#define OA_1802 6
#define OA_TMS9900 7
#define OA_8008 8
#define OA_INS8060 9
#define OA_INS8070 10
#define OA_WARREX 11
#define OA_BYTE 12 /* Bytecode */
#define OA_6809 13
#define OA_PE16 14 /* Interdata/Perkin Elmer 16bit */
#define OA_8086 15
#define OA_GB 16 /* Gameboy */
#define OA_6805 17 /* 6805/05/HC08 - 6808 is unrelated */
#define OA_H316 18 /* System 16 */
#define OA_CP1600 19 /* CP1600 */
#define OA_PE32 20 /* Interdata/Perkin Elmer 32bit */
#define OA_PDP4 21 /* PDP4/7/9/15 */
uint8_t o_flags;
#define OF_BIGENDIAN 1
#define OF_WORDMACHINE 2 /* 16bit word addressed */
uint16_t o_cpuflags;
#define OA_8080_Z80 1
#define OA_8080_Z180 2
#define OA_8080_Z280 4
#define OA_8080_R800 8
#define OA_8080_8085 16
#define OA_8080_Z80N 32
#define OA_8080_EZ80 64
#define OA_6502_BCD 1 /* Uses BCD instructions */
#define OA_6502_NMOS 2 /* Uses NMOS undocumented */
#define OA_6502_65C02 4 /* Uses 65C02 */
#define OA_6502_BITOPS 8 /* Uses extended bit operations */
#define OA_6502_65C816 16 /* 65C816 and relatives */
#define OA_6502_ZPAT0 32 /* Binary Assumes ZP is at 0 */
#define OA_6502_65CE02 64 /* Does anyone really care ? */
#define OA_6502_65C816_16 128 /* 16bit mode binary */
#define OA_DGNOVA_MUL 1
#define OA_DGNOVA_FPU 2
#define OA_DGNOVA_NOVA3 4
#define OA_DGNOVA_NOVA4 8
#define OA_6800_6803 1
#define OA_6800_6303 2
#define OA_6800_68HC11 4
#define OA_Z8_BASE 1 /* Define 1 for each form as they all conflict */
#define OA_Z8_SUPER 2
#define OA_Z8_EZ8 4
#define OA_TMS9900_9995 1 /* TMS 9995 */
#define OA_WARREX_CPU6 1
#define OA_6809_6309 1
#define OA_8086_186 1
#define OA_8086_286 2
#define OA_6805_HC08 1
#define OA_H316_516 1
#define OA_H316_HSA 2
#define OA_PDP4_7 1
#define OA_PDP4_9 2
#define OA_PDP4_15 4
uint16_t o_unused; /* So it packs right */
uint32_t o_segbase[OSEG];
addr_t o_size[OSEG];
uint32_t o_symbase;
uint32_t o_dbgbase;
};
/* This byte introduces a relocation or may be escaped */
#define REL_ESC 0xDA
#define REL_SIZE 0x30 /* 1-4 bytes */
/* If REL_SIMPLE then ... */
#define REL_SIMPLE 0x80 /* relocation to base of segment */
#define REL_SEG 0x0F /* segment 0-15 */
/* followed by the bytes to relocate */
/* Otherwise */
#define REL_TYPE 0x0F
/* 00 is reserved */
#define REL_SPECIAL 0x00 /* REL_REL REL_EOF etc */
#define REL_SYMBOL 0x01 /* Followed by a 2 byte symbol code then
offset to relocate */
#define REL_PCREL 0x02 /* Followed by a 2 byte symbol code then
a word sized value regardless of reloc size
but the resulting reloc is written to the
size given */
#define REL_REL (REL_SPECIAL| (0 << 4)) /* 00 */
#define REL_EOF (REL_SPECIAL| (1 << 4)) /* 10 */
/* Overflow suppresses overflow checking on the relocation that follows (no
second REL_ESC */
#define REL_OVERFLOW (REL_SPECIAL| (2 << 4)) /* 20 */
/* Indicate a high byte relocation. Treated as normal until the final absolute
write where the two bytes of reloc are relocated and the high byte used. If
used with overflow must follow it directly */
#define REL_HIGH (REL_SPECIAL| (3 << 4)) /* 30 */
/* Indicate a change in address for ABS areas */
#define REL_ORG (REL_SPECIAL| (4 << 4)) /* 40 */
/* Relocation modifier block. Not yet implemented. Needed
for things like B pointers and page addressing (eg 1802 branches) */
#define REL_MOD (REL_SPECIAL| (5 << 4)) /* 50 */
/* Followed by
7: highbit (set if mask is high bits used)
6: error if cannot resolve
5-0: mask number of bits 0-63 - 16 is no mask (FFFF)
byte 2 (bits 5-3 0 for now)
7: scale direction
6: error if cannot resolve
5-0: shift for scale
(proposed - see doc)
*/
#define RELMOD_RELH 0x80
#define RELMOD_RELERR 0x40
#define RELMOD_RELBITS 0x3F
/* Blocks - reserved */
#define REL_BLOCK (REL_SPECIAL | (6 << 4)) /* 60 */
/* Following simple relocation is ,PCR style (PC relative across segments) */
#define REL_PCR (REL_SPECIAL | (7 << 4)) /* 70 */
#define REL_SPECIAL2 0x8F /* 8F, 9F ... */
/* Target specific */
#define REL_TARGET (REL_SPECIAL2)) /* 8F */
#define REL_EXTEND (REL_SPECIAL2 | 0x70) /* Reserved FF */
/* symbols and debug are in the format
uint8_t flags
char name[16] (0 terminated if < 16)
uint16_t data */
#define S_UNKNOWN 0x80
#define S_PUBLIC 0x40 /* unknown is public .. */
#define S_SEGMENT 0x0F /* 00 means absolute */
#define S_ANY 0x0F
#define S_SIZE 0x30 /* Size bits 0-3 = 1-4 bytes */
#define S_ENTRYSIZE (3 + NAMELEN)
/*
* Segments
*/
#define UNKNOWN 15
#define ABSOLUTE 0 /* Constant, not relocated */
#define CODE 1 /* Relocated versus code */
#define DATA 2 /* Relocated versus data */
#define BSS 3 /* Relocated versus BSS */
#define ZP 4 /* Relocated versus zero page */
#define DISCARD 5 /* Discard for things like kernels */
#define COMMON 6 /* Common for things like kernels */
#define LITERAL 7 /* Literals (mostly a compiler helper) */
#define COMMONDATA 8 /* Common for writables */
#define BUFFERS 9 /* Buffers for kernel */
/* Special cases 10+ don't exist as real segments */
#define PCREL 14 /* assumed signed */
/* and 15 is 'any' */
#endif