2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/**********************************************************************
|
|
|
32 |
$Author: release $
|
|
|
33 |
$Date: 1998/02/04 10:43:42 $
|
|
|
34 |
$Revision: 1.2 $
|
|
|
35 |
$Log: makesymtab.c,v $
|
|
|
36 |
* Revision 1.2 1998/02/04 10:43:42 release
|
|
|
37 |
* Changes during testing.
|
|
|
38 |
*
|
|
|
39 |
* Revision 1.1.1.1 1998/01/17 15:56:06 release
|
|
|
40 |
* First version to be checked into rolling release.
|
|
|
41 |
*
|
|
|
42 |
* Revision 1.3 1995/11/23 13:17:22 currie
|
|
|
43 |
* Cache real consts + get text file name right in diags
|
|
|
44 |
*
|
|
|
45 |
* Revision 1.2 1995/09/12 10:59:32 currie
|
|
|
46 |
* gcc pedanttry
|
|
|
47 |
*
|
|
|
48 |
* Revision 1.1 1995/04/13 09:08:06 currie
|
|
|
49 |
* Initial revision
|
|
|
50 |
*
|
|
|
51 |
***********************************************************************/
|
|
|
52 |
#include "config.h"
|
|
|
53 |
#include "cross_config.h"
|
|
|
54 |
|
|
|
55 |
#ifndef CROSS_INCLUDE
|
|
|
56 |
#include <symconst.h>
|
|
|
57 |
#else
|
|
|
58 |
#include CROSS_INCLUDE/symconst.h>
|
|
|
59 |
#endif
|
|
|
60 |
|
|
|
61 |
#include "symtab.h"
|
|
|
62 |
#include "common_types.h"
|
|
|
63 |
#include "flags.h"
|
|
|
64 |
#include "makesymtab.h"
|
|
|
65 |
#include "xalloc.h"
|
|
|
66 |
|
|
|
67 |
extern bool BIGEND;
|
|
|
68 |
int MAJOR_VERSION_as = 3;
|
|
|
69 |
int MINOR_VERSION_as = 12;
|
|
|
70 |
|
|
|
71 |
long count_syms
|
|
|
72 |
PROTO_N ( (symlist) )
|
|
|
73 |
PROTO_T ( LSYMS* symlist )
|
|
|
74 |
{
|
|
|
75 |
long symindex = symlist->noofsyms;
|
|
|
76 |
while (symlist->nextsyms!=0)
|
|
|
77 |
{ symlist=symlist->nextsyms;
|
|
|
78 |
symindex+=symlist->noofsyms;
|
|
|
79 |
}
|
|
|
80 |
return symindex;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
long count_strings
|
|
|
85 |
PROTO_N ( (list) )
|
|
|
86 |
PROTO_T ( STRINGS* list )
|
|
|
87 |
{
|
|
|
88 |
long stringind=list->usage;
|
|
|
89 |
while (list->overspill!=0)
|
|
|
90 |
{ list=list->overspill;
|
|
|
91 |
stringind+=list->usage;
|
|
|
92 |
}
|
|
|
93 |
return stringind;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
long count_aux
|
|
|
98 |
PROTO_N ( (auxdata) )
|
|
|
99 |
PROTO_T ( AUXTAB* auxdata )
|
|
|
100 |
{
|
|
|
101 |
long auxcount=auxdata->num;
|
|
|
102 |
while (auxdata->moreaux!=0)
|
|
|
103 |
{ auxdata=auxdata->moreaux;
|
|
|
104 |
auxcount+=auxdata->num;
|
|
|
105 |
}
|
|
|
106 |
return auxcount;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
/* Function to make a symbol table from various components.
|
|
|
112 |
Sets up a .T file for use by as1 (this function is called from
|
|
|
113 |
new_symbol.c using output_symtab(name of .T file). )
|
|
|
114 |
by R.R.R 3/12/90 */
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
void makesymtab
|
|
|
118 |
PROTO_N ((extstrings, extsymbols, densenos, filedescs, numfiles,
|
|
|
119 |
symtabname, noextsyms, nosyms, extstringsize, stringsize,
|
|
|
120 |
noaux, densind, procinds, noprocs))
|
|
|
121 |
PROTO_T ( STRINGS* extstrings X ESYMS* extsymbols X DENSETAB* densenos X
|
|
|
122 |
pSYMFDR filedescs X long numfiles X char* symtabname X
|
|
|
123 |
long noextsyms X long nosyms X long extstringsize X
|
|
|
124 |
long stringsize X long noaux X long densind X
|
|
|
125 |
PROCSYM* procinds X long noprocs )
|
|
|
126 |
{
|
|
|
127 |
|
|
|
128 |
/* function to produce a symbol table (.T file), from information supplied
|
|
|
129 |
by the translator, including TDF diagnostics. The output file and the
|
|
|
130 |
binary assembler file (.G , made by as0 on a *.s file) can then be
|
|
|
131 |
passed to as1 */
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
LSYMS * symlist;
|
|
|
135 |
|
|
|
136 |
HDRR symhdrout; /* symbolic header */
|
|
|
137 |
int i,j;
|
|
|
138 |
FDR fdrtab;
|
|
|
139 |
long stroff=0;
|
|
|
140 |
long symoff=0;
|
|
|
141 |
long procoff=0;
|
|
|
142 |
long auxoff=0;
|
|
|
143 |
PDR* pdr_ptr;
|
|
|
144 |
STRINGS* tempstrings;
|
|
|
145 |
AUXTAB* auxdata;
|
|
|
146 |
pSYMFDR tempfileptr;
|
|
|
147 |
FILE* sym_tab_file = fopen(symtabname,"w");
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
/****************** set up new symbolic header **********************/
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
symhdrout.magic = magicSym; /* defined in symconst.h */
|
|
|
154 |
symhdrout.vstamp = MAJOR_VERSION_as*256+MINOR_VERSION_as;
|
|
|
155 |
symhdrout.ilineMax = 0;
|
|
|
156 |
symhdrout.cbLine = 0;
|
|
|
157 |
symhdrout.cbLineOffset = 0;
|
|
|
158 |
symhdrout.ipdMax = noprocs;
|
|
|
159 |
symhdrout.cbPdOffset = sizeof(HDRR);
|
|
|
160 |
symhdrout.isymMax = nosyms;
|
|
|
161 |
symhdrout.cbSymOffset = symhdrout.cbPdOffset + noprocs*sizeof(PDR);
|
|
|
162 |
symhdrout.ioptMax = 0;
|
|
|
163 |
symhdrout.cbOptOffset = 0;
|
|
|
164 |
symhdrout.iauxMax = noaux;
|
|
|
165 |
symhdrout.cbAuxOffset = symhdrout.cbSymOffset + nosyms*sizeof(SYMR);
|
|
|
166 |
symhdrout.issMax = stringsize;
|
|
|
167 |
symhdrout.cbSsOffset = symhdrout.cbAuxOffset + noaux*sizeof(AUXU);
|
|
|
168 |
symhdrout.issExtMax = extstringsize;
|
|
|
169 |
symhdrout.cbSsExtOffset = symhdrout.cbSsOffset + stringsize;
|
|
|
170 |
symhdrout.ifdMax = numfiles;
|
|
|
171 |
symhdrout.cbFdOffset = symhdrout.cbSsExtOffset + extstringsize;
|
|
|
172 |
symhdrout.crfd = 0;
|
|
|
173 |
symhdrout.cbRfdOffset = 0; /* something may need to be done here */
|
|
|
174 |
symhdrout.iextMax = noextsyms;
|
|
|
175 |
symhdrout.cbExtOffset = symhdrout.cbFdOffset + symhdrout.ifdMax*sizeof(FDR);
|
|
|
176 |
|
|
|
177 |
/* Dense numbers */
|
|
|
178 |
|
|
|
179 |
symhdrout.idnMax = densind;
|
|
|
180 |
symhdrout.cbDnOffset = symhdrout.cbExtOffset + symhdrout.iextMax*sizeof(EXTR);
|
|
|
181 |
|
|
|
182 |
/* write header to output file */
|
|
|
183 |
|
|
|
184 |
fwrite(&symhdrout,sizeof(HDRR),1,sym_tab_file);
|
|
|
185 |
|
|
|
186 |
/******************** header completed *************************/
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
/**************** write the tables to the file ******************/
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
tempfileptr=filedescs;
|
|
|
194 |
|
|
|
195 |
/* initialise proc info */
|
|
|
196 |
pdr_ptr=(PDR*)xcalloc(1,sizeof(PDR));
|
|
|
197 |
for (j=0;j<numfiles;j++)
|
|
|
198 |
{PROCSYM* procindptr=procinds;
|
|
|
199 |
for (i=1;i<=noprocs;i++,procindptr++)
|
|
|
200 |
{if (procindptr->fnum==j)
|
|
|
201 |
{
|
|
|
202 |
pdr_ptr->isym=procindptr->procsymindex;
|
|
|
203 |
fwrite(pdr_ptr,sizeof(PDR),1,sym_tab_file);
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
/* write local symbols */
|
|
|
209 |
|
|
|
210 |
for (i=1;i<=numfiles;i++,tempfileptr++)
|
|
|
211 |
{symlist=tempfileptr->symbols;
|
|
|
212 |
while (symlist)
|
|
|
213 |
{
|
|
|
214 |
fwrite(symlist->symlist,sizeof(SYMR), symlist->noofsyms, sym_tab_file);
|
|
|
215 |
symlist=symlist->nextsyms;
|
|
|
216 |
}
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
/* write auxillary symbol entries */
|
|
|
220 |
|
|
|
221 |
tempfileptr=filedescs;
|
|
|
222 |
for (i=1;i<=numfiles;i++,tempfileptr++)
|
|
|
223 |
{auxdata=tempfileptr->auxtabs;
|
|
|
224 |
while (auxdata)
|
|
|
225 |
{ fwrite(auxdata->auxinfo,sizeof(AUXU),auxdata->num,
|
|
|
226 |
sym_tab_file);
|
|
|
227 |
auxdata=auxdata->moreaux;
|
|
|
228 |
}
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
/* write local strings */
|
|
|
232 |
|
|
|
233 |
tempfileptr=filedescs;
|
|
|
234 |
for (i=1;i<=numfiles;i++,tempfileptr++)
|
|
|
235 |
{
|
|
|
236 |
tempstrings = tempfileptr->filestr;
|
|
|
237 |
while (tempstrings)
|
|
|
238 |
{
|
|
|
239 |
fwrite(tempstrings->str, sizeof(char), tempstrings->usage,sym_tab_file);
|
|
|
240 |
tempstrings=tempstrings->overspill;
|
|
|
241 |
}
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
/* write external strings */
|
|
|
246 |
|
|
|
247 |
tempstrings=extstrings;
|
|
|
248 |
while (tempstrings)
|
|
|
249 |
{
|
|
|
250 |
fwrite(tempstrings->str, sizeof(char), tempstrings->usage,sym_tab_file);
|
|
|
251 |
tempstrings=tempstrings->overspill;
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
/* write file descriptors */
|
|
|
256 |
|
|
|
257 |
tempfileptr=filedescs;
|
|
|
258 |
for(i=1;i<=numfiles;i++,tempfileptr++)
|
|
|
259 |
|
|
|
260 |
{long count;
|
|
|
261 |
fdrtab.adr=0;
|
|
|
262 |
fdrtab.rss=1; /* source file name at start of lsymbols */
|
|
|
263 |
fdrtab.issBase = stroff;
|
|
|
264 |
count= count_strings(tempfileptr->filestr);
|
|
|
265 |
stroff+=count;
|
|
|
266 |
fdrtab.cbSs=count;
|
|
|
267 |
count=count_syms(tempfileptr->symbols);
|
|
|
268 |
fdrtab.isymBase = symoff;
|
|
|
269 |
symoff+=count;
|
|
|
270 |
fdrtab.csym=count;
|
|
|
271 |
fdrtab.ilineBase=0;
|
|
|
272 |
fdrtab.cline=0;
|
|
|
273 |
fdrtab.ioptBase=0;
|
|
|
274 |
fdrtab.copt=0;
|
|
|
275 |
fdrtab.ipdFirst=procoff;
|
|
|
276 |
procoff+=tempfileptr->proc_count;
|
|
|
277 |
fdrtab.cpd = tempfileptr->proc_count;
|
|
|
278 |
fdrtab.iauxBase = auxoff;
|
|
|
279 |
count=count_aux(tempfileptr->auxtabs);
|
|
|
280 |
auxoff+=count;
|
|
|
281 |
fdrtab.caux=count;
|
|
|
282 |
fdrtab.rfdBase=0;
|
|
|
283 |
fdrtab.crfd=0;
|
|
|
284 |
fdrtab.lang=langC; /* C ,see symconst.h */
|
|
|
285 |
fdrtab.fMerge=0; /* 1 for .h files I think */
|
|
|
286 |
fdrtab.fReadin=0;
|
|
|
287 |
fdrtab.fBigendian=BIGEND;
|
|
|
288 |
fdrtab.glevel= diagnose?GLEVEL_2:GLEVEL_0;
|
|
|
289 |
fdrtab.reserved=0; /* what else ! */
|
|
|
290 |
fdrtab.cbLineOffset=0; /* ??? */
|
|
|
291 |
fdrtab.cbLine=0; /* ??? */
|
|
|
292 |
|
|
|
293 |
fwrite(&fdrtab,sizeof(FDR),1,sym_tab_file);
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
/*appears to write the right stuff so is it the right place?? */
|
|
|
297 |
/* write external symbols */
|
|
|
298 |
|
|
|
299 |
while (extsymbols)
|
|
|
300 |
{
|
|
|
301 |
fwrite(extsymbols->symlist, sizeof(EXTR), extsymbols->noofsyms, sym_tab_file);
|
|
|
302 |
extsymbols=extsymbols->nextsyms;
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
/* write dense nos */
|
|
|
306 |
|
|
|
307 |
while (densenos)
|
|
|
308 |
{
|
|
|
309 |
fwrite(densenos->densenolist,sizeof(DNR),densenos->num,sym_tab_file);
|
|
|
310 |
densenos=densenos->moredensenos;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
fclose(sym_tab_file);
|
|
|
314 |
return;
|
|
|
315 |
}
|