Example #1
0
def main():
    """
    Program main
    """
    args = sys.argv[1:]
    cmdline = microprobe.utils.cmdline.CLI("MicroprobeTest (mpt) to C tool",
                                           mpt_options=True,
                                           default_config_file="mp_mpt2c.cfg",
                                           force_required=['target'])

    groupname = "MPT to C arguments"
    cmdline.add_group(groupname, "Command arguments related to MPT to C tool")

    cmdline.add_option("c-output-file",
                       "O",
                       None,
                       "C output file name",
                       group=groupname,
                       opt_type=new_file_ext(".c"),
                       required=True)

    groupname = "Fixing options"
    cmdline.add_group(groupname, "Command arguments related to fixing options")
    cmdline.add_flag("fix-indirect-branches", None,
                     "Fix branches without known target", groupname)
    cmdline.add_flag(
        "fix-branch-next", None, "Force target of branches to be the next "
        "sequential instruction", groupname)
    cmdline.add_flag(
        "fix-memory-references", None,
        "Ensure that registers used by instructions accessing "
        "storage are initialized to valid locations", groupname)
    cmdline.add_flag(
        "fix-memory-registers", None,
        "Fix non-storage instructions touching registers used for"
        " storage address computations (implies "
        "--fix-memory-referenes flag)", groupname)

    cmdline.add_flag("endless", None,
                     "Wrap the code generated within an endless loop",
                     groupname)

    print_info("Processing input arguments...")
    cmdline.main(args, _main)
Example #2
0
def main():
    """
    Program main
    """
    args = sys.argv[1:]
    cmdline = microprobe.utils.cmdline.CLI(
        "MicroprobeTest (mpt) to TRACE tool",
        mpt_options=True,
        default_config_file="mp_mpt2trace.cfg",
        force_required=['target']
    )

    groupname = "MPT to trace arguments"
    cmdline.add_group(
        groupname,
        "Command arguments related to MPT to trace tool")

    cmdline.add_option(
        "trace-output-file",
        "O",
        None,
        "C output file name",
        group=groupname,
        opt_type=new_file_ext([".qt", ".qt.gz", ".qt.bz2"]),
        required=True
    )

    groupname = "Trace generation options"
    cmdline.add_group(groupname,
                      "Command arguments related to trace generation options")

    cmdline.add_option(
        "default-memory-access-pattern", None, None,
        "Memory access pattern for memory references that are not modeled by"
        "Microprobe or not modeled using 'MP' decorator in MPT file. "
        "Format: comma separated list of addresses or address ranges. If a "
        "file path is provided, the file is readed to gather the list of "
        "addresses.  The format of the file should be one address or range "
        "per line. Address range format is : <start>-<end>-<strid>. E.g. "
        "0x100-0x200-0x010 will generate 0x100,0x110,0x120...0x1F0,0x200 "
        "pattern.",
        group=groupname,
        opt_type=file_with(csv_with_ranges(0, 0xFFFFFFFFFFFFFFFF)),
    )

    cmdline.add_option(
        "default-branch-pattern", None, None,
        "Branch pattern for branches that are not modeled by"
        "Microprobe or not modeled using 'BP' decorator in MPT file. "
        "Format: string with T or N, for taken and not taken branches, "
        " respectively. If a file path is provided, the file is readed to "
        "gather the branch pattern. The format of the file should be one "
        "string providing the branch pattern (T and N characters).",
        group=groupname,
        opt_type=file_with(string_with_chars('TN')),
    )

    cmdline.add_option(
        "default-branch-indirect-target-pattern", None, None,
        "Branch target pattern for branches that are not modeled by"
        "Microprobe or not modeled using 'BT' decorator in MPT file. "
        "Format: comma separated list of target addresses. If a file "
        "path is provided, the file is readed to gather the list of addresses."
        " The format of the file should be one address per line.",
        group=groupname,
        opt_type=file_with(csv_with_integer),
    )

    cmdline.add_option(
        "max-trace-size", None, _DEFAULT_MAX_INS,
        "Maximum trace size in intructions. Default: %d" % _DEFAULT_MAX_INS,
        group=groupname,
        opt_type=int_type(0, 999999999999),
    )

    cmdline.add_flag(
        "show-trace",
        None,
        "Show trace while being generated",
        group=groupname,
    )

    cmdline.add_flag(
        "safe-bin", None, "Ignore unrecognized binary codifications (do not"
        "fail). Useful when MPTs are generated by dumping directly code "
        "pages, which contain padding zeros and other non-code stuff)",
        groupname
    )

    print_info("Processing input arguments...")
    cmdline.main(args, _main)
Example #3
0
def main():
    """
    Program main
    """
    args = sys.argv[1:]
    cmdline = CLI(
        "Microprobe Objdump to MPT tool",
        default_config_file="mp_objdump2mpt.cfg",
        force_required=['target']
    )

    groupname = "Objdump to MPT arguments"

    cmdline.add_group(
        groupname, "Command arguments related to Objdump to MPT tool"
    )

    cmdline.add_option(
        "input-objdump-file",
        "i",
        None,
        "Objdump file to process, if not provided, the input is read from"
        " standard input",
        group=groupname,
        opt_type=existing_file,
        required=False
    )

    cmdline.add_option(
        "output-mpt-file",
        "O",
        None,
        "Output file name",
        group=groupname,
        opt_type=new_file_ext(".mpt"),
        required=True
    )

    cmdline.add_flag(
        "strict",
        "S",
        "Be strict when parsing objdump input, if not set, silently skip "
        "unparsed elements",
        group=groupname
    )

    cmdline.add_option(
        "sections",
        "s", ['.text'],
        "Space separated CODE section names to interpret. "
        "(default: '.text' section)",
        group=groupname,
        nargs='+',
        required=False
    )

    cmdline.add_option(
        "from-address",
        "f",
        0x0,
        "If set, start interpreting from this address",
        group=groupname,
        opt_type=int_type(0, float('+inf')),
        required=False
    )

    cmdline.add_option(
        "to-address",
        "t",
        float('+inf'),
        "If set, end interpreting at this address",
        group=groupname,
        opt_type=int_type(0, float('+inf')),
        required=False
    )

    cmdline.add_option(
        "default-code-address",
        "X",
        None,
        "Default code address",
        group=groupname,
        opt_type=int_type(0, float('+inf')),
        required=False
    )

    cmdline.add_option(
        "default-data-address",
        "D",
        None,
        "Default data address",
        group=groupname,
        opt_type=int_type(0, float('+inf')),
        required=False
    )

    cmdline.add_flag(
        "elf-abi",
        None,
        "Ensure ELF Application Binary Interface (e.g. define stack, stack"
        " pointer, etc.)",
        group=groupname
    )

    cmdline.add_option(
        "stack-size",
        None,
        4096,
        "Stack size in bytes (Default: 4096)",
        group=groupname,
        opt_type=int_type(0, float('+inf')),
        required=False
    )

    cmdline.add_option(
        "stack-name",
        None,
        None,
        "Stack name (Default: microprobe_stack)",
        group=groupname,
        opt_type=str,
        required=False
    )

    cmdline.add_option(
        "stack-address",
        None,
        None,
        "Stack address (Default: allocated in the data area)",
        group=groupname,
        opt_type=int_type(0, float('+inf')),
        required=False
    )

    cmdline.add_option(
        "start-symbol",
        None,
        None,
        "Symbol to call after initializing the stack. If not specified, "
        "no call is performed",
        group=groupname,
        opt_type=str,
        required=False
    )

    cmdline.add_flag(
        "end-branch-to-itself",
        None,
        "A branch to itself instruction will be added at the end of the test",
        group=groupname
    )

    print_info("Processing input arguments...")
    cmdline.main(args, _main)
Example #4
0
def main():
    """Program main."""
    args = sys.argv[1:]
    cmdline = microprobe.utils.cmdline.CLI(
        "MicroprobeTest (mpt) to ELF tool",
        mpt_options=True,
        default_config_file="mp_mpt2elf.cfg",
        force_required=['target'],
    )

    group_name = "MPT to ELF arguments"
    cmdline.add_group(
        group_name, "Command arguments related to MPT to ELF tool",
    )

    cmdline.add_option(
        "elf-output-file",
        "O",
        None,
        "ELF output file name",
        group=group_name,
        opt_type=new_file_ext(".s"),
        required=True,
    )

    cmdline.add_option(
        "compiler",
        None,
        None,
        "Path to the compiler",
        group=group_name,
    )

    cmdline.add_option(
        "compiler-flags",
        None,
        "",
        "Compiler flags to use, if compiler is provided",
        group=group_name,
    )

    group_name = "Fixing options"
    cmdline.add_group(
        group_name,
        "Command arguments related to fixing options",
    )
    cmdline.add_flag(
        "fix-indirect-branches", None, "Fix branches without known target",
        group_name,
    )
    cmdline.add_flag(
        "fix-branch-next", None, "Force target of branches to be the next "
                                 "sequential instruction",
        group_name,
    )
    cmdline.add_flag(
        "fix-memory-references", None,
        "Ensure that registers used by instructions accessing "
        "storage are initialized to valid locations", group_name,
    )
    cmdline.add_flag(
        "fix-memory-registers", None,
        "Fix non-storage instructions touching registers used for"
        " storage address computations (implies "
        "--fix-memory-references flag)", group_name,
    )
    cmdline.add_flag(
        "fix-flatten-code", None,
        "All code is flatten using consecutive addresses",
        group_name,
    )
    cmdline.add_flag(
        "safe-bin", None, "Ignore unrecognized binary codifications (do not"
                          "fail). Useful when MPTs are generated by dumping "
                          "directly code "
                          "pages, which contain padding zeros and other "
                          "non-code stuff)",
        group_name,
    )
    cmdline.add_flag(
        "raw-bin", None, "Process all instruction entries together. They "
                         "all shoud be binary entries. Implies --safe-bin "
                         "flag. Useful when MPTs are generated by dumping "
                         "directly code "
                         "pages, which contain padding zeros and other "
                         "non-code stuff)",
        group_name,
    )
    cmdline.add_flag(
        "fix-long-jump", None,
        "Sometimes the generated code is unable compile due a long jump "
        "displacement required to jump to the start insturction.",
        group_name,
    )

    cmdline.add_option(
        "fix-start-address",
        "S",
        None,
        "Sometimes the user requires the main start point to be on specific "
        "address to avoid compilation issues or comply with the execution "
        "environment requirements. This flag forces the main entry point of "
        "execution to be at the specified address. It is up to the user to "
        "define a proper entry point that does not clash with existing code.",
        group=group_name,
        opt_type=int_type(0, 2**64)
    )

    group_name = "Wrapping options"
    cmdline.add_group(
        group_name,
        "Command arguments related to wrapping options",
    )
    cmdline.add_flag(
        "no-wrap-test", None, "By default the code is wrapped like it was "
                              "a function call, use this flag to disable the "
                              "wrapping",
        group_name,
    )
    cmdline.add_flag(
        "wrap-endless", None, "Use this flag to wrap the code in an endless "
                              "loop assuming it is a function. "
                              "If needed (--reset option), additional "
                              "instructions are added to reset the "
                              "the initial state between loop iterations. ",
        group_name,
    )
    cmdline.add_option(
        "wrap-endless-threshold",
        None,
        1,
        "Maximum percentage of instructions allowed in the reset code if "
        "--wrap-endless and --reset is used. I.e. if 10 is set, the tool will "
        "fail if the reset code required is more than 10%% of the actual "
        "code of the test case."
        " Default is 1%%.",
        group=group_name,
        opt_type=float_type(0, 1000),
        required=False,
    )
    cmdline.add_flag(
        "reset", None, "Use this flag to enable the generation of reset "
                       "code if wrap-endless is enabled.",
        group_name,
    )

    print_info("Processing input arguments...")
    cmdline.main(args, _main)
Example #5
0
def main():
    """
    Program main
    """
    args = sys.argv[1:]
    cmdline = CLI(
        "Microprobe C to MPT tool",
        compilation_options=True,
        default_config_file="mp_c2mpt.cfg",
        force_required=['target'],
    )

    groupname = "C to MPT arguments"

    cmdline.add_group(groupname, "Command arguments related to C to MPT tool")

    cmdline.add_option("input-c-file",
                       "i",
                       None,
                       "C file to process",
                       group=groupname,
                       opt_type=existing_file_ext(".c"),
                       required=False)

    cmdline.add_option("output-mpt-file",
                       "O",
                       None,
                       "Output file name",
                       group=groupname,
                       opt_type=new_file_ext(".mpt"),
                       required=True)

    cmdline.add_flag(
        "strict",
        "S", "Be strict when parsing objdump input, if not set, silently skip "
        "unparsed elements",
        group=groupname)

    cmdline.add_option("default-code-address",
                       "X",
                       0x10030000,
                       "Default code address (default: 0x10030000)",
                       group=groupname,
                       opt_type=int_type(0, float('+inf')),
                       required=False)

    cmdline.add_option("default-data-address",
                       "D",
                       0x10040000,
                       "Default data address (default: 0x10040000)",
                       group=groupname,
                       opt_type=int_type(0, float('+inf')),
                       required=False)

    cmdline.add_option("stack-size",
                       None,
                       4096,
                       "Stack size in bytes (Default: 4096)",
                       group=groupname,
                       opt_type=int_type(0, float('+inf')),
                       required=False)

    cmdline.add_option(
        "host-displacement",
        None,
        None,
        "Displacement between static objdump code and loaded image on the "
        "host. Default computed automatically",
        group=groupname,
        opt_type=int_type(0, float('+inf')),
        required=False)

    cmdline.add_flag(
        "fix-displacement",
        None,
        "If data contains addresses (such as pointers) to code or data "
        "regions, the tool will try to fix them adding the necessary "
        "displacement",
        group=groupname,
    )

    cmdline.add_option("stack-name",
                       None,
                       "microprobe_stack",
                       "Stack name (Default: microprobe_stack)",
                       group=groupname,
                       opt_type=str,
                       required=False)

    cmdline.add_option("stack-address",
                       None,
                       None,
                       "Stack address (Default: allocated in the data area)",
                       group=groupname,
                       opt_type=int_type(0, float('+inf')),
                       required=False)

    cmdline.add_flag(
        "no-data-initialization",
        None, "Do not run the compiled code locally to get the contents of"
        " registered variables before executing the *c2mpt_function*. Only "
        "statically specified variable contents will be dumped in the MPT"
        " generated",
        group=groupname)

    cmdline.add_flag(
        "save-temps",
        None,
        "Store the generated intermediate files permanently; place them in "
        "the input source file directory and name them based on the source "
        "file",
        group=groupname)

    cmdline.add_flag(
        "dump-c2mpt-template",
        None,
        "Dump a template C file, which can be used afterwards as an input "
        "file",
        group=groupname)

    cmdline.add_flag(
        "end-branch-to-itself",
        None,
        "A branch to itself instruction will be added at the end of the test",
        group=groupname)

    print_info("Processing input arguments...")
    cmdline.main(args, _main)
Example #6
0
def main():
    """
    Program main
    """
    args = sys.argv[1:]
    cmdline = CLI("Microprobe COBOL lst to MPT tool",
                  default_config_file="mp_coblst2mpt.cfg",
                  force_required=['target'])

    groupname = "COBOL lst to MPT arguments"

    cmdline.add_group(groupname,
                      "Command arguments related to COBOL lst to MPT tool")

    cmdline.add_option(
        "input-coblst-file",
        "i",
        None,
        "COBOL lst file to process, if not provided, the input is read from"
        " standard input",
        group=groupname,
        opt_type=existing_file,
        required=False)

    cmdline.add_option("output-mpt-file",
                       "O",
                       None,
                       "Output file name",
                       group=groupname,
                       opt_type=new_file_ext(".mpt"),
                       required=True)

    cmdline.add_flag(
        "strict",
        "S", "Be strict when parsing objdump input, if not set, silently skip "
        "unparsed elements",
        group=groupname)

    cmdline.add_option("from-address",
                       "f",
                       0x0,
                       "If set, start interpreting from this address",
                       group=groupname,
                       opt_type=int_type(0, float('+inf')),
                       required=False)

    cmdline.add_option("to-address",
                       "t",
                       float('+inf'),
                       "If set, end interpreting at this address",
                       group=groupname,
                       opt_type=int_type(0, float('+inf')),
                       required=False)

    cmdline.add_option("default-code-address",
                       "X",
                       None,
                       "Default code address",
                       group=groupname,
                       opt_type=int_type(0, float('+inf')),
                       required=False)

    cmdline.add_option("default-data-address",
                       "D",
                       None,
                       "Default data address",
                       group=groupname,
                       opt_type=int_type(0, float('+inf')),
                       required=False)

    print_info("Processing input arguments...")
    cmdline.main(args, _main)
Example #7
0
def main():
    """
    Program main
    """
    args = sys.argv[1:]
    cmdline = microprobe.utils.cmdline.CLI(
        "MicroprobeTest (mpt) to test tool",
        mpt_options=True,
        default_config_file="mp_mpt2test.cfg",
        force_required=['target'])

    groupname = "MPT to test arguments"
    cmdline.add_group(groupname,
                      "Command arguments related to MPT to test tool")

    cmdline.add_option("c-output-file",
                       "O",
                       None,
                       "C output file name",
                       group=groupname,
                       opt_type=new_file_ext(".c"),
                       required=True)

    groupname = "Fixing options"
    cmdline.add_group(groupname, "Command arguments related to fixing options")
    cmdline.add_flag("fix-indirect-branches", None,
                     "Fix branches without known target", groupname)
    cmdline.add_flag(
        "fix-branch-next", None, "Force target of branches to be the next "
        "sequential instruction", groupname)
    cmdline.add_flag(
        "fix-memory-references", None,
        "Ensure that registers used by instructions accessing "
        "storage are initialized to valid locations", groupname)
    cmdline.add_flag(
        "fix-memory-registers", None,
        "Fix non-storage instructions touching registers used for"
        " storage address computations (implies "
        "--fix-memory-referenes flag)", groupname)
    cmdline.add_flag(
        "safe-bin",
        None,
        "Ignore unrecognized binary codifications (do not"
        "fail). Useful when MPTs are generated by dumping "
        "directly code "
        "pages, which contain padding zeros and other "
        "non-code stuff)",
        groupname,
    )
    cmdline.add_flag(
        "raw-bin",
        None,
        "Process all instruction entries together. They "
        "all shoud be binary entries. Implies --safe-bin "
        "flag. Useful when MPTs are generated by dumping "
        "directly code "
        "pages, which contain padding zeros and other "
        "non-code stuff)",
        groupname,
    )
    cmdline.add_flag("endless", None,
                     "Wrap the code generated within an endless loop",
                     groupname)

    print_info("Processing input arguments...")
    cmdline.main(args, _main)
Example #8
0
def main():
    """Program main."""
    args = sys.argv[1:]
    cmdline = microprobe.utils.cmdline.CLI(
        "MicroprobeTest (mpt) to BIN tool",
        mpt_options=True,
        avp_options=False,
        default_config_file="mp_mpt2bin.cfg",
        force_required=['target'],
    )

    group_name = "MPT to BIN arguments"
    cmdline.add_group(
        group_name, "Command arguments related to MPT to BIN tool",
    )

    cmdline.add_option(
        "bin-output-file",
        "O",
        None,
        "BIN output file name",
        group=group_name,
        opt_type=new_file_ext(".bin"),
        required=True,
    )
    cmdline.add_flag(
        "big-endian", None, "Test case in big endian (default is little "
                            "endian)",
        group_name,
    )

    group_name = "Fixing options"
    cmdline.add_group(
        group_name,
        "Command arguments related to fixing options",
    )
    cmdline.add_flag(
        "fix-indirect-branches", None, "Fix branches without known target",
        group_name,
    )
    cmdline.add_flag(
        "fix-branch-next", None, "Force target of branches to be the next "
                                 "sequential instruction",
        group_name,
    )
    cmdline.add_flag(
        "fix-memory-references", None,
        "Ensure that registers used by instructions accessing "
        "storage are initialized to valid locations", group_name,
    )
    cmdline.add_flag(
        "fix-memory-registers", None,
        "Fix non-storage instructions touching registers used for"
        " storage address computations (implies "
        "--fix-memory-references flag)", group_name,
    )
    cmdline.add_flag(
        "fix-flatten-code", None,
        "All code is flatten using consecutive addresses",
        group_name,
    )
    cmdline.add_flag(
        "safe-bin", None, "Ignore unrecognized binary codifications (do not"
                          "fail). Useful when MPTs are generated by dumping "
                          "directly code "
                          "pages, which contain padding zeros and other "
                          "non-code stuff)",
        group_name,
    )

    group_name = "Wrapping options"
    cmdline.add_group(
        group_name,
        "Command arguments related to wrapping options",
    )
    cmdline.add_flag(
        "no-wrap-test", None, "By default the code is wrapped like it was "
                              "a function call, use this flag to disable the "
                              "wrapping",
        group_name,
    )
    cmdline.add_flag(
        "wrap-endless", None, "Use this flag to wrap the code in an endless "
                              "loop assuming it is a function. "
                              "If needed, additional instructions are "
                              "added to reset the "
                              "the initial state between loop iterations. ",
        group_name,
    )
    cmdline.add_option(
        "wrap-endless-threshold",
        None,
        1,
        "Maximum percentage of instructions allowed in the reset code if "
        "--wrap-endless loop is used. I.e. if 10 is set, the tool will "
        "fail if the reset code required is more than 10%% of the actual "
        "code of the test case."
        " Default is 1%%.",
        group=group_name,
        opt_type=float_type(0, 1000),
        required=False,
    )
    cmdline.add_flag(
        "endless", None, "Use this flag to wrap the code in an endless "
                         "loop.",
        group_name,
    )

    print_info("Processing input arguments...")
    cmdline.main(args, _main)