Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
/* 	$Id: makesymtab.c,v 1.2 1998/02/04 10:43:31 release Exp $	 */
32
 
33
#ifndef lint
34
static char vcid[] = "$Id: makesymtab.c,v 1.2 1998/02/04 10:43:31 release Exp $";
35
#endif /* lint */
36
 
37
#include "config.h"
38
#include "symtab.h"	
39
#include "makesymtab.h"	
40
#include "xalloc.h"
41
#include "cross_config.h"
42
/* type definitions for translator produced debugging 
43
   information to be incorporated into a .T file  */
44
 
45
#ifndef CROSS_INCLUDE
46
#include <symconst.h>
47
#else
48
#include CROSS_INCLUDE/symconst.h>
49
#endif
50
 
51
/*
52
$Log: makesymtab.c,v $
53
 * Revision 1.2  1998/02/04  10:43:31  release
54
 * Changes during testing.
55
 *
56
 * Revision 1.1.1.1  1998/01/17  15:56:00  release
57
 * First version to be checked into rolling release.
58
 *
59
 * Revision 1.3  1995/06/28  10:25:22  john
60
 * Changed value in file header
61
 *
62
 * Revision 1.2  1995/05/23  10:57:04  john
63
 * Reformatting
64
 *
65
 * Revision 1.1.1.1  1995/03/23  10:39:30  john
66
 * Entered into CVS
67
 *
68
 * Revision 1.6  1995/01/26  13:44:02  john
69
 * Removed unused variables and fixed memory allocation
70
 *
71
 * Revision 1.5  1995/01/12  15:09:35  john
72
 * Generalised magic number
73
 *
74
*/
75
 
76
 
77
extern char diagnose;
78
 
79
 
80
long count_syms
81
    PROTO_N ( ( symlist ) )
82
    PROTO_T ( LSYMS *symlist )
83
{
84
  long symindex = symlist->noofsyms;
85
  while (symlist->nextsyms!=0){  
86
    symlist=symlist->nextsyms;
87
    symindex+=symlist->noofsyms;
88
  }
89
  return symindex;
90
}
91
 
92
 
93
long count_strings
94
    PROTO_N ( ( list ) )
95
    PROTO_T ( STRINGS *list )
96
{
97
  long stringind=list->usage;
98
  while (list->overspill!=0){
99
    list=list->overspill;
100
    stringind+=list->usage;
101
  }
102
  return stringind;
103
}
104
 
105
 
106
long count_aux
107
    PROTO_N ( ( auxdata ) )
108
    PROTO_T ( AUXTAB *auxdata )
109
{
110
  long auxcount=auxdata->num;
111
  while (auxdata->moreaux!=0){
112
    auxdata=auxdata->moreaux;
113
    auxcount+=auxdata->num;
114
  }	
115
  return auxcount;
116
}
117
 
118
#define MAJOR_ASSEMBLER_VERSION 3
119
#define MINOR_ASSEMBLER_VERSION 11
120
 
121
 
122
/* 
123
   Function to make a symbol table from various components. 
124
   Sets up a .T file for use by as1 (this function is called 
125
   from new_symbol.c using output_symtab(name of .T file). )
126
   by R.R.R  3/12/90  
127
*/
128
void makesymtab
129
    PROTO_N ( ( extstrings,extsymbols,densenos,filedescs,numfiles,
130
		symtabname,noextsyms,nosyms,extstringsize,stringsize,
131
		noaux,densind,procinds,noprocs ) )
132
    PROTO_T ( STRINGS *extstrings X ESYMS* extsymbols X DENSETAB* densenos X
133
	      pSYMFDR filedescs X int numfiles X char* symtabname X
134
	      int noextsyms X int nosyms X int extstringsize X
135
	      int stringsize X int noaux X int densind X
136
	      PROCSYM* procinds X int noprocs )
137
{
138
 
139
 
140
/* 
141
   function to produce a symbol table (.T file), from information 
142
   supplied by the translator, including TDF diagnostics. 
143
   The output file and the binary assembler file (.G , made by 
144
   as0 on a *.s file) can then be passed to as1 
145
*/
146
  LSYMS * symlist;
147
 
148
  HDRR symhdrout;				/* symbolic header */	
149
  int i,j;
150
  FDR fdrtab;
151
  long stroff=0;
152
  long symoff=0;
153
  long procoff=0;
154
  long auxoff=0;
155
  PDR* pdr_ptr;			
156
  STRINGS* tempstrings;
157
  AUXTAB* auxdata;
158
  pSYMFDR tempfileptr;
159
  FILE* sym_tab_file = fopen(symtabname,"w");
160
 
161
 
162
/**************  set up new symbolic header  **********************/
163
 
164
 
165
  symhdrout.magic = magicSym;	/* defined in symconst.h */
166
  symhdrout.vstamp = MAJOR_ASSEMBLER_VERSION*256+MINOR_ASSEMBLER_VERSION;
167
  symhdrout.ilineMax = 0;
168
  symhdrout.cbLine = 0;
169
  symhdrout.cbLineOffset = 0;
170
  symhdrout.ipdMax = noprocs;
171
  symhdrout.cbPdOffset = (long)sizeof(HDRR);
172
  symhdrout.isymMax = nosyms;
173
  symhdrout.cbSymOffset = symhdrout.cbPdOffset + noprocs*sizeof(PDR);
174
  symhdrout.ioptMax = 0;
175
  symhdrout.cbOptOffset = 0;
176
  symhdrout.iauxMax = noaux;
177
  symhdrout.cbAuxOffset = symhdrout.cbSymOffset + nosyms*sizeof(SYMR);
178
  symhdrout.issMax = stringsize;
179
  symhdrout.cbSsOffset = symhdrout.cbAuxOffset + noaux*sizeof(AUXU);
180
  symhdrout.issExtMax = extstringsize;
181
  symhdrout.cbSsExtOffset = symhdrout.cbSsOffset + stringsize;
182
  symhdrout.ifdMax = numfiles;
183
  symhdrout.cbFdOffset = symhdrout.cbSsExtOffset + extstringsize;
184
  symhdrout.crfd = 0;
185
  symhdrout.cbRfdOffset = 0;	/* something may need to be done here */
186
  symhdrout.iextMax = noextsyms;
187
  symhdrout.cbExtOffset = symhdrout.cbFdOffset + symhdrout.ifdMax*sizeof(FDR);
188
 
189
/* Dense numbers */
190
 
191
  symhdrout.idnMax = densind;
192
  symhdrout.cbDnOffset = symhdrout.cbExtOffset + symhdrout.iextMax*sizeof(EXTR);
193
 
194
/* write header to output file */
195
 
196
  fwrite(&symhdrout,sizeof(HDRR),1,sym_tab_file);
197
 
198
/********************  header completed  *************************/
199
 
200
 
201
 
202
/**************** write the tables to the file  ******************/
203
 
204
 
205
  tempfileptr=filedescs;
206
 
207
 
208
/* initialise proc info */
209
  pdr_ptr=(PDR*)xcalloc(1,sizeof(PDR));
210
  for (j=0;j<numfiles;j++){
211
    PROCSYM* procindptr=procinds;
212
    for (i=1;i<=noprocs;i++,procindptr++){
213
      if (procindptr->fnum==j){
214
	pdr_ptr->isym=procindptr->procsymindex;
215
	fwrite(pdr_ptr,sizeof(PDR),1,sym_tab_file);
216
      }
217
    }
218
  }
219
 
220
/* write local symbols */
221
 
222
  for (i=1;i<=numfiles;i++,tempfileptr++){
223
    symlist=tempfileptr->symbols;
224
    while (symlist){
225
      fwrite(symlist->symlist,sizeof(SYMR), symlist->noofsyms, sym_tab_file);
226
      symlist=symlist->nextsyms;
227
    }
228
  }
229
 
230
/* write auxillary symbol entries */
231
 
232
  tempfileptr=filedescs;
233
  for (i=1;i<=numfiles;i++,tempfileptr++){
234
    auxdata=tempfileptr->auxtabs;
235
    while (auxdata){
236
      fwrite(auxdata->auxinfo,sizeof(AUXU),auxdata->num, sym_tab_file);
237
      auxdata=auxdata->moreaux;
238
    }
239
  }
240
 
241
/* write local strings */
242
 
243
  tempfileptr=filedescs;
244
  for (i=1;i<=numfiles;i++,tempfileptr++){
245
    tempstrings = tempfileptr->filestr;
246
    while (tempstrings){
247
      fwrite(tempstrings->str, sizeof(char), tempstrings->usage,sym_tab_file);
248
      tempstrings=tempstrings->overspill;
249
    }	
250
  }
251
 
252
 
253
/* write external strings */
254
 
255
  tempstrings=extstrings;
256
  while (tempstrings){
257
    fwrite(tempstrings->str, sizeof(char), tempstrings->usage,sym_tab_file);
258
    tempstrings=tempstrings->overspill;
259
  }
260
 
261
 
262
/* write file descriptors */
263
 
264
  tempfileptr=filedescs;
265
  for(i=1;i<=numfiles;i++,tempfileptr++){
266
    long count;
267
    fdrtab.adr=0;
268
    fdrtab.rss=1;	/* source file name at start of lsymbols */
269
    fdrtab.issBase = stroff;
270
    count= count_strings(tempfileptr->filestr);
271
    stroff+=count;
272
    fdrtab.cbSs=count;
273
    count=count_syms(tempfileptr->symbols);
274
    fdrtab.isymBase = symoff;
275
    symoff+=count;
276
    fdrtab.csym=count;
277
    fdrtab.ilineBase=0;
278
    fdrtab.cline=0;
279
    fdrtab.ioptBase=0;
280
    fdrtab.copt=0;
281
    fdrtab.ipdFirst=procoff;
282
    procoff+=tempfileptr->proc_count;
283
    fdrtab.cpd = tempfileptr->proc_count;
284
    fdrtab.iauxBase = auxoff;
285
    count=count_aux(tempfileptr->auxtabs);
286
    auxoff+=count;
287
    fdrtab.caux=count;
288
    fdrtab.rfdBase=0;
289
    fdrtab.crfd=0;
290
    fdrtab.lang=langC;	/* C ,see symconst.h  */
291
    fdrtab.fMerge=0;	/* 1 for .h files I think */
292
    fdrtab.fReadin=0;
293
    fdrtab.fBigendian=0;
294
    fdrtab.glevel= diagnose?GLEVEL_2 : GLEVEL_0;
295
    fdrtab.reserved=0;	/* what else ! */
296
    fdrtab.cbLineOffset=0;	/* ??? */
297
    fdrtab.cbLine=0;	/* ??? */
298
 
299
    fwrite(&fdrtab,sizeof(FDR),1,sym_tab_file);
300
  }
301
 
302
/*appears to write the right stuff so is it the right place?? */
303
/* write external symbols */
304
 
305
  while (extsymbols){
306
    fwrite(extsymbols->symlist, sizeof(EXTR), extsymbols->noofsyms, 
307
	   sym_tab_file);
308
    extsymbols=extsymbols->nextsyms;
309
  }
310
 
311
/* write dense nos */
312
 
313
  while (densenos){
314
    fwrite(densenos->densenolist,sizeof(DNR),densenos->num,sym_tab_file);
315
    densenos=densenos->moredensenos;
316
  }
317
 
318
  fclose(sym_tab_file);
319
 
320
  return;
321
 
322
}