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