2020-03-29 15:19:14 +00:00
|
|
|
|
/*
|
|
|
|
|
Copyright 2019 Blue Liang, liangkangnan@163.com
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
`include "defines.v"
|
|
|
|
|
|
2020-04-18 12:14:37 +00:00
|
|
|
|
// 控制模块
|
|
|
|
|
// 发出跳转、暂停流水线信号
|
2020-03-29 15:19:14 +00:00
|
|
|
|
module ctrl(
|
|
|
|
|
|
|
|
|
|
input wire rst,
|
|
|
|
|
|
2020-04-18 12:14:37 +00:00
|
|
|
|
// from ex
|
2020-03-29 15:19:14 +00:00
|
|
|
|
input wire jump_flag_i,
|
|
|
|
|
input wire[`InstAddrBus] jump_addr_i,
|
|
|
|
|
input wire hold_flag_ex_i,
|
2020-04-18 12:14:37 +00:00
|
|
|
|
|
|
|
|
|
// from rib
|
2020-03-29 15:19:14 +00:00
|
|
|
|
input wire hold_flag_rib_i,
|
2020-04-18 12:14:37 +00:00
|
|
|
|
|
|
|
|
|
// from jtag
|
2020-03-29 15:19:14 +00:00
|
|
|
|
input wire jtag_halt_flag_i,
|
|
|
|
|
|
2020-04-25 09:08:46 +00:00
|
|
|
|
// from clint
|
|
|
|
|
input wire hold_flag_clint_i,
|
|
|
|
|
|
2020-03-29 15:19:14 +00:00
|
|
|
|
output reg[`Hold_Flag_Bus] hold_flag_o,
|
2020-04-18 12:14:37 +00:00
|
|
|
|
|
|
|
|
|
// to pc_reg
|
2020-03-29 15:19:14 +00:00
|
|
|
|
output reg jump_flag_o,
|
|
|
|
|
output reg[`InstAddrBus] jump_addr_o
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
always @ (*) begin
|
|
|
|
|
if (rst == `RstEnable) begin
|
2020-05-02 03:58:44 +00:00
|
|
|
|
hold_flag_o = `Hold_None;
|
|
|
|
|
jump_flag_o = `JumpDisable;
|
|
|
|
|
jump_addr_o = `ZeroWord;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
end else begin
|
2020-05-02 03:58:44 +00:00
|
|
|
|
jump_addr_o = jump_addr_i;
|
|
|
|
|
jump_flag_o = jump_flag_i;
|
2020-04-18 12:14:37 +00:00
|
|
|
|
// 默认不暂停
|
2020-05-02 03:58:44 +00:00
|
|
|
|
hold_flag_o = `Hold_None;
|
2020-04-18 12:14:37 +00:00
|
|
|
|
// 按优先级处理不同模块的请求
|
2020-04-25 09:08:46 +00:00
|
|
|
|
if (jump_flag_i == `JumpEnable || hold_flag_ex_i == `HoldEnable || hold_flag_clint_i == `HoldEnable) begin
|
2020-04-18 12:14:37 +00:00
|
|
|
|
// 暂停整条流水线
|
2020-05-02 03:58:44 +00:00
|
|
|
|
hold_flag_o = `Hold_Id;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
end else if (hold_flag_rib_i == `HoldEnable) begin
|
2020-04-18 12:14:37 +00:00
|
|
|
|
// 暂停PC,即取指地址不变
|
2020-05-02 03:58:44 +00:00
|
|
|
|
hold_flag_o = `Hold_Pc;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
end else if (jtag_halt_flag_i == `HoldEnable) begin
|
2020-04-18 12:14:37 +00:00
|
|
|
|
// 暂停整条流水线
|
2020-05-02 03:58:44 +00:00
|
|
|
|
hold_flag_o = `Hold_Id;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
end else begin
|
2020-05-02 03:58:44 +00:00
|
|
|
|
hold_flag_o = `Hold_None;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
endmodule
|