- def elaborate(self, platform):
- m = super().elaborate(platform)
- comb = m.d.comb
-
- # create dcache module
- m.submodules.dcache = dcache = self.dcache
-
- # temp vars
- d_out, l_out, dbus = self.d_out, self.l_out, self.dbus
-
- with m.If(d_out.error):
- with m.If(d_out.cache_paradox):
- comb += self.derror.eq(1)
- # dsisr(63 - 38) := not r2.req.load;
- # -- XXX there is no architected bit for this
- # -- (probably should be a machine check in fact)
- # dsisr(63 - 35) := d_in.cache_paradox;
- with m.Else():
- # Look up the translation for TLB miss
- # and also for permission error and RC error
- # in case the PTE has been updated.
- comb += self.mmureq.eq(1)
- # v.state := MMU_LOOKUP;
- # v.stage1_en := '0';
-
- exc = self.pi.exc_o
-
- #happened, alignment, instr_fault, invalid,
- comb += exc.happened.eq(d_out.error | l_out.err)
- comb += exc.invalid.eq(l_out.invalid)
-
- #badtree, perm_error, rc_error, segment_fault
- comb += exc.badtree.eq(l_out.badtree)
- comb += exc.perm_error.eq(l_out.perm_error)
- comb += exc.rc_error.eq(l_out.rc_error)
- comb += exc.segment_fault.eq(l_out.segerr)
-
- # TODO connect those signals somewhere
- #print(d_out.valid) -> no error
- #print(d_out.store_done) -> no error
- #print(d_out.cache_paradox) -> ?
- #print(l_out.done) -> no error
-
- # TODO some exceptions set SPRs
-
- # TODO, connect dcache wb_in/wb_out to "standard" nmigen Wishbone bus
- comb += dbus.adr.eq(dcache.wb_out.adr)
- comb += dbus.dat_w.eq(dcache.wb_out.dat)
- comb += dbus.sel.eq(dcache.wb_out.sel)
- comb += dbus.cyc.eq(dcache.wb_out.cyc)
- comb += dbus.stb.eq(dcache.wb_out.stb)
- comb += dbus.we.eq(dcache.wb_out.we)
-
- comb += dcache.wb_in.dat.eq(dbus.dat_r)
- comb += dcache.wb_in.ack.eq(dbus.ack)
- if hasattr(dbus, "stall"):
- comb += dcache.wb_in.stall.eq(dbus.stall)
-
- # create a blip (single pulse) on valid read/write request
- m.d.comb += self.d_validblip.eq(rising_edge(m, self.d_valid))
-
- # write out d data only when flag set
- with m.If(self.d_w_valid):
- m.d.sync += self.d_in.data.eq(self.d_w_data)
- with m.Else():
- m.d.sync += self.d_in.data.eq(0)
-
- return m
-
- def ports(self):
- yield from super().ports()
- # TODO: memory ports
-
-
-class TestSRAMLoadStore1(LoadStore1):
- def __init__(self, pspec):
- super().__init__(pspec)
- pspec = self.pspec
- # small 32-entry Memory
- if (hasattr(pspec, "dmem_test_depth") and
- isinstance(pspec.dmem_test_depth, int)):
- depth = pspec.dmem_test_depth
- else:
- depth = 32
- print("TestSRAMBareLoadStoreUnit depth", depth)
-
- self.mem = Memory(width=pspec.reg_wid, depth=depth)
-
- def elaborate(self, platform):
- m = super().elaborate(platform)
- comb = m.d.comb
- m.submodules.sram = sram = SRAM(memory=self.mem, granularity=8,
- features={'cti', 'bte', 'err'})
- dbus = self.dbus
-
- # directly connect the wishbone bus of LoadStoreUnitInterface to SRAM
- # note: SRAM is a target (slave), dbus is initiator (master)
- fanouts = ['dat_w', 'sel', 'cyc', 'stb', 'we', 'cti', 'bte']
- fanins = ['dat_r', 'ack', 'err']
- for fanout in fanouts:
- print("fanout", fanout, getattr(sram.bus, fanout).shape(),
- getattr(dbus, fanout).shape())
- comb += getattr(sram.bus, fanout).eq(getattr(dbus, fanout))
- comb += getattr(sram.bus, fanout).eq(getattr(dbus, fanout))
- for fanin in fanins:
- comb += getattr(dbus, fanin).eq(getattr(sram.bus, fanin))
- # connect address
- comb += sram.bus.adr.eq(dbus.adr)
-
- return m