OpenCores
URL https://opencores.org/ocsvn/k68/k68/trunk

Subversion Repositories k68

[/] [k68/] [trunk/] [rtl/] [verilog/] [k68_fetch.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sybreon
//                              -*- Mode: Verilog -*-
2
// Filename        : k68_fetch.v
3
// Description     : RISC Like Fetch Unit
4
// Author          : Shawn Tan
5
// Created On      : Fri Feb  7 16:17:17 2003
6
// Last Modified By: .
7
// Last Modified On: .
8
// Update Count    : 0
9
// Status          : Unknown, Use with caution!
10
/////////////////////////////////////////////////////////////////////
11
////                                                             ////
12
//// Copyright (C) 2002 to Shawn Tan Ser Ngiap.                  ////
13
////                       shawn.tan@aeste.net                   ////
14
////                                                             ////
15
//// This source file may be used and distributed without        ////
16
//// restriction provided that this copyright statement is not   ////
17
//// removed from the file and that any derivative work contains ////
18
//// the original copyright notice and the associated disclaimer.////
19
////                                                             ////
20
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
21
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
22
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
23
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
24
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
25
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
26
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
27
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
28
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
29
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
30
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
31
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
32
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
33
////                                                             ////
34
/////////////////////////////////////////////////////////////////////
35
 
36
`include "k68_defines.v"
37
 
38
module k68_fetch (/*AUTOARG*/
39
   // Outputs
40
   p_cs_o, p_add_o, pc_o, op_o, imm_o,
41
   // Inputs
42
   p_dat_i, cpu_clk_i, mem_clk_i, rst_i, brch_i, pc_i
43
   ) ;
44
   parameter dw = `k68_DATA_W;
45
   parameter aw = `k68_ADDR_W;
46
   parameter nop = `k68_OP_NOP;
47
   parameter ow = `k68_OP_W;
48
   parameter zero = `ZERO;
49
   parameter reset = `k68_RST_VECTOR;
50
 
51
   input [ow-1:0] p_dat_i;
52
   input            cpu_clk_i,mem_clk_i,rst_i, brch_i;
53
   output           p_cs_o;//, rdy_o;
54
   output [aw-1:0]  p_add_o, pc_o;
55
   input [aw-1:0]   pc_i;
56
   output [ow-1:0] op_o;
57
   output [dw-1:0]   imm_o;
58
 
59
   reg               rdy;
60
   reg [ow-1:0]      op_o,immh_o,imml_o, tmpa,tmpb,tmpc,tmpd;
61
 
62
   // Internal State Counters Assume it takes 4 counts to read data
63
   reg [1:0]          mem_cnt, cpu_cnt;
64
 
65
   reg [aw-1:0]      p_add_o,pc;
66
 
67
   assign            pc_o = pc;
68
 
69
   assign            imm_o = {immh_o, imml_o};
70
   assign            p_cs_o = 1'b1;
71
 
72
   //
73
   // CPU SIDE
74
   //
75
 
76
   always @ (posedge cpu_clk_i) begin
77
      if (rst_i) begin
78
         /*AUTORESET*/
79
         // Beginning of autoreset for uninitialized flops
80
         cpu_cnt <= 0;
81
         immh_o <= 0;
82
         imml_o <= 0;
83
         op_o <= 0;
84
         p_add_o <= 0;
85
         pc <= 0;
86
         // End of automatics
87
         p_add_o <= reset;
88
         pc <= reset;
89
         op_o <= nop;
90
 
91
      end else begin
92
         if (rdy) begin
93
            case (cpu_cnt)
94
 
95
              2'b00: begin
96
                 op_o <= tmpa;
97
                 immh_o <= tmpb;
98
                 imml_o <= tmpc;
99
 
100
              end
101
 
102
              2'b01: begin
103
                 op_o <= tmpb;
104
                 immh_o <= tmpc;
105
                 imml_o <= tmpd;
106
 
107
              end
108
 
109
              2'b10: begin
110
                 op_o <= tmpc;
111
                 immh_o <= tmpd;
112
                 imml_o <= tmpa;
113
 
114
              end
115
 
116
              2'b11: begin
117
                 op_o <= tmpd;
118
                 immh_o <= tmpa;
119
                 imml_o <= tmpb;
120
 
121
              end
122
 
123
            endcase // case(cnt[3:2])
124
         end else begin // if (rdy)
125
            op_o <= nop;
126
            {immh_o, imml_o} <= zero;
127
 
128
         end // else: !if(rdy)
129
 
130
 
131
         if (brch_i) begin
132
            pc <= pc_i;
133
            cpu_cnt <= 2'd0;
134
            p_add_o <= pc_i;
135
 
136
         end else begin
137
 
138
            if (rdy) begin
139
               pc <= pc + 2'd2;
140
            end
141
 
142
            p_add_o <= p_add_o + 2'd2;
143
            cpu_cnt <= cpu_cnt + 1'd1;
144
 
145
         end // else: !if(brch_i)
146
 
147
      end
148
 
149
   end
150
 
151
 
152
   //
153
   //  RDY FLAG
154
   //
155
   always @ (/*AUTOSENSE*/brch_i or p_add_o or pc or rst_i) begin
156
      if (rst_i || brch_i) begin
157
         /*AUTORESET*/
158
         // Beginning of autoreset for uninitialized flops
159
         rdy <= 0;
160
         // End of automatics
161
      end else if (p_add_o[3:1] - pc[3:1] == 3'd3) begin
162
         rdy <= 1'b1;
163
      end else begin
164
         rdy <= 1'b0;
165
 
166
      end
167
 
168
   end // always @ (...
169
 
170
 
171
   wire [ow-1:0]     s_dat_i;
172
 
173
`ifdef k68_SWAP
174
   assign            s_dat_i = {p_dat_i[7:0],p_dat_i[15:8]};
175
`else
176
   assign            s_dat_i = p_dat_i;
177
`endif
178
 
179
   //
180
   // PMEM SIDE
181
   //
182
   always @(posedge mem_clk_i) begin
183
      if (rst_i) begin
184
         /*AUTORESET*/
185
         // Beginning of autoreset for uninitialized flops
186
         mem_cnt <= 0;
187
         tmpa <= 0;
188
         tmpb <= 0;
189
         tmpc <= 0;
190
         tmpd <= 0;
191
         // End of automatics
192
 
193
         tmpa <= nop;
194
         tmpb <= nop;
195
         tmpc <= nop;
196
         tmpd <= nop;
197
 
198
      end else begin
199
 
200
         if (mem_cnt == 2'b00) begin
201
            case (cpu_cnt)
202
              2'b00: tmpd <= s_dat_i;
203
              2'b01: tmpa <= s_dat_i;
204
              2'b10: tmpb <= s_dat_i;
205
              2'b11: tmpc <= s_dat_i;
206
 
207
            endcase // case(cpu_cnt)
208
 
209
         end
210
 
211
         if (brch_i) begin
212
            tmpd <= nop;
213
            tmpa <= nop;
214
            tmpc <= nop;
215
            tmpb <= nop;
216
 
217
         end
218
 
219
         mem_cnt <= mem_cnt + 1'd1;
220
 
221
      end
222
 
223
 
224
   end
225
 
226
 
227
endmodule // k68_fetch
228
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.