Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

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