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
    Copyright (c) 1993 Open Software Foundation, Inc.
32
    Copyright (c) 1993 Open Software Foundation, Inc.
3
 
33
 
4
 
34
 
5
    All Rights Reserved
35
    All Rights Reserved
Line 24... Line 54...
24
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
*/
55
*/
26
 
56
 
27
/*
57
/*
28
    		 Crown Copyright (c) 1997
58
    		 Crown Copyright (c) 1997
29
    
59
 
30
    This TenDRA(r) Computer Program is subject to Copyright
60
    This TenDRA(r) Computer Program is subject to Copyright
31
    owned by the United Kingdom Secretary of State for Defence
61
    owned by the United Kingdom Secretary of State for Defence
32
    acting through the Defence Evaluation and Research Agency
62
    acting through the Defence Evaluation and Research Agency
33
    (DERA).  It is made available to Recipients with a
63
    (DERA).  It is made available to Recipients with a
34
    royalty-free licence for its use, reproduction, transfer
64
    royalty-free licence for its use, reproduction, transfer
35
    to other parties and amendment for any purpose not excluding
65
    to other parties and amendment for any purpose not excluding
36
    product development provided that any such use et cetera
66
    product development provided that any such use et cetera
37
    shall be deemed to be acceptance of the following conditions:-
67
    shall be deemed to be acceptance of the following conditions:-
38
    
68
 
39
        (1) Its Recipients shall ensure that this Notice is
69
        (1) Its Recipients shall ensure that this Notice is
40
        reproduced upon any copies or amended versions of it;
70
        reproduced upon any copies or amended versions of it;
41
    
71
 
42
        (2) Any amended version of it shall be clearly marked to
72
        (2) Any amended version of it shall be clearly marked to
43
        show both the nature of and the organisation responsible
73
        show both the nature of and the organisation responsible
44
        for the relevant amendment or amendments;
74
        for the relevant amendment or amendments;
45
    
75
 
46
        (3) Its onward transfer from a recipient to another
76
        (3) Its onward transfer from a recipient to another
47
        party shall be deemed to be that party's acceptance of
77
        party shall be deemed to be that party's acceptance of
48
        these conditions;
78
        these conditions;
49
    
79
 
50
        (4) DERA gives no warranty or assurance as to its
80
        (4) DERA gives no warranty or assurance as to its
51
        quality or suitability for any purpose and DERA accepts
81
        quality or suitability for any purpose and DERA accepts
52
        no liability whatsoever in relation to any use to which
82
        no liability whatsoever in relation to any use to which
53
        it may be put.
83
        it may be put.
54
*/
84
*/
Line 83... Line 113...
83
******************************************************************/
113
******************************************************************/
84
 
114
 
85
#include "config.h"
115
#include "config.h"
86
#include "geninst.h"
116
#include "geninst.h"
87
 
117
 
88
#include "proc.h"		
118
#include "proc.h"
89
#include "myassert.h"
119
#include "myassert.h"
90
#include "flags.h"
120
#include "flags.h"
91
#include "comment.h"
121
#include "comment.h"
92
#include "translat.h"
122
#include "translat.h"
93
#include "maxminmacs.h"		/* for absval() */
123
#include "maxminmacs.h"		/* for absval() */
94
#include "stack.h"
124
#include "stack.h"
95
#include "inst_fmt.h"
125
#include "inst_fmt.h"
96
#include "macro.h"
126
#include "macro.h"
97
#include "mask.h"
127
#include "mask.h"
98
#define IS_POW2(c)		((c) != 0 && ((c) & ((c)-1)) == 0)
128
#define IS_POW2(c)		((c)!= 0 && ((c) & ((c) -1)) == 0)
99
 
129
 
100
#define CHECKREG(r)		ASSERT(IS_FIXREG(r) && (!IS_SREG(r) || (r) >= p_sreg_first_save || (r == R_FP)) );
130
#define CHECKREG(r)		ASSERT(IS_FIXREG(r) && (!IS_SREG(r) || (r) >= p_sreg_first_save || (r == R_FP)));
101
#define CHECKFREG(r)		ASSERT((!IS_FLT_SREG(r) || (r) >= p_sfreg_first_save));
131
#define CHECKFREG(r)		ASSERT((!IS_FLT_SREG(r) || (r) >= p_sfreg_first_save));
102
 
132
 
103
extern FILE *as_file;
133
extern FILE *as_file;
104
char * get_instruction PROTO_S ((Instruction_P));
134
char * get_instruction(Instruction_P);
105
 
135
 
106
char *ext_name PROTO_N ((id)) PROTO_T (long id)
136
char *ext_name(long id)
107
{
137
{
108
  if (id < 0)
138
  if (id < 0)
109
  {
139
  {
110
    char *ext = main_globals[(-id) - 1]->dec_u.dec_val.dec_id;
140
    char *ext = main_globals[(-id) - 1] ->dec_u.dec_val.dec_id;
111
 
141
 
112
    return ext;
142
    return ext;
113
  }
143
  }
114
  else
144
  else
115
  {
145
  {
Line 122... Line 152...
122
  }
152
  }
123
}
153
}
124
 
154
 
125
/* +++ do better for offset to R_SP too big, trace reg or load extra base reg */
155
/* +++ do better for offset to R_SP too big, trace reg or load extra base reg */
126
 
156
 
127
void ld_ro_ins PROTO_N ((ins,a,dest)) PROTO_T (Instruction_P ins X baseoff a X int dest)
157
void ld_ro_ins(Instruction_P ins, baseoff a, int dest)
128
{
158
{
129
  CHECKREG(dest); CHECKREG(a.base);
159
  CHECKREG(dest); CHECKREG(a.base);
130
 
160
 
131
  clear_reg(dest);
161
  clear_reg(dest);
132
 
162
 
133
  if (a.base == R_0)
163
  if (a.base == R_0)
134
  {
164
  {
135
    /* base reg of R_0 is not normally allowed, special case 0 offset */
165
    /* base reg of R_0 is not normally allowed, special case 0 offset */
136
    if (a.offset != 0)
166
    if (a.offset != 0)
137
      fail("ld_ro_ins: non zero offset to R_0");
167
      fail("ld_ro_ins: non zero offset to R_0");
138
    /* with XXXx (indexed instructions) RA of R_0 is taken as constant 0 */
168
    /* with XXXx (indexed instructions) RA of R_0 is taken as constant 0 */
139
#ifdef DO_ASSEMBLER_MACROS
169
#ifdef DO_ASSEMBLER_MACROS
140
    fprintf(as_file, "\t%sx\t%s,%s,%s",get_instruction(ins),reg_macro(dest),reg_macro(R_0),reg_macro(R_0));
170
    fprintf(as_file, "\t%sx\t%s,%s,%s",get_instruction(ins),reg_macro(dest),reg_macro(R_0),reg_macro(R_0));
141
#else
171
#else
142
    fprintf(as_file, "\t%sx\t%d,%d,%d", get_instruction(ins), dest, R_0, R_0);
172
    fprintf(as_file, "\t%sx\t%d,%d,%d", get_instruction(ins), dest, R_0, R_0);
143
#endif
173
#endif
144
  }
174
  }
145
  else if (IMM_SIZE(a.offset))
175
  else if (IMM_SIZE(a.offset))
146
  {
176
  {
147
#ifdef DO_ASSEMBLER_MACROS
177
#ifdef DO_ASSEMBLER_MACROS
148
    fprintf(as_file, "\t%s\t%s,%d(%s)", get_instruction(ins), reg_macro(dest), (int)a.offset, reg_macro(a.base));
178
    fprintf(as_file, "\t%s\t%s,%d(%s)", get_instruction(ins), reg_macro(dest), (int)a.offset, reg_macro(a.base));
149
#else
179
#else
150
    fprintf(as_file, "\t%s\t%d,%d(%d)", get_instruction(ins), dest, (int)a.offset, a.base);
180
    fprintf(as_file, "\t%s\t%d,%d(%d)", get_instruction(ins), dest,(int)a.offset, a.base);
151
#endif
181
#endif
152
  }
182
  }
153
  else
183
  else
154
  {
184
  {
155
    /* offset too big, put in temp reg and used ld_rr_ins */
185
    /* offset too big, put in temp reg and used ld_rr_ins */
156
    /* +++ arrange stack variable to minimise this */
186
    /* +++ arrange stack variable to minimise this */
157
    ASSERT(a.base!=R_TMP0);
187
    ASSERT(a.base!=R_TMP0);
158
    ld_const_ins(a.offset, R_TMP0);
188
    ld_const_ins(a.offset, R_TMP0);
159
    ld_rr_ins(ins, a.base, R_TMP0, dest);
189
    ld_rr_ins(ins, a.base, R_TMP0, dest);
160
  }
190
  }
161
}
191
}
162
 
192
 
163
 
193
 
164
void ld_rr_ins PROTO_N ((ins,reg1,reg2,dest)) PROTO_T (Instruction_P ins X int reg1 X int reg2 X int dest)
194
void ld_rr_ins(Instruction_P ins, int reg1, int reg2, int dest)
165
{
195
{
166
  CHECKREG(dest); CHECKREG(reg1); CHECKREG(reg2);
196
  CHECKREG(dest); CHECKREG(reg1); CHECKREG(reg2);
167
  ASSERT(reg1!=R_0);
197
  ASSERT(reg1!=R_0);
168
 
198
 
169
  clear_reg(dest);
199
  clear_reg(dest);
170
#ifdef DO_ASSEMBLER_MACROS
200
#ifdef DO_ASSEMBLER_MACROS
171
  fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), reg_macro(dest), reg_macro(reg1), reg_macro(reg2));
201
  fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), reg_macro(dest), reg_macro(reg1), reg_macro(reg2));
172
#else
202
#else
173
  fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), dest, reg1, reg2);
203
  fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), dest, reg1, reg2);
174
#endif
204
#endif
175
}
205
}
176
 
206
 
177
 
207
 
178
void set_ins PROTO_N ((a,dest)) PROTO_T (baseoff a X int dest)
208
void set_ins(baseoff a, int dest)
179
{
209
{
180
  char *extname = ext_name(a.base);
210
  char *extname = ext_name(a.base);
181
 
211
 
182
  CHECKREG(dest);
212
  CHECKREG(dest);
183
 
213
 
184
  clear_reg(dest);
214
  clear_reg(dest);
185
#ifdef DO_ASSEMBLER_MACROS
215
#ifdef DO_ASSEMBLER_MACROS
186
  fprintf(as_file, "\t%s\t%s,T.%s(%s)\n", get_instruction(i_l), reg_macro(dest), extname, reg_macro(R_TOC));
216
  fprintf(as_file, "\t%s\t%s,T.%s(%s)\n", get_instruction(i_l), reg_macro(dest), extname, reg_macro(R_TOC));
187
#else
217
#else
188
  fprintf(as_file, "\t%s\t%d,T.%s(%d)\n", get_instruction(i_l), dest, extname, R_TOC);
218
  fprintf(as_file, "\t%s\t%d,T.%s(%d)\n", get_instruction(i_l), dest, extname, R_TOC);
189
#endif
219
#endif
190
  /* +++ offsets in TOC */
220
  /* +++ offsets in TOC */
191
  if (a.offset != 0)
221
  if (a.offset != 0)
192
    rir_ins(i_a, dest, a.offset, dest);
222
    rir_ins(i_a, dest, a.offset, dest);
193
}
223
}
194
 
224
 
195
 
225
 
196
void ld_ins PROTO_N ((ins,a,dest)) PROTO_T (Instruction_P ins X baseoff a X int dest)
226
void ld_ins(Instruction_P ins, baseoff a, int dest)
197
{
227
{
198
  /*
228
  /*
199
   * Not a single instruction. Load from baseoff, which may be a global
229
   * Not a single instruction. Load from baseoff, which may be a global
200
   * requiring a temporary reg.
230
   * requiring a temporary reg.
201
   */
231
   */
Line 213... Line 243...
213
    /* load base into dest reg, then let ld_ro_ins do offset (which may need R_TMP0) */
243
    /* load base into dest reg, then let ld_ro_ins do offset (which may need R_TMP0) */
214
    tmp_off.base = a.base;
244
    tmp_off.base = a.base;
215
    tmp_off.offset = 0;
245
    tmp_off.offset = 0;
216
 
246
 
217
    set_ins(tmp_off, dest);
247
    set_ins(tmp_off, dest);
218
 
248
 
219
    tmp_off.base = dest;
249
    tmp_off.base = dest;
220
    tmp_off.offset = a.offset;
250
    tmp_off.offset = a.offset;
221
 
251
 
222
    ld_ro_ins(ins, tmp_off, dest);comment(NIL);
252
    ld_ro_ins(ins, tmp_off, dest);comment(NIL);
223
  }
253
  }
Line 226... Line 256...
226
    ld_ro_ins(ins, a, dest);comment(NIL);
256
    ld_ro_ins(ins, a, dest);comment(NIL);
227
  }
257
  }
228
}
258
}
229
 
259
 
230
 
260
 
231
void st_ro_ins PROTO_N ((ins,src,a)) PROTO_T (Instruction_P ins X int src X baseoff a)
261
void st_ro_ins(Instruction_P ins, int src, baseoff a)
232
{
262
{
233
  CHECKREG(src); CHECKREG(a.base);
263
  CHECKREG(src); CHECKREG(a.base);
234
 
264
 
235
 
265
 
236
  /* in general we cannot cope with store using temp reg, catch it always */
266
  /* in general we cannot cope with store using temp reg, catch it always */
Line 244... Line 274...
244
    /* with XXXx (indexed instructions) RA of R_0 is taken as constant 0 */
274
    /* with XXXx (indexed instructions) RA of R_0 is taken as constant 0 */
245
#ifdef DO_ASSEMBLER_MACROS
275
#ifdef DO_ASSEMBLER_MACROS
246
    fprintf(as_file, "\t%sx\t%s,%s,%s", get_instruction(ins), reg_macro(src), reg_macro(R_0), reg_macro(R_0));
276
    fprintf(as_file, "\t%sx\t%s,%s,%s", get_instruction(ins), reg_macro(src), reg_macro(R_0), reg_macro(R_0));
247
#else
277
#else
248
    fprintf(as_file, "\t%sx\t%d,%d,%d", get_instruction(ins), src, R_0, R_0);
278
    fprintf(as_file, "\t%sx\t%d,%d,%d", get_instruction(ins), src, R_0, R_0);
249
#endif
279
#endif
250
  }
280
  }
251
  else if (IMM_SIZE(a.offset))
281
  else if (IMM_SIZE(a.offset))
252
  {
282
  {
253
#ifdef DO_ASSEMBLER_MACROS
283
#ifdef DO_ASSEMBLER_MACROS
254
    fprintf(as_file, "\t%s\t%s,%d(%s)", get_instruction(ins), reg_macro(src), (int)a.offset, reg_macro(a.base));
284
    fprintf(as_file, "\t%s\t%s,%d(%s)", get_instruction(ins), reg_macro(src), (int)a.offset, reg_macro(a.base));
255
#else
285
#else
256
    fprintf(as_file, "\t%s\t%d,%d(%d)", get_instruction(ins), src, (int)a.offset, a.base);
286
    fprintf(as_file, "\t%s\t%d,%d(%d)", get_instruction(ins), src,(int)a.offset, a.base);
257
#endif
287
#endif
258
  }
288
  }
259
  else
289
  else
260
  {
290
  {
261
    /* offset too big, put in temp reg and used st_rr_ins */
291
    /* offset too big, put in temp reg and used st_rr_ins */
262
    /* +++ arrange stack variable to minimise this */
292
    /* +++ arrange stack variable to minimise this */
263
    COMMENT("st_ro_ins: big offset, use temp reg and st_rr_ins");
293
    COMMENT("st_ro_ins: big offset, use temp reg and st_rr_ins");
264
    ASSERT(a.base!=R_TMP0);		/* otherwise we corrupt it */
294
    ASSERT(a.base!=R_TMP0);		/* otherwise we corrupt it */
265
    ld_const_ins(a.offset, R_TMP0);
295
    ld_const_ins(a.offset, R_TMP0);
266
    st_rr_ins(ins, src, a.base, R_TMP0);
296
    st_rr_ins(ins, src, a.base, R_TMP0);
267
  }
297
  }
268
}
298
}
-
 
299
 
269
 
300
 
270
 
-
 
271
void st_rr_ins PROTO_N ((ins,src,reg1,reg2)) PROTO_T (Instruction_P ins X int src X int reg1 X int reg2)
301
void st_rr_ins(Instruction_P ins, int src, int reg1, int reg2)
272
{
302
{
273
  CHECKREG(src); CHECKREG(reg1); CHECKREG(reg2);
303
  CHECKREG(src); CHECKREG(reg1); CHECKREG(reg2);
274
  ASSERT(reg1!=R_0);
304
  ASSERT(reg1!=R_0);
275
#ifdef DO_ASSEMBLER_MACROS
305
#ifdef DO_ASSEMBLER_MACROS
276
  fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), reg_macro(src), reg_macro(reg1), reg_macro(reg2));
306
  fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), reg_macro(src), reg_macro(reg1), reg_macro(reg2));
277
#else
307
#else
278
  fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), src, reg1, reg2);
308
  fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), src, reg1, reg2);
279
#endif
309
#endif
280
}
310
}
281
 
311
 
282
 
312
 
283
void st_ins PROTO_N ((ins,src,a)) PROTO_T (Instruction_P ins X int src X baseoff a)
313
void st_ins(Instruction_P ins, int src, baseoff a)
284
{
314
{
285
  /*
315
  /*
286
   * Not a single instruction. Store into baseoff, which may be a global
316
   * Not a single instruction. Store into baseoff, which may be a global
287
   * requiring a temporary reg.
317
   * requiring a temporary reg.
288
   */
318
   */
289
 
319
 
290
  CHECKREG(src);
320
  CHECKREG(src);
291
 
321
 
292
  if (!IS_FIXREG(a.base))
322
  if (!IS_FIXREG(a.base))
293
  {
323
  {
294
    /* global */
324
    /* global */
295
    baseoff tmp_off;
325
    baseoff tmp_off;
296
 
326
 
297
    if (src == R_TMP0)
327
    if (src == R_TMP0)
298
      fail("st_ins: store of temp reg to global not allowed");	/* should not happen */
328
      fail("st_ins: store of temp reg to global not allowed");	/* should not happen */
299
 
329
 
300
    tmp_off.base = R_TMP0;
330
    tmp_off.base = R_TMP0;
301
    tmp_off.offset = 0;
331
    tmp_off.offset = 0;
302
 
332
 
303
    set_ins(a, R_TMP0);
333
    set_ins(a, R_TMP0);
304
    st_ro_ins(ins, src, tmp_off);comment(NIL);
334
    st_ro_ins(ins, src, tmp_off);comment(NIL);
305
  }
335
  }
306
  else
336
  else
307
  {
337
  {
308
    st_ro_ins(ins, src, a);comment(NIL);
338
    st_ro_ins(ins, src, a);comment(NIL);
309
  }
339
  }
310
}
340
}
311
 
341
 
312
 
342
 
313
/* 3 register operand instructions, source1, source2, destination */
343
/* 3 register operand instructions, source1, source2, destination */
314
void rrr_ins PROTO_N ((ins,src1,src2,dest)) PROTO_T (Instruction_P ins X int src1 X int src2 X int dest)
344
void rrr_ins(Instruction_P ins, int src1, int src2, int dest)
315
{
345
{
316
  CHECKREG(dest); CHECKREG(src1); CHECKREG(src2);
346
  CHECKREG(dest); CHECKREG(src1); CHECKREG(src2);
317
 
347
 
318
  clear_reg(dest);
348
  clear_reg(dest);
319
 
349
 
320
  /* i_s is a pseudo instruction, use i_sf with reversed ops */
350
  /* i_s is a pseudo instruction, use i_sf with reversed ops */
321
  if (ins == i_s)
351
  if (ins == i_s)
322
  {
352
  {
323
#ifdef DO_ASSEMBLER_MACROS
353
#ifdef DO_ASSEMBLER_MACROS
324
    fprintf(as_file, "\t%s\t%s,%s,%s\n", get_instruction(i_sf), reg_macro(dest), reg_macro(src2), reg_macro(src1));
354
    fprintf(as_file, "\t%s\t%s,%s,%s\n", get_instruction(i_sf), reg_macro(dest), reg_macro(src2), reg_macro(src1));
325
#else
355
#else
326
    fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(i_sf), dest, src2, src1);
356
    fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(i_sf), dest, src2, src1);
327
#endif
357
#endif
328
  }
358
  }
329
  else
359
  else
330
  {
360
  {
331
#ifdef DO_ASSEMBLER_MACROS
361
#ifdef DO_ASSEMBLER_MACROS
332
    fprintf(as_file, "\t%s\t%s,%s,%s\n", get_instruction(ins), reg_macro(dest), reg_macro(src1), reg_macro(src2));
362
    fprintf(as_file, "\t%s\t%s,%s,%s\n", get_instruction(ins), reg_macro(dest), reg_macro(src1), reg_macro(src2));
333
#else
363
#else
334
    fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(ins), dest, src1, src2);
364
    fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(ins), dest, src1, src2);
335
#endif
365
#endif
336
  }
366
  }
337
  
367
 
338
}
368
}
339
 
369
 
340
 
370
 
341
/* source register, immediate, destination register instructions */
371
/* source register, immediate, destination register instructions */
342
 
372
 
343
void rir_ins PROTO_N ((ins,src,imm,dest)) PROTO_T (Instruction_P ins X int src X long imm X int dest)
373
void rir_ins(Instruction_P ins, int src, long imm, int dest)
344
{
374
{
345
  bool logical = ins == i_and || ins == i_or || ins == i_xor|| 
375
  bool logical = ins == i_and || ins == i_or || ins == i_xor||
346
    ins ==i_and_cr|| ins==i_or_cr || ins==i_xor_cr;
376
    ins ==i_and_cr|| ins==i_or_cr || ins==i_xor_cr;
347
 
377
 
348
  CHECKREG(dest); CHECKREG(src);
378
  CHECKREG(dest); CHECKREG(src);
349
  ASSERT(ins!=i_divs&&ins!=i_div);	/* no divi, so we should not be called for div */
379
  ASSERT(ins!=i_divs&&ins!=i_div);	/* no divi, so we should not be called for div */
350
 
380
 
Line 357... Line 387...
357
  clear_reg(dest);
387
  clear_reg(dest);
358
 
388
 
359
  if (!logical && IMM_SIZE(imm))
389
  if (!logical && IMM_SIZE(imm))
360
  {
390
  {
361
    Instruction_P imins;
391
    Instruction_P imins;
362
    if      (ins==i_a)       imins=i_ai;
392
    if     (ins==i_a)      imins=i_ai;
363
    else if (ins==i_a_cr)    imins=i_ai_cr;
393
    else if (ins==i_a_cr)   imins=i_ai_cr;
364
    else if (ins==i_sf)      imins=i_sfi;
394
    else if (ins==i_sf)     imins=i_sfi;
365
    else if (ins==i_sl)      imins=i_sli;
395
    else if (ins==i_sl)     imins=i_sli;
366
    else if (ins==i_sl_cr)   imins=i_sli_cr;
396
    else if (ins==i_sl_cr)  imins=i_sli_cr;
367
    else if (ins==i_sr)      imins=i_sri;
397
    else if (ins==i_sr)     imins=i_sri;
368
    else if (ins==i_sr_cr)   imins=i_sri_cr;
398
    else if (ins==i_sr_cr)  imins=i_sri_cr;
369
    else if (ins==i_sra)     imins=i_srai;
399
    else if (ins==i_sra)    imins=i_srai;
370
    else if (ins==i_sra_cr)  imins=i_srai_cr;
400
    else if (ins==i_sra_cr) imins=i_srai_cr;
371
    else if (ins==i_muls)    imins=i_muli;
401
    else if (ins==i_muls)   imins=i_muli;
372
    else
402
    else
373
    {
403
    {
374
      printf("Unknown immediate instruction for %s\n",get_instruction(ins));
404
      printf("Unknown immediate instruction for %s\n",get_instruction(ins));
375
      imins=ins;    
405
      imins=ins;
376
    }
406
    }
377
    
407
 
378
#ifdef DO_ASSEMBLER_MACROS 
408
#ifdef DO_ASSEMBLER_MACROS
379
    fprintf(as_file,"\t%s\t%s,%s,%ld\n",get_instruction(imins), reg_macro(dest), reg_macro(src), imm);
409
    fprintf(as_file,"\t%s\t%s,%s,%ld\n",get_instruction(imins), reg_macro(dest), reg_macro(src), imm);
380
#else
410
#else
381
    fprintf(as_file,"\t%s\t%d,%d,%ld\n",get_instruction(imins), dest, src, imm);
411
    fprintf(as_file,"\t%s\t%d,%d,%ld\n",get_instruction(imins), dest, src, imm);
382
#endif
412
#endif
383
 
413
 
Line 393... Line 423...
393
    fprintf(as_file, "\t%s\t%d,%d,%ld\n", get_instruction(i_cau), dest, src, uimm >> 16);
423
    fprintf(as_file, "\t%s\t%d,%d,%ld\n", get_instruction(i_cau), dest, src, uimm >> 16);
394
#endif
424
#endif
395
    return;
425
    return;
396
  }
426
  }
397
 
427
 
398
  if ((ins == i_a || ins == i_s) && IMM_SIZE((imm/2)+1) && dest != R_SP)
428
  if ((ins == i_a || ins == i_s) && IMM_SIZE((imm/2) +1) && dest != R_SP)
399
  {
429
  {
400
    COMMENT1("rir_ins: special casing add/sub of constant %ld", imm);
430
    COMMENT1("rir_ins: special casing add/sub of constant %ld", imm);
401
    if (ins == i_s && imm == 0x8000)
431
    if (ins == i_s && imm == 0x8000)
402
    {
432
    {
403
      /* use -0x8000 as imm, which is immediate */
433
      /* use -0x8000 as imm, which is immediate */
Line 454... Line 484...
454
      fprintf(as_file, "\t%s\t%d,%d,0,0x%lx\n", get_instruction(i_rlinm_cr), dest, src, imm);
484
      fprintf(as_file, "\t%s\t%d,%d,0,0x%lx\n", get_instruction(i_rlinm_cr), dest, src, imm);
455
#endif
485
#endif
456
      return;
486
      return;
457
    }
487
    }
458
  }
488
  }
459
  
489
 
460
 
490
 
461
  if (logical && IMMLOGL_SIZE(imm))  /* Lower 16 bit load */
491
  if (logical && IMMLOGL_SIZE(imm))  /* Lower 16 bit load */
462
  {
492
  {
463
    Instruction_P ilins;
493
    Instruction_P ilins;
464
    if      (ins==i_and)  ilins = i_andil_cr;
494
    if     (ins==i_and) ilins = i_andil_cr;
465
    else if (ins==i_or)   ilins = i_oril;
495
    else if (ins==i_or)  ilins = i_oril;
466
    else if (ins==i_xor)  ilins = i_xoril;
496
    else if (ins==i_xor) ilins = i_xoril;
467
    else if (ins==i_and_cr) ilins = i_andil_cr;
497
    else if (ins==i_and_cr)ilins = i_andil_cr;
468
    else fail("Should never reach here");
498
    else fail("Should never reach here");
469
#ifdef DO_ASSEMBLER_MACROS
499
#ifdef DO_ASSEMBLER_MACROS
470
    fprintf(as_file, "\t%s\t%s,%s,%ld\n", get_instruction(ilins), reg_macro(dest), reg_macro(src), imm);
500
    fprintf(as_file, "\t%s\t%s,%s,%ld\n", get_instruction(ilins), reg_macro(dest), reg_macro(src), imm);
471
#else
501
#else
472
    fprintf(as_file, "\t%s\t%d,%d,%ld\n", get_instruction(ilins), dest, src, imm);
502
    fprintf(as_file, "\t%s\t%d,%d,%ld\n", get_instruction(ilins), dest, src, imm);
473
#endif
503
#endif
474
    return;
504
    return;
475
  }
505
  }
476
 
506
 
477
  if (logical && IMMLOGU_SIZE(imm))  /* Upper 16 bit load */ 
507
  if (logical && IMMLOGU_SIZE(imm))  /* Upper 16 bit load */
478
  {
508
  {
479
    unsigned long uimm = imm;
509
    unsigned long uimm = imm;
480
    Instruction_P iuins;
510
    Instruction_P iuins;
481
    if      (ins==i_and)  iuins = i_andiu_cr;
511
    if     (ins==i_and) iuins = i_andiu_cr;
482
    else if (ins==i_or)   iuins = i_oriu;
512
    else if (ins==i_or)  iuins = i_oriu;
483
    else if (ins==i_xor)  iuins = i_xoriu;
513
    else if (ins==i_xor) iuins = i_xoriu;
484
    else if (ins==i_and_cr) iuins = i_andiu_cr;
514
    else if (ins==i_and_cr)iuins = i_andiu_cr;
485
    else fail("Should never reach here");
515
    else fail("Should never reach here");
486
#ifdef DO_ASSEMBLER_MACROS
516
#ifdef DO_ASSEMBLER_MACROS
487
    fprintf(as_file, "\t%s\t%s,%s,%ld\n",get_instruction(iuins), reg_macro(dest), reg_macro(src), uimm >> 16);
517
    fprintf(as_file, "\t%s\t%s,%s,%ld\n",get_instruction(iuins), reg_macro(dest), reg_macro(src), uimm >> 16);
488
#else
518
#else
489
    fprintf(as_file, "\t%s\t%d,%d,%ld\n",get_instruction(iuins), dest, src, uimm >> 16);
519
    fprintf(as_file, "\t%s\t%d,%d,%ld\n",get_instruction(iuins), dest, src, uimm >> 16);
Line 493... Line 523...
493
 
523
 
494
  if (ins == i_or)
524
  if (ins == i_or)
495
  {
525
  {
496
    /* or lower and then upper end */
526
    /* or lower and then upper end */
497
    unsigned long uimm = imm;
527
    unsigned long uimm = imm;
498
#ifdef DO_ASSEMBLER_MACROS
528
#ifdef DO_ASSEMBLER_MACROS
499
    fprintf(as_file, "\t%s\t%s,%s,0x%lx\n", get_instruction(i_oril), reg_macro(dest), reg_macro(src), uimm & 0xffff);
529
    fprintf(as_file, "\t%s\t%s,%s,0x%lx\n", get_instruction(i_oril), reg_macro(dest), reg_macro(src), uimm & 0xffff);
500
    fprintf(as_file, "\t%s\t%s,%s,0x%lx\n", get_instruction(i_oriu), reg_macro(dest), reg_macro(dest), uimm >> 16);
530
    fprintf(as_file, "\t%s\t%s,%s,0x%lx\n", get_instruction(i_oriu), reg_macro(dest), reg_macro(dest), uimm >> 16);
501
#else
531
#else
502
    fprintf(as_file, "\t%s\t%d,%d,0x%lx\n", get_instruction(i_oril), dest, src, uimm & 0xffff);
532
    fprintf(as_file, "\t%s\t%d,%d,0x%lx\n", get_instruction(i_oril), dest, src, uimm & 0xffff);
503
    fprintf(as_file, "\t%s\t%d,%d,0x%lx\n", get_instruction(i_oriu), dest, dest, uimm >> 16);
533
    fprintf(as_file, "\t%s\t%d,%d,0x%lx\n", get_instruction(i_oriu), dest, dest, uimm >> 16);
504
#endif
534
#endif
505
 
535
 
506
    return;
536
    return;
507
  }
537
  }
508
 
538
 
509
  /* default: use temp reg for large constant */
539
  /* default: use temp reg for large constant */
510
  COMMENT("rir_ins: large constant in R_TMP0");
540
  COMMENT("rir_ins: large constant in R_TMP0");
511
  if (src == R_TMP0)
541
  if (src == R_TMP0)
512
    fail("rir_ins: temp reg in use when needed for large constant");	/* should not happen */
542
    fail("rir_ins: temp reg in use when needed for large constant");	/* should not happen */
513
  ld_const_ins(imm, R_TMP0);
543
  ld_const_ins(imm, R_TMP0);
514
  rrr_ins(ins, src, R_TMP0, dest);
544
  rrr_ins(ins, src, R_TMP0, dest);
515
}
545
}
516
 
546
 
517
/* register to register pseudo instruction */
547
/* register to register pseudo instruction */
518
void rr_ins PROTO_N ((ins,src,dest)) PROTO_T (Instruction_P ins X int src X int dest)
548
void rr_ins(Instruction_P ins, int src, int dest)
519
{
549
{
520
  CHECKREG(dest); CHECKREG(src);
550
  CHECKREG(dest); CHECKREG(src);
521
 
551
 
522
  clear_reg(dest);
552
  clear_reg(dest);
523
  if (ins == i_not)
553
  if (ins == i_not)
524
    rir_ins(i_sf, src, -1, dest);		/* implements monadic not */
554
    rir_ins(i_sf, src, -1, dest);		/* implements monadic not */
525
  else
555
  else
526
#ifdef DO_ASSEMBLER_MACROS
556
#ifdef DO_ASSEMBLER_MACROS
527
    fprintf(as_file, "\t%s\t%s,%s\n", get_instruction(ins), reg_macro(dest), reg_macro(src));
557
    fprintf(as_file, "\t%s\t%s,%s\n", get_instruction(ins), reg_macro(dest), reg_macro(src));
528
#else
558
#else
529
    fprintf(as_file, "\t%s\t%d,%d\n", get_instruction(ins), dest, src);
559
    fprintf(as_file, "\t%s\t%d,%d\n", get_instruction(ins), dest, src);
530
#endif
560
#endif
531
}
561
}
532
 
562
 
533
 
563
 
534
 
564
 
535
/* mov fixed point reg to another */
565
/* mov fixed point reg to another */
536
void mov_rr_ins PROTO_N ((src,dest)) PROTO_T (int src X int dest)
566
void mov_rr_ins(int src, int dest)
537
{
567
{
538
  CHECKREG(dest); CHECKREG(src);
568
  CHECKREG(dest); CHECKREG(src);
539
 
569
 
540
  if (src != dest)
570
  if (src != dest)
541
  {
571
  {
Line 543... Line 573...
543
    /* move by i_oril of src with 0 to dest */
573
    /* move by i_oril of src with 0 to dest */
544
#ifdef DO_ASSEMBLER_MACROS
574
#ifdef DO_ASSEMBLER_MACROS
545
    fprintf(as_file, "\t%s\t%s,%s,%d", get_instruction(i_oril), reg_macro(dest), reg_macro(src), 0);
575
    fprintf(as_file, "\t%s\t%s,%s,%d", get_instruction(i_oril), reg_macro(dest), reg_macro(src), 0);
546
#else
576
#else
547
    fprintf(as_file, "\t%s\t%d,%d,%d", get_instruction(i_oril), dest, src, 0);
577
    fprintf(as_file, "\t%s\t%d,%d,%d", get_instruction(i_oril), dest, src, 0);
548
#endif
578
#endif
549
  }
579
  }
550
}
580
}
551
 
581
 
552
 
582
 
553
/* load const into fixed point reg */
583
/* load const into fixed point reg */
554
void ld_const_ins PROTO_N ((imm,dest)) PROTO_T (long imm X int dest)
584
void ld_const_ins(long imm, int dest)
555
{
585
{
556
  CHECKREG(dest);
586
  CHECKREG(dest);
557
 
587
 
558
  clear_reg(dest);
588
  clear_reg(dest);
559
 
589
 
Line 588... Line 618...
588
  }
618
  }
589
}
619
}
590
 
620
 
591
 
621
 
592
/* move from branch unit to fixed point reg */
622
/* move from branch unit to fixed point reg */
593
void mf_ins PROTO_N ((ins,dest)) PROTO_T (Instruction_P ins X int dest)
623
void mf_ins(Instruction_P ins, int dest)
594
{
624
{
595
  if (ins !=i_mffs)
625
  if (ins !=i_mffs)
596
  {
626
  {
597
    CHECKREG(dest);
627
    CHECKREG(dest);
598
    clear_reg(dest);
628
    clear_reg(dest);
599
  }
629
  }
600
  else 
630
  else
601
  {
631
  {
602
    CHECKFREG(dest);
632
    CHECKFREG(dest);
603
    clear_freg(dest);
633
    clear_freg(dest);
604
  }
634
  }
605
#ifdef DO_ASSEMBLER_MACROS
635
#ifdef DO_ASSEMBLER_MACROS
Line 608... Line 638...
608
  fprintf(as_file, "\t%s\t%d\n", get_instruction(ins), dest);
638
  fprintf(as_file, "\t%s\t%d\n", get_instruction(ins), dest);
609
#endif
639
#endif
610
}
640
}
611
 
641
 
612
/* move to branch unit from fixed point reg */
642
/* move to branch unit from fixed point reg */
613
void mt_ins PROTO_N ((ins,src)) PROTO_T (Instruction_P ins X int src)
643
void mt_ins(Instruction_P ins, int src)
614
{
644
{
615
  CHECKREG(src);
645
  CHECKREG(src);
616
#ifdef DO_ASSEMBLER_MACROS
646
#ifdef DO_ASSEMBLER_MACROS
617
  fprintf(as_file, "\t%s\t%s\n", get_instruction(ins), reg_macro(src));
647
  fprintf(as_file, "\t%s\t%s\n", get_instruction(ins), reg_macro(src));
618
#else
648
#else
Line 621... Line 651...
621
}
651
}
622
 
652
 
623
 
653
 
624
 
654
 
625
/* zeroadic pseudo instruction */
655
/* zeroadic pseudo instruction */
626
void z_ins PROTO_N ((ins)) PROTO_T (Instruction_P ins)
656
void z_ins(Instruction_P ins)
627
{
657
{
628
  fprintf(as_file, "\t%s\n", get_instruction(ins));
658
  fprintf(as_file, "\t%s\n", get_instruction(ins));
629
}
659
}
630
 
660
 
631
 
661
 
632
/******************************************************************************
662
/******************************************************************************
633
Branch instructions. These have labels as destination.
663
Branch instructions. These have labels as destination.
634
******************************************************************************/
664
******************************************************************************/
635
 
665
 
636
/* unconditional branch */
666
/* unconditional branch */
637
void uncond_ins PROTO_N ((ins,lab)) PROTO_T (Instruction_P ins X int lab)
667
void uncond_ins(Instruction_P ins, int lab)
638
{
668
{
639
  fprintf(as_file, "\t%s\tL.%d\n", get_instruction(ins), lab);
669
  fprintf(as_file, "\t%s\tL.%d\n", get_instruction(ins), lab);
640
}
670
}
641
 
671
 
642
 
672
 
643
 
673
 
644
 
674
 
645
/*
675
/*
646
 * Call, and external jump instructions.
676
 * Call, and external jump instructions.
647
 */
677
 */
648
 
678
 
649
/* jump/call to external identifier */
679
/* jump/call to external identifier */
650
void extj_ins PROTO_N ((ins,b)) PROTO_T (Instruction_P ins X baseoff b)
680
void extj_ins(Instruction_P ins, baseoff b)
651
{
681
{
652
  char *ext;
682
  char *ext;
653
 
683
 
654
  FULLCOMMENT1("extj_ins: global proc no=%d", (-b.base) - 1);
684
  FULLCOMMENT1("extj_ins: global proc no=%d",(-b.base) - 1);
655
  ASSERT(((-b.base)-1)>=0);
685
  ASSERT(((-b.base) -1) >=0);
656
 
686
 
657
  ext = main_globals[(-b.base) - 1]->dec_u.dec_val.dec_id;
687
  ext = main_globals[(-b.base) - 1] ->dec_u.dec_val.dec_id;
658
 
688
 
659
  fprintf(as_file, "\t%s\t.%s\n", get_instruction(ins), ext);
689
  fprintf(as_file, "\t%s\t.%s\n", get_instruction(ins), ext);
660
 
690
 
661
  /*
691
  /*
662
   * By convention a special no-op is generated after a call,
692
   * By convention a special no-op is generated after a call,
663
   * which the linker changes to reload our TOC reg (2) if the
693
   * which the linker changes to reload our TOC reg (2) if the
664
   * call is inter-module.
694
   * call is inter-module.
665
   *
695
   *
666
   * We optimise by omitting the no-op where we know the call is intra-module.
696
   * We optimise by omitting the no-op where we know the call is intra-module.
667
   */
697
   */
668
  if (diagnose || !main_globals[(-b.base)-1]->dec_u.dec_val.have_def)
698
  if (diagnose || !main_globals[(-b.base) -1] ->dec_u.dec_val.have_def)
669
  {
699
  {
670
    fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(i_cror), 15, 15, 15);	/* conventional nop */
700
    fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(i_cror), 15, 15, 15);	/* conventional nop */
671
  }
701
  }
672
  
702
 
673
}
703
}
674
 
704
 
675
/* jump/call to compiler generated external identifier, eg .mul */
705
/* jump/call to compiler generated external identifier, eg .mul */
676
void extj_special_ins PROTO_N ((ins,nm)) PROTO_T (Instruction_P ins X char *nm)
706
void extj_special_ins(Instruction_P ins, char *nm)
677
{
707
{
678
  fprintf(as_file, "\t%s\t%s\n", get_instruction(ins), nm);
708
  fprintf(as_file, "\t%s\t%s\n", get_instruction(ins), nm);
679
  fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(i_cror), 15, 15, 15);	/* conventional nop */
709
  fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(i_cror), 15, 15, 15);	/* conventional nop */
680
}
710
}
681
 
711
 
682
 
712
 
683
/*
713
/*
684
 * Conditional instructions.
714
 * Conditional instructions.
685
 */
715
 */
686
 
716
 
687
/* branch conditional instruction */
717
/* branch conditional instruction */
688
void bc_ins PROTO_N ((ins,creg,lab,prediction)) PROTO_T (Instruction_P ins X int creg X int lab X int prediction)
718
void bc_ins(Instruction_P ins, int creg, int lab, int prediction)
689
{
719
{
690
  if(architecture == POWERPC_CODE)
720
  if (architecture == POWERPC_CODE)
691
  {
721
  {
692
    
722
 
693
    int BI;
723
    int BI;
694
    int BO;
724
    int BO;
695
    BI=creg*4;
725
    BI=creg*4;
696
    
726
 
697
    if (ins==i_ble)
727
    if (ins==i_ble)
698
    {
728
    {
699
      BO  = 4;
729
      BO  = 4;
700
      BI += 1;
730
      BI += 1;
701
    }
731
    }
702
    else if (ins ==i_blt)
732
    else if (ins ==i_blt)
703
    {
733
    {
704
      BO  = 12;
734
      BO  = 12;
-
 
735
      BI += 0;
-
 
736
    }
-
 
737
    else if (ins == i_bge)
-
 
738
    {
-
 
739
      BO  = 4;
705
      BI += 0;
740
      BI += 0;
706
    }
741
    }
707
    else if (ins == i_bge)
-
 
708
    {
-
 
709
      BO  = 4 ;
-
 
710
      BI += 0;
-
 
711
    } 
-
 
712
    else if (ins == i_bgt)
742
    else if (ins == i_bgt)
713
    {
743
    {
714
      BO  = 12;
744
      BO  = 12;
715
      BI += 1;
745
      BI += 1;
716
    }
746
    }
717
    else if(ins == i_bne)
747
    else if (ins == i_bne)
718
    {
748
    {
719
      BO  = 4;
749
      BO  = 4;
720
      BI += 2;
750
      BI += 2;
721
    }
751
    }
722
    else if (ins == i_beq)
752
    else if (ins == i_beq)
723
    {
753
    {
724
      BO  = 12;
754
      BO  = 12;
725
      BI += 2;
755
      BI += 2;
726
    }
756
    }
727
    else 
757
    else
728
    {
758
    {
729
      fprintf(as_file,"\t%s\t%d,L.%d\n",get_instruction(ins),creg,lab);
759
      fprintf(as_file,"\t%s\t%d,L.%d\n",get_instruction(ins),creg,lab);
730
      return;
760
      return;
731
    }
761
    }
732
    if(prediction)
762
    if (prediction)
733
    {
763
    {
734
      BO+=1;
764
      BO+=1;
735
    }
765
    }
736
    fprintf(as_file,"\t%s\t%d,%d,L.%d\n",get_instruction(i_bc),BO,BI,lab);
766
    fprintf(as_file,"\t%s\t%d,%d,L.%d\n",get_instruction(i_bc),BO,BI,lab);
737
  }
767
  }
738
  else
768
  else
739
  {
769
  {
740
#ifdef DO_ASSEMBLER_MACROS
770
#ifdef DO_ASSEMBLER_MACROS
741
    fprintf(as_file,"\t%s\t%s,L.%d\n",get_instruction(ins),cr_macro(creg),lab);
771
    fprintf(as_file,"\t%s\t%s,L.%d\n",get_instruction(ins),cr_macro(creg),lab);
742
#else
772
#else
743
    fprintf(as_file,"\t%s\t%d,L.%d\n",get_instruction(ins),creg,lab);
773
    fprintf(as_file,"\t%s\t%d,L.%d\n",get_instruction(ins),creg,lab);
744
#endif
774
#endif
745
  }
775
  }
746
}
776
}
747
/* branch conditional instruction */
777
/* branch conditional instruction */
748
void long_bc_ins PROTO_N ((ins,creg,lab,prediction)) PROTO_T (Instruction_P ins X int creg X int lab X int prediction)
778
void long_bc_ins(Instruction_P ins, int creg, int lab, int prediction)
749
{
779
{
750
  /* same as bc_ins only the test is reversed so that the lab is called directly so that there is no chance of the branch being out of range */
780
  /* same as bc_ins only the test is reversed so that the lab is called directly so that there is no chance of the branch being out of range */
751
 
781
 
752
  long new_lab = lab;
782
  long new_lab = lab;
753
  lab = new_label();
783
  lab = new_label();
754
  if      (ins==i_blt){ins = i_bge;}
784
  if     (ins==i_blt) {ins = i_bge;}
755
  else if (ins==i_ble){ins = i_bgt;}
785
  else if (ins==i_ble) {ins = i_bgt;}
756
  else if (ins==i_bne){ins = i_beq;}
786
  else if (ins==i_bne) {ins = i_beq;}
757
  else if (ins==i_beq){ins = i_bne;}
787
  else if (ins==i_beq) {ins = i_bne;}
758
  else if (ins==i_bgt){ins = i_ble;}
788
  else if (ins==i_bgt) {ins = i_ble;}
759
  else if (ins==i_bge){ins = i_blt;}
789
  else if (ins==i_bge) {ins = i_blt;}
760
  else if (ins==i_bso){ins = i_bns;}
790
  else if (ins==i_bso) {ins = i_bns;}
761
  else if (ins==i_bns){ins = i_bso;}
791
  else if (ins==i_bns) {ins = i_bso;}
762
  else
792
  else
763
  {
793
  {
764
    fail("Don't know how to reverse this test");
794
    fail("Don't know how to reverse this test");
765
  }
795
  }
766
  
796
 
767
  if(architecture == POWERPC_CODE)
797
  if (architecture == POWERPC_CODE)
768
  {
798
  {
769
    
799
 
770
    int BI;
800
    int BI;
771
    int BO;
801
    int BO;
772
    BI=creg*4;
802
    BI=creg*4;
773
    
803
 
774
    if (ins==i_ble)
804
    if (ins==i_ble)
775
    {
805
    {
776
      BO  = 4;
806
      BO  = 4;
777
      BI += 1;
807
      BI += 1;
778
    }
808
    }
779
    else if (ins ==i_blt)
809
    else if (ins ==i_blt)
780
    {
810
    {
781
      BO  = 12;
811
      BO  = 12;
782
      BI += 0;
812
      BI += 0;
783
    }
813
    }
784
    else if (ins == i_bge)
814
    else if (ins == i_bge)
785
    {
815
    {
786
      BO  = 4 ;
816
      BO  = 4;
787
      BI += 0;
817
      BI += 0;
788
    } 
818
    }
789
    else if (ins == i_bgt)
819
    else if (ins == i_bgt)
790
    {
820
    {
791
      BO  = 12;
821
      BO  = 12;
792
      BI += 1;
822
      BI += 1;
793
    }
823
    }
794
    else if(ins == i_bne)
824
    else if (ins == i_bne)
795
    {
825
    {
796
      BO  = 4;
826
      BO  = 4;
797
      BI += 2;
827
      BI += 2;
798
    }
828
    }
799
    else if (ins == i_beq)
829
    else if (ins == i_beq)
800
    {
830
    {
801
      BO  = 12;
831
      BO  = 12;
802
      BI += 2;
832
      BI += 2;
803
    }
833
    }
804
    else 
834
    else
805
    {
835
    {
806
      fprintf(as_file,"\t%s\t%d,L.%d\n",get_instruction(ins),creg,lab);
836
      fprintf(as_file,"\t%s\t%d,L.%d\n",get_instruction(ins),creg,lab);
807
      uncond_ins(i_b,new_lab);
837
      uncond_ins(i_b,new_lab);
808
      set_label(lab);
838
      set_label(lab);
809
      return;
839
      return;
810
    }
840
    }
811
    if(prediction)
841
    if (prediction)
812
    {
842
    {
813
      BO+=1;
843
      BO+=1;
814
    }
844
    }
815
    fprintf(as_file,"\t%s\t%d,%d,L.%d\n",get_instruction(i_bc),BO,BI,lab);
845
    fprintf(as_file,"\t%s\t%d,%d,L.%d\n",get_instruction(i_bc),BO,BI,lab);
816
    uncond_ins(i_b,new_lab);
846
    uncond_ins(i_b,new_lab);
Line 831... Line 861...
831
  }
861
  }
832
}
862
}
833
 
863
 
834
 
864
 
835
/* cmp or cmpl instruction */
865
/* cmp or cmpl instruction */
836
void cmp_rr_ins PROTO_N ((ins,reg1,reg2,cr_dest)) PROTO_T (Instruction_P ins X int reg1 X int reg2 X int cr_dest)
866
void cmp_rr_ins(Instruction_P ins, int reg1, int reg2, int cr_dest)
837
{
867
{
838
  CHECKREG(reg1); CHECKREG(reg2);
868
  CHECKREG(reg1); CHECKREG(reg2);
839
#ifdef DO_ASSEMBLER_MACROS
869
#ifdef DO_ASSEMBLER_MACROS
840
  fprintf(as_file, "\t%s\t%s,%s,%s\n", get_instruction(ins), cr_macro(cr_dest), reg_macro(reg1), reg_macro(reg2));
870
  fprintf(as_file, "\t%s\t%s,%s,%s\n", get_instruction(ins), cr_macro(cr_dest), reg_macro(reg1), reg_macro(reg2));
841
#else
871
#else
842
  fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(ins), cr_dest, reg1, reg2);
872
  fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(ins), cr_dest, reg1, reg2);
843
#endif
873
#endif
844
}
874
}
845
 
875
 
846
 
876
 
847
/* for cmpi or cmpli instruction */
877
/* for cmpi or cmpli instruction */
848
void cmp_ri_ins PROTO_N ((ins,reg,imm,cr_dest)) PROTO_T (Instruction_P ins X int reg X long imm X int cr_dest)
878
void cmp_ri_ins(Instruction_P ins, int reg, long imm, int cr_dest)
849
{
879
{
850
  CHECKREG(reg);
880
  CHECKREG(reg);
851
 
881
 
852
  /* +++ for equality can use cmpi or cmpli for larger constant range */
882
  /* +++ for equality can use cmpi or cmpli for larger constant range */
853
  if (ins == i_cmp && IMM_SIZE(imm))
883
  if (ins == i_cmp && IMM_SIZE(imm))
Line 862... Line 892...
862
  {
892
  {
863
#ifdef DO_ASSEMBLER_MACROS
893
#ifdef DO_ASSEMBLER_MACROS
864
    fprintf(as_file, "\t%si\t%s,%s,%ld\n", get_instruction(ins), cr_macro(cr_dest), reg_macro(reg), imm);
894
    fprintf(as_file, "\t%si\t%s,%s,%ld\n", get_instruction(ins), cr_macro(cr_dest), reg_macro(reg), imm);
865
#else
895
#else
866
    fprintf(as_file, "\t%si\t%d,%d,%ld\n", get_instruction(ins), cr_dest, reg, imm);
896
    fprintf(as_file, "\t%si\t%d,%d,%ld\n", get_instruction(ins), cr_dest, reg, imm);
867
#endif
897
#endif
868
  }
898
  }
869
  else
899
  else
870
  {
900
  {
871
    /* use temp reg for large constant */
901
    /* use temp reg for large constant */
872
    COMMENT("condri_ins: large constant in R_TMP0");
902
    COMMENT("condri_ins: large constant in R_TMP0");
873
    if (reg == R_TMP0)
903
    if (reg == R_TMP0)
874
      fail("cmp_ri_ins: temp reg in use when needed for large constant");	/* should not happen */
904
      fail("cmp_ri_ins: temp reg in use when needed for large constant");	/* should not happen */
875
    ld_const_ins(imm, R_TMP0);
905
    ld_const_ins(imm, R_TMP0);
876
    cmp_rr_ins(ins, reg, R_TMP0, cr_dest);
906
    cmp_rr_ins(ins, reg, R_TMP0, cr_dest);
877
  }
907
  }
878
}
908
}
879
 
909
 
880
 
910
 
881
 
911
 
882
 
912
 
883
/*
913
/*
884
 * Floating point instructions.
914
 * Floating point instructions.
885
 */
915
 */
886
 
916
 
887
void ldf_ro_ins PROTO_N ((ins,a,dest)) PROTO_T (Instruction_P ins X baseoff a X int dest)
917
void ldf_ro_ins(Instruction_P ins, baseoff a, int dest)
888
{
918
{
889
  CHECKREG(a.base); CHECKFREG(dest);
919
  CHECKREG(a.base); CHECKFREG(dest);
890
 
920
 
891
  clear_freg(dest);
921
  clear_freg(dest);
892
 
922
 
893
  if (a.base == R_0)
923
  if (a.base == R_0)
894
  {
924
  {
895
    if (a.offset != 0)
925
    if (a.offset != 0)
896
      fail("ldf_ro_ins: non zero offset to R_0");
926
      fail("ldf_ro_ins: non zero offset to R_0");
897
    /* with XXXx (indexed instructions) RA of R_0 is taken as constant 0 */
927
    /* with XXXx (indexed instructions) RA of R_0 is taken as constant 0 */
898
#ifdef DO_ASSEMBLER_MACROS
928
#ifdef DO_ASSEMBLER_MACROS
899
    fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), freg_macro(dest), reg_macro(R_0), reg_macro(R_0));
929
    fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), freg_macro(dest), reg_macro(R_0), reg_macro(R_0));
900
#else
930
#else
901
    fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), dest, R_0, R_0);
931
    fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), dest, R_0, R_0);
902
#endif
932
#endif
903
  }
933
  }
904
  else
934
  else
905
  if (IMM_SIZE(a.offset))
935
  if (IMM_SIZE(a.offset))
906
  {
936
  {
907
#ifdef DO_ASSEMBLER_MACROS
937
#ifdef DO_ASSEMBLER_MACROS
908
    fprintf(as_file, "\t%s\t%s,%d(%s)\n", get_instruction(ins), freg_macro(dest), (int)a.offset, reg_macro(a.base));
938
    fprintf(as_file, "\t%s\t%s,%d(%s)\n", get_instruction(ins), freg_macro(dest), (int)a.offset, reg_macro(a.base));
909
#else
939
#else
910
    fprintf(as_file, "\t%s\t%d,%d(%d)\n", get_instruction(ins), dest, (int)a.offset, a.base);
940
    fprintf(as_file, "\t%s\t%d,%d(%d)\n", get_instruction(ins), dest,(int)a.offset, a.base);
911
#endif
941
#endif
912
  }
942
  }
913
  else
943
  else
914
  {
944
  {
915
    /* offset too big, put in temp reg and used ld_rr_ins */
945
    /* offset too big, put in temp reg and used ld_rr_ins */
Line 920... Line 950...
920
    ldf_rr_ins(ins, a.base, R_TMP0, dest);
950
    ldf_rr_ins(ins, a.base, R_TMP0, dest);
921
  }
951
  }
922
}
952
}
923
 
953
 
924
 
954
 
925
void ldf_rr_ins PROTO_N ((ins,reg1,reg2,dest)) PROTO_T (Instruction_P ins X int reg1 X int reg2 X int dest)
955
void ldf_rr_ins(Instruction_P ins, int reg1, int reg2, int dest)
926
{
956
{
927
  CHECKREG(reg1); CHECKREG(reg2); CHECKFREG(dest);
957
  CHECKREG(reg1); CHECKREG(reg2); CHECKFREG(dest);
928
 
958
 
929
  clear_freg(dest);
959
  clear_freg(dest);
930
#ifdef DO_ASSEMBLER_MACROS
960
#ifdef DO_ASSEMBLER_MACROS
Line 933... Line 963...
933
  fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), dest, reg1, reg2);
963
  fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), dest, reg1, reg2);
934
#endif
964
#endif
935
}
965
}
936
 
966
 
937
 
967
 
938
void ldf_ins PROTO_N ((ins,a,dest)) PROTO_T (Instruction_P ins X baseoff a X int dest)
968
void ldf_ins(Instruction_P ins, baseoff a, int dest)
939
{
969
{
940
  /*
970
  /*
941
   * Not a single instruction. Load from baseoff, which may be a global
971
   * Not a single instruction. Load from baseoff, which may be a global
942
   * requiring a temporary reg.
972
   * requiring a temporary reg.
943
   */
973
   */
944
 
974
 
945
  CHECKFREG(dest);
975
  CHECKFREG(dest);
946
 
976
 
947
  if (!IS_FIXREG(a.base))
977
  if (!IS_FIXREG(a.base))
948
  {
978
  {
949
    /* global */
979
    /* global */
950
    baseoff tmp_off;
980
    baseoff tmp_off;
951
 
981
 
952
    tmp_off.base = R_TMP0;
982
    tmp_off.base = R_TMP0;
953
    tmp_off.offset = 0;
983
    tmp_off.offset = 0;
954
 
984
 
955
    set_ins(a, R_TMP0);
985
    set_ins(a, R_TMP0);
956
    ldf_ro_ins(ins, tmp_off, dest);
986
    ldf_ro_ins(ins, tmp_off, dest);
957
  }
987
  }
958
  else
988
  else
959
  {
989
  {
960
    ldf_ro_ins(ins, a, dest);
990
    ldf_ro_ins(ins, a, dest);
961
  }
991
  }
962
}
992
}
963
 
993
 
964
 
994
 
965
void stf_ro_ins PROTO_N (( ins,src,a)) PROTO_T (Instruction_P ins X int src X baseoff a)
995
void stf_ro_ins(Instruction_P ins, int src, baseoff a)
966
{
996
{
967
  CHECKREG(a.base); CHECKFREG(src);
997
  CHECKREG(a.base); CHECKFREG(src);
968
 
998
 
969
  /* in general we cannot cope with store using temp reg, catch it always */
999
  /* in general we cannot cope with store using temp reg, catch it always */
970
  if (a.base == R_TMP0 && absval(a.offset) > (16 + 1 + 6) * 4)	/* leeway for mem_temp() */
1000
  if (a.base == R_TMP0 && absval(a.offset) > (16 + 1 + 6) * 4)	/* leeway for mem_temp() */
971
    fail("stf_ro_ins: store of temp reg to offset not allowed");	/* should not happen */
1001
    fail("stf_ro_ins: store of temp reg to offset not allowed");	/* should not happen */
972
 
1002
 
973
  if (a.base == R_0)
1003
  if (a.base == R_0)
Line 977... Line 1007...
977
    /* with XXXx (indexed instructions) RA of R_0 is taken as constant 0 */
1007
    /* with XXXx (indexed instructions) RA of R_0 is taken as constant 0 */
978
#ifdef DO_ASSEMBLER_MACROS
1008
#ifdef DO_ASSEMBLER_MACROS
979
    fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), freg_macro(src), reg_macro(R_0), reg_macro(R_0));
1009
    fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), freg_macro(src), reg_macro(R_0), reg_macro(R_0));
980
#else
1010
#else
981
    fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), src, R_0, R_0);
1011
    fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), src, R_0, R_0);
982
#endif
1012
#endif
983
  }
1013
  }
984
  else
1014
  else
985
  if (IMM_SIZE(a.offset))
1015
  if (IMM_SIZE(a.offset))
986
  {
1016
  {
987
#ifdef DO_ASSEMBLER_MACROS
1017
#ifdef DO_ASSEMBLER_MACROS
988
    fprintf(as_file, "\t%s\t%s,%d(%s)\n", get_instruction(ins), freg_macro(src), (int)a.offset, reg_macro(a.base));
1018
    fprintf(as_file, "\t%s\t%s,%d(%s)\n", get_instruction(ins), freg_macro(src), (int)a.offset, reg_macro(a.base));
989
#else
1019
#else
990
    fprintf(as_file, "\t%s\t%d,%d(%d)\n", get_instruction(ins), src, (int)a.offset, a.base);
1020
    fprintf(as_file, "\t%s\t%d,%d(%d)\n", get_instruction(ins), src,(int)a.offset, a.base);
991
#endif
1021
#endif
992
  }
1022
  }
993
  else
1023
  else
994
  {
1024
  {
995
    /* offset too big, put in temp reg and used stf_rr_ins */
1025
    /* offset too big, put in temp reg and used stf_rr_ins */
Line 1000... Line 1030...
1000
    stf_rr_ins(ins, src, a.base, R_TMP0);
1030
    stf_rr_ins(ins, src, a.base, R_TMP0);
1001
  }
1031
  }
1002
}
1032
}
1003
 
1033
 
1004
 
1034
 
1005
void stf_rr_ins PROTO_N ((ins,src,reg1,reg2)) PROTO_T (Instruction_P ins X int src X int reg1 X int reg2)
1035
void stf_rr_ins(Instruction_P ins, int src, int reg1, int reg2)
1006
{
1036
{
1007
  CHECKREG(reg1); CHECKREG(reg2);
1037
  CHECKREG(reg1); CHECKREG(reg2);
1008
#ifdef DO_ASSEMBLER_MACROS
1038
#ifdef DO_ASSEMBLER_MACROS
1009
  fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), freg_macro(src), reg_macro(reg1), reg_macro(reg2));
1039
  fprintf(as_file, "\t%sx\t%s,%s,%s\n", get_instruction(ins), freg_macro(src), reg_macro(reg1), reg_macro(reg2));
1010
#else
1040
#else
1011
  fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), src, reg1, reg2);
1041
  fprintf(as_file, "\t%sx\t%d,%d,%d\n", get_instruction(ins), src, reg1, reg2);
1012
#endif
1042
#endif
1013
}
1043
}
1014
 
1044
 
1015
 
1045
 
1016
void stf_ins PROTO_N ((ins,src,a)) PROTO_T (Instruction_P ins X int src X baseoff a)
1046
void stf_ins(Instruction_P ins, int src, baseoff a)
1017
{
1047
{
1018
  /*
1048
  /*
1019
   * Not a single instruction. Store into baseoff, which may be a global
1049
   * Not a single instruction. Store into baseoff, which may be a global
1020
   * requiring a temporary reg.
1050
   * requiring a temporary reg.
1021
   */
1051
   */
Line 1038... Line 1068...
1038
    stf_ro_ins(ins, src, a);
1068
    stf_ro_ins(ins, src, a);
1039
  }
1069
  }
1040
}
1070
}
1041
 
1071
 
1042
 
1072
 
1043
void rrf_cmp_ins PROTO_N ((ins,reg1,reg2,cr_dest)) PROTO_T (Instruction_P ins X int reg1 X int reg2 X int cr_dest)
1073
void rrf_cmp_ins(Instruction_P ins, int reg1, int reg2, int cr_dest)
1044
{
1074
{
1045
  CHECKFREG(reg1); CHECKFREG(reg2);
1075
  CHECKFREG(reg1); CHECKFREG(reg2);
1046
#ifdef DO_ASSEMBLER_MACROS
1076
#ifdef DO_ASSEMBLER_MACROS
1047
  fprintf(as_file, "\t%s\t%s,%s,%s\n", get_instruction(ins), cr_macro(cr_dest), freg_macro(reg1), freg_macro(reg2));
1077
  fprintf(as_file, "\t%s\t%s,%s,%s\n", get_instruction(ins), cr_macro(cr_dest), freg_macro(reg1), freg_macro(reg2));
1048
#else
1078
#else
1049
  fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(ins), cr_dest, reg1, reg2);
1079
  fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(ins), cr_dest, reg1, reg2);
1050
#endif
1080
#endif
1051
}
1081
}
1052
 
1082
 
1053
 
1083
 
1054
void rrf_ins PROTO_N ((ins,src,dest)) PROTO_T (Instruction_P ins X int src X int dest)
1084
void rrf_ins(Instruction_P ins, int src, int dest)
1055
{
1085
{
1056
  CHECKFREG(dest); CHECKFREG(src);
1086
  CHECKFREG(dest); CHECKFREG(src);
1057
 
1087
 
1058
  clear_freg(dest);
1088
  clear_freg(dest);
1059
#ifdef DO_ASSEMBLER_MACROS
1089
#ifdef DO_ASSEMBLER_MACROS
1060
  fprintf(as_file, "\t%s\t%s,%s\n", get_instruction(ins), freg_macro(dest), freg_macro(src));
1090
  fprintf(as_file, "\t%s\t%s,%s\n", get_instruction(ins), freg_macro(dest), freg_macro(src));
1061
#else
1091
#else
1062
  fprintf(as_file, "\t%s\t%d,%d\n", get_instruction(ins), dest, src);
1092
  fprintf(as_file, "\t%s\t%d,%d\n", get_instruction(ins), dest, src);
1063
#endif
1093
#endif
1064
}
1094
}
1065
 
1095
 
1066
 
1096
 
1067
void rrrf_ins PROTO_N ((ins,src1,src2,dest)) PROTO_T(Instruction_P ins X int src1 X int src2 X int dest)
1097
void rrrf_ins(Instruction_P ins, int src1, int src2, int dest)
1068
{
1098
{
1069
  CHECKFREG(dest); CHECKFREG(src1); CHECKFREG(src2);
1099
  CHECKFREG(dest); CHECKFREG(src1); CHECKFREG(src2);
1070
 
1100
 
1071
  clear_freg(dest);
1101
  clear_freg(dest);
1072
#ifdef DO_ASSEMBLER_MACROS
1102
#ifdef DO_ASSEMBLER_MACROS
Line 1074... Line 1104...
1074
#else
1104
#else
1075
  fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(ins), dest, src1, src2);
1105
  fprintf(as_file, "\t%s\t%d,%d,%d\n", get_instruction(ins), dest, src1, src2);
1076
#endif
1106
#endif
1077
}
1107
}
1078
 
1108
 
1079
void rrrrf_ins PROTO_N ((ins,src1,src2,src3,dest)) PROTO_T (Instruction_P ins X int src1 X int src2 X int src3 X int dest )
1109
void rrrrf_ins(Instruction_P ins, int src1, int src2, int src3, int dest)
1080
{
1110
{
1081
  CHECKFREG(dest); CHECKFREG(src1); CHECKFREG(src2); CHECKFREG(src3);
1111
  CHECKFREG(dest); CHECKFREG(src1); CHECKFREG(src2); CHECKFREG(src3);
1082
  
1112
 
1083
  clear_freg(dest);
1113
  clear_freg(dest);
1084
#ifdef DO_ASSEMBLER_MACROS
1114
#ifdef DO_ASSEMBLER_MACROS
1085
  fprintf(as_file,"\t%s\t%s,%s,%s,%s\n",get_instruction(ins),freg_macro(dest),freg_macro(src1),freg_macro(src2),freg_macro(src3));
1115
  fprintf(as_file,"\t%s\t%s,%s,%s,%s\n",get_instruction(ins),freg_macro(dest),freg_macro(src1),freg_macro(src2),freg_macro(src3));
1086
#else
1116
#else
1087
  fprintf(as_file,"\t%s\t%d,%d,%d,%d\n",get_instruction(ins),dest,src1,src2,src3);
1117
  fprintf(as_file,"\t%s\t%d,%d,%d,%d\n",get_instruction(ins),dest,src1,src2,src3);
1088
#endif
1118
#endif
1089
}
1119
}
1090
void rlinm_ins PROTO_N ((ins,src1,sl,mask,dest)) PROTO_T (Instruction_P ins X int src1 X int sl X unsigned int mask X int dest )
1120
void rlinm_ins(Instruction_P ins, int src1, int sl, unsigned int mask, int dest)
1091
{
1121
{
1092
  CHECKREG(dest);CHECKREG(src1);
1122
  CHECKREG(dest);CHECKREG(src1);
1093
  ASSERT(ins==i_rlinm||ins==i_rlinm_cr);
1123
  ASSERT(ins==i_rlinm||ins==i_rlinm_cr);
1094
  clear_reg(dest);
1124
  clear_reg(dest);
1095
#ifdef DO_ASSEMBLER_MACROS
1125
#ifdef DO_ASSEMBLER_MACROS
Line 1097... Line 1127...
1097
#else
1127
#else
1098
  fprintf(as_file,"\t%s\t%d,%d,%d,0x%x\n",get_instruction(ins),dest,src1,sl,mask);
1128
  fprintf(as_file,"\t%s\t%d,%d,%d,0x%x\n",get_instruction(ins),dest,src1,sl,mask);
1099
#endif
1129
#endif
1100
}
1130
}
1101
 
1131
 
1102
void mfspr_ins PROTO_N ((spr,dest)) PROTO_T (int spr X int dest )
1132
void mfspr_ins(int spr, int dest)
1103
{  
1133
{
1104
  CHECKREG(dest);
1134
  CHECKREG(dest);
1105
  clear_reg(dest);
1135
  clear_reg(dest);
1106
#ifdef DO_ASSEMBLER_MACROS
1136
#ifdef DO_ASSEMBLER_MACROS
1107
  fprintf(as_file,"\t%s\t%s,%s\n",get_instruction(i_mfspr),reg_macro(dest),spr_macro(spr));
1137
  fprintf(as_file,"\t%s\t%s,%s\n",get_instruction(i_mfspr),reg_macro(dest),spr_macro(spr));
1108
#else
1138
#else
1109
  fprintf(as_file,"\t%s\t%d,%d\n",get_instruction(i_mfspr),dest,spr);
1139
  fprintf(as_file,"\t%s\t%d,%d\n",get_instruction(i_mfspr),dest,spr);
1110
#endif
1140
#endif
1111
}
1141
}
1112
void mtfsfi_ins PROTO_N ((fld,imm)) PROTO_T (int fld X int imm )
1142
void mtfsfi_ins(int fld, int imm)
1113
{
1143
{
1114
  fprintf(as_file,"\t%s\t%d,%d\n",get_instruction(i_mtfsfi),fld,imm);
1144
  fprintf(as_file,"\t%s\t%d,%d\n",get_instruction(i_mtfsfi),fld,imm);
1115
}
1145
}
1116
void mtfsb0_ins PROTO_N ((bit)) PROTO_T (int bit)
1146
void mtfsb0_ins(int bit)
1117
{
1147
{
1118
  ASSERT(bit>=0 && bit<=31);
1148
  ASSERT(bit>=0 && bit<=31);
1119
  fprintf(as_file,"\t%s\t%d\n",get_instruction(i_mtfsb0),bit);
1149
  fprintf(as_file,"\t%s\t%d\n",get_instruction(i_mtfsb0),bit);
1120
}
1150
}
1121
void mtfsb1_ins PROTO_N ((bit)) PROTO_T (int bit)
1151
void mtfsb1_ins(int bit)
1122
{
1152
{
1123
  ASSERT(bit>=0 && bit<=31);
1153
  ASSERT(bit>=0 && bit<=31);
1124
  fprintf(as_file,"\t%s\t%d\n",get_instruction(i_mtfsb1),bit);
1154
  fprintf(as_file,"\t%s\t%d\n",get_instruction(i_mtfsb1),bit);
1125
}
1155
}
1126
void mcrfs_ins PROTO_N ((a,b)) PROTO_T (int a X int b)
1156
void mcrfs_ins(int a, int b)
1127
{
1157
{
1128
  ASSERT(a>=0 && a<=7);
1158
  ASSERT(a>=0 && a<=7);
1129
  ASSERT(b>=0 && b<=7);
1159
  ASSERT(b>=0 && b<=7);
1130
#ifdef DO_ASSEMBLER_MACROS
1160
#ifdef DO_ASSEMBLER_MACROS
1131
  fprintf(as_file,"\t%s\t%s,%d\n",get_instruction(i_mcrfs),cr_macro(a),b);
1161
  fprintf(as_file,"\t%s\t%s,%d\n",get_instruction(i_mcrfs),cr_macro(a),b);
1132
#else
1162
#else
1133
  fprintf(as_file,"\t%s\t%d,%d\n",get_instruction(i_mcrfs),a,b);
1163
  fprintf(as_file,"\t%s\t%d,%d\n",get_instruction(i_mcrfs),a,b);
1134
#endif
1164
#endif
1135
}
1165
}
1136
void lsi_ins PROTO_N ((src,dest,nb)) PROTO_T (int src X int dest X int nb)
1166
void lsi_ins(int src, int dest, int nb)
1137
{
1167
{
1138
  fprintf(as_file,"\t%s\t%d,%d,%d\n",get_instruction(i_lsi),dest,src,nb);
1168
  fprintf(as_file,"\t%s\t%d,%d,%d\n",get_instruction(i_lsi),dest,src,nb);
1139
}
1169
}
1140
void stsi_ins PROTO_N ((src,dest,nb)) PROTO_T (int src X int dest X int nb)
1170
void stsi_ins(int src, int dest, int nb)
1141
{
1171
{
1142
  fprintf(as_file,"\t%s\t%d,%d,%d\n",get_instruction(i_stsi),src,dest,nb);
1172
  fprintf(as_file,"\t%s\t%d,%d,%d\n",get_instruction(i_stsi),src,dest,nb);
1143
}
1173
}
1144
void comment PROTO_N ((p)) PROTO_T (char *p)
1174
void comment(char *p)
1145
{
1175
{
1146
#ifdef DEBUG_POWERTRANS
1176
#ifdef DEBUG_POWERTRANS
1147
  if (p==NIL)
1177
  if (p==NIL)
1148
  {
1178
  {
1149
    fprintf(as_file,"\n");
1179
    fprintf(as_file,"\n");
Line 1156... Line 1186...
1156
  fprintf(as_file,"\n");
1186
  fprintf(as_file,"\n");
1157
#endif
1187
#endif
1158
  return;
1188
  return;
1159
}
1189
}
1160
 
1190
 
1161
char * get_instruction PROTO_N ((ins)) PROTO_T (Instruction_P ins)
1191
char * get_instruction(Instruction_P ins)
1162
{
1192
{
1163
  char *w;
1193
  char *w;
1164
  switch(architecture)
1194
  switch (architecture)
1165
  {
1195
  {
1166
   case COMMON_CODE:
1196
   case COMMON_CODE:
1167
    w=ins->com;
1197
    w=ins->com;
1168
    break;
1198
    break;
1169
   case RS6000_CODE:
1199
   case RS6000_CODE: