Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 63... Line 93...
63
/* machine dependent */
93
/* machine dependent */
64
#include "machine.h"
94
#include "machine.h"
65
#include "codermacs.h"
95
#include "codermacs.h"
66
 
96
 
67
#include "tags.h"
97
#include "tags.h"
68
 
98
 
69
/* machine dependent */
99
/* machine dependent */
70
#include "out.h"
100
#include "out.h"
71
 
101
 
72
#include "shapemacs.h"
102
#include "shapemacs.h"
73
 
103
 
74
/* machine dependent */
104
/* machine dependent */
75
#include "expmacs.h"
105
#include "expmacs.h"
76
 
106
 
77
#include "basicread.h"
107
#include "basicread.h"
78
 
108
 
79
#include "dwarf_types.h"
109
#include "dwarf_types.h"
80
#include "dwarf_out.h"
110
#include "dwarf_out.h"
81
#include "dwarf_queue.h"
111
#include "dwarf_queue.h"
82
#include "dwarf_type.h"
112
#include "dwarf_type.h"
83
 
113
 
84
#include "dwarf_loc.h"
114
#include "dwarf_loc.h"
85
#include "cross_config.h"
115
#include "cross_config.h"
86
 
116
 
87
#ifndef CROSS_INCLUDE
117
#ifndef CROSS_INCLUDE
88
#include <dwarf.h>
118
#include <dwarf.h>
89
#else
119
#else
90
#include CROSS_INCLUDE/dwarf.h>
120
#include CROSS_INCLUDE/dwarf.h>
91
#endif
121
#endif
92
 
122
 
93
void out_dwarf_const4
123
void
94
    PROTO_N ( (x) )
-
 
95
    PROTO_T ( exp x )
124
out_dwarf_const4(exp x)
96
{
125
{
97
  if (name(x) != val_tag && name(x) != null_tag)
126
	if (name(x) != val_tag && name(x) != null_tag) {
98
  {
-
 
99
    failer("non const exp in out_dwarf_const4");
127
		failer("non const exp in out_dwarf_const4");
100
    return;
128
		return;
101
  }
129
	}
102
  dwarf4n(no(x));
130
	dwarf4n(no(x));
103
}
131
}
-
 
132
 
104
 
133
 
105
void out_dwarf_const_by8
134
void
106
    PROTO_N ( (x) )
-
 
107
    PROTO_T ( exp x )
135
out_dwarf_const_by8(exp x)
108
{
136
{
109
  if (name(x) != val_tag)
137
	if (name(x) != val_tag) {
110
  {
-
 
111
    failer("non const exp in out_dwarf_const_by8");
138
		failer("non const exp in out_dwarf_const_by8");
112
    return;
139
		return;
113
  }
140
	}
114
  dwarf4n((no(x)/8));
141
	dwarf4n((no(x) / 8));
115
}
142
}
-
 
143
 
116
 
144
 
-
 
145
void
117
void out_dwarf_member_loc_attr
146
out_dwarf_member_loc_attr(exp e)
118
    PROTO_N ( (e) )
-
 
119
    PROTO_T ( exp e )
-
 
120
{
147
{
121
  int o;
148
	int o;
122
 
149
 
123
  OUT_DWARF_ATTR(AT_location);
150
	OUT_DWARF_ATTR(AT_location);
124
  if (name(e) != val_tag)
151
	if (name(e) != val_tag) {
125
    failer("out_mem_loc_attr");
152
		failer("out_mem_loc_attr");
-
 
153
	}
126
 
154
 
127
#ifdef LOCS_IN_BLKS
155
#ifdef LOCS_IN_BLKS
128
  new_dwarf_blk2();
156
	new_dwarf_blk2();
129
#else
157
#else
130
  OUT_DWARF_LOC_BLK(6);
158
	OUT_DWARF_LOC_BLK(6);
131
#endif
159
#endif
132
  o = no(e)/8;
160
	o = no(e) /8;
133
  dwarf1(OP_CONST);
161
	dwarf1(OP_CONST);
134
  dwarf4n(o);
162
	dwarf4n(o);
135
  dwarf1(OP_ADD);
163
	dwarf1(OP_ADD);
136
#ifdef LOCS_IN_BLKS
164
#ifdef LOCS_IN_BLKS
137
  leave_dwarf_blk2();
165
	leave_dwarf_blk2();
138
#endif
166
#endif
139
}
167
}
-
 
168
 
140
 
169
 
141
/* given the bit offset to base of anon object */
170
/* given the bit offset to base of anon object */
-
 
171
void
142
void out_dwarf_bit_member_loc_attr
172
out_dwarf_bit_member_loc_attr(int u)
143
    PROTO_N ( (u) )
-
 
144
    PROTO_T ( int u )
-
 
145
{
173
{
146
  OUT_DWARF_ATTR(AT_location);
174
	OUT_DWARF_ATTR(AT_location);
147
 
175
 
148
#ifdef LOCS_IN_BLKS
176
#ifdef LOCS_IN_BLKS
149
  new_dwarf_blk2();
177
	new_dwarf_blk2();
150
#else
178
#else
151
  OUT_DWARF_LOC_BLK(6);
179
	OUT_DWARF_LOC_BLK(6);
152
#endif
180
#endif
153
  dwarf1(OP_CONST);
181
	dwarf1(OP_CONST);
154
  dwarf4n(u/8);
182
	dwarf4n(u/8);
155
  dwarf1(OP_ADD);
183
	dwarf1(OP_ADD);
156
#ifdef LOCS_IN_BLKS
184
#ifdef LOCS_IN_BLKS
157
  leave_dwarf_blk2();
185
	leave_dwarf_blk2();
158
#endif
186
#endif
159
}
187
}
-
 
188
 
160
 
189
 
161
#if (is80x86)
190
#if (is80x86)
162
static int ok_reg_no
191
static int
-
 
192
ok_reg_no(int x)
-
 
193
{
163
    PROTO_N ( (x) )
194
	switch (x) {
-
 
195
	case 1:
-
 
196
	case 2:
-
 
197
	case 4:
-
 
198
	case 8:
-
 
199
	case 16:
-
 
200
	case 0x20:
-
 
201
	case 0x40:
-
 
202
		return 1;
-
 
203
	default:
-
 
204
		return 0;
-
 
205
	}
-
 
206
}
-
 
207
 
-
 
208
 
-
 
209
static char *
164
    PROTO_T ( int x )
210
dwarf_reg_str(int x)
165
{
211
{
166
  switch (x)
212
	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:
213
	case 1:
188
    return("0\t#\teax");
214
		return("0\t#\teax");
189
   case 2:
215
	case 2:
190
    return("2\t#\tedx");
216
		return("2\t#\tedx");
191
   case 4:
217
	case 4:
192
    return("1\t#\tecx");
218
		return("1\t#\tecx");
193
   case 8:
219
	case 8:
194
    return("3\t#\tebx");	/* 4 is esp */
220
		return("3\t#\tebx");	/* 4 is esp */
195
   case 0x10:
221
	case 0x10:
196
    return("7\t#\tedi");
222
		return("7\t#\tedi");
197
   case 0x20:
223
	case 0x20:
198
    return("6\t#\tesi");
224
		return("6\t#\tesi");
199
   case 0x40:
225
	case 0x40:
200
    return("5\t#\tebp");
226
		return("5\t#\tebp");
201
				/* 8 eip 9 eflags 10 fpsw 11 fpcw
227
		/* 8 eip 9 eflags 10 fpsw 11 fpcw
202
				 12 fpip 13 fpdp 14 st0....*/
228
		   12 fpip 13 fpdp 14 st0....*/
203
   default:
229
	default:
204
    failer("Illegal reg no in dwarf_reg_str");
230
		failer("Illegal reg no in dwarf_reg_str");
205
    exit(EXIT_FAILURE);
231
		exit(EXIT_FAILURE);
206
  }
232
	}
207
}
233
}
208
 
234
 
209
#define DWARF_FP "5\t# ebp"
235
#define DWARF_FP "5\t# ebp"
210
 
236
 
211
#else
237
#else
212
#if (issparc)
238
#if (issparc)
213
 
-
 
214
static char *dwarf_reg_str
239
static char *
215
    PROTO_N ( ( x ) )
-
 
216
    PROTO_T ( long x )
240
dwarf_reg_str(long x)
217
{
241
{
218
    int i ;
242
	int i;
219
    for ( i = 0 ; i < 32 ; i++ ) {
243
	for (i = 0; i < 32; i++) {
220
	if ( x & 1 ) {
244
		if (x & 1) {
221
	    static char buff [10] ;
245
			static char buff[10];
222
	    sprintf ( buff, "%d", i ) ;
246
			sprintf(buff, "%d", i);
-
 
247
		}
-
 
248
		x >>= 1;
223
	}
249
	}
224
	x >>= 1 ;
-
 
225
    }
-
 
226
    failer ( "Illegal register number in dwarf_reg_str" ) ;
250
	failer("Illegal register number in dwarf_reg_str");
227
    return ( "???" ) ;
251
	return("???");
228
}
252
}
229
 
253
 
230
#else
254
#else
231
error need internal to dwarf register number routines
255
error need internal to dwarf register number routines
232
#endif
256
#endif
233
#endif
257
#endif
234
 
258
 
235
int out_dwarf_loc_attr
259
int
236
    PROTO_N ( (t,proc_no) )
-
 
237
    PROTO_T ( exp t X int proc_no )
260
out_dwarf_loc_attr(exp t, int proc_no)
238
{
261
{
239
  int rval = 1;
262
	int rval = 1;
240
 
263
 
241
  if (name(t) != name_tag) {
264
	if (name(t) != name_tag) {
242
    OUT_DWARF_ATTR(AT_const_value);
265
		OUT_DWARF_ATTR(AT_const_value);
243
    out_dwarf_const4(t);
266
		out_dwarf_const4(t);
244
    return rval;
267
		return rval;
245
  }
268
	}
246
 
269
 
247
#ifdef NEWDIAGS
270
#ifdef NEWDIAGS
248
  if (isdiscarded(t))
271
	if (isdiscarded(t)) {
249
    return rval;	/* no location */
272
		/* no location */
-
 
273
		return rval;
-
 
274
	}
250
#endif
275
#endif
251
 
276
 
252
 
277
 
253
  OUT_DWARF_ATTR(AT_location);
278
	OUT_DWARF_ATTR(AT_location);
254
#ifdef LOCS_IN_BLKS
279
#ifdef LOCS_IN_BLKS
255
  new_dwarf_blk2();
280
	new_dwarf_blk2();
256
#endif
281
#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
	{
282
	{
276
	  char expr_buf[100];
283
		exp s = son(t);
277
 
284
 
278
	  sprintf(expr_buf,"%d - %sdisp%d # local var",(no(s)+no(t))/8,
-
 
279
		  local_prefix,proc_no);
285
		if (isglob(s)) {
280
#ifndef LOCS_IN_BLKS
286
#ifndef LOCS_IN_BLKS
281
	  OUT_DWARF_LOC_BLK(11);
287
			OUT_DWARF_LOC_BLK(5);
282
#endif
288
#endif
283
	  dwarf1(OP_CONST);
289
			dwarf1(OP_ADDR);
284
	  dwarf4(expr_buf);
290
			dwarf4(brog(s) -> dec_u.dec_val.dec_id);
285
	}
291
		} else {
286
	dwarf1(OP_BASEREG);
292
#if (is80x86)
287
	dwarf4(DWARF_FP);
293
			int p = ptno(s);
288
	dwarf1(OP_ADD);
294
			switch (p) {
289
	break;
295
			case local_pl: {
-
 
296
				char expr_buf[100];
-
 
297
 
-
 
298
				sprintf(expr_buf, "%d - %sdisp%d # local var", 
-
 
299
					(no(s) + no(t)) / 8,
290
       case par_pl:
300
					local_prefix,proc_no);
291
#ifndef LOCS_IN_BLKS
301
#ifndef LOCS_IN_BLKS
292
	OUT_DWARF_LOC_BLK(11);
302
				OUT_DWARF_LOC_BLK(11);
293
#endif
303
#endif
294
	dwarf1(OP_CONST);
304
				dwarf1(OP_CONST);
-
 
305
				dwarf4(expr_buf);
-
 
306
			}
-
 
307
				dwarf1(OP_BASEREG);
-
 
308
				dwarf4(DWARF_FP);
-
 
309
				dwarf1(OP_ADD);
-
 
310
				break;
-
 
311
			case par_pl:
-
 
312
#ifndef LOCS_IN_BLKS
-
 
313
				OUT_DWARF_LOC_BLK(11);
-
 
314
#endif
-
 
315
				dwarf1(OP_CONST);
295
	dwarf4n((no(s)+no(t))/8 + 8);
316
				dwarf4n((no(s) +no(t)) /8 + 8);
296
	dwarf1(OP_BASEREG);
317
				dwarf1(OP_BASEREG);
297
	dwarf4(DWARF_FP);
318
				dwarf4(DWARF_FP);
298
	dwarf1(OP_ADD);
319
				dwarf1(OP_ADD);
299
	break;
320
				break;
300
       case reg_pl:
321
			case reg_pl:
-
 
322
				if (!ok_reg_no(no(s))) {
301
	if (!ok_reg_no(no(s)))	/* fails for fp regs, so put out no atoms */
323
					/* fails for fp regs, so put out no
-
 
324
					 * atoms */
302
	  rval = 0;
325
					rval = 0;
-
 
326
				} else {
-
 
327
#ifndef LOCS_IN_BLKS
-
 
328
					OUT_DWARF_LOC_BLK(5);
-
 
329
#endif
-
 
330
					dwarf1(OP_REG);
-
 
331
					dwarf4(dwarf_reg_str(no(s)));
303
	else
332
				}
-
 
333
				break;
-
 
334
			default:
-
 
335
				failer("illegal ptno in out_loc_attr");
-
 
336
				exit(EXIT_FAILURE);
304
	{
337
			}
-
 
338
#else
-
 
339
#if (issparc)
-
 
340
			if (props(s) & defer_bit) {
-
 
341
				failer("Deferred expression in out_loc_attr");
-
 
342
				rval = 0;
-
 
343
			} else if (props(s) & inreg_bits) {
305
#ifndef LOCS_IN_BLKS
344
#ifndef LOCS_IN_BLKS
306
	  OUT_DWARF_LOC_BLK(5);
345
				OUT_DWARF_LOC_BLK(5);
307
#endif
346
#endif
308
	  dwarf1(OP_REG);
347
				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 ) ) ;
348
				dwarf4n(no(s));
329
	} else if ( props ( s ) & infreg_bits ) {
349
			} else if (props(s) & infreg_bits) {
330
	    failer ( "Floating register expression in out_loc_attr" ) ;
350
				failer("Floating register expression in out_loc_attr");
331
	    rval = 0 ;
351
				rval = 0;
332
	} else {
352
			} else {
333
	    baseoff b ;
353
				baseoff b;
334
	    b = boff ( s ) ;
354
				b = boff(s);
335
#ifndef LOCS_IN_BLKS
355
#ifndef LOCS_IN_BLKS
336
	    OUT_DWARF_LOC_BLK(11);
356
				OUT_DWARF_LOC_BLK(11);
337
#endif
357
#endif
338
	    dwarf1 ( OP_CONST ) ;
358
				dwarf1(OP_CONST);
339
	    dwarf4n ( ( int ) b.offset ) ;
359
				dwarf4n((int)b.offset);
340
	    dwarf1 ( OP_BASEREG ) ;
360
				dwarf1(OP_BASEREG);
341
	    dwarf4n ( ( int ) b.base ) ;
361
				dwarf4n((int)b.base);
342
	    dwarf1 ( OP_ADD ) ;
362
				dwarf1(OP_ADD);
343
	}
363
			}
344
    }
-
 
345
#else
364
#else
346
error need machine specific non-global location description code
365
		error need machine specific non-global location description code
347
#endif
366
#endif
-
 
367
		}
348
#endif
368
#endif
349
  }
369
	}
350
#ifdef LOCS_IN_BLKS
370
#ifdef LOCS_IN_BLKS
351
  leave_dwarf_blk2();
371
	leave_dwarf_blk2();
352
#endif
372
#endif
353
  return rval;
373
	return rval;
354
}
374
}
355
 
-