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