Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / exe / nas / bin / SS_Main.py
# ========== Copyright Header Begin ==========================================
#
# OpenSPARC T2 Processor File: SS_Main.py
# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
#
# The above named program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License version 2 as published by the Free Software Foundation.
#
# The above named program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this work; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ========== Copyright Header End ============================================
##***********************************************************************
##
## Copyright (C) 2006, Sun Microsystems, Inc.
##
## Sun considers its source code as an unpublished, proprietary
## trade secret and it is available only under strict license provisions.
## This copyright notice is placed here only to protect Sun in the event
## the source is deemed a published work. Disassembly, decompilation,
## or other means of reducing the object code to human readable form
## is prohibited by the license agreement under which this code is
## provided to the user or company in possession of this copy.
##
##***********************************************************************
### @-ARCH-@_Main.py is automatically generated from
### ss/exe/nas/bin/SS_Main.py, do not modify @-ARCH-@_Main.py,
### make necessary changes in ss/exe/nas/bin/Bl_Main.py instead.
import os
import sys
import atexit
import readline
import Pfe_Version
import @-arch-@
from optparse import OptionParser
from @-ARCH-@_Model import *
import SS_Ram
import SS_Memory
import SS_Io
opts = None
args = None
def options(prog):
argv_parser = OptionParser(usage="usage: "+prog+" [options]",version=Pfe_Version.version())
argv_parser.disable_interspersed_args()
argv_parser.add_option(
"-c","--record",
action="store_true",dest="record",default=False,
help="Record pli socket i/o for replay")
argv_parser.add_option(
"-e","--ras_enable",
action="store_true",dest="ras_enable",default=False,
help="RAS enable.")
argv_parser.add_option(
"-f","--format",
action="store_true",dest="format",default=False,
help="Output in n2 sas.log format if -f is specified.")
argv_parser.add_option(
"-i","--interactive",
action="store_true",dest="interactive",default=False,
help="switch to interactive (inspect) mode")
argv_parser.add_option(
"-n","--samfe",
action="store_true",dest="samfe",default=False,
help="Invoke nas-fe command parser in batch & interactive modes")
argv_parser.add_option(
"-p","--replay",
action="store_true",dest="replay",default=False,
help="Replay and verify from a previous run.")
argv_parser.add_option(
"-r","--release",
action="store",type="string",dest="release",default='',
metavar="VERSION",help="Release version of this tool")
argv_parser.add_option(
"-s","--riesling-conf",
action="append",type="string",dest="riesling_conf",default=["riesling.conf"],
metavar="FILE",help="Default riesling.conf")
argv_parser.add_option(
"-t","--trace",
action="store_true",dest="trace",default=False,
help="Trace instruction stepping to stdout.")
argv_parser.add_option(
"-x","--diag-simics",
action="append",type="string",dest="diag_simics",default=["diag.simics"],
metavar="FILE",help="Default diag.simics")
global opts
global args
(opts,args) = argv_parser.parse_args()
def history(name):
histfile = '/home/'+os.environ["USER"]+'/'+name
try:
readline.read_history_file(histfile)
atexit.register(readline.write_history_file,histfile)
except IOError:
pass
options('nas')
import commands
import time
sys.stdout.write('\n')
sys.stdout.write('# %s\n' % (time.ctime()))
sys.stdout.write('# %s\n' % (commands.getoutput('uname -a')))
#sys.stdout.write('# Python %s\n' % sys.version)
sys.stdout.write('# NAS release %s\n' % ('nas,'+opts.release))
#sys.stdout.write('\n')
#sys.stdout.write('# PATH %s\n' % sys.path)
sys.stdout.write('\n')
# this must happen before the Model() is created, otherwise frontend model
# object won't have the same cpu-core-strand structure as the backend
@-arch-@.init(int(opts.record),int(opts.replay))
sim = Model(SS_Memory.Memory(SS_Ram.get_memory()),SS_Io.Io(@-ARCH-@_Python.get_io()),@-ARCH-@_Python.@-arch-@_model(@-arch-@.model()))
if opts.ras_enable:
sim.ras_enable()
if os.path.exists('mem.image.gz'):
sim.mem.load('mem.image.gz')
elif os.path.exists('mem.image'):
sim.mem.load('mem.image')
else:
sys.stderr.write('WARNING: mem.image is not loaded\n')
# when() is used in combination with run()
# when(e) expects e to be a function that returns true when e() evaluates to true
when_expr = []
def when(e):
global when_expr
when_expr.append(e)
# run() steps the cosim environement forever until a when clause
# evaluates to true. ok>0 means we hits a breakpoint, ok==0 means
# all's fine and we keep going, ok==-1 means we saw PLI_QUIT, ok<-1
# means something is messed up ... e.g. pli socket read error
def run():
ok = 0
stop = False
while not stop:
ok = @-arch-@.step(1)
if ok == 0:
for e in when_expr:
stop = stop or e()
else:
stop = True
return ok
# step() steps the cosim environment n (default n=1) steps forward
# Which strand is stepped is controlled by the RTL testbench or
# the replay input
def step(n=1):
return @-arch-@.step(n)
if opts.trace or @-arch-@.trace():
for s in sim.s:
s.set_format(opts.format)
if not @-arch-@.trace():
# if -sas_run_args=-DPLI_DEBUG is not used, let -t decide the trace
# cscope
s.lstmode(3)
else:
# otherwise rely on -sas_run_args=-DPLI_DEBUG to decide the level of
# trace
s.lstmode(1)
# reset trace mode: 0 - silent, 1 - trap, 2 - trap+instr, 3 - trap+instr+delta,
# others - silent
# when invoke lstmode() in cosim mode, we should always use lstmode(1), and
# rely on cosim -sas_run_args=-DPLI_DEBUG option to control the level of data
# output.
def lstmode(n):
for s in sim.s:
s.lstmode(n)
hexmode()
if opts.samfe:
# in nas-fe mode, use the information in -x to conduct the execution
fe_opts = {}
fe_opts['-x'] = opts.diag_simics[-1]
fe_opts['--ar'] = '@-arch-@'
import SamFE
SamFE.init(sim, fe_opts, globals())
elif not opts.interactive:
run()
else:
os.environ['PYTHONINSPECT'] = 'inspect'
history('.@-arch-@pfe')