Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 113... Line 143...
113
#include "regmacs.h"
143
#include "regmacs.h"
114
#include "flags.h"
144
#include "flags.h"
115
#include "frames.h"
145
#include "frames.h"
116
 
146
 
117
extern char *proc_name;
147
extern char *proc_name;
118
extern int bitsin PROTO_S ((long));
148
extern int bitsin(long);
119
extern exp father PROTO_S ((exp));
149
extern exp father(exp);
120
extern int diagnose;
150
extern int diagnose;
121
extern int gdb;
151
extern int gdb;
122
 
152
 
123
bool Has_fp = 0;
153
bool Has_fp = 0;
124
bool Has_vsp = 0;
154
bool Has_vsp = 0;
Line 248... Line 278...
248
 
278
 
249
*/
279
*/
250
 
280
 
251
 
281
 
252
void setframe_flags
282
void setframe_flags
253
    PROTO_N ( (e,leaf) )
-
 
254
    PROTO_T ( exp e X bool leaf )
283
(exp e, bool leaf)
255
{
284
{
256
   /* e is a proc_tag */
285
   /* e is a proc_tag */
257
   unsigned char ne = name(e);
286
   unsigned char ne = name(e);
258
   Uses_crt_env = proc_uses_crt_env(e);
287
   Uses_crt_env = proc_uses_crt_env(e);
259
   No_S = ( !leaf && Uses_crt_env && proc_has_lv(e)
288
   No_S = (!leaf && Uses_crt_env && proc_has_lv(e)
260
		  && (ne!=general_proc_tag || !proc_has_nolongj(e)) );
289
		  && (ne!=general_proc_tag || !proc_has_nolongj(e)));
261
   Has_ll = procrecs[no(e)].Has_ll;
290
   Has_ll = procrecs[no(e)].Has_ll;
262
   Has_checkalloc = procrecs[no(e)].Has_checkalloc;
291
   Has_checkalloc = procrecs[no(e)].Has_checkalloc;
263
   Has_vsp = ( proc_has_alloca(e) || No_S || ne==general_proc_tag  );
292
   Has_vsp = (proc_has_alloca(e) || No_S || ne==general_proc_tag );
264
   Has_tos = ( No_S && proc_has_alloca(e) );
293
   Has_tos = (No_S && proc_has_alloca(e));
265
   Has_callees = ( ne==general_proc_tag );
294
   Has_callees = (ne==general_proc_tag);
266
   Has_vcallees = ( ne==general_proc_tag && proc_has_vcallees(e) );
295
   Has_vcallees = (ne==general_proc_tag && proc_has_vcallees(e));
267
   Has_no_vcallers = ( ne==proc_tag || !proc_has_vcallers(e) );
296
   Has_no_vcallers = (ne==proc_tag || !proc_has_vcallers(e));
268
   Has_fp = ( Has_vcallees || gdb );
297
   Has_fp = (Has_vcallees || gdb);
269
   /*  n.b. gdb, apparently, tracks all locals and parameters via +ve
298
   /*  n.b. gdb, apparently, tracks all locals and parameters via +ve
270
       offsets relative to a frame pointer = %r3. We comply by putting
299
       offsets relative to a frame pointer = %r3. We comply by putting
271
       Has_fp=1  */
300
       Has_fp=1  */
272
   is_PIC_and_calls = ( PIC_code && !leaf );
301
   is_PIC_and_calls = (PIC_code && !leaf);
273
 
302
 
274
#ifdef Try_No_S
303
#ifdef Try_No_S
275
   No_S = 1;
304
   No_S = 1;
276
#endif
305
#endif
277
#ifdef Try_Has_fp
306
#ifdef Try_Has_fp
Line 282... Line 311...
282
#endif
311
#endif
283
}
312
}
284
 
313
 
285
 
314
 
286
void set_up_frame
315
void set_up_frame
287
    PROTO_N ( (e) )
-
 
288
    PROTO_T ( exp e )
316
(exp e)
289
{
317
{
290
    procrec * pr = & procrecs[no(e)];
318
    procrec * pr = & procrecs[no(e)];
291
    needs * ndpr = & pr->needsproc;
319
    needs * ndpr = & pr->needsproc;
292
    spacereq *sppr = & pr->spacereqproc;
320
    spacereq *sppr = & pr->spacereqproc;
293
    long pprops = (ndpr->propsneeds);
321
    long pprops = (ndpr->propsneeds);
Line 329... Line 357...
329
    }
357
    }
330
 
358
 
331
    st+=(2<<5);       /* 2 words of temporary memory */
359
    st+=(2<<5);       /* 2 words of temporary memory */
332
    if (!simpleans)  /*  + 2 words in which to store address of long result */
360
    if (!simpleans)  /*  + 2 words in which to store address of long result */
333
    {
361
    {
334
       st+=(2<<5);
362
       st+= (2<<5);
335
    }
363
    }
336
    if (Has_tos)
364
    if (Has_tos)
337
    {
365
    {
338
       st+=(1<<5);  /*  + 1 word in which to store SP (reset at possible  */
366
       st+=(1<<5);  /*  + 1 word in which to store SP (reset at possible  */
339
    }              /*   long jump targets)                               */
367
    }              /*   long jump targets)                               */
340
 
368
 
341
    /*   HP PA reserved stack area. c.f. p 3-13 of HP PA reference manual */
369
    /*   HP PA reserved stack area. c.f. p 3-13 of HP PA reference manual */
342
    if (!leaf)
370
    if (!leaf)
343
    {
371
    {
344
       if (ma<(4<<5))
372
       if (ma< (4<<5))
345
	  ma = (4<<5);	 /* 4 words for parameter dump */
373
	  ma = (4<<5);	 /* 4 words for parameter dump */
346
       ma+=(8<<5);  	/*  + 8 word frame marker     */
374
       ma+=(8<<5);  	/*  + 8 word frame marker     */
347
    }
375
    }
348
 
376
 
349
    /* keep maxargs a multiple of 2 words to ease possible alloca inlining */
377
    /* keep maxargs a multiple of 2 words to ease possible alloca inlining */
Line 372... Line 400...
372
       }
400
       }
373
       else
401
       else
374
       {
402
       {
375
	  nos = bitsin(fixdump); /* = number of s regs used in body of proc */
403
	  nos = bitsin(fixdump); /* = number of s regs used in body of proc */
376
       }
404
       }
377
       st+=(nos<<5);
405
       st+= (nos<<5);
378
    }
406
    }
379
 
407
 
380
    if (!Has_vcallees)
408
    if (!Has_vcallees)
381
    {
409
    {
382
       /* adjust st so that ma + st + cs is a multiple of 16 words
410
       /* adjust st so that ma + st + cs is a multiple of 16 words
383
	* according to convention */
411
	* according to convention */
384
       st = ((ma+st+cs+511) & (~511)) - ma -cs ;
412
       st = ((ma+st+cs+511) & (~511)) - ma -cs;
385
    }
413
    }
386
 
414
 
387
    pr->locals_space = st;
415
    pr->locals_space = st;
388
    pr->frame_sz = ma + st + cs;
416
    pr->frame_sz = ma + st + cs;
389
    if (Has_vcallees)
417
    if (Has_vcallees)
390
    {
418
    {
391
       /* relative to FP */
419
       /* relative to FP */
392
       pr->params_offset = (8<<5);
420
       pr->params_offset = (8<<5);
393
       pr->callees_offset = -(18<<5);
421
       pr->callees_offset = - (18<<5);
394
    }
422
    }
395
    else
423
    else
396
    {
424
    {
397
       /* relative to EP */
425
       /* relative to EP */
398
       pr->params_offset = pr->frame_sz + (8<<5);
426
       pr->params_offset = pr->frame_sz + (8<<5);
399
       pr->callees_offset = pr->frame_sz - (18<<5);
427
       pr->callees_offset = pr->frame_sz - (18<<5);
400
    }
428
    }
401
    pr->leaf = leaf;
429
    pr->leaf = leaf;
402
    pr->max_args = ma;
430
    pr->max_args = ma;
403
 
431
 
404
    MEM_TEMP_BOFF.base = EP; MEM_TEMP_BOFF.offset = -(ma>>3)-(2<<2);
432
    MEM_TEMP_BOFF.base = EP; MEM_TEMP_BOFF.offset = - (ma>>3) - (2<<2);
405
    LONG_RESULT_BOFF.base = EP; LONG_RESULT_BOFF.offset = -(ma>>3)-(4<<2);
433
    LONG_RESULT_BOFF.base = EP; LONG_RESULT_BOFF.offset = - (ma>>3) - (4<<2);
406
    SP_BOFF.base = EP; SP_BOFF.offset = -(ma>>3)-(simpleans ? (3<<2) : (5<<2));
434
    SP_BOFF.base = EP; SP_BOFF.offset = - (ma>>3) - (simpleans ?(3<<2):(5<<2));
407
    FP_BOFF.base = EP; FP_BOFF.offset = -4;
435
    FP_BOFF.base = EP; FP_BOFF.offset = -4;
408
 
436
 
409
    stackerr_lab=0;
437
    stackerr_lab=0;
410
    aritherr_lab=0;
438
    aritherr_lab=0;
411
}
439
}
412
 
440
 
413
 
441
 
414
long frame_offset
442
long frame_offset
415
    PROTO_N ( (e) )
-
 
416
    PROTO_T ( exp e )
443
(exp e)
417
{
444
{
418
   exp p;
445
   exp p;
419
   procrec *pr;
446
   procrec *pr;
420
   int eo,lo,po,co;
447
   int eo,lo,po,co;
421
   for (p = father(e); (name(p)!=proc_tag && name(p)!=general_proc_tag);                              p = father(p));
448
   for (p = father(e);(name(p)!=proc_tag && name(p)!=general_proc_tag);                              p = father(p));
422
   pr = &procrecs[no(p)];
449
   pr = &procrecs[no(p)];
423
   lo = pr->locals_offset>>3;
450
   lo = pr->locals_offset>>3;
424
   po = pr->params_offset>>3;
451
   po = pr->params_offset>>3;
425
   co = pr->callees_offset>>3;
452
   co = pr->callees_offset>>3;
426
   if (isparam(e))
453
   if (isparam(e))
427
   {
454
   {
428
      int nse = no(son(e));
455
      int nse = no(son(e));
429
      if (name(son(e))==formal_callee_tag)
456
      if (name(son(e)) ==formal_callee_tag)
430
      {
457
      {
431
	 eo = -co+(nse>>3);
458
	 eo = -co+ (nse>>3);
432
      }
459
      }
433
      else
460
      else
434
      {
461
      {
435
	 eo = -po-(nse>>3);
462
	 eo = -po- (nse>>3);
436
      }
463
      }
437
   }
464
   }
438
   else
465
   else
439
   {
466
   {
440
      int  n = no(e);
467
      int  n = no(e);
441
      int  b = n & 0x3f;
468
      int  b = n & 0x3f;
442
      eo = -lo+((n-b)>>4);
469
      eo = -lo+ ((n-b) >>4);
443
   }
470
   }
444
   return eo;
471
   return eo;
445
}
472
}
446
 
473
 
447
 
474