Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / sam / bin / sam_ss.py
# ========== Copyright Header Begin ==========================================
#
# OpenSPARC T2 Processor File: sam_ss.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 ============================================
#### sam_@-arch-@.py is automatically generated from
### ss/api/sam/bin/sam_ss.py, do not modify sam_@-arch-@.py,
### make necessary changes in ss/api/sam/bin/sam_ss.py instead.
#
# startup file for @-arch-@ sam frontend
#
import sys
# This python script lives in the pfe/samfe subdirectory. That
# subdiractory is automatically added to the python search path.
# We need to add the pfe directory as well so do that here.
sys.path.append('/'.join(sys.argv[0].split('/')[:-2]))
# swig layer
import @-ARCH-@_Python
# extended interface for sam
# modules/py/py_interface.cc::py_thread() { Py_InitModule((char*)"sam", py_methods); }
import sam
#from SamCmd import *
### pfe @-arch-@ system
from @-ARCH-@_Model import *
import Pfe_Memory
import SS_Io
class SAM_Memory(Pfe_Memory.Memory):
def __init__(self):
Pfe_Memory.Memory.__init__(self)
def load(self,filename,base=None):
if base==None:
sam.ui_exec('load img '+filename)
else:
sam.ui_exec('load bin '+filename+' '+str(base))
def save(self,filename,base,size):
sam.ui_exec('memdump '+filename+' '+str(base)+' '+str(size))
def __ldb__(self,addr): return sam.mem_ld8(addr)
def __ldh__(self,addr): return sam.mem_ld16(addr)
def __ldw__(self,addr): return sam.mem_ld32(addr)
def __ldx__(self,addr): return sam.mem_ld64(addr)
def __stb__(self,addr,data): sam.mem_st8(addr,data)
def __sth__(self,addr,data): sam.mem_st16(addr,data)
def __stw__(self,addr,data): sam.mem_st32(addr,data)
def __stx__(self,addr,data): sam.mem_st64(addr,data)
def dis(opc,vpc=0):
return @-ARCH-@_Python.dis(opc,vpc)
def usage():
"""
runtime options
"""
sys.stderr.write('\n')
sys.stderr.write('synopsis: [options] python scripts ... \n')
sys.stderr.write('\n')
sys.stderr.write('options:\n')
sys.stderr.write(' -h : help\n')
sys.stderr.write(' -p X : python script file to be executed at the beginning\n')
sys.stderr.write(' -x diag.sam : startup config, combine with diag.conf to form config\n')
sys.stderr.write(' --ar X : n2\n')
sys.stderr.write(' --blaze X : n2\n')
sys.stderr.write(' --blazeopt "Xs" : blaze options\n')
sys.stderr.write(' --cpu X : number of cpus\n')
sys.stderr.write(' --pmask X : indicate enabled strands\n')
sys.stderr.write(' --rc riesling.rc : combination of diag.sam and diag.conf\n')
sys.exit()
### start sam frontend
### MAIN ###
if __name__ == '__main__':
"""
Sam frontend startup
"""
# if --blaze is specified, then Blaze_x_System should be used.
# if --blaze is not specified, but -DMOM is specified, then --blaze
# will be added to optdir.
import getopt
# concatenate options embraced in double-quote, "..."
#sys.stderr.write('DBX: sys.argv=%s\n' % sys.argv) #DBX
argv = []
argMerge = []
for arg in sys.argv:
if argMerge == [] and arg.startswith('"'):
argMerge.append(arg[1:])
elif argMerge != [] and arg.endswith('"'):
argMerge.append(arg[:-1])
argv.append(' '.join(argMerge))
argMerge = []
elif argMerge != []:
argMerge.append(arg)
else:
argv.append(arg)
#sys.stderr.write('DBX: argv=%s\n' % argv) #DBX
# see usage()
optlist, args = getopt.getopt(argv[1:], 'hp:x:', ['ar=','pmask=','rc=','blaze=','blazeopt=','cpu='])
optdir = { '--cpu':1 }
for (key,value) in optlist:
optdir[key] = value
if not optdir.has_key('--ar') and optdir.has_key('--blaze'):
optdir['--ar'] = optdir['--blaze']
else:
optdir['--ar'] = '@-arch-@'
#sys.stderr.write('DBX: optdir=%s\n' % optdir) #DBX
if optdir.has_key('-h'):
usage()
optdir['scripts'] = args
# init system
sim = Model(SAM_Memory(),SS_Io.Io(@-ARCH-@_Python.get_io()),@-ARCH-@_Python.@-arch-@_model(sam.sys_pntr(0)))
ncpu = int(optdir['--cpu'])
if (optdir['--ar'] == 'n2' and (ncpu != 1)):
sys.stderr.write('ERROR: wrong number of %s cpus: %d\n' % (optdir['--ar'].upper(), ncpu))
sys.exit()
# set up frontend system
#sys.stderr.write('DBX: ncpu=%d, cpus=%s\n' % (ncpu, cpus)) #DBX
####
hexmode()
import SamFE
SamFE.dis = dis
SamFE.init(sim, optdir, globals())