Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # ========== Copyright Header Begin ========================================== |
2 | # | |
3 | # OpenSPARC T2 Processor File: SS_Main.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 | ##*********************************************************************** | |
22 | ## | |
23 | ## Copyright (C) 2006, Sun Microsystems, Inc. | |
24 | ## | |
25 | ## Sun considers its source code as an unpublished, proprietary | |
26 | ## trade secret and it is available only under strict license provisions. | |
27 | ## This copyright notice is placed here only to protect Sun in the event | |
28 | ## the source is deemed a published work. Disassembly, decompilation, | |
29 | ## or other means of reducing the object code to human readable form | |
30 | ## is prohibited by the license agreement under which this code is | |
31 | ## provided to the user or company in possession of this copy. | |
32 | ## | |
33 | ##*********************************************************************** | |
34 | ||
35 | ### @-ARCH-@_Main.py is automatically generated from | |
36 | ### ss/exe/nas/bin/SS_Main.py, do not modify @-ARCH-@_Main.py, | |
37 | ### make necessary changes in ss/exe/nas/bin/Bl_Main.py instead. | |
38 | ||
39 | import os | |
40 | import sys | |
41 | import atexit | |
42 | import readline | |
43 | import Pfe_Version | |
44 | import @-arch-@ | |
45 | ||
46 | from optparse import OptionParser | |
47 | from @-ARCH-@_Model import * | |
48 | ||
49 | import SS_Ram | |
50 | import SS_Memory | |
51 | import SS_Io | |
52 | ||
53 | opts = None | |
54 | args = None | |
55 | ||
56 | def options(prog): | |
57 | argv_parser = OptionParser(usage="usage: "+prog+" [options]",version=Pfe_Version.version()) | |
58 | argv_parser.disable_interspersed_args() | |
59 | ||
60 | argv_parser.add_option( | |
61 | "-c","--record", | |
62 | action="store_true",dest="record",default=False, | |
63 | help="Record pli socket i/o for replay") | |
64 | ||
65 | argv_parser.add_option( | |
66 | "-e","--ras_enable", | |
67 | action="store_true",dest="ras_enable",default=False, | |
68 | help="RAS enable.") | |
69 | ||
70 | argv_parser.add_option( | |
71 | "-f","--format", | |
72 | action="store_true",dest="format",default=False, | |
73 | help="Output in n2 sas.log format if -f is specified.") | |
74 | ||
75 | argv_parser.add_option( | |
76 | "-i","--interactive", | |
77 | action="store_true",dest="interactive",default=False, | |
78 | help="switch to interactive (inspect) mode") | |
79 | ||
80 | argv_parser.add_option( | |
81 | "-n","--samfe", | |
82 | action="store_true",dest="samfe",default=False, | |
83 | help="Invoke nas-fe command parser in batch & interactive modes") | |
84 | ||
85 | argv_parser.add_option( | |
86 | "-p","--replay", | |
87 | action="store_true",dest="replay",default=False, | |
88 | help="Replay and verify from a previous run.") | |
89 | ||
90 | argv_parser.add_option( | |
91 | "-r","--release", | |
92 | action="store",type="string",dest="release",default='', | |
93 | metavar="VERSION",help="Release version of this tool") | |
94 | ||
95 | argv_parser.add_option( | |
96 | "-s","--riesling-conf", | |
97 | action="append",type="string",dest="riesling_conf",default=["riesling.conf"], | |
98 | metavar="FILE",help="Default riesling.conf") | |
99 | ||
100 | argv_parser.add_option( | |
101 | "-t","--trace", | |
102 | action="store_true",dest="trace",default=False, | |
103 | help="Trace instruction stepping to stdout.") | |
104 | ||
105 | argv_parser.add_option( | |
106 | "-x","--diag-simics", | |
107 | action="append",type="string",dest="diag_simics",default=["diag.simics"], | |
108 | metavar="FILE",help="Default diag.simics") | |
109 | ||
110 | global opts | |
111 | global args | |
112 | ||
113 | (opts,args) = argv_parser.parse_args() | |
114 | ||
115 | ||
116 | def history(name): | |
117 | histfile = '/home/'+os.environ["USER"]+'/'+name | |
118 | try: | |
119 | readline.read_history_file(histfile) | |
120 | atexit.register(readline.write_history_file,histfile) | |
121 | except IOError: | |
122 | pass | |
123 | ||
124 | ||
125 | options('nas') | |
126 | import commands | |
127 | import time | |
128 | ||
129 | sys.stdout.write('\n') | |
130 | sys.stdout.write('# %s\n' % (time.ctime())) | |
131 | sys.stdout.write('# %s\n' % (commands.getoutput('uname -a'))) | |
132 | #sys.stdout.write('# Python %s\n' % sys.version) | |
133 | sys.stdout.write('# NAS release %s\n' % ('nas,'+opts.release)) | |
134 | #sys.stdout.write('\n') | |
135 | #sys.stdout.write('# PATH %s\n' % sys.path) | |
136 | sys.stdout.write('\n') | |
137 | ||
138 | # this must happen before the Model() is created, otherwise frontend model | |
139 | # object won't have the same cpu-core-strand structure as the backend | |
140 | @-arch-@.init(int(opts.record),int(opts.replay)) | |
141 | ||
142 | sim = Model(SS_Memory.Memory(SS_Ram.get_memory()),SS_Io.Io(@-ARCH-@_Python.get_io()),@-ARCH-@_Python.@-arch-@_model(@-arch-@.model())) | |
143 | ||
144 | if opts.ras_enable: | |
145 | sim.ras_enable() | |
146 | ||
147 | if os.path.exists('mem.image.gz'): | |
148 | sim.mem.load('mem.image.gz') | |
149 | elif os.path.exists('mem.image'): | |
150 | sim.mem.load('mem.image') | |
151 | else: | |
152 | sys.stderr.write('WARNING: mem.image is not loaded\n') | |
153 | ||
154 | # when() is used in combination with run() | |
155 | # when(e) expects e to be a function that returns true when e() evaluates to true | |
156 | ||
157 | when_expr = [] | |
158 | ||
159 | def when(e): | |
160 | global when_expr | |
161 | when_expr.append(e) | |
162 | ||
163 | # run() steps the cosim environement forever until a when clause | |
164 | # evaluates to true. ok>0 means we hits a breakpoint, ok==0 means | |
165 | # all's fine and we keep going, ok==-1 means we saw PLI_QUIT, ok<-1 | |
166 | # means something is messed up ... e.g. pli socket read error | |
167 | ||
168 | def run(): | |
169 | ok = 0 | |
170 | stop = False | |
171 | while not stop: | |
172 | ok = @-arch-@.step(1) | |
173 | if ok == 0: | |
174 | for e in when_expr: | |
175 | stop = stop or e() | |
176 | else: | |
177 | stop = True | |
178 | return ok | |
179 | ||
180 | # step() steps the cosim environment n (default n=1) steps forward | |
181 | # Which strand is stepped is controlled by the RTL testbench or | |
182 | # the replay input | |
183 | ||
184 | def step(n=1): | |
185 | return @-arch-@.step(n) | |
186 | ||
187 | if opts.trace or @-arch-@.trace(): | |
188 | for s in sim.s: | |
189 | s.set_format(opts.format) | |
190 | if not @-arch-@.trace(): | |
191 | # if -sas_run_args=-DPLI_DEBUG is not used, let -t decide the trace | |
192 | # cscope | |
193 | s.lstmode(3) | |
194 | else: | |
195 | # otherwise rely on -sas_run_args=-DPLI_DEBUG to decide the level of | |
196 | # trace | |
197 | s.lstmode(1) | |
198 | ||
199 | # reset trace mode: 0 - silent, 1 - trap, 2 - trap+instr, 3 - trap+instr+delta, | |
200 | # others - silent | |
201 | # when invoke lstmode() in cosim mode, we should always use lstmode(1), and | |
202 | # rely on cosim -sas_run_args=-DPLI_DEBUG option to control the level of data | |
203 | # output. | |
204 | def lstmode(n): | |
205 | for s in sim.s: | |
206 | s.lstmode(n) | |
207 | ||
208 | hexmode() | |
209 | ||
210 | if opts.samfe: | |
211 | # in nas-fe mode, use the information in -x to conduct the execution | |
212 | fe_opts = {} | |
213 | fe_opts['-x'] = opts.diag_simics[-1] | |
214 | fe_opts['--ar'] = '@-arch-@' | |
215 | import SamFE | |
216 | SamFE.init(sim, fe_opts, globals()) | |
217 | elif not opts.interactive: | |
218 | run() | |
219 | else: | |
220 | os.environ['PYTHONINSPECT'] = 'inspect' | |
221 | history('.@-arch-@pfe') |