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 79... Line 109...
79
 
109
 
80
 
110
 
81
 
111
 
82
/* PROCEDURES */
112
/* PROCEDURES */
83
 
113
 
84
void outbyte
114
void
85
    PROTO_Z ()
115
outbyte(void)
86
{
116
{
87
  outs(".byte ");
117
  outs(".byte ");
88
  return;
118
  return;
89
}
119
}
90
 
120
 
91
void outshort
121
void
92
    PROTO_Z ()
122
outshort(void)
93
{
123
{
94
  outs(".2byte ");
124
  outs(".2byte ");
95
  return;
125
  return;
96
}
126
}
97
 
127
 
98
void outlong
128
void
99
    PROTO_Z ()
129
outlong(void)
100
{
130
{
101
  outs(".4byte ");
131
  outs(".4byte ");
102
  return;
132
  return;
103
}
133
}
104
 
134
 
105
void align_label
135
void
106
    PROTO_N ( (f, jr) )
-
 
107
    PROTO_T ( int f X exp jr )
136
align_label(int f, exp jr)
108
{
137
{
109
  if (is80486 && !is80586 && ptno(jr) != last_jump_label)  {
138
  if (is80486 && !is80586 && ptno(jr)!= last_jump_label) {
110
 
139
 
111
/* forward jump and continued into
140
/* forward jump and continued into
112
    if (f==0)
141
    if (f==0)
113
      outs(".align 16,7,1");
142
      outs(".align 16,7,1");
114
*/
143
*/
115
    if (f == 1)	/* repeat jump */
144
    if (f == 1) {	/* repeat jump */
116
      outs(".align 16,7,1");
-
 
117
    if (f == 2)	/* preceded by a jmp or ret */
-
 
118
      outs(".align 16,7,1");
145
      outs(".align 16,7,1");
-
 
146
    }
-
 
147
    if (f == 2) {	/* preceded by a jmp or ret */
-
 
148
      outs(".align 16,7,1");
-
 
149
    }
119
    if (f == 3)
150
    if (f == 3) {
120
      outs(".align 4");
151
      outs(".align 4");
-
 
152
    }
121
    outs("\n");
153
    outs("\n");
122
  };
154
  }
123
  if (is80586 && ptno(jr) != last_jump_label)  {
155
  if (is80586 && ptno(jr)!= last_jump_label) {
124
    if (f >= 1 && f <= 3)
156
    if (f >= 1 && f <= 3) {
125
      outs(".align 4\n");
157
      outs(".align 4\n");
-
 
158
    }
126
  };
159
  }
127
  return;
160
  return;
128
}
161
}
129
 
162
 
130
void eval_postlude
163
void
131
    PROTO_N ( (s, c) )
-
 
132
    PROTO_T ( char * s X exp c )
164
eval_postlude(char *s, exp c)
133
{
165
{
134
    outs(".size ");
166
    outs(".size ");
135
    outs (s);
167
    outs(s);
136
    outs (",");
168
    outs(",");
137
    outn((long)(shape_size(sh(c))+7)/8);
169
    outn((long)(shape_size(sh(c)) + 7) / 8);
138
    outnl();
170
    outnl();
139
    outs(".type ");
171
    outs(".type ");
140
    outs (s);
172
    outs(s);
141
    outs (",@object");
173
    outs(",@object");
142
    outnl();
174
    outnl();
143
    return;
175
    return;
144
}
176
}
145
 
177
 
-
 
178
void
146
void out_readonly_section
179
out_readonly_section(void)
-
 
180
{
-
 
181
  outs(".section .rodata");
147
    PROTO_Z ()
182
  return;
-
 
183
}
-
 
184
 
-
 
185
void
-
 
186
out_dot_comm(char *id, shape sha)
148
{
187
{
149
  outs (".section .rodata");
188
	outs(".comm ");
-
 
189
	outs(id);
-
 
190
	outs(",");
-
 
191
        outn((long)shape_size(sha) / 8);
-
 
192
	outs(",");
-
 
193
        if (is80486 && (name(sha) == realhd ||
-
 
194
            (name(sha) == nofhd && ptno(sha) == realhd) ||
-
 
195
	    shape_size(sha) >= 512)) {
-
 
196
                /* the pt field of an nof is used to hold the
-
 
197
		   shapemacs.h hd description of the shape and is set in
-
 
198
		   f_nof */
-
 
199
          outn((long)8);
-
 
200
	} else if (shape_align(sha) < 8) {	/* alignment of bitfields */
-
 
201
	  int nbytes = (shape_size(sha) + 7) / 8;
-
 
202
	  outn((long)((nbytes < 4) ? nbytes : 4));
-
 
203
	} else {
-
 
204
	  outn((long)shape_align(sha) / 8);
-
 
205
	}
-
 
206
 
-
 
207
	outnl();
150
  return;
208
  return;
151
}
209
}
152
 
210
 
153
void out_dot_comm
211
void
154
    PROTO_N ( (id, sha) )
-
 
155
    PROTO_T ( char * id X shape sha )
212
out_dot_lcomm(char *id, shape sha)
156
{
213
{
157
	outs (".comm ");
214
	outs(".lcomm ");
158
	outs (id);
215
	outs(id);
159
	outs (",");
216
	outs(",");
160
        outn((long)shape_size(sha)/ 8);
217
        outn((long)shape_size(sha) / 8);
161
	outs (",");
218
	outs(",");
162
        if (is80486 && (name(sha) == realhd ||
219
        if (is80486 && (name(sha) == realhd ||
163
             (name(sha) == nofhd && ptno(sha) == realhd) ||
220
            (name(sha) == nofhd && ptno(sha) == realhd) ||
164
		shape_size(sha) >= 512))
221
	    shape_size(sha) >= 512)) {
165
                /* the pt field of an nof is used to hold the
222
                /* the pt field of an nof is used to hold the
166
		   shapemacs.h hd description of the shape and is set in
223
		   shapemacs.h hd description of the shape and is set in
167
		   f_nof */
224
		   f_nof */
168
          outn((long)8);
225
          outn((long)8);
169
        else
-
 
170
	if (shape_align(sha)<8) {	/* alignment of bitfields */
226
	} else if (shape_align(sha) < 8) {	/* alignment of bitfields */
171
	  int nbytes = (shape_size(sha)+7)/8;
227
	  int nbytes = (shape_size(sha) + 7) / 8;
172
	  outn ((long)((nbytes<4) ? nbytes : 4));
228
	  outn((long)((nbytes < 4) ? nbytes : 4));
173
	}
-
 
174
	else
229
	} else {
175
	  outn((long)shape_align(sha)/8);
230
	  outn((long)shape_align(sha) /8);
176
 
-
 
177
	outnl ();
-
 
178
  return;
-
 
179
}
-
 
180
 
-
 
181
void out_dot_lcomm
-
 
182
    PROTO_N ( (id, sha) )
-
 
183
    PROTO_T ( char * id X shape sha )
-
 
184
{
-
 
185
	outs (".lcomm ");
-
 
186
	outs (id);
-
 
187
	outs (",");
-
 
188
        outn((long)shape_size(sha)/ 8);
-
 
189
	outs (",");
-
 
190
        if (is80486 && (name(sha) == realhd ||
-
 
191
             (name(sha) == nofhd && ptno(sha) == realhd) ||
-
 
192
		shape_size(sha) >= 512))
-
 
193
                /* the pt field of an nof is used to hold the
-
 
194
		   shapemacs.h hd description of the shape and is set in
-
 
195
		   f_nof */
-
 
196
          outn((long)8);
-
 
197
        else
-
 
198
	if (shape_align(sha)<8) {	/* alignment of bitfields */
-
 
199
	  int nbytes = (shape_size(sha)+7)/8;
-
 
200
	  outn ((long)((nbytes<4) ? nbytes : 4));
-
 
201
	}
231
	}
202
	else
-
 
203
	  outn((long)shape_align(sha)/8);
-
 
204
 
232
 
205
	outnl ();
233
	outnl();
206
  return;
234
  return;
207
}
235
}
208
 
236
 
209
void out_bss
237
void
210
    PROTO_N ( (id, sha) )
-
 
211
    PROTO_T ( char * id X shape sha )
238
out_bss(char *id, shape sha)
212
{
239
{
213
	outs (".bss ");
240
	outs(".bss ");
214
	outs (id);
241
	outs(id);
215
	outs (",");
242
	outs(",");
216
	outn ((long)((( shape_size(sha)/ 8) + 3) / 4) * 4);
243
	outn((long)(((shape_size(sha) / 8) + 3) / 4) * 4);
217
 
244
 
218
	outnl ();
245
	outnl();
219
  return;
246
  return;
220
}
247
}
221
 
248
 
222
static int pic_label;
249
static int pic_label;
223
 
250
 
224
void pic_prelude
251
void
225
    PROTO_Z ()
252
pic_prelude(void)
226
{
253
{
227
  int n = next_lab();
254
  int n = next_lab();
228
  pic_label = n;
255
  pic_label = n;
229
  outs(" call .L"); outn((long)n); outnl();
256
  outs(" call .L");
230
  outs(".L"); outn((long)n); outs(":"); outnl();
257
  outn((long)n);
-
 
258
  outnl();
-
 
259
  outs(".L");
-
 
260
  outn((long)n);
-
 
261
  outs(":");
-
 
262
  outnl();
231
  outs(" popl %ebx"); outnl();
263
  outs(" popl %ebx");
-
 
264
  outnl();
232
  outs(" addl $_GLOBAL_OFFSET_TABLE_+[.-.L"); outn((long)n); outs("],%ebx");
265
  outs(" addl $_GLOBAL_OFFSET_TABLE_+ [.-.L");
-
 
266
  outn((long)n);
-
 
267
  outs("],%ebx");
-
 
268
  outnl();
-
 
269
  return;
-
 
270
}
-
 
271
 
-
 
272
void
-
 
273
out_rename(char *oldid, char *newid)
-
 
274
{
-
 
275
  outs(".set ");
-
 
276
  outs(oldid);
-
 
277
  outs(",");
-
 
278
  outs(newid);
233
    outnl();
279
  outnl();
234
  return;
280
  return;
235
}
281
}
236
 
282
 
237
void out_rename
283
void
238
    PROTO_N ( (oldid, newid) )
-
 
239
    PROTO_T ( char * oldid X char * newid )
284
out_switch_jump(int tab, where a, int min)
240
{
285
{
241
  outs(".set "); outs(oldid); outs(","); outs(newid); outnl();
-
 
242
  return;
-
 
243
}
-
 
244
 
-
 
245
void out_switch_jump
-
 
246
    PROTO_N ( (tab, a, min) )
-
 
247
    PROTO_T ( int tab X where a X int min )
-
 
248
{
-
 
249
  if (PIC_code)  {
286
  if (PIC_code) {
250
    outs(" leal ");
287
    outs(" leal ");
251
    outs(local_prefix);
288
    outs(local_prefix);
252
    outn((long)tab);
289
    outn((long)tab);
253
    outs("@GOTOFF(%ebx,");
290
    outs("@GOTOFF(%ebx,");
254
    operand (32, a, 1, 0);
291
    operand(32, a, 1, 0);
255
    outs(",4),%eax");
292
    outs(",4),%eax");
256
    outnl();
293
    outnl();
257
    outs(" movl ");
294
    outs(" movl ");
258
    outs("-");
295
    outs("-");
259
    outn((long)(4 * min));
296
    outn((long)(4 * min));
260
    outs ("(%eax),%eax");
297
    outs("(%eax),%eax");
261
    outnl();
298
    outnl();
262
    outs(" addl %ebx,%eax");
299
    outs(" addl %ebx,%eax");
263
    outnl();
300
    outnl();
264
    outs(" subl $_GLOBAL_OFFSET_TABLE_+[.-.L"); outn((long)pic_label);
301
    outs(" subl $_GLOBAL_OFFSET_TABLE_+ [.-.L");
-
 
302
    outn((long)pic_label);
265
      outs("],%eax"); outnl();
303
    outs("],%eax");
-
 
304
    outnl();
266
    outs(" jmp *%eax");
305
    outs(" jmp *%eax");
267
    outnl();
306
    outnl();
268
    return;
307
    return;
269
    /* MODIFY FOR NEW CASE !!!!! */
308
    /* MODIFY FOR NEW CASE !!!!! */
270
  }
-
 
271
  else  {
309
  } else {
272
    outs (" jmp *");
310
    outs(" jmp *");
273
    outs(local_prefix);
311
    outs(local_prefix);
274
    outn((long)tab);
312
    outn((long)tab);
275
    outs("-");
313
    outs("-");
276
    outn((long)(4 * min));
314
    outn((long)(4 * min));
277
    outs ("(,");
315
    outs("(,");
278
    operand (32, a, 1, 0);
316
    operand(32, a, 1, 0);
279
    outs (",4)");
317
    outs(",4)");
280
    outnl ();
318
    outnl();
281
    return;
319
    return;
282
  };
320
  }
283
}
321
}
284
 
322
 
285
void out_switch_table
323
void
286
    PROTO_N ( (tab, min, max, v, absent) )
-
 
287
    PROTO_T ( int tab X int min X int max X int * v X int absent )
324
out_switch_table(int tab, int min, int max, int *v, int absent)
288
{
325
{
289
  int i;
326
  int i;
290
 
327
 
291
  if (PIC_code)  {
328
  if (PIC_code) {
292
    outs(".section .rodata");
329
    outs(".section .rodata");
293
    outnl();
330
    outnl();
294
    outs(".align 4");
331
    outs(".align 4");
295
    outnl();
332
    outnl();
296
 
333
 
297
    outs(local_prefix);
334
    outs(local_prefix);
298
    outn ((long)tab);
335
    outn((long)tab);
299
    outs (":");
336
    outs(":");
300
    outnl ();
337
    outnl();
301
 
338
 
302
    for (i = min; i <= max; ++i) {
339
    for (i = min; i <= max; ++i) {
303
      outs (".long ");
340
      outs(".long ");
304
      if (v[i - min] != -1)  {
341
      if (v[i - min]!= -1) {
305
        outs(local_prefix);
342
        outs(local_prefix);
306
        outn ((long)v[i - min]);
343
        outn((long)v[i - min]);
307
        outs("-");
344
        outs("-");
308
        outs(local_prefix);
345
        outs(local_prefix);
309
        outn((long)pic_label);
346
        outn((long)pic_label);
310
      }
-
 
311
      else  {
347
      } else {
312
	if (absent == -1)
348
	if (absent == -1) {
313
	  outn((long)0);
349
	  outn((long)0);
314
        else {
350
	} else {
315
          outs(local_prefix);
351
          outs(local_prefix);
316
          outn ((long)absent);
352
          outn((long)absent);
317
          outs("-");
353
          outs("-");
318
          outs(local_prefix);
354
          outs(local_prefix);
319
          outn((long)pic_label);
355
          outn((long)pic_label);
320
	};
356
	}
321
      };
357
      }
322
      outnl ();
358
      outnl();
323
    };
359
    }
324
    outs(".text");
360
    outs(".text");
325
    outnl();
361
    outnl();
326
    return;
362
    return;
327
  }
-
 
328
  else  {
363
  } else {
329
    outs(".section .rodata");
364
    outs(".section .rodata");
330
    outnl();
365
    outnl();
331
    outs(".align 4");
366
    outs(".align 4");
332
    outnl();
367
    outnl();
333
 
368
 
334
    outs(local_prefix);
369
    outs(local_prefix);
335
    outn ((long)tab);
370
    outn((long)tab);
336
    outs (":");
371
    outs(":");
337
    outnl ();
372
    outnl();
338
 
373
 
339
    for (i = min; i <= max; ++i) {
374
    for (i = min; i <= max; ++i) {
340
      outs (".long ");
375
      outs(".long ");
341
      if (v[i - min] != -1)  {
376
      if (v[i - min] != -1) {
342
        outs(local_prefix);
377
        outs(local_prefix);
343
        outn ((long)v[i - min]);
378
        outn((long)v[i - min]);
344
      }
-
 
345
      else  {
379
      } else {
346
	if (absent == -1)
380
	if (absent == -1) {
347
          outn ((long)0);
381
          outn((long)0);
348
	else {
382
	} else {
349
          outs(local_prefix);
383
          outs(local_prefix);
350
          outn ((long)absent);
384
          outn((long)absent);
351
	};
385
	}
352
      };
386
      }
353
      outnl ();
387
      outnl();
354
    };
388
    }
355
    outs(".text");
389
    outs(".text");
356
    outnl();
390
    outnl();
357
    return;
391
    return;
358
  };
392
  }
359
}
393
}
360
 
394
 
361
void proc_size
395
void
362
    PROTO_N ( (s) )
-
 
363
    PROTO_T ( char * s )
396
proc_size(char *s)
364
{
397
{
365
  outs(".align 16,7,4");
398
  outs(".align 16,7,4");
366
  outnl();
399
  outnl();
367
  outs(".size ");
400
  outs(".size ");
368
  outs(s);
401
  outs(s);
369
  outs(", .-");
402
  outs(", .-");
370
  outs(s);
403
  outs(s);
371
  outnl();
404
  outnl();
372
}
405
}
373
 
406
 
374
void proc_type
407
void
375
    PROTO_N ( (s) )
-
 
376
    PROTO_T ( char * s )
408
proc_type(char *s)
377
{
409
{
378
  outs(".type ");
410
  outs(".type ");
379
  outs(s);
411
  outs(s);
380
  outs(",@function");
412
  outs(",@function");
381
  outnl();
413
  outnl();
382
  return;
414
  return;
383
}
415
}
384
 
416
 
385
void dot_align
417
void
386
    PROTO_N ( (n) )
-
 
387
    PROTO_T ( int n )
418
dot_align(int n)
388
{
419
{
389
  outs(".align "); outn((long)n); outnl();
420
  outs(".align ");
-
 
421
  outn((long)n);
-
 
422
  outnl();
390
  return;
423
  return;
391
}
424
}
392
 
425
 
393
void outend
426
void
394
    PROTO_Z ()
427
outend(void)
-
 
428
{
395
{		/* close the output */
429
  /* close the output */
396
  int   st = fclose (fpout);
430
  int st = fclose(fpout);
397
  if (st == EOF) {
431
  if (st == EOF) {
398
    failer ("failed to close file");
432
    failer("failed to close file");
399
    exit(EXIT_FAILURE);
433
    exit(EXIT_FAILURE);
400
  };
434
  }
401
}
435
}
402
 
436
 
403
void outopenbr
437
void
404
    PROTO_Z ()
438
outopenbr(void)
405
{
439
{
406
  outs("[");
440
  outs("[");
407
  return;
441
  return;
408
}
442
}
409
 
443
 
410
 
444
 
411
void outclosebr
445
void
412
    PROTO_Z ()
446
outclosebr(void)
413
{
447
{
414
  outs("]");
448
  outs("]");
415
  return;
449
  return;
416
}
450
}
417
 
451
 
418
void outdivsym
452
void
419
    PROTO_Z ()
453
outdivsym(void)
420
{
454
{
421
  outs("\\/");
455
  outs("\\/");
422
  return;
456
  return;
423
}
457
}
424
 
458
 
425
void out_initialiser
459
void
426
    PROTO_N ( (id) )
-
 
427
    PROTO_T ( char* id )
460
out_initialiser(char *id)
428
{
461
{
429
  outs (".section .init\n");
462
  outs(".section .init\n");
430
  outs (" call ");
463
  outs(" call ");
431
  outs (id);
464
  outs(id);
432
  if (PIC_code)
465
  if (PIC_code) {
433
    outs ("@PLT");
466
    outs("@PLT");
-
 
467
  }
434
  outnl ();
468
  outnl();
435
  outnl ();
469
  outnl();
436
  return;
470
  return;
437
}
471
}
438
 
-
 
439
 
-