Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / api / pfe / src / Pfe_Shell.py
CommitLineData
920dae64
AT
1# ========== Copyright Header Begin ==========================================
2#
3# OpenSPARC T2 Processor File: Pfe_Shell.py
4# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6#
7# The above named program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public
9# License version 2 as published by the Free Software Foundation.
10#
11# The above named program is distributed in the hope that it will be
12# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public
17# License along with this work; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19#
20# ========== Copyright Header End ============================================
21
22import os
23import sys
24import atexit
25import readline
26import Pfe_Version
27
28from optparse import OptionParser, Option, OptionValueError
29from string import join
30from copy import copy
31from Pfe_Slicer import Slicer
32
33
34def history(name):
35 histfile = os.path.join(os.environ["HOME"],name)
36 try:
37 readline.read_history_file(histfile)
38 atexit.register(readline.write_history_file, histfile)
39 except IOError:
40 pass
41
42
43def check_slice(option,opt,value):
44 for s in value.split(','):
45 try:
46 eval('slice('+join(s.split(':'),',')+')')
47 except NameError, ValueError:
48 raise OptionValueError("option %s: invalid slice: %r" % (opt, value))
49 return value
50
51
52class SliceOption (Option):
53 TYPES = Option.TYPES + ("slice",)
54 TYPE_CHECKER = copy(Option.TYPE_CHECKER)
55 TYPE_CHECKER["slice"] = check_slice
56
57
58opts = None
59args = [] # The script files to execute
60argv = [] # The arguments after --
61
62def options(prog):
63 argv_parser = OptionParser(usage="usage: "+prog+" [options]",
64 version=Pfe_Version.version(),
65 option_class=SliceOption)
66 argv_parser.disable_interspersed_args()
67
68 argv_parser.add_option(
69 "-i","--interactive",
70 action="store_true",dest="interactive",default=False,
71 help="switch to interactive (inspect) mode")
72
73 #argv_parser.add_option(
74 #"-f","--file",
75 #action="append",type="string",dest="file",default=[],
76 #metavar="FILE",help="load one or more elf or memory image files")
77
78 argv_parser.add_option(
79 "-l","--lstmode",
80 action="store_true",dest="lstmode",default=False,
81 help="switch to lstmode, default is runmode")
82
83 #argv_parser.add_option(
84 #"-n","--steps",
85 #action="store",type="int",dest="steps",
86 #metavar="STEPS",help="step the simulator STEPS instructions per strand")
87
88 #argv_parser.add_option(
89 #"-a","--available",
90 #action="store",type="slice",dest="available",default="0",
91 #metavar="SLICE",help="CMP: Make the SLICE of strands available for stepping (default=0)")
92
93 #argv_parser.add_option(
94 #"-e","--enable",
95 #action="store",type="slice",dest="enable",default="0",
96 #metavar="SLICE",help="CMP: Set the SLICE of strands to enabled for stepping (default=0)")
97
98 #argv_parser.add_option(
99 #"-r","--running",
100 #action="store",type="slice",dest="running",default="0",
101 #metavar="SLICE",help="CMP: Put the SLICE of strands in running mode for stepping (default=0)")
102
103 #argv_parser.add_option(
104 #"-s","--stepping",
105 #action="store",type="slice",dest="stepping",default="0",
106 #metavar="SLICE",help="Enable the SLICE of strands for stepping (default=0)")
107
108 global opts
109 global args
110 global argv
111
112 (opts,args_argv) = argv_parser.parse_args()
113
114 # Split the file arguments around the '--' if it is present.
115 # There is one problem "-- no pyfile" fails, while
116 # "pyfile -- no pyfile" succeeds. Awel, that;'s not a big
117 # issue as anything after '--' is means for the pyfile anyways.
118
119 while args_argv:
120 arg = args_argv[0]
121 if arg == '--':
122 argv = args_argv[1:]
123 break
124 else:
125 args.append(arg)
126 del args_argv[0]
127
128
129def setup(sim):
130 global opts
131 global args
132
133 #for strand in eval('Slicer(sim.s)['+opts.available+']'):
134 #strand.available()
135 #for strand in eval('Slicer(sim.s)['+opts.enable+']'):
136 #strand.enable()
137 #for strand in eval('Slicer(sim.s)['+opts.running+']'):
138 #strand.running()
139 #for strand in eval('Slicer(sim.s)['+opts.stepping+']'):
140 #strand.stepping()
141
142 #for file in opts.file:
143 #sim.mem.load(file)
144
145 for strand in sim.s:
146 strand.lstmode(opts.lstmode and 1 or 0)
147
148 if opts.interactive or len(args) == 0:
149 os.environ['PYTHONINSPECT'] = 'x'
150
151
152
153
154
155
156
157
158