X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=cpu_fetch_stage.py;h=3d25d3507cdf8362b5467bbca2cf51240559affe;hb=84762ebcde7d4dc6493571f7337637e747139876;hp=a120573b6499ed1ca98ba2e2e298fbb22fffa4c9;hpb=2d4a23664382c3192bb492218ce01c07353ca118;p=rv32.git diff --git a/cpu_fetch_stage.py b/cpu_fetch_stage.py index a120573..3d25d35 100644 --- a/cpu_fetch_stage.py +++ b/cpu_fetch_stage.py @@ -41,70 +41,73 @@ class CPUFetchStage(Module): #input [31:0] memory_interface_fetch_data, self.memory_interface_fetch_data = Signal(32) self.memory_interface_fetch_valid = Signal() - input `fetch_action fetch_action, - input [31:0] target_pc, + self.fetch_action = Signal(fetch_action) + self.target_pc = Signal(32) self.output_pc = Signal(32, reset=reset_vector) self.output_instruction = Signal(32) - output reg `fetch_output_state output_state - + self.output_state = Signal(fetch_output_state, + reset=fetch_output_state_empty) + self.comb += [ self.cd_sys.clk.eq(self.clk), self.cd_sys.rst.eq(self.reset) ] fetch_pc = Signal(32, reset=reset_vector) - - self.sync += output_pc.eq((fetch_action == `fetch_action_wait) ? output_pc : fetch_pc); - - memory_interface_fetch_address = fetch_pc[31:2]; + + self.sync += If(fetch_action != fetch_action_wait, + output_pc.eq(fetch_pc)). + Else( output_pc.eq(output_pc)) # hmmm... + #self.sync += output_pc.eq((fetch_action == `fetch_action_wait) ? + # output_pc : fetch_pc); + + memory_interface_fetch_address = fetch_pc[2:] initial output_pc <= reset_vector; initial output_state <= `fetch_output_state_empty; - + delayed_instruction = Signal(32, reset=0); delayed_instruction_valid = Signal(reset=0); - + self.sync += delayed_instruction.eq(output_instruction) - - assign output_instruction = delayed_instruction_valid ? delayed_instruction : memory_interface_fetch_data; - - self.sync += delayed_instruction_valid.eq(fetch_action == `fetch_action_wait) - - always @(posedge clk or posedge reset) begin - if(reset) begin - output_state <= `fetch_output_state_empty; - end - else begin - case(fetch_action) - `fetch_action_default, - `fetch_action_ack_trap: begin - if(memory_interface_fetch_valid) begin - fetch_pc <= fetch_pc + 4; - output_state <= `fetch_output_state_valid; - end - else begin - fetch_pc <= mtvec; - output_state <= `fetch_output_state_trap; - end - end - `fetch_action_fence: begin - fetch_pc <= output_pc + 4; - output_state <= `fetch_output_state_empty; - end - `fetch_action_jump: begin - fetch_pc <= target_pc; - output_state <= `fetch_output_state_empty; - end - `fetch_action_error_trap, - `fetch_action_noerror_trap: begin - fetch_pc <= mtvec; - output_state <= `fetch_output_state_empty; - end - `fetch_action_wait: begin - fetch_pc <= fetch_pc; - output_state <= `fetch_output_state_valid; - end - endcase - end - end - endmodule + self.sync += output_state.eq(fetch_output_state_empty) + + self.comb += If(delayed_instruction_valid, + output_instruction.eq(delayed_instruction) + ).Else( + output_instruction.eq(memory_interface_fetch_data) + ) + + self.sync += delayed_instruction_valid.eq(fetch_action == + fetch_action_wait) + + fc = { + fetch_action_ack_trap: + If(memory_interface_fetch_valid, + [fetch_pc.eq(fetch_pc + 4), + output_state.eq(fetch_output_state_valid)] + ).Else( + [fetch_pc.eq(mtvec), + output_state.eq(fetch_output_state_trap)] + ), + fetch_action_fence: + [ fetch_pc.eq(output_pc + 4), + output_state.eq(fetch_output_state_empty) + ], + fetch_action_jump: + [ fetch_pc.eq(target_pc), + output_state.eq(fetch_output_state_empty) + ], + fetch_action_error_trap, + [fetch_pc.eq(mtvec), + output_state.eq(fetch_output_state_empty) + ], + fetch_action_wait: + [fetch_pc.eq(fetch_pc), + output_state.eq(fetch_output_state_valid) + ] + } + fc[fetch_action_default] = fc[fetch_action_ack_trap] + fc[fetch_action_noerror_trap] = fc[fetch_action_error_trap] + self.sync += Case(fetch_action, fc).makedefault(fetch_action_default) +