Co-authored-by: Hooo1941 <Hooo1941@users.noreply.github.com>
This commit is contained in:
Paul Pan 2021-08-09 23:26:49 +08:00
parent 24e13ae6c3
commit 50b5a2ae04
11 changed files with 235 additions and 829 deletions

View File

@ -1,8 +1,6 @@
`include "defines.svh"
`include "CP0.svh"
// TODO: Config1 reg
module CP0 (
input logic clk,
input logic rst,
@ -30,27 +28,36 @@ module CP0 (
rf_cp0.Cause.IP & rf_cp0.Status.IM, rf_cp0.Cause.TI & rf_cp0.Status.IM[7]
};
assign rf_cp0.Config.M = 1'b0;
assign rf_cp0.TagLo.zero = 9'b0;
assign rf_cp0.Config.M = 1'b1;
assign rf_cp0.Config.zero = 15'b0;
assign rf_cp0.Config.BE = 1'b0;
assign rf_cp0.Config.AT = 2'b0;
assign rf_cp0.Config.AR = 3'b0;
assign rf_cp0.Config.MT = 3'b001;
assign rf_cp0.Config.zero1 = 4'b0;
assign rf_cp0.Cause.zero1 = 14'b0;
assign rf_cp0.Cause.IP[7:2] = ext_int;
assign rf_cp0.Cause.zero2 = 1'b0;
assign rf_cp0.Cause.zero3 = 2'b00;
assign rf_cp0.Status.zero1 = 9'b0;
assign rf_cp0.Status.Bev = 1'b1;
assign rf_cp0.Status.zero2 = 6'b0;
assign rf_cp0.Status.zero3 = 6'b0;
assign rf_cp0.EntryHi.zero = 5'b0;
assign rf_cp0.PageMask.zero1 = 7'b0;
assign rf_cp0.PageMask.zero2 = 13'b0;
assign rf_cp0.EntryLo1.zero = 6'b0;
assign rf_cp0.EntryLo0.zero = 6'b0;
assign rf_cp0.Index.zero = 26'b0;
assign rf_cp0.Config1 = 32'b0_011111_000_100_011_001_011_011_0000000;
always_ff @(posedge clk)
if (rst) begin
// rf_cp0 = {504'b0, 8'b10000011, 105'b0, 1'b1, 117'b0, 1'b1, 288'b0};
rf_cp0.TagLo.Tag = 21'b0;
rf_cp0.TagLo.D = 1'b0;
rf_cp0.TagLo.V = 1'b0;
rf_cp0.Config.K0 = 3'b011;
rf_cp0.EPC = 32'h0;
rf_cp0.Cause.BD = 1'b0;
@ -61,8 +68,24 @@ module CP0 (
rf_cp0.Status.EXL = 1'b0;
rf_cp0.Status.IE = 1'b0;
rf_cp0.Compare = 32'hFFFF_FFFF;
rf_cp0.EntryHi.VPN2 = 19'b0;
rf_cp0.EntryHi.ASID = 8'b0;
rf_cp0.Count = 32'h0;
rf_cp0.BadVAddr = 32'h0;
rf_cp0.PageMask.Mask = 12'b0;
rf_cp0.EntryLo1.PFN = 20'b0;
rf_cp0.EntryLo1.C = 3'b0;
rf_cp0.EntryLo1.D = 1'b0;
rf_cp0.EntryLo1.V = 1'b0;
rf_cp0.EntryLo1.G = 1'b0;
rf_cp0.EntryLo0.PFN = 20'b0;
rf_cp0.EntryLo0.C = 3'b0;
rf_cp0.EntryLo0.D = 1'b0;
rf_cp0.EntryLo0.V = 1'b0;
rf_cp0.EntryLo0.G = 1'b0;
rf_cp0.Index.P = 1'b0;
rf_cp0.Index.Index = 5'b0;
count_lo = 0;
end else begin
// count
@ -73,7 +96,11 @@ module CP0 (
// 31: rf_cp0.DESAVE = wdata;
// 30: rf_cp0.ErrorEPC = wdata;
// 29: rf_cp0.TagHi = wdata;
// 28: rf_cp0.Taglo = wdata;
28: begin
rf_cp0.TagLo.Tag = wdata[22:2];
rf_cp0.TagLo.D = wdata[1];
rf_cp0.TagLo.V = wdata[0];
end
// 27: rf_cp0.CacheErr = wdata;
// 26: rf_cp0.Errctl = wdata;
// 25: rf_cp0.PerfCnt = wdata;
@ -98,17 +125,35 @@ module CP0 (
rf_cp0.Compare = wdata;
rf_cp0.Cause.TI = 0;
end
// 10: rf_cp0.EntryHi = wdata;
10: begin
rf_cp0.EntryHi.VPN2 = wdata[31:13];
rf_cp0.EntryHi.ASID = wdata[7:0];
end
9: rf_cp0.Count = wdata;
8: rf_cp0.BadVAddr = wdata;
// 7: rf_cp0.HWREna = wdata;
// 6: rf_cp0.Wired = wdata;
// 5: rf_cp0.PageMask = wdata;
5: rf_cp0.PageMask.Mask = wdata[24:13];
// 4: rf_cp0.Context = wdata;
// 3: rf_cp0.EntryLo1 = wdata;
// 2: rf_cp0.EntryLo0 = wdata;
3: begin
rf_cp0.EntryLo1.PFN = wdata[25:6];
rf_cp0.EntryLo1.C = wdata[5:3];
rf_cp0.EntryLo1.D = wdata[2];
rf_cp0.EntryLo1.V = wdata[1];
rf_cp0.EntryLo1.G = wdata[0];
end
2: begin
rf_cp0.EntryLo0.PFN = wdata[25:6];
rf_cp0.EntryLo0.C = wdata[5:3];
rf_cp0.EntryLo0.D = wdata[2];
rf_cp0.EntryLo0.V = wdata[1];
rf_cp0.EntryLo0.G = wdata[0];
end
// 1: rf_cp0.Random = wdata;
// 0: rf_cp0.Index = wdata;
0: begin
rf_cp0.Index.P = wdata[31];
rf_cp0.Index.Index = wdata[4:0];
end
default: begin
end
endcase
@ -164,6 +209,7 @@ module CP0 (
// 0: rdata = rf_cp0.Index;
default: rdata = 32'h0;
endcase
assign EPC = rf_cp0.EPC;
assign K0 = rf_cp0.Config.K0;
endmodule

View File

@ -1,187 +0,0 @@
`include "defines.svh"
module InstrQueue (
input logic clk,
input logic rst,
input logic vinA,
input word_t inA,
input word_t pinA,
input logic vinB,
input word_t inB,
input word_t pinB,
input logic enA,
output logic voutA,
output word_t outA,
output word_t poutA,
input logic enB,
output logic voutB,
output word_t outB,
output word_t poutB,
output logic [3:0] valids
);
word_t di1, di2, di3, di4, qi1, qi2, qi3, qi4;
logic dv1, dv2, dv3, dv4, qv1, qv2, qv3, qv4;
logic en1, en2, en3, en4;
word_t dp1, dp2, dp3, dp4, qp1, qp2, qp3, qp4;
logic [5:0] judge;
assign judge = {qv4, qv3, qv2, qv1, enA, enB};
// assign valids = {qv4, qv3, qv2, qv1};
assign valids = {qv1, qv2, qv3, qv4};
assign en1 = ~judge[2] | judge[1];
assign en2 = ~judge[3] | judge[1];
assign en3 = (~judge[3] & judge[2] & ~judge[1] & ~judge[0] | judge[3] & (~judge[1] & ~judge[4] & ~judge[0] | judge[1] & (~judge[0] | judge[4])));
assign en4 = judge[3] & (~judge[0] & (~judge[5] & (~judge[1] | judge[4]) | judge[5] & judge[1]) | judge[0] & judge[5] & judge[1]);
assign {outA, outB, poutA, poutB} = {qi1, qi2, qp1, qp2};
assign voutA = judge[2] & ~rst;
assign voutB = judge[3] & ~rst;
always_comb begin
if (judge[3] & ~judge[0]) {di1, dv1, dp1} = {qi2, qv2, qp2};
else if (judge[3] & judge[0] & judge[4]) {di1, dv1, dp1} = {qi3, qv3, qp3};
else {di1, dv1, dp1} = {inA, vinA, pinA};
if (judge[4] & ~judge[0]) {di2, dv2, dp2} = {qi3, qv3, qp3};
else if (judge[4] & judge[0] & judge[5]) {di2, dv2, dp2} = {qi4, qv4, qp4};
else if (~judge[4] & (~judge[2] | (~judge[3] & judge[1] | judge[0])))
{di2, dv2, dp2} = {inB, vinB, pinB};
else {di2, dv2, dp2} = {inA, vinA, pinA};
if (judge[5] & ~judge[0]) {di3, dv3, dp3} = {qi4, qv4, qp4};
else if ((~judge[5] & judge[3] & ~judge[0] & (~judge[4] & ~judge[1] | judge[4]) | judge[5] & judge[0]))
{di3, dv3, dp3} = {inA, vinA, pinA};
else {di3, dv3, dp3} = {inB, vinA, pinB};
di4 = (judge[4] & ~judge[0] & (~judge[1] | judge[5])) ? inA : inB;
dv4 = ((judge[4] & ~judge[0] & (~judge[1] | judge[5])) ? vinA : vinB);
dp4 = (judge[4] & ~judge[0] & (~judge[1] | judge[5])) ? pinA : pinB;
end
ffen #(32) pc1 (
clk,
dp1,
en1,
qp1
);
ffen #(32) pc2 (
clk,
dp2,
en2,
qp2
);
ffen #(32) pc3 (
clk,
dp3,
en3,
qp3
);
ffen #(32) pc4 (
clk,
dp4,
en4,
qp4
);
ffen #(32) instr1 (
clk,
di1,
en1,
qi1
);
ffen #(32) instr2 (
clk,
di2,
en2,
qi2
);
ffen #(32) instr3 (
clk,
di3,
en3,
qi3
);
ffen #(32) instr4 (
clk,
di4,
en4,
qi4
);
ffenr #(1) valid1 (
clk,
rst,
dv1,
en1,
qv1
);
ffenr #(1) valid2 (
clk,
rst,
dv2,
en2,
qv2
);
ffenr #(1) valid3 (
clk,
rst,
dv3,
en3,
qv3
);
ffenr #(1) valid4 (
clk,
rst,
dv4,
en4,
qv4
);
/*
instr: ffen
valid: ffenr
readygo to valid
0:
0out: instr1<-inA, instr2<-inB
1out: outA<-inA, instr1<-inB
2out: outA<-inA, outB<-inB
1:
0out: instr2<-inA, instr3<-inB
1out: outA<-instr1 instr1<-inA instr2<-inB
2out: outA<-instr1 outB<-inA instr1<-inB
2:
0out: instr4<-inA
1out: outA<-instr1 instr1<-instr2 instr2<-inA instr3<-inB
2out: outA<-instr1 outB<-instr2 instr1<-inA instr2<-inB
3:
1out: outA<-instr1 instr1<-instr2 instr2<-inA instr3<-inB
2out: outA<-instr1 outB<-instr2 instr1<-instr3 instr2<-inA instr3<-inB
4:
0out:
1out: outA<-instr1 instr1<-instr2 instr2<-instr3 instr3<-inA
2out: outA<-instr1 outB<-instr2 instr1<-instr3 instr3<-instr4 instr4<-inA
0:
0out: instr1<-inA, instr2<-inB
1out: instr1<-inA, instr2<-inB
2out: instr1<-inA, instr2<-inB
1:
0out: instr2<-inA, instr3<-inB
1out: outA<-instr1 instr1<-inA instr2<-inB
2out: outA<-instr1 instr1<-inA instr2<-inB
2:
0out: instr3<-inA instr4<-inB
1out: outA<-instr1 instr1<-instr2 instr2<-inA instr3<-inB
2out: outA<-instr1 outB<-instr2 instr1<-inA instr2<-inB
3:
0out: instr4<-inA
1out: outA<-instr1 instr1<-instr2 instr2<-instr3 instr3<-inA instr4<-inB
2out: outA<-instr1 outB<-instr2 instr1<-instr3 instr2<-inA instr3<-inB
4:
0out: nop
1out: outA<-instr1 instr1<-instr2 instr2<-instr3 instr3<-instr4 instr4<-inA
2out: outA<-instr1 outB<-instr2 instr1<-instr3 instr2<-instr4 instr3<-inA instr4<-inB
*/
endmodule

View File

@ -1,82 +0,0 @@
`include "sram.svh"
module Issue(
input clk, rst,
sramro_i.master fetch_i);
wire logic validF, goF1, goF2;
wire logic enD, validD, goD;
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
pre-fetch
assign pcp8F = {pcF[31:3], 3'b000} + 8;
assign pcbF = pcF + {{14{instrD[15]}}, instrD[15:0], 2'b0};
assign pcjF = {pcF[31:28], instrD[25:0], 2'b0};
assign pcjrF = datasD;
logic [31:0] pcp4F, pcp8F, pcF, nextpcF;
logic [31:0] pcb1F, pcj1F, pcjr1F;
logic [31:0] pcb2F, pcj2F, pcjr2F;
logic [31:0] pcbF, pcjF, pcjrF;
logic [31:0] EPCF;
logic enF;
logic [31:0] instrD;
logic jsrcD;
logic [2:0] pcsrcD;
mux2#(96) pcj_mux({pcb1F, pcj1F, pcjr1F}, {pcb2F, pcj2F, pcjr2F}, jsrcD, {pcbF, pcjF, pcjrF});
mux6#(32) nextpc_mux(pcp4F, pcp8F, EPCF, pcbF, pcjF, pcjrF, pcsrcD, nextpcF);
assign fetch_i.req = enF;
assign fetch_i.addr = nextpcF;
fetch stage logic
ffenr#(1) valid_ffF(clk, rst, 1'b1, enF, validF);
pcenr pc_reg(clk, rst, nextpcF, enF, pcF);
assign enF = fetch_i.data_ok;
assign goF1 = validF & enF;
assign goF2 = validF & enF;
HandShake HS_iq_in1(), HS_iq_in2();
HandShake HS_iq_out1(), HS_iq_out2();
logic [31:0] instr_toD1, instr_toD2, pc_toD1, pc_toD2;
logic iq_clear = 1'b0;
TODO: if allowin == 0?
assign HS_iq_in1.readygo = goF1;
assign HS_iq_in2.readygo = goF2;
InstrQueue InstrQueue (
.clk(clk),
.rst(rst),
.HandShake_in1(HS_iq_in1),
.in1(fetch_i.rdata0),
.pin1(pcF),
.HandShake_in2(HS_iq_in2),
.in2(fetch_i.rdata1),
.pin2(pcF + 4),
.HandShake_out1(HS_iq_out1),
.out1(instr_toD1),
.pout1(pc_toD1),
.HandShake_out2(HS_iq_out2),
.out2(instr_toD2),
.pout2(pc_toD2),
.clear(iq_clear) //flush, will ignore the current input, need to keep the input instr!
);
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
ffenr#(1) valid_ffD(clk, rst, goF1, enD, validD);
ffen#(32) instr_ffD(clk, fetch_i.rdata0, enD, instrD);
controller
controller c(instrD, pcsrcD, rsD, rtD, rdD, immD);
register file (operates in decode and writeback)
RF rf(clk, rst, rsD, rtD, datasD, datatD, rdW, datawW, regwriteW);
assign enD = fetch_i.addr_ok;
assign goD = validD & enD;
assign goD = validD;
endmodule

View File

@ -1,436 +0,0 @@
`include "constants.svh"
module RF (
input clk,
input rst,
input [ 4 : 0] raddr1,
input [ 4 : 0] raddr2,
input en,
input [ 4 : 0] waddr,
input [`WIDTH - 1:0] wdata,
input enl,
input [ 4:0] laddr,
input [`LABEL - 1:0] ldata,
output reg [`WIDTH - 1:0] rdata1,
output reg [`WIDTH - 1:0] rdata2,
output reg [`LABEL - 1:0] rlabel1,
output reg [`LABEL - 1:0] rlabel2,
input [ 4 : 0] test_addr,
output reg [`WIDTH - 1:0] test_data,
output reg [`LABEL - 1:0] test_label
);
reg [`LABEL - 1:0] rl[31:0];
reg [`WIDTH - 1:0] rf[31:0];
integer i;
always @(posedge clk or posedge rst)
if (rst) begin
for (i = 0; i < 32; i = i + 1) rf[i] <= 0;
end else begin
if (en && waddr != 0) begin
rf[waddr] <= wdata;
end
if (enl && laddr != 0) begin
rl[laddr] <= ldata;
end
end
// assign rdata1 = rf[raddr1];
// assign rdata2 = (raddr2 != 0) ? rf[raddr2] : 0;
// assign test_data = (test_addr != 0) ? rf[test_addr] : 0;
always @(*) begin
case (raddr1)
5'd1: begin
rdata1 = rf[1];
rlabel1 = rl[1];
end
5'd2: begin
rdata1 = rf[2];
rlabel1 = rl[2];
end
5'd3: begin
rdata1 = rf[3];
rlabel1 = rl[3];
end
5'd4: begin
rdata1 = rf[4];
rlabel1 = rl[4];
end
5'd5: begin
rdata1 = rf[5];
rlabel1 = rl[5];
end
5'd6: begin
rdata1 = rf[6];
rlabel1 = rl[6];
end
5'd7: begin
rdata1 = rf[7];
rlabel1 = rl[7];
end
5'd8: begin
rdata1 = rf[8];
rlabel1 = rl[8];
end
5'd9: begin
rdata1 = rf[9];
rlabel1 = rl[9];
end
5'd10: begin
rdata1 = rf[10];
rlabel1 = rl[10];
end
5'd11: begin
rdata1 = rf[11];
rlabel1 = rl[11];
end
5'd12: begin
rdata1 = rf[12];
rlabel1 = rl[12];
end
5'd13: begin
rdata1 = rf[13];
rlabel1 = rl[13];
end
5'd14: begin
rdata1 = rf[14];
rlabel1 = rl[14];
end
5'd15: begin
rdata1 = rf[15];
rlabel1 = rl[15];
end
5'd16: begin
rdata1 = rf[16];
rlabel1 = rl[16];
end
5'd17: begin
rdata1 = rf[17];
rlabel1 = rl[17];
end
5'd18: begin
rdata1 = rf[18];
rlabel1 = rl[18];
end
5'd19: begin
rdata1 = rf[19];
rlabel1 = rl[19];
end
5'd20: begin
rdata1 = rf[20];
rlabel1 = rl[20];
end
5'd21: begin
rdata1 = rf[21];
rlabel1 = rl[21];
end
5'd22: begin
rdata1 = rf[22];
rlabel1 = rl[22];
end
5'd23: begin
rdata1 = rf[23];
rlabel1 = rl[23];
end
5'd24: begin
rdata1 = rf[24];
rlabel1 = rl[24];
end
5'd25: begin
rdata1 = rf[25];
rlabel1 = rl[25];
end
5'd26: begin
rdata1 = rf[26];
rlabel1 = rl[26];
end
5'd27: begin
rdata1 = rf[27];
rlabel1 = rl[27];
end
5'd28: begin
rdata1 = rf[28];
rlabel1 = rl[28];
end
5'd29: begin
rdata1 = rf[29];
rlabel1 = rl[29];
end
5'd30: begin
rdata1 = rf[30];
rlabel1 = rl[30];
end
5'd31: begin
rdata1 = rf[31];
rlabel1 = rl[31];
end
default: begin
rdata1 = `WIDTH'd0;
rlabel1 = `LABEL'd0;
end
endcase
end
always @(*) begin
case (raddr2)
5'd1: begin
rdata2 = rf[1];
rlabel2 = rl[1];
end
5'd2: begin
rdata2 = rf[2];
rlabel2 = rl[2];
end
5'd3: begin
rdata2 = rf[3];
rlabel2 = rl[3];
end
5'd4: begin
rdata2 = rf[4];
rlabel2 = rl[4];
end
5'd5: begin
rdata2 = rf[5];
rlabel2 = rl[5];
end
5'd6: begin
rdata2 = rf[6];
rlabel2 = rl[6];
end
5'd7: begin
rdata2 = rf[7];
rlabel2 = rl[7];
end
5'd8: begin
rdata2 = rf[8];
rlabel2 = rl[8];
end
5'd9: begin
rdata2 = rf[9];
rlabel2 = rl[9];
end
5'd10: begin
rdata2 = rf[10];
rlabel2 = rl[10];
end
5'd11: begin
rdata2 = rf[11];
rlabel2 = rl[11];
end
5'd12: begin
rdata2 = rf[12];
rlabel2 = rl[12];
end
5'd13: begin
rdata2 = rf[13];
rlabel2 = rl[13];
end
5'd14: begin
rdata2 = rf[14];
rlabel2 = rl[14];
end
5'd15: begin
rdata2 = rf[15];
rlabel2 = rl[15];
end
5'd16: begin
rdata2 = rf[16];
rlabel2 = rl[16];
end
5'd17: begin
rdata2 = rf[17];
rlabel2 = rl[17];
end
5'd18: begin
rdata2 = rf[18];
rlabel2 = rl[18];
end
5'd19: begin
rdata2 = rf[19];
rlabel2 = rl[19];
end
5'd20: begin
rdata2 = rf[20];
rlabel2 = rl[20];
end
5'd21: begin
rdata2 = rf[21];
rlabel2 = rl[21];
end
5'd22: begin
rdata2 = rf[22];
rlabel2 = rl[22];
end
5'd23: begin
rdata2 = rf[23];
rlabel2 = rl[23];
end
5'd24: begin
rdata2 = rf[24];
rlabel2 = rl[24];
end
5'd25: begin
rdata2 = rf[25];
rlabel2 = rl[25];
end
5'd26: begin
rdata2 = rf[26];
rlabel2 = rl[26];
end
5'd27: begin
rdata2 = rf[27];
rlabel2 = rl[27];
end
5'd28: begin
rdata2 = rf[28];
rlabel2 = rl[28];
end
5'd29: begin
rdata2 = rf[29];
rlabel2 = rl[29];
end
5'd30: begin
rdata2 = rf[30];
rlabel2 = rl[30];
end
5'd31: begin
rdata2 = rf[31];
rlabel2 = rl[31];
end
default: begin
rdata2 = `WIDTH'd0;
rlabel2 = `LABEL'd0;
end
endcase
end
always @(*) begin
case (test_addr)
5'd1: begin
test_data = rf[1];
test_label = rl[1];
end
5'd2: begin
test_data = rf[2];
test_label = rl[2];
end
5'd3: begin
test_data = rf[3];
test_label = rl[3];
end
5'd4: begin
test_data = rf[4];
test_label = rl[4];
end
5'd5: begin
test_data = rf[5];
test_label = rl[5];
end
5'd6: begin
test_data = rf[6];
test_label = rl[6];
end
5'd7: begin
test_data = rf[7];
test_label = rl[7];
end
5'd8: begin
test_data = rf[8];
test_label = rl[8];
end
5'd9: begin
test_data = rf[9];
test_label = rl[9];
end
5'd10: begin
test_data = rf[10];
test_label = rl[10];
end
5'd11: begin
test_data = rf[11];
test_label = rl[11];
end
5'd12: begin
test_data = rf[12];
test_label = rl[12];
end
5'd13: begin
test_data = rf[13];
test_label = rl[13];
end
5'd14: begin
test_data = rf[14];
test_label = rl[14];
end
5'd15: begin
test_data = rf[15];
test_label = rl[15];
end
5'd16: begin
test_data = rf[16];
test_label = rl[16];
end
5'd17: begin
test_data = rf[17];
test_label = rl[17];
end
5'd18: begin
test_data = rf[18];
test_label = rl[18];
end
5'd19: begin
test_data = rf[19];
test_label = rl[19];
end
5'd20: begin
test_data = rf[20];
test_label = rl[20];
end
5'd21: begin
test_data = rf[21];
test_label = rl[21];
end
5'd22: begin
test_data = rf[22];
test_label = rl[22];
end
5'd23: begin
test_data = rf[23];
test_label = rl[23];
end
5'd24: begin
test_data = rf[24];
test_label = rl[24];
end
5'd25: begin
test_data = rf[25];
test_label = rl[25];
end
5'd26: begin
test_data = rf[26];
test_label = rl[26];
end
5'd27: begin
test_data = rf[27];
test_label = rl[27];
end
5'd28: begin
test_data = rf[28];
test_label = rl[28];
end
5'd29: begin
test_data = rf[29];
test_label = rl[29];
end
5'd30: begin
test_data = rf[30];
test_label = rl[30];
end
5'd31: begin
test_data = rf[31];
test_label = rl[31];
end
default: begin
test_data = `WIDTH'd0;
test_label = `LABEL'd0;
end
endcase
end
endmodule

View File

@ -1,44 +0,0 @@
`timescale 1ns / 1ps
module mul(
input logic clk, rst,
input logic [31:0] a,
input logic [31:0] b,
input logic valid_i,
input logic issigned,
output logic [31:0] hi,
output logic [31:0] lo,
output logic valid_o
);
wire valid_t, signed_t, issigned_o;
wire [63:0] signed_o, unsigned_o;
ffenr #(2) stage1(
.clk(clk),
.rst(rst),
.d({valid_i, issigned}),
.en(1'b1),
.q({valid_t, signed_t})
);
ffenr #(2) stage2(
.clk(clk),
.rst(rst),
.d({valid_t, signed_t}),
.en(1'b1),
.q({valid_o, issigned_o})
);
mul_signed mul_signed(
.CLK(clk),
.A(a),
.B(b),
.P(signed_o)
);
mul_unsigned mul_unsigned(
.CLK(clk),
.A(a),
.B(b),
.P(unsigned_o)
);
assign hi = issigned_o ? signed_o[63:32] : unsigned_o[63:32];
assign lo = issigned_o ? signed_o[31:0] : unsigned_o[31:0];
endmodule

View File

@ -649,7 +649,7 @@ module mapping (
end else if (addr_in > 32'h9FFF_FFFF) begin // kseg1 uncached
addr_out = addr_in & 32'h1FFF_FFFF;
cached = 1'b0;
end else begin // kseg0 -> CP0.K0 default: uncached
end else begin // kseg0 -> CP0.K0
addr_out = addr_in & 32'h1FFF_FFFF;
cached = (K0 == 3'b011);
end

50
src/MMU/TLB.sv Normal file
View File

@ -0,0 +1,50 @@
`include "TLB.svh"
module TLB (
input clk, rst,
// CP0
input logic [2:0] K0,
input logic c0_wr,
input Index_t c0_Index,
input EntryHi_t c0_EntryHi,
input PageMask_t c0_PageMask,
input EntryLo_t c0_EntryLo1,
input EntryLo_t c0_EntryLo0,
output EntryHi_t EntryHi,
output PageMask_t PageMask,
output EntryLo_t EntryLo1,
output EntryLo_t EntryLo0,
// MMU
input word_t vaddr,
output word_t paddr,
output logic cached,
output logic valid
);
TLB_t TLB_Entries[32];
logic hit[32];
TLB_t entry;
always_comb begin
if (vaddr > 32'hBFFF_FFFF || vaddr <= 32'h7FFF_FFFF) begin // kseg2 + kseg3 + kuseg? -> tlb
paddr = vaddr;
cached = 1'b1;
end else if (vaddr > 32'h9FFF_FFFF) begin // kseg1 uncached
paddr = vaddr & 32'h1FFF_FFFF;
cached = 1'b0;
end else begin // kseg0 -> CP0.K0
paddr = vaddr & 32'h1FFF_FFFF;
cached = (K0 == 3'b011);
end
// cached = ~(paddr >= 32'h1faf0000 & paddr <= 32'h1fafffff);
end
for(genvar i = 0; i < 32; i = i + 1)
assign hit[i] = TLB_Entries[i].VPN2 == vaddr[31:13]
& (TLB_Entries[i].ASID == c0_EntryHi.ASID | TLB_Entries[i].G);
endmodule

View File

@ -1,12 +1,16 @@
`ifndef CP0_SVH
`define CP0_SVH
`include "defines.svh"
`include "Cache.svh"
`include "TLB.svh"
typedef struct packed {
logic ExcValid;
logic delay;
logic [4:0] ExcCode;
logic [31:0] BadVAddr;
logic [31:0] EPC;
word_t BadVAddr;
word_t EPC;
logic ERET;
} EXCEPTION_t;
@ -41,10 +45,10 @@ typedef struct packed {
} CP0_REGS_CAUSE_t;
typedef struct packed {
// logic [31:0] DESAVE,
// word_t DESAVE,
// ErrorEPC,
// TagHi,
// Taglo,
// word_t TagHi;
TagLo_t TagLo;
// CacheErr,
// Errctl,
// PerfCnt,
@ -58,16 +62,21 @@ typedef struct packed {
// LLAddr
// ;
CP0_REGS_CONFIG_t Config;
// logic [31:0] PRId;
logic [31:0] EPC;
// word_t PRId;
word_t EPC;
CP0_REGS_CAUSE_t Cause;
CP0_REGS_STATUS_t Status;
logic [31:0] Compare,
// EntryHi,
Count,
BadVAddr
// HWREna, Wired, PageMask, Context, EntryLo1, EntryLo0, Random, Index
;
word_t Compare;
EntryHi_t EntryHi;
word_t Count;
word_t BadVAddr;
// HWREna, Wired, Context,
PageMask_t PageMask;
EntryLo_t EntryLo1;
EntryLo_t EntryLo0;
//Random
Index_t Index;
word_t Config1;
} CP0_REGS_t;
`endif

11
src/include/Cache.svh Normal file
View File

@ -0,0 +1,11 @@
`ifndef CACHE_SVH
`define CACHE_SVH
typedef struct packed {
logic [ 8:0] zero;
logic [20:0] Tag;
logic D;
logic V;
} TagLo_t;
`endif

46
src/include/TLB.svh Normal file
View File

@ -0,0 +1,46 @@
`ifndef TLB_SVH
`define TLB_SVH
typedef struct packed {
logic [18:0] VPN2;
logic [ 4:0] zero;
logic [ 7:0] ASID;
} EntryHi_t;
typedef struct packed {
logic [ 6:0] zero1;
logic [11:0] Mask;
logic [12:0] zero2;
} PageMask_t;
typedef struct packed {
logic [ 5:0] zero;
logic [19:0] PFN;
logic [ 2:0] C;
logic D;
logic V;
logic G;
} EntryLo_t;
typedef struct packed {
logic P;
logic [25:0] zero;
logic [ 4:0] Index;
} Index_t;
typedef struct packed {
logic [18:0] VPN2;
logic [ 7:0] ASID;
logic [11:0] PageMask;
logic G;
logic [19:0] PFN0;
logic [ 2:0] C0;
logic D0;
logic V0;
logic [19:0] PFN1;
logic [ 2:0] C1;
logic D1;
logic V1;
} TLB_t;
`endif

View File

@ -1,7 +0,0 @@
`ifndef CONSTANTS_SVH
`define CONSTANTS_SVH
`define WIDTH 32
`define LABEL 6
`endif