RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
common.h
1#ifndef COMMON_H
2#define COMMON_H
3
4#include <cassert>
5#include <cstdint>
6#include <cstddef>
7#include <map>
8#include <memory>
9#include <iostream>
10#include <string>
11
12typedef uint64_t offset_t;
13typedef int64_t relative_offset_t;
14typedef size_t number_t;
15
16enum EndianType
17{
18 Undefined,
19 LittleEndian,
20 BigEndian,
21 PDP11Endian, /* little endian within a 16-bit word, big endian between words */
22 AntiPDP11Endian,
23};
24
25extern EndianType DefaultEndianType;
26
30size_t GetOffset(EndianType endiantype, size_t bytes, size_t index);
31
35offset_t AlignTo(offset_t value, offset_t align);
36
40uint16_t Swap16(uint16_t value);
41
45uint16_t FromLittleEndian16(uint16_t value);
46
50uint16_t FromBigEndian16(uint16_t value);
51
55uint32_t Swap32(uint32_t value);
56
60uint32_t Swap32words(uint32_t value);
61
65uint32_t FromLittleEndian32(uint32_t value);
66
70uint32_t FromBigEndian32(uint32_t value);
71
75uint32_t FromPDP11Endian32(uint32_t value);
76
80uint64_t Swap64(uint64_t value);
81
85uint64_t Swap64words(uint64_t value);
86
90uint64_t FromLittleEndian64(uint64_t value);
91
92uint64_t FromBigEndian64(uint64_t value);
93
94uint64_t FromPDP11Endian64(uint64_t value);
95
99uint64_t ReadUnsigned(size_t bytes, size_t maximum, uint8_t const * data, EndianType endiantype);
100
104int64_t SignExtend(size_t bytes, int64_t value);
105
109int64_t ReadSigned(size_t bytes, size_t maximum, uint8_t const * data, EndianType endiantype);
110
114void WriteWord(size_t bytes, size_t maximum, uint8_t * data, uint64_t value, EndianType endiantype);
115
116bool LookupOption(std::map<std::string, std::string>& options, std::string key, std::string& value);
117
118namespace Linker
119{
121 {
122 public:
123 std::string message;
124 Exception(std::string message) : message(message)
125 {
126 }
127 };
128
129 /* TODO: implement these properly */
130 extern std::ostream Debug;
131 extern std::ostream Warning;
132 extern std::ostream Error;
133
134 [[noreturn]] void FatalError(std::string message);
135
136 class Section;
137 class Location;
138 typedef std::map<std::shared_ptr<Section>, Location> Displacement;
139
140 class Relocation;
141 class Segment;
142 class Writer;
143}
144
145#endif /* COMMON_H */
Definition common.h:121
Represents a single offset within a section, or an absolute location in memory if the section is null...
Definition location.h:17
A representation of a value within some binary data that has to be fixed up once the exact position o...
Definition relocation.h:27
A section of data as read from an object file.
Definition section.h:25
A class representing a sequence of sections that must be written to the output file as a group.
Definition segment.h:26
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15