-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCUDecoder.sv
More file actions
122 lines (106 loc) · 2.96 KB
/
CUDecoder.sv
File metadata and controls
122 lines (106 loc) · 2.96 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
`timescale 1ns / 1ps
module CUDecoder(
input BR_EQ, BR_LT, BR_LTU,CLK,
input [2:0] FUNC3,
input [6:0] FUNC7, CU_OPCODE,
input INT_TAKEN,
output logic [3:0] ALU_FUN,
output logic [2:0] PC_SOURCE,
output logic [1:0] ALU_SRCB,
output logic [1:0] RF_WR_SEL,
output logic ALU_SRCA
);
// Create enumberation data type for the opcode.
//Symbols tied to bit values
typedef enum logic [6:0] {
LUI = 7'b0110111,
AUIPC = 7'b0010111,
JAL = 7'b1101111,
JALR = 7'b1100111,
BRANCH = 7'b1100011,
LOAD = 7'b0000011,
STORE = 7'b0100011,
OP_IMM = 7'b0010011,
OP = 7'b0110011,
SYSTEM = 7'b1110011
} opcode_t;
opcode_t OPCODE; //Define variable of
//newly defined type
//Cast input bits as enum, for showing opcode
//names during simulation
assign OPCODE = opcode_t'(CU_OPCODE);
always@*
if (OPCODE == 7'b0110111) //LIU
begin
ALU_FUN = 9; ALU_SRCA = 1; ALU_SRCB = 0; PC_SOURCE = 0;RF_WR_SEL = 3;
end
else if (OPCODE == 7'b0010111) //AUIPC
begin
ALU_FUN = 0; ALU_SRCA = 1; ALU_SRCB = 3; PC_SOURCE = 0; RF_WR_SEL = 3;
end
else if (OPCODE == 7'b1101111) //JAL
begin
ALU_FUN = 0; ALU_SRCA = 0; ALU_SRCB = 0; PC_SOURCE = 3; RF_WR_SEL = 0;
end
else if (OPCODE == 7'b1100111) //JALR
begin
ALU_FUN = 0; ALU_SRCA = 0; ALU_SRCB = 0; PC_SOURCE = 1; RF_WR_SEL = 0;
end
else if (OPCODE == 7'b1100011) //BRANCH
begin
ALU_FUN = 0; ALU_SRCA = 0; ALU_SRCB = 0; RF_WR_SEL = 0;
if (FUNC3 ==0 && BR_EQ ==1)
PC_SOURCE = 2;
else if
(FUNC3 ==1 && BR_EQ ==0)
PC_SOURCE = 2;
else if
(FUNC3 ==4 && BR_LT ==1)
PC_SOURCE = 2;
else if
(FUNC3 ==5 && BR_LT ==0)
PC_SOURCE = 2;
else if
(FUNC3 ==6 && BR_LTU ==1)
PC_SOURCE = 2;
else if
(FUNC3 ==7 && BR_LTU ==0)
PC_SOURCE = 2;
else
PC_SOURCE =0;
end
else if (OPCODE == 7'b0000011) //LOAD
begin
ALU_FUN = 0; ALU_SRCA = 0; ALU_SRCB = 1; PC_SOURCE = 0; RF_WR_SEL = 2;
end
else if (OPCODE == 7'b0100011) //STORE
begin
ALU_FUN = 0; ALU_SRCA = 0; ALU_SRCB = 2; PC_SOURCE = 0; RF_WR_SEL = 0;
end
else if (OPCODE == 7'b0010011) //OP_IMM
begin
ALU_SRCA = 0; ALU_SRCB = 1; PC_SOURCE = 0; RF_WR_SEL = 3;
if (FUNC3 == 5)
ALU_FUN = {FUNC7[5],FUNC3};
else
ALU_FUN = {1'b0,FUNC3};
end
else if (OPCODE == 7'b0110011) //OP
begin
ALU_FUN = {FUNC7[5],FUNC3}; ALU_SRCA = 0; ALU_SRCB = 0; PC_SOURCE = 0; RF_WR_SEL = 3;
end
else if (OPCODE == 7'b1110011) //SYSTEM
begin
ALU_FUN = 9; ALU_SRCA = 0; ALU_SRCB = 0; RF_WR_SEL = 1;
if (INT_TAKEN == 1)
PC_SOURCE =4;
else if (FUNC3 == 0)
PC_SOURCE = 5;
else
PC_SOURCE = 0;
end
else //default
begin
ALU_FUN = 0; ALU_SRCA = 0; ALU_SRCB = 0; PC_SOURCE = 0; RF_WR_SEL =0;
end
endmodule