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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [instr.c] - Blame information for rev 98

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

Line No. Rev Author Line
1 8 hellwig
/*
2
 * instr.c -- instruction encoding
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
#include "common.h"
11
#include "console.h"
12
#include "error.h"
13
#include "instr.h"
14
 
15
 
16
/*
17
 * This is the ECO32 machine instruction set.
18
 * The table below needs no particular order
19
 * and may have gaps in the instruction encoding.
20
 */
21
Instr instrTbl[] = {
22
  { "add",   FORMAT_RRY, OP_ADD  },
23
  { "sub",   FORMAT_RRY, OP_SUB  },
24
  { "mul",   FORMAT_RRY, OP_MUL  },
25
  { "mulu",  FORMAT_RRX, OP_MULU },
26
  { "div",   FORMAT_RRY, OP_DIV  },
27
  { "divu",  FORMAT_RRX, OP_DIVU },
28
  { "rem",   FORMAT_RRY, OP_REM  },
29
  { "remu",  FORMAT_RRX, OP_REMU },
30
  { "and",   FORMAT_RRX, OP_AND  },
31
  { "or",    FORMAT_RRX, OP_OR   },
32
  { "xor",   FORMAT_RRX, OP_XOR  },
33
  { "xnor",  FORMAT_RRX, OP_XNOR },
34
  { "sll",   FORMAT_RRX, OP_SLL  },
35
  { "slr",   FORMAT_RRX, OP_SLR  },
36
  { "sar",   FORMAT_RRX, OP_SAR  },
37
  { "ldhi",  FORMAT_RHH, OP_LDHI },
38
  { "beq",   FORMAT_RRB, OP_BEQ  },
39
  { "bne",   FORMAT_RRB, OP_BNE  },
40
  { "ble",   FORMAT_RRB, OP_BLE  },
41
  { "bleu",  FORMAT_RRB, OP_BLEU },
42
  { "blt",   FORMAT_RRB, OP_BLT  },
43
  { "bltu",  FORMAT_RRB, OP_BLTU },
44
  { "bge",   FORMAT_RRB, OP_BGE  },
45
  { "bgeu",  FORMAT_RRB, OP_BGEU },
46
  { "bgt",   FORMAT_RRB, OP_BGT  },
47
  { "bgtu",  FORMAT_RRB, OP_BGTU },
48
  { "j",     FORMAT_J,   OP_J    },
49
  { "jr",    FORMAT_JR,  OP_JR   },
50
  { "jal",   FORMAT_J,   OP_JAL  },
51
  { "jalr",  FORMAT_JR,  OP_JALR },
52
  { "trap",  FORMAT_N,   OP_TRAP },
53
  { "rfx",   FORMAT_N,   OP_RFX  },
54
  { "ldw",   FORMAT_RRS, OP_LDW  },
55
  { "ldh",   FORMAT_RRS, OP_LDH  },
56
  { "ldhu",  FORMAT_RRS, OP_LDHU },
57
  { "ldb",   FORMAT_RRS, OP_LDB  },
58
  { "ldbu",  FORMAT_RRS, OP_LDBU },
59
  { "stw",   FORMAT_RRS, OP_STW  },
60
  { "sth",   FORMAT_RRS, OP_STH  },
61
  { "stb",   FORMAT_RRS, OP_STB  },
62
  { "mvfs",  FORMAT_RH,  OP_MVFS },
63
  { "mvts",  FORMAT_RH,  OP_MVTS },
64
  { "tbs",   FORMAT_N,   OP_TBS  },
65
  { "tbwr",  FORMAT_N,   OP_TBWR },
66
  { "tbri",  FORMAT_N,   OP_TBRI },
67
  { "tbwi",  FORMAT_N,   OP_TBWI }
68
};
69
 
70
 
71
Instr *instrCodeTbl[64];
72
 
73
 
74
static int instrCompare(const void *instr1, const void *instr2) {
75
  return strcmp(((Instr *) instr1)->name, ((Instr *) instr2)->name);
76
}
77
 
78
 
79
void initInstrTable(void) {
80
  int i;
81
 
82
  /* first sort instruction table alphabetically */
83
  qsort(instrTbl, sizeof(instrTbl)/sizeof(instrTbl[0]),
84
        sizeof(instrTbl[0]), instrCompare);
85
  /* then initialize instruction code table */
86
  for (i = 0; i < 64; i++) {
87
    instrCodeTbl[i] = NULL;
88
  }
89
  for (i = 0; i < sizeof(instrTbl)/sizeof(instrTbl[0]); i++) {
90
    instrCodeTbl[instrTbl[i].opcode] = &instrTbl[i];
91
    if (instrTbl[i].format == FORMAT_RRX ||
92
        instrTbl[i].format == FORMAT_RRY) {
93
      /* enter the immediate variant of this instruction also */
94
      instrCodeTbl[instrTbl[i].opcode + 1] = &instrTbl[i];
95
    }
96
  }
97
}
98
 
99
 
100
Instr *lookupInstr(char *name) {
101
  int lo, hi, tst;
102
  int res;
103
 
104
  lo = 0;
105
  hi = sizeof(instrTbl) / sizeof(instrTbl[0]) - 1;
106
  while (lo <= hi) {
107
    tst = (lo + hi) / 2;
108
    res = strcmp(instrTbl[tst].name, name);
109
    if (res == 0) {
110
      return &instrTbl[tst];
111
    }
112
    if (res < 0) {
113
      lo = tst + 1;
114
    } else {
115
      hi = tst - 1;
116
    }
117
  }
118
  return NULL;
119
}

powered by: WebSVN 2.1.0

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