Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
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 122... Line 152...
122
 
152
 
123
 
153
 
124
extern int locals_offset; /* declared in cproc.c */
154
extern int locals_offset; /* declared in cproc.c */
125
 
155
 
126
 
156
 
127
static long dwarfreg [8] = {0, 2, 1, 3, 7, 6, 5, 4};
157
static long dwarfreg[8] = {0, 2, 1, 3, 7, 6, 5, 4};
128
#define dw_sp 4
158
#define dw_sp 4
129
#define dw_fp 5
159
#define dw_fp 5
130
#define retaddr 8
160
#define retaddr 8
131
 
161
 
132
static long cie_pointer;
162
static long cie_pointer;
Line 151... Line 181...
151
 
181
 
152
 
182
 
153
 
183
 
154
 
184
 
155
static void outsep
185
static void outsep
156
    PROTO_Z ()
186
(void)
157
{
187
{
158
  outs (", ");
188
  outs(", ");
159
}
189
}
160
 
190
 
161
 
191
 
162
int dw_is_const
192
int dw_is_const
163
    PROTO_N ( (e) )
-
 
164
    PROTO_T ( exp e )
193
(exp e)
165
{
194
{
166
  switch (name(e)) {
195
  switch (name(e)) {
167
    case val_tag:
196
    case val_tag:
168
    case null_tag:
197
    case null_tag:
169
    case real_tag:
198
    case real_tag:
170
      return 1;
199
      return 1;
171
    case name_tag:
200
    case name_tag:
172
      return (!isdiscarded(e) && isvar(son(e)));
201
      return(!isdiscarded(e) && isvar(son(e)));
173
#if 0
202
#if 0
174
    case cont_tag:
203
    case cont_tag:
175
      return (name(son(e)) == name_tag && !isdiscarded(son(e)) &&
204
      return(name(son(e)) == name_tag && !isdiscarded(son(e)) &&
176
		!isvar(son(son(e))) && !isparam(son(son(e))) );
205
		!isvar(son(son(e))) && !isparam(son(son(e))));
177
#endif
206
#endif
178
    case reff_tag:
207
    case reff_tag:
179
      return 1;
208
      return 1;
180
    default:
209
    default:
181
      return 0;
210
      return 0;
182
  }
211
  }
183
}
212
}
184
 
213
 
185
exp dw_has_location
214
exp dw_has_location
186
    PROTO_N ( (e) )
-
 
187
    PROTO_T ( exp e )
215
(exp e)
188
{
216
{
189
  switch (name(e)) {
217
  switch (name(e)) {
190
    case name_tag: {
218
    case name_tag: {
191
      if (isdiscarded(e) || isvar(son(e)))
219
      if (isdiscarded(e) || isvar(son(e)))
192
	return nilexp;
220
	return nilexp;
193
      return (son(e));
221
      return(son(e));
194
    }
222
    }
195
    case cont_tag: {
223
    case cont_tag: {
196
      do {
224
      do {
197
	e = son(e);
225
	e = son(e);
198
	if (name(e) == name_tag && isdiscarded(e))
226
	if (name(e) == name_tag && isdiscarded(e))
199
	  return nilexp;
227
	  return nilexp;
200
      }
228
      }
201
      while (name(e) != ident_tag);
229
      while (name(e)!= ident_tag);
202
      return e;
230
      return e;
203
    }
231
    }
204
    default:
232
    default:
205
      return nilexp;
233
      return nilexp;
206
  }
234
  }
207
}
235
}
208
 
236
 
209
 
237
 
210
static loc_s name_to_loc PROTO_S ((exp e));
238
static loc_s name_to_loc(exp e);
211
 
239
 
212
static loc_s find_param
240
static loc_s find_param
213
    PROTO_N ( (e) )
-
 
214
    PROTO_T ( exp e )
241
(exp e)
215
{
242
{
216
  switch (name(e)) {
243
  switch (name(e)) {
217
    case name_tag:
244
    case name_tag:
218
      if (isvar(son(e)))
245
      if (isvar(son(e)))
219
	extra_deref--;
246
	extra_deref--;
220
      if (isparam(son(e)))
247
      if (isparam(son(e)))
221
        return name_to_loc (e);
248
        return name_to_loc(e);
222
      return find_param (son(son(e)));
249
      return find_param(son(son(e)));
223
    case cont_tag:
250
    case cont_tag:
224
      extra_deref++;	/* drop through */
251
      extra_deref++;	/* drop through */
225
    case chvar_tag:
252
    case chvar_tag:
226
    case chfl_tag:
253
    case chfl_tag:
227
      return find_param (son(e));
254
      return find_param(son(e));
228
    default:
255
    default:
229
      break;
256
      break;
230
  }
257
  }
231
  failer ("parameter inconsistency");
258
  failer("parameter inconsistency");
232
  return find_param (e);
259
  return find_param(e);
233
}
260
}
234
 
261
 
235
static loc_s name_to_loc
262
static loc_s name_to_loc
236
    PROTO_N ( (e) )
-
 
237
    PROTO_T ( exp e )
263
(exp e)
238
{
264
{
239
  loc_s l;
265
  loc_s l;
240
  exp id = son(e);
266
  exp id = son(e);
241
  long n_off = no(e)/8;
267
  long n_off = no(e) /8;
242
  if (locate_param && !isparam(id)) {
268
  if (locate_param && !isparam(id)) {
243
    return find_param (son(id));
269
    return find_param(son(id));
244
#if 0
270
#if 0
245
    if (name(son(id)) == name_tag && isloadparam(son(id)) && isparam(son(son(id))))
271
    if (name(son(id)) == name_tag && isloadparam(son(id)) && isparam(son(son(id))))
246
      return name_to_loc (son(id));
272
      return name_to_loc(son(id));
247
    if (name(son(id)) == cont_tag && name(son(son(id))) == name_tag &&
273
    if (name(son(id)) == cont_tag && name(son(son(id))) == name_tag &&
248
		isparam(son(son(son(id)))))
274
		isparam(son(son(son(id)))))
249
      return name_to_loc (son(son(id)));
275
      return name_to_loc(son(son(id)));
250
    failer ("parameter inconsistency");
276
    failer("parameter inconsistency");
251
#endif
277
#endif
252
  }
278
  }
253
  if (isglob (id)) {
279
  if (isglob(id)) {
254
    l.key = L_GLOB;
280
    l.key = L_GLOB;
255
    l.s = brog(id) -> dec_u.dec_val.dec_id;
281
    l.s = brog(id) -> dec_u.dec_val.dec_id;
256
    l.off = n_off;
282
    l.off = n_off;
257
  }
283
  }
258
  else {
284
  else {
259
    switch (ptno (id)) {
285
    switch (ptno(id)) {
260
      case local_pl: {
286
      case local_pl: {
261
	l.key = L_REGOFF;
287
	l.key = L_REGOFF;
262
	l.reg = -1;
288
	l.reg = -1;
263
	l.off = (no(id)/8) + n_off;
289
	l.off = (no(id) /8) + n_off;
264
	if (name(id))
290
	if (name(id))
265
	  l.off -= locals_offset;
291
	  l.off -= locals_offset;
266
	else {			/* env_off modification */
292
	else {			/* env_off modification */
267
	  if (locate_param) {
293
	  if (locate_param) {
268
	    l.reg = dw_sp;
294
	    l.reg = dw_sp;
269
	  }
295
	  }
270
	}
296
	}
271
	if (has_fp && l.reg < 0)
297
	if (has_fp && l.reg < 0)
272
	  l.off += 4;
298
	  l.off += 4;
273
	break;
299
	break;
274
      };
300
      };
275
      case callstack_pl: {
301
      case callstack_pl: {
276
	failer ("callstack arg - location list needed");
302
	failer("callstack arg - location list needed");
277
	break;
303
	break;
278
      };
304
      };
279
      case par_pl: {
305
      case par_pl: {
280
	l.key = L_REGOFF;
306
	l.key = L_REGOFF;
281
	l.reg = (locate_param ? dw_sp : -1);
307
	l.reg = (locate_param ? dw_sp : -1);
282
	l.off = (no(id)/8) +4 + n_off;
308
	l.off = (no(id) /8) +4 + n_off;
283
	break;
309
	break;
284
      };
310
      };
285
      case reg_pl: {
311
      case reg_pl: {
286
	int z = get_reg_no (no(id));
312
	int z = get_reg_no(no(id));
287
	l.key = L_INREG;
313
	l.key = L_INREG;
288
	l.reg = (z >= first_fl_reg ? 100 + z - first_fl_reg : 
314
	l.reg = (z >= first_fl_reg ? 100 + z - first_fl_reg :
289
					(int)dwarfreg[z]);
315
					(int)dwarfreg[z]);
290
	break;
316
	break;
291
      };
317
      };
292
      default:
318
      default:
293
	failer ("no location for id");
319
	failer("no location for id");
294
	SET (l);
320
	SET(l);
295
    }
321
    }
296
    if (has_fp && l.reg < 0)
322
    if (has_fp && l.reg < 0)
297
      l.off += 4;
323
      l.off += 4;
298
  }
324
  }
299
  return l;
325
  return l;
300
}
326
}
301
 
327
 
302
static loc_s find_loc
328
static loc_s find_loc
303
    PROTO_N ( (e) )
-
 
304
    PROTO_T ( exp e )
329
(exp e)
305
{
330
{
306
  loc_s l;
331
  loc_s l;
307
  switch ( name ( e ) ) {
332
  switch (name(e)) {
308
 
333
 
309
    case name_tag : {
334
    case name_tag: {
310
      if (isdiscarded(e) || (isglob(son(e)) && no(son(e)) == 0 &&
335
      if (isdiscarded(e) || (isglob(son(e)) && no(son(e)) == 0 &&
311
				!(brog(son(e))->dec_u.dec_val.extnamed) )) {
336
				!(brog(son(e)) ->dec_u.dec_val.extnamed))) {
312
	l.key = L_INREG;
337
	l.key = L_INREG;
313
	l.reg = 0;
338
	l.reg = 0;
314
	no_location = 1;
339
	no_location = 1;
315
	return l;
340
	return l;
316
      }
341
      }
317
      if ( isvar(son(e)) )
342
      if (isvar(son(e)))
318
	extra_deref--;
343
	extra_deref--;
319
      return name_to_loc (e);
344
      return name_to_loc(e);
320
    }
345
    }
321
 
346
 
322
    case cont_tag :
347
    case cont_tag:
323
    case contvol_tag : {
348
    case contvol_tag: {
324
      if (name(son(e)) == name_tag) {
349
      if (name(son(e)) == name_tag) {
325
	if (isdiscarded(son(e)) ||
350
	if (isdiscarded(son(e)) ||
326
			(isglob(son(son(e))) && no(son(son(e))) == 0 &&
351
			(isglob(son(son(e))) && no(son(son(e))) == 0 &&
327
			 !(brog(son(son(e)))->dec_u.dec_val.extnamed) )) {
352
			 !(brog(son(son(e))) ->dec_u.dec_val.extnamed))) {
328
	  l.key = L_INREG;
353
	  l.key = L_INREG;
329
	  l.reg = 0;
354
	  l.reg = 0;
330
	  no_location = 1;
355
	  no_location = 1;
331
	  return l;
356
	  return l;
332
	}
357
	}
333
	if ( isvar(son(son(e))) )
358
	if (isvar(son(son(e))))
334
	  return name_to_loc (son(e));
359
	  return name_to_loc(son(e));
335
      }
360
      }
336
      l = find_loc (son(e));
361
      l = find_loc(son(e));
337
      if (l.key == L_INREG) {
362
      if (l.key == L_INREG) {
338
	l.key = L_REGOFF;
363
	l.key = L_REGOFF;
339
	l.off = 0;
364
	l.off = 0;
340
      }
365
      }
341
      else
366
      else
342
	l.key = L_INDIRECT;
367
	l.key = L_INDIRECT;
343
      break;
368
      break;
344
    }
369
    }
345
 
370
 
346
    case reff_tag : {
371
    case reff_tag: {
347
      l = find_loc (son(e));
372
      l = find_loc(son(e));
348
      if (l.key == L_GLOB || l.key == L_REGOFF)
373
      if (l.key == L_GLOB || l.key == L_REGOFF)
349
	l.off += (no(e)/8);
374
	l.off += (no(e) /8);
350
      else
375
      else
351
      if (l.key == L_INREG) {
376
      if (l.key == L_INREG) {
352
	l.key = L_REGOFF;
377
	l.key = L_REGOFF;
353
	l.off = (no(e)/8);
378
	l.off = (no(e) /8);
354
	extra_deref--;
379
	extra_deref--;
355
      }
380
      }
356
      else
381
      else
357
	l.key = L_INDIRECT;
382
	l.key = L_INDIRECT;
358
      break;
383
      break;
359
    }
384
    }
360
 
385
 
361
    case chvar_tag : {
386
    case chvar_tag: {
362
      l = find_loc (son(e));
387
      l = find_loc(son(e));
363
      break;
388
      break;
364
    }
389
    }
365
 
390
 
366
    default:
391
    default:
367
      failer ("unimplemented location condition");
392
      failer("unimplemented location condition");
368
      SET (l);
393
      SET(l);
369
  }
394
  }
370
  return l;
395
  return l;
371
}
396
}
372
 
397
 
373
static int inreg_length
398
static int inreg_length
374
    PROTO_N ( (r, more) )
-
 
375
    PROTO_T ( int r X int more )
399
(int r, int more)
376
{
400
{
377
  int ans = 1 + more;
401
  int ans = 1 + more;
378
  if (r >= 32)
402
  if (r >= 32)
379
    ans += uleb128_length((unsigned long)r);
403
    ans += uleb128_length((unsigned long)r);
380
  return ans;
404
  return ans;
381
}
405
}
382
 
406
 
383
static void out_inreg
407
static void out_inreg
384
    PROTO_N ( (r, more) )
-
 
385
    PROTO_T ( int r X int more )
408
(int r, int more)
386
{
409
{
387
  if (!more) {
410
  if (!more) {
388
    if (r < 32)
411
    if (r < 32)
389
      outn ((long)(DW_OP_reg0 + r));
412
      outn((long)(DW_OP_reg0 + r));
-
 
413
    else {
-
 
414
      outn((long)DW_OP_regx); outsep(); uleb128((unsigned long)r);
-
 
415
    }
-
 
416
  }
-
 
417
  else {
-
 
418
    if (r < 32)
-
 
419
      outn((long)(DW_OP_breg0 + r));
390
    else {
420
    else {
391
      outn ((long)DW_OP_regx); outsep(); uleb128((unsigned long)r);
421
      outn((long)DW_OP_bregx); outsep(); uleb128((unsigned long)r);
392
    }
422
    }
-
 
423
    outsep(); outn((long)0);
393
  }
424
  }
394
  else {
-
 
395
    if (r < 32)
-
 
396
      outn ((long)(DW_OP_breg0 + r));
-
 
397
    else {
-
 
398
      outn ((long)DW_OP_bregx); outsep(); uleb128((unsigned long)r);
-
 
399
    }
-
 
400
    outsep(); outn ((long)0);
-
 
401
  }
-
 
402
  return;
425
  return;
403
}
426
}
404
 
427
 
405
static int regoff_length
428
static int regoff_length
-
 
429
(loc_s l)
-
 
430
{
-
 
431
  return(1 + sleb128_length(l.off));
-
 
432
}
-
 
433
 
-
 
434
static void out_regoff
-
 
435
(loc_s l)
-
 
436
{
-
 
437
  outn((long)(l.reg < 0 ? DW_OP_fbreg : DW_OP_breg0 + l.reg)); outsep();
406
    PROTO_N ( (l) )
438
  sleb128(l.off);
-
 
439
  return;
-
 
440
}
-
 
441
 
-
 
442
static int glob_length
407
    PROTO_T ( loc_s l )
443
(loc_s l)
408
{
444
{
409
  return (1 + sleb128_length (l.off));
-
 
410
}
-
 
411
 
-
 
412
static void out_regoff
-
 
413
    PROTO_N ( (l) )
-
 
414
    PROTO_T ( loc_s l )
-
 
415
{
-
 
416
  outn ((long)(l.reg < 0 ? DW_OP_fbreg : DW_OP_breg0 + l.reg)); outsep();
-
 
417
  sleb128 (l.off);
-
 
418
  return;
-
 
419
}
-
 
420
 
-
 
421
static int glob_length
-
 
422
    PROTO_N ( (l) )
-
 
423
    PROTO_T ( loc_s l )
-
 
424
{
-
 
425
  UNUSED (l);
445
  UNUSED(l);
426
  return 5;
446
  return 5;
427
}
447
}
428
 
448
 
429
static void out_glob
449
static void out_glob
430
    PROTO_N ( (l) )
-
 
431
    PROTO_T ( loc_s l )
450
(loc_s l)
432
{
451
{
433
  outn ((long)DW_OP_addr); d_outnl ();
452
  outn((long)DW_OP_addr); d_outnl();
434
  out32 (); outs (l.s);
453
  out32(); outs(l.s);
435
  if (l.off) {
454
  if (l.off) {
436
    outs (" + ");
455
    outs(" + ");
437
    outn ((long)l.off);
456
    outn((long)l.off);
438
  }
457
  }
439
  return;
458
  return;
440
}
459
}
441
 
460
 
442
static int indirect_length
461
static int indirect_length
443
    PROTO_N ( (e) )
-
 
444
    PROTO_T ( exp e )
462
(exp e)
445
{
463
{
446
  int length;
464
  int length;
447
  loc_s l;
465
  loc_s l;
448
  switch (name(e)) {
466
  switch (name(e)) {
449
    case cont_tag: {
467
    case cont_tag: {
450
      length = 1;
468
      length = 1;
451
      break;
469
      break;
452
    }
470
    }
453
    case reff_tag: {
471
    case reff_tag: {
454
      if (no(e) >= 0)
472
      if (no(e) >= 0)
455
	length = 1 + uleb128_length ((unsigned long)(no(e)/8));
473
	length = 1 + uleb128_length((unsigned long)(no(e) /8));
456
      else
474
      else
457
	length = 2 + uleb128_length ((unsigned long)(-no(e)/8));
475
	length = 2 + uleb128_length((unsigned long)(-no(e) /8));
458
      break;
476
      break;
459
    }
477
    }
460
    default: {
478
    default: {
461
      failer ("unimplemented dwarf locate");
479
      failer("unimplemented dwarf locate");
462
      return 0;
480
      return 0;
463
    }
481
    }
464
  }
482
  }
465
  l = find_loc (son(e));
483
  l = find_loc(son(e));
466
  switch (l.key) {
484
  switch (l.key) {
467
    case L_INREG: {
485
    case L_INREG: {
468
      length += inreg_length (l.reg, 1);
486
      length += inreg_length(l.reg, 1);
469
      break;
487
      break;
470
    }
488
    }
471
    case L_REGOFF: {
489
    case L_REGOFF: {
472
      length += regoff_length(l);
490
      length += regoff_length(l);
473
      break;
491
      break;
474
    }
492
    }
475
    case L_GLOB: {
493
    case L_GLOB: {
476
      length += glob_length(l);
494
      length += glob_length(l);
477
      break;
495
      break;
478
    }
496
    }
479
    case L_INDIRECT: {
497
    case L_INDIRECT: {
480
      length += indirect_length(son(e));
498
      length += indirect_length(son(e));
481
      break;
499
      break;
482
    }
500
    }
483
  }
501
  }
484
  return length;
502
  return length;
485
}
503
}
486
 
504
 
487
static void out_indirect
505
static void out_indirect
488
    PROTO_N ( (e) )
-
 
489
    PROTO_T ( exp e )
506
(exp e)
490
{
507
{
491
  loc_s l;
508
  loc_s l;
492
  l = find_loc (e);
509
  l = find_loc(e);
493
  switch (l.key) {
510
  switch (l.key) {
494
    case L_INREG: {
511
    case L_INREG: {
495
      out_inreg (l.reg, 1);
512
      out_inreg(l.reg, 1);
496
      outsep();
513
      outsep();
497
      break;
514
      break;
498
    }
515
    }
499
    case L_REGOFF: {
516
    case L_REGOFF: {
500
      out_regoff (l);
517
      out_regoff(l);
501
      outsep();
518
      outsep();
502
      break;
519
      break;
503
    }
520
    }
504
    case L_GLOB: {
521
    case L_GLOB: {
505
      out_glob (l);
522
      out_glob(l);
506
      d_outnl(); out8();
523
      d_outnl(); out8();
507
      break;
524
      break;
508
    }
525
    }
509
    case L_INDIRECT: {
526
    case L_INDIRECT: {
510
      out_indirect(son(e));
527
      out_indirect(son(e));
511
      outsep();
528
      outsep();
512
      break;
529
      break;
513
    }
530
    }
514
  }
531
  }
515
  switch (name(e)) {
532
  switch (name(e)) {
516
    case cont_tag: {
533
    case cont_tag: {
517
      outn ((long)DW_OP_deref);
534
      outn((long)DW_OP_deref);
518
      break;
535
      break;
519
    }
536
    }
520
    case reff_tag: {
537
    case reff_tag: {
521
      if (no(e) >= 0) {
538
      if (no(e) >= 0) {
522
	outn ((long)DW_OP_plus_uconst); outsep();
539
	outn((long)DW_OP_plus_uconst); outsep();
523
	uleb128 ((unsigned long)(no(e)/8));
540
	uleb128((unsigned long)(no(e) /8));
524
      }
541
      }
525
      else {
542
      else {
526
	outn ((long)DW_OP_constu); outsep();
543
	outn((long)DW_OP_constu); outsep();
527
	uleb128 ((unsigned long)(-no(e)/8)); outsep();
544
	uleb128((unsigned long)(-no(e) /8)); outsep();
528
	outn ((long)DW_OP_minus);
545
	outn((long)DW_OP_minus);
529
      }
546
      }
530
      break;
547
      break;
531
    }
548
    }
532
  }
549
  }
533
  return;
550
  return;
534
}
551
}
535
 
552
 
536
 
553
 
537
void dw2_locate_exp
554
void dw2_locate_exp
538
    PROTO_N ( (e, locate_const, cx) )
-
 
539
    PROTO_T ( exp e X int locate_const X int cx )
555
(exp e, int locate_const, int cx)
540
{
556
{
541
  loc_s l;
557
  loc_s l;
542
  int length;
558
  int length;
543
  int within_loclist = (cx & 1);
559
  int within_loclist = (cx & 1);
544
  locate_param = (cx & 2);
560
  locate_param = (cx & 2);
Line 546... Line 562...
546
  no_location = 0;
562
  no_location = 0;
547
  l = find_loc (e);	/* may reduce extra_deref */
563
  l = find_loc (e);	/* may reduce extra_deref */
548
  length = extra_deref;
564
  length = extra_deref;
549
  switch (l.key) {
565
  switch (l.key) {
550
    case L_INREG: {
566
    case L_INREG: {
551
      length += inreg_length (l.reg, extra_deref);
567
      length += inreg_length(l.reg, extra_deref);
552
      break;
568
      break;
553
    }
569
    }
554
    case L_REGOFF: {
570
    case L_REGOFF: {
555
      length += regoff_length(l);
571
      length += regoff_length(l);
556
      break;
572
      break;
Line 566... Line 582...
566
  }
582
  }
567
  if (no_location)
583
  if (no_location)
568
    length = 0;
584
    length = 0;
569
 
585
 
570
  if (within_loclist) {
586
  if (within_loclist) {
571
    out16 ();
587
    out16();
572
    outn ((long)length); outnl();
588
    outn((long)length); outnl();
573
    if (no_location)
589
    if (no_location)
574
      return;
590
      return;
575
    out8 ();
591
    out8();
576
  }
592
  }
577
  else {
593
  else {
578
    out8 ();
594
    out8();
579
    outn ((long)length);
595
    outn((long)length);
580
    if (no_location) {
596
    if (no_location) {
581
      outnl();
597
      outnl();
582
      return;
598
      return;
583
    }
599
    }
584
    outsep();
600
    outsep();
585
  }
601
  }
586
  switch (l.key) {
602
  switch (l.key) {
587
    case L_INREG: {
603
    case L_INREG: {
588
      out_inreg (l.reg, extra_deref);
604
      out_inreg(l.reg, extra_deref);
589
      break;
605
      break;
590
    }
606
    }
591
    case L_REGOFF: {
607
    case L_REGOFF: {
592
      out_regoff (l);
608
      out_regoff(l);
593
      break;
609
      break;
594
    }
610
    }
595
    case L_GLOB: {
611
    case L_GLOB: {
596
      out_glob (l);
612
      out_glob(l);
597
      break;
613
      break;
598
    }
614
    }
599
    case L_INDIRECT: {
615
    case L_INDIRECT: {
600
      out_indirect (e);
616
      out_indirect(e);
601
      break;
617
      break;
602
    }
618
    }
603
  }
619
  }
604
  while (extra_deref) {
620
  while (extra_deref) {
605
    if (extra_deref < 0) {
621
    if (extra_deref < 0) {
606
      failer ("miscalculated location");
622
      failer("miscalculated location");
607
      break;
623
      break;
608
    }
624
    }
609
#if 0
625
#if 0
610
    if (locate_const)
626
    if (locate_const)
611
      failer ("constant location???");
627
      failer("constant location???");
612
#endif
628
#endif
613
    outsep();
629
    outsep();
614
    outn ((long)DW_OP_deref);
630
    outn((long)DW_OP_deref);
615
    extra_deref--;
631
    extra_deref--;
616
  }
632
  }
617
  d_outnl ();
633
  d_outnl();
618
  return;
634
  return;
619
}
635
}
620
 
636
 
621
 
637
 
622
void dw2_prepare_locate
638
void dw2_prepare_locate
623
    PROTO_N ( (id) )
-
 
624
    PROTO_T ( exp id )
639
(exp id)
625
{
640
{
626
			/* set local proc conditions for local locations */
641
			/* set local proc conditions for local locations */
627
  exp p = son(id);	/* proc or general proc */
642
  exp p = son(id);	/* proc or general proc */
628
  locals_offset = no(p);
643
  locals_offset = no(p);
629
  has_fp = proc_has_fp(p);
644
  has_fp = proc_has_fp(p);
630
  return;
645
  return;
631
}
646
}
632
 
647
 
633
void dw_at_procdetails
648
void dw_at_procdetails
634
    PROTO_Z ()
649
(void)
635
{
650
{
636
			/* return address and frame base */
651
			/* return address and frame base */
637
  out8(); outn((long)2); outsep(); outn((long)DW_OP_fbreg); outsep();
652
  out8(); outn((long)2); outsep(); outn((long)DW_OP_fbreg); outsep();
638
  if (has_fp) {
653
  if (has_fp) {
639
    outn((long)4); d_outnl();
654
    outn((long)4); d_outnl();
Line 647... Line 662...
647
  return;
662
  return;
648
}
663
}
649
 
664
 
650
 
665
 
651
void dw2_locate_result
666
void dw2_locate_result
652
    PROTO_N ( (sha) )
-
 
653
    PROTO_T ( shape sha )
667
(shape sha)
654
{
668
{
655
  long length = 1;
669
  long length = 1;
656
  int reg = 0;
670
  int reg = 0;
657
  int indirect = 0;
671
  int indirect = 0;
658
  int multi = 0;
672
  int multi = 0;
659
  if (is_floating(name(sha))) {
673
  if (is_floating(name(sha))) {
660
    reg = 100;
674
    reg = 100;
661
    length = inreg_length (reg, 0);
675
    length = inreg_length(reg, 0);
662
  }
676
  }
663
  else
677
  else
664
  if (!reg_result(sha)) {
678
  if (!reg_result(sha)) {
665
    indirect = 1;
679
    indirect = 1;
666
    length = 2;
680
    length = 2;
667
  }
681
  }
668
  else
682
  else
669
  if (shape_size (sha) > 32) {
683
  if (shape_size(sha) > 32) {
670
    multi = 1;
684
    multi = 1;
671
    length = 6;
685
    length = 6;
672
  }
686
  }
673
  out8 (); outn (length); outsep();
687
  out8(); outn(length); outsep();
674
  if (multi) {
688
  if (multi) {
675
    outn ((long)DW_OP_reg0); outsep();
689
    outn((long)DW_OP_reg0); outsep();
676
    outn ((long)DW_OP_piece); outsep(); outn ((long)4);
690
    outn((long)DW_OP_piece); outsep(); outn((long)4);
677
    outsep();
691
    outsep();
678
    outn ((long)DW_OP_reg0+2); outsep();
692
    outn((long)DW_OP_reg0+2); outsep();
679
    outn ((long)DW_OP_piece); outsep(); outn ((long)4);
693
    outn((long)DW_OP_piece); outsep(); outn((long)4);
680
  }
694
  }
681
  else
695
  else
682
  if (indirect) {
696
  if (indirect) {
683
    outn ((long)DW_OP_breg0); outsep(); outn ((long)0);
697
    outn((long)DW_OP_breg0); outsep(); outn((long)0);
684
  }
698
  }
685
  else {
699
  else {
686
    out_inreg (reg, 0);
700
    out_inreg(reg, 0);
687
  }
701
  }
688
  d_outnl ();
702
  d_outnl();
689
  return;
703
  return;
690
}
704
}
691
 
705
 
692
 
706
 
693
void dw2_locate_val
707
void dw2_locate_val
694
    PROTO_N ( (v) )
-
 
695
    PROTO_T ( dg_where v )
708
(dg_where v)
696
{
709
{
697
  out8 ();
710
  out8();
698
  switch (v.k) {
711
  switch (v.k) {
699
    case NO_WH: {
712
    case NO_WH: {
700
      outn ((long)0);
713
      outn((long)0);
701
      break;
714
      break;
702
    }
715
    }
703
    case WH_STR: {
716
    case WH_STR: {
704
      loc_s l;
717
      loc_s l;
705
      l.key = L_GLOB;
718
      l.key = L_GLOB;
706
      l.s = v.u.s;
719
      l.s = v.u.s;
707
      l.off = v.o;
720
      l.off = v.o;
708
      outn ((long)glob_length (l)); outsep();
721
      outn((long)glob_length(l)); outsep();
709
      out_glob (l);
722
      out_glob(l);
710
      break;
723
      break;
711
    }
724
    }
712
    case WH_REG: {
725
    case WH_REG: {
713
      int r = (int)dwarfreg[v.u.l];
726
      int r = (int)dwarfreg[v.u.l];
714
      outn ((long)inreg_length (r, 0)); outsep();
727
      outn((long)inreg_length(r, 0)); outsep();
715
      out_inreg (r, 0);
728
      out_inreg(r, 0);
716
      break;
729
      break;
717
    }
730
    }
718
    case WH_REGOFF: {
731
    case WH_REGOFF: {
719
      loc_s l;
732
      loc_s l;
720
      l.key = L_REGOFF;
733
      l.key = L_REGOFF;
Line 722... Line 735...
722
      l.off = v.o;
735
      l.off = v.o;
723
      if (l.reg == -2) {
736
      if (l.reg == -2) {
724
	l.reg = -1;
737
	l.reg = -1;
725
	l.off -= locals_offset;
738
	l.off -= locals_offset;
726
      }
739
      }
727
      outn ((long)regoff_length (l)); outsep();
740
      outn((long)regoff_length(l)); outsep();
728
      out_regoff (l);
741
      out_regoff(l);
729
      break;
742
      break;
730
    }
743
    }
731
    default:
744
    default:
732
      failer ("unexpected locate val");
745
      failer("unexpected locate val");
733
  }
746
  }
734
  d_outnl ();
747
  d_outnl();
735
  return;
748
  return;
736
}
749
}
737
 
750
 
738
 
751
 
739
static int dw_eval_exp
752
static int dw_eval_exp
740
    PROTO_N ( (e, line_started) )
-
 
741
    PROTO_T ( exp e X int line_started )
753
(exp e, int line_started)
742
{
754
{
743
  if (line_started)
755
  if (line_started)
744
    outsep();
756
    outsep();
745
  else {
757
  else {
746
    out8 ();
758
    out8();
747
    line_started = 1;
759
    line_started = 1;
748
  }
760
  }
749
  switch (name(e)) {
761
  switch (name(e)) {
750
    case name_tag:
762
    case name_tag:
751
    case cont_tag:
763
    case cont_tag:
752
    case contvol_tag:
764
    case contvol_tag:
753
    case reff_tag: {
765
    case reff_tag: {
754
      loc_s l;
766
      loc_s l;
755
      locate_param = extra_deref = no_location = 0;
767
      locate_param = extra_deref = no_location = 0;
756
      l = find_loc (e);
768
      l = find_loc(e);
757
      if (no_location || extra_deref)
769
      if (no_location || extra_deref)
758
	failer ("value unobtainable by DWARF expression");
770
	failer("value unobtainable by DWARF expression");
759
      switch (l.key) {
771
      switch (l.key) {
760
	case L_INREG: {
772
	case L_INREG: {
761
	  out_inreg (l.reg, extra_deref);
773
	  out_inreg(l.reg, extra_deref);
762
	  break;
774
	  break;
763
	}
775
	}
764
	case L_REGOFF: {
776
	case L_REGOFF: {
765
	  out_regoff (l);
777
	  out_regoff(l);
766
	  break;
778
	  break;
767
	}
779
	}
768
	case L_GLOB: {
780
	case L_GLOB: {
769
	  out_glob (l);
781
	  out_glob(l);
770
	  d_outnl ();
782
	  d_outnl();
771
	  line_started = 0;
783
	  line_started = 0;
772
	  break;
784
	  break;
773
	}
785
	}
774
	case L_INDIRECT: {
786
	case L_INDIRECT: {
775
	  out_indirect (e);
787
	  out_indirect(e);
776
	  break;
788
	  break;
777
	}
789
	}
778
      }
790
      }
779
      break;
791
      break;
780
    }
792
    }
781
    case val_tag:
793
    case val_tag:
782
    case null_tag : {
794
    case null_tag: {
783
      if (isbigval(e)) {
795
      if (isbigval(e)) {
784
	flt64 x;
796
	flt64 x;
785
	int ov;
797
	int ov;
786
	x = flt_to_f64(no(e), is_signed(sh(e)), &ov);
798
	x = flt_to_f64(no(e), is_signed(sh(e)), &ov);
787
	outn((long)(is_signed(sh(e)) ? DW_OP_const8s : DW_OP_const8u)); d_outnl();
799
	outn((long)(is_signed(sh(e))? DW_OP_const8s : DW_OP_const8u)); d_outnl();
788
	out32(); outn((long)(x.small)); outsep(); outn((long)(x.big)); d_outnl();
800
	out32(); outn((long)(x.small)); outsep(); outn((long)(x.big)); d_outnl();
789
	line_started = 0;
801
	line_started = 0;
790
      }
802
      }
791
      else
803
      else
792
      if (no(e) >= 0 && no(e) < 32)
804
      if (no(e) >= 0 && no(e) < 32)
793
	outn((long)(DW_OP_lit0 + no(e)));
805
	outn((long)(DW_OP_lit0 + no(e)));
794
      else
806
      else
795
      if (is_signed(sh(e))) {
807
      if (is_signed(sh(e))) {
796
	outn((long)DW_OP_consts); outsep();
808
	outn((long)DW_OP_consts); outsep();
797
	sleb128 ((long)no(e));
809
	sleb128((long)no(e));
798
      }
810
      }
799
      else {
811
      else {
800
	outn((long)DW_OP_constu); outsep();
812
	outn((long)DW_OP_constu); outsep();
801
	uleb128 ((unsigned long)no(e));
813
	uleb128((unsigned long)no(e));
802
      }
814
      }
803
      break;
815
      break;
804
    }
816
    }
805
    case plus_tag:
817
    case plus_tag:
806
    case offset_add_tag : {
818
    case offset_add_tag: {
807
      line_started = dw_eval_exp (son(e), line_started);
819
      line_started = dw_eval_exp(son(e), line_started);
808
      if (name(bro(son(e))) == val_tag && !is_signed(sh(e)) && !isbigval(bro(son(e)))) {
820
      if (name(bro(son(e))) == val_tag && !is_signed(sh(e)) && !isbigval(bro(son(e)))) {
809
	if (line_started)
821
	if (line_started)
810
	  outsep();
822
	  outsep();
811
	else {
823
	else {
812
	  out8 ();
824
	  out8();
813
	  line_started = 1;
825
	  line_started = 1;
814
	}
826
	}
815
	outn((long)DW_OP_plus_uconst); outsep();
827
	outn((long)DW_OP_plus_uconst); outsep();
816
	uleb128 ((unsigned long)no(e));
828
	uleb128((unsigned long)no(e));
817
      }
829
      }
818
      else {
830
      else {
819
	line_started = dw_eval_exp (bro(son(e)), line_started);
831
	line_started = dw_eval_exp(bro(son(e)), line_started);
820
	if (line_started)
832
	if (line_started)
821
	  outsep();
833
	  outsep();
822
	else {
834
	else {
823
	  out8 ();
835
	  out8();
824
	  line_started = 1;
836
	  line_started = 1;
825
	}
837
	}
826
	outn((long)DW_OP_plus);
838
	outn((long)DW_OP_plus);
827
      }
839
      }
828
      break;
840
      break;
829
    }
841
    }
830
    case minus_tag:
842
    case minus_tag:
831
    case offset_subtract_tag : {
843
    case offset_subtract_tag: {
832
      line_started = dw_eval_exp (son(e), line_started);
844
      line_started = dw_eval_exp(son(e), line_started);
833
      line_started = dw_eval_exp (bro(son(e)), line_started);
845
      line_started = dw_eval_exp(bro(son(e)), line_started);
834
      if (line_started)
846
      if (line_started)
835
	outsep();
847
	outsep();
836
      else {
848
      else {
837
	out8 ();
849
	out8();
838
	line_started = 1;
850
	line_started = 1;
839
      }
851
      }
840
      outn((long)DW_OP_minus);
852
      outn((long)DW_OP_minus);
841
      break;
853
      break;
842
    }
854
    }
843
    case neg_tag:
855
    case neg_tag:
844
    case offset_negate_tag : {
856
    case offset_negate_tag: {
845
      line_started = dw_eval_exp (son(e), line_started);
857
      line_started = dw_eval_exp(son(e), line_started);
846
      if (line_started)
858
      if (line_started)
847
	outsep();
859
	outsep();
848
      else {
860
      else {
849
	out8 ();
861
	out8();
850
	line_started = 1;
862
	line_started = 1;
851
      }
863
      }
852
      outn((long)DW_OP_neg);
864
      outn((long)DW_OP_neg);
853
      break;
865
      break;
854
    }
866
    }
855
    case mult_tag:
867
    case mult_tag:
856
    case offset_mult_tag : {
868
    case offset_mult_tag: {
857
      line_started = dw_eval_exp (son(e), line_started);
869
      line_started = dw_eval_exp(son(e), line_started);
858
      line_started = dw_eval_exp (bro(son(e)), line_started);
870
      line_started = dw_eval_exp(bro(son(e)), line_started);
859
      if (line_started)
871
      if (line_started)
860
	outsep();
872
	outsep();
861
      else {
873
      else {
862
	out8 ();
874
	out8();
863
	line_started = 1;
875
	line_started = 1;
864
      }
876
      }
865
      outn((long)DW_OP_mul);
877
      outn((long)DW_OP_mul);
866
      break;
878
      break;
867
    }
879
    }
868
    case div0_tag :
880
    case div0_tag:
869
    case div1_tag :
881
    case div1_tag:
870
    case div2_tag :
882
    case div2_tag:
871
    case offset_div_by_int_tag :
883
    case offset_div_by_int_tag:
872
    case offset_div_tag : {
884
    case offset_div_tag: {
873
      line_started = dw_eval_exp (son(e), line_started);
885
      line_started = dw_eval_exp(son(e), line_started);
874
      line_started = dw_eval_exp (bro(son(e)), line_started);
886
      line_started = dw_eval_exp(bro(son(e)), line_started);
875
      if (line_started)
887
      if (line_started)
876
	outsep();
888
	outsep();
877
      else {
889
      else {
878
	out8 ();
890
	out8();
879
	line_started = 1;
891
	line_started = 1;
880
      }
892
      }
881
      outn((long)DW_OP_div);
893
      outn((long)DW_OP_div);
882
      break;
894
      break;
883
    }
895
    }
884
    default:
896
    default:
885
      failer ("unsupported operation for DWARF expression");
897
      failer("unsupported operation for DWARF expression");
886
  }
898
  }
887
  return line_started;
899
  return line_started;
888
}
900
}
889
 
901
 
890
 
902
 
891
void dw2_offset_exp
903
void dw2_offset_exp
892
    PROTO_N ( (e) )
-
 
893
    PROTO_T ( exp e )
904
(exp e)
894
{
905
{
895
  long block_end = next_dwarf_label ();
906
  long block_end = next_dwarf_label();
896
  if (name(sh(e)) != offsethd)
907
  if (name(sh(e))!= offsethd)
897
    failer ("wrong shape for offset expression");
908
    failer("wrong shape for offset expression");
898
  dw_at_form (DW_FORM_block2); d_outnl();
909
  dw_at_form(DW_FORM_block2); d_outnl();
899
  out16 (); out_dwf_dist_to_label (block_end); d_outnl();
910
  out16(); out_dwf_dist_to_label(block_end); d_outnl();
900
  if (dw_eval_exp (e, 0))
911
  if (dw_eval_exp(e, 0))
901
    d_outnl();
912
    d_outnl();
902
  if (name(sh(e)) == offsethd && al2(sh(e)) < 8 ) {
913
  if (name(sh(e)) == offsethd && al2(sh(e)) < 8) {
903
    out8 (); outn((long)(DW_OP_lit0 + 8)); outsep();
914
    out8(); outn((long)(DW_OP_lit0 + 8)); outsep();
904
    outn((long)DW_OP_mul); d_outnl();
915
    outn((long)DW_OP_mul); d_outnl();
905
  }
916
  }
906
  out_dwf_label (block_end, 1);
917
  out_dwf_label(block_end, 1);
907
  return;
918
  return;
908
}
919
}
909
 
920
 
910
 
921
 
911
void dw2_cie
922
void dw2_cie
912
    PROTO_Z ()
923
(void)
913
{
924
{
914
  long cie_end;
925
  long cie_end;
915
  cie_pointer = next_dwarf_label();
926
  cie_pointer = next_dwarf_label();
916
  cie_end = next_dwarf_label();
927
  cie_end = next_dwarf_label();
917
  enter_section ("debug_frame");
928
  enter_section("debug_frame");
918
  outnl_comment ("Common Information Entry");
929
  outnl_comment("Common Information Entry");
919
  out_dwf_label (cie_pointer, 1);
930
  out_dwf_label(cie_pointer, 1);
920
  out32 (); out_dwf_dist_to_label (cie_end); d_outnl();
931
  out32(); out_dwf_dist_to_label(cie_end); d_outnl();
921
  out32 (); outn ((long)DW_CIE_id); d_outnl ();
932
  out32(); outn((long)DW_CIE_id); d_outnl();
922
  out8 (); outn ((long)DW_CIE_MOD_VERSION); d_outnl ();
933
  out8(); outn((long)DW_CIE_MOD_VERSION); d_outnl();
923
  out_string ("DERA/DDC-I");
934
  out_string("DERA/DDC-I");
924
  out8 (); uleb128 ((unsigned long)framecode_factor); d_outnl ();
935
  out8(); uleb128((unsigned long)framecode_factor); d_outnl();
925
  out8 (); sleb128 ((long)framedata_factor); d_outnl ();
936
  out8(); sleb128((long)framedata_factor); d_outnl();
926
  out8 (); outn ((long)retaddr); d_outnl ();	/* return address column */
937
  out8 (); outn ((long)retaddr); d_outnl ();	/* return address column */
927
  out8 (); outn ((long)DW_CFA_def_cfa);
938
  out8(); outn((long)DW_CFA_def_cfa);
928
	outsep (); uleb128 ((unsigned long)dw_sp);
939
	outsep(); uleb128((unsigned long)dw_sp);
929
	outsep (); uleb128 ((unsigned long)0);	/* CFA is sp at entry point */
940
	outsep (); uleb128 ((unsigned long)0);	/* CFA is sp at entry point */
930
	d_outnl ();
941
	d_outnl();
931
  out8 (); outn ((long)DW_CFA_undefined);
942
  out8(); outn((long)DW_CFA_undefined);
932
	outsep (); uleb128 ((unsigned long)dwarfreg [0]);	/* eax */
943
	outsep (); uleb128 ((unsigned long)dwarfreg [0]);	/* eax */
933
	d_outnl ();
944
	d_outnl();
934
  out8 (); outn ((long)DW_CFA_undefined);
945
  out8(); outn((long)DW_CFA_undefined);
935
	outsep (); uleb128 ((unsigned long)dwarfreg [1]);	/* edx */
946
	outsep (); uleb128 ((unsigned long)dwarfreg [1]);	/* edx */
936
	d_outnl ();
947
	d_outnl();
937
  out8 (); outn ((long)DW_CFA_undefined);
948
  out8(); outn((long)DW_CFA_undefined);
938
	outsep (); uleb128 ((unsigned long)dwarfreg [2]);	/* ecx */
949
	outsep (); uleb128 ((unsigned long)dwarfreg [2]);	/* ecx */
939
	d_outnl ();
950
	d_outnl();
940
  out8 (); outn ((long)DW_CFA_same_value);
951
  out8(); outn((long)DW_CFA_same_value);
941
	outsep (); uleb128 ((unsigned long)dwarfreg [3]);	/* ebx */
952
	outsep (); uleb128 ((unsigned long)dwarfreg [3]);	/* ebx */
942
	d_outnl ();
953
	d_outnl();
943
  out8 (); outn ((long)DW_CFA_same_value);
954
  out8(); outn((long)DW_CFA_same_value);
944
	outsep (); uleb128 ((unsigned long)dwarfreg [4]);	/* edi */
955
	outsep (); uleb128 ((unsigned long)dwarfreg [4]);	/* edi */
945
	d_outnl ();
956
	d_outnl();
946
  out8 (); outn ((long)DW_CFA_same_value);
957
  out8(); outn((long)DW_CFA_same_value);
947
	outsep (); uleb128 ((unsigned long)dwarfreg [5]);	/* esi */
958
	outsep (); uleb128 ((unsigned long)dwarfreg [5]);	/* esi */
948
	d_outnl ();
959
	d_outnl();
949
  out8 (); outn ((long)DW_CFA_same_value);
960
  out8(); outn((long)DW_CFA_same_value);
950
	outsep (); uleb128 ((unsigned long)dwarfreg [6]);	/* ebp */
961
	outsep (); uleb128 ((unsigned long)dwarfreg [6]);	/* ebp */
951
	d_outnl ();
962
	d_outnl();
952
  out8 (); outn ((long)DW_CFA_DD_location);
963
  out8(); outn((long)DW_CFA_DD_location);
953
	outsep (); uleb128 ((unsigned long)dw_sp);		/* esp */
964
	outsep (); uleb128 ((unsigned long)dw_sp);		/* esp */
954
	outsep (); outn ((long)2);	/* location block */
965
	outsep (); outn ((long)2);	/* location block */
955
	outsep (); outn ((long)DW_OP_plus_uconst);
966
	outsep(); outn((long)DW_OP_plus_uconst);
956
	outsep (); uleb128 ((unsigned long)4);	/* virtual pop return address */
967
	outsep (); uleb128 ((unsigned long)4);	/* virtual pop return address */
957
	d_outnl ();
968
	d_outnl();
958
  out8 (); outn ((long)DW_CFA_offset + retaddr);
969
  out8(); outn((long)DW_CFA_offset + retaddr);
959
	outsep (); uleb128 ((unsigned long)0);	/* return address */
970
	outsep (); uleb128 ((unsigned long)0);	/* return address */
960
	d_outnl ();
971
	d_outnl();
961
  dot_align (PTR_SZ/8);
972
  dot_align(PTR_SZ/8);
962
  out_dwf_label (cie_end, 1);
973
  out_dwf_label(cie_end, 1);
963
  exit_section ();
974
  exit_section();
964
  return;
975
  return;
965
}
976
}
966
 
977
 
967
static void short_advance
978
static void short_advance
968
    PROTO_N ( (lo, hi) )
-
 
969
    PROTO_T ( long lo X long hi )
979
(long lo, long hi)
970
{
980
{
971
  if (lo) {
981
  if (lo) {
972
    out8 (); out_dwf_label (hi, 0);  outs (" - "); out_dwf_label (lo, 0);
982
    out8(); out_dwf_label(hi, 0);  outs(" - "); out_dwf_label(lo, 0);
973
    outs (" + "); outn ((long)DW_CFA_advance_loc); d_outnl ();
983
    outs(" + "); outn((long)DW_CFA_advance_loc); d_outnl();
974
  }
984
  }
975
  else {
985
  else {
976
    out8 (); outn ((long)DW_CFA_set_loc); d_outnl ();
986
    out8(); outn((long)DW_CFA_set_loc); d_outnl();
977
    out32 (); out_dwf_label (hi, 0); d_outnl ();
987
    out32(); out_dwf_label(hi, 0); d_outnl();
978
  }
988
  }
979
  return;
989
  return;
980
}
990
}
981
 
991
 
982
long dw2_start_fde
992
long dw2_start_fde
983
    PROTO_N ( (proc_start, fblab) )
-
 
984
    PROTO_T ( long proc_start X long fblab )
993
(long proc_start, long fblab)
985
{
994
{
986
  long hold_pos;
995
  long hold_pos;
987
  fde_end = next_dwarf_label();
996
  fde_end = next_dwarf_label();
988
  proc_end = next_dwarf_label();
997
  proc_end = next_dwarf_label();
989
  enter_section ("debug_frame");
998
  enter_section("debug_frame");
990
  outnl_comment ("Frame Descriptor Entry");
999
  outnl_comment("Frame Descriptor Entry");
991
  out32 (); out_dwf_dist_to_label (fde_end); d_outnl ();
1000
  out32(); out_dwf_dist_to_label(fde_end); d_outnl();
992
  out32 (); out_dwf_label (cie_pointer, 0); d_outnl ();
1001
  out32(); out_dwf_label(cie_pointer, 0); d_outnl();
993
  out32 (); out_dwf_label (proc_start, 0); d_outnl ();
1002
  out32(); out_dwf_label(proc_start, 0); d_outnl();
994
  out32 (); out_dwf_labdiff (proc_start, proc_end); d_outnl ();
1003
  out32(); out_dwf_labdiff(proc_start, proc_end); d_outnl();
995
 
1004
 
996
  if (callee_size >= 0) {
1005
  if (callee_size >= 0) {
997
    unsigned long pop_bytes = 4;
1006
    unsigned long pop_bytes = 4;
998
    int n = (remove_struct_ref && has_struct_res(crt_proc_exp)) ? 32 : 0;
1007
    int n = (remove_struct_ref && has_struct_res(crt_proc_exp))? 32 : 0;
999
    if ((n += callee_size) != 0) {
1008
    if ((n += callee_size)!= 0) {
1000
      pop_bytes += (unsigned long)(n/8);
1009
      pop_bytes += (unsigned long)(n/8);
1001
      out8 (); outn ((long)DW_CFA_DD_location);
1010
      out8(); outn((long)DW_CFA_DD_location);
1002
	outsep (); uleb128 ((unsigned long)dw_sp);
1011
	outsep(); uleb128((unsigned long)dw_sp);
1003
	outsep (); outn ((long)1 + (long)uleb128_length(pop_bytes));
1012
	outsep(); outn((long)1 + (long)uleb128_length(pop_bytes));
1004
	outsep (); outn ((long)DW_OP_plus_uconst);
1013
	outsep(); outn((long)DW_OP_plus_uconst);
1005
	outsep (); uleb128 (pop_bytes);	/* adjust virtual pops */
1014
	outsep (); uleb128 (pop_bytes);	/* adjust virtual pops */
1006
	d_outnl ();
1015
	d_outnl();
1007
    }
1016
    }
1008
  }
1017
  }
1009
  else {	/* var_callees */
1018
  else {	/* var_callees */
1010
    int extra = (remove_struct_ref && has_struct_res(crt_proc_exp)) ? 2 : 0;
1019
    int extra = (remove_struct_ref && has_struct_res(crt_proc_exp))? 2 : 0;
1011
    out8 (); outn ((long)DW_CFA_DD_location);
1020
    out8(); outn((long)DW_CFA_DD_location);
1012
	outsep (); uleb128 ((unsigned long)dw_sp);
1021
	outsep(); uleb128((unsigned long)dw_sp);
1013
	outsep (); outn ((long)(3 + extra));	/* location block length */
1022
	outsep (); outn ((long)(3 + extra));	/* location block length */
1014
	outsep (); outn ((long)DW_OP_plus_uconst);
1023
	outsep(); outn((long)DW_OP_plus_uconst);
1015
	outsep (); uleb128 ((unsigned long)4);	/* virtual pop return address */
1024
	outsep (); uleb128 ((unsigned long)4);	/* virtual pop return address */
1016
	outsep (); outn ((long)DW_OP_deref);	/* over callees */
1025
	outsep (); outn ((long)DW_OP_deref);	/* over callees */
1017
	if (extra) {
1026
	if (extra) {
1018
	  outsep (); outn ((long)DW_OP_plus_uconst);
1027
	  outsep(); outn((long)DW_OP_plus_uconst);
1019
	  outsep (); uleb128 ((unsigned long)4);	/* pop struct_res */
1028
	  outsep (); uleb128 ((unsigned long)4);	/* pop struct_res */
1020
	}
1029
	}
1021
	d_outnl ();
1030
	d_outnl();
1022
  }
1031
  }
1023
 
1032
 
1024
  if (!no_frame) {
1033
  if (!no_frame) {
1025
    short_advance (proc_start, fblab);
1034
    short_advance(proc_start, fblab);
1026
    out8 (); outn ((long)DW_CFA_def_cfa);
1035
    out8(); outn((long)DW_CFA_def_cfa);
1027
	outsep (); uleb128 ((unsigned long)dwarfreg[6]);
1036
	outsep(); uleb128((unsigned long)dwarfreg[6]);
1028
	outsep (); uleb128 ((unsigned long)4);	/* CFA now relative to %ebp */
1037
	outsep (); uleb128 ((unsigned long)4);	/* CFA now relative to %ebp */
1029
	d_outnl ();
1038
	d_outnl();
1030
    out8 (); outn ((long)DW_CFA_offset + dwarfreg[6]); /* %ebp */
1039
    out8 (); outn ((long)DW_CFA_offset + dwarfreg[6]); /* %ebp */
1031
	outsep (); uleb128 ((unsigned long)1); d_outnl ();
1040
	outsep(); uleb128((unsigned long)1); d_outnl();
1032
  }
1041
  }
1033
 
1042
 
1034
  if (flush_before_tell)
1043
  if (flush_before_tell)
1035
    IGNORE fflush(fpout);
1044
    IGNORE fflush(fpout);
1036
  hold_pos = ftell (fpout);
1045
  hold_pos = ftell(fpout);
1037
  outs (sp50); outs (sp50); outs (sp50); outs (sp50); outs (sp50); outs (sp50); outs (sp50);
1046
  outs(sp50); outs(sp50); outs(sp50); outs(sp50); outs(sp50); outs(sp50); outs(sp50);
1038
  d_outnl ();
1047
  d_outnl();
1039
 
1048
 
1040
  exit_section ();
1049
  exit_section();
1041
  return hold_pos;
1050
  return hold_pos;
1042
}
1051
}
1043
 
1052
 
1044
void dw2_fde_entry
1053
void dw2_fde_entry
1045
    PROTO_N ( (dwl0, dwl1, dwl2, dwl3, dwl4, dwl8, space) )
-
 
1046
    PROTO_T ( long dwl0 X long dwl1 X long dwl2 X long dwl3 X long dwl4 X long dwl8 X int space )
1054
(long dwl0, long dwl1, long dwl2, long dwl3, long dwl4, long dwl8, int space)
1047
{
1055
{
1048
  long here = dwl0;
1056
  long here = dwl0;
1049
  unsigned long up = 0;
1057
  unsigned long up = 0;
1050
  if (!no_frame) {
1058
  if (!no_frame) {
1051
    here = dwl1;
1059
    here = dwl1;
1052
    ++up;
1060
    ++up;
1053
  }
1061
  }
1054
  if (min_rfree & 0x8) {
1062
  if (min_rfree & 0x8) {
1055
    short_advance (here, dwl2);
1063
    short_advance(here, dwl2);
1056
    here = dwl2;
1064
    here = dwl2;
1057
    out8 ();
1065
    out8();
1058
    if (no_frame) {
1066
    if (no_frame) {
1059
	outn ((long)DW_CFA_DD_def_cfa_inc_offset); outsep ();
1067
	outn((long)DW_CFA_DD_def_cfa_inc_offset); outsep();
1060
    }
1068
    }
1061
	outn ((long)DW_CFA_offset + dwarfreg[3]); /* %ebx */
1069
	outn ((long)DW_CFA_offset + dwarfreg[3]); /* %ebx */
1062
	outsep (); uleb128 (++up); d_outnl ();
1070
	outsep(); uleb128(++up); d_outnl();
1063
  }
1071
  }
1064
  if (min_rfree & 0x10) {
1072
  if (min_rfree & 0x10) {
1065
    short_advance (here, dwl3);
1073
    short_advance(here, dwl3);
1066
    here = dwl3;
1074
    here = dwl3;
1067
    out8 ();
1075
    out8();
1068
    if (no_frame) {
1076
    if (no_frame) {
1069
	outn ((long)DW_CFA_DD_def_cfa_inc_offset); outsep ();
1077
	outn((long)DW_CFA_DD_def_cfa_inc_offset); outsep();
1070
    }
1078
    }
1071
	outn ((long)DW_CFA_offset + dwarfreg[4]); /* %edi */
1079
	outn ((long)DW_CFA_offset + dwarfreg[4]); /* %edi */
1072
	outsep (); uleb128 (++up); d_outnl ();
1080
	outsep(); uleb128(++up); d_outnl();
1073
  }
1081
  }
1074
  if (min_rfree & 0x20) {
1082
  if (min_rfree & 0x20) {
1075
    short_advance (here, dwl4);
1083
    short_advance(here, dwl4);
1076
    here = dwl4;
1084
    here = dwl4;
1077
    out8 ();
1085
    out8();
1078
    if (no_frame) {
1086
    if (no_frame) {
1079
	outn ((long)DW_CFA_DD_def_cfa_inc_offset); outsep ();
1087
	outn((long)DW_CFA_DD_def_cfa_inc_offset); outsep();
1080
    }
1088
    }
1081
	outn ((long)DW_CFA_offset + dwarfreg[5]); /* %esi */
1089
	outn ((long)DW_CFA_offset + dwarfreg[5]); /* %esi */
1082
	outsep (); uleb128 (++up); d_outnl ();
1090
	outsep(); uleb128(++up); d_outnl();
1083
  }
1091
  }
1084
  if (no_frame && (min_rfree & 0x40)) {
1092
  if (no_frame && (min_rfree & 0x40)) {
1085
    short_advance (here, dwl1);
1093
    short_advance(here, dwl1);
1086
    here = dwl1;
1094
    here = dwl1;
1087
    out8 (); outn ((long)DW_CFA_DD_def_cfa_inc_offset); outsep ();
1095
    out8(); outn((long)DW_CFA_DD_def_cfa_inc_offset); outsep();
1088
	outn ((long)DW_CFA_offset + dwarfreg[6]); /* %ebp */
1096
	outn ((long)DW_CFA_offset + dwarfreg[6]); /* %ebp */
1089
	outsep (); uleb128 (++up); d_outnl ();
1097
	outsep(); uleb128(++up); d_outnl();
1090
  }
1098
  }
1091
  if (space && no_frame) {
1099
  if (space && no_frame) {
1092
    short_advance (here, dwl8);
1100
    short_advance(here, dwl8);
1093
    out8 (); outn ((long)DW_CFA_def_cfa_offset); outsep ();
1101
    out8(); outn((long)DW_CFA_def_cfa_offset); outsep();
1094
	uleb128 ((unsigned long)space); d_outnl ();
1102
	uleb128((unsigned long)space); d_outnl();
1095
  }
1103
  }
1096
  return;
1104
  return;
1097
}
1105
}
1098
 
1106
 
1099
void dw2_untidy_return
1107
void dw2_untidy_return
1100
    PROTO_Z ()
1108
(void)
1101
{
1109
{
1102
	/* we have pushed the return address */
1110
	/* we have pushed the return address */
1103
  long here = set_dw_text_label ();
1111
  long here = set_dw_text_label();
1104
  enter_section ("debug_frame");
1112
  enter_section("debug_frame");
1105
  out8 (); outn ((long)DW_CFA_set_loc); d_outnl ();
1113
  out8(); outn((long)DW_CFA_set_loc); d_outnl();
1106
  out32 (); out_dwf_label (here, 0); d_outnl ();
1114
  out32(); out_dwf_label(here, 0); d_outnl();
1107
  out8 (); outn ((long)DW_CFA_remember_state); outsep ();
1115
  out8(); outn((long)DW_CFA_remember_state); outsep();
1108
  if (no_frame) {
1116
  if (no_frame) {
1109
    outn ((long)DW_CFA_DD_def_cfa_inc_offset); d_outnl ();
1117
    outn((long)DW_CFA_DD_def_cfa_inc_offset); d_outnl();
1110
  }
1118
  }
1111
  exit_section ();
1119
  exit_section();
1112
  return;
1120
  return;
1113
}
1121
}
1114
 
1122
 
1115
long dw2_prep_fde_restore_args
1123
long dw2_prep_fde_restore_args
1116
    PROTO_N ( (untidy) )
-
 
1117
    PROTO_T ( int untidy )
1124
(int untidy)
1118
{
1125
{
1119
  long here;
1126
  long here;
1120
  if (!untidy) {
1127
  if (!untidy) {
1121
    long pos;
1128
    long pos;
1122
    enter_section ("debug_frame");
1129
    enter_section("debug_frame");
1123
    out8 (); outn ((long)DW_CFA_remember_state); d_outnl ();
1130
    out8(); outn((long)DW_CFA_remember_state); d_outnl();
1124
    pos = ftell(fpout);
1131
    pos = ftell(fpout);
1125
    outs (sp50); outs (sp50); outs (sp50); outs (sp50); outs (sp50); outs (sp50);
1132
    outs(sp50); outs(sp50); outs(sp50); outs(sp50); outs(sp50); outs(sp50);
1126
    d_outnl ();
-
 
1127
    d_outnl();
1133
    d_outnl();
-
 
1134
    d_outnl();
1128
    exit_section ();
1135
    exit_section();
1129
    return pos;
1136
    return pos;
1130
  }
1137
  }
1131
	/* otherwise */
1138
	/* otherwise */
1132
  here = set_dw_text_label ();
1139
  here = set_dw_text_label();
1133
  enter_section ("debug_frame");
1140
  enter_section("debug_frame");
1134
  short_advance ((long)0, here);
1141
  short_advance((long)0, here);
1135
  out8 (); outn ((long)DW_CFA_restore + dwarfreg[3]); d_outnl ();
1142
  out8(); outn((long)DW_CFA_restore + dwarfreg[3]); d_outnl();
1136
  out8 (); outn ((long)DW_CFA_restore + dwarfreg[4]); d_outnl ();
1143
  out8(); outn((long)DW_CFA_restore + dwarfreg[4]); d_outnl();
1137
  out8 (); outn ((long)DW_CFA_restore + dwarfreg[5]); d_outnl ();
1144
  out8(); outn((long)DW_CFA_restore + dwarfreg[5]); d_outnl();
1138
  out8 (); outn ((long)DW_CFA_restore + dwarfreg[6]); d_outnl ();
1145
  out8(); outn((long)DW_CFA_restore + dwarfreg[6]); d_outnl();
1139
 
1146
 
1140
  if (!no_frame) {	/* %ebp restored, return address pushed */
1147
  if (!no_frame) {	/* %ebp restored, return address pushed */
1141
    out8 (); outn ((long)DW_CFA_def_cfa);
1148
    out8(); outn((long)DW_CFA_def_cfa);
1142
	outsep (); uleb128 ((unsigned long)dw_sp);
1149
	outsep(); uleb128((unsigned long)dw_sp);
1143
	outsep (); uleb128 ((unsigned long)0);	/* temp CFA */
1150
	outsep (); uleb128 ((unsigned long)0);	/* temp CFA */
1144
	d_outnl ();
1151
	d_outnl();
1145
    out8 (); outn ((long)DW_CFA_undefined);
1152
    out8(); outn((long)DW_CFA_undefined);
1146
	outsep (); uleb128 ((unsigned long)dw_sp);
1153
	outsep(); uleb128((unsigned long)dw_sp);
1147
	d_outnl ();
1154
	d_outnl();
1148
  }
1155
  }
1149
  exit_section ();
1156
  exit_section();
1150
  return 0;
1157
  return 0;
1151
}
1158
}
1152
 
1159
 
1153
void dw2_fde_restore_args
1160
void dw2_fde_restore_args
1154
    PROTO_N ( (dwl0, dwl1, dwl2, dwl3, dwl4, space) )
-
 
1155
    PROTO_T ( long dwl0 X long dwl1 X long dwl2 X long dwl3 X long dwl4 X int space )
1161
(long dwl0, long dwl1, long dwl2, long dwl3, long dwl4, int space)
1156
{
1162
{
1157
  long here = 0;
1163
  long here = 0;
1158
  if (no_frame && dwl0) {
1164
  if (no_frame && dwl0) {
1159
    short_advance (here, dwl0);
1165
    short_advance(here, dwl0);
1160
    here = dwl0;
1166
    here = dwl0;
1161
    out8 (); outn ((long)DW_CFA_def_cfa_offset); outsep ();
1167
    out8(); outn((long)DW_CFA_def_cfa_offset); outsep();
1162
	uleb128 ((unsigned long)space); d_outnl ();
1168
	uleb128((unsigned long)space); d_outnl();
1163
  }
1169
  }
1164
  if (no_frame && (min_rfree & 0x40)) {
1170
  if (no_frame && (min_rfree & 0x40)) {
1165
    short_advance (here, dwl1);
1171
    short_advance(here, dwl1);
1166
    here = dwl1;
1172
    here = dwl1;
1167
    out8 (); outn ((long)DW_CFA_DD_def_cfa_dec_offset); outsep ();
1173
    out8(); outn((long)DW_CFA_DD_def_cfa_dec_offset); outsep();
1168
	outn ((long)DW_CFA_restore + dwarfreg[6]); /* %ebp */
1174
	outn ((long)DW_CFA_restore + dwarfreg[6]); /* %ebp */
1169
	d_outnl ();
1175
	d_outnl();
1170
  }
1176
  }
1171
  if (min_rfree & 0x20) {
1177
  if (min_rfree & 0x20) {
1172
    short_advance (here, dwl2);
1178
    short_advance(here, dwl2);
1173
    here = dwl2;
1179
    here = dwl2;
1174
    out8 ();
1180
    out8();
1175
    if (no_frame) {
1181
    if (no_frame) {
1176
	outn ((long)DW_CFA_DD_def_cfa_dec_offset); outsep ();
1182
	outn((long)DW_CFA_DD_def_cfa_dec_offset); outsep();
1177
    }
1183
    }
1178
	outn ((long)DW_CFA_restore + dwarfreg[5]); /* %esi */
1184
	outn ((long)DW_CFA_restore + dwarfreg[5]); /* %esi */
1179
	d_outnl ();
1185
	d_outnl();
1180
  }
1186
  }
1181
  if (min_rfree & 0x10) {
1187
  if (min_rfree & 0x10) {
1182
    short_advance (here, dwl3);
1188
    short_advance(here, dwl3);
1183
    here = dwl3;
1189
    here = dwl3;
1184
    out8 ();
1190
    out8();
1185
    if (no_frame) {
1191
    if (no_frame) {
1186
	outn ((long)DW_CFA_DD_def_cfa_dec_offset); outsep ();
1192
	outn((long)DW_CFA_DD_def_cfa_dec_offset); outsep();
1187
    }
1193
    }
1188
	outn ((long)DW_CFA_restore + dwarfreg[4]); /* %edi */
1194
	outn ((long)DW_CFA_restore + dwarfreg[4]); /* %edi */
1189
	d_outnl ();
1195
	d_outnl();
1190
  }
1196
  }
1191
  if (min_rfree & 0x8) {
1197
  if (min_rfree & 0x8) {
1192
    short_advance (here, dwl4);
1198
    short_advance(here, dwl4);
1193
    here = dwl4;
1199
    here = dwl4;
1194
    out8 ();
1200
    out8();
1195
    if (no_frame) {
1201
    if (no_frame) {
1196
	outn ((long)DW_CFA_DD_def_cfa_dec_offset); outsep ();
1202
	outn((long)DW_CFA_DD_def_cfa_dec_offset); outsep();
1197
    }
1203
    }
1198
	outn ((long)DW_CFA_restore + dwarfreg[3]); /* %ebx */
1204
	outn ((long)DW_CFA_restore + dwarfreg[3]); /* %ebx */
1199
	d_outnl ();
1205
	d_outnl();
1200
  }
1206
  }
1201
  if (!no_frame)  {
1207
  if (!no_frame) {
1202
    short_advance (here, dwl1);
1208
    short_advance(here, dwl1);
1203
    here = dwl1;
1209
    here = dwl1;
1204
    out8 (); outn ((long)DW_CFA_restore + dwarfreg[6]); /* %ebp */
1210
    out8 (); outn ((long)DW_CFA_restore + dwarfreg[6]); /* %ebp */
1205
	outsep (); outn ((long)DW_CFA_def_cfa);
1211
	outsep(); outn((long)DW_CFA_def_cfa);
1206
	outsep (); uleb128 ((unsigned long)dw_sp);
1212
	outsep(); uleb128((unsigned long)dw_sp);
1207
	outsep (); uleb128 ((unsigned long)0);	/* CFA is sp at entry point */
1213
	outsep (); uleb128 ((unsigned long)0);	/* CFA is sp at entry point */
1208
	d_outnl ();
1214
	d_outnl();
1209
  }
1215
  }
1210
  UNUSED (here);
1216
  UNUSED(here);
1211
}
1217
}
1212
 
1218
 
1213
void dw2_after_fde_exit
1219
void dw2_after_fde_exit
1214
    PROTO_N ( (here) )
-
 
1215
    PROTO_T ( long here )
1220
(long here)
1216
{
1221
{
1217
  out_dwf_label (here, 1);
1222
  out_dwf_label(here, 1);
1218
  enter_section ("debug_frame");
1223
  enter_section("debug_frame");
1219
  short_advance ((long)0, here);
1224
  short_advance((long)0, here);
1220
  out8 (); outn ((long)DW_CFA_restore_state); d_outnl ();
1225
  out8(); outn((long)DW_CFA_restore_state); d_outnl();
1221
  exit_section ();
1226
  exit_section();
1222
  return;
1227
  return;
1223
}
1228
}
1224
 
1229
 
1225
void dw2_track_push
1230
void dw2_track_push
1226
    PROTO_Z ()
1231
(void)
1227
{
1232
{
1228
  long here = set_dw_text_label ();
1233
  long here = set_dw_text_label();
1229
  enter_section ("debug_frame");
1234
  enter_section("debug_frame");
1230
  short_advance ((long)0, here);
1235
  short_advance((long)0, here);
1231
  out8 (); outn ((long)DW_CFA_DD_def_cfa_inc_offset); d_outnl ();
1236
  out8(); outn((long)DW_CFA_DD_def_cfa_inc_offset); d_outnl();
1232
  exit_section ();
1237
  exit_section();
1233
  return;
1238
  return;
1234
}
1239
}
1235
 
1240
 
1236
void dw2_track_pop
1241
void dw2_track_pop
1237
    PROTO_Z ()
1242
(void)
1238
{
1243
{
1239
  long here = set_dw_text_label ();
1244
  long here = set_dw_text_label();
1240
  enter_section ("debug_frame");
1245
  enter_section("debug_frame");
1241
  short_advance ((long)0, here);
1246
  short_advance((long)0, here);
1242
  out8 (); outn ((long)DW_CFA_DD_def_cfa_dec_offset); d_outnl ();
1247
  out8(); outn((long)DW_CFA_DD_def_cfa_dec_offset); d_outnl();
1243
  exit_section ();
1248
  exit_section();
1244
  return;
1249
  return;
1245
}
1250
}
1246
 
1251
 
1247
void dw2_track_sp
1252
void dw2_track_sp
1248
    PROTO_Z ()
1253
(void)
1249
{
1254
{
1250
  long here = set_dw_text_label ();
1255
  long here = set_dw_text_label();
1251
  enter_section ("debug_frame");
1256
  enter_section("debug_frame");
1252
  short_advance ((long)0, here);
1257
  short_advance((long)0, here);
1253
  out8 (); outn ((long)DW_CFA_DD_def_cfa_fixed_offset); d_outnl ();
1258
  out8(); outn((long)DW_CFA_DD_def_cfa_fixed_offset); d_outnl();
1254
  out32 (); outn ((long)((extra_stack - stack_dec) / 8));
1259
  out32(); outn((long)((extra_stack - stack_dec) / 8));
1255
    outs("+");
1260
    outs("+");
1256
    outs(local_prefix);
1261
    outs(local_prefix);
1257
    outs ("disp");
1262
    outs("disp");
1258
    outn ((long)crt_proc_id);
1263
    outn((long)crt_proc_id);
1259
  d_outnl ();
1264
  d_outnl();
1260
  exit_section ();
1265
  exit_section();
1261
  return;
1266
  return;
1262
}
1267
}
1263
 
1268
 
1264
 
1269
 
1265
void dw2_complete_fde
1270
void dw2_complete_fde
1266
    PROTO_Z ()
1271
(void)
1267
{
1272
{
1268
  out_dwf_label (proc_end, 1);
1273
  out_dwf_label(proc_end, 1);
1269
  enter_section ("debug_frame");
1274
  enter_section("debug_frame");
1270
  dot_align (PTR_SZ/8);
1275
  dot_align(PTR_SZ/8);
1271
  out_dwf_label (fde_end, 1);
1276
  out_dwf_label(fde_end, 1);
1272
  exit_section ();
1277
  exit_section();
1273
  return;
1278
  return;
1274
}
1279
}
1275
 
1280
 
1276
 
1281
 
1277
void dw2_start_extra_bit
1282
void dw2_start_extra_bit
1278
    PROTO_N ( (body) )
-
 
1279
    PROTO_T ( exp body )
1283
(exp body)
1280
{
1284
{
1281
  dg_info di = new_dg_info (DGA_EXTRA);
1285
  dg_info di = new_dg_info(DGA_EXTRA);
1282
  di->data.i_scope.start = next_dwarf_label();
1286
  di->data.i_scope.start = next_dwarf_label();
1283
  di->data.i_scope.end = next_dwarf_label();
1287
  di->data.i_scope.end = next_dwarf_label();
1284
  di->more = dgf(body);
1288
  di->more = dgf(body);
1285
  dgf(body) = di;
1289
  dgf(body) = di;
1286
  return;
1290
  return;
1287
}
1291
}
1288
 
1292
 
1289
void dw2_end_extra_bit
1293
void dw2_end_extra_bit
1290
    PROTO_N ( (body) )
-
 
1291
    PROTO_T ( exp body )
1294
(exp body)
1292
{
1295
{
1293
  UNUSED (body);
1296
  UNUSED(body);
1294
  return;
1297
  return;
1295
}
1298
}
1296
 
1299
 
1297
 
1300
 
1298
static exp lab_mark_list;
1301
static exp lab_mark_list;
1299
 
1302
 
1300
static void mark_lab
1303
static void mark_lab
1301
    PROTO_N ( (labst) )
-
 
1302
    PROTO_T ( exp labst )
1304
(exp labst)
1303
{
1305
{
1304
  if (!dg_labmark (labst)) {
1306
  if (!dg_labmark(labst)) {
1305
    set_dg_labmark (labst);
1307
    set_dg_labmark(labst);
1306
    if (son(son(labst)) != nilexp)
1308
    if (son(son(labst))!= nilexp)
1307
      failer ("strange labst");
1309
      failer("strange labst");
1308
    son(son(labst)) = lab_mark_list;
1310
    son(son(labst)) = lab_mark_list;
1309
    lab_mark_list = labst;
1311
    lab_mark_list = labst;
1310
  }
1312
  }
1311
  return;
1313
  return;
1312
}
1314
}
1313
 
1315
 
1314
static void trace_branch_aux
1316
static void trace_branch_aux
1315
    PROTO_N ( (whole, e) )
-
 
1316
    PROTO_T ( exp whole X exp e )
1317
(exp whole, exp e)
1317
{
1318
{
1318
  exp t;
1319
  exp t;
1319
  switch (name(e)) {
1320
  switch (name(e)) {
1320
    case test_tag:
1321
    case test_tag:
1321
    case goto_tag: {
1322
    case goto_tag: {
1322
      if (!intnl_to (whole, pt(e)))
1323
      if (!intnl_to(whole, pt(e)))
1323
	mark_lab (pt(e));
1324
	mark_lab(pt(e));
1324
      break;
1325
      break;
1325
    }
1326
    }
1326
    case case_tag: {
1327
    case case_tag: {
1327
      t = bro(son(e));
1328
      t = bro(son(e));
1328
      for (;;) {
1329
      for (;;) {
1329
	if (!intnl_to (whole, pt(t)))
1330
	if (!intnl_to(whole, pt(t)))
1330
	  mark_lab (pt(t));
1331
	  mark_lab(pt(t));
1331
	if (last(t)) break;
1332
	if (last(t))break;
1332
	t = bro(t);
1333
	t = bro(t);
1333
      }
1334
      }
1334
      break;
1335
      break;
1335
    }
1336
    }
1336
    case labst_tag: {
1337
    case labst_tag: {
1337
      t = final_dest(e);
1338
      t = final_dest(e);
1338
      if (!intnl_to (whole, t))
1339
      if (!intnl_to(whole, t))
1339
	mark_lab (t);
1340
	mark_lab(t);
1340
      break;
1341
      break;
1341
    }
1342
    }
1342
    case name_tag:
1343
    case name_tag:
1343
    case env_offset_tag:
1344
    case env_offset_tag:
1344
    case general_env_offset_tag:
1345
    case general_env_offset_tag:
1345
      return;
1346
      return;
1346
  }
1347
  }
1347
  t = son(e);
1348
  t = son(e);
1348
  if (t) {
1349
  if (t) {
1349
    for (;;) {
1350
    for (;;) {
1350
      trace_branch_aux (whole, t);
1351
      trace_branch_aux(whole, t);
1351
      if (last(t) || name(e) == case_tag) break;
1352
      if (last(t) || name(e) == case_tag)break;
1352
      t = bro(t);
1353
      t = bro(t);
1353
    }
1354
    }
1354
  }
1355
  }
1355
  return;
1356
  return;
1356
}
1357
}
1357
 
1358
 
1358
void trace_dw_branch_exits
1359
void trace_dw_branch_exits
1359
    PROTO_N ( (e) )
-
 
1360
    PROTO_T ( exp e )
1360
(exp e)
1361
{
1361
{
1362
  lab_mark_list = nilexp;
1362
  lab_mark_list = nilexp;
1363
  trace_branch_aux (e, e);
1363
  trace_branch_aux(e, e);
1364
  while (lab_mark_list) {
1364
  while (lab_mark_list) {
1365
    exp labst = lab_mark_list;
1365
    exp labst = lab_mark_list;
1366
    exp dest = final_dest(labst);
1366
    exp dest = final_dest(labst);
1367
    clear_dg_labmark (labst);
1367
    clear_dg_labmark(labst);
1368
    lab_mark_list = son(son(labst));
1368
    lab_mark_list = son(son(labst));
1369
    son(son(labst)) = nilexp;
1369
    son(son(labst)) = nilexp;
1370
    IGNORE dw_entry (dwe_break, (long)0);
1370
    IGNORE dw_entry(dwe_break,(long)0);
1371
    out32 (); out_code_label ((long)ptno(pt(son(dest)))); d_outnl ();
1371
    out32(); out_code_label((long)ptno(pt(son(dest)))); d_outnl();
1372
  }
1372
  }
1373
  return;
1373
  return;
1374
}
1374
}
1375
 
1375
 
1376
 
1376
 
1377
 
1377
 
1378
int dw_loc_equivalence
1378
int dw_loc_equivalence
1379
    PROTO_N ( (a, b) )
-
 
1380
    PROTO_T ( exp a X exp b )
1379
(exp a, exp b)
1381
{
1380
{
1382
  return eq_where_exp (a, b, 1, 0);
1381
  return eq_where_exp(a, b, 1, 0);
1383
}
1382
}
1384
 
1383
 
1385
typedef struct
1384
typedef struct
1386
{
1385
{
1387
  dg_name	nm;
1386
  dg_name	nm;
Line 1391... Line 1390...
1391
 
1390
 
1392
typedef struct
1391
typedef struct
1393
{
1392
{
1394
  dg_name	alloc;
1393
  dg_name	alloc;
1395
  void *	share_set;
1394
  void *	share_set;
1396
  dw_regassn	assn [2];
1395
  dw_regassn	assn[2];
1397
} dw_regdata;
1396
} dw_regdata;
1398
 
1397
 
1399
#define TRACKREGS no_fixed_regs
1398
#define TRACKREGS no_fixed_regs
1400
 
1399
 
1401
static dw_regdata regassns [TRACKREGS];
1400
static dw_regdata regassns[TRACKREGS];
1402
 
1401
 
1403
 
1402
 
1404
void dw_allocated
1403
void dw_allocated
1405
    PROTO_N ( (nm, id) )
-
 
1406
    PROTO_T ( dg_name nm X exp id )
1404
(dg_name nm, exp id)
1407
{
1405
{
1408
  int reg = no(id);
1406
  int reg = no(id);
1409
  if (!isglob(id) && ptno(id) == reg_pl && reg < TRACKREGS) {
1407
  if (!isglob(id) && ptno(id) == reg_pl && reg < TRACKREGS) {
1410
    dw_close_regassn (reg, 0);
1408
    dw_close_regassn(reg, 0);
1411
    dw_close_regassn (reg, 1);
1409
    dw_close_regassn(reg, 1);
1412
    regassns[reg].alloc = nm;
1410
    regassns[reg].alloc = nm;
1413
    regassns[reg].share_set = (void *)0;
1411
    regassns[reg].share_set = (void *)0;
1414
  }
1412
  }
1415
  return;
1413
  return;
1416
}
1414
}
1417
 
1415
 
1418
void dw_deallocated
1416
void dw_deallocated
1419
    PROTO_N ( (nm) )
-
 
1420
    PROTO_T ( dg_name nm )
1417
(dg_name nm)
1421
{
1418
{
1422
  int i;
1419
  int i;
1423
  for (i=0; i<TRACKREGS; i++) {
1420
  for (i=0; i<TRACKREGS; i++) {
1424
    if (regassns[i].alloc == nm) {
1421
    if (regassns[i].alloc == nm) {
1425
      dw_close_regassn (i, 0);
1422
      dw_close_regassn(i, 0);
1426
      dw_close_regassn (i, 1);
1423
      dw_close_regassn(i, 1);
1427
      regassns[i].alloc = (dg_name)0;
1424
      regassns[i].alloc = (dg_name)0;
1428
      regassns[i].share_set = (void *)0;
1425
      regassns[i].share_set = (void *)0;
1429
    }
1426
    }
1430
  }
1427
  }
1431
  return;
1428
  return;
1432
}
1429
}
1433
 
1430
 
1434
void dw_all_deallocated		/* initialisation */
1431
void dw_all_deallocated		/* initialisation */
1435
    PROTO_Z ()
1432
(void)
1436
{
1433
{
1437
  int i;
1434
  int i;
1438
  for (i=0; i<TRACKREGS; i++) {
1435
  for (i=0; i<TRACKREGS; i++) {
1439
    dw_regassn * a = &(regassns[i].assn[0]);
1436
    dw_regassn * a = & (regassns[i].assn[0]);
1440
    dw_regassn * b = &(regassns[i].assn[1]);
1437
    dw_regassn * b = & (regassns[i].assn[1]);
1441
    regassns[i].alloc = (dg_name)0;
1438
    regassns[i].alloc = (dg_name)0;
1442
    regassns[i].share_set = (void *)0;
1439
    regassns[i].share_set = (void *)0;
1443
    a->start = a->end = b->start = b->end = (long)0;
1440
    a->start = a->end = b->start = b->end = (long)0;
1444
  }
1441
  }
1445
  return;
1442
  return;
Line 1447... Line 1444...
1447
 
1444
 
1448
 
1445
 
1449
int dw_ignore_used_regassn = 0;
1446
int dw_ignore_used_regassn = 0;
1450
 
1447
 
1451
void dw_init_regassn
1448
void dw_init_regassn
1452
    PROTO_N ( (reg, x) )
-
 
1453
    PROTO_T ( int reg X int x )
1449
(int reg, int x)
1454
{
1450
{
1455
  if (reg < TRACKREGS) {
1451
  if (reg < TRACKREGS) {
1456
    dg_name nm = find_equiv_object ((!x ? crt_reg_record[reg].first_dest
1452
    dg_name nm = find_equiv_object((!x ? crt_reg_record[reg].first_dest
1457
				: crt_reg_record[reg].second_dest), 0);
1453
				: crt_reg_record[reg].second_dest), 0);
1458
    if (nm) {
1454
    if (nm) {
1459
      dw_regassn * a = &(regassns[reg].assn[x]);
1455
      dw_regassn * a = & (regassns[reg].assn[x]);
1460
      a->nm = nm;
1456
      a->nm = nm;
1461
      a->start = set_dw_text_label ();
1457
      a->start = set_dw_text_label();
1462
      a->end = (long)0;
1458
      a->end = (long)0;
1463
    }
1459
    }
1464
  }
1460
  }
1465
  return;
1461
  return;
1466
}
1462
}
1467
 
1463
 
1468
void dw_used_regassn
1464
void dw_used_regassn
1469
    PROTO_N ( (reg, x) )
-
 
1470
    PROTO_T ( int reg X int x )
1465
(int reg, int x)
1471
{
1466
{
1472
  if (reg < TRACKREGS && regassns[reg].assn[x].start)
1467
  if (reg < TRACKREGS && regassns[reg].assn[x].start)
1473
    regassns[reg].assn[x].end = set_dw_text_label ();
1468
    regassns[reg].assn[x].end = set_dw_text_label();
1474
  return;
1469
  return;
1475
}
1470
}
1476
 
1471
 
1477
void dw_close_regassn
1472
void dw_close_regassn
1478
    PROTO_N ( (reg, x) )
-
 
1479
    PROTO_T ( int reg X int x )
1473
(int reg, int x)
1480
{
1474
{
1481
  dw_regassn * a;
1475
  dw_regassn * a;
1482
  if (dw_ignore_used_regassn || reg >= TRACKREGS)
1476
  if (dw_ignore_used_regassn || reg >= TRACKREGS)
1483
    return;
1477
    return;
1484
  a = &(regassns[reg].assn[x]);
1478
  a = & (regassns[reg].assn[x]);
1485
  if (a->end) {
1479
  if (a->end) {
1486
    if (!regassns[reg].share_set) {
1480
    if (!regassns[reg].share_set) {
1487
      regassns[reg].share_set = (void *)
1481
      regassns[reg].share_set = (void *)
1488
		dw_new_regshare (regassns[reg].alloc, dwarfreg[reg]);
1482
		dw_new_regshare(regassns[reg].alloc, dwarfreg[reg]);
1489
    }
1483
    }
1490
    dw_add_regshare (regassns[reg].share_set, a->nm,
1484
    dw_add_regshare(regassns[reg].share_set, a->nm,
1491
		a->start, a->end);
1485
		a->start, a->end);
1492
    a->end = (long)0;
1486
    a->end = (long)0;
1493
    if (!regassns[reg].alloc && !regassns[reg].assn[1-x].start)
1487
    if (!regassns[reg].alloc && !regassns[reg].assn[1-x].start)
1494
      regassns[reg].share_set = (void *)0;
1488
      regassns[reg].share_set = (void *)0;
1495
  }
1489
  }