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
/*
7 7u83 2
 * Copyright (c) 2002-2006 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) 1996
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
			    VERSION INFORMATION
61
			    ===================
62
 
63
--------------------------------------------------------------------------
64
$Header: /u/g/release/CVSROOT/Source/src/installers/680x0/common/stab_types.c,v 1.1.1.1 1998/01/17 15:55:50 release Exp $
65
--------------------------------------------------------------------------
66
$Log: stab_types.c,v $
67
 * Revision 1.1.1.1  1998/01/17  15:55:50  release
68
 * First version to be checked into rolling release.
69
 *
70
Revision 1.1.1.1  1997/10/13 12:43:01  ma
71
First version.
72
 
73
Revision 1.1.1.1  1997/03/14 07:50:22  ma
74
Imported from DRA
75
 
76
 * Revision 1.1.1.1  1996/09/20  10:57:01  john
77
 *
78
 * Revision 1.2  1996/07/05  14:31:36  john
79
 * Removed copyright message
80
 *
81
 * Revision 1.1  95/03/08  16:46:11  ra
82
 * Added missing files.
83
 *
84
 * Revision 1.3  94/02/21  16:08:10  16:08:10  ra (Robert Andrews)
85
 * Clear up a couple of long-int confusions.
86
 *
87
 * Revision 1.2  93/04/19  13:38:52  13:38:52  ra (Robert Andrews)
88
 * struct_fields and union_fields have been renamed diag_field.
89
 *
90
 * Revision 1.1  93/02/22  17:17:11  17:17:11  ra (Robert Andrews)
91
 * Initial revision
92
 *
93
--------------------------------------------------------------------------
94
*/
95
 
96
 
97
#include "config.h"
98
#include "common_types.h"
99
#include "expmacs.h"
100
#include "externs.h"
101
#include "instrs.h"
102
#include "mach.h"
103
#include "mach_ins.h"
104
#include "mach_op.h"
105
#include "output.h"
106
#include "shapemacs.h"
107
#include "utility.h"
108
#include "xdb_output.h"
109
#include "stab_types.h"
110
 
111
 
112
/*
113
    CREATE A STABS INSTRUCTION
114
*/
115
 
7 7u83 116
void
117
make_stabs(char *s, int a, long b, mach_op *op)
2 7u83 118
{
7 7u83 119
	mach_op *p = make_extern_data(s, 0);
120
	p->of = make_int_data((long)a);
121
	p->of->of = make_int_data(0);
122
	p->of->of->of = make_int_data(b);
123
	p->of->of->of->of = (op ? op : make_int_data(0));
124
	make_instr(m_stabs, p, null, 0);
125
	return;
2 7u83 126
}
127
 
128
 
129
/*
130
    CREATE A STABN INSTRUCTION
131
*/
132
 
7 7u83 133
void
134
make_stabn(int a, long lab)
2 7u83 135
{
7 7u83 136
	mach_op *p = make_int_data((long)a);
137
	p->of = make_int_data(0);
138
	p->of->of = make_int_data(0);
139
	p->of->of->of = make_lab_data(lab, 0);
140
	make_instr(m_stabn, p, null, 0);
141
	return;
2 7u83 142
}
143
 
144
 
145
/*
146
    TYPE USED FOR BUILDING STAB TYPES
147
*/
148
 
149
#define TSIZE 100
150
 
151
typedef struct page_tag {
7 7u83 152
	int index;
153
	char text[TSIZE];
154
	struct page_tag *next;
155
} page;
2 7u83 156
 
157
 
158
/*
159
    LIST OF FREE PAGES
160
*/
161
 
7 7u83 162
static page *free_pages = null;
2 7u83 163
 
164
 
165
/*
166
    CREATE A NEW PAGE
167
*/
168
 
7 7u83 169
static page *
170
new_page(void)
2 7u83 171
{
7 7u83 172
	page *p = free_pages;
173
	if (p == null) {
174
		p = alloc_nof(page, 1);
175
	} else {
176
		free_pages = p->next;
177
	}
178
	p->index = 0;
179
	p->next = null;
180
	return (p);
2 7u83 181
}
182
 
183
 
184
/*
185
    ADD A STRING TO A PAGE
186
*/
187
 
7 7u83 188
static page *
189
sprint_string(page *p, char *s)
2 7u83 190
{
7 7u83 191
	int i = p->index;
192
	for (; *s; s++) {
193
		if (i >= TSIZE) {
194
			p->index = TSIZE;
195
			p->next = new_page();
196
			p = p->next;
197
			i = 0;
198
		}
199
		p->text[i] = *s;
200
		i++;
2 7u83 201
	}
7 7u83 202
	p->index = i;
203
	return (p);
2 7u83 204
}
205
 
206
 
207
/*
208
    ADD A NUMBER TO A PAGE
209
*/
210
 
7 7u83 211
static page *
212
sprint_number(page *p, long n)
2 7u83 213
{
7 7u83 214
	char buff[100];
215
	(void)sprintf(buff, "%ld", n);
216
	return (sprint_string(p, buff));
2 7u83 217
}
218
 
219
 
220
/*
221
    CREATE A NEW STAB TYPE
222
*/
223
 
7 7u83 224
static char *
225
new_stab_type(diag_type dt)
2 7u83 226
{
7 7u83 227
	static long next_stab_type = 16;
228
	char *res = alloc_nof(char, 8);
229
	sprintf(res, "%ld", next_stab_type++);
230
	if (dt) {
231
		dt->been_outed = (OUTPUT_REC)res;
232
	}
233
	return (res);
2 7u83 234
}
235
 
236
 
237
/*
238
    SIZE OF LAST TYPE ANALYSED
239
*/
240
 
7 7u83 241
static long last_type_sz = 0;
2 7u83 242
 
243
 
244
/*
245
    INDEX TO SIMPLE STAB TYPES
246
*/
247
 
248
#define STAB_SCHAR	0
249
#define STAB_UCHAR	1
250
#define STAB_SWORD	2
251
#define STAB_UWORD	3
252
#define STAB_SLONG	4
253
#define STAB_ULONG	5
254
#define STAB_FLOAT	6
255
#define STAB_DOUBLE	7
256
#define STAB_LDOUBLE	8
257
#define STAB_VOID	9
258
#define STAB_PTR	10
259
#define STAB_COMPLEX	-1
260
 
261
 
262
/*
263
    TABLE OF SIMPLE STAB TYPES
264
*/
265
 
7 7u83 266
static char *stab_tab[] = {
267
	"2", "11", "6", "8", "1", "4", "12", "13", "14", "15",
268
	null, null, null, null, null, null, null, null, null, null
269
};
2 7u83 270
 
271
 
272
/*
273
    TEST IF A TYPE IS SIMPLE
274
*/
275
 
7 7u83 276
static int
277
test_type(diag_type dt)
2 7u83 278
{
7 7u83 279
	switch (dt->key) {
280
	case DIAG_TYPE_FLOAT: {
281
		shape sha = f_floating(dt->data.f_var);
282
		last_type_sz = shape_size(sha);
283
		if (name(sha) == shrealhd) {
284
			return (STAB_FLOAT);
285
		}
286
		if (name(sha) == realhd) {
287
			return (STAB_DOUBLE);
288
		}
289
		return (STAB_LDOUBLE);
2 7u83 290
	}
7 7u83 291
	case DIAG_TYPE_VARIETY: {
292
		shape sha = f_integer(dt->data.var);
293
		last_type_sz = shape_size(sha);
294
		switch (name(sha)) {
295
		case scharhd:
296
			return (STAB_SCHAR);
297
		case swordhd:
298
			return (STAB_SWORD);
299
		case slonghd:
300
			return (STAB_SLONG);
301
		case ucharhd:
302
			return (STAB_UCHAR);
303
		case uwordhd:
304
			return (STAB_UWORD);
305
		case ulonghd:
306
			return (STAB_ULONG);
307
		}
308
		break;
2 7u83 309
	}
7 7u83 310
	case DIAG_TYPE_NULL:
311
		last_type_sz = 0;
312
		return (STAB_VOID);
313
	default:
314
		break;
2 7u83 315
	}
7 7u83 316
	return (STAB_COMPLEX);
2 7u83 317
}
318
 
319
 
320
/*
321
    BUILD UP A STAB TYPE IN A BUFFER
322
*/
323
 
7 7u83 324
static page *
325
build_stab_type(diag_type dt, page *ptr)
2 7u83 326
{
7 7u83 327
	switch (dt->key) {
328
	case DIAG_TYPE_FLOAT:
329
	case DIAG_TYPE_NULL:
330
	case DIAG_TYPE_VARIETY: {
331
		/* Simple types */
332
		int t = test_type(dt);
333
		ptr = sprint_string(ptr, stab_tab[t]);
334
		break;
2 7u83 335
	}
7 7u83 336
	case DIAG_TYPE_ARRAY: {
337
		diag_type dtl = dt->data.array.element_type;
338
		long lo = no(dt->data.array.lower_b);
339
		long hi = no(dt->data.array.upper_b);
340
		char *stl = analyse_stab_type(dtl, null, null);
341
		ptr = sprint_string(ptr, new_stab_type(dt));
342
		ptr = sprint_string(ptr, "=ar1;");
343
		ptr = sprint_number(ptr, lo);
344
		ptr = sprint_string(ptr, ";");
345
		ptr = sprint_number(ptr, hi);
346
		ptr = sprint_string(ptr, ";");
347
		ptr = sprint_string(ptr, stl);
348
		last_type_sz *= (hi - lo + 1);
349
		break;
2 7u83 350
	}
7 7u83 351
	case DIAG_TYPE_BITFIELD: {
352
		long sz = dt->data.bitfield.no_of_bits.nat_val.small_nat;
353
		ptr = sprint_string(ptr, "1");
354
		last_type_sz = sz;
355
		break;
2 7u83 356
	}
7 7u83 357
	case DIAG_TYPE_ENUM:
358
		/* Not yet supported */
359
		ptr = sprint_string(ptr, "1");
360
		last_type_sz = 32;
361
		break;
362
	case DIAG_TYPE_LOC: {
363
		diag_type dtl = dt->data.loc.object;
364
		ptr = build_stab_type(dtl, ptr);
365
		break;
2 7u83 366
	}
7 7u83 367
	case DIAG_TYPE_PROC: {
368
		diag_type dtl = dt->data.proc.result_type;
369
		char *stl = analyse_stab_type(dtl, null, null);
370
		ptr = sprint_string(ptr, new_stab_type(dt));
371
		ptr = sprint_string(ptr, "=*");
372
		ptr = sprint_string(ptr, new_stab_type(null));
373
		ptr = sprint_string(ptr, "=f");
374
		ptr = sprint_string(ptr, stl);
375
		last_type_sz = 32;
376
		break;
2 7u83 377
	}
7 7u83 378
	case DIAG_TYPE_PTR: {
379
		diag_type dtl = dt->data.ptr.object;
380
		int t = test_type(dtl);
381
		if (t != STAB_COMPLEX) {
382
			char *st = stab_tab[STAB_PTR + t];
383
			if (st) {
384
				ptr = sprint_string(ptr, st);
385
			} else {
386
				st = new_stab_type(null);
387
				stab_tab[STAB_PTR + t] = st;
388
				ptr = sprint_string(ptr, st);
389
				ptr = sprint_string(ptr, "=*");
390
				ptr = sprint_string(ptr, stab_tab[t]);
391
			}
2 7u83 392
		} else {
7 7u83 393
			char *stl = analyse_stab_type(dtl, null, null);
394
			ptr = sprint_string(ptr, new_stab_type(dt));
395
			ptr = sprint_string(ptr, "=*");
396
			ptr = sprint_string(ptr, stl);
2 7u83 397
		}
7 7u83 398
		last_type_sz = 32;
399
		break;
2 7u83 400
	}
7 7u83 401
	case DIAG_TYPE_STRUCT: {
402
		char *nm = dt->data.t_struct.nme.ints.chars;
403
		if (*nm) {
404
			char *res;
405
			dt->data.t_struct.nme.ints.chars = "";
406
			res = analyse_stab_type(dt, nm, "T");
407
			dt->data.t_struct.nme.ints.chars = nm;
408
			make_stabs(res, 128, L0, null);
409
			res = (char *)dt->been_outed;
410
			ptr = sprint_string(ptr, res);
411
		} else {
412
			shape sha = dt->data.t_struct.tdf_shape;
413
			long sz = shape_size(sha);
2 7u83 414
#if 0
7 7u83 415
			struct_fields *fld = dt->data.t_struct.fields->array;
2 7u83 416
#else
7 7u83 417
			diag_field *fld = dt->data.t_struct.fields->array;
2 7u83 418
#endif
7 7u83 419
			long i, n = (long)dt->data.t_struct.fields->lastused;
2 7u83 420
 
7 7u83 421
			ptr = sprint_string(ptr, new_stab_type(dt));
422
			ptr = sprint_string(ptr, "=s");
423
			ptr = sprint_number(ptr, sz / 8);
2 7u83 424
 
7 7u83 425
			/* Deal with structure fields */
426
			for (i = n - 1; i >= 0; i--) {
427
				char *fnm = fld[i] ->field_name.ints.chars;
428
				long off = no(fld[i] ->where);
429
				diag_type dtl = fld[i] ->field_type;
430
				char *q = analyse_stab_type(dtl, null, null);
431
				ptr = sprint_string(ptr, fnm);
432
				ptr = sprint_string(ptr, ":");
433
				ptr = sprint_string(ptr, q);
434
				ptr = sprint_string(ptr, ",");
435
				ptr = sprint_number(ptr, off);
436
				ptr = sprint_string(ptr, ",");
437
				ptr = sprint_number(ptr, last_type_sz);
438
				ptr = sprint_string(ptr, ";");
439
			}
440
			ptr = sprint_string(ptr, ";");
441
			last_type_sz = sz;
2 7u83 442
		}
7 7u83 443
		break;
2 7u83 444
	}
7 7u83 445
	case DIAG_TYPE_UNION: {
446
		char *nm = dt->data.t_union.nme.ints.chars;
447
		if (*nm) {
448
			char *res;
449
			dt->data.t_struct.nme.ints.chars = "";
450
			res = analyse_stab_type(dt, nm, "T");
451
			dt->data.t_struct.nme.ints.chars = nm;
452
			make_stabs(res, 128, L0, null);
453
			res = (char *)dt->been_outed;
454
			ptr = sprint_string(ptr, res);
455
		} else {
456
			shape sha = dt->data.t_union.tdf_shape;
457
			long sz = shape_size(sha);
2 7u83 458
#if 0
7 7u83 459
			union_fields *fld = dt->data.t_union.fields->array;
2 7u83 460
#else
7 7u83 461
			diag_field *fld = dt->data.t_union.fields->array;
2 7u83 462
#endif
7 7u83 463
			long i, n = (long)dt->data.t_union.fields->lastused;
2 7u83 464
 
7 7u83 465
			ptr = sprint_string(ptr, new_stab_type(dt));
466
			ptr = sprint_string(ptr, "=u");
467
			ptr = sprint_number(ptr, sz / 8);
2 7u83 468
 
7 7u83 469
			/* Deal with union fields */
470
			for (i = n - 1; i >= 0; i--) {
471
				char *fnm = fld[i] ->field_name.ints.chars;
472
				diag_type dtl = fld[i] ->field_type;
473
				char *q = analyse_stab_type(dtl, null, null);
474
				ptr = sprint_string(ptr, fnm);
475
				ptr = sprint_string(ptr, ":");
476
				ptr = sprint_string(ptr, q);
477
				ptr = sprint_string(ptr, ",0,");
478
				ptr = sprint_number(ptr, last_type_sz);
479
				ptr = sprint_string(ptr, ";");
480
			}
481
			ptr = sprint_string(ptr, ";");
482
			last_type_sz = sz;
2 7u83 483
		}
7 7u83 484
		break;
2 7u83 485
	}
7 7u83 486
	default:
487
		ptr = sprint_string(ptr, "15");
488
		last_type_sz = 0;
489
		break;
2 7u83 490
	}
7 7u83 491
	return (ptr);
2 7u83 492
}
493
 
494
 
495
/*
496
    FIND A STAB TYPE
497
*/
498
 
7 7u83 499
char *
500
analyse_stab_type(diag_type dt, char *nm, char *cl)
2 7u83 501
{
7 7u83 502
	int n = 0;
503
	page *ptr, *p;
504
	char *res = (char *)dt->been_outed;
505
	if (res && nm == null && cl == null) {
506
		return (res);
507
	}
508
	p = ptr = new_page();
509
	if (nm) {
510
		p = sprint_string(p, "\"");
511
		p = sprint_string(p, nm);
512
	}
513
	if (cl) {
514
		p = sprint_string(p, ":");
515
		p = sprint_string(p, cl);
516
	}
517
	if (res) {
518
		p = sprint_string(p, res);
519
	} else {
520
		p = build_stab_type(dt, p);
521
	}
522
	if (nm) {
523
		p = sprint_string(p, "\"");
524
	}
2 7u83 525
 
7 7u83 526
	/* Copy accumulated string */
527
	for (p = ptr; p; p = p->next) {
528
		n += p->index;
529
	}
530
	res = alloc_nof(char, n + 1);
531
	n = 0;
532
	for (p = ptr; p; p = p->next) {
533
		strncpy(res + n, p->text, p->index);
534
		n += p->index;
535
	}
536
	res[n] = 0;
2 7u83 537
 
7 7u83 538
	/* Free pages */
539
	p =  ptr;
540
	while (p->next) {
541
		p = p->next;
542
	}
543
	p->next = free_pages;
544
	free_pages = ptr;
545
	return (res);
2 7u83 546
}
547
 
548
 
549
/*
550
    INITIALIZE BASIC STAB TYPES
551
*/
552
 
7 7u83 553
void
554
init_stab_types(void)
2 7u83 555
{
7 7u83 556
	static char *stab_types[] = {
557
		"\"int:t1=r1;-2147483648;2147483647;\"",
558
		"\"char:t2=r2;0;127;\"",
559
		"\"long int:t3=r1;-2147483648;2147483647;\"",
560
		"\"unsigned int:t4=r1;0;-1;\"",
561
		"\"long unsigned int:t5=r1;0;-1;\"",
562
		"\"short int:t6=r1;-32768;32767;\"",
563
		"\"long long int:t7=r1;0;-1;\"",
564
		"\"short unsigned int:t8=r1;0;65535;\"",
565
		"\"long long unsigned int:t9=r1;0;-1;\"",
566
		"\"signed char:t10=r1;-128;127;\"",
567
		"\"unsigned char:t11=r1;0;255;\"",
568
		"\"float:t12=r1;4;0;\"",
569
		"\"double:t13=r1;8;0;\"",
570
		"\"long double:t14=r1;8;0;\"",
571
		"\"void:t15=15\""
572
	};
573
	int i;
574
	for (i = 0; i < 15; i++) {
575
		make_stabs(stab_types[i], 128, L0, null);
576
	}
577
	return;
2 7u83 578
}