2020-03-29 15:19:14 +00:00
|
|
|
|
/*
|
|
|
|
|
Copyright 2020 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"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// core local interruptor module
|
2020-04-18 03:21:09 +00:00
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٲ<EFBFBD>ģ<EFBFBD><EFBFBD>
|
2020-03-29 15:19:14 +00:00
|
|
|
|
module clint(
|
|
|
|
|
|
|
|
|
|
input wire clk,
|
|
|
|
|
input wire rst,
|
|
|
|
|
|
2020-04-18 03:21:09 +00:00
|
|
|
|
// from id
|
2020-04-11 11:03:49 +00:00
|
|
|
|
input wire[`INT_BUS] int_flag_i,
|
|
|
|
|
input wire[`InstBus] inst_i,
|
|
|
|
|
input wire[`InstAddrBus] inst_addr_i,
|
2020-04-18 03:21:09 +00:00
|
|
|
|
|
|
|
|
|
// from ctrl
|
2020-04-11 11:03:49 +00:00
|
|
|
|
input wire[`Hold_Flag_Bus] hold_flag_i,
|
2020-04-18 03:21:09 +00:00
|
|
|
|
|
|
|
|
|
// from csr_reg
|
2020-04-11 11:03:49 +00:00
|
|
|
|
input wire[`RegBus] data_i,
|
2020-03-29 15:19:14 +00:00
|
|
|
|
|
2020-04-18 03:21:09 +00:00
|
|
|
|
// to csr_reg
|
2020-04-11 11:03:49 +00:00
|
|
|
|
output reg we_o,
|
|
|
|
|
output reg[`MemAddrBus] waddr_o,
|
|
|
|
|
output reg[`MemAddrBus] raddr_o,
|
|
|
|
|
output reg[`RegBus] data_o,
|
|
|
|
|
|
2020-04-18 03:21:09 +00:00
|
|
|
|
// to ex
|
2020-04-11 11:03:49 +00:00
|
|
|
|
output reg[`InstAddrBus] int_addr_o,
|
|
|
|
|
output reg int_assert_o
|
2020-03-29 15:19:14 +00:00
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
2020-04-11 11:03:49 +00:00
|
|
|
|
|
2020-04-18 03:21:09 +00:00
|
|
|
|
// ״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
localparam STATE_IDLE = 4'b0001;
|
|
|
|
|
localparam STATE_ASSERT = 4'b0010;
|
|
|
|
|
localparam STATE_WAIT_MRET = 4'b0100;
|
|
|
|
|
localparam STATE_MRET = 4'b1000;
|
|
|
|
|
|
|
|
|
|
reg[3:0] state;
|
|
|
|
|
reg[3:0] next_state;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
2020-04-18 03:21:09 +00:00
|
|
|
|
// ״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2020-03-29 15:19:14 +00:00
|
|
|
|
always @ (posedge clk) begin
|
|
|
|
|
if (rst == `RstEnable) begin
|
2020-04-18 03:21:09 +00:00
|
|
|
|
state <= STATE_IDLE;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
end else begin
|
2020-04-18 03:21:09 +00:00
|
|
|
|
state <= next_state;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-18 03:21:09 +00:00
|
|
|
|
// ״̬<EFBFBD>л<EFBFBD>
|
|
|
|
|
always @ (*) begin
|
|
|
|
|
if (rst == `RstEnable) begin
|
|
|
|
|
next_state <= STATE_IDLE;
|
|
|
|
|
end else begin
|
|
|
|
|
case (state)
|
|
|
|
|
STATE_IDLE: begin
|
|
|
|
|
// ĿǰֻҪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD>źŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ.
|
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>(Ƕ<EFBFBD><EFBFBD>)ʱ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (int_flag_i != `INT_NONE) begin
|
|
|
|
|
next_state <= STATE_ASSERT;
|
|
|
|
|
end else begin
|
|
|
|
|
next_state <= STATE_IDLE;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
STATE_ASSERT: begin
|
|
|
|
|
next_state <= STATE_WAIT_MRET;
|
|
|
|
|
end
|
|
|
|
|
STATE_WAIT_MRET: begin
|
|
|
|
|
if (inst_i == `INST_MRET) begin
|
|
|
|
|
next_state <= STATE_MRET;
|
|
|
|
|
end else begin
|
|
|
|
|
next_state <= STATE_WAIT_MRET;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
STATE_MRET: begin
|
|
|
|
|
next_state <= STATE_IDLE;
|
|
|
|
|
end
|
|
|
|
|
default: begin
|
|
|
|
|
next_state <= STATE_IDLE;
|
|
|
|
|
end
|
|
|
|
|
endcase
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD>ͬ<EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>CSR<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
always @ (*) begin
|
2020-04-11 11:03:49 +00:00
|
|
|
|
if (rst == `RstEnable) begin
|
|
|
|
|
raddr_o <= `ZeroWord;
|
|
|
|
|
end else begin
|
2020-04-18 03:21:09 +00:00
|
|
|
|
case (state)
|
|
|
|
|
STATE_IDLE: begin
|
|
|
|
|
raddr_o <= {20'h0, `CSR_MTVEC};
|
|
|
|
|
end
|
|
|
|
|
STATE_ASSERT: begin
|
|
|
|
|
raddr_o <= {20'h0, `CSR_MTVEC};
|
|
|
|
|
end
|
|
|
|
|
STATE_WAIT_MRET: begin
|
|
|
|
|
raddr_o <= {20'h0, `CSR_MEPC};
|
|
|
|
|
end
|
|
|
|
|
STATE_MRET: begin
|
|
|
|
|
raddr_o <= {20'h0, `CSR_MEPC};
|
|
|
|
|
end
|
|
|
|
|
default: begin
|
|
|
|
|
raddr_o <= {20'h0, `CSR_MTVEC};
|
|
|
|
|
end
|
|
|
|
|
endcase
|
2020-04-11 11:03:49 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-04-18 03:21:09 +00:00
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD>ź<EFBFBD>
|
|
|
|
|
// <EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>жϷ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>
|
|
|
|
|
always @ (posedge clk) begin
|
|
|
|
|
if (rst == `RstEnable) begin
|
|
|
|
|
int_assert_o <= `INT_DEASSERT;
|
|
|
|
|
int_addr_o <= `ZeroWord;
|
|
|
|
|
end else begin
|
|
|
|
|
case (state)
|
|
|
|
|
STATE_ASSERT: begin
|
|
|
|
|
int_assert_o <= `INT_ASSERT;
|
|
|
|
|
int_addr_o <= data_i;
|
|
|
|
|
end
|
|
|
|
|
STATE_MRET: begin
|
|
|
|
|
int_assert_o <= `INT_ASSERT;
|
|
|
|
|
int_addr_o <= data_i;
|
|
|
|
|
end
|
|
|
|
|
default: begin
|
|
|
|
|
int_assert_o <= `INT_DEASSERT;
|
|
|
|
|
int_addr_o <= `ZeroWord;
|
|
|
|
|
end
|
|
|
|
|
endcase
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD>ͬ<EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>CSR<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
2020-04-11 11:03:49 +00:00
|
|
|
|
always @ (posedge clk) begin
|
2020-03-29 15:19:14 +00:00
|
|
|
|
if (rst == `RstEnable) begin
|
2020-04-11 11:03:49 +00:00
|
|
|
|
we_o <= `WriteDisable;
|
|
|
|
|
waddr_o <= `ZeroWord;
|
2020-03-29 15:19:14 +00:00
|
|
|
|
data_o <= `ZeroWord;
|
|
|
|
|
end else begin
|
2020-04-18 03:21:09 +00:00
|
|
|
|
if (state == STATE_ASSERT) begin
|
|
|
|
|
we_o <= `WriteEnable;
|
|
|
|
|
waddr_o <= {20'h0, `CSR_MEPC};
|
|
|
|
|
data_o <= inst_addr_i;
|
|
|
|
|
end else begin
|
|
|
|
|
we_o <= `WriteEnable;
|
|
|
|
|
waddr_o <= {20'h0, `CSR_MCAUSE};
|
|
|
|
|
data_o <= {24'h0, int_flag_i};
|
|
|
|
|
end
|
2020-03-29 15:19:14 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
endmodule
|