Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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