Subversion Repositories tendra.SVN

Rev

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

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