Exemplo n.º 1
0
def work(agi):
    ild_gendir = agi.common.options.gendir
    init_debug(agi)
    is_3dnow = _is_amd3dnow(agi)

    debug.write("state_space:\n %s" % agi.common.state_space)
    #return

    debug.write("DUMP STORAGE %s\n" % agi.common.options.gen_ild_storage)

    # Collect up interesting NT names.
    # We are going to use them when we generate pattern_t objects
    # and also when we build resolution functions.
    eosz_nts = ild_eosz.get_eosz_binding_nts(agi)
    easz_nts = ild_easz.get_easz_binding_nts(agi)
    imm_nts = ild_imm.get_imm_binding_nts(agi)

    disp_nts = ild_disp.get_disp_binding_nts(agi)
    brdisp_nts = ild_disp.get_brdisp_binding_nts(agi)

    #just for debugging
    _msg("EOSZ NTS:")
    for nt_name in eosz_nts:
        _msg(nt_name)

    _msg("\nEASZ NTS:")
    for nt_name in easz_nts:
        _msg(nt_name)

    _msg("\nIMMNTS:")
    for nt_name in imm_nts:
        _msg(nt_name)

    _msg("\nDISP NTS:")
    for nt_name in disp_nts:
        _msg(nt_name)

    _msg("\nBRDISP NTS:")
    for nt_name in brdisp_nts:
        _msg(nt_name)

    nested_nts = _get_nested_nts(agi)
    _msg("\NESTED NTS:")
    for nt_name in nested_nts:
        _msg(nt_name)

    #Get dictionary with all legal values for all interesting operands
    all_state_space = ild_cdict.get_all_constraints_state_space(agi)
    _msg("ALL_STATE_SPACE:")
    for k, v in all_state_space.items():
        _msg("%s: %s" % (k, v))

    #Get widths for the operands
    all_ops_widths = ild_cdict.get_state_op_widths(agi, all_state_space)

    _msg("ALL_OPS_WIDTHS:")
    for k, v in all_ops_widths.items():
        _msg("%s: %s" % (k, v))

    #generate a list of pattern_t objects that describes the ISA.
    #This is the main data structure for XED3
    ild_patterns = get_patterns(agi, is_3dnow, eosz_nts, easz_nts, imm_nts,
                                disp_nts, brdisp_nts, all_state_space)

    if ild_patterns:
        if agi.common.options.gen_ild_storage:
            #dump the ild_storage_data.py file
            emit_gen_info_lookup(agi, ild_patterns, is_3dnow, debug)
            reload(ild_storage_data)

        #get ild_storage_t object - the main data structure for ILD
        #essentially a 2D dictionary:
        #united_lookup[map][opcode] == [ ild_info_t ]
        #the ild_info_t objects are obtained both from grammar and
        #ild_storage_data.py file, so that if ild_info_t objects are
        #defined in ild_storage_data.py file, ILD will have information
        #about illegal map-opcodes too.
        united_lookup = _get_united_lookup(ild_patterns, is_3dnow)

        #generate modrm lookup tables
        ild_modrm.work(agi, united_lookup, debug)

        #dump_patterns is for debugging
        if verbosity.vild():
            dump_patterns(ild_patterns,
                          mbuild.join(ild_gendir, 'all_patterns.txt'))

        eosz_dict = ild_eosz.work(agi, united_lookup, eosz_nts, ild_gendir,
                                  debug)

        easz_dict = ild_easz.work(agi, united_lookup, easz_nts, ild_gendir,
                                  debug)

        #dump operand accessor functions
        agi.operand_storage.dump_operand_accessors(agi)

        if eosz_dict and easz_dict:
            ild_imm.work(agi, united_lookup, imm_nts, ild_gendir, eosz_dict,
                         debug)
            ild_disp.work(agi, united_lookup, disp_nts, brdisp_nts, ild_gendir,
                          eosz_dict, easz_dict, debug)

        #dump scanners headers - they might be different for different
        #models.
        scanners_dict = agi.common.ild_scanners_dict
        dump_header_with_header(agi, 'xed-ild-scanners.h', scanners_dict)

        getters_dict = agi.common.ild_getters_dict
        dump_header_with_header(agi, 'xed-ild-getters.h', getters_dict)

        gen_xed3(agi, ild_info, is_3dnow, ild_patterns, all_state_space,
                 ild_gendir, all_ops_widths)
Exemplo n.º 2
0
def work(agi):
    ild_gendir = agi.common.options.gendir
    init_debug(agi)

    debug.write("state_space:\n %s" % agi.common.state_space)

    # Collect up interesting NT names.
    # We are going to use them when we generate pattern_t objects
    # and also when we build resolution functions.
    eosz_nts   = ild_eosz.get_eosz_binding_nts(agi)
    easz_nts   = ild_easz.get_easz_binding_nts(agi)
    imm_nts    = ild_imm.get_imm_binding_nts(agi)
    disp_nts   = ild_disp.get_disp_binding_nts(agi)
    brdisp_nts = ild_disp.get_brdisp_binding_nts(agi)

    #just for debugging
    _msg("EOSZ NTS:")
    for nt_name in eosz_nts:
        _msg(nt_name)

    _msg("\nEASZ NTS:")
    for nt_name in easz_nts:
        _msg(nt_name)

    _msg("\nIMMNTS:")
    for nt_name in imm_nts:
        _msg(nt_name)

    _msg("\nDISP NTS:")
    for nt_name in disp_nts:
        _msg(nt_name)

    _msg("\nBRDISP NTS:")
    for nt_name in brdisp_nts:
        _msg(nt_name)

    nested_nts = _get_nested_nts(agi)
    _msg("\nNESTED NTS:")
    for nt_name in nested_nts:
        _msg(nt_name)

    #Get dictionary with all legal values for all interesting operands
    all_state_space = ild_cdict.get_all_constraints_state_space(agi)
    _msg("ALL_STATE_SPACE:")
    for k,v in list(all_state_space.items()):
        _msg("%s: %s"% (k,v))

    #Get widths for the operands
    all_ops_widths = ild_cdict.get_state_op_widths(agi, all_state_space)

    _msg("ALL_OPS_WIDTHS:")
    for k,v in list(all_ops_widths.items()):
        _msg("%s: %s"% (k,v))

    #generate a list of pattern_t objects that describes the ISA.
    #This is the main data structure for XED3
    ild_patterns = get_patterns(agi, eosz_nts, easz_nts, imm_nts,
                                disp_nts, brdisp_nts, all_state_space)

    if ild_patterns:

        #get ild_storage_t object - the main data structure for ILD
        #essentially a 2D dictionary:
        #ild_tbl[map][opcode] == [ ild_info_t ]
        #the ild_info_t objects are obtained from the grammar
        priority = 0
        ild_tbl = _get_info_storage(agi, ild_patterns, priority)

        #generate modrm lookup tables
        ild_modrm.work(agi, ild_tbl, debug)

        #dump_patterns is for debugging
        if verbosity.vild():
            dump_patterns(ild_patterns,
                          mbuild.join(ild_gendir, 'all_patterns.txt'))

        eosz_dict = ild_eosz.work(agi, ild_tbl, eosz_nts, ild_gendir, debug)
        easz_dict = ild_easz.work(agi, ild_tbl, easz_nts, ild_gendir, debug)

        #dump operand accessor functions
        agi.operand_storage.dump_operand_accessors(agi)
        
        if eosz_dict and easz_dict:
            ild_imm.work(agi, ild_tbl, imm_nts, ild_gendir,
                         eosz_dict, debug)
            ild_disp.work(agi, ild_tbl, disp_nts, brdisp_nts, ild_gendir,
                          eosz_dict, easz_dict, debug)

        # now handle the actual instructions
        gen_xed3(agi, ild_info, ild_patterns, 
                 all_state_space, ild_gendir, all_ops_widths)
Exemplo n.º 3
0
def _log(f,s):
    if verbosity.vild():
        f.write(s)