Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/* freebsd/assembler.c */
32
 
33
#include "config.h"
34
#include "common_types.h"
35
#include "out.h"
36
#include "expmacs.h"
37
#include "operand.h"
38
#include "machine.h"
39
#include "localflags.h"
40
#include "basicread.h"
41
#include "coder.h"
42
 
43
 
44
/* PROCEDURES */
45
 
46
void dot_align
47
    PROTO_N ( (n) )
48
    PROTO_T ( int n )
49
{
50
  if (n == 1)
51
    return;
52
  outs(".align ");
53
  switch (n) {
54
    case 16:
55
      n = 4; break;
56
    case 8:
57
      n = 3; break;
58
    case 4:
59
      n = 2; break;
60
    default:
61
      n = 1; break;
62
  };
63
  outn((long)n); outnl();
64
  return;
65
}
66
 
67
 
68
void outbyte
69
    PROTO_Z ()
70
{
71
  outs(".byte ");
72
  return;
73
}
74
 
75
void outshort
76
    PROTO_Z ()
77
{
78
  outs(".value ");
79
  return;
80
}
81
 
82
void outlong
83
    PROTO_Z ()
84
{
85
  outs(".long ");
86
  return;
87
}
88
 
89
void align_label
90
    PROTO_N ( (f, jr) )
91
    PROTO_T ( int f X exp jr )
92
{
93
  if (is80486 && !is80586 && ptno(jr) != last_jump_label) {
94
    if (f == 1)	/* repeat jump */
95
      outs(".align 3,0x90");
96
    if (f == 2)	/* preceded by a jmp or ret */
97
      outs(".align 4,0x90");
98
    if (f == 3)
99
      outs(".align 2,0x90");
100
    outs("\n");
101
  };
102
  if (is80586 && ptno(jr) != last_jump_label)  {
103
    if (f >= 1 && f <= 3)
104
      outs(".align 2,0x90\n");
105
  };
106
  return;
107
}
108
 
109
void eval_postlude
110
    PROTO_N ( (s, c) )
111
    PROTO_T ( char * s X exp c )
112
{
113
  UNUSED(s); UNUSED(c);
114
  return;
115
}
116
 
117
void out_readonly_section
118
    PROTO_Z ()
119
{
120
  outs (".text");
121
  return;
122
}
123
 
124
void out_dot_comm
125
    PROTO_N ( (id, sha) )
126
    PROTO_T ( char * id X shape sha )
127
{
128
  outs (".comm ");
129
  outs (id);
130
  outs (",");
131
  outn ((long)((( shape_size(sha)/ 8) + 3) / 4) * 4);
132
  outnl ();
133
  return;
134
}
135
 
136
void out_dot_lcomm
137
    PROTO_N ( (id, sha) )
138
    PROTO_T ( char * id X shape sha )
139
{
140
  outs (".lcomm ");
141
  outs (id);
142
  outs (",");
143
  outn ((long)((( shape_size(sha)/ 8) + 3) / 4) * 4);
144
  outnl ();
145
  return;
146
}
147
 
148
void out_bss
149
    PROTO_N ( (id, sha) )
150
    PROTO_T ( char * id X shape sha )
151
{
152
  outs (".bss ");
153
  outs (id);
154
  outs (",");
155
  outn ((long)((( shape_size(sha)/ 8) + 3) / 4) * 4);
156
  outnl ();
157
  return;
158
}
159
 
160
void pic_prelude
161
    PROTO_Z ()
162
{
163
  return;
164
}
165
 
166
void out_rename
167
    PROTO_N ( (oldid, newid) )
168
    PROTO_T ( char * oldid X char * newid )
169
{
170
  UNUSED(oldid); UNUSED(newid);
171
  return;
172
}
173
 
174
void out_switch_jump
175
    PROTO_N ( (tab, a, min) )
176
    PROTO_T ( int tab X where a X int min )
177
{
178
  outs (" jmp *");
179
  outs(local_prefix);
180
  outn((long)tab);
181
  outs("-");
182
  outn((long)(4 * min));
183
  outs ("(,");
184
  operand (32, a, 1, 0);
185
  outs (",4)");
186
  outnl ();
187
  return;
188
}
189
 
190
void out_switch_table
191
    PROTO_N ( (tab, min, max, v, absent) )
192
    PROTO_T ( int tab X int min X int max X int * v X int absent )
193
{
194
  int i;
195
 
196
  dot_align(4);
197
  outnl();
198
 
199
  outs(local_prefix);
200
  outn ((long)tab);
201
  outs (":");
202
  outnl ();
203
 
204
  for (i = min; i <= max; ++i) {
205
    outs (".long ");
206
    if (v[i - min] != -1)  {
207
      outs(local_prefix);
208
      outn ((long)v[i - min]);
209
    }
210
    else  {
211
      if (absent == -1)
212
        outn ((long)0);
213
      else {
214
        outs(local_prefix);
215
        outn ((long)absent);
216
      };
217
    };
218
    outnl ();
219
  };
220
  outnl();
221
  return;
222
}
223
 
224
void proc_size
225
    PROTO_N ( (s) )
226
    PROTO_T ( char * s )
227
{
228
  outs(".align 4");
229
  outnl();
230
  outs(".size ");
231
  outs(s);
232
  outs(", .-");
233
  outs(s);
234
  outnl();
235
  return;
236
}
237
 
238
void proc_type
239
    PROTO_N ( (s) )
240
    PROTO_T ( char * s )
241
{
242
  outs(".type ");
243
  outs(s);
244
  outs(",@function");
245
  outnl();
246
  return;
247
}
248
 
249
void outend
250
    PROTO_Z ()
251
{
252
  int   st;
253
  outs(".text");
254
  outnl();
255
  dot_align(16);
256
  outnl();
257
  outs("___tdf_end:");
258
  outnl();
259
  st = fclose (fpout);
260
  if (st == EOF) {
261
    failer ("failed to close file");
262
    exit(EXIT_FAILURE);
263
  };
264
}
265
 
266
void outopenbr
267
    PROTO_Z ()
268
{
269
  return;
270
}
271
 
272
 
273
void outclosebr
274
    PROTO_Z ()
275
{
276
  return;
277
}
278
 
279
void outdivsym
280
    PROTO_Z ()
281
{
282
  outs("/");
283
  return;
284
}
285
 
286
void out_initialiser
287
    PROTO_N ( (id) )
288
    PROTO_T ( char* id )
289
{
290
  outs(".stabs \"___TDFI_LIST__\",22,0,0,");
291
  outs (id);
292
  outnl ();
293
  outnl ();
294
  return;
295
}
296
 
297
 
298
void out_main_prelude
299
    PROTO_Z ()
300
{
301
  int nl1 = next_lab ();
302
  int nl2 = next_lab ();
303
  min_rfree |= 0x8;
304
  outs (" movl $___TDFI_LIST__+4, %ebx\n");
305
  outs (local_prefix);
306
  outn ((long)nl1);
307
  outs (":\n");
308
  outs (" movl (%ebx),%eax\n");
309
  outs (" cmpl $0,%eax\n");
310
  simple_branch ("je", nl2);
311
  outs (" call *%eax\n");
312
  outs (" addl $4,%ebx\n");
313
  simple_branch ("jmp", nl1);
314
  outs (local_prefix);
315
  outn ((long)nl2);
316
  outs (":\n");
317
  return;
318
}
319
 
320
void out_main_postlude
321
    PROTO_Z ()
322
{
323
  char * sdummy = "Idummy";
324
  char * pdummy = (char *) xcalloc (((int)strlen(local_prefix) +
325
				(int)strlen(sdummy) + 1), sizeof (char));
326
  strcpy (pdummy, local_prefix);
327
  strcat (pdummy, sdummy);
328
  outs (".text\n");
329
  outs (pdummy);
330
  outs (":\n");
331
  outs (" ret\n");
332
  out_initialiser(pdummy);
333
  return;
334
}