-
Notifications
You must be signed in to change notification settings - Fork 2
/
Execute.bsv
executable file
·56 lines (45 loc) · 1.54 KB
/
Execute.bsv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// import Common::*;
import ProcTypes::*;
import ALU::*;
// ALU
///////////////////////////////////////////////////////////////////////////
// `include "hiddenALU.bsv"
function Bool aluBr(Word a, Word b, BrFunc brFunc);
Bool res = case (brFunc)
Eq: (a == b);
Neq: (a != b);
Lt: signedLT(a, b);
Ltu: (a < b);
Ge: signedGE(a, b);
Geu: (a >= b);
AT: True;
NT: False;
endcase;
return res;
endfunction
function ExecInst execute( DecodedInst dInst, Word rVal1, Word rVal2, Word pc );
let imm = dInst.imm;
let brFunc = dInst.brFunc;
let aluFunc = dInst.aluFunc;
Word data = ?;
Word nextPc = ?;
Word addr = ?;
case (dInst.iType) matches
OP: begin data = alu(rVal1, rVal2, aluFunc); nextPc = pc+4; end
OPIMM: begin data = alu(rVal1, imm, aluFunc); nextPc = pc+4; end
BRANCH: begin nextPc = aluBr(rVal1, rVal2, brFunc) ? pc+imm : pc+4; end
LUI: begin data = imm; nextPc = pc+4; end
JAL: begin data = pc+4; nextPc = pc+imm; end
JALR: begin data = pc+4; nextPc = rcaN(rVal1,imm,0) & ~1; end
LOAD: begin addr = rcaN(rVal1, imm, 0); nextPc = pc+4; end
STORE: begin data = rVal2; addr = rcaN(rVal1, imm, 0); nextPc = pc+4; end
AUIPC: begin data = rcaN(pc, imm, 0); nextPc = pc+4; end
endcase
ExecInst eInst = ?;
eInst.iType = dInst.iType;
eInst.dst = dInst.dst;
eInst.data = data;
eInst.addr = addr;
eInst.nextPc = nextPc;
return eInst;
endfunction