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
/*
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
/* 	$Id: out_ba.c,v 1.1.1.1 1998/01/17 15:56:01 release Exp $	 */
32
 
33
#ifndef lint
34
static char vcid[] = "$Id: out_ba.c,v 1.1.1.1 1998/01/17 15:56:01 release Exp $";
35
#endif /* lint */
36
 
37
/*
38
   out_ba.c
39
 
40
   This file contains code to output a file of machine instructions
41
   in binary assembler format.
42
 
43
*/
44
 
45
/*
46
$Log: out_ba.c,v $
47
 * Revision 1.1.1.1  1998/01/17  15:56:01  release
48
 * First version to be checked into rolling release.
49
 *
50
 * Revision 1.7  1995/09/06  09:01:10  john
51
 * removed old command line argument parsing
52
 *
53
 * Revision 1.6  1995/06/28  10:26:00  john
54
 * Some reformatting
55
 *
56
 * Revision 1.5  1995/05/23  13:24:02  john
57
 * Change for 64 bit support
58
 *
59
 * Revision 1.4  1995/04/10  14:13:27  john
60
 * Minor changes
61
 *
62
 * Revision 1.3  1995/04/07  11:05:10  john
63
 * Fixed assembler output.
64
 *
65
 * Revision 1.2  1995/03/29  14:07:58  john
66
 * Changed strings.h to string.h
67
 *
68
 * Revision 1.1.1.1  1995/03/23  10:39:32  john
69
 * Entered into CVS
70
 *
71
 * Revision 1.5  1995/03/23  10:09:21  john
72
 * Added support for scheduler
73
 *
74
 * Revision 1.4  1995/01/26  13:46:39  john
75
 * Removed unused variable
76
 *
77
*/
78
 
79
 
80
#include "config.h"
81
#include "ibinasm.h"
82
#include "main.h"
83
#include "out_ba.h"
84
#include "xalloc.h"
85
extern  FILE * ba_file;
86
 
87
static  binasm ba;
88
 
89
#define  OUT out_one(ba.data)
90
#define C(x)  ba.x.symno = symno; ba.x.fill0a =0;ba.x.asmtype = asmtype                 
91
 
92
/*
93
   output one binasm record and return a copy of the output.
94
*/
95
char * out_one
96
    PROTO_N ( ( d ) )
97
    PROTO_T ( char *d )
98
{
99
#if DO_SCHEDULE
100
  char * res = (char*)xcalloc(binasm_record_length,sizeof(char));
101
#endif
102
  int   i;
103
  for (i = 0; i < binasm_record_length; i++) {
104
#if DO_SCHEDULE
105
    res[i] = d[i];
106
#else
107
    putc (d[i], ba_file);
108
#endif
109
    d[i] = 0;
110
  }
111
#if DO_SCHEDULE
112
  return res;
113
#endif
114
  return (char*)NULL;
115
}
116
 
117
 
118
/*
119
   output string as set of binasm records
120
*/
121
char * out_data
122
    PROTO_N ( ( s,size ) )
123
    PROTO_T ( char *s X int size )
124
{
125
 
126
  int i;
127
  int j = ((size+binasm_record_length-1)/binasm_record_length)
128
    *binasm_record_length;
129
#if DO_SCHEDULE
130
  char * res = (char*)xcalloc(j,sizeof(char));
131
#else
132
  char *res = (char*)NULL;
133
#endif
134
 
135
  for (i = 0; i < size; i++) {
136
#if DO_SCHEDULE
137
    res[i] = s[i];
138
#else   
139
    putc (s[i], ba_file);
140
#endif
141
  }
142
  for (i = size; i < j; i++)
143
#if DO_SCHEDULE
144
    res[i] = ' ';
145
#else 
146
  putc (' ', ba_file);
147
#endif
148
  return res;
149
}
150
 
151
 
152
char * out_common
153
    PROTO_N ( ( symno, asmtype ) )
154
    PROTO_T ( asmsym symno X unsigned asmtype )
155
{
156
  /* things like label settings */
157
  C (common);
158
  return OUT;
159
}	
160
 
161
 
162
/*
163
   output enter binasm record
164
*/
165
char * out_ent
166
    PROTO_N ( ( symno, asmtype, lexlev ) )
167
    PROTO_T ( asmsym symno X unsigned asmtype X unsigned lexlev )
168
{
169
  C (ent);
170
  ba.ent.lexlev = lexlev;
171
  return OUT;
172
}
173
 
174
 
175
/*
176
   output frame binasm record
177
*/
178
char * out_frame
179
    PROTO_N ( ( symno,asmtype,frameoffset,framereg,pcreg ) )
180
    PROTO_T ( asmsym symno X unsigned asmtype X asmint frameoffset X asmreg framereg X asmreg pcreg )
181
{
182
  C (frame);
183
  ba.frame.frameoffset = frameoffset;
184
  ba.frame.framereg = framereg;
185
  ba.frame.pcreg = pcreg;
186
  return OUT;
187
}
188
 
189
 
190
 
191
/*
192
   output mask binasm record
193
*/
194
char * out_mask
195
    PROTO_N ( ( symno,asmtype,regmask,regoffset ) )
196
    PROTO_T ( asmsym symno X unsigned asmtype X unsigned regmask X asmint regoffset )
197
{
198
  C (mask);
199
  ba.mask.regmask = regmask;
200
  ba.mask.regoffset = regoffset;
201
  return OUT;
202
}
203
 
204
 
205
/*
206
   output version stamp binasm record
207
*/
208
char * out_verstamp
209
    PROTO_N ( ( majornumber, minornumber ) )
210
    PROTO_T ( int majornumber X int minornumber )
211
{
212
  ba.verstamp.symno = 0;
213
  ba.verstamp.fill0a = 0;
214
  ba.verstamp.asmtype = iverstamp;
215
  ba.verstamp.majornumber = majornumber;
216
  ba.verstamp.minornumber = minornumber;
217
  return OUT;
218
}
219
 
220
 
221
/*
222
   output line-no binasm record
223
*/
224
void out_loc
225
    PROTO_N ( ( filenumber, linenumber ) )
226
    PROTO_T ( int filenumber X unsigned linenumber )
227
{
228
  ba.loc.symno = 0;
229
  ba.loc.fill0a = 0;
230
  ba.loc.asmtype = iloc;
231
  ba.loc.filenumber = (filenumber<0)?2:filenumber;
232
  ba.loc.linenumber = linenumber;
233
  OUT;
234
#if !DO_SCHEDULE
235
  fflush (ba_file);
236
#endif
237
}
238
 
239
 
240
/*
241
   output some data directive binasm record
242
*/
243
char *out_chars
244
    PROTO_N ( ( symno,asmtype,expression,repeat ) )
245
    PROTO_T ( asmsym symno X unsigned asmtype X asmint expression X unsigned short repeat )
246
{
247
  C (value);
248
  ba.value.expression = expression;
249
  ba.value.repeat = repeat;
250
  return OUT;
251
}
252
 
253
 
254
 
255
/*
256
   output option binasm record
257
*/
258
char * out_option
259
    PROTO_N ( ( optype, opint ) )
260
    PROTO_T ( int optype X int opint )
261
{
262
 
263
  ba.voption.symno = 0;
264
  ba.voption.fill0a = 0;
265
  ba.voption.asmtype = ioption;
266
  ba.voption.option = optype;
267
  ba.voption.opt_int_value = opint;
268
  return OUT;
269
}
270
 
271
 
272
/*
273
   output some data directive binasm record
274
*/
275
char * out_value
276
    PROTO_N ( ( symno,asmtype,expression,repeat ) )
277
    PROTO_T ( asmsym symno X unsigned asmtype X INT64 expression X unsigned int repeat )
278
{
279
  C (value);
280
  ba.value.expression = expression;
281
  /*ba.value.repeat = (repeat>0xffff)?0xffff:repeat;*/
282
  ba.value.repeat = repeat;
283
  return OUT;
284
  /*if (repeat>0xffff) out_value(symno, asmtype, expression, repeat-0xffff);*/
285
}
286
 
287
 
288
 
289
/*
290
   output alias binasm record
291
*/
292
void out_alias
293
    PROTO_N ( ( symno,asmtype,basereg1,basereg2 ) )
294
    PROTO_T ( asmsym symno X unsigned asmtype X asmreg basereg1 X asmreg basereg2 )
295
{
296
 
297
  C (alias);
298
  ba.alias.basereg1 = basereg1;
299
  ba.alias.basereg2 = basereg2;
300
  OUT;
301
}
302
 
303
 
304
 
305
/*
306
   output binasm for instruction with no
307
   immediate operand
308
*/
309
char * out_rinst
310
    PROTO_N ( ( symno,opcode,reg1,reg2,form,reg3 ) )
311
    PROTO_T ( asmsym symno X int opcode X asmreg reg1 X asmreg reg2 X asmformat form X asmreg reg3 )
312
{
313
  ba.rinst.symno = symno;
314
  ba.rinst.asmtype = iocode;
315
  ba.rinst.fill0a = 0;
316
  ba.rinst.fill03 = 0;
317
  ba.rinst.op = opcode;
318
  ba.rinst.reg1 = reg1;
319
  ba.rinst.reg2 = reg2;
320
  ba.rinst.form = form;
321
  ba.rinst.reg3 = reg3;
322
  return OUT;
323
}
324
 
325
 
326
/*
327
   output binasm for instruction with immediate operand
328
*/
329
 
330
char * out_iinst
331
    PROTO_N ( ( symno,opcode,reg1,reg2,form,mem_tag,immediate ) )
332
    PROTO_T ( asmsym symno X int opcode X asmreg reg1 X asmreg reg2 X asmformat form X unsigned int mem_tag X int immediate )
333
{
334
  ba.iinst.symno = symno;
335
  ba.iinst.asmtype = iocode;
336
  ba.iinst.fill0a = 0;
337
  ba.iinst.fill03 = 0;
338
  ba.iinst.op = opcode;
339
  ba.iinst.reg1 = reg1;
340
  ba.iinst.reg2 = reg2;
341
  ba.iinst.mem_tag = mem_tag;
342
  ba.iinst.form = form;
343
  ba.iinst.immediate = immediate;
344
  return OUT;
345
}
346
 
347
char * out_biinst
348
    PROTO_N ( ( symno,opcode,reg1,reg2,form,mem_tag,immediate ) )
349
    PROTO_T ( asmsym symno X int opcode X asmreg reg1 X asmreg reg2 X asmformat form X unsigned int mem_tag X INT64 immediate )
350
{
351
  ba.iinst.symno = symno;
352
  ba.iinst.asmtype = iocode;
353
  ba.iinst.fill0a = 0;
354
  ba.iinst.fill03 = 0;
355
  ba.iinst.op = opcode;
356
  ba.iinst.reg1 = reg1;
357
  ba.iinst.reg2 = reg2;
358
  ba.iinst.mem_tag = mem_tag;
359
  ba.iinst.form = form;
360
  ba.iinst.immediate = immediate;
361
  return OUT;
362
}
363
 
364
 
365
/*
366
 
367
*/
368
 
369
char * out_linst
370
    PROTO_N ( ( symno,opcode,reg1,reg2,form,imm ) )
371
    PROTO_T ( asmsym symno X int opcode X asmreg reg1 X asmreg reg2 X asmformat form X asmint imm )
372
{
373
  ba.linst.symno = symno;
374
  ba.linst.asmtype = iocode;
375
  ba.linst.fill0a = 0;
376
  ba.linst.fill03 = 0 ;
377
  ba.linst.op = opcode;
378
  ba.linst.reg1 = reg1;
379
  ba.linst.reg2 = reg2;
380
  ba.linst.form = form;
381
  ba.linst.imm = imm;
382
  return OUT;
383
}
384
 
385
 
386
 
387
 
388
 
389
 
390
 
391