rtl: core: fix sync interrupt

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/1/head
liangkangnan 2020-08-15 16:05:06 +08:00
parent fccb920070
commit 10a3df3e5a
2 changed files with 19 additions and 6 deletions

View File

@ -34,6 +34,7 @@ module clint(
// from ex
input wire jump_flag_i,
input wire[`InstAddrBus] jump_addr_i,
input wire div_started_i,
// from ctrl
input wire[`Hold_Flag_Bus] hold_flag_i, // 线
@ -63,10 +64,10 @@ module clint(
//
localparam S_INT_IDLE = 4'b0001;
localparam S_INT_SYNC_ASSERT = 4'b0010;
localparam S_INT_ASYNC_ASSERT = 4'b0100;
localparam S_INT_MRET = 4'b1000;
localparam S_INT_IDLE = 4'b0001;
localparam S_INT_SYNC_ASSERT = 4'b0010;
localparam S_INT_ASYNC_ASSERT = 4'b0100;
localparam S_INT_MRET = 4'b1000;
// CSR
localparam S_CSR_IDLE = 5'b00001;
@ -81,7 +82,7 @@ module clint(
reg[31:0] cause;
assign hold_flag_o = ((int_state != S_INT_IDLE) || (csr_state != S_CSR_IDLE))? `HoldEnable: `HoldDisable;
assign hold_flag_o = ((int_state != S_INT_IDLE) | (csr_state != S_CSR_IDLE))? `HoldEnable: `HoldDisable;
//
@ -90,7 +91,12 @@ module clint(
int_state = S_INT_IDLE;
end else begin
if (inst_i == `INST_ECALL || inst_i == `INST_EBREAK) begin
int_state = S_INT_SYNC_ASSERT;
//
if (div_started_i == `DivStop) begin
int_state = S_INT_SYNC_ASSERT;
end else begin
int_state = S_INT_IDLE;
end
end else if (int_flag_i != `INT_NONE && global_int_en_i == `True) begin
int_state = S_INT_ASYNC_ASSERT;
end else if (inst_i == `INST_MRET) begin
@ -110,8 +116,10 @@ module clint(
end else begin
case (csr_state)
S_CSR_IDLE: begin
//
if (int_state == S_INT_SYNC_ASSERT) begin
csr_state <= S_CSR_MEPC;
// 4
if (jump_flag_i == `JumpEnable) begin
inst_addr <= jump_addr_i - 4'h4;
end else begin
@ -128,12 +136,16 @@ module clint(
cause <= 32'd10;
end
endcase
//
end else if (int_state == S_INT_ASYNC_ASSERT) begin
//
cause <= 32'h80000004;
csr_state <= S_CSR_MEPC;
if (jump_flag_i == `JumpEnable) begin
inst_addr <= jump_addr_i;
//
end else if (div_started_i == `DivStart) begin
inst_addr <= inst_addr_i - 4'h4;
end else begin
inst_addr <= inst_addr_i;
end

View File

@ -354,6 +354,7 @@ module tinyriscv(
.jump_flag_i(ex_jump_flag_o),
.jump_addr_i(ex_jump_addr_o),
.hold_flag_i(ctrl_hold_flag_o),
.div_started_i(ex_div_start_o),
.data_i(csr_clint_data_o),
.csr_mtvec(csr_clint_csr_mtvec),
.csr_mepc(csr_clint_csr_mepc),