Subversion Repositories tendra.SVN

Rev

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