Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | 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
/**********************************************************************
32
$Author: release $
33
$Date: 1998/02/04 10:43:37 $
34
$Revision: 1.2 $
35
$Log: dwarf_loc.c,v $
36
 * Revision 1.2  1998/02/04  10:43:37  release
37
 * Changes during testing.
38
 *
39
 * Revision 1.1.1.1  1998/01/17  15:55:47  release
40
 * First version to be checked into rolling release.
41
 *
42
 * Revision 1.3  1997/02/19  12:53:44  pwe
43
 * NEWDIAGS for debugging optimised code
44
 *
45
 * Revision 1.2  1995/09/28  12:39:42  pwe
46
 * dwarf.h via import, and type changes for tcc checks
47
 *
48
 * Revision 1.1.1.1  1995/08/14  14:30:21  pwe
49
 * transferred from DJCH
50
 *
51
**********************************************************************/
52
 
53
/* LOG 6/9/93 changes for sparc/ICL port of SVR4.2 djch
54
   new stuff for sparc registers  added by ra 8/9/93 */
55
 
56
/* LOG 27/9/93 removing the blocks aroung locations djch */
57
/* LOG 26/11/93 proc_no long -> int to shut up tdfc djch */
58
 
59
#include "config.h"
60
#include "common_types.h"
61
#include "installtypes.h"
62
 
63
/* machine dependent */
64
#include "machine.h"
65
#include "codermacs.h"
66
 
67
#include "tags.h"
68
 
69
/* machine dependent */
70
#include "out.h"
71
 
72
#include "shapemacs.h"
73
 
74
/* machine dependent */
75
#include "expmacs.h"
76
 
77
#include "basicread.h"
78
 
79
#include "dwarf_types.h"
80
#include "dwarf_out.h"
81
#include "dwarf_queue.h"
82
#include "dwarf_type.h"
83
 
84
#include "dwarf_loc.h"
85
#include "cross_config.h"
86
 
87
#ifndef CROSS_INCLUDE
88
#include <dwarf.h>
89
#else
90
#include CROSS_INCLUDE/dwarf.h>
91
#endif
92
 
93
void out_dwarf_const4
94
    PROTO_N ( (x) )
95
    PROTO_T ( exp x )
96
{
97
  if (name(x) != val_tag && name(x) != null_tag)
98
  {
99
    failer("non const exp in out_dwarf_const4");
100
    return;
101
  }
102
  dwarf4n(no(x));
103
}
104
 
105
void out_dwarf_const_by8
106
    PROTO_N ( (x) )
107
    PROTO_T ( exp x )
108
{
109
  if (name(x) != val_tag)
110
  {
111
    failer("non const exp in out_dwarf_const_by8");
112
    return;
113
  }
114
  dwarf4n((no(x)/8));
115
}
116
 
117
void out_dwarf_member_loc_attr
118
    PROTO_N ( (e) )
119
    PROTO_T ( exp e )
120
{
121
  int o;
122
 
123
  OUT_DWARF_ATTR(AT_location);
124
  if (name(e) != val_tag)
125
    failer("out_mem_loc_attr");
126
 
127
#ifdef LOCS_IN_BLKS
128
  new_dwarf_blk2();
129
#else
130
  OUT_DWARF_LOC_BLK(6);
131
#endif
132
  o = no(e)/8;
133
  dwarf1(OP_CONST);
134
  dwarf4n(o);
135
  dwarf1(OP_ADD);
136
#ifdef LOCS_IN_BLKS
137
  leave_dwarf_blk2();
138
#endif
139
}
140
 
141
/* given the bit offset to base of anon object */
142
void out_dwarf_bit_member_loc_attr
143
    PROTO_N ( (u) )
144
    PROTO_T ( int u )
145
{
146
  OUT_DWARF_ATTR(AT_location);
147
 
148
#ifdef LOCS_IN_BLKS
149
  new_dwarf_blk2();
150
#else
151
  OUT_DWARF_LOC_BLK(6);
152
#endif
153
  dwarf1(OP_CONST);
154
  dwarf4n(u/8);
155
  dwarf1(OP_ADD);
156
#ifdef LOCS_IN_BLKS
157
  leave_dwarf_blk2();
158
#endif
159
}
160
 
161
#if (is80x86)
162
static int ok_reg_no
163
    PROTO_N ( (x) )
164
    PROTO_T ( int x )
165
{
166
  switch (x)
167
  {
168
   case 1:
169
   case 2:
170
   case 4:
171
   case 8:
172
   case 16:
173
   case 0x20:
174
   case 0x40:
175
    return 1;
176
   default:
177
    return 0;
178
  }
179
}
180
 
181
static char *dwarf_reg_str
182
    PROTO_N ( (x) )
183
    PROTO_T ( int x )
184
{
185
  switch (x)
186
  {
187
   case 1:
188
    return("0\t#\teax");
189
   case 2:
190
    return("2\t#\tedx");
191
   case 4:
192
    return("1\t#\tecx");
193
   case 8:
194
    return("3\t#\tebx");	/* 4 is esp */
195
   case 0x10:
196
    return("7\t#\tedi");
197
   case 0x20:
198
    return("6\t#\tesi");
199
   case 0x40:
200
    return("5\t#\tebp");
201
				/* 8 eip 9 eflags 10 fpsw 11 fpcw
202
				 12 fpip 13 fpdp 14 st0....*/
203
   default:
204
    failer("Illegal reg no in dwarf_reg_str");
205
    exit(EXIT_FAILURE);
206
  }
207
}
208
 
209
#define DWARF_FP "5\t# ebp"
210
 
211
#else
212
#if (issparc)
213
 
214
static char *dwarf_reg_str
215
    PROTO_N ( ( x ) )
216
    PROTO_T ( long x )
217
{
218
    int i ;
219
    for ( i = 0 ; i < 32 ; i++ ) {
220
	if ( x & 1 ) {
221
	    static char buff [10] ;
222
	    sprintf ( buff, "%d", i ) ;
223
	}
224
	x >>= 1 ;
225
    }
226
    failer ( "Illegal register number in dwarf_reg_str" ) ;
227
    return ( "???" ) ;
228
}
229
 
230
#else
231
error need internal to dwarf register number routines
232
#endif
233
#endif
234
 
235
int out_dwarf_loc_attr
236
    PROTO_N ( (t,proc_no) )
237
    PROTO_T ( exp t X int proc_no )
238
{
239
  int rval = 1;
240
 
241
  if (name(t) != name_tag) {
242
    OUT_DWARF_ATTR(AT_const_value);
243
    out_dwarf_const4(t);
244
    return rval;
245
  }
246
 
247
#ifdef NEWDIAGS
248
  if (isdiscarded(t))
249
    return rval;	/* no location */
250
#endif
251
 
252
 
253
  OUT_DWARF_ATTR(AT_location);
254
#ifdef LOCS_IN_BLKS
255
  new_dwarf_blk2();
256
#endif
257
  {
258
    exp s = son(t);
259
 
260
    if (isglob(s))
261
    {
262
#ifndef LOCS_IN_BLKS
263
      OUT_DWARF_LOC_BLK(5);
264
#endif
265
      dwarf1(OP_ADDR);
266
      dwarf4(brog(s) -> dec_u.dec_val.dec_id);
267
    }
268
    else
269
#if (is80x86)
270
    {
271
      int p = ptno(s);
272
      switch (p)
273
      {
274
       case local_pl:
275
	{
276
	  char expr_buf[100];
277
 
278
	  sprintf(expr_buf,"%d - %sdisp%d # local var",(no(s)+no(t))/8,
279
		  local_prefix,proc_no);
280
#ifndef LOCS_IN_BLKS
281
	  OUT_DWARF_LOC_BLK(11);
282
#endif
283
	  dwarf1(OP_CONST);
284
	  dwarf4(expr_buf);
285
	}
286
	dwarf1(OP_BASEREG);
287
	dwarf4(DWARF_FP);
288
	dwarf1(OP_ADD);
289
	break;
290
       case par_pl:
291
#ifndef LOCS_IN_BLKS
292
	OUT_DWARF_LOC_BLK(11);
293
#endif
294
	dwarf1(OP_CONST);
295
	dwarf4n((no(s)+no(t))/8 + 8);
296
	dwarf1(OP_BASEREG);
297
	dwarf4(DWARF_FP);
298
	dwarf1(OP_ADD);
299
	break;
300
       case reg_pl:
301
	if (!ok_reg_no(no(s)))	/* fails for fp regs, so put out no atoms */
302
	  rval = 0;
303
	else
304
	{
305
#ifndef LOCS_IN_BLKS
306
	  OUT_DWARF_LOC_BLK(5);
307
#endif
308
	  dwarf1(OP_REG);
309
	  dwarf4(dwarf_reg_str(no(s)));
310
	}
311
	break;
312
       default:
313
	failer("illegal ptno in out_loc_attr");
314
	exit(EXIT_FAILURE);
315
      }
316
    }
317
#else
318
#if (issparc)
319
    {
320
	if ( props ( s ) & defer_bit ) {
321
	    failer ( "Deferred expression in out_loc_attr" ) ;
322
	    rval = 0 ;
323
	} else if ( props ( s ) & inreg_bits ) {
324
#ifndef LOCS_IN_BLKS
325
	    OUT_DWARF_LOC_BLK(5);
326
#endif
327
	    dwarf1 ( OP_REG ) ;
328
	    dwarf4n ( no ( s ) ) ;
329
	} else if ( props ( s ) & infreg_bits ) {
330
	    failer ( "Floating register expression in out_loc_attr" ) ;
331
	    rval = 0 ;
332
	} else {
333
	    baseoff b ;
334
	    b = boff ( s ) ;
335
#ifndef LOCS_IN_BLKS
336
	    OUT_DWARF_LOC_BLK(11);
337
#endif
338
	    dwarf1 ( OP_CONST ) ;
339
	    dwarf4n ( ( int ) b.offset ) ;
340
	    dwarf1 ( OP_BASEREG ) ;
341
	    dwarf4n ( ( int ) b.base ) ;
342
	    dwarf1 ( OP_ADD ) ;
343
	}
344
    }
345
#else
346
error need machine specific non-global location description code
347
#endif
348
#endif
349
  }
350
#ifdef LOCS_IN_BLKS
351
  leave_dwarf_blk2();
352
#endif
353
  return rval;
354
}
355