Example #1
0
    def __init__(self,args,dm):
        self.dm=dm                # Global Debug Manager instance
        self.args=args            # Command line arguments
        self.clstats=args.stats   # Command-line statistics flag

        # Enable any command line debug flags
        for flag in self.args.debug:
            self.dm.enable(flag)

        self.aout=assembler.AsmOut(\
            deck=args.object,\
            image=args.image,\
            ldipl=args.gldipl,\
            listing=args.listing,\
            mc=args.store,\
            rc=args.rc,\
            vmc=args.vmc)

        msl,cpu=self.target()
        cptrans,cpfile=self.code_page("94C")
        defn=self.defines()

        self.assembler=assembler.Assembler(cpu,msl,self.aout,\
            msldft=satkutil.satkdir("asma/msl"),\
            addr=args.addr,\
            bltin=args.bltin,\
            case=args.case,\
            debug=dm,\
            defines=defn,\
            dump=args.dump,\
            error=args.error,\
            nest=self.args.nest,\
            ptrace=args.pas,\
            otrace=args.oper,\
            cpfile=cpfile,\
            cptrans=cptrans)

        self.source=args.source[0]     # Source input file
        
        # Gather together time related data saved outside this object.
        self.process_start=process_start
        self.wall_start=wall_start
        self.import_start=import_start
        self.import_start_w=import_start_w
        self.objects_start=objects_start
        self.objects_start_w=objects_start_w
        
        # Timer information gathered during run() method
        self.assemble_end=None
        self.assemble_end_w=None
        self.out_end=None
        self.out_end_w=None
        
        # Save some of my own time information
        self.objects_end=time.process_time()
        self.objects_end_w=time.time()
Example #2
0
    def __init__(self, args):
        self.mslfile = args.mslfile[0]  # Input MSL text file

        # Normal processing options
        self.expand = args.expand  # Expand a cpu statment with dependencies
        self.fail = args.fail  # If True fail immediately on an error
        self.xref = args.xref  # Print the cross-reference listing

        # Diagnostic options
        self.dump = args.dump  # Dump the final output DB

        # The Machine Language Specification Processor
        self.dbp = msldb.MSL(default=satkutil.satkdir("asma/msl", debug=False))
Example #3
0
File: msl.py Project: mstramb/SATK
    def __init__(self,args):
        self.mslfile=args.mslfile[0]   # Input MSL text file

        # Normal processing options
        self.expand=args.expand        # Expand a cpu statment with dependencies
        self.fail=args.fail            # If True fail immediately on an error
        self.xref=args.xref            # Print the cross-reference listing

        # Diagnostic options
        self.dump=args.dump            # Dump the final output DB

        # The Machine Language Specification Processor
        self.dbp=msldb.MSL(default=satkutil.satkdir("asma/msl",debug=False))
Example #4
0
    def tool_spec(self):
        prog = "%s.py" % self.name

        # Return to full usage when epilog not shown whithout help
        # Seems to be an error with Python 3.4.1
        #epilog="%s\n%s\n%s" % (asma.variables,config.CINFO.cinfo_options(),copyright)
        epilog = copyright
        cfg=config.Configuration(prog,epilog,\
            "from assembler source create a bare-metal usable file")

        cfg.arg(config.Choices("target",short="t",full="target",metavar="ISA",\
            choices=asma.target_choices,default="24",\
            help="target instruction set architecture.  ISA may be: s360, s370, s380, "\
                 "s370xa, e370, e390, s390, s390x, 24, 31, or 64.  Defaults to 24.",\
            cl=True,cfg=True))

        # Override MSL maximum address size
        # May be specified in a local configuration
        cfg.arg(config.IntChoices("addr",short="a",full="addr",metavar="SIZE",\
            choices=["16","24","31","64"],\
            help="overrides target CPU maximum address size (in bits) in the "\
                 "listing. SIZE may be 16, 24, 31 or 64.",\
            cl=True,cfg=True))

        # Specify error handling level
        # May be specified in a local configuration
        cfg.arg(config.IntChoices("error",short="e",full="error",metavar="LEVEL",\
            choices=["0","1","2","3"],default="2",\
            help="specifies error handling level.  Defaults to 2.",\
            cl=True,cfg=True))

        # Specify the initial XMODE PSW format
        psw_formats = [
            "S", "360", "67", "BC", "EC", "380", "XA", "E370", "E390", "Z",
            "none"
        ]
        cfg.arg(config.Choices("psw",full="psw",metavar="FORMAT",\
            choices=psw_formats,\
            cl=True,cfg=True))

        # Specify the initial XMODE CCW format
        cfg.arg(config.Choices("ccw",full="ccw",metavar="FORMAT",\
            choices=["0","1","none"],\
            help="set the initial XMODE PSW or CCW format. Overrides the value "
                 "supplited by the target CPU definition.",\
            cl=True,cfg=True))

        # Define a global SETC symbol via the comnand line
        cfg.arg(config.ListArg("symbol",short="D",metavar="SYMBOL[=VALUE]",\
            help="define a global read-only SETC symbolic variable (without the "
                 "leading ampersand) to a value.",\
            cl=True,cfg=True))

        # Dump the completed CSECT's, region's and image
        cfg.arg(config.Enable("dump",short="d",full="dump",\
            help="listing provides the image content in storage dump format.",\
            cl=True,cfg=True))

        # Set macro call printing option
        cfg.arg(config.Enable("mcall",short="m",full="mcall",\
            help="Include inner macro statements during PRINT ON listing option. "
                 "By default inner macro statements are suppressed.",\
            cl=True,cfg=True))

        # Generic list directed IPL option
        cfg.arg(config.Option_SV("gldipl",short="g",full="gldipl",\
            metavar="FILEPATH",\
            help="identifies the location of the list directed IPL file. All related "
                 "files are written to the same diretory. If omitted, no files are "
                 "created.",
            cl=True,cfg=True))

        # Path and filename of the written binary image file
        cfg.arg(config.Option_SV("image",short="i",full="image",metavar="FILEPATH",\
            help="binary image file containing content.  If omitted, no file is "
                 "created.",\
            cl=True,cfg=True))

        # Assembling listing
        cfg.arg(config.Option_SV("listing",short='l',full="listing",\
            metavar="FILEPATH",\
            help="assembly listing file.  If omitted, no listing file is created.",\
            cl=True,cfg=True))

        # Object Deck file name
        cfg.arg(config.Option_SV("object",short="o",full="object",\
            metavar="FILEPATH",\
            help="loadable object deck file with assembled content.  If omitted, an "
                 "object deck is not created.",\
            cl=True,cfg=True))

        # Hercules RC script file
        cfg.arg(config.Option_SV("rc",short="r",full="rc",metavar="FILEPATH",\
            help="Hercules RC script file with assembled content.  If omitted, "
                 "a script file is not created.",\
            cl=True,cfg=True))

        # STORE command file
        cfg.arg(config.Option_SV("store",short="s",full="store",\
            metavar="FILEPATH",\
            help="STORE command file with assembled content.  If omitted, a "
                 "command file is not created.",\
            cl=True,cfg=True))

        # virtual machine STORE ommand file
        cfg.arg(config.Option_SV("vmc",short="v",full="vmc",metavar="FILEPATH",\
            help="virtual machine STORE command file with assembled content. If "
                 "omitted, a command file is not created.",\
            cl=True,cfg=True))

        # Set case sensitivity
        cfg.arg(config.Enable("case",full="case",\
            help="Enable case sensitivity for labels, symbolic variables, and "
            "sequence symbols.  Defaults to case insensitive.",\
            cl=True,cfg=True))

        # Enable statistics reporting
        cfg.arg(config.Enable("stats",full="stats",\
            help="enables statististics reporting.",\
            cl=True,cfg=True))

        # Specify the code page translation
        cfg.arg(config.Option_SV("cp",full="cp",metavar="TRANS[=FILE]",\
            help="specify the code page translation and, if provided, the code page "
                 "file containing it. Defaults to '94C' in the default code page "
                 "file.",\
            cl=True,cfg=True))

        # Machine Target
        cfg.arg(config.Option_SV("cpu",full="cpu",metavar="MSLFILE=CPU",\
            help="identifies the CPU and its MSL file targeted by the assembly. "
                 "MSLFILE must be found in the default MSL directory or a directory "
                 "specified by the MSLPATH environment variable.",\
            cl=True,cfg=True))

        # Maximum depth of nested input sources.
        # May be specified in a local configuration
        nest_default = "20"
        cfg.arg(config.Decimal("nest",full="nest",default=nest_default,\
            metavar="DEPTH",
            help="maximum depth of nested input sources (default %s)." % nest_default,\
            cl=True,cfg=True))

        # Build list of instructions or assembler directives to trace
        cfg.arg(config.ListArg("oper",full="oper",metavar="OPER",\
            help="indicate the operation by name to trace (may be used multiple "
                 "times).",\
            cl=True,cfg=True))

        # Add debug options from Debug Manager
        dm = assembler.Assembler.DM()
        choices, help_str = dm.build_arg()
        cfg.arg(config.ListArg("debug",full="debug",metavar="OPTION",\
            choices=choices,help=help_str,cl=True,cfg=True))

        # Each tool that uses the configuration system should use these options:
        self.option_cfg(cfg)  # Standard cfg option definition
        self.option_cinfo(cfg)  # Standard configuration information option
        self.option_source(cfg,"source","input","asmpath",required=True,\
            shelp="identifies the input assembler source file. Option is of type "\
                  "FILENAME. Defaults to the value of the configuration option "\
                  "'input'.",\
            ihelp="input source file name"\
            )

        # ENVIRONMENT VARIABLE USAGE
        self.option_satkcfg(cfg)  # Standard satkcfg option
        self.option_cwd(cfg)  # cwduse option value in SITE
        cfg.arg(config.Path("asmpath", cfg=True))
        cfg.arg(config.Path("maclib", cfg=True))
        cfg.arg(config.Path("mslpath", default=satkutil.satkdir("asma/msl")))
        cfg.arg(config.Path("cdpgpath", cfg=True))

        return cfg
Example #5
0
    def tool_spec(self):
        prog="%s.py" % self.name
        
        # Return to full usage when epilog not shown whithout help
        # Seems to be an error with Python 3.4.1
        #epilog="%s\n%s\n%s" % (asma.variables,config.CINFO.cinfo_options(),copyright)
        epilog=copyright
        cfg=config.Configuration(prog,epilog,\
            "from assembler source create a bare-metal usable file")

        cfg.arg(config.Choices("target",short="t",full="target",metavar="ISA",\
            choices=asma.target_choices,default="24",\
            help="target instruction set architecture.  ISA may be: s360, s370, s380, "\
                 "s370xa, e370, e390, s390, s390x, 24, 31, or 64.  Defaults to 24.",\
            cl=True,cfg=True))

        # Override MSL maximum address size
        # May be specified in a local configuration
        cfg.arg(config.IntChoices("addr",short="a",full="addr",metavar="SIZE",\
            choices=["16","24","31","64"],\
            help="overrides target CPU maximum address size (in bits) in the "\
                 "listing. SIZE may be 16, 24, 31 or 64.",\
            cl=True,cfg=True))

        # Specify error handling level
        # May be specified in a local configuration
        cfg.arg(config.IntChoices("error",short="e",full="error",metavar="LEVEL",\
            choices=["0","1","2","3"],default="2",\
            help="specifies error handling level.  Defaults to 2.",\
            cl=True,cfg=True))

        # Specify the initial XMODE PSW format
        psw_formats=["S","360","67","BC","EC","380","XA","E370","E390","Z","none"]
        cfg.arg(config.Choices("psw",full="psw",metavar="FORMAT",\
            choices=psw_formats,\
            cl=True,cfg=True))

         # Specify the initial XMODE CCW format
        cfg.arg(config.Choices("ccw",full="ccw",metavar="FORMAT",\
            choices=["0","1","none"],\
            help="set the initial XMODE PSW or CCW format. Overrides the value "
                 "supplited by the target CPU definition.",\
            cl=True,cfg=True))

        # Define a global SETC symbol via the comnand line
        cfg.arg(config.ListArg("symbol",short="D",metavar="SYMBOL[=VALUE]",\
            help="define a global read-only SETC symbolic variable (without the "
                 "leading ampersand) to a value.",\
            cl=True,cfg=True))

        # Dump the completed CSECT's, region's and image
        cfg.arg(config.Enable("dump",short="d",full="dump",\
            help="listing provides the image content in storage dump format.",\
            cl=True,cfg=True))

        # Set macro call printing option
        cfg.arg(config.Enable("mcall",short="m",full="mcall",\
            help="Include inner macro statements during PRINT ON listing option. "
                 "By default inner macro statements are suppressed.",\
            cl=True,cfg=True))

        # Generic list directed IPL option
        cfg.arg(config.Option_SV("gldipl",short="g",full="gldipl",\
            metavar="FILEPATH",\
            help="identifies the location of the list directed IPL file. All related "
                 "files are written to the same diretory. If omitted, no files are "
                 "created.",
            cl=True,cfg=True))

        # Path and filename of the written binary image file
        cfg.arg(config.Option_SV("image",short="i",full="image",metavar="FILEPATH",\
            help="binary image file containing content.  If omitted, no file is "
                 "created.",\
            cl=True,cfg=True))

        # Assembling listing
        cfg.arg(config.Option_SV("listing",short='l',full="listing",\
            metavar="FILEPATH",\
            help="assembly listing file.  If omitted, no listing file is created.",\
            cl=True,cfg=True))

        # Object Deck file name
        cfg.arg(config.Option_SV("object",short="o",full="object",\
            metavar="FILEPATH",\
            help="loadable object deck file with assembled content.  If omitted, an "
                 "object deck is not created.",\
            cl=True,cfg=True))

        # Hercules RC script file
        cfg.arg(config.Option_SV("rc",short="r",full="rc",metavar="FILEPATH",\
            help="Hercules RC script file with assembled content.  If omitted, "
                 "a script file is not created.",\
            cl=True,cfg=True))

        # STORE command file
        cfg.arg(config.Option_SV("store",short="s",full="store",\
            metavar="FILEPATH",\
            help="STORE command file with assembled content.  If omitted, a "
                 "command file is not created.",\
            cl=True,cfg=True))

        # virtual machine STORE ommand file
        cfg.arg(config.Option_SV("vmc",short="v",full="vmc",metavar="FILEPATH",\
            help="virtual machine STORE command file with assembled content. If "
                 "omitted, a command file is not created.",\
            cl=True,cfg=True))

        # Set case sensitivity
        cfg.arg(config.Enable("case",full="case",\
            help="Enable case sensitivity for labels, symbolic variables, and "
            "sequence symbols.  Defaults to case insensitive.",\
            cl=True,cfg=True))

        # Enable statistics reporting
        cfg.arg(config.Enable("stats",full="stats",\
            help="enables statististics reporting.",\
            cl=True,cfg=True))

        # Specify the code page translation
        cfg.arg(config.Option_SV("cp",full="cp",metavar="TRANS[=FILE]",\
            help="specify the code page translation and, if provided, the code page "
                 "file containing it. Defaults to '94C' in the default code page "
                 "file.",\
            cl=True,cfg=True))

        # Machine Target
        cfg.arg(config.Option_SV("cpu",full="cpu",metavar="MSLFILE=CPU",\
            help="identifies the CPU and its MSL file targeted by the assembly. "
                 "MSLFILE must be found in the default MSL directory or a directory "
                 "specified by the MSLPATH environment variable.",\
            cl=True,cfg=True))

        # Maximum depth of nested input sources.
        # May be specified in a local configuration
        nest_default="20"
        cfg.arg(config.Decimal("nest",full="nest",default=nest_default,\
            metavar="DEPTH",
            help="maximum depth of nested input sources (default %s)." % nest_default,\
            cl=True,cfg=True))

        # Build list of instructions or assembler directives to trace
        cfg.arg(config.ListArg("oper",full="oper",metavar="OPER",\
            help="indicate the operation by name to trace (may be used multiple "
                 "times).",\
            cl=True,cfg=True))

        # Add debug options from Debug Manager
        dm=assembler.Assembler.DM()
        choices,help_str=dm.build_arg()
        cfg.arg(config.ListArg("debug",full="debug",metavar="OPTION",\
            choices=choices,help=help_str,cl=True,cfg=True))

        # Each tool that uses the configuration system should use these options:
        self.option_cfg(cfg)     # Standard cfg option definition
        self.option_cinfo(cfg)   # Standard configuration information option
        self.option_source(cfg,"source","input","asmpath",required=True,\
            shelp="identifies the input assembler source file. Option is of type "\
                  "FILENAME. Defaults to the value of the configuration option "\
                  "'input'.",\
            ihelp="input source file name"\
            )
        
        # ENVIRONMENT VARIABLE USAGE
        self.option_satkcfg(cfg)      # Standard satkcfg option
        self.option_cwd(cfg)          # cwduse option value in SITE
        cfg.arg(config.Path("asmpath",cfg=True))
        cfg.arg(config.Path("maclib",cfg=True))
        cfg.arg(config.Path("mslpath",default=satkutil.satkdir("asma/msl")))
        cfg.arg(config.Path("cdpgpath",cfg=True))

        return cfg
Example #6
0

# Parse the command line arguments.
# Returns:
#   argparse Namespace object.
def parse_args():
    parser=argparse.ArgumentParser(prog=this_module,
        epilog=copyright,
        description="audits Hercules operation code tables against ASMA MSL "\
            "specifications")

    parser.add_argument("-H","--Hercules",metavar="DIR",\
        help="Hercules root source directory. If omitted the current working "
            "directory is assumed to be the Hercules root directory")

    parser.add_argument("-l","--listing",metavar="FILEPATH",\
        help="optional audit report output listing file path")

    parser.add_argument("-v","--verbose",action="store_true",default=False,\
        help="specifies that the audit report is to be displayed.  Assumed if "
        "--listing is omitted")

    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()
    print(copyright)
    herc_audit.Hercules_Opcodes(args,
                                satkutil.satkdir("asma/msl")).run(debug=True)
Example #7
0
class MSLRPT(object):
    PATHVAR = "MSLPATH"
    DEFAULT = satkutil.satkdir("asma/msl", debug=False)

    def __init__(self, args):
        self.report = args.report  # Report requested.  See run() method
        self.cpus = []

        # Process the --cpu argument(s)
        for c in args.cpu:
            seps = c.count("=")
            if seps != 1:
                print("invalid --cpu argument ignored: %s" % c)
                continue
            file_cpu = c.split("=")
            t = (file_cpu[0], file_cpu[1])
            self.cpus.append(t)

        # Remeber the --listing argument (may be None)
        self.listing = args.listing

        # Remember --extended argument
        self.extend = args.extended

        # Process --seq argument(s)
        if args.seq is None:
            self.seq = [
                "mnemonic",
            ]
        else:
            self.seq = args.seq

        # Remeber line length
        self.line = args.line

    def __find_files(self):
        msl = msldb.MSL(default=MSLRPT.DEFAULT)
        path = msl.opath  # Reach in and get the path manager
        return path.files(MSLRPT.PATHVAR, ext=".msl")

    def cpu_report(self):
        files = self.__find_files()
        mslf = {}
        for filename in sorted(files):
            msl = msldb.MSL(default=MSLRPT.DEFAULT)
            errors = msl.build(filename)
            if errors:
                print("MSL errors encountered in file: %s" % f)
                continue
            db = msl.DB()
            cpus = []
            for entry in db.iter_entries():
                if isinstance(entry, msldb.CPU):
                    cpus.append(entry.ID)
            if len(cpus) > 0:
                mslf[filename] = cpus
        print("Available CPUs:")
        for f, cpus in mslf.items():
            strcpus = ""
            for c in sorted(cpus):
                strcpus = "%s, %s" % (strcpus, c)
            strcpus = strcpus[2:]
            print("    %s: %s" % (f, strcpus))

    def files_report(self):
        files = self.__find_files()
        print("MSL Files in MSLPATH:")
        for f in files:
            print("    %s" % f)

    def inst_report(self):
        if len(self.cpus) == 0:
            print("inst report requires one or more --cpu arguments")
            return
        files = {}
        # Create a dictionary by file of a list the its requested cpu(s)
        for filename, cpu in self.cpus:
            fn = files.setdefault(filename, [])
            if cpu not in fn:
                fn.append(cpu)
            files[filename] = fn
        dbs = {}
        for filename in files.keys():
            msl = msldb.MSL(default=MSLRPT.DEFAULT)
            errors = msl.build(filename)
            if errors:
                print("MSL errors encountered in file: %s" % filename)
                continue
            # No errors to extract the database for the file and create dictionary
            dbs[filename] = msl.DB()

        # Create a list of the expanded CPU definitions requested
        cpux = []  # This is a list of tupples: (filename,msldb.CPUX)
        col = 0
        for filename, cpu in self.cpus:
            db = dbs[filename]
            try:
                cpu = db[cpu]
            except KeyError:
                print("MSL file %s does not define cpu: %s" % (filename, cpu))
            cpu_ex = cpu.expand(db)
            cpux.append(CPU(col, filename, cpu_ex))
            col += 1

        # Build the Instruction Table
        itbl=ITBL(len(cpux),self.seq,\
            extend=self.extend,linesize=self.line)
        for c in cpux:
            itbl.cpu(c)
        itbl.validate()  # Valid the instructions

        # Print the instruction report
        itbl.prepare()  # Prepare to do the report
        if self.listing is None:
            print(itbl.generate())
        else:
            itbl.generate(filename=self.listing)

    def run(self):
        if self.report == "files":
            self.files_report()
        elif self.report == "inst":
            self.inst_report()
        elif self.report == "cpu":
            self.cpu_report()
        elif self.report == "PoO":
            self.cpus = []
            self.cpus.append(("s360-insn.msl", "s360"))
            self.cpus.append(("s370-insn.msl", "s370"))
            self.cpus.append(("s380-insn.msl", "s380"))
            self.cpus.append(("s370XA-insn.msl", "s370XA"))
            self.cpus.append(("e370-insn.msl", "e370"))
            self.cpus.append(("e390-insn.msl", "e390"))
            self.cpus.append(("s390x-insn.msl", "s390"))
            self.cpus.append(("s390x-insn.msl", "s390x"))
            self.cpus.append(("all-insn.msl", "24"))
            self.inst_report()
        else:
            raise ValueError("unexpected --report argument: %s" % self.report)
Example #8
0
import herc_audit     # Access the Hercules operation code audit processing


# Parse the command line arguments.
# Returns:
#   argparse Namespace object.
def parse_args():
    parser=argparse.ArgumentParser(prog=this_module,
        epilog=copyright, 
        description="audits Hercules operation code tables against ASMA MSL "\
            "specifications")

    parser.add_argument("-H","--Hercules",metavar="DIR",\
        help="Hercules root source directory. If omitted the current working "
            "directory is assumed to be the Hercules root directory")

    parser.add_argument("-l","--listing",metavar="FILEPATH",\
        help="optional audit report output listing file path")

    parser.add_argument("-v","--verbose",action="store_true",default=False,\
        help="specifies that the audit report is to be displayed.  Assumed if "
        "--listing is omitted")

    return parser.parse_args()


if __name__ == "__main__":
    args=parse_args()
    print(copyright)
    herc_audit.Hercules_Opcodes(args,satkutil.satkdir("asma/msl")).run(debug=True)