add get_fetch_action ready for conversion
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 26 Nov 2018 00:41:06 +0000 (00:41 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 26 Nov 2018 00:41:06 +0000 (00:41 +0000)
cpu.py

diff --git a/cpu.py b/cpu.py
index 98ea036524f93ae776fe4e8f262787f19c3e5e89..47985745841e156ea462c3f12b8066e511c8f791 100644 (file)
--- a/cpu.py
+++ b/cpu.py
@@ -204,6 +204,82 @@ class CPU(Module):
         for f in [F3.csrrc, F3.csrrci]: c[f] = ~written_value & previous_value
         return Case(funct3, c)
 
+    """
+    def get_fetch_action(self, fetch_output_state,
+        input `decode_action decode_action,
+        input load_store_misaligned,
+        input memory_interface_rw_address_valid,
+        input memory_interface_rw_wait,
+        input branch_taken,
+        input misaligned_jump_target,
+        input csr_op_is_valid
+        );
+    begin
+        case(fetch_output_state)
+        `fetch_output_state_empty:
+            get_fetch_action = `fetch_action_default;
+        `fetch_output_state_trap:
+            get_fetch_action = `fetch_action_ack_trap;
+        `fetch_output_state_valid: begin
+            if((decode_action & `decode_action_trap_illegal_instruction) != 0) begin
+                get_fetch_action = `fetch_action_error_trap;
+            end
+            else if((decode_action & `decode_action_trap_ecall_ebreak) != 0) begin
+                get_fetch_action = `fetch_action_noerror_trap;
+            end
+            else if((decode_action & (`decode_action_load | `decode_action_store)) != 0) begin
+                if(load_store_misaligned | ~memory_interface_rw_address_valid) begin
+                    get_fetch_action = `fetch_action_error_trap;
+                end
+                else if(memory_interface_rw_wait) begin
+                    get_fetch_action = `fetch_action_wait;
+                end
+                else begin
+                    get_fetch_action = `fetch_action_default;
+                end
+            end
+            else if((decode_action & `decode_action_fence_i) != 0) begin
+                get_fetch_action = `fetch_action_fence;
+            end
+            else if((decode_action & `decode_action_branch) != 0) begin
+                if(branch_taken) begin
+                    if(misaligned_jump_target) begin
+                        get_fetch_action = `fetch_action_error_trap;
+                    end
+                    else begin
+                        get_fetch_action = `fetch_action_jump;
+                    end
+                end
+                else
+                begin
+                    get_fetch_action = `fetch_action_default;
+                end
+            end
+            else if((decode_action & (`decode_action_jal | `decode_action_jalr)) != 0) begin
+                if(misaligned_jump_target) begin
+                    get_fetch_action = `fetch_action_error_trap;
+                end
+                else begin
+                    get_fetch_action = `fetch_action_jump;
+                end
+            end
+            else if((decode_action & `decode_action_csr) != 0) begin
+                if(csr_op_is_valid)
+                    get_fetch_action = `fetch_action_default;
+                else
+                    get_fetch_action = `fetch_action_error_trap;
+            end
+            else begin
+                get_fetch_action = `fetch_action_default;
+            end
+        end
+        default:
+            get_fetch_action = 32'hXXXXXXXX;
+        endcase
+    end
+    endfunction
+    """
+
     def __init__(self):
         self.clk = ClockSignal()
         self.reset = ResetSignal()