Fetch, ICache: Autoize ICache/Fetch interface, and rename with more stylish names.
[firearm.git] / Fetch.v
diff --git a/Fetch.v b/Fetch.v
index 0a18b31..4dbe365 100644 (file)
--- a/Fetch.v
+++ b/Fetch.v
@@ -1,41 +1,54 @@
 module Fetch(
-       input clk,
-       input Nrst,
+       input              clk,
+       input              Nrst,
        
-       output wire [31:0] rd_addr,
-       output wire rd_req,
-       input rd_wait,
-       input [31:0] rd_data,
+       output wire [31:0] ic__rd_addr_0a,
+       output wire        ic__rd_req_0a,
+       input              ic__rd_wait_0a,
+       input       [31:0] ic__rd_data_0a,
        
-       input stall,
-       input jmp,
-       input [31:0] jmppc,
-       output wire bubble,
-       output wire [31:0] insn,
-       output reg [31:0] pc);
-
-       reg [31:0] prevpc;
-       initial
-               prevpc = 32'hFFFFFFFC;  /* ugh... the first pc we request will be this +4 */
-       always @(negedge Nrst)
-               prevpc <= 32'hFFFFFFFC;
+       input              stall_0a,
+       input              jmp_0a,
+       input       [31:0] jmppc_0a,
+       output reg         bubble_1a = 1,
+       output reg  [31:0] insn_1a = 0,
+       output reg  [31:0] pc_1a = 32'hFFFFFFFC);
        
-       always @(*)
+       reg qjmp = 0;   /* A jump has been queued up while we were waiting. */
+       reg [31:0] qjmppc;
+       always @(posedge clk or negedge Nrst)
                if (!Nrst)
-                       pc = 32'hFFFFFFFC;
-               else if (stall) /* don't change any internal state */
-                       pc = prevpc;
-               else if (jmp)
-                       pc = jmppc;
-               else
-                       pc = prevpc + 32'h4;
+                       qjmp <= 0;
+               else if ((ic__rd_wait_0a || stall_0a) && jmp_0a)
+                       {qjmp,qjmppc} <= {jmp_0a, jmppc_0a};
+               else if (!ic__rd_wait_0a && !stall_0a && qjmp)  /* It has already been intoed. */
+                       {qjmp,qjmppc} <= {1'b0, 32'hxxxxxxxx};
        
-       assign bubble = stall | rd_wait;
-       assign rd_addr = pc;
-       assign rd_req = !stall;
-       assign insn = rd_data;
-                       
-       always @(posedge clk)
-               if (!rd_wait || !Nrst)
-                       prevpc <= pc;
+       reg [31:0] reqpc_0a;
+       
+       /* Output latch logic */
+       assign ic__rd_addr_0a = reqpc_0a;
+       assign ic__rd_req_0a = 1;
+       always @(posedge clk or negedge Nrst)
+               if (!Nrst) begin
+                       bubble_1a <= 1;
+                       insn_1a <= 32'h00000000;
+                       pc_1a <= 32'h00000000;
+               end else if (!stall_0a) begin
+                       bubble_1a <= (jmp_0a || qjmp || ic__rd_wait_0a);
+                       insn_1a <= ic__rd_data_0a;
+                       pc_1a <= reqpc_0a;
+               end
+       
+       always @(posedge clk or negedge Nrst)
+               if (!Nrst)
+                       reqpc_0a <= 0;
+               else if (!stall_0a && !ic__rd_wait_0a) begin
+                       if (qjmp)
+                               reqpc_0a <= qjmppc;
+                       else if (jmp_0a)
+                               reqpc_0a <= jmppc_0a;
+                       else
+                               reqpc_0a <= reqpc_0a + 4;
+               end
 endmodule
This page took 0.021761 seconds and 4 git commands to generate.