class TestSRAMBareLoadStoreUnit(BareLoadStoreUnit):
- def __init__(self, addr_wid=64, mask_wid=4, data_wid=64):
- super().__init__(addr_wid, mask_wid, data_wid)
+ def __init__(self, pspec):
+ super().__init__(pspec)
def elaborate(self, platform):
m = super().elaborate(platform)
class TestSRAMBareFetchUnit(BareFetchUnit):
- def __init__(self, addr_wid=64, data_wid=64):
- super().__init__(addr_wid, data_wid)
+ def __init__(self, pspec):
+ super().__init__(pspec)
# small 16-entry Memory
self.mem = Memory(width=self.data_wid, depth=32)
#'test_cache_wb': TestCacheFetchUnit
}
fukls = fudict[pspec.imem_ifacetype]
- self.fu = fukls(addr_wid=pspec.addr_wid, # address range
- data_wid=pspec.reg_wid) # data bus width
+ self.fu = fukls(pspec)
#'test_cache_wb': TestCacheLoadStoreUnit
}
lsikls = lsidict[pspec.ldst_ifacetype]
- self.lsi = lsikls(addr_wid=pspec.addr_wid, # address range
- mask_wid=pspec.mask_wid, # cache line range
- data_wid=pspec.reg_wid) # data bus width
+ self.lsi = lsikls(pspec)
class ConfigMemoryPortInterface:
def tst_lsmemtype(ifacetype):
m = Module()
- pspec = TestMemPspec(ldst_ifacetype=ifacetype, addr_wid=64,
+ pspec = TestMemPspec(ldst_ifacetype=ifacetype,
+ imem_ifacetype='' , addr_wid=64,
mask_wid=4,
reg_wid=32)
dut = ConfigLoadStoreUnit(pspec).lsi
"""
dut = Module()
pspec = TestMemPspec(ldst_ifacetype=ifacetype,
+ imem_ifacetype='',
addr_wid=48,
mask_wid=8,
reg_wid=64)
class TestMemFetchUnit(FetchUnitInterface, Elaboratable):
- def __init__(self, addr_wid=32, data_wid=32):
- print ("testmemfetchunit", addr_wid, data_wid)
- super().__init__(addr_wid=addr_wid, data_wid=data_wid)
+ def __init__(self, pspec):
+ print ("testmemfetchunit", pspec.addr_wid, pspec.reg_wid)
+ super().__init__(pspec)
# limit TestMemory to 2^6 entries of regwid size
self.mem = TestMemory(self.data_wid, 6, readonly=True)
class FetchUnitInterface:
- def __init__(self, addr_wid=32, data_wid=32):
- self.addr_wid = addr_wid
- self.data_wid = data_wid
- self.adr_lsbs = log2_int(data_wid//8)
- self.ibus = Record(make_wb_layout(addr_wid, data_wid//8, data_wid))
- bad_wid = addr_wid - self.adr_lsbs # TODO: is this correct?
+ def __init__(self, pspec):
+ self.pspec = pspec
+ self.addr_wid = pspec.addr_wid
+ self.data_wid = pspec.reg_wid
+ self.adr_lsbs = log2_int(pspec.reg_wid//8)
+ self.ibus = Record(make_wb_layout(pspec))
+ bad_wid = pspec.addr_wid - self.adr_lsbs # TODO: is this correct?
# inputs: address to fetch PC, and valid/stall signalling
- self.a_pc_i = Signal(addr_wid)
+ self.a_pc_i = Signal(self.addr_wid)
self.a_stall_i = Signal()
self.a_valid_i = Signal()
self.f_stall_i = Signal()
# outputs: instruction (or error), and busy indicators
self.a_busy_o = Signal()
self.f_busy_o = Signal()
- self.f_instr_o = Signal(data_wid)
+ self.f_instr_o = Signal(self.data_wid)
self.f_fetch_err_o = Signal()
self.f_badaddr_o = Signal(bad_wid)
class CachedFetchUnit(FetchUnitInterface, Elaboratable):
- def __init__(self, *icache_args, addr_wid=32, data_wid=32):
- super().__init__(addr_wid=addr_wid, data_wid=data_wid)
+ def __init__(self, pspec):
+ super().__init__(pspec)
- self.icache_args = icache_args
+ self.icache_args = pspec.icache_args
self.a_flush = Signal()
self.f_pc = Signal(addr_wid)
icache.s2_valid.eq(self.f_valid_i & f_icache_select)
]
- iba = WishboneArbiter(self.addr_wid, self.adr_lsbs, self.data_wid)
+ iba = WishboneArbiter(self.pspec)
m.submodules.ibus_arbiter = iba
m.d.comb += iba.bus.connect(self.ibus)
class LoadStoreUnitInterface:
- def __init__(self, addr_wid=32, mask_wid=4, data_wid=32):
- print ("loadstoreunit addr mask data", addr_wid, mask_wid, data_wid)
- self.dbus = Record(make_wb_layout(addr_wid, mask_wid, data_wid))
+ def __init__(self, pspec):
+ self.pspec = pspec
+ self.dbus = Record(make_wb_layout(pspec))
print (self.dbus.sel.shape())
- self.mask_wid = mask_wid
- self.addr_wid = addr_wid
- self.data_wid = data_wid
+ self.mask_wid = mask_wid = pspec.mask_wid
+ self.addr_wid = addr_wid = pspec.addr_wid
+ self.data_wid = data_wid = pspec.reg_wid
+ print ("loadstoreunit addr mask data", addr_wid, mask_wid, data_wid)
self.adr_lsbs = log2_int(mask_wid) # LSBs of addr covered by mask
badwid = addr_wid-self.adr_lsbs # TODO: is this correct?
class CachedLoadStoreUnit(LoadStoreUnitInterface, Elaboratable):
- def __init__(self, *dcache_args, addr_wid=32, mask_wid=4, data_wid=32):
- super().__init__(addr_wid, mask_wid, data_wid)
+ def __init__(self, pspec):
+ super().__init__(pspec)
- self.dcache_args = dcache_args
+ self.dcache_args = psiec.dcache_args
self.x_fence_i = Signal()
self.x_flush = Signal()
wrbuf_r_data.eq(wrbuf.r_data),
]
- dba = WishboneArbiter(self.addr_wid, self.mask_wid, self.data_wid)
+ dba = WishboneArbiter(self.pspec)
m.submodules.dbus_arbiter = dba
m.d.comb += dba.bus.connect(self.dbus)
from nmigen.utils import log2_int
-__all__ = ["Cycle", "wishbone_layout", "make_wb_layout", "WishboneArbiter"]
+__all__ = ["Cycle", "make_wb_layout", "WishboneArbiter"]
class Cycle:
END = 7
-def make_wb_layout(addr_wid, mask_wid, data_wid):
+def make_wb_layout(spec):
+ addr_wid, mask_wid, data_wid = spec.addr_wid, spec.mask_wid, spec.reg_wid
adr_lsbs = log2_int(mask_wid) # LSBs of addr covered by mask
- badwid = addr_wid-adr_lsbs # MSBs (not covered by mask)
+ badwid = spec.addr_wid-adr_lsbs # MSBs (not covered by mask)
return [
("adr", badwid , DIR_FANOUT),
("err", 1, DIR_FANIN)
]
-wishbone_layout = make_wb_layout(32, 4, 32)
-
class WishboneArbiter(Elaboratable):
- def __init__(self, addr_wid=32, mask_wid=4, data_wid=32):
- self.bus = Record(make_wb_layout(addr_wid, mask_wid, data_wid))
+ def __init__(self, pspec):
+ self.bus = Record(make_wb_layout(pspec))
self._port_map = dict()
def port(self, priority):