rsp2elf.h
6.74 KB
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
203
#include <iostream.h>
#include <iomanip.h>
void nospace( void );
int GetFileOfAddr( unsigned long );
class symbol {
char * symName;
unsigned long symValue;
int localIndex, globalIndex, symIndex, symType, symFile;
public:
symbol * next, * pnext;
symbol( char * name, unsigned long value, int type ) {
next = 0; pnext = 0; localIndex = 0; globalIndex = 0;
symIndex = 0;
symName = name; symValue = value; symType = type;
symFile = GetFileOfAddr( value ); }
void print( void ) { cout << " SYM " << symName << " Val " << hex <<
symValue << dec << " loc strndx " << localIndex <<
" glb strndx " << globalIndex << " type " << symType <<
" file " << symFile << endl; }
void AsgFile( void ) { symFile = GetFileOfAddr( symValue ); }
int matches( char * s ) { return !strcmp( s, symName ); }
void AsgGlobalIndex( int index ) { globalIndex = index; }
void AsgLocalIndex( int index ) { localIndex = index; }
void AsgSymIndex( int index ) { symIndex = index; }
char * NameIs( void ) { return symName; }
int GetGlobalIndex( void ) { return globalIndex; }
int GetLocalIndex( void ) { return localIndex; }
unsigned long GetValue( void ) { return symValue; }
int GetType( void ) { return symType; }
int GetSymIndex( void ) { return symIndex; }
int GetFile( void ) { return symFile; }
};
class line {
int lineNumber;
friend class proc;
friend class source;
public:
line * next;
line( int l ) { next = 0; lineNumber = l; }
void print( void ) { cout << lineNumber << ' '; }
int LineIs( void ) { return lineNumber; }
};
class proc {
char * procName;
unsigned long lowAddr, highAddr;
line * lineList, * lineLast;
int lowLine, highLine, localIndex, auxEntry, firstSym,
lineCount, lineIndex;
symbol * symList, * symLast; // symbols associated with proc
public:
proc * next;
proc() { next = 0; symList = 0; lowLine = 0; highLine = 0;
lowAddr = 0; highAddr = 0; localIndex = 0; auxEntry = 0;
firstSym = 0; lineIndex = 0; lineList = 0; lineCount = 0; }
void print( void );
void callMe( char * s ) {
procName = (char *) malloc( strlen( s ) + 1 );
if ( !procName ) nospace();
strcpy( procName, s ); }
void newhigh( unsigned long addr, line * l ) {
highAddr = addr; highLine = l->lineNumber; }
void newlow( unsigned long addr, int line ) {
lowAddr = addr; lowLine = line; }
void InheritLines( line * first, line * last ) {
lineList = first; lineLast = last; }
void InheritLabels( symbol * first, symbol * last ) {
symList = first; symLast = last; }
char * nameIs() { return procName; }
int contains( unsigned long addr );
unsigned long FirstInst( void ) { return lowAddr; }
unsigned long NextInst( void ) { return highAddr + 1; }
int FirstLine( void ) { return lowLine; }
int LastLine( void ) { return highLine; }
void AddLine( line * l );
void AddSymbol( symbol * sym ) {
if ( symList )
symLast->pnext = sym;
else
symList = sym;
symLast = sym; }
void AsgSymIndex( int index );
symbol * GetLabels( void ) { return symList; }
void AsgLocalIndex( int index ) { localIndex = index; }
void AsgAux( int aux ) { auxEntry = aux; }
void AsgFirstSym( int s ) { firstSym = s; }
void AsgLineIndex( int li ) { lineIndex = li; }
void NewLineRange( int low, int high ) { lowLine = low;
highLine = high; }
int GetAux( void ) { return auxEntry; }
int GetStringIndex( void ) { return localIndex; }
int GetFirstSym( void ) { return firstSym; }
int GetLineIndex( void ) { return lineIndex; }
line * GetLines( void ) { return lineList; }
};
class range {
unsigned long lowAddr, highAddr;
int lowLine, highLine;
friend class source;
public:
range * next;
range( unsigned long addr, int line ) {
next = 0; lowLine = line;
highLine = line + 1;
lowAddr = addr;
highAddr = addr + 3;
}
void print( void ) { cout << " RANGE addr " << hex << lowAddr <<
":" << highAddr << dec << " lines " << lowLine << ":" <<
highLine << endl; }
int inrange( unsigned long addr );
unsigned long endOfRange( void ) { return highAddr; }
void extend( int newline ) {
highAddr += 4; highLine = newline;
}
};
class source {
char * fileName;
range * rangeList, * rangeLast;
line * lineList, * lineLast;
proc * procList, * procLast;
symbol * symList, * symLast; // symbols with no proc
int stringIndex, stringSize, firstSym, lineCount, lineBytes,
lineBase, procCount, labelCount, auxBase;
public:
source * next;
source() { next = 0; rangeList = 0; lineList = 0; lineCount = 0;
procCount = 0; procList = 0; labelCount = 0; lineBase = 0;
auxBase = 0; symList = 0; }
void print( void ) { cout << "FILE " << fileName << " strndx "
<< stringIndex << " strsize " << stringSize << " 1stsym "
<< firstSym << " lines " << lineCount << " 1stlin " <<
lineBase << " procs " << procCount << endl; }
void PrintProcs( void );
void PrintSymbols( void );
void callMe( char * s ) {
fileName = (char *) malloc( strlen( s ) + 1 );
if ( !fileName ) nospace();
strcpy( fileName, s ); }
int containsAddr( unsigned long addr );
void newRange( unsigned long addr, int sourceLine );
void AddProc( proc * p );
void JamProc( proc * p ) { procList = p; ++procCount; }
void AddLine( line * l );
void AddSymbol( symbol * sym );
void MakeProcForFile( void );
void AsgLineBase( int l ) { lineBase = l; }
void AsgLineBytes( int l ) { lineBytes = l; }
void AsgStringIndex( int l ) { stringIndex = l; }
void AsgStringSize( int l ) { stringSize = l; }
void AsgFirstSym( int l ) { firstSym = l; }
void OneMoreLabel( void ) { ++labelCount; }
void OneMoreLine( void ) { ++lineCount; }
void AsgAuxBase( int a ) { auxBase = a; }
char * filename( void ) { return fileName; }
range * firstRange( void ) { return rangeList; }
line * GetLines( void ) { return lineList; }
proc * GetProcs( void ) { return procList; }
int FirstLineIs( void ) { return lineList->lineNumber; }
int LastLineIs( void ) { return lineLast->lineNumber; }
int StringIndexIs( void ) { return stringIndex; }
int StringSizeIs( void ) { return stringSize; }
int FirstSymIs( void ) { return firstSym; }
int ProcCountIs( void ) { return procCount; }
int LineCountIs( void ) { return lineCount; }
int LabelCountIs( void ) { return labelCount; }
int LineBytesIs( void ) { return lineBytes; }
unsigned long FirstInst( void ) { return rangeList->lowAddr; }
unsigned long NextInst( void ) { return rangeLast->highAddr + 1; }
symbol * GetLabels( void ) { return symList; }
int LineBaseIs( void ) { return lineBase; }
int GetAuxBase( void ) { return auxBase; }
};
#define IMEM_START 0x4001000
#define DMEM_START 0x4000000
/* decls */
void WriteString( char * );
int NewSymbol( char * , unsigned long , int );
void BuildFileTable( void );
void WriteDebugInfo( void );
void AddSymToFile( symbol * sym );
void DumpFileTable( void );
void CleanupInfo( void );
void AddSyntheticProc( void );
int SymBaseOfFile( int );