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