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
/* 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
 
7 7u83 76
void
77
dot_align(int n)
2 7u83 78
{
7 7u83 79
  if (freebsd_elf) {
80
    outs(".align ");
81
    outn((long)n);
82
    outnl();
2 7u83 83
    return;
7 7u83 84
  }
85
  if (n == 1) {
86
    return;
87
  }
2 7u83 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;
7 7u83 98
  }
99
  outn((long)n);
100
  outnl();
2 7u83 101
  return;
102
}
103
 
104
 
7 7u83 105
void
106
outbyte(void)
2 7u83 107
{
108
  outs(".byte ");
109
  return;
110
}
111
 
7 7u83 112
void
113
outshort(void)
2 7u83 114
{
115
  outs(".value ");
116
  return;
117
}
118
 
7 7u83 119
void
120
outlong(void)
2 7u83 121
{
122
  outs(".long ");
123
  return;
124
}
125
 
7 7u83 126
void
127
align_label(int f, exp jr)
2 7u83 128
{
7 7u83 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 */
2 7u83 143
      outs(".align 3,0x90");
7 7u83 144
    }
145
    if (f == 2) {	/* preceded by a jmp or ret */
2 7u83 146
      outs(".align 4,0x90");
7 7u83 147
    }
148
    if (f == 3) {
2 7u83 149
      outs(".align 2,0x90");
7 7u83 150
    }
2 7u83 151
    outs("\n");
7 7u83 152
  }
153
  if (is80586 && ptno(jr)!= last_jump_label) {
154
    if (f >= 1 && f <= 3) {
2 7u83 155
      outs(".align 2,0x90\n");
7 7u83 156
    }
157
  }
2 7u83 158
  return;
159
}
160
 
7 7u83 161
void
162
eval_postlude(char *s, exp c)
2 7u83 163
{
7 7u83 164
  UNUSED(s);
165
  UNUSED(c);
2 7u83 166
  return;
167
}
168
 
7 7u83 169
void
170
out_readonly_section(void)
2 7u83 171
{
7 7u83 172
  if (freebsd_elf) {
173
    outs(".section .rodata");
174
  } else {
175
    outs(".text");
176
  }
2 7u83 177
  return;
178
}
179
 
7 7u83 180
void
181
out_dot_comm(char *id, shape sha)
2 7u83 182
{
7 7u83 183
  outs(".comm ");
184
  outs(id);
185
  outs(",");
186
  outn((long)(((shape_size(sha) / 8) + 3) / 4) * 4);
187
  outnl();
2 7u83 188
  return;
189
}
190
 
7 7u83 191
void
192
out_dot_lcomm(char *id, shape sha)
2 7u83 193
{
7 7u83 194
  outs(".lcomm ");
195
  outs(id);
196
  outs(",");
197
  outn((long)(((shape_size(sha) / 8) + 3) / 4) * 4);
198
  outnl();
2 7u83 199
  return;
200
}
201
 
7 7u83 202
void
203
out_bss(char *id, shape sha)
2 7u83 204
{
7 7u83 205
  outs(".bss ");
206
  outs(id);
207
  outs(",");
208
  outn((long)(((shape_size(sha) / 8) + 3) / 4) * 4);
209
  outnl();
2 7u83 210
  return;
211
}
212
 
7 7u83 213
void
214
pic_prelude(void)
2 7u83 215
{
216
  return;
217
}
218
 
7 7u83 219
void
220
out_rename(char *oldid, char *newid)
2 7u83 221
{
7 7u83 222
  UNUSED(oldid);
223
  UNUSED(newid);
2 7u83 224
  return;
225
}
226
 
7 7u83 227
void
228
out_switch_jump(int tab, where a, int min)
2 7u83 229
{
7 7u83 230
  outs(" jmp *");
2 7u83 231
  outs(local_prefix);
232
  outn((long)tab);
233
  outs("-");
234
  outn((long)(4 * min));
7 7u83 235
  outs("(,");
236
  operand(32, a, 1, 0);
237
  outs(",4)");
238
  outnl();
2 7u83 239
  return;
240
}
241
 
7 7u83 242
void
243
out_switch_table(int tab, int min, int max, int *v, int absent)
2 7u83 244
{
245
  int i;
246
 
247
  dot_align(4);
248
  outnl();
249
 
250
  outs(local_prefix);
7 7u83 251
  outn((long)tab);
252
  outs(":");
253
  outnl();
2 7u83 254
 
255
  for (i = min; i <= max; ++i) {
7 7u83 256
    outs(".long ");
257
    if (v[i - min]!= -1) {
2 7u83 258
      outs(local_prefix);
7 7u83 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
      }
2 7u83 267
    }
7 7u83 268
    outnl();
269
  }
2 7u83 270
  outnl();
271
  return;
272
}
273
 
7 7u83 274
void
275
proc_size(char *s)
2 7u83 276
{
277
  outs(".align 4");
278
  outnl();
279
  outs(".size ");
280
  outs(s);
281
  outs(", .-");
282
  outs(s);
283
  outnl();
284
  return;
285
}
286
 
7 7u83 287
void
288
proc_type(char *s)
2 7u83 289
{
290
  outs(".type ");
291
  outs(s);
292
  outs(",@function");
293
  outnl();
294
  return;
295
}
296
 
7 7u83 297
void
298
outend(void)
2 7u83 299
{
7 7u83 300
  int st;
2 7u83 301
  outs(".text");
302
  outnl();
303
  dot_align(16);
304
  outnl();
305
  outs("___tdf_end:");
306
  outnl();
7 7u83 307
  st = fclose(fpout);
2 7u83 308
  if (st == EOF) {
7 7u83 309
    failer("failed to close file");
2 7u83 310
    exit(EXIT_FAILURE);
7 7u83 311
  }
2 7u83 312
}
313
 
7 7u83 314
void
315
outopenbr(void)
2 7u83 316
{
317
  return;
318
}
319
 
320
 
7 7u83 321
void
322
outclosebr(void)
2 7u83 323
{
324
  return;
325
}
326
 
7 7u83 327
void
328
outdivsym(void)
2 7u83 329
{
330
  outs("/");
331
  return;
332
}
333
 
7 7u83 334
void
335
out_initialiser(char *id)
2 7u83 336
{
7 7u83 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
  }
2 7u83 348
  return;
349
}
350
 
351
 
7 7u83 352
void
353
out_main_prelude(void)
2 7u83 354
{
7 7u83 355
  int nl1 = next_lab();
356
  int nl2 = next_lab();
2 7u83 357
  min_rfree |= 0x8;
7 7u83 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");
2 7u83 371
  return;
372
}
373
 
7 7u83 374
void
375
out_main_postlude(void)
2 7u83 376
{
7 7u83 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");
2 7u83 386
  out_initialiser(pdummy);
387
  return;
388
}