Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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