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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [monitor/] [monitor/] [common/] [instr.c] - Blame information for rev 317

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

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

powered by: WebSVN 2.1.0

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