Subversion Repositories tendra.SVN

Rev

Rev 6 | Details | Compare with Previous | 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
/* dragonfly/assembler.c */
62
 
63
#include "config.h"
64
#include "common_types.h"
65
#include "out.h"
66
#include "expmacs.h"
67
#include "operand.h"
68
#include "machine.h"
69
#include "localflags.h"
70
#include "basicread.h"
71
#include "coder.h"
72
 
73
 
74
/* PROCEDURES */
75
 
76
void
77
dot_align(int n)
78
{
79
  if (dragonfly_elf) {
80
    outs(".align ");
81
    outn((long)n);
82
    outnl();
83
    return;
84
  }
85
  if (n == 1)
86
    return;
87
  outs(".align ");
88
  switch (n) {
89
    case 16:
90
      n = 4;
91
      break;
92
    case 8:
93
      n = 3;
94
      break;
95
    case 4:
96
      n = 2;
97
      break;
98
    default:
99
      n = 1;
100
      break;
101
  }
102
  outn((long)n);
103
  outnl();
104
  return;
105
}
106
 
107
 
108
void
109
outbyte(void)
110
{
111
  outs(".byte ");
112
  return;
113
}
114
 
115
void
116
outshort(void)
117
{
118
  outs(".value ");
119
  return;
120
}
121
 
122
void
123
outlong(void)
124
{
125
  outs(".long ");
126
  return;
127
}
128
 
129
void
130
align_label(int f, exp jr)
131
{
132
  if (dragonfly_elf) {
133
    if (is80486 && !is80586 && ptno(jr) != last_jump_label) {
134
      /* repeat jump */
135
      if (f == 1) {
136
        outs(".align 4");
137
      }
138
      /* preceded by a jmp or ret */
139
      if (f == 2) {
140
        outs(".align 16");
141
      }
142
      outs("\n");
143
      return;
144
    }
145
  }
146
  if (is80486 && !is80586 && ptno(jr) != last_jump_label) {
147
    /* repeat jump */
148
    if (f == 1)	{
149
      outs(".align 3,0x90");
150
    }
151
    /* preceded by a jmp or ret */
152
    if (f == 2)	{
153
      outs(".align 4,0x90");
154
    }
155
    if (f == 3) {
156
      outs(".align 2,0x90");
157
    }
158
    outs("\n");
159
  }
160
  if (is80586 && ptno(jr) != last_jump_label) {
161
    if (f >= 1 && f <= 3) {
162
      outs(".align 2,0x90\n");
163
    }
164
  }
165
  return;
166
}
167
 
168
void
169
eval_postlude(char *s, exp c)
170
{
171
  UNUSED(s);
172
  UNUSED(c);
173
  return;
174
}
175
 
176
void
177
out_readonly_section(void)
178
{
179
  if (dragonfly_elf) {
180
    outs(".section .rodata");
181
  } else {
182
    outs(".text");
183
  }
184
  return;
185
}
186
 
187
void
188
out_dot_comm(char *id, shape sha)
189
{
190
  outs(".comm ");
191
  outs(id);
192
  outs(",");
193
  outn((long)(((shape_size(sha) / 8) + 3) / 4)* 4);
194
  outnl();
195
  return;
196
}
197
 
198
void
199
out_dot_lcomm(char *id, shape sha)
200
{
201
  outs(".lcomm ");
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_bss(char *id, shape sha)
211
{
212
  outs(".bss ");
213
  outs(id);
214
  outs(",");
215
  outn((long)(((shape_size(sha) / 8) + 3) / 4)* 4);
216
  outnl();
217
  return;
218
}
219
 
220
void
221
pic_prelude(void)
222
{
223
  return;
224
}
225
 
226
void
227
out_rename(char *oldid, char *newid)
228
{
229
  UNUSED(oldid);
230
  UNUSED(newid);
231
  return;
232
}
233
 
234
void
235
out_switch_jump(int tab, where a, int min)
236
{
237
  outs(" jmp *");
238
  outs(local_prefix);
239
  outn((long)tab);
240
  outs("-");
241
  outn((long)(4 * min));
242
  outs("(,");
243
  operand(32, a, 1, 0);
244
  outs(",4)");
245
  outnl();
246
  return;
247
}
248
 
249
void
250
out_switch_table(int tab, int min, int max, int *v, int absent)
251
{
252
  int i;
253
 
254
  dot_align(4);
255
  outnl();
256
 
257
  outs(local_prefix);
258
  outn((long)tab);
259
  outs(":");
260
  outnl();
261
 
262
  for (i = min; i <= max; ++i) {
263
    outs(".long ");
264
    if (v[i - min] != -1) {
265
      outs(local_prefix);
266
      outn((long)v[i - min]);
267
    }
268
    else {
269
      if (absent == -1) {
270
        outn((long)0);
271
      } else {
272
        outs(local_prefix);
273
        outn((long)absent);
274
      }
275
    }
276
    outnl();
277
  }
278
  outnl();
279
  return;
280
}
281
 
282
void
283
proc_size(char *s)
284
{
285
  outs(".align 4");
286
  outnl();
287
  outs(".size ");
288
  outs(s);
289
  outs(", .-");
290
  outs(s);
291
  outnl();
292
  return;
293
}
294
 
295
void
296
proc_type(char *s)
297
{
298
  outs(".type ");
299
  outs(s);
300
  outs(",@function");
301
  outnl();
302
  return;
303
}
304
 
305
void
306
outend(void)
307
{
308
  int st;
309
  outs(".text");
310
  outnl();
311
  dot_align(16);
312
  outnl();
313
  outs("___tdf_end:");
314
  outnl();
315
  st = fclose(fpout);
316
  if (st == EOF) {
317
    failer("failed to close file");
318
    exit(EXIT_FAILURE);
319
  }
320
}
321
 
322
void
323
outopenbr(void)
324
{
325
  return;
326
}
327
 
328
 
329
void
330
outclosebr(void)
331
{
332
  return;
333
}
334
 
335
void
336
outdivsym(void)
337
{
338
  outs("/");
339
  return;
340
}
341
 
342
void
343
out_initialiser(char *id)
344
{
345
  if (dragonfly_elf) {
346
    outs(".section .init");
347
    outnl();
348
    outs(" call ");
349
    outs(id);
350
  } else {
351
    outs(".stabs \"___TDFI_LIST__\",22,0,0,");
352
    outs(id);
353
    outnl();
354
    outnl();
355
  }
356
  return;
357
}
358
 
359
 
360
void
361
out_main_prelude(void) /* !dragonfly_elf */
362
{
363
  int nl1 = next_lab();
364
  int nl2 = next_lab();
365
  min_rfree |= 0x8;
366
  outs(" movl $___TDFI_LIST__+4, %ebx\n");
367
  outs(local_prefix);
368
  outn((long)nl1);
369
  outs(":\n");
370
  outs(" movl (%ebx),%eax\n");
371
  outs(" cmpl $0,%eax\n");
372
  simple_branch("je", nl2);
373
  outs(" call *%eax\n");
374
  outs(" addl $4,%ebx\n");
375
  simple_branch("jmp", nl1);
376
  outs(local_prefix);
377
  outn((long)nl2);
378
  outs(":\n");
379
  return;
380
}
381
 
382
void
383
out_main_postlude(void) /* !dragonfly_elf */
384
{
385
  char *sdummy = "Idummy";
386
  char *pdummy = (char *)xcalloc(((int)strlen(local_prefix) +
387
				  (int)strlen(sdummy) + 1), sizeof(char));
388
  strcpy(pdummy, local_prefix);
389
  strcat(pdummy, sdummy);
390
  outs(".text\n");
391
  outs(pdummy);
392
  outs(":\n");
393
  outs(" ret\n");
394
  out_initialiser(pdummy);
395
  return;
396
}