-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSynchronous_Core.v
158 lines (134 loc) · 3.71 KB
/
Synchronous_Core.v
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 21.09.2024 09:29:27
// Design Name:
// Module Name: Synchronous_Core
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Synchronous_Core(
input clk, Reset,
output [31:0] out, file
);
//////////////////////////////////////////////////////////////////////////////////
// DECLARATIONS
//Fetch Unit declarations
wire Branch;
wire [9:0] TargetAddress;
wire [31:0] Instruction;
wire [9:0] Add;
//Decode Unit declarations
wire valid;
wire [0:5] type;
wire [3:0] opcode;
wire [6:0] alu_opcode;
wire [4:0] rs0, rs1, rdt;
wire [2:0] funct3;
wire [6:0] funct7;
wire [11:0] imm;
//Execute Unit declarations
wire [31:0] op0, op1;
wire s, i;
wire [4:0] write_address;
wire [9:0] mem_address;
wire [31:0] result;
assign out = result;
//Memory Access and Writeback Unit declarations
wire [31:0] write_data;
reg [4:0] reg_file_address;
reg [31:0] alu_result;
reg type_s, type_i;
//////////////////////////////////////////////////////////////////////////////////
// SUPPLEMENTARY COMPONENTS
//Instruction RAM
wire instruction_write;
wire [31:0] data_in;
wire [31:0] data_out;
reg [9:0] instruction_address;
RAM i_ram(
.write_enable(instruction_enable),
.address(instruction_address),
.data_in(data_in),
.data_out(data_out)
);
always @ * begin
if(|Branch)
instruction_address = TargetAddress;
else
instruction_address = Add;
end
//Register File
reg [31:0] Reg_File [0:15];
assign op0 = rs0[4] ? Reg_File[rs0] : {28'b0, rs0[3:0]};
assign op1 = rs1[4] ? Reg_File[rs1] : {28'b0, rs1[3:0]};
assign file = Reg_File[0];
reg [9:0] data_address=0;
//Data RAM
RAM d_ram(
.write_enable(type_s),
.address(data_address),
.data_in(store_data),
.data_out(write_data)
);
//////////////////////////////////////////////////////////////////////////////////
//PIPELINE BEGINS
// Stage 1
Fetch fu(.clk(clk),
.Reset(Reset),
.Branch(Branch),
.TargetAddress(TargetAddress),
.plus32(data_out),
.Instruction(Instruction),
.Add(Add)
);
// Stage 2
Decode du(.clk(clk),
.instruction(Instruction),
.valid(valid),
.type(type),
.opcode(opcode), .alu_opcode(alu_opcode),
.rs0(rs0), .rs1(rs1), .rdt(rdt),
.funct3(funct3), .funct7(funct7),
.imm(imm)
);
// Stage 3
Execute eu(.clk(clk),
.valid(valid),
.type(type),
.opcode(opcode), .alu_opcode(alu_opcode),
.op0(op0), .op1(op1), .rdt(rdt),
.funct3(funct3), .funct7(funct7),
.imm(imm), .address(Add),
.targetAddress(TargetAddress),
.write_address(write_address),
.result(result),
.s(s), .i(i),
.branch(Branch),
.mem_address(mem_address),
.store_data(store_data)
);
// Stage 4
//Memory Access and Write-Back logic
always @ (posedge clk) begin
//Writing to Register File / Store operation
reg_file_address <= write_address;
data_address <= mem_address;
alu_result <= result;
{type_s, type_i} <= {s, i};
#5;
if(type_s) Reg_File[reg_file_address] <= write_data;
else if(type_i) Reg_File[reg_file_address] <= alu_result;
end
endmodule