exec.c 1.9 KB
Newer Older
Z
Zihao Yu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include "cpu/exec.h"
#include "all-instr.h"

static OpcodeEntry load_table [8] = {
  EMPTY, EMPTY, EXW(ld, 4), EMPTY, EMPTY, EMPTY, EMPTY, EMPTY
};

static make_EHelper(load) {
  decinfo.width = load_table[decinfo.isa.instr.funct3].width;
  idex(eip, &load_table[decinfo.isa.instr.funct3]);
}

static OpcodeEntry store_table [8] = {
  EMPTY, EMPTY, EXW(st, 4), EMPTY, EMPTY, EMPTY, EMPTY, EMPTY
};

static make_EHelper(store) {
  decinfo.width = store_table[decinfo.isa.instr.funct3].width;
  idex(eip, &store_table[decinfo.isa.instr.funct3]);
}

Z
Zihao Yu 已提交
22
static OpcodeEntry op_imm_table [8] = {
Z
Zihao Yu 已提交
23
  EX(add), EX(sll), EMPTY, EX(sltu), EMPTY, EX(srl), EMPTY, EX(and)
Z
Zihao Yu 已提交
24 25 26 27 28 29
};

static make_EHelper(op_imm) {
  idex(eip, &op_imm_table[decinfo.isa.instr.funct3]);
}

Z
Zihao Yu 已提交
30
static OpcodeEntry op_table [8] = {
31 32 33 34 35
  EX(add), EMPTY, EX(slt), EX(sltu), EX(xor), EMPTY, EX(or), EMPTY
};

static OpcodeEntry op2_table [8] = {
  EX(sub), EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY
Z
Zihao Yu 已提交
36 37
};

Z
Zihao Yu 已提交
38 39 40 41
static OpcodeEntry muldiv_table [8] = {
  EX(mul), EX(mulh), EMPTY, EMPTY, EX(div), EMPTY, EX(rem), EMPTY
};

Z
Zihao Yu 已提交
42
static make_EHelper(op) {
43 44
  switch (decinfo.isa.instr.funct7) {
    case 0:  idex(eip, &op_table[decinfo.isa.instr.funct3]); break;
Z
Zihao Yu 已提交
45
    case 1:  idex(eip, &muldiv_table[decinfo.isa.instr.funct3]); break;
46 47 48
    case 32: idex(eip, &op2_table[decinfo.isa.instr.funct3]); break;
    default: assert(0);
  }
Z
Zihao Yu 已提交
49 50
}

Z
Zihao Yu 已提交
51
static OpcodeEntry opcode_table [32] = {
Z
Zihao Yu 已提交
52
  /* b00 */ IDEX(ld, load), EMPTY, EMPTY, EMPTY, IDEX(I, op_imm), IDEX(U, auipc), EMPTY, EMPTY,
Z
Zihao Yu 已提交
53
  /* b01 */ IDEX(st, store), EMPTY, EMPTY, EMPTY, IDEX(R, op), IDEX(U, lui), EMPTY, EMPTY,
Z
Zihao Yu 已提交
54
  /* b10 */ EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
Z
Zihao Yu 已提交
55
  /* b11 */ IDEX(B, branch), IDEX(I, jalr), EX(nemu_trap), IDEX(J, jal), EMPTY, EMPTY, EMPTY, EMPTY,
Z
Zihao Yu 已提交
56 57 58 59 60 61 62
};

make_EHelper(isa) {
  decinfo.isa.instr.val = instr_fetch(eip, 4);
  assert(decinfo.isa.instr.opcode1_0 == 0x3);
  idex(eip, &opcode_table[decinfo.isa.instr.opcode6_2]);
}