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

Subversion Repositories amber

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

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 35 csantifort
input                       i_exec_stall,
50 16 csantifort
input                       i_conflict,         // Decode stage stall pipeline because of an instruction conflict
51
output                      o_fetch_stall,      // when this is asserted all registers 
52
                                                // in decode and exec stages are frozen
53
input                       i_system_rdy,       // External system can stall core with this signal
54
 
55
input       [31:0]          i_iaddress,
56
input                       i_iaddress_valid,
57
input       [31:0]          i_iaddress_nxt,     // un-registered version of address to the cache rams
58
output      [31:0]          o_fetch_instruction,
59
 
60
input                       i_cache_enable,     // cache enable
61
input                       i_cache_flush,      // cache flush
62
input       [31:0]          i_cacheable_area,   // each bit corresponds to 2MB address space
63
 
64
output                      o_wb_req,
65
output      [31:0]          o_wb_address,
66 35 csantifort
input       [127:0]         i_wb_read_data,
67 16 csantifort
input                       i_wb_ready
68
 
69
);
70
 
71 82 csantifort
`include "memory_configuration.vh"
72 16 csantifort
 
73
wire                        core_stall;
74
wire                        cache_stall;
75 35 csantifort
wire    [127:0]             cache_read_data128;
76 16 csantifort
wire    [31:0]              cache_read_data;
77
wire                        sel_cache;
78
wire                        uncached_instruction_read;
79
wire                        address_cachable;
80
wire                        icache_wb_req;
81
wire                        wait_wb;
82
reg                         wb_req_r = 'd0;
83 35 csantifort
wire    [31:0]              wb_rdata32;
84 16 csantifort
 
85
// ======================================
86
// Memory Decode
87
// ======================================
88
assign address_cachable  = in_cachable_mem( i_iaddress ) && i_cacheable_area[i_iaddress[25:21]];
89
 
90
assign sel_cache         = address_cachable && i_iaddress_valid && i_cache_enable;
91
 
92
// Don't start wishbone transfers when the cache is stalling the core
93
// The cache stalls the core during its initialization sequence
94
assign uncached_instruction_read = !sel_cache && i_iaddress_valid && !(cache_stall);
95
 
96
// Return read data either from the wishbone bus or the cache
97 35 csantifort
 
98
assign cache_read_data     = i_iaddress[3:2] == 2'd0    ? cache_read_data128[ 31: 0] :
99
                             i_iaddress[3:2] == 2'd1    ? cache_read_data128[ 63:32] :
100
                             i_iaddress[3:2] == 2'd2    ? cache_read_data128[ 95:64] :
101
                                                          cache_read_data128[127:96] ;
102
 
103
assign wb_rdata32 = i_iaddress[3:2] == 2'd0 ? i_wb_read_data[ 31: 0] :
104
                    i_iaddress[3:2] == 2'd1 ? i_wb_read_data[ 63:32] :
105
                    i_iaddress[3:2] == 2'd2 ? i_wb_read_data[ 95:64] :
106
                                              i_wb_read_data[127:96] ;
107
 
108 16 csantifort
assign o_fetch_instruction = sel_cache                  ? cache_read_data :
109 35 csantifort
                             uncached_instruction_read  ? wb_rdata32      :
110 16 csantifort
                                                          32'hffeeddcc    ;
111
 
112
// Stall the instruction decode and execute stages of the core
113
// when the fetch stage needs more than 1 cycle to return the requested
114
// read data
115
assign o_fetch_stall    = !i_system_rdy || wait_wb || cache_stall;
116
 
117
assign o_wb_address     = i_iaddress;
118
assign o_wb_req         = icache_wb_req || uncached_instruction_read;
119
 
120
assign wait_wb          = (o_wb_req || wb_req_r) && !i_wb_ready;
121
 
122
always @(posedge i_clk)
123
    wb_req_r <= o_wb_req && !i_wb_ready;
124
 
125 35 csantifort
assign core_stall = o_fetch_stall || i_mem_stall || i_exec_stall || i_conflict;
126 16 csantifort
 
127
// ======================================
128
// L1 Instruction Cache
129
// ======================================
130
a25_icache u_cache (
131
    .i_clk                      ( i_clk                 ),
132
    .i_core_stall               ( core_stall            ),
133
    .o_stall                    ( cache_stall           ),
134
 
135
    .i_select                   ( sel_cache             ),
136
    .i_address                  ( i_iaddress            ),
137
    .i_address_nxt              ( i_iaddress_nxt        ),
138
    .i_cache_enable             ( i_cache_enable        ),
139
    .i_cache_flush              ( i_cache_flush         ),
140 35 csantifort
    .o_read_data                ( cache_read_data128    ),
141 16 csantifort
 
142
    .o_wb_req                   ( icache_wb_req         ),
143
    .i_wb_read_data             ( i_wb_read_data        ),
144
    .i_wb_ready                 ( i_wb_ready            )
145
);
146
 
147
 
148
endmodule
149
 

powered by: WebSVN 2.1.0

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