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

Subversion Repositories myblaze

[/] [myblaze/] [trunk/] [rtl/] [fetch.py] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 rockee
# -*- coding: utf-8 -*-
2
"""
3
    fetch.py
4
    ========
5
 
6
    Fetch Unit
7
 
8
    :copyright: Copyright (c) 2010 Jian Luo.
9
    :author-email: jian <dot> luo <dot> cn <at> gmail <dot> com.
10
    :license: BSD, see LICENSE for details.
11
    :revision: $Id: fetch.py 3 2010-11-21 07:17:00Z rockee $
12
"""
13
 
14
from myhdl import *
15
from defines import *
16
from functions import *
17
 
18
def FetchUnit(
19
        clock,
20
        reset,
21
        enable,
22
        of_hazard,
23
        ex_alu_result,
24
        ex_branch,
25
        if_program_counter,
26
        imem_addr_out,
27
        imem_ena_out,
28
        ):
29
    """
30
    """
31
    MAX_IMEM_ADDR = 2**CFG_IMEM_SIZE
32
    if_comb_r_program_counter = Signal(intbv(0)[CFG_IMEM_SIZE:])
33
    if_r_program_counter = Signal(intbv(0)[CFG_IMEM_SIZE:])
34
 
35
    @always_comb
36
    def comb():
37
        program_counter = intbv(0)[CFG_IMEM_SIZE:]
38
        if reset:
39
            program_counter[:] = 0
40
        elif of_hazard:
41
            program_counter[:] = if_r_program_counter
42
        elif ex_branch:
43
            program_counter[:] = ex_alu_result[CFG_IMEM_SIZE:]
44
        else:
45
            #program_counter[:] = ((if_r_program_counter[CFG_IMEM_SIZE:2]+1)
46
                                    #<< 2) % MAX_IMEM_ADDR
47
            program_counter[:] = (if_r_program_counter+4) % MAX_IMEM_ADDR
48
        if_comb_r_program_counter.next = program_counter
49
        #if ex_branch:
50
            #program_counter[:] = ex_alu_result[CFG_IMEM_SIZE:]
51
        #else:
52
            #program_counter[:] = if_r_program_counter
53
            ###program_counter[:] = ((if_r_program_counter[CFG_IMEM_SIZE:2]+1)
54
                                    ###<< 2) % MAX_IMEM_ADDR
55
            ##program_counter[:] = (if_r_program_counter+4) % MAX_IMEM_ADDR
56
        #if_program_counter.next = program_counter
57
        #imem_addr_out.next = program_counter
58
        #if of_hazard:
59
            #if_comb_r_program_counter.next = program_counter
60
        #else:
61
            #if_comb_r_program_counter.next = (program_counter+4) % MAX_IMEM_ADDR
62
 
63
    @always(clock.posedge)
64
    def seq():
65
        if reset:
66
            if_r_program_counter.next = 0
67
        elif enable:
68
            if_r_program_counter.next = if_comb_r_program_counter
69
        #if __debug__:
70
            #print 'pc:=0x%x, enable:=%s, reset:=%s' % (
71
                #if_comb_r_program_counter, enable, reset)
72
 
73
    @always_comb
74
    def regout():
75
        imem_ena_out.next = enable
76
        imem_addr_out.next = if_comb_r_program_counter
77
        #if __debug__:
78
            #imem_addr_out.next = if_r_program_counter
79
 
80
        if_program_counter.next = if_r_program_counter
81
 
82
    return instances()
83
 
84
if __name__ == '__main__':
85
    clock = Signal(False)
86
    reset = Signal(False)
87
    enable = Signal(False)
88
    imem_addr_out = Signal(intbv(0)[CFG_IMEM_SIZE:])
89
    imem_ena_out = Signal(False)
90
    if_program_counter = Signal(intbv(0)[CFG_IMEM_SIZE:])
91
    of_hazard = Signal(False)
92
    ex_alu_result = Signal(intbv(0)[32:])
93
    ex_branch = Signal(False)
94
 
95
    args = [
96
        FetchUnit,
97
        clock,
98
        reset,
99
        enable,
100
        of_hazard,
101
        ex_alu_result,
102
        ex_branch,
103
        if_program_counter,
104
        imem_addr_out,
105
        imem_ena_out,
106
    ]
107
    toVHDL(*args)
108
    toVerilog(*args)
109
 
110
### EOF ###
111
# vim:smarttab:sts=4:ts=4:sw=4:et:ai:tw=80:
112
 

powered by: WebSVN 2.1.0

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