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

Subversion Repositories qrisc32

[/] [qrisc32/] [trunk/] [qrisc32_IF.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 vinogradov
//////////////////////////////////////////////////////////////////////////////////////////////
2
//    Project Qrisc32 is risc cpu implementation, purpose is studying
3
//    Digital System Design course at Kyoung Hee University during my PhD earning
4
//    Copyright (C) 2010  Vinogradov Viacheslav
5
//
6
//    This library is free software; you can redistribute it and/or
7
//   modify it under the terms of the GNU Lesser General Public
8
//    License as published by the Free Software Foundation; either
9
//    version 2.1 of the License, or (at your option) any later version.
10
//
11
//    This library is distributed in the hope that it will be useful,
12
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
//    Lesser General Public License for more details.
15
//
16
//    You should have received a copy of the GNU Lesser General Public
17
//    License along with this library; if not, write to the Free Software
18
//    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
//
20
//
21
//////////////////////////////////////////////////////////////////////////////////////////////
22
 
23
 
24
import risc_pack::*;
25
 
26
module qrisc32_IF(
27
        input                           clk,reset,
28
        interface                       avm_instructions,//avalon master port only for  reading instructions
29
 
30
        input                           pipe_stall,//feed back from MEM stage
31
 
32
        input                           new_address_valid,//feed back from  EX stage
33
        input[31:0]                     new_address,//feed back from  EX stage
34
 
35
        output bit[31:0]        instruction,
36
        output bit[31:0]        pc
37
        );
38
 
39
import risc_pack::*;
40
 
41
        bit[2:0]        offset_w;//
42
        bit[31:0]       base_w;//
43
        wire[31:0]      jump_address_w  =       base_w+offset_w;
44
 
45
        wire            if_stall                =       avm_instructions.wait_req | pipe_stall;
46
 
47
        bit[31:0]       stalled_adr0;
48
        bit[31:0]       stalled_adr1;
49
 
50
        always_comb
51
        begin
52
                pc<=avm_instructions.address_r;//
53
 
54
                base_w=avm_instructions.address_r;
55
                offset_w=4;
56
                if(if_stall)
57
                        offset_w=0;
58
                else
59
                if(new_address_valid)
60
                begin
61
                        base_w=new_address;
62
                        offset_w=0;
63
                end
64
        end
65
 
66
        always@(posedge clk)// or posedge reset)
67
        if(reset)
68
        begin
69
                avm_instructions.address_r<='0;//reset address!
70
                avm_instructions.rd<=1;//forever =1
71
                instruction<='0;//=ldr R0,R0 =nop
72
        end
73
        else
74
        begin
75
                if(~if_stall)
76
                begin
77
                        instruction<=avm_instructions.data_r;
78
                        avm_instructions.address_r<=jump_address_w;
79
                        stalled_adr0<=jump_address_w;
80
                        stalled_adr1<=stalled_adr0;
81
                end
82
                else
83
                begin
84
                        avm_instructions.address_r<=stalled_adr0;
85
                        //instruction<='0;
86
                        //instruction<=avm_instructions.data_r;
87
                        $display("[IF stage] Stalled->%s",(pipe_stall)?"Mem stage is stalled":"Fetching is stalled");
88
                end
89
        end
90
 
91
endmodule

powered by: WebSVN 2.1.0

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