OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [cuc/] [load.c] - Blame information for rev 1062

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 879 markom
/* load.c -- OpenRISC Custom Unit Compiler, instruction loading and converting
2
 *    Copyright (C) 2002 Marko Mlinar, markom@opencores.org
3
 *
4
 *    This file is part of OpenRISC 1000 Architectural Simulator.
5
 *
6
 *    This program is free software; you can redistribute it and/or modify
7
 *    it under the terms of the GNU General Public License as published by
8
 *    the Free Software Foundation; either version 2 of the License, or
9
 *    (at your option) any later version.
10
 *
11
 *    This program is distributed in the hope that it will be useful,
12
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *    GNU General Public License for more details.
15
 *
16
 *    You should have received a copy of the GNU General Public License
17
 *    along with this program; if not, write to the Free Software
18
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
#include <stdio.h>
21
#include <stdlib.h>
22
#include <stdarg.h>
23
#include <assert.h>
24 897 markom
#include "sim-config.h"
25 879 markom
#include "cuc.h"
26
#include "opcode/or32.h"
27
#include "insn.h"
28
 
29
static const cuc_conv conv[] = {
30
{"l.add", II_ADD}, {"l.addi", II_ADD},
31 898 markom
{"l.movhi", II_OR},
32 879 markom
{"l.sub", II_SUB}, {"l.subi", II_SUB},
33
{"l.and", II_AND}, {"l.andi", II_AND},
34
{"l.xor", II_XOR}, {"l.xori", II_XOR},
35
{"l.or",  II_OR }, {"l.ori",  II_OR},
36
{"l.mul", II_MUL}, {"l.muli", II_MUL},
37
 
38
{"l.sra", II_SRA}, {"l.srai", II_SRA},
39
{"l.srl", II_SRL}, {"l.srli", II_SRL},
40
{"l.sll", II_SLL}, {"l.slli", II_SLL},
41
 
42
{"l.lbz",II_LB | II_MEM}, {"l.lbs", II_LB | II_MEM | II_SIGNED},
43
{"l.lhz",II_LH | II_MEM}, {"l.lhs", II_LH | II_MEM | II_SIGNED},
44
{"l.lwz",II_LW | II_MEM}, {"l.lws", II_LW | II_MEM | II_SIGNED},
45
{"l.sb", II_SB | II_MEM}, {"l.sh",  II_SH | II_MEM}, {"l.sw", II_SW | II_MEM},
46
{"l.sfeq",  II_SFEQ }, {"l.sfeqi", II_SFEQ},
47
{"l.sfne",  II_SFNE }, {"l.sfnei", II_SFNE},
48
{"l.sflts", II_SFLT | II_SIGNED}, {"l.sfltis", II_SFLT | II_SIGNED},
49
{"l.sfltu", II_SFLT}, {"l.sfltiu", II_SFLT},
50
{"l.sfgts", II_SFGT | II_SIGNED}, {"l.sfgtis", II_SFGT | II_SIGNED},
51
{"l.sfgtu", II_SFGT}, {"l.sfgtiu", II_SFGT},
52
{"l.sfges", II_SFGE | II_SIGNED}, {"l.sfgeis", II_SFGE | II_SIGNED},
53
{"l.sfgeu", II_SFGE}, {"l.sfgeiu", II_SFGE},
54
{"l.sfles", II_SFLE | II_SIGNED}, {"l.sfleis", II_SFLE | II_SIGNED},
55
{"l.sfleu", II_SFLE}, {"l.sfleiu", II_SFLE},
56
{"l.j",     II_BF   },
57
{"l.bf",    II_BF   },
58 906 markom
{"l.jal",   II_CALL },
59 879 markom
{"l.nop",   II_NOP  }
60
};
61
 
62
/* Instructions from function */
63
cuc_insn insn[MAX_INSNS];
64
int num_insn;
65
int reloc[MAX_INSNS];
66
 
67
/* Prints out instructions */
68
void print_cuc_insns (char *s, int verbose)
69
{
70
  int i, j;
71 997 markom
  PRINTF ("****************** %s ******************\n", s);
72 1062 markom
  print_insns (0, insn, num_insn,verbose);
73 997 markom
  PRINTF ("\n\n");
74 879 markom
}
75
 
76
void xchg_insn (int i, int j)
77
{
78
  cuc_insn t;
79
  t = insn[i];
80
  insn[i] = insn[j];
81
  insn[j] = t;
82
}
83
 
84 905 markom
/* Negates conditional instruction */
85
void negate_conditional (cuc_insn *ii)
86
{
87
  assert (ii->type & IT_COND);
88
 
89
  if (ii->index == II_SFEQ) change_insn_type (ii, II_SFNE);
90
  else if (ii->index == II_SFNE) change_insn_type (ii, II_SFEQ);
91
  else if (ii->index == II_SFLT) change_insn_type (ii, II_SFGE);
92
  else if (ii->index == II_SFGT) change_insn_type (ii, II_SFLE);
93
  else if (ii->index == II_SFLE) change_insn_type (ii, II_SFGT);
94
  else if (ii->index == II_SFGE) change_insn_type (ii, II_SFLT);
95
  else assert (0);
96
}
97
 
98 879 markom
/* Remove delay slots */
99
void remove_dslots ()
100
{
101
  int i;
102
  int in_delay = 0;
103
  for (i = 0; i < num_insn; i++) {
104
    if (in_delay) insn[i].type |= IT_INDELAY;
105
    in_delay = 0;
106
    if (insn[i].type & IT_BRANCH) in_delay = 1;
107
    if (insn[i].type & IT_INDELAY) {
108 1043 markom
      cuc_insn *ii;
109
      cuc_insn *bi;
110
      assert (i >= 2);
111
      ii = &insn[i - 2];
112
      bi = &insn[i - 1];
113 879 markom
      /* delay slot should not be a branch target! */
114
      assert ((insn[i].type & IT_BBSTART) == 0);
115 1043 markom
      assert ((bi->type & IT_INDELAY) == 0);
116 879 markom
      insn[i].type &= ~IT_INDELAY; /* no more in delay slot */
117 1043 markom
 
118
      /* Get the value we need before the actual jump */
119
      if (bi->opt[1] & OPT_REGISTER && bi->op[1] >= 0) {
120
        int r = bi->op[1];
121
        assert (ii->index == II_NOP);
122
        change_insn_type (ii, II_ADD);
123
        ii->type = IT_COND;
124
        ii->dep = NULL;
125
        ii->op[0] = r; ii->opt[0] = OPT_REGISTER | OPT_DEST;
126
        ii->op[1] = r; ii->opt[1] = OPT_REGISTER;
127
        ii->op[2] = 0; ii->opt[2] = OPT_CONST;
128
        ii->opt[3] = OPT_NONE;
129
        bi->op[1] = i - 2; bi->opt[1] = OPT_REF;
130
      }
131
      xchg_insn (i, i - 1);
132 879 markom
    }
133
  }
134
  assert (in_delay == 0);
135
}
136
 
137
/* Convert local variables (uses stack frame -- r1) to internal values */
138
void detect_locals ()
139
{
140
  int stack[MAX_STACK];
141
  int i, can_remove_stack = 1;
142
  int real_stack_size = 0;
143
 
144
  for (i = 0; i < MAX_STACK; i++) stack[i] = -1;
145
 
146
  for (i = 0; i < num_insn; i++) {
147
    /* sw off (r1),rx */
148
    if (insn[i].index == II_SW
149
      && (insn[i].opt[0] & OPT_CONST)
150
      && insn[i].op[1] == 1 && (insn[i].opt[1] & OPT_REGISTER)) {
151
 
152 883 markom
      if (insn[i].op[0] < MAX_STACK/* && insn[i].op[1] >= 4*/) { /* Convert to normal move */
153 879 markom
        stack[insn[i].op[0]] = i;
154
        insn[i].type &= IT_INDELAY | IT_BBSTART;
155
        change_insn_type (&insn[i], II_ADD);
156
        insn[i].op[0] = -1; insn[i].opt[0] = OPT_REGISTER | OPT_DEST;
157
        insn[i].op[1] = insn[i].op[2]; insn[i].opt[1] = insn[i].opt[2];
158
        insn[i].op[2] = 0; insn[i].opt[2] = OPT_CONST;
159
      } else can_remove_stack = 0;
160
    /* lw rx,off (r1) */
161
    } else if (insn[i].index == II_LW
162
      && (insn[i].opt[1] & OPT_CONST)
163
      && insn[i].op[2] == 1 && (insn[i].opt[2] & OPT_REGISTER)) {
164
 
165 883 markom
      if (insn[i].op[1] < MAX_STACK && stack[insn[i].op[1]] >= 0) { /* Convert to normal move */
166 879 markom
        insn[i].type &= IT_INDELAY | IT_BBSTART;
167
        change_insn_type (&insn[i], II_ADD);
168
        insn[i].op[1] = stack[insn[i].op[1]]; insn[i].opt[1] = OPT_REF;
169
        insn[i].op[2] = 0; insn[i].opt[2] = OPT_CONST;
170
      } else can_remove_stack = 0;
171
    /* Check for defined stack size */
172
    } else if (insn[i].index == II_ADD && !real_stack_size
173
            && (insn[i].opt[0] & OPT_REGISTER) && insn[i].op[0] == 1
174
            && (insn[i].opt[1] & OPT_REGISTER) && insn[i].op[1] == 1
175
            && (insn[i].opt[2] & OPT_CONST)) {
176
      real_stack_size = -insn[i].op[2];
177
    }
178
  }
179 883 markom
  //assert (can_remove_stack); /* TODO */  
180 879 markom
}
181
 
182
/* Disassemble one instruction from insn index and generate parameters */
183
const char *build_insn (unsigned long data, cuc_insn *insn)
184
{
185
  const char *name;
186
  char *s;
187
  extern char *disassembled;
188
  int index = insn_decode (data);
189
  struct or32_opcode const *opcode;
190
  int i, argc = 0;
191
 
192
  insn->insn = data;
193
  insn->index = -1;
194
  insn->type = 0;
195
  name = insn_name (index);
196
  insn->index = index;
197
  disassemble_index (data, index);
198
  strcpy (insn->disasm, disassembled);
199
  insn->dep = NULL;
200
  for (i = 0; i < MAX_OPERANDS; i++) insn->opt[i] = OPT_NONE;
201
 
202
  if (index < 0) {
203
    fprintf (stderr, "Invalid opcode 0x%08x!\n", data);
204
    exit (1);
205
  }
206
  opcode = &or32_opcodes[index];
207
 
208
  for (s = opcode->args; *s != '\0'; ++s) {
209
    switch (*s) {
210
    case '\0': return name;
211
    case 'r':
212
      insn->opt[argc] = OPT_REGISTER | (argc ? 0 : OPT_DEST);
213
      insn->op[argc++] = or32_extract(*++s, opcode->encoding, data);
214
      break;
215
 
216
    default:
217
      if (strchr (opcode->encoding, *s)) {
218
        unsigned long imm = or32_extract (*s, opcode->encoding, data);
219
        imm = extend_imm(imm, *s);
220
        insn->opt[argc] = OPT_CONST;
221
        insn->op[argc++] = imm;
222
      }
223
    }
224
  }
225
  return name;
226
}
227
 
228 1043 markom
/* inserts nop before branch */
229
void expand_branch ()
230
{
231
  int i, j, num_bra = 0, d;
232
  for (i = 0; i < num_insn; i++) if (insn[i].type & IT_BRANCH) num_bra++;
233
 
234 1062 markom
  d = num_insn + 2 * num_bra;
235 1043 markom
  assert (d < MAX_INSNS);
236
 
237 1061 markom
  /* Add nop before branch */
238 1043 markom
  for (i = num_insn - 1; i >= 0; i--) if (insn[i].type & IT_BRANCH) {
239 1062 markom
    insn[--d] = insn[i]; // for delay slot (later)
240
    if (insn[d].opt[1] & OPT_REGISTER) {
241
      assert (insn[d].op[1] == FLAG_REG);
242
      insn[d].op[1] = i; insn[d].opt[1] = OPT_REF;
243
    }
244
    insn[--d] = insn[i]; // for branch
245
    change_insn_type (&insn[d], II_NOP);
246
    insn[--d] = insn[i]; // save flag & negation of conditional, if required
247
    change_insn_type (&insn[d], II_CMOV);
248
    insn[d].op[0] = -1; insn[d].opt[0] = OPT_REGISTER | OPT_DEST;
249
    insn[d].op[1] = insn[d].type & IT_FLAG1 ? 0 : 1; insn[d].opt[1] = OPT_CONST;
250
    insn[d].op[2] = insn[d].type & IT_FLAG1 ? 1 : 0; insn[d].opt[2] = OPT_CONST;
251
    insn[d].op[3] = FLAG_REG; insn[d].opt[3] = OPT_REGISTER;
252
    insn[d].type = IT_COND;
253
    if (insn[d].type)
254 1043 markom
    reloc[i] = d;
255
  } else {
256
    insn[--d] = insn[i];
257
    reloc[i] = d;
258
  }
259 1062 markom
  num_insn += 2 * num_bra;
260 1043 markom
  for (i = 0; i < num_insn; i++)
261
    for (j = 0; j < MAX_OPERANDS; j++)
262
      if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP)
263
        insn[i].op[j] = reloc[insn[i].op[j]];
264
}
265
 
266 879 markom
/* expands immediate memory instructions to two */
267
void expand_memory ()
268
{
269
  int i, j, num_mem = 0, d;
270
  for (i = 0; i < num_insn; i++) if (insn[i].type & IT_MEMORY) num_mem++;
271
 
272
  d = num_insn + num_mem;
273
  assert (d < MAX_INSNS);
274
 
275
  /* Split memory commands */
276
  for (i = num_insn - 1; i >= 0; i--) if (insn[i].type & IT_MEMORY) {
277
    insn[--d] = insn[i];
278
    insn[--d] = insn[i];
279
    reloc[i] = d;
280
    switch (insn[d].index) {
281
    case II_SW:
282
    case II_SH:
283
    case II_SB:
284 1060 markom
              insn[d + 1].op[1] = d; insn[d + 1].opt[1] = OPT_REF; /* sw rx,(t($-1)) */
285
              insn[d + 1].op[0] = insn[i].op[2]; insn[d + 1].opt[0] = insn[d + 1].opt[2];
286
              insn[d + 1].opt[2] = OPT_NONE;
287
              insn[d + 1].type &= ~IT_BBSTART;
288 1061 markom
              insn[d].op[2] = insn[d].op[0]; insn[d].opt[2] = insn[d].opt[0];
289 879 markom
              insn[d].op[0] = -1; insn[d].opt[0] = OPT_REGISTER | OPT_DEST; /* add rd, ra, rb */
290
              insn[d].opt[3] = OPT_NONE;
291
              insn[d].type &= IT_INDELAY | IT_BBSTART;
292
              insn[d].type |= IT_MEMADD;
293
              change_insn_type (&insn[d], II_ADD);
294
              break;
295
    case II_LW:
296
    case II_LH:
297
    case II_LB:
298
              insn[d].op[0] = -1; insn[d].opt[0] = OPT_REGISTER | OPT_DEST; /* add rd, ra, rb */
299
              insn[d].type &= IT_INDELAY | IT_BBSTART;
300
              insn[d].type |= IT_MEMADD;
301
              change_insn_type (&insn[d], II_ADD);
302
              insn[d + 1].op[1] = d; insn[d + 1].opt[1] = OPT_REF; /* lw (t($-1)),rx */
303
              insn[d + 1].opt[2] = OPT_NONE;
304
              insn[d + 1].opt[3] = OPT_NONE;
305
              insn[d + 1].type &= ~IT_BBSTART;
306
              break;
307
    default:  fprintf (stderr, "%4i, %4i: %s\n", i, d, cuc_insn_name (&insn[d]));
308
              assert (0);
309
    }
310
  } else {
311
    insn[--d] = insn[i];
312
    reloc[i] = d;
313
  }
314
  num_insn += num_mem;
315
  for (i = 0; i < num_insn; i++) if (!(insn[i].type & IT_MEMORY))
316
    for (j = 0; j < MAX_OPERANDS; j++)
317
      if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP)
318
        insn[i].op[j] = reloc[insn[i].op[j]];
319
}
320
 
321
/* expands signed comparisons to three instructions */
322
void expand_signed ()
323
{
324
  int i, j, num_sig = 0, d;
325 897 markom
  for (i = 0; i < num_insn; i++)
326
    if (insn[i].type & IT_SIGNED && !(insn[i].type & IT_MEMORY)) num_sig++;
327 879 markom
 
328
  d = num_insn + num_sig * 2;
329
  assert (d < MAX_INSNS);
330
 
331
  /* Split signed instructions */
332 897 markom
  for (i = num_insn - 1; i >= 0; i--)
333 879 markom
    /* We will expand signed memory later */
334 897 markom
    if (insn[i].type & IT_SIGNED && !(insn[i].type & IT_MEMORY)) {
335
      insn[--d] = insn[i];
336
      insn[d].op[1] = d - 2; insn[d].opt[1] = OPT_REF;
337
      insn[d].op[2] = d - 1; insn[d].opt[2] = OPT_REF;
338 879 markom
 
339 897 markom
      insn[--d] = insn[i];
340
      change_insn_type (&insn[d], II_ADD);
341
      insn[d].type = 0;
342
      insn[d].op[0] = -1; insn[d].opt[0] = OPT_REGISTER | OPT_DEST;
343
      insn[d].op[1] = insn[d].op[2]; insn[d].opt[1] = insn[d].opt[2];
344 905 markom
      insn[d].op[2] = 0x80000000; insn[d].opt[2] = OPT_CONST;
345 897 markom
      insn[d].opt[3] = OPT_NONE;
346 879 markom
 
347 897 markom
      insn[--d] = insn[i];
348
      change_insn_type (&insn[d], II_ADD);
349
      insn[d].type = 0;
350
      insn[d].op[0] = -1; insn[d].opt[0] = OPT_REGISTER | OPT_DEST;
351
      insn[d].op[1] = insn[d].op[1]; insn[d].opt[1] = insn[d].opt[1];
352 905 markom
      insn[d].op[2] = 0x80000000; insn[d].opt[2] = OPT_CONST;
353 897 markom
      insn[d].opt[3] = OPT_NONE;
354 879 markom
 
355 897 markom
      reloc[i] = d;
356
    } else {
357
      insn[--d] = insn[i];
358
      reloc[i] = d;
359
    }
360 879 markom
  num_insn += num_sig * 2;
361
  for (i = 0; i < num_insn; i++) if (insn[i].type & IT_MEMORY || !(insn[i].type & IT_SIGNED)) {
362
    for (j = 0; j < MAX_OPERANDS; j++)
363
      if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP)
364
        insn[i].op[j] = reloc[insn[i].op[j]];
365
  } else insn[i].type &= ~IT_SIGNED;
366
}
367
 
368 906 markom
/* expands calls to 7 instructions */
369
void expand_calls ()
370
{
371
  int i, j, num_call = 0, d;
372
  for (i = 0; i < num_insn; i++)
373
    if (insn[i].index == II_CALL) num_call++;
374
 
375
  d = num_insn + num_call * 6; /* 6 parameters */
376
  assert (d < MAX_INSNS);
377
 
378
  /* Split call instructions */
379
  for (i = num_insn - 1; i >= 0; i--)
380
    /* We will expand signed memory later */
381
    if (insn[i].index == II_CALL) {
382
      insn[--d] = insn[i];
383
      insn[d].op[0] = insn[d].op[1]; insn[d].opt[0] = OPT_CONST;
384
      insn[d].opt[1] = OPT_NONE;
385
      insn[d].type |= IT_VOLATILE;
386
 
387
      for (j = 0; j < 6; j++) {
388
        insn[--d] = insn[i];
389
        change_insn_type (&insn[d], II_ADD);
390
        insn[d].type = IT_VOLATILE;
391
        insn[d].op[0] = 3 + j; insn[d].opt[0] = OPT_REGISTER | OPT_DEST;
392
        insn[d].op[1] = 3 + j; insn[d].opt[1] = OPT_REGISTER;
393
        insn[d].op[2] = 0x80000000; insn[d].opt[2] = OPT_CONST;
394
        insn[d].opt[3] = OPT_NONE;
395
      }
396
 
397
      reloc[i] = d;
398
    } else {
399
      insn[--d] = insn[i];
400
      reloc[i] = d;
401
    }
402
  num_insn += num_call * 6;
403
  for (i = 0; i < num_insn; i++)
404
    for (j = 0; j < MAX_OPERANDS; j++)
405
      if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP)
406
        insn[i].op[j] = reloc[insn[i].op[j]];
407
}
408
 
409 897 markom
/* Loads function from file into global array insn.
410
   Function returns nonzero if function cannot be converted. */
411
int cuc_load (char *in_fn)
412 879 markom
{
413
  int i, j, in_delay;
414
  FILE *fi;
415
  int func_return = 0;
416
  num_insn = 0;
417
 
418
  log ("Loading filename %s\n", in_fn);
419
  if ((fi = fopen (in_fn, "rt")) == NULL) {
420
    fprintf (stderr, "Cannot open '%s'\n", in_fn);
421
    exit (1);
422
  }
423
  /* Read in the function and decode the instructions */
424
  for (i = 0;; i++) {
425
    unsigned long data;
426
    extern char *disassembled;
427
    const char *name;
428
 
429
    if (fscanf (fi, "%08x\n", &data) != 1) break;
430
 
431
    /* build params */
432
    name = build_insn (data, &insn[i]);
433
    if (func_return) func_return++;
434 997 markom
    //PRINTF ("%s\n", name);
435 879 markom
 
436
    if (or32_opcodes[insn[i].index].flags & OR32_IF_DELAY) {
437
      int f;
438
      if (strcmp (name, "l.bnf") == 0) f = 1;
439
      else if (strcmp (name, "l.bf") == 0) f = 0;
440
      else if (strcmp (name, "l.j") == 0) {
441
        f = -1;
442
      } else if (strcmp (name, "l.jr") == 0 && func_return == 0) {
443
        func_return = 1;
444
        change_insn_type (&insn[i], II_NOP);
445
        continue;
446
      } else {
447 897 markom
        cucdebug (1, "Instruction #%i: \"%s\" not supported.\n", i, name);
448
        log ("Instruction #%i: \"%s\" not supported.\n", i, name);
449
        return 1;
450 879 markom
      }
451
      if (f < 0) { /* l.j */
452
        /* repair params */
453
        change_insn_type (&insn[i], II_BF);
454
        insn[i].op[0] = i + insn[i].op[0]; insn[i].opt[0] = OPT_JUMP;
455
        insn[i].op[1] = 1; insn[i].opt[1] = OPT_CONST;
456
        insn[i].type |= IT_BRANCH | IT_VOLATILE;
457
      } else {
458
        change_insn_type (&insn[i], II_BF);
459
        insn[i].op[0] = i + insn[i].op[0]; insn[i].opt[0] = OPT_JUMP;
460
        insn[i].op[1] = FLAG_REG; insn[i].opt[1] = OPT_REGISTER;
461
        insn[i].type |= IT_BRANCH | IT_VOLATILE;
462 1062 markom
        if (f) insn[i].type |= IT_FLAG1;
463 879 markom
      }
464
    } else {
465
      insn[i].index = -1;
466
      for (j = 0; j < sizeof (conv) / sizeof (cuc_conv); j++)
467
        if (strcmp (conv[j].from, name) == 0) {
468
          const int x = conv[j].to;
469
          if (conv[j].to & II_SIGNED) insn[i].type |= IT_SIGNED;
470
          if (conv[j].to & II_MEM) insn[i].type |= IT_MEMORY | IT_VOLATILE;
471
          change_insn_type (&insn[i], conv[j].to & II_MASK);
472
          break;
473
        }
474 898 markom
      if (strcmp (name, "l.movhi") == 0) {
475
        insn[i].op[1] <<= 16;
476
        insn[i].op[2] = 0;
477
        insn[i].opt[2] = OPT_CONST;
478
      }
479 1062 markom
      if (insn[i].index == II_SFEQ || insn[i].index == II_SFNE
480
       || insn[i].index == II_SFLE || insn[i].index == II_SFGT
481
       || insn[i].index == II_SFGE || insn[i].index == II_SFLT) {
482
        /* repair params */
483
        insn[i].op[2] = insn[i].op[1]; insn[i].opt[2] = insn[i].opt[1] & ~OPT_DEST;
484
        insn[i].op[1] = insn[i].op[0]; insn[i].opt[1] = insn[i].opt[0] & ~OPT_DEST;
485
        insn[i].op[0] = FLAG_REG; insn[i].opt[0] = OPT_DEST | OPT_REGISTER;
486
        insn[i].opt[3] = OPT_NONE;
487
        insn[i].type |= IT_COND;
488
      }
489 897 markom
      if (insn[i].index < 0 || insn[i].index == II_NOP && insn[i].op[0] != 0) {
490
        cucdebug (1, "Instruction #%i: \"%s\" not supported (2).\n", i, name);
491
        log ("Instruction #%i: \"%s\" not supported (2).\n", i, name);
492
        return 1;
493 879 markom
      }
494
    }
495
  }
496
  num_insn = i;
497
  fclose (fi);
498
  if (func_return != 2) {
499 897 markom
    cucdebug (1, "Unsupported function structure.\n");
500
    log ("Unsupported function structure.\n");
501
    return 1;
502 879 markom
  }
503
 
504
  log ("Number of instructions loaded = %i\n", num_insn);
505 883 markom
  if (cuc_debug >= 3) print_cuc_insns ("INITIAL", 1);
506 879 markom
 
507
  log ("Converting.\n");
508 1043 markom
  expand_branch ();
509
  if (cuc_debug >= 6) print_cuc_insns ("AFTER_EXP_BRANCH", 0);
510
 
511 879 markom
  remove_dslots ();
512 883 markom
  if (cuc_debug >= 6) print_cuc_insns ("NO_DELAY_SLOTS", 0);
513 879 markom
 
514 897 markom
  if (config.cuc.calling_convention) {
515 879 markom
    detect_locals ();
516 883 markom
    if (cuc_debug >= 7) print_cuc_insns ("AFTER_LOCALS", 0);
517 879 markom
  }
518
  expand_memory ();
519 883 markom
  if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_MEM", 0);
520 879 markom
 
521
  expand_signed ();
522 883 markom
  if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_SIG", 0);
523 906 markom
 
524
  expand_calls ();
525
  if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_CALLS", 0);
526 1043 markom
 
527 897 markom
  return 0;
528 879 markom
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.