Subversion Repositories tendra.SVN

Rev

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

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