龙芯杯备战4

龙芯杯备战4

国科大试验系统迁移 LAB3-1

代码对比

1.接口

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
//机组cpu
module pipeline_cpu(
input clk,
input resetn,

//display data
input [ 4:0] rf_addr,//regfile 的测试地址(用于测试regfile)
input [31:0] mem_addr,//memory的地址,用于取出数据
output [31:0] rf_data,
output [31:0] mem_data,
output [31:0] IF_pc,
output [31:0] IF_inst,
output [31:0] ID_pc,
output [31:0] EXE_pc,
output [31:0] MEM_pc,
output [31:0] WB_pc,

//最后需要用来检测的数据(检测5级的valid信号以及wb的数据)
output [31:0] cpu_5_valid,
output [31:0] HI_data,
output [31:0] LO_data
);



//国科大 CPU
module mycpu_top(
input clk,//时钟
input resetn,//复位信号

//ram 指令
input [31:0] inst_sram_rdata,//ram 读数据 -> inst(所得到的指令)
output inst_sram_en,//ram 使能信号 (需要自己添加这一信号的赋值) ---->还未修改
output [3:0] inst_sram_wen,//ram 字节写使能信号 (在机组的流水线中,并未实现) ---> 还未修改
output [31:0] inst_sram_addr,//ram 读写地址,字节寻址 -> pc (inst_addr)
output [31:0] inst_sram_wdata,//ram 写数据 (所需要修改的数据指令) ---> 还未修改
//ram 数据 ->类似于inst_sram 可以直接在mem.v阶段使用
input [31:0] data_sram_rdata,//ram 读数据
output data_sram_en,//ram 使能信号,高电平有效 ----> 还未修改
output [3:0] data_sram_wen,//ram 字节写使能信号
output [31:0] data_sram_addr,//ram 读写地址
output [31:0] data_sram_wdata,//ram 写数据

output [31:0] debug_wb_pc,//wb级的PC,因而需要mycpu 的PC 一路带到写回级
output [3:0] debug_wb_rf_wen,// 写回级写寄存器堆(regfiles) 的写使能,为字节写使能
output [4:0] debug_wb_rf_wnum,// 写回级写regfiles的目的寄存器号
output [31:0] debug_wb_rf_wdata// 写回级写regfiles的写数据
);

2.regfile

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
//regilfe 中原机组代码有test,但是由于在修改后的cpu后没有test的input信号,所以修改后直接删除就好
`timescale 1ns / 1ps
//*************************************************************************
// LOONGSON
// 2016-04-14
//*************************************************************************
module regfile(
input clk,
input wen,
input [4 :0] raddr1,
input [4 :0] raddr2,
input [4 :0] waddr,
input [31:0] wdata,
output reg [31:0] rdata1,
output reg [31:0] rdata2,
input [4 :0] test_addr,
output reg [31:0] test_data
);
reg [31:0] rf[31:0];

// three ported register file
// read two ports combinationally
// write third port on rising edge of clock
// register 0 hardwired to 0

always @(posedge clk)
begin
if (wen)
begin
rf[waddr] <= wdata;
end
end

always @(*)
begin
case (raddr1)
5'd1 : rdata1 <= rf[1 ];
5'd2 : rdata1 <= rf[2 ];
5'd3 : rdata1 <= rf[3 ];
5'd4 : rdata1 <= rf[4 ];
5'd5 : rdata1 <= rf[5 ];
5'd6 : rdata1 <= rf[6 ];
5'd7 : rdata1 <= rf[7 ];
5'd8 : rdata1 <= rf[8 ];
5'd9 : rdata1 <= rf[9 ];
5'd10: rdata1 <= rf[10];
5'd11: rdata1 <= rf[11];
5'd12: rdata1 <= rf[12];
5'd13: rdata1 <= rf[13];
5'd14: rdata1 <= rf[14];
5'd15: rdata1 <= rf[15];
5'd16: rdata1 <= rf[16];
5'd17: rdata1 <= rf[17];
5'd18: rdata1 <= rf[18];
5'd19: rdata1 <= rf[19];
5'd20: rdata1 <= rf[20];
5'd21: rdata1 <= rf[21];
5'd22: rdata1 <= rf[22];
5'd23: rdata1 <= rf[23];
5'd24: rdata1 <= rf[24];
5'd25: rdata1 <= rf[25];
5'd26: rdata1 <= rf[26];
5'd27: rdata1 <= rf[27];
5'd28: rdata1 <= rf[28];
5'd29: rdata1 <= rf[29];
5'd30: rdata1 <= rf[30];
5'd31: rdata1 <= rf[31];
default : rdata1 <= 32'd0;
endcase
end

always @(*)
begin
case (raddr2)
5'd1 : rdata2 <= rf[1 ];
5'd2 : rdata2 <= rf[2 ];
5'd3 : rdata2 <= rf[3 ];
5'd4 : rdata2 <= rf[4 ];
5'd5 : rdata2 <= rf[5 ];
5'd6 : rdata2 <= rf[6 ];
5'd7 : rdata2 <= rf[7 ];
5'd8 : rdata2 <= rf[8 ];
5'd9 : rdata2 <= rf[9 ];
5'd10: rdata2 <= rf[10];
5'd11: rdata2 <= rf[11];
5'd12: rdata2 <= rf[12];
5'd13: rdata2 <= rf[13];
5'd14: rdata2 <= rf[14];
5'd15: rdata2 <= rf[15];
5'd16: rdata2 <= rf[16];
5'd17: rdata2 <= rf[17];
5'd18: rdata2 <= rf[18];
5'd19: rdata2 <= rf[19];
5'd20: rdata2 <= rf[20];
5'd21: rdata2 <= rf[21];
5'd22: rdata2 <= rf[22];
5'd23: rdata2 <= rf[23];
5'd24: rdata2 <= rf[24];
5'd25: rdata2 <= rf[25];
5'd26: rdata2 <= rf[26];
5'd27: rdata2 <= rf[27];
5'd28: rdata2 <= rf[28];
5'd29: rdata2 <= rf[29];
5'd30: rdata2 <= rf[30];
5'd31: rdata2 <= rf[31];
default : rdata2 <= 32'd0;
endcase
end

always @(*)
begin
case (test_addr)
5'd1 : test_data <= rf[1 ];
5'd2 : test_data <= rf[2 ];
5'd3 : test_data <= rf[3 ];
5'd4 : test_data <= rf[4 ];
5'd5 : test_data <= rf[5 ];
5'd6 : test_data <= rf[6 ];
5'd7 : test_data <= rf[7 ];
5'd8 : test_data <= rf[8 ];
5'd9 : test_data <= rf[9 ];
5'd10: test_data <= rf[10];
5'd11: test_data <= rf[11];
5'd12: test_data <= rf[12];
5'd13: test_data <= rf[13];
5'd14: test_data <= rf[14];
5'd15: test_data <= rf[15];
5'd16: test_data <= rf[16];
5'd17: test_data <= rf[17];
5'd18: test_data <= rf[18];
5'd19: test_data <= rf[19];
5'd20: test_data <= rf[20];
5'd21: test_data <= rf[21];
5'd22: test_data <= rf[22];
5'd23: test_data <= rf[23];
5'd24: test_data <= rf[24];
5'd25: test_data <= rf[25];
5'd26: test_data <= rf[26];
5'd27: test_data <= rf[27];
5'd28: test_data <= rf[28];
5'd29: test_data <= rf[29];
5'd30: test_data <= rf[30];
5'd31: test_data <= rf[31];
default : test_data <= 32'd0;
endcase
end
endmodule

其它过程

对于整个迁移的其它过程,都主要是按照接口来做,没有什么特别的地方需要说明。

另外需要说明的一点是,在机组实现的流水线cpu中,是在整个cpu的总线中进行调用inst_sram和data_sram,而在国科大的lab中,由更高一层的soc_lite_top.v进行调用和控制,而my_cpu中只需要调用fetch,decode,exe,mem,wb以及regfile进行执行即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//*************************************************************************
// > File Name : soc_top.v
// > Description : SoC, included cpu, 2 x 3 bridge,
// inst ram, confreg, data ram
//
// -------------------------
// | cpu |
// -------------------------
// inst| | data
// | |
// | ---------------------
// | | 1 x 2 bridge |
// | ---------------------
// | | |
// | | |
// ------------- ----------- -----------
// | inst ram | | data ram| | confreg |
// ------------- ----------- -----------
//
// > Author : LOONGSON
// > Date : 2017-08-04
//*************************************************************************

其主要框架如图所示,需要更具体地进行了解

IP核锁定解决方案

由于从旧的vivado版本迁移到新的版本中,会遇到IP核锁定的问题,所以我跑simulation的时候,发现跑不过,我开始以为是coe文件的问题,后来重新导入coe文件后,发现还是报错,于是我发现,是IP核锁定了。

首先查看网上的解决方案,在工具栏找到report->Report IP Status,然后发现没办法upgrade selected,这个时候点击右键,可以发现有UPGRADE IP的选项,果断选择,然后好像就OK了。容我跑一跑simulation(时间有点长,现在很慌~~)什么信息也不报一个

其它还需要修改的错误

wb端实际上还需要修改,同时,并没有将所有需要的output实现,目前还有很多X与Z的存在,需要进一步修改其中的代码。