Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – //branches/tendra4/src/installers/hppa/common/frames.c – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
	(1) Its Recipients shall ensure that this Notice is
14
	reproduced upon any copies or amended versions of it;
15
 
16
	(2) Any amended version of it shall be clearly marked to
17
	show both the nature of and the organisation responsible
18
	for the relevant amendment or amendments;
19
 
20
	(3) Its onward transfer from a recipient to another
21
	party shall be deemed to be that party's acceptance of
22
	these conditions;
23
 
24
	(4) DERA gives no warranty or assurance as to its
25
	quality or suitability for any purpose and DERA accepts
26
	no liability whatsoever in relation to any use to which
27
	it may be put.
28
*/
29
 
30
 
31
/*
32
$Log: frames.c,v $
33
 * Revision 1.1.1.1  1998/01/17  15:56:02  release
34
 * First version to be checked into rolling release.
35
 *
36
 * Revision 1.6  1996/11/14  15:22:13  wfs
37
 *    Fixed a bug in regexps.c which was common to most of the installers and
38
 * has only just come to light due to PWE's work on powertrans. (There was
39
 * previously only a patch.) Cosmetic changes to other files.
40
 *
41
 * Revision 1.5  1996/10/24  15:51:14  wfs
42
 * Added "~alloc_size" special token. Minor change to alloca_tag - only need
43
 * one word for storage of pointer. Major change to round_tag (rounding to
44
 * unsigned chars) in the fix of avs bug.
45
 *
46
 * Revision 1.4  1996/09/06  10:38:19  wfs
47
 * bug fixes to "offset.pl" and cosmetic changes to the dynamic initialization
48
 * code.
49
 *
50
 * Revision 1.3  1996/09/05  11:05:08  wfs
51
 * "dynamic_init" boolean variable removed - must always be considered true.
52
 *
53
 * Revision 1.2  1995/12/18  13:11:19  wfs
54
 * Put hppatrans uder cvs control. Major Changes made since last release
55
 * include:
56
 * (i) PIC code generation.
57
 * (ii) Profiling.
58
 * (iii) Dynamic Initialization.
59
 * (iv) Debugging of Exception Handling and Diagnostics.
60
 *
61
 * Revision 5.5  1995/10/11  15:52:57  wfs
62
 * "Has_no_vcallers" was defined incorrectly.
63
 *
64
 * Revision 5.4  1995/10/09  13:04:27  wfs
65
 * Cosmetic changes.
66
 *
67
 * Revision 5.3  1995/09/15  14:47:07  wfs
68
 * Removed "#include "extra_expmacs.h"".
69
 *
70
 * Revision 5.2  1995/09/15  12:20:09  wfs
71
 * "extra_expmacs.h" included + minor variable name changes and
72
 * initializations.
73
 *
74
 * Revision 5.1  1995/09/07  15:41:49  wfs
75
 * Removed "extra_expmacs.h" include.
76
 *
77
 * Revision 5.0  1995/08/25  13:42:58  wfs
78
 * Preperation for August 25 Glue release
79
 *
80
 * Revision 3.4  1995/08/25  09:20:13  wfs
81
 * All the stuff (formerly in "proc.c") which set up the variables
82
 * for stack frames has been moved to frames.c. Substantial comments
83
 * have been added.
84
 *
85
 * Revision 3.4  1995/08/25  09:20:13  wfs
86
 * All the stuff (formerly in "proc.c") which set up the variables
87
 * for stack frames has been moved to frames.c. Substantial comments
88
 * have been added.
89
 *
90
 * Revision 3.1  95/04/10  16:26:26  16:26:26  wfs (William Simmonds)
91
 * Apr95 tape version.
92
 *
93
 * Revision 3.0  95/03/30  11:17:06  11:17:06  wfs (William Simmonds)
94
 * Mar95 tape version with CRCR95_178 bug fix.
95
 *
96
 * Revision 2.0  95/03/15  15:26:53  15:26:53  wfs (William Simmonds)
97
 * spec 3.1 changes implemented, tests outstanding.
98
 *
99
 * Revision 1.1  95/01/11  13:06:47  13:06:47  wfs (William Simmonds)
100
 * Initial revision
101
 *
102
*/
103
 
104
 
105
#include "config.h"
106
#include "bitsmacs.h"
107
#include "common_types.h"
108
#include "expmacs.h"
109
#include "procrec.h"
110
#include "tags.h"
111
#include "addrtypes.h"
112
#include "hppains.h"
113
#include "regmacs.h"
114
#include "flags.h"
115
#include "frames.h"
116
 
117
extern char *proc_name;
118
extern int bitsin PROTO_S ((long));
119
extern exp father PROTO_S ((exp));
120
extern int diagnose;
121
extern int gdb;
122
 
123
bool Has_fp = 0;
124
bool Has_vsp = 0;
125
bool Has_tos = 0;
126
bool No_S = 0;
127
bool Has_ll = 0;
128
bool Has_checkalloc = 0;
129
bool Has_callees = 0;
130
bool Has_vcallees = 0;
131
bool Has_no_vcallers = 0;
132
bool Uses_crt_env = 0;
133
bool is_PIC_and_calls = 0;
134
bool plusZ;
135
int fixdump = 0;
136
long callee_sz;
137
long callees_offset;
138
long locals_offset;
139
long max_args;
140
long params_offset;
141
long locals_space;
142
long frame_sz;
143
long stackerr_lab;
144
long aritherr_lab;
145
 
146
baseoff MEM_TEMP_BOFF;
147
baseoff LONG_RESULT_BOFF;
148
baseoff SP_BOFF;
149
baseoff FP_BOFF;
150
 
151
/*
152
	The purpose of this file (the 5th revision) is to collect together
153
     all the code which maintains the stack frame. Below is an illustration
154
     of the >>most general<< stack frame.
155
 
156
 
157
 
158
	|                                       |
159
	|---------------------------------------|<--SP
160
	|                                       |
161
	|                                       |
162
	|                                       |
163
	|                                       |
164
	|                                       |
165
	|                                       |
166
	|                                       |
167
	|         8 word "frame marker"         |
168
	|                                       |
169
	|                                       |
170
	|                                       |
171
	|                                       |
172
	|                                       |
173
	|                                       |
174
	|                                       |
175
	|---------------------------------------|
176
	|                                       |
177
	|                                       |
178
	|                                       |
179
	|        4 word "parameter dump"        |
180
	|                                       |
181
	|                                       |
182
	|                                       |
183
	|---------------------------------------|
184
	|                                       |
185
	:                                       :
186
	:          remaining arguments          :
187
	:                                       :
188
	|                                       |
189
	|---------------------------------------|
190
	|                                       |
191
	:                                       :
192
	:      dynamically allocated space      :
193
	:                                       :
194
	|                                       |
195
	|---------------------------------------|
196
	|                                       |
197
	|       2 words of temporary mem        |
198
	|                                       |
199
	|---------------------------------------|
200
	|                                       |
201
	|       2 words for long result         |
202
	|                                       |
203
	|---------------------------------------|
204
	|     1 word to keep track of SP        |
205
	|---------------------------------------|
206
	|                                       |
207
	:                                       :
208
	:                                       :
209
	:                                       :
210
	:            locals space               :
211
	:                                       :
212
	:                                       :
213
	:                                       :
214
	|                                       |
215
	|---------------------------------------|
216
	|                                       |
217
	:                                       :
218
	:                                       :
219
	:                                       :
220
	:            callees space              :
221
	:                                       :
222
	:                                       :
223
	:                                       :
224
	|                                       |
225
	|---------------------------------------|
226
	|        2 words for callee_sz          |
227
	|---------------------------------------|
228
	|                                       |
229
	:                                       :
230
	:  s reg save space (16 words maximum)  :
231
	:                                       :
232
	|                                       |
233
	|---------------------------------------|<--FP (=OLD SP)
234
	|                                       |
235
 
236
 
237
 
238
 
239
	   EP ("enviroment" pointer) is a copy of the SP before (if ever) SP
240
	is incremented to create dynamically allocated space.
241
	   The locals, the temporary memory, the long result words, and the
242
	stack copies of SP and FP (both reset at possible long jump
243
	targets) are all offset relative to EP. If Has_fp==0, then the
244
	parameters and the callees are also offset relative to EP,
245
	otherwise they are offset relative to FP. The callee_sz is stored
246
	on the stack only when Has_vcallees==1, and therefore Has_fp==1,
247
	and is offset relative to FP.
248
 
249
*/
250
 
251
 
252
void setframe_flags
253
    PROTO_N ( (e,leaf) )
254
    PROTO_T ( exp e X bool leaf )
255
{
256
   /* e is a proc_tag */
257
   unsigned char ne = name(e);
258
   Uses_crt_env = proc_uses_crt_env(e);
259
   No_S = ( !leaf && Uses_crt_env && proc_has_lv(e)
260
		  && (ne!=general_proc_tag || !proc_has_nolongj(e)) );
261
   Has_ll = procrecs[no(e)].Has_ll;
262
   Has_checkalloc = procrecs[no(e)].Has_checkalloc;
263
   Has_vsp = ( proc_has_alloca(e) || No_S || ne==general_proc_tag  );
264
   Has_tos = ( No_S && proc_has_alloca(e) );
265
   Has_callees = ( ne==general_proc_tag );
266
   Has_vcallees = ( ne==general_proc_tag && proc_has_vcallees(e) );
267
   Has_no_vcallers = ( ne==proc_tag || !proc_has_vcallers(e) );
268
   Has_fp = ( Has_vcallees || gdb );
269
   /*  n.b. gdb, apparently, tracks all locals and parameters via +ve
270
       offsets relative to a frame pointer = %r3. We comply by putting
271
       Has_fp=1  */
272
   is_PIC_and_calls = ( PIC_code && !leaf );
273
 
274
#ifdef Try_No_S
275
   No_S = 1;
276
#endif
277
#ifdef Try_Has_fp
278
   Has_fp = !leaf;
279
#endif
280
#ifdef Try_Has_tos
281
   Has_tos = 1;
282
#endif
283
}
284
 
285
 
286
void set_up_frame
287
    PROTO_N ( (e) )
288
    PROTO_T ( exp e )
289
{
290
    procrec * pr = & procrecs[no(e)];
291
    needs * ndpr = & pr->needsproc;
292
    spacereq *sppr = & pr->spacereqproc;
293
    long pprops = (ndpr->propsneeds);
294
    bool leaf = (pprops & anyproccall) == 0;
295
    long ma = ndpr->maxargs;   /* maxargs of proc body in bits  */
296
    long st = sppr->stack;    /*  space for locals in bits     */
297
    bool simpleans = (pprops & long_result_bit) == 0;
298
    int cs = pr->callee_sz;
299
 
300
    setframe_flags(e,leaf);
301
 
302
    if (No_S)
303
    {
304
       fixdump = -65536; /* dump all sregs */
305
    }
306
    else
307
    {
308
       fixdump = sppr->fixdump;
309
    }
310
    if (Has_fp) /* Has frame pointer */
311
    {
312
       /* reserved GR3 for use as frame pointer...     */
313
       fixdump|=(1<<FP) ; /* ...dump and restore FP  */
314
    }
315
    if (Has_vsp) /* Has variable stack pointer */
316
    {
317
       /* reserved GR4 for use as "enviroment pointer"...   */
318
       EP = GR4;
319
       fixdump|=(1<<EP) ; /* ...dump and restore EP    */
320
    }
321
    else
322
    {
323
       EP = SP;
324
    }
325
    if (is_PIC_and_calls)
326
    {
327
       /* reserved GR5 as a copy of GR19...             */
328
       fixdump|=(1<<GR5) ; /* ...dump and restore GR5  */
329
    }
330
 
331
    st+=(2<<5);       /* 2 words of temporary memory */
332
    if (!simpleans)  /*  + 2 words in which to store address of long result */
333
    {
334
       st+=(2<<5);
335
    }
336
    if (Has_tos)
337
    {
338
       st+=(1<<5);  /*  + 1 word in which to store SP (reset at possible  */
339
    }              /*   long jump targets)                               */
340
 
341
    /*   HP PA reserved stack area. c.f. p 3-13 of HP PA reference manual */
342
    if (!leaf)
343
    {
344
       if (ma<(4<<5))
345
	  ma = (4<<5);	 /* 4 words for parameter dump */
346
       ma+=(8<<5);  	/*  + 8 word frame marker     */
347
    }
348
 
349
    /* keep maxargs a multiple of 2 words to ease possible alloca inlining */
350
    ma = (ma+63) & ~63;
351
    /* keep st a multiple of 2 words */
352
    st = (st + 63) & ~63;
353
 
354
    pr->locals_offset = ma + st;  /* relative to EP */
355
 
356
    /*  Budget for sreg save area  */
357
    if (Has_callees)
358
    {
359
       st+=(18<<5); /* 2 words to keep a record of callee sz (2 words      */
360
		   /*  are allocated to guarentee the callees are double  */
361
		  /*   word aligned) + (maximum) 16 word register save   */
362
		 /*    area (because callers must know where to put     */
363
		/*     callees).                                       */
364
    }
365
    else
366
    {
367
       /* Can we be more economical? */
368
       int nos;
369
       if (No_S)
370
       {
371
	  nos = 16;
372
       }
373
       else
374
       {
375
	  nos = bitsin(fixdump); /* = number of s regs used in body of proc */
376
       }
377
       st+=(nos<<5);
378
    }
379
 
380
    if (!Has_vcallees)
381
    {
382
       /* adjust st so that ma + st + cs is a multiple of 16 words
383
	* according to convention */
384
       st = ((ma+st+cs+511) & (~511)) - ma -cs ;
385
    }
386
 
387
    pr->locals_space = st;
388
    pr->frame_sz = ma + st + cs;
389
    if (Has_vcallees)
390
    {
391
       /* relative to FP */
392
       pr->params_offset = (8<<5);
393
       pr->callees_offset = -(18<<5);
394
    }
395
    else
396
    {
397
       /* relative to EP */
398
       pr->params_offset = pr->frame_sz + (8<<5);
399
       pr->callees_offset = pr->frame_sz - (18<<5);
400
    }
401
    pr->leaf = leaf;
402
    pr->max_args = ma;
403
 
404
    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);
406
    SP_BOFF.base = EP; SP_BOFF.offset = -(ma>>3)-(simpleans ? (3<<2) : (5<<2));
407
    FP_BOFF.base = EP; FP_BOFF.offset = -4;
408
 
409
    stackerr_lab=0;
410
    aritherr_lab=0;
411
}
412
 
413
 
414
long frame_offset
415
    PROTO_N ( (e) )
416
    PROTO_T ( exp e )
417
{
418
   exp p;
419
   procrec *pr;
420
   int eo,lo,po,co;
421
   for (p = father(e); (name(p)!=proc_tag && name(p)!=general_proc_tag);                              p = father(p));
422
   pr = &procrecs[no(p)];
423
   lo = pr->locals_offset>>3;
424
   po = pr->params_offset>>3;
425
   co = pr->callees_offset>>3;
426
   if (isparam(e))
427
   {
428
      int nse = no(son(e));
429
      if (name(son(e))==formal_callee_tag)
430
      {
431
	 eo = -co+(nse>>3);
432
      }
433
      else
434
      {
435
	 eo = -po-(nse>>3);
436
      }
437
   }
438
   else
439
   {
440
      int  n = no(e);
441
      int  b = n & 0x3f;
442
      eo = -lo+((n-b)>>4);
443
   }
444
   return eo;
445
}
446
 
447
 
448
 
449
 
450
 
451