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
/* svr4/assembler.c */
32
 
33
/**********************************************************************
34
$Author: release $
35
$Date: 1998/01/17 15:55:53 $
36
$Revision: 1.1.1.1 $
37
$Log: assembler.c,v $
38
 * Revision 1.1.1.1  1998/01/17  15:55:53  release
39
 * First version to be checked into rolling release.
40
 *
41
 * Revision 1.7  1997/03/24  12:43:46  pwe
42
 * outn int->long
43
 *
44
 * Revision 1.6  1995/10/23  17:34:52  pwe
45
 * dynamic initialisation PIC, and sco diags
46
 *
47
 * Revision 1.5  1995/10/09  15:14:48  pwe
48
 * dynamic initialisation etc
49
 *
50
 * Revision 1.4  1995/07/07  15:22:39  pwe
51
 * prepare for 4.0, and correct PIC switch
52
 *
53
 * Revision 1.3  1995/02/20  09:50:56  pwe
54
 * alignment of bitfield global data
55
 *
56
 * Revision 1.2  1995/01/30  12:57:39  pwe
57
 * Ownership -> PWE, tidy banners
58
 *
59
 * Revision 1.1  1994/10/27  12:16:59  jmf
60
 * Initial revision
61
 *
62
 * Revision 1.2  1994/07/13  07:51:05  jmf
63
 * Added Log
64
 *
65
**********************************************************************/
66
 
67
 
68
#include "config.h"
69
#include "common_types.h"
70
#include "out.h"
71
#include "expmacs.h"
72
#include "exp.h"
73
#include "localflags.h"
74
#include "shapemacs.h"
75
#include "operand.h"
76
#include "machine.h"
77
#include "flags.h"
78
#include "basicread.h"
79
 
80
 
81
 
82
/* PROCEDURES */
83
 
84
void outbyte
85
    PROTO_Z ()
86
{
87
  outs(".byte ");
88
  return;
89
}
90
 
91
void outshort
92
    PROTO_Z ()
93
{
94
  outs(".2byte ");
95
  return;
96
}
97
 
98
void outlong
99
    PROTO_Z ()
100
{
101
  outs(".4byte ");
102
  return;
103
}
104
 
105
void align_label
106
    PROTO_N ( (f, jr) )
107
    PROTO_T ( int f X exp jr )
108
{
109
  if (is80486 && !is80586 && ptno(jr) != last_jump_label)  {
110
 
111
/* forward jump and continued into
112
    if (f==0)
113
      outs(".align 16,7,1");
114
*/
115
    if (f == 1)	/* repeat jump */
116
      outs(".align 16,7,1");
117
    if (f == 2)	/* preceded by a jmp or ret */
118
      outs(".align 16,7,1");
119
    if (f == 3)
120
      outs(".align 4");
121
    outs("\n");
122
  };
123
  if (is80586 && ptno(jr) != last_jump_label)  {
124
    if (f >= 1 && f <= 3)
125
      outs(".align 4\n");
126
  };
127
  return;
128
}
129
 
130
void eval_postlude
131
    PROTO_N ( (s, c) )
132
    PROTO_T ( char * s X exp c )
133
{
134
    outs(".size ");
135
    outs (s);
136
    outs (",");
137
    outn((long)(shape_size(sh(c))+7)/8);
138
    outnl();
139
    outs(".type ");
140
    outs (s);
141
    outs (",@object");
142
    outnl();
143
    return;
144
}
145
 
146
void out_readonly_section
147
    PROTO_Z ()
148
{
149
  outs (".section .rodata");
150
  return;
151
}
152
 
153
void out_dot_comm
154
    PROTO_N ( (id, sha) )
155
    PROTO_T ( char * id X shape sha )
156
{
157
	outs (".comm ");
158
	outs (id);
159
	outs (",");
160
        outn((long)shape_size(sha)/ 8);
161
	outs (",");
162
        if (is80486 && (name(sha) == realhd ||
163
             (name(sha) == nofhd && ptno(sha) == realhd) ||
164
		shape_size(sha) >= 512))
165
                /* the pt field of an nof is used to hold the
166
		   shapemacs.h hd description of the shape and is set in
167
		   f_nof */
168
          outn((long)8);
169
        else
170
	if (shape_align(sha)<8) {	/* alignment of bitfields */
171
	  int nbytes = (shape_size(sha)+7)/8;
172
	  outn ((long)((nbytes<4) ? nbytes : 4));
173
	}
174
	else
175
	  outn((long)shape_align(sha)/8);
176
 
177
	outnl ();
178
  return;
179
}
180
 
181
void out_dot_lcomm
182
    PROTO_N ( (id, sha) )
183
    PROTO_T ( char * id X shape sha )
184
{
185
	outs (".lcomm ");
186
	outs (id);
187
	outs (",");
188
        outn((long)shape_size(sha)/ 8);
189
	outs (",");
190
        if (is80486 && (name(sha) == realhd ||
191
             (name(sha) == nofhd && ptno(sha) == realhd) ||
192
		shape_size(sha) >= 512))
193
                /* the pt field of an nof is used to hold the
194
		   shapemacs.h hd description of the shape and is set in
195
		   f_nof */
196
          outn((long)8);
197
        else
198
	if (shape_align(sha)<8) {	/* alignment of bitfields */
199
	  int nbytes = (shape_size(sha)+7)/8;
200
	  outn ((long)((nbytes<4) ? nbytes : 4));
201
	}
202
	else
203
	  outn((long)shape_align(sha)/8);
204
 
205
	outnl ();
206
  return;
207
}
208
 
209
void out_bss
210
    PROTO_N ( (id, sha) )
211
    PROTO_T ( char * id X shape sha )
212
{
213
	outs (".bss ");
214
	outs (id);
215
	outs (",");
216
	outn ((long)((( shape_size(sha)/ 8) + 3) / 4) * 4);
217
 
218
	outnl ();
219
  return;
220
}
221
 
222
static int pic_label;
223
 
224
void pic_prelude
225
    PROTO_Z ()
226
{
227
  int n = next_lab();
228
  pic_label = n;
229
  outs(" call .L"); outn((long)n); outnl();
230
  outs(".L"); outn((long)n); outs(":"); outnl();
231
  outs(" popl %ebx"); outnl();
232
  outs(" addl $_GLOBAL_OFFSET_TABLE_+[.-.L"); outn((long)n); outs("],%ebx");
233
    outnl();
234
  return;
235
}
236
 
237
void out_rename
238
    PROTO_N ( (oldid, newid) )
239
    PROTO_T ( char * oldid X char * newid )
240
{
241
  outs(".set "); outs(oldid); outs(","); outs(newid); outnl();
242
  return;
243
}
244
 
245
void out_switch_jump
246
    PROTO_N ( (tab, a, min) )
247
    PROTO_T ( int tab X where a X int min )
248
{
249
  if (PIC_code)  {
250
    outs(" leal ");
251
    outs(local_prefix);
252
    outn((long)tab);
253
    outs("@GOTOFF(%ebx,");
254
    operand (32, a, 1, 0);
255
    outs(",4),%eax");
256
    outnl();
257
    outs(" movl ");
258
    outs("-");
259
    outn((long)(4 * min));
260
    outs ("(%eax),%eax");
261
    outnl();
262
    outs(" addl %ebx,%eax");
263
    outnl();
264
    outs(" subl $_GLOBAL_OFFSET_TABLE_+[.-.L"); outn((long)pic_label);
265
      outs("],%eax"); outnl();
266
    outs(" jmp *%eax");
267
    outnl();
268
    return;
269
    /* MODIFY FOR NEW CASE !!!!! */
270
  }
271
  else  {
272
    outs (" jmp *");
273
    outs(local_prefix);
274
    outn((long)tab);
275
    outs("-");
276
    outn((long)(4 * min));
277
    outs ("(,");
278
    operand (32, a, 1, 0);
279
    outs (",4)");
280
    outnl ();
281
    return;
282
  };
283
}
284
 
285
void out_switch_table
286
    PROTO_N ( (tab, min, max, v, absent) )
287
    PROTO_T ( int tab X int min X int max X int * v X int absent )
288
{
289
  int i;
290
 
291
  if (PIC_code)  {
292
    outs(".section .rodata");
293
    outnl();
294
    outs(".align 4");
295
    outnl();
296
 
297
    outs(local_prefix);
298
    outn ((long)tab);
299
    outs (":");
300
    outnl ();
301
 
302
    for (i = min; i <= max; ++i) {
303
      outs (".long ");
304
      if (v[i - min] != -1)  {
305
        outs(local_prefix);
306
        outn ((long)v[i - min]);
307
        outs("-");
308
        outs(local_prefix);
309
        outn((long)pic_label);
310
      }
311
      else  {
312
	if (absent == -1)
313
	  outn((long)0);
314
        else {
315
          outs(local_prefix);
316
          outn ((long)absent);
317
          outs("-");
318
          outs(local_prefix);
319
          outn((long)pic_label);
320
	};
321
      };
322
      outnl ();
323
    };
324
    outs(".text");
325
    outnl();
326
    return;
327
  }
328
  else  {
329
    outs(".section .rodata");
330
    outnl();
331
    outs(".align 4");
332
    outnl();
333
 
334
    outs(local_prefix);
335
    outn ((long)tab);
336
    outs (":");
337
    outnl ();
338
 
339
    for (i = min; i <= max; ++i) {
340
      outs (".long ");
341
      if (v[i - min] != -1)  {
342
        outs(local_prefix);
343
        outn ((long)v[i - min]);
344
      }
345
      else  {
346
	if (absent == -1)
347
          outn ((long)0);
348
	else {
349
          outs(local_prefix);
350
          outn ((long)absent);
351
	};
352
      };
353
      outnl ();
354
    };
355
    outs(".text");
356
    outnl();
357
    return;
358
  };
359
}
360
 
361
void proc_size
362
    PROTO_N ( (s) )
363
    PROTO_T ( char * s )
364
{
365
  outs(".align 16,7,4");
366
  outnl();
367
  outs(".size ");
368
  outs(s);
369
  outs(", .-");
370
  outs(s);
371
  outnl();
372
}
373
 
374
void proc_type
375
    PROTO_N ( (s) )
376
    PROTO_T ( char * s )
377
{
378
  outs(".type ");
379
  outs(s);
380
  outs(",@function");
381
  outnl();
382
  return;
383
}
384
 
385
void dot_align
386
    PROTO_N ( (n) )
387
    PROTO_T ( int n )
388
{
389
  outs(".align "); outn((long)n); outnl();
390
  return;
391
}
392
 
393
void outend
394
    PROTO_Z ()
395
{		/* close the output */
396
  int   st = fclose (fpout);
397
  if (st == EOF) {
398
    failer ("failed to close file");
399
    exit(EXIT_FAILURE);
400
  };
401
}
402
 
403
void outopenbr
404
    PROTO_Z ()
405
{
406
  outs("[");
407
  return;
408
}
409
 
410
 
411
void outclosebr
412
    PROTO_Z ()
413
{
414
  outs("]");
415
  return;
416
}
417
 
418
void outdivsym
419
    PROTO_Z ()
420
{
421
  outs("\\/");
422
  return;
423
}
424
 
425
void out_initialiser
426
    PROTO_N ( (id) )
427
    PROTO_T ( char* id )
428
{
429
  outs (".section .init\n");
430
  outs (" call ");
431
  outs (id);
432
  if (PIC_code)
433
    outs ("@PLT");
434
  outnl ();
435
  outnl ();
436
  return;
437
}
438
 
439