OpenASIP 2.2
Loading...
Searching...
No Matches
AOutReader.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file AOutReader.hh
26 *
27 * Declaration of AOutReader.
28 *
29 * @author Jussi Nykänen 2003 (nykanen-no.spam-cs.tut.fi)
30 * @author Mikael Lepistö 18.12.2003 (tmlepist-no.spam-cs.tut.fi)
31 *
32 * @note reviewed 7 October 2003 by jn, ml, tr, ll
33 * @note rating: yellow
34 */
35
36#ifndef TTA_AOUT_READER_HH
37#define TTA_AOUT_READER_HH
38
39#include "BinaryReader.hh"
40#include "Binary.hh"
41#include "TPEFBaseType.hh"
42#include "Exception.hh"
43
44namespace TPEF {
45 class Binary;
46 class CodeSection;
47 class ResourceSection;
48 class NullSection;
49 class DebugSection;
50
51/**
52 * Reads binary file that is in TTA a.out format.
53 */
54class AOutReader : public BinaryReader {
55public:
56
57 /**
58 * TODO: get these from tce-frontend
59 * a.out symbols. (from MOVE/sched/exec.h)
60 */
62 N_UNDF = 0x0, ///< Undefined.
63 N_ABS = 0x2, ///< Absolute.
64 N_TEXT = 0x4, ///< Text.
65 N_DATA = 0x6, ///< Data.
66 N_BSS = 0x8, ///< BSS.
67 N_COMM = 0x12, ///< Common (internal to ld).
68 N_FN = 0x1e, ///< File name.
69 N_EXT = 0x1, ///< Mask bit for external.
70 N_TYPE = 0x1e, ///< Mask bits for resolving symbol type.
71 N_TJ = 0x76, ///< Table jump.
72 N_JTE = 0x96, ///< Jump table entry.
73 N_MEM = 0xb6, ///< Memory reference.
74 N_FC = 0xd6, ///< Function call.
75 N_STAB = 0xe0, ///< Mask for stabs.
76 N_GSYM = 0x20, ///< Global.
77 N_FNAME = 0x22, ///< Procedure name (f77).
78 N_FUN = 0x24, ///< Procedure.
79 N_STSYM = 0x26, ///< Static.
80 N_LCSYM = 0x28, ///< .lcomm.
81 N_MAIN = 0x2a, ///< Name of main rutine.
82 N_RSYM = 0x40, ///< Register.
83 N_SLINE = 0x44, ///< Source line.
84 N_SSYM = 0x60, ///< Structure.
85 N_SO = 0x64, ///< Source file name.
86 N_LSYM = 0x80, ///< Local.
87 N_BINCL = 0x82, ///< Header file.
88 N_SOL = 0x84, ///< #included file name.
89 N_PSYM = 0xa0, ///< Parameter.
90 N_EINCL = 0xa2, ///< End of include file.
91 N_LBRAC = 0xc0, ///< Left bracket.
92 N_EXCL = 0xc2, ///< Excluded include file.
93 N_RBRAC = 0xe0, ///< Right bracket.
94 N_BCOMM = 0xe2, ///< Begin common.
95 N_ECOMM = 0xe4, ///< End common.
96 N_ECOML = 0xe8, ///< End common (local name).
97 N_LENG = 0xfe, ///< Second symbol table entry with length.
98 N_PC = 0x30, ///< Global pascal symbol.
99 N_M2C = 0x42, ///< Compilation unit symbol table entry.
100 N_SCOPE = 0xc4, ///< Scope information.
101 N_BROWS = 0x48, ///< Sun source code browser.
102 N_PRTAB = 0xd2, ///< TCE processors resource entry.
103 N_ANN = 0xa4 ///< TCE annotation entry.
104 };
105
106
107 /**
108 * Names for a.out sections.
109 *
110 * Sections are expected in this order in a.out file.
111 * Since there is only one section of each type, these names
112 * can be used as section identifiers.
113 */
115 ST_UNDEF = 0x00, ///< Undefined section.
116 ST_TEXT = N_TEXT, ///< Text section.
117 ST_DATA = N_DATA, ///< Data section.
118 ST_UDATA = N_BSS, ///< Uninitialized data section.
119 ST_SYMBOL = 0x10, ///< Symbol table.
120 ST_STRING = 0x12 ///< String table.
121 };
122
123 /// Number of integer registers.
124 static const Word INT_REGISTERS;
125 /// Number of floating-point registers.
126 static const Word FP_REGISTERS;
127 /// Number of Boolean registers.
128 static const Word BOOL_REGISTERS;
129
130 /// Index of the first integer register in a.out.
131 static const Word FIRST_INT_REGISTER;
132 /// Index of the first floating-point register.
133 static const Word FIRST_FP_REGISTER;
134 /// Index of the first Boolean register.
135 static const Word FIRST_BOOL_REGISTER;
136 /// Index of the first function unit register.
137 static const Word FIRST_FU_REGISTER;
138
139 /// Size of one instruction in a.out file.
141
142 /// Minimum addressable word of address space.
144 /// Aligment of address space.
145 static const Byte AOUT_WORD_ALIGN;
146 /// Word size of address space.
147 static const Byte AOUT_WORD_SIZE;
148
149 /// Name of universal machines code address space.
150 static const char* AOUT_CODE_ASPACE_NAME;
151 /// Name of universal machines data address space.
152 static const char* AOUT_DATA_ASPACE_NAME;
153
154 /**
155 * Stores the data of a.out file header.
156 */
157 class Header {
158 public:
159 Header();
160 virtual ~Header();
161
162 void setSectionSizeData(Word size);
163 void setSectionSizeUData(Word size);
164 void setSectionSizeText(Word size);
165 void setSectionSizeSymbol(Word size);
166 void setSectionSizeTextReloc(Word size);
167 void setSectionSizeDataReloc(Word size);
168 void setSectionSizeString(Word size);
169 Word sectionSizeData() const;
170 Word sectionSizeUData() const;
171 Word sectionSizeText() const;
172 Word sectionSizeSymbol() const;
175 Word sectionSizeString() const;
176
177 private:
178
179 /// This structure holds the sizes of every section in bytes.
181 Word text_; ///< The size of text section.
182 Word data_; ///< The size of data section.
183 Word uData_; ///< The size of uninitialized data section.
184 Word textReloc_; ///< The size of text relocation section.
185 Word dataReloc_; ///< The size of data relocation section.
186 Word symbol_; ///< The size of symbol table.
187 Word string_; ///< The size of string section.
189
190 };
191
193
195
197
199
201
203
205
207
209
210 static const Header& header();
211
212protected:
213 AOutReader();
214 virtual ~AOutReader();
215
216 virtual Binary* readData(BinaryStream& stream) const;
217
218 virtual bool isMyStreamType(BinaryStream& stream) const;
219
220private:
221 void readHeader(BinaryStream& stream) const;
222
224 BinaryStream& stream, FileOffset startPosition, Section* section,
225 Length length) const;
226
227 void addOrDeleteSection(Section* section, Binary* binary) const;
228
229 /// Copying not allowed.
231 /// Assignment not allowed.
233
234 /// Undefined address space.
236 /// Address space of text section.
238 /// Address space of data sections.
240
241 // Processors resource table for AOoutSymbolSectionReader
243
244 // Null section for AOoutSymbolSectionReader
246
247 // Debug section
249
250 // String section
252
253 // Text section (a.out's code section)
255
256 /// Move a.out format identifier.
257 static const HalfWord OMAGIC;
258 /// Size of file header.
259 static const Byte FILE_HEADER_SIZE;
260
261 /// Header of a.out file.
263 /// Prototype instance of AOutReader registered into BinaryReader.
265};
266}
267
268#include "AOutReader.icc"
269#endif
UInt32 AddressImage
Type for storing addresses to memory image.
Definition BaseType.hh:179
unsigned char Byte
Definition BaseType.hh:116
Word sectionSizeText() const
void setSectionSizeSymbol(Word size)
void setSectionSizeData(Word size)
Word sectionSizeDataReloc() const
Word sectionSizeData() const
void setSectionSizeDataReloc(Word size)
void setSectionSizeTextReloc(Word size)
void setSectionSizeString(Word size)
void setSectionSizeText(Word size)
Word sectionSizeUData() const
void setSectionSizeUData(Word size)
Word sectionSizeSymbol() const
struct TPEF::AOutReader::Header::HeaderRawData sizes_
Word sectionSizeTextReloc() const
Word sectionSizeString() const
static const HalfWord OMAGIC
Move a.out format identifier.
static BinaryReader * instance()
static Header header_
Header of a.out file.
virtual Binary * readData(BinaryStream &stream) const
static const Word FIRST_INT_REGISTER
Index of the first integer register in a.out.
CodeSection * textSection() const
static const Byte AOUT_WORD_ALIGN
Aligment of address space.
static const Byte AOUT_WORD_SIZE
Word size of address space.
AOutReader & operator=(const AOutReader &)
Assignment not allowed.
static ResourceSection * resourceTable_
AddressImage addressOfElement(SectionElement *elem) const
void addOrDeleteSection(Section *section, Binary *binary) const
static const char * AOUT_CODE_ASPACE_NAME
Name of universal machines code address space.
void readHeader(BinaryStream &stream) const
virtual bool isMyStreamType(BinaryStream &stream) const
static const Word INT_REGISTERS
Number of integer registers.
@ ST_SYMBOL
Symbol table.
@ ST_UDATA
Uninitialized data section.
@ ST_STRING
String table.
@ ST_DATA
Data section.
@ ST_TEXT
Text section.
@ ST_UNDEF
Undefined section.
SectionOffset sectionOffsetOfAddress(AddressImage address) const
static const char * AOUT_DATA_ASPACE_NAME
Name of universal machines data address space.
static NullSection * nullSection_
ASpaceElement * codeASpace_
Address space of text section.
ASpaceElement * undefASpace_
Undefined address space.
static CodeSection * textSection_
static const Word FP_REGISTERS
Number of floating-point registers.
StringSection * stringSection() const
AOutReader(const AOutReader &)
Copying not allowed.
NullSection * nullSection() const
void readSection(BinaryStream &stream, FileOffset startPosition, Section *section, Length length) const
ASpaceElement * dataASpace_
Address space of data sections.
static StringSection * stringSection_
static const Byte FILE_HEADER_SIZE
Size of file header.
static DebugSection * debugSection_
DebugSection * debugSection() const
static const Word FIRST_BOOL_REGISTER
Index of the first Boolean register.
static const Word BOOL_REGISTERS
Number of Boolean registers.
ResourceSection * resourceTable() const
@ N_ANN
TCE annotation entry.
@ N_PSYM
Parameter.
Definition AOutReader.hh:89
@ N_ABS
Absolute.
Definition AOutReader.hh:63
@ N_BCOMM
Begin common.
Definition AOutReader.hh:94
@ N_FNAME
Procedure name (f77).
Definition AOutReader.hh:77
@ N_UNDF
Undefined.
Definition AOutReader.hh:62
@ N_LENG
Second symbol table entry with length.
Definition AOutReader.hh:97
@ N_BINCL
Header file.
Definition AOutReader.hh:87
@ N_EXCL
Excluded include file.
Definition AOutReader.hh:92
@ N_MAIN
Name of main rutine.
Definition AOutReader.hh:81
@ N_ECOML
End common (local name).
Definition AOutReader.hh:96
@ N_MEM
Memory reference.
Definition AOutReader.hh:73
@ N_FC
Function call.
Definition AOutReader.hh:74
@ N_FUN
Procedure.
Definition AOutReader.hh:78
@ N_SCOPE
Scope information.
@ N_PRTAB
TCE processors resource entry.
@ N_RBRAC
Right bracket.
Definition AOutReader.hh:93
@ N_COMM
Common (internal to ld).
Definition AOutReader.hh:67
@ N_BROWS
Sun source code browser.
@ N_ECOMM
End common.
Definition AOutReader.hh:95
@ N_LBRAC
Left bracket.
Definition AOutReader.hh:91
@ N_SOL
#included file name.
Definition AOutReader.hh:88
@ N_SLINE
Source line.
Definition AOutReader.hh:83
@ N_SO
Source file name.
Definition AOutReader.hh:85
@ N_STAB
Mask for stabs.
Definition AOutReader.hh:75
@ N_RSYM
Register.
Definition AOutReader.hh:82
@ N_FN
File name.
Definition AOutReader.hh:68
@ N_PC
Global pascal symbol.
Definition AOutReader.hh:98
@ N_JTE
Jump table entry.
Definition AOutReader.hh:72
@ N_M2C
Compilation unit symbol table entry.
Definition AOutReader.hh:99
@ N_EXT
Mask bit for external.
Definition AOutReader.hh:69
@ N_TJ
Table jump.
Definition AOutReader.hh:71
@ N_EINCL
End of include file.
Definition AOutReader.hh:90
@ N_TYPE
Mask bits for resolving symbol type.
Definition AOutReader.hh:70
@ N_SSYM
Structure.
Definition AOutReader.hh:84
static const Byte AOUT_INSTRUCTION_SIZE
Size of one instruction in a.out file.
virtual ~AOutReader()
static const Word FIRST_FU_REGISTER
Index of the first function unit register.
static const Word FIRST_FP_REGISTER
Index of the first floating-point register.
static AOutReader * proto_
Prototype instance of AOutReader registered into BinaryReader.
ASpaceElement * aSpaceOfElement(SectionElement *elem) const
static const Byte AOUT_BITS_PER_MAU
Minimum addressable word of address space.
static const Header & header()
unsigned long Length
Word SectionOffset
Type for storing offsets relative to a given base offset value.
Word FileOffset
Type for storing absolute file offsets.
This structure holds the sizes of every section in bytes.
Word textReloc_
The size of text relocation section.
Word uData_
The size of uninitialized data section.
Word data_
The size of data section.
Word dataReloc_
The size of data relocation section.
Word text_
The size of text section.
Word symbol_
The size of symbol table.
Word string_
The size of string section.