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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [cuc/] [load.c] - Blame information for rev 1308

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