main.py revision 2973:56dea3a9d279
12381SN/A# Copyright (c) 2005 The Regents of The University of Michigan 210694SMarco.Balboni@ARM.com# All rights reserved. 38949Sandreas.hansson@arm.com# 48949Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 58949Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 68949Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 78949Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 88949Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 98949Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 108949Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 118949Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 128949Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from 138949Sandreas.hansson@arm.com# this software without specific prior written permission. 142592SN/A# 157636Ssteve.reinhardt@amd.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162381SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172381SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182381SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192381SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202381SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212381SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222381SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232381SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242381SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252381SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262381SN/A# 272381SN/A# Authors: Nathan Binkert 282381SN/A 292381SN/Aimport code, optparse, os, socket, sys 302381SN/Afrom datetime import datetime 312381SN/Afrom attrdict import attrdict 322381SN/A 332381SN/Atry: 342381SN/A import info 352381SN/Aexcept ImportError: 362381SN/A info = None 372381SN/A 382381SN/A__all__ = [ 'options', 'arguments', 'main' ] 392381SN/A 402665Ssaidi@eecs.umich.eduusage="%prog [m5 options] script.py [script options]" 412665Ssaidi@eecs.umich.eduversion="%prog 2.0" 422665Ssaidi@eecs.umich.edubrief_copyright=''' 432665Ssaidi@eecs.umich.eduCopyright (c) 2001-2006 449031Sandreas.hansson@arm.comThe Regents of The University of Michigan 452381SN/AAll Rights Reserved 462381SN/A''' 472381SN/A 482381SN/A# there's only one option parsing done, so make it global and add some 492662Sstever@eecs.umich.edu# helper functions to make it work well. 502381SN/Aparser = optparse.OptionParser(usage=usage, version=version, 512381SN/A description=brief_copyright, 522381SN/A formatter=optparse.TitledHelpFormatter()) 532381SN/Aparser.disable_interspersed_args() 542381SN/A 558229Snate@binkert.org# current option group 563348Sbinkertn@umich.edugroup = None 573348Sbinkertn@umich.edu 583348Sbinkertn@umich.edudef set_group(*args, **kwargs): 595735Snate@binkert.org '''set the current option group''' 604024Sbinkertn@umich.edu global group 615735Snate@binkert.org if not args and not kwargs: 623940Ssaidi@eecs.umich.edu group = None 635314Sstever@gmail.com else: 646216Snate@binkert.org group = parser.add_option_group(*args, **kwargs) 652392SN/A 664167Sbinkertn@umich.educlass splitter(object): 672394SN/A def __init__(self, split): 688737Skoansin.tan@gmail.com self.split = split 693349Sbinkertn@umich.edu def __call__(self, option, opt_str, value, parser): 702394SN/A getattr(parser.values, option.dest).extend(value.split(self.split)) 712812Srdreslin@umich.edu 722812Srdreslin@umich.edudef add_option(*args, **kwargs): 734022Sstever@eecs.umich.edu '''add an option to the current option group, or global none set''' 744022Sstever@eecs.umich.edu 755735Snate@binkert.org # if action=split, but allows the option arguments 765735Snate@binkert.org # themselves to be lists separated by the split variable''' 774022Sstever@eecs.umich.edu 785735Snate@binkert.org if kwargs.get('action', None) == 'append' and 'split' in kwargs: 795735Snate@binkert.org split = kwargs.pop('split') 805735Snate@binkert.org kwargs['default'] = [] 814022Sstever@eecs.umich.edu kwargs['type'] = 'string' 824022Sstever@eecs.umich.edu kwargs['action'] = 'callback' 834022Sstever@eecs.umich.edu kwargs['callback'] = splitter(split) 844022Sstever@eecs.umich.edu 854473Sstever@eecs.umich.edu if group: 865319Sstever@gmail.com return group.add_option(*args, **kwargs) 874022Sstever@eecs.umich.edu 884022Sstever@eecs.umich.edu return parser.add_option(*args, **kwargs) 894022Sstever@eecs.umich.edu 9010883Sali.jafri@arm.comdef bool_option(name, default, help): 914022Sstever@eecs.umich.edu '''add a boolean option called --name and --no-name. 924022Sstever@eecs.umich.edu Display help depending on which is the default''' 934022Sstever@eecs.umich.edu 944022Sstever@eecs.umich.edu tname = '--%s' % name 954022Sstever@eecs.umich.edu fname = '--no-%s' % name 964022Sstever@eecs.umich.edu dest = name.replace('-', '_') 974022Sstever@eecs.umich.edu if default: 987465Ssteve.reinhardt@amd.com thelp = optparse.SUPPRESS_HELP 994628Sstever@eecs.umich.edu fhelp = help 1007465Ssteve.reinhardt@amd.com else: 1017465Ssteve.reinhardt@amd.com thelp = help 1024022Sstever@eecs.umich.edu fhelp = optparse.SUPPRESS_HELP 1034022Sstever@eecs.umich.edu 1044626Sstever@eecs.umich.edu add_option(tname, action="store_true", default=default, help=thelp) 1054626Sstever@eecs.umich.edu add_option(fname, action="store_false", dest=dest, help=fhelp) 1067669Ssteve.reinhardt@amd.com 1074626Sstever@eecs.umich.edu# Help options 1084040Ssaidi@eecs.umich.eduadd_option('-A', "--authors", action="store_true", default=False, 1094040Ssaidi@eecs.umich.edu help="Show author information") 1105650Sgblack@eecs.umich.eduadd_option('-C', "--copyright", action="store_true", default=False, 1115650Sgblack@eecs.umich.edu help="Show full copyright information") 1124870Sstever@eecs.umich.eduadd_option('-R', "--readme", action="store_true", default=False, 1134870Sstever@eecs.umich.edu help="Show the readme") 1144870Sstever@eecs.umich.eduadd_option('-N', "--release-notes", action="store_true", default=False, 1154870Sstever@eecs.umich.edu help="Show the release notes") 1164870Sstever@eecs.umich.edu 1174870Sstever@eecs.umich.edu# Options for configuring the base simulator 1188436SBrad.Beckmann@amd.comadd_option('-d', "--outdir", metavar="DIR", default=".", 1198436SBrad.Beckmann@amd.com help="Set the output directory to DIR [Default: %default]") 1205314Sstever@gmail.comadd_option('-i', "--interactive", action="store_true", default=False, 1215314Sstever@gmail.com help="Invoke the interactive interpreter after running the script") 1228184Ssomayeh@cs.wisc.eduadd_option("--pdb", action="store_true", default=False, 1238716Snilay@cs.wisc.edu help="Invoke the python debugger before running the script") 1244022Sstever@eecs.umich.eduadd_option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':', 1254022Sstever@eecs.umich.edu help="Prepend PATH to the system path when invoking the script") 1264022Sstever@eecs.umich.eduadd_option('-q', "--quiet", action="count", default=0, 1274022Sstever@eecs.umich.edu help="Reduce verbosity") 1285735Snate@binkert.orgadd_option('-v', "--verbose", action="count", default=0, 1295735Snate@binkert.org help="Increase verbosity") 1305735Snate@binkert.org 1314022Sstever@eecs.umich.edu# Statistics options 1324022Sstever@eecs.umich.eduset_group("Statistics Options") 1334626Sstever@eecs.umich.eduadd_option("--stats-file", metavar="FILE", default="m5stats.txt", 1344626Sstever@eecs.umich.edu help="Sets the output file for statistics [Default: %default]") 1357465Ssteve.reinhardt@amd.com 1364022Sstever@eecs.umich.edu# Debugging options 1374626Sstever@eecs.umich.eduset_group("Debugging Options") 1384626Sstever@eecs.umich.eduadd_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',', 1394626Sstever@eecs.umich.edu help="Cycle to create a breakpoint") 1404626Sstever@eecs.umich.edu 1414022Sstever@eecs.umich.edu# Tracing options 1424022Sstever@eecs.umich.eduset_group("Trace Options") 1436076Sgblack@eecs.umich.eduadd_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',', 1444626Sstever@eecs.umich.edu help="Sets the flags for tracing") 1454870Sstever@eecs.umich.eduadd_option("--trace-start", metavar="TIME", default='0s', 1465314Sstever@gmail.com help="Start tracing at TIME (must have units)") 1478184Ssomayeh@cs.wisc.eduadd_option("--trace-file", metavar="FILE", default="cout", 1484022Sstever@eecs.umich.edu help="Sets the output file for tracing [Default: %default]") 1494022Sstever@eecs.umich.eduadd_option("--trace-circlebuf", metavar="SIZE", type="int", default=0, 1504022Sstever@eecs.umich.edu help="If SIZE is non-zero, turn on the circular buffer with SIZE lines") 1515735Snate@binkert.orgadd_option("--no-trace-circlebuf", action="store_const", const=0, 1525735Snate@binkert.org dest='trace_circlebuf', help=optparse.SUPPRESS_HELP) 1535735Snate@binkert.orgbool_option("trace-dumponexit", default=False, 1545735Snate@binkert.org help="Dump trace buffer on exit") 1555735Snate@binkert.orgadd_option("--trace-ignore", metavar="EXPR", action='append', split=':', 1565735Snate@binkert.org help="Ignore EXPR sim objects") 1575735Snate@binkert.org 1584022Sstever@eecs.umich.edu# Execution Trace options 1595735Snate@binkert.orgset_group("Execution Trace Options") 1605735Snate@binkert.orgbool_option("speculative", default=True, 1614022Sstever@eecs.umich.edu help="Don't capture speculative instructions") 1625735Snate@binkert.orgbool_option("print-cycle", default=True, 1634022Sstever@eecs.umich.edu help="Don't print cycle numbers in trace output") 1644022Sstever@eecs.umich.edubool_option("print-symbol", default=True, 1654022Sstever@eecs.umich.edu help="Disable PC symbols in trace output") 1665735Snate@binkert.orgbool_option("print-opclass", default=True, 1674022Sstever@eecs.umich.edu help="Don't print op class type in trace output") 1684022Sstever@eecs.umich.edubool_option("print-thread", default=True, 1694022Sstever@eecs.umich.edu help="Don't print thread number in trace output") 1704022Sstever@eecs.umich.edubool_option("print-effaddr", default=True, 1714022Sstever@eecs.umich.edu help="Don't print effective address in trace output") 1724022Sstever@eecs.umich.edubool_option("print-data", default=True, 1735735Snate@binkert.org help="Don't print result data in trace output") 1745735Snate@binkert.orgbool_option("print-iregs", default=False, 1755735Snate@binkert.org help="Print fetch sequence numbers in trace output") 1764022Sstever@eecs.umich.edubool_option("print-fetch-seq", default=False, 1774022Sstever@eecs.umich.edu help="Print fetch sequence numbers in trace output") 1784022Sstever@eecs.umich.edubool_option("print-cpseq", default=False, 1794022Sstever@eecs.umich.edu help="Print correct path sequence numbers in trace output") 1804022Sstever@eecs.umich.edu#bool_option("print-reg-delta", default=False, 18110583SCurtis.Dunham@arm.com# help="Print which registers changed to what in trace output") 18210583SCurtis.Dunham@arm.com 18310583SCurtis.Dunham@arm.comoptions = attrdict() 18410583SCurtis.Dunham@arm.comarguments = [] 18510583SCurtis.Dunham@arm.com 18610583SCurtis.Dunham@arm.comdef usage(exitcode=None): 18710583SCurtis.Dunham@arm.com parser.print_help() 18810583SCurtis.Dunham@arm.com if exitcode is not None: 18910583SCurtis.Dunham@arm.com sys.exit(exitcode) 19010583SCurtis.Dunham@arm.com 19110570Sandreas.hansson@arm.comdef parse_args(): 19210570Sandreas.hansson@arm.com _opts,args = parser.parse_args() 19310570Sandreas.hansson@arm.com opts = attrdict(_opts.__dict__) 19410570Sandreas.hansson@arm.com 19510570Sandreas.hansson@arm.com # setting verbose and quiet at the same time doesn't make sense 19610570Sandreas.hansson@arm.com if opts.verbose > 0 and opts.quiet > 0: 1974022Sstever@eecs.umich.edu usage(2) 1986102Sgblack@eecs.umich.edu 19910343SCurtis.Dunham@arm.com # store the verbosity in a single variable. 0 is default, 20010343SCurtis.Dunham@arm.com # negative numbers represent quiet and positive values indicate verbose 20110343SCurtis.Dunham@arm.com opts.verbose -= opts.quiet 20210343SCurtis.Dunham@arm.com 2034870Sstever@eecs.umich.edu del opts.quiet 2045314Sstever@gmail.com 2058184Ssomayeh@cs.wisc.edu options.update(opts) 2064022Sstever@eecs.umich.edu arguments.extend(args) 2075735Snate@binkert.org return opts,args 2085735Snate@binkert.org 2095735Snate@binkert.orgdef main(): 2104022Sstever@eecs.umich.edu import cc_main 2114022Sstever@eecs.umich.edu 2124022Sstever@eecs.umich.edu parse_args() 2135735Snate@binkert.org 2145735Snate@binkert.org done = False 2154022Sstever@eecs.umich.edu if options.copyright: 2164022Sstever@eecs.umich.edu done = True 2175735Snate@binkert.org print info.LICENSE 2185735Snate@binkert.org print 2195735Snate@binkert.org 2204022Sstever@eecs.umich.edu if options.authors: 2215735Snate@binkert.org done = True 2225735Snate@binkert.org print 'Author information:' 2234022Sstever@eecs.umich.edu print 2244022Sstever@eecs.umich.edu print info.AUTHORS 2252381SN/A print 2262662Sstever@eecs.umich.edu 2272662Sstever@eecs.umich.edu if options.readme: 2282662Sstever@eecs.umich.edu done = True 2292662Sstever@eecs.umich.edu print 'Readme:' 2302662Sstever@eecs.umich.edu print 2312381SN/A print info.README 2329044SAli.Saidi@ARM.com print 2332381SN/A 2342813Srdreslin@umich.edu if options.release_notes: 2355735Snate@binkert.org done = True 2365735Snate@binkert.org print 'Release Notes:' 2374022Sstever@eecs.umich.edu print 2385735Snate@binkert.org print info.RELEASE_NOTES 2395735Snate@binkert.org print 2405735Snate@binkert.org 2415735Snate@binkert.org if done: 2425735Snate@binkert.org sys.exit(0) 2435735Snate@binkert.org 2445735Snate@binkert.org if options.verbose >= 0: 2455735Snate@binkert.org print "M5 Simulator System" 2465735Snate@binkert.org print brief_copyright 2475735Snate@binkert.org print 2485735Snate@binkert.org print "M5 compiled %s" % cc_main.cvar.compileDate; 2495735Snate@binkert.org print "M5 started %s" % datetime.now().ctime() 2505735Snate@binkert.org print "M5 executing on %s" % socket.gethostname() 2515735Snate@binkert.org print "command line:", 2525735Snate@binkert.org for argv in sys.argv: 2535735Snate@binkert.org print argv, 2545735Snate@binkert.org print 2555735Snate@binkert.org 2565735Snate@binkert.org # check to make sure we can find the listed script 2575735Snate@binkert.org if not arguments or not os.path.isfile(arguments[0]): 2585735Snate@binkert.org if arguments and not os.path.isfile(arguments[0]): 25910566Sandreas.hansson@arm.com print "Script %s not found" % arguments[0] 26010566Sandreas.hansson@arm.com usage(2) 2615735Snate@binkert.org 2628436SBrad.Beckmann@amd.com # tell C++ about output directory 2638436SBrad.Beckmann@amd.com cc_main.setOutputDir(options.outdir) 2648436SBrad.Beckmann@amd.com 26510763Sali.jafri@arm.com # update the system path with elements from the -p option 26610763Sali.jafri@arm.com sys.path[0:0] = options.path 26710763Sali.jafri@arm.com 2685735Snate@binkert.org import objects 2695735Snate@binkert.org 2705735Snate@binkert.org # set stats options 2715735Snate@binkert.org objects.Statistics.text_file = options.stats_file 2724022Sstever@eecs.umich.edu 2734022Sstever@eecs.umich.edu # set debugging options 2745735Snate@binkert.org objects.Debug.break_cycles = options.debug_break 2754870Sstever@eecs.umich.edu 2764870Sstever@eecs.umich.edu # set tracing options 2775735Snate@binkert.org objects.Trace.flags = options.trace_flags 27810569Sandreas.hansson@arm.com objects.Trace.start = options.trace_start 2794870Sstever@eecs.umich.edu objects.Trace.file = options.trace_file 2802566SN/A objects.Trace.bufsize = options.trace_circlebuf 2815735Snate@binkert.org objects.Trace.dump_on_exit = options.trace_dumponexit 2825735Snate@binkert.org objects.Trace.ignore = options.trace_ignore 2835735Snate@binkert.org 2845735Snate@binkert.org # set execution trace options 2855735Snate@binkert.org objects.ExecutionTrace.speculative = options.speculative 2865735Snate@binkert.org objects.ExecutionTrace.print_cycle = options.print_cycle 2872566SN/A objects.ExecutionTrace.pc_symbol = options.print_symbol 2882566SN/A objects.ExecutionTrace.print_opclass = options.print_opclass 2892566SN/A objects.ExecutionTrace.print_thread = options.print_thread 2905735Snate@binkert.org objects.ExecutionTrace.print_effaddr = options.print_effaddr 2915735Snate@binkert.org objects.ExecutionTrace.print_data = options.print_data 2922381SN/A objects.ExecutionTrace.print_iregs = options.print_iregs 2932381SN/A objects.ExecutionTrace.print_fetchseq = options.print_fetch_seq 29410028SGiacomo.Gabrielli@arm.com objects.ExecutionTrace.print_cpseq = options.print_cpseq 29510028SGiacomo.Gabrielli@arm.com #objects.ExecutionTrace.print_reg_delta = options.print_reg_delta 29610028SGiacomo.Gabrielli@arm.com 2975735Snate@binkert.org sys.argv = arguments 2986227Snate@binkert.org sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path 2992381SN/A 3005735Snate@binkert.org scope = { '__file__' : sys.argv[0] } 3015735Snate@binkert.org 3024870Sstever@eecs.umich.edu # we want readline if we're doing anything interactive 3034870Sstever@eecs.umich.edu if options.interactive or options.pdb: 3044870Sstever@eecs.umich.edu exec("import readline", scope) 3054870Sstever@eecs.umich.edu 3064870Sstever@eecs.umich.edu # if pdb was requested, execfile the thing under pdb, otherwise, 3074870Sstever@eecs.umich.edu # just do the execfile normally 3088668Sgeoffrey.blake@arm.com if options.pdb: 30910723Sandreas.hansson@arm.com from pdb import Pdb 3108668Sgeoffrey.blake@arm.com debugger = Pdb() 31110723Sandreas.hansson@arm.com debugger.run('execfile("%s")' % sys.argv[0], scope) 3128668Sgeoffrey.blake@arm.com else: 3132641Sstever@eecs.umich.edu execfile(sys.argv[0], scope) 3142811Srdreslin@umich.edu 3159547Sandreas.hansson@arm.com # once the script is done 31610694SMarco.Balboni@ARM.com if options.interactive: 31710405Sandreas.hansson@arm.com interact = code.InteractiveConsole(scope) 31810405Sandreas.hansson@arm.com interact.interact("M5 Interactive Console") 31910405Sandreas.hansson@arm.com 32010405Sandreas.hansson@arm.comif __name__ == '__main__': 3219547Sandreas.hansson@arm.com from pprint import pprint 32210694SMarco.Balboni@ARM.com 3233218Sgblack@eecs.umich.edu parse_args() 3249547Sandreas.hansson@arm.com 32510694SMarco.Balboni@ARM.com print 'opts:' 32610694SMarco.Balboni@ARM.com pprint(options, indent=4) 32710694SMarco.Balboni@ARM.com print 32810694SMarco.Balboni@ARM.com 32910405Sandreas.hansson@arm.com print 'args:' 33010405Sandreas.hansson@arm.com pprint(arguments, indent=4) 3319547Sandreas.hansson@arm.com