예제 #1
0
    def add_fasm_line(self, line, missing_features):
        if not line.set_feature:
            return

        self.feature_callback(line.set_feature)

        line_strs = tuple(fasm.fasm_line_to_string(line))
        assert len(line_strs) == 1
        line_str = line_strs[0]

        parts = line.set_feature.feature.split('.')
        tile = parts[0]
        feature = '.'.join(parts[1:])

        # canonical_features flattens multibit feature enables to only
        # single bit features, which is what enable_feature expects.
        #
        # canonical_features also filters out features that are not enabled,
        # which are no-ops.
        for flat_set_feature in fasm.canonical_features(line.set_feature):
            address = 0
            if flat_set_feature.start is not None:
                address = flat_set_feature.start

            try:
                self.enable_feature(tile, feature, address, line_str)
            except FasmLookupError as e:
                missing_features.append(str(e))
예제 #2
0
def main():
    parser = argparse.ArgumentParser()

    util.db_root_arg(parser)
    util.part_arg(parser)

    parser.add_argument('input')

    args = parser.parse_args()

    db = Database(args.db_root, args.part)

    grid = db.grid()

    base_address_to_tiles = {}

    for tile in grid.tiles():
        gridinfo = grid.gridinfo_at_tilename(tile)
        if BlockType.CLB_IO_CLK in gridinfo.bits:
            base_address = gridinfo.bits[BlockType.CLB_IO_CLK].base_address
            if base_address not in base_address_to_tiles:
                base_address_to_tiles[base_address] = []
            base_address_to_tiles[base_address].append(
                (tile, gridinfo.bits[BlockType.CLB_IO_CLK]))

    for line in fasm.parse_fasm_filename(args.input):
        is_unknown = False

        annotation_data = {}
        for annotation in line.annotations:
            annotation_data[annotation.name] = annotation.value

        if 'unknown_bit' not in annotation_data:
            continue

        base_address = int(annotation_data['unknown_segment'], 0)
        frame_offset = int(annotation_data['unknown_segbit'].split('_')[0])
        bit = int(annotation_data['unknown_segbit'].split('_')[1])
        offset = bit // 16

        if base_address not in base_address_to_tiles:
            print('# No tile for base address')
        else:
            for tile, bits in base_address_to_tiles[base_address]:
                if offset >= bits.offset and offset - bits.offset < bits.words:
                    print('# {} : {:02d}_{:02d}'.format(
                        tile, frame_offset,
                        bit - bitstream.WORD_SIZE_BITS * bits.offset))

        for l in fasm.fasm_line_to_string(line):
            print(l)
예제 #3
0
    def parse_fasm_filename(self, filename):
        for line in fasm.parse_fasm_filename(filename):
            if not line.set_feature:
                continue

            line_strs = tuple(fasm.fasm_line_to_string(line))
            assert len(line_strs) == 1
            line_str = line_strs[0]

            parts = line.set_feature.feature.split('.')
            tile = parts[0]
            feature = '.'.join(parts[1:])

            # canonical_features flattens multibit feature enables to only
            # single bit features, which is what enable_feature expects.
            #
            # canonical_features also filters out features that are not enabled,
            # which are no-ops.
            for flat_set_feature in fasm.canonical_features(line.set_feature):
                address = 0
                if flat_set_feature.start is not None:
                    address = flat_set_feature.start

                self.enable_feature(tile, feature, address, line_str)
예제 #4
0
def print_memfasm(memfasm):
    for mf in memfasm:
        print(type(mf))
        print(next(fasm.fasm_line_to_string(mf)))
예제 #5
0
def fasm_to_asc(in_fasm, outf, device):
    """Convert an FASM input to an ASC file

    Set input enable defaults, RAM powerup, and enables all ColBufCtrl (until modeled in VPR see: #464)
    """

    ic = icebox.iceconfig()

    init_method_name = "setup_empty_{}".format(device.lower()[2:])
    assert hasattr(ic,
                   init_method_name), "no icebox method to init empty device"
    getattr(ic, init_method_name)()

    device_1k = ic.device == "1k"

    fasmdb = read_ice_db(ic)
    # TODO: upstream init "default" bitstream
    locs = [(x, y) for x in range(ic.max_x + 1) for y in range(ic.max_y + 1)]
    for tile_loc in locs:
        tile = ic.tile(*tile_loc)
        if tile is None:
            continue
        db = ic.tile_db(*tile_loc)
        tile_type = ic.tile_type(*tile_loc)
        for entry in db:
            if (device_1k and
                ((tile_type == "IO" and entry[-1] in ["IE_0", "IE_1"]) or
                 (tile_type == "RAMB" and entry[-1] == "PowerUp"))
                    or (entry[-2] == "ColBufCtrl")):
                tile_bits = _tile_to_array(tile)
                tile_type = ic.tile_type(*tile_loc)
                bm, bv = _get_iceconfig_bits(tile_bits, entry[0])
                tile_bits[bm] = bv[bm]
                _array_to_tile(tile_bits, tile)

    missing_features = []
    for line in fasm.parse_fasm_string(in_fasm.read()):
        if not line.set_feature:
            continue

        line_strs = tuple(fasm.fasm_line_to_string(line))
        assert len(line_strs) == 1

        feature = Feature.from_fasm_entry(
            FasmEntry(line.set_feature.feature, []))

        def find_ieren(ic, loc, iob):
            tmap = [
                xx[3:] for xx in ic.ieren_db()
                if xx[:3] == (tuple(loc) + (iob, ))
            ]
            assert len(tmap) < 2, "expected 1 IEREN_DB entry found {}".format(
                len(tmap))

            if len(tmap) == 0:
                print("no ieren found for {}".format((tile_loc + (iob, ))))
                return
            return tmap[0]

        # fix up for IO
        if feature.parts[-1] == "SimpleInput":
            iob = int(feature.parts[-2][-1])
            new_ieren = find_ieren(ic, feature.loc, iob)

            feature.parts[-1] = "PINTYPE_0"
            db_entry = fasmdb[feature.to_fasm_entry().feature]
            _set_feature_bits(ic, db_entry.loc, db_entry.bit_tuples)

            feature.loc = new_ieren[:2]
            feature.parts[-2] = "IoCtrl"
            feature.parts[-1] = "IE_{}".format(new_ieren[2])
            db_entry = fasmdb[feature.to_fasm_entry().feature]
            _set_feature_bits(ic, db_entry.loc, db_entry.bit_tuples)
            feature.parts[-1] = "REN_{}".format(new_ieren[2])
            db_entry = fasmdb[feature.to_fasm_entry().feature]
            _set_feature_bits(ic, db_entry.loc, db_entry.bit_tuples)
            continue

        if feature.parts[-1] == "SimpleOutput":
            iob = int(feature.parts[-2][-1])
            new_ieren = find_ieren(ic, feature.loc, iob)

            feature.parts[-1] = "PINTYPE_3"
            db_entry = fasmdb[feature.to_fasm_entry().feature]
            _set_feature_bits(ic, db_entry.loc, db_entry.bit_tuples)
            feature.parts[-1] = "PINTYPE_4"
            db_entry = fasmdb[feature.to_fasm_entry().feature]
            _set_feature_bits(ic, db_entry.loc, db_entry.bit_tuples)

            feature.loc = new_ieren[:2]
            feature.parts[-2] = "IoCtrl"
            feature.parts[-1] = "REN_{}".format(new_ieren[2])
            db_entry = fasmdb[feature.to_fasm_entry().feature]
            _set_feature_bits(ic, db_entry.loc, db_entry.bit_tuples)
            continue

        ## special case for RAM INIT values
        tile_type, loc = feature.tile_type, feature.loc
        if tile_type == "RAMB" and feature.parts[-1].startswith("INIT"):
            tloc = tuple(loc)
            if tloc not in ic.ram_data:
                ic.ram_data[tloc] = [64 * "0" for _ in range(16)]
            tile = ic.ram_data[tloc]
            tile_bits = _tile_to_array(tile, is_hex=True)
        elif tile_type == "RAMB" and feature.parts[-1].endswith("_MODE"):
            # hack to force modes to the RAMT
            tile = ic.tile(loc[0], loc[1] + 1)
            tile_bits = _tile_to_array(tile)
        else:
            tile = ic.tile(*loc)
            tile_bits = _tile_to_array(tile)

        # lookup feature and convert
        for canonical_feature in fasm.canonical_features(line.set_feature):
            key = fasm.set_feature_to_str(canonical_feature)
            feature = fasmdb[key]
            bm, bv = _get_feature_bits(tile_bits, feature.bit_tuples)

            tile_bits[bm] = bv[bm]

        if tile_type == "RAMB" and feature.parts[-1].startswith("INIT"):
            _array_to_tile(tile_bits, tile, is_hex=True)
        else:
            _array_to_tile(tile_bits, tile)

    # TODO: would be nice to upstream a way to write to non-files
    ic.write_file(outf.name)