Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | ### N2_Main.py is automatically generated from |
2 | ### ss/exe/nas/bin/Bl_Main.py, do not modify N2_Main.py, | |
3 | ### make necessary changes in ss/exe/nas/bin/Bl_Main.py instead. | |
4 | ||
5 | import os | |
6 | import sys | |
7 | import atexit | |
8 | import readline | |
9 | import Pfe_Version | |
10 | import n2 | |
11 | ||
12 | from optparse import OptionParser | |
13 | from N2_Model import * | |
14 | ||
15 | import SS_Ram | |
16 | import SS_Memory | |
17 | import SS_Io | |
18 | ||
19 | opts = None | |
20 | args = None | |
21 | ||
22 | def options(prog): | |
23 | argv_parser = OptionParser(usage="usage: "+prog+" [options]",version=Pfe_Version.version()) | |
24 | argv_parser.disable_interspersed_args() | |
25 | ||
26 | argv_parser.add_option( | |
27 | "-c","--record", | |
28 | action="store_true",dest="record",default=False, | |
29 | help="Record pli socket i/o for replay") | |
30 | ||
31 | argv_parser.add_option( | |
32 | "-e","--ras_enable", | |
33 | action="store_true",dest="ras_enable",default=False, | |
34 | help="RAS enable.") | |
35 | ||
36 | argv_parser.add_option( | |
37 | "-f","--format", | |
38 | action="store_true",dest="format",default=False, | |
39 | help="Output in n2 sas.log format if -f is specified.") | |
40 | ||
41 | argv_parser.add_option( | |
42 | "-i","--interactive", | |
43 | action="store_true",dest="interactive",default=False, | |
44 | help="switch to interactive (inspect) mode") | |
45 | ||
46 | argv_parser.add_option( | |
47 | "-n","--samfe", | |
48 | action="store_true",dest="samfe",default=False, | |
49 | help="Invoke nas-fe command parser in batch & interactive modes") | |
50 | ||
51 | argv_parser.add_option( | |
52 | "-p","--replay", | |
53 | action="store_true",dest="replay",default=False, | |
54 | help="Replay and verify from a previous run.") | |
55 | ||
56 | argv_parser.add_option( | |
57 | "-r","--release", | |
58 | action="store",type="string",dest="release",default='', | |
59 | metavar="VERSION",help="Release version of this tool") | |
60 | ||
61 | argv_parser.add_option( | |
62 | "-s","--riesling-conf", | |
63 | action="append",type="string",dest="riesling_conf",default=["riesling.conf"], | |
64 | metavar="FILE",help="Default riesling.conf") | |
65 | ||
66 | argv_parser.add_option( | |
67 | "-t","--trace", | |
68 | action="store_true",dest="trace",default=False, | |
69 | help="Trace instruction stepping to stdout.") | |
70 | ||
71 | argv_parser.add_option( | |
72 | "-x","--diag-simics", | |
73 | action="append",type="string",dest="diag_simics",default=["diag.simics"], | |
74 | metavar="FILE",help="Default diag.simics") | |
75 | ||
76 | global opts | |
77 | global args | |
78 | ||
79 | (opts,args) = argv_parser.parse_args() | |
80 | ||
81 | ||
82 | def history(name): | |
83 | histfile = '/home/'+os.environ["USER"]+'/'+name | |
84 | try: | |
85 | readline.read_history_file(histfile) | |
86 | atexit.register(readline.write_history_file,histfile) | |
87 | except IOError: | |
88 | pass | |
89 | ||
90 | ||
91 | options('nas') | |
92 | import commands | |
93 | import time | |
94 | ||
95 | sys.stdout.write('\n') | |
96 | sys.stdout.write('# %s\n' % (time.ctime())) | |
97 | sys.stdout.write('# %s\n' % (commands.getoutput('uname -a'))) | |
98 | #sys.stdout.write('# Python %s\n' % sys.version) | |
99 | sys.stdout.write('# NAS release %s\n' % ('nas,'+opts.release)) | |
100 | #sys.stdout.write('\n') | |
101 | #sys.stdout.write('# PATH %s\n' % sys.path) | |
102 | sys.stdout.write('\n') | |
103 | ||
104 | sim = Model(SS_Memory.Memory(SS_Ram.get_memory()),SS_Io.Io(N2_Python.get_io()),N2_Python.n2_model(n2.model())) | |
105 | ||
106 | if opts.ras_enable: | |
107 | sim.ras_enable() | |
108 | ||
109 | if os.path.exists('mem.image.gz'): | |
110 | sim.mem.load('mem.image.gz') | |
111 | elif os.path.exists('mem.image'): | |
112 | sim.mem.load('mem.image') | |
113 | else: | |
114 | sys.stderr.write('WARNING: mem.image is not loaded\n') | |
115 | ||
116 | # when() is used in combination with run() | |
117 | # when(e) expects e to be a function that returns true when e() evaluates to true | |
118 | ||
119 | when_expr = [] | |
120 | ||
121 | def when(e): | |
122 | global when_expr | |
123 | when_expr.append(e) | |
124 | ||
125 | # run() steps the cosim environement forever until a when clause | |
126 | # evaluates to true. ok>0 means we hits a breakpoint, ok==0 means | |
127 | # all's fine and we keep going, ok==-1 means we saw PLI_QUIT, ok<-1 | |
128 | # means something is messed up ... e.g. pli socket read error | |
129 | ||
130 | def run(): | |
131 | ok = 0 | |
132 | stop = False | |
133 | while not stop: | |
134 | ok = n2.step(1) | |
135 | if ok == 0: | |
136 | for e in when_expr: | |
137 | stop = stop or e() | |
138 | else: | |
139 | stop = True | |
140 | return ok | |
141 | ||
142 | # step() steps the cosim environment n (default n=1) steps forward | |
143 | # Which strand is stepped is controlled by the RTL testbench or | |
144 | # the replay input | |
145 | ||
146 | def step(n=1): | |
147 | return n2.step(n) | |
148 | ||
149 | n2.init(int(opts.record),int(opts.replay)) | |
150 | ||
151 | if opts.trace or n2.trace(): | |
152 | for s in sim.s: | |
153 | s.set_format(opts.format) | |
154 | if not n2.trace(): | |
155 | # if -sas_run_args=-DPLI_DEBUG is not used, let -t decide the trace | |
156 | # cscope | |
157 | s.lstmode(3) | |
158 | else: | |
159 | # otherwise rely on -sas_run_args=-DPLI_DEBUG to decide the level of | |
160 | # trace | |
161 | s.lstmode(n2.trace()+90) | |
162 | ||
163 | # reset trace mode: 0 - silent, 1 - trap, 2 - trap+instr, 3 - trap+instr+delta, | |
164 | # others - silent (except [91,92,93,94], those are used by -sas_run_args=-DPLI_DEBUG) | |
165 | def lstmode(n): | |
166 | for s in sim.s: | |
167 | s.lstmode(n) | |
168 | ||
169 | hexmode() | |
170 | ||
171 | if opts.samfe: | |
172 | # in nas-fe mode, use the information in -x to conduct the execution | |
173 | fe_opts = {} | |
174 | fe_opts['-x'] = opts.diag_simics[-1] | |
175 | fe_opts['--ar'] = 'n2' | |
176 | import SamFE | |
177 | SamFE.init(sim, fe_opts, globals()) | |
178 | elif not opts.interactive: | |
179 | run() | |
180 | else: | |
181 | os.environ['PYTHONINSPECT'] = 'inspect' | |
182 | history('.n2pfe') |