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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber25/] [a25_fetch.v] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Fetch - Instantiates the fetch stage sub-modules of         //
4
//  the Amber 25 Core                                           //
5
//                                                              //
6
//  This file is part of the Amber project                      //
7
//  http://www.opencores.org/project,amber                      //
8
//                                                              //
9
//  Description                                                 //
10
//  Instantiates the Cache and Wishbone I/F                     //
11
//  Also contains a little bit of logic to decode memory        //
12
//  accesses to decide if they are cached or not                //
13
//                                                              //
14
//  Author(s):                                                  //
15
//      - Conor Santifort, csantifort.amber@gmail.com           //
16
//                                                              //
17
//////////////////////////////////////////////////////////////////
18
//                                                              //
19
// Copyright (C) 2011 Authors and OPENCORES.ORG                 //
20
//                                                              //
21
// This source file may be used and distributed without         //
22
// restriction provided that this copyright statement is not    //
23
// removed from the file and that any derivative work contains  //
24
// the original copyright notice and the associated disclaimer. //
25
//                                                              //
26
// This source file is free software; you can redistribute it   //
27
// and/or modify it under the terms of the GNU Lesser General   //
28
// Public License as published by the Free Software Foundation; //
29
// either version 2.1 of the License, or (at your option) any   //
30
// later version.                                               //
31
//                                                              //
32
// This source is distributed in the hope that it will be       //
33
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
34
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
35
// PURPOSE.  See the GNU Lesser General Public License for more //
36
// details.                                                     //
37
//                                                              //
38
// You should have received a copy of the GNU Lesser General    //
39
// Public License along with this source; if not, download it   //
40
// from http://www.opencores.org/lgpl.shtml                     //
41
//                                                              //
42
//////////////////////////////////////////////////////////////////
43
 
44
 
45
module a25_fetch
46
(
47
input                       i_clk,
48
input                       i_mem_stall,
49
input                       i_conflict,         // Decode stage stall pipeline because of an instruction conflict
50
output                      o_fetch_stall,      // when this is asserted all registers 
51
                                                // in decode and exec stages are frozen
52
input                       i_system_rdy,       // External system can stall core with this signal
53
 
54
input       [31:0]          i_iaddress,
55
input                       i_iaddress_valid,
56
input       [31:0]          i_iaddress_nxt,     // un-registered version of address to the cache rams
57
output      [31:0]          o_fetch_instruction,
58
 
59
input                       i_cache_enable,     // cache enable
60
input                       i_cache_flush,      // cache flush
61
input       [31:0]          i_cacheable_area,   // each bit corresponds to 2MB address space
62
 
63
output                      o_wb_req,
64
output                      o_wb_qword,         // High for a quad-word fetch request
65
output      [31:0]          o_wb_address,
66
input       [31:0]          i_wb_read_data,
67
input                       i_wb_ready
68
 
69
);
70
 
71
`include "memory_configuration.v"
72
 
73
wire                        core_stall;
74
wire                        cache_stall;
75
wire    [31:0]              cache_read_data;
76
wire                        sel_cache;
77
wire                        uncached_instruction_read;
78
wire                        address_cachable;
79
wire                        icache_wb_req;
80
wire                        wait_wb;
81
reg                         wb_req_r = 'd0;
82
 
83
// ======================================
84
// Memory Decode
85
// ======================================
86
assign address_cachable  = in_cachable_mem( i_iaddress ) && i_cacheable_area[i_iaddress[25:21]];
87
 
88
assign sel_cache         = address_cachable && i_iaddress_valid && i_cache_enable;
89
 
90
// Don't start wishbone transfers when the cache is stalling the core
91
// The cache stalls the core during its initialization sequence
92
assign uncached_instruction_read = !sel_cache && i_iaddress_valid && !(cache_stall);
93
 
94
// Return read data either from the wishbone bus or the cache
95
assign o_fetch_instruction = sel_cache                  ? cache_read_data :
96
                             uncached_instruction_read  ? i_wb_read_data  :
97
                                                          32'hffeeddcc    ;
98
 
99
// Stall the instruction decode and execute stages of the core
100
// when the fetch stage needs more than 1 cycle to return the requested
101
// read data
102
assign o_fetch_stall    = !i_system_rdy || wait_wb || cache_stall;
103
 
104
assign o_wb_address     = i_iaddress;
105
assign o_wb_req         = icache_wb_req || uncached_instruction_read;
106
assign o_wb_qword       = icache_wb_req;
107
 
108
assign wait_wb          = (o_wb_req || wb_req_r) && !i_wb_ready;
109
 
110
always @(posedge i_clk)
111
    wb_req_r <= o_wb_req && !i_wb_ready;
112
 
113
assign core_stall = o_fetch_stall || i_mem_stall || i_conflict;
114
 
115
// ======================================
116
// L1 Instruction Cache
117
// ======================================
118
a25_icache u_cache (
119
    .i_clk                      ( i_clk                 ),
120
    .i_core_stall               ( core_stall            ),
121
    .o_stall                    ( cache_stall           ),
122
 
123
    .i_select                   ( sel_cache             ),
124
    .i_address                  ( i_iaddress            ),
125
    .i_address_nxt              ( i_iaddress_nxt        ),
126
    .i_cache_enable             ( i_cache_enable        ),
127
    .i_cache_flush              ( i_cache_flush         ),
128
    .o_read_data                ( cache_read_data       ),
129
 
130
    .o_wb_req                   ( icache_wb_req         ),
131
    .i_wb_read_data             ( i_wb_read_data        ),
132
    .i_wb_ready                 ( i_wb_ready            )
133
);
134
 
135
 
136
endmodule
137
 

powered by: WebSVN 2.1.0

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