Esempio n. 1
0
 def __init__(self, count, width, coding={}):
     self._count = count
     self._width = width
     self._coding = coding
     self._dwords = binutils.requires(width, UHAL_DATA_WIDTH)
     self._charcount = binutils.charcount(width)
     self._bitmask = binutils.bitmask(width)
Esempio n. 2
0
 def __str__(self):
     """Returns formatted string representation to be used as row of a record
     report listing (showing line, name, hex value, dec value).
     """
     return RECORD_EOL.join([
         "0x{offset:04x} {value:0{chars}x}".format(
             offset=i, value=self.index(i), chars=charcount(RECORD_WIDTH))
         for i in range(self.lines)
     ])
Esempio n. 3
0
 def __str__(self):
     """Serialize image to memory dump format.
     >>> with open("memdump.txt", "w") as fs:
     ...     data = str(image)
     ...     fs.write(data)
     """
     chars = charcount(self.RECORD_WIDTH)
     return '\n'.join('{0:0{1}x}'.format(value, chars)
                      for value in self.lines())
Esempio n. 4
0
 def __str__(self):
     """Serialize image to memory dump format.
     >>> with open("memdump.txt", "w") as fs:
     ...     data = str(image)
     ...     fs.write(data)
     """
     chars = charcount(self.columns * TDF.DATA_WIDTH)
     return '\n'.join(
         TDF.ALGORITHM.hexstr(value) for value in self.algorithms())
Esempio n. 5
0
 def read(self):
     record = RecordData()
     pattern = re.compile('^[0-9a-f]{{{chars}}}(?:(?:\r)?{eol})?$'.format(
         chars=charcount(RECORD_WIDTH), eol=RECORD_EOL))
     for i, line in enumerate(self._file):
         if not pattern.match(line):
             raise ValueError(
                 "read(): format mismatch in line {lineno}".format(
                     lineno=i + 1))
         record.append(int(line, 16))
     return record
Esempio n. 6
0
    def read(self, fs):
        """Reads an image from a memory dump file stream *fs*.
        >>> with open("memdump.txt", "r") as fs:
        ...     image.read(fs)

        To produce a compatible memoy dump see method *dump()*. To read data
        from a test vector, see method *read_testvector()*.
        """
        # Clear image contents.
        self.clear()

        # Create file reader for memory dump. Note: take care to match the format
        # written by method *__str__*.
        reader = FileReader(fs, (
            ('muon', 'x{0}'.format(charcount(TDF.MUON.width)), TDF.MUON.count),
            ('eg', 'x{0}'.format(charcount(TDF.EG.width)), TDF.EG.count),
            ('tau', 'x{0}'.format(charcount(TDF.TAU.width)), TDF.TAU.count),
            ('jet', 'x{0}'.format(charcount(TDF.JET.width)), TDF.JET.count),
            ('ett', 'x{0}'.format(charcount(TDF.ETT.width))),
            ('ht', 'x{0}'.format(charcount(TDF.HT.width))),
            ('etm', 'x{0}'.format(charcount(TDF.ETM.width))),
            ('htm', 'x{0}'.format(charcount(TDF.HTM.width))),
            ('etmhf', 'x{0}'.format(charcount(TDF.ETMHF.width))),
            ('htmhf', 'x{0}'.format(charcount(TDF.HTMHF.width))),
            ('link_11_fr_0', 'x{0}'.format(charcount(TDF.LINK_11_FR_0.width))),
            ('link_11_fr_1', 'x{0}'.format(charcount(TDF.LINK_11_FR_1.width))),
            ('link_11_fr_2', 'x{0}'.format(charcount(TDF.LINK_11_FR_2.width))),
            ('link_11_fr_3', 'x{0}'.format(charcount(TDF.LINK_11_FR_3.width))),
            ('link_11_fr_4', 'x{0}'.format(charcount(TDF.LINK_11_FR_4.width))),
            ('link_11_fr_5', 'x{0}'.format(charcount(TDF.LINK_11_FR_5.width))),
            ('extcond', 'x{0}'.format(charcount(TDF.EXTCOND.width))),
        ))
        # Read data from file.
        data = reader.read()

        # Populate memory image.
        for i, values in enumerate(data['muon']):
            self.inject(values, self.MuonOffset + TDF.MUON.dwords * i,
                        TDF.MUON.dwords)
        for i, values in enumerate(data['eg']):
            self.inject(values, self.EgOffset + TDF.EG.dwords * i,
                        TDF.EG.dwords)
        for i, values in enumerate(data['tau']):
            self.inject(values, self.TauOffset + TDF.TAU.dwords * i,
                        TDF.TAU.dwords)
        for i, values in enumerate(data['jet']):
            self.inject(values, self.JetOffset + TDF.JET.dwords * i,
                        TDF.JET.dwords)
        self.inject(data['ett'], self.EttOffset, TDF.ETT.dwords)
        self.inject(data['ht'], self.HtOffset, TDF.HT.dwords)
        self.inject(data['etm'], self.EtmOffset, TDF.ETM.dwords)
        self.inject(data['htm'], self.HtmOffset, TDF.HTM.dwords)
        self.inject(data['etmhf'], self.EtmhfOffset, TDF.ETMHF.dwords)
        self.inject(data['htmhf'], self.HtmhfOffset, TDF.HTMHF.dwords)
        self.inject(data['link_11_fr_0'], self.L11f0Offset,
                    TDF.LINK_11_FR_0.dwords)
        self.inject(data['link_11_fr_1'], self.L11f1Offset,
                    TDF.LINK_11_FR_1.dwords)
        self.inject(data['link_11_fr_2'], self.L11f2Offset,
                    TDF.LINK_11_FR_2.dwords)
        self.inject(data['link_11_fr_3'], self.L11f3Offset,
                    TDF.LINK_11_FR_3.dwords)
        self.inject(data['link_11_fr_4'], self.L11f4Offset,
                    TDF.LINK_11_FR_4.dwords)
        self.inject(data['link_11_fr_5'], self.L11f5Offset,
                    TDF.LINK_11_FR_5.dwords)
        self.inject(data['extcond'], self.ExtCondOffset, TDF.EXTCOND.dwords)