Bluepsec Examples
Cyan Processor Types
Overview
This package contains the types (structures, enumerations, etc.) and helper functions common to the whole design. The structures and enumerations do much of the work of decoding instructions.
The code
package CyanTypes;
typedef Int#(32) WordT;
typedef enum {RgZero, Rg1, Rg2, Rg3, Rg4, Rg5, Rg6, Rg7,
Rg8, Rg9, Rg10, Rg11, Rg12, Rg13, Rg14, Rg15,
Rg16, Rg17, Rg18, Rg19, Rg20, Rg21, Rg22, Rg23,
Rg24, Rg25, Rg26, Rg27, Rg28, Rgfp, Rgsp, Rgra} RegT deriving (Bits, Eq, Bounded);
function Fmt reg2fmt(RegT r);
case (r)
RgZero: return $format("zero");
Rgfp: return $format("fp");
Rgsp: return $format("sp");
Rgra: return $format("ra");
default: return $format("r%1d",pack(r));
endcase
endfunction
// opcodes: N.B. if you change any of these you need to update mkDecode
typedef enum {OpOR, OpAND, OpADD, OpSUB, Op04, Op05, Op06, Op07,
OpORI, OpANDI, OpADDI, Op0b, Op0c, Op0d, Op0e, Op0f,
OpLOAD, OpSTORE, Op12, Op13, Op14, Op15, Op16, Op17,
OpBEQ, OpBNE, OpBLT, OpBLE, OpJSR, OpJR, Op1E, Op1F} OpcodeT deriving (Bits,Eq, Bounded);
typedef SizeOf#(OpcodeT) OpcodeT_size;
function String opcode2string(OpcodeT op);
case(op)
OpOR: return "OR";
OpAND: return "AND";
OpADD: return "ADD";
OpSUB: return "SUB";
OpORI: return "ORI";
OpANDI: return "ANDI";
OpADDI: return "ADDI";
OpLOAD: return "LOAD";
OpSTORE: return "STORE";
OpBEQ: return "BEQ";
OpBNE: return "BNE";
OpBLT: return "BLT";
OpBLE: return "BLE";
OpJSR: return "JSR";
OpJR: return "JR";
default: return "UNDEFINED";
endcase
endfunction
//typedef UInt#(5) RegT; // 32 registers
typedef Int#(12) ImmT; // 12-bits of immediate (constants)
typedef struct {
OpcodeT opcode; // 5-bits
RegT rd; // 5-bits
RegT ra; // 5-bits
RegT rb; // 5-bits
ImmT imm; //12-bits (total: 32-bits)
} InstructionT deriving (Bits, Eq, Bounded);
function InstructionT word2instruction(WordT w);
return unpack(pack(w));
endfunction
function WordT instruction2word(InstructionT i);
return unpack(pack(i));
endfunction
typedef UInt#(2) ThreadidT;
typedef struct {
WordT pc; // program counter
ThreadidT id; // thread ID
UInt#(32) inst_count; // instruction counter
} ContextT deriving (Bits, Eq, Bounded);
// ALU operations type
typedef enum { ALU_nop, ALU_or, ALU_and, ALU_add, ALU_sub } ALUopT deriving (Bits, Eq, Bounded);
typedef enum { MEM_nop, MEM_load, MEM_store } MEMopT deriving (Bits, Eq, Bounded);
typedef enum { BR_nop, BR_con, BR_jmp } BranchT deriving (Bits, Eq, Bounded);
typedef struct {
Bool imm; // flag indicating if operand B is an immediate
ALUopT alu; // ALU operation
MEMopT mem; // memory operation
BranchT br; // flag to indicate if branch or jump is taken
Bool wb; // flag to indicate if write-back should happen
} DecodedT deriving (Bits, Eq, Bounded);
typedef Tuple2#(ContextT,InstructionT) IFtokenT;
typedef struct {
ContextT contx;
InstructionT inst;
DecodedT dec;
WordT ra_src;
WordT rb_src;
WordT result;
} ControlTokenT deriving (Bits, Eq, Bounded);
typedef enum { Address_reset=0, Address_magic_output=512 } AddressMapT deriving (Bits, Eq, Bounded);
endpackage: CyanTypes
Link to the CyanTypes.bsv source