diff options
Diffstat (limited to 'src/common.svh')
-rw-r--r-- | src/common.svh | 115 |
1 files changed, 114 insertions, 1 deletions
diff --git a/src/common.svh b/src/common.svh index 42fdb71..67a87d2 100644 --- a/src/common.svh +++ b/src/common.svh @@ -1,6 +1,119 @@ `ifndef __COMMON_SVH__ `define __COMMON_SVH__ -`define NOP 0 +`define RV_OP_FIELD 6:0 +typedef logic [31:0] rv_t; +typedef logic [31:0] xlen_t; + +typedef struct packed { + logic [6:0] funct7; + logic [4:0] rs2; + logic [4:0] rs1; + logic [2:0] funct3; + logic [4:0] rd; + logic [6:0] op; +} rtype_t; + +typedef struct packed { + logic [11:0] imm; + logic [4:0] rs1; + logic [2:0] funct3; + logic [4:0] rd; + logic [6:0] op; +} itype_t; + +typedef struct packed { + logic [6:0] imm1; + logic [4:0] rs2; + logic [4:0] rs1; + logic [2:0] funct3; + logic [4:0] imm0; + logic [6:0] op; +} stype_t; + +typedef struct packed { + logic [0:0] imm3; + logic [5:0] imm2; + logic [4:0] rs2; + logic [4:0] rs1; + logic [2:0] funct3; + logic [3:0] imm1; + logic [0:0] imm0; + logic [6:0] op; +} btype_t; + +typedef struct packed { + logic [19:0] imm; + logic [4:0] rd; + logic [6:0] op; +} utype_t; + +typedef struct packed { + logic [0:0] imm3; + logic [9:0] imm2; + logic [0:0] imm1; + logic [7:0] imm0; + logic [4:0] rd; + logic [6:0] op; +} jtype_t; + +typedef enum logic [6:0] { + LOAD = 7'b0000011, + LOAD_FP = 7'b0000111, + MISC_MEM = 7'b0001111, + OP_IMM = 7'b0010011, + AUIPC = 7'b0010111, + OP_IMM_32 = 7'b0011011, + + STORE = 7'b0100011, + STORE_FP = 7'b0100111, + AMO = 7'b0101111, + OP = 7'b0110011, + LUI = 7'b0110111, + OP_32 = 7'b0111011, + + MADD = 7'b1000011, + MSUB = 7'b1000111, + NMSUB = 7'b1001011, + NMADD = 7'b1001111, + OP_FP = 7'b1010011, + + BRANCH = 7'b1100011, + JALR = 7'b1100111, + JAL = 7'b1101111, + SYSTEM = 7'b1110011 +} opcode_t; + +typedef logic[7:0] port_t; + +typedef enum port_t { + NOP = 8'b00000000, + REG = 8'b00100000, + ALU = 8'b01000000 +} port_base_t; + +typedef struct packed { + port_t src; + port_t dst; +} mov_t; + +typedef logic[7:0] op_t; +typedef logic[19:0] imm_t; + +typedef struct packed { + mov_t[1:0] in; + mov_t out; + op_t op; + imm_t imm; +} insn_t; + +typedef enum op_t { + ALU_ADD, + ALU_SUB, + ALU_ADDI +} alu_op_t; + +`define rn(r) (REG + port_t'(r)) +`define alu(fu) (ALU + port_t'(fu)) `endif /* __COMMON_SVH__ */ |