Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / sam / bin / sam_ss.py
CommitLineData
920dae64
AT
1# ========== Copyright Header Begin ==========================================
2#
3# OpenSPARC T2 Processor File: sam_ss.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#### sam_@-arch-@.py is automatically generated from
23### ss/api/sam/bin/sam_ss.py, do not modify sam_@-arch-@.py,
24### make necessary changes in ss/api/sam/bin/sam_ss.py instead.
25
26#
27# startup file for @-arch-@ sam frontend
28#
29
30import sys
31
32# This python script lives in the pfe/samfe subdirectory. That
33# subdiractory is automatically added to the python search path.
34# We need to add the pfe directory as well so do that here.
35
36sys.path.append('/'.join(sys.argv[0].split('/')[:-2]))
37
38# swig layer
39import @-ARCH-@_Python
40
41# extended interface for sam
42# modules/py/py_interface.cc::py_thread() { Py_InitModule((char*)"sam", py_methods); }
43import sam
44
45#from SamCmd import *
46
47### pfe @-arch-@ system
48
49from @-ARCH-@_Model import *
50import Pfe_Memory
51import SS_Io
52
53class SAM_Memory(Pfe_Memory.Memory):
54 def __init__(self):
55 Pfe_Memory.Memory.__init__(self)
56
57 def load(self,filename,base=None):
58 if base==None:
59 sam.ui_exec('load img '+filename)
60 else:
61 sam.ui_exec('load bin '+filename+' '+str(base))
62
63 def save(self,filename,base,size):
64 sam.ui_exec('memdump '+filename+' '+str(base)+' '+str(size))
65
66 def __ldb__(self,addr): return sam.mem_ld8(addr)
67 def __ldh__(self,addr): return sam.mem_ld16(addr)
68 def __ldw__(self,addr): return sam.mem_ld32(addr)
69 def __ldx__(self,addr): return sam.mem_ld64(addr)
70
71 def __stb__(self,addr,data): sam.mem_st8(addr,data)
72 def __sth__(self,addr,data): sam.mem_st16(addr,data)
73 def __stw__(self,addr,data): sam.mem_st32(addr,data)
74 def __stx__(self,addr,data): sam.mem_st64(addr,data)
75
76
77def dis(opc,vpc=0):
78 return @-ARCH-@_Python.dis(opc,vpc)
79
80def usage():
81 """
82 runtime options
83 """
84 sys.stderr.write('\n')
85 sys.stderr.write('synopsis: [options] python scripts ... \n')
86 sys.stderr.write('\n')
87 sys.stderr.write('options:\n')
88 sys.stderr.write(' -h : help\n')
89 sys.stderr.write(' -p X : python script file to be executed at the beginning\n')
90 sys.stderr.write(' -x diag.sam : startup config, combine with diag.conf to form config\n')
91 sys.stderr.write(' --ar X : n2\n')
92 sys.stderr.write(' --blaze X : n2\n')
93 sys.stderr.write(' --blazeopt "Xs" : blaze options\n')
94 sys.stderr.write(' --cpu X : number of cpus\n')
95 sys.stderr.write(' --pmask X : indicate enabled strands\n')
96 sys.stderr.write(' --rc riesling.rc : combination of diag.sam and diag.conf\n')
97 sys.exit()
98
99### start sam frontend
100### MAIN ###
101if __name__ == '__main__':
102 """
103 Sam frontend startup
104 """
105 # if --blaze is specified, then Blaze_x_System should be used.
106 # if --blaze is not specified, but -DMOM is specified, then --blaze
107 # will be added to optdir.
108 import getopt
109 # concatenate options embraced in double-quote, "..."
110 #sys.stderr.write('DBX: sys.argv=%s\n' % sys.argv) #DBX
111 argv = []
112 argMerge = []
113 for arg in sys.argv:
114 if argMerge == [] and arg.startswith('"'):
115 argMerge.append(arg[1:])
116 elif argMerge != [] and arg.endswith('"'):
117 argMerge.append(arg[:-1])
118 argv.append(' '.join(argMerge))
119 argMerge = []
120 elif argMerge != []:
121 argMerge.append(arg)
122 else:
123 argv.append(arg)
124 #sys.stderr.write('DBX: argv=%s\n' % argv) #DBX
125
126 # see usage()
127 optlist, args = getopt.getopt(argv[1:], 'hp:x:', ['ar=','pmask=','rc=','blaze=','blazeopt=','cpu='])
128
129 optdir = { '--cpu':1 }
130 for (key,value) in optlist:
131 optdir[key] = value
132 if not optdir.has_key('--ar') and optdir.has_key('--blaze'):
133 optdir['--ar'] = optdir['--blaze']
134 else:
135 optdir['--ar'] = '@-arch-@'
136 #sys.stderr.write('DBX: optdir=%s\n' % optdir) #DBX
137
138 if optdir.has_key('-h'):
139 usage()
140
141 optdir['scripts'] = args
142
143 # init system
144 sim = Model(SAM_Memory(),SS_Io.Io(@-ARCH-@_Python.get_io()),@-ARCH-@_Python.@-arch-@_model(sam.sys_pntr(0)))
145 ncpu = int(optdir['--cpu'])
146 if (optdir['--ar'] == 'n2' and (ncpu != 1)):
147 sys.stderr.write('ERROR: wrong number of %s cpus: %d\n' % (optdir['--ar'].upper(), ncpu))
148 sys.exit()
149
150 # set up frontend system
151 #sys.stderr.write('DBX: ncpu=%d, cpus=%s\n' % (ncpu, cpus)) #DBX
152
153 ####
154 hexmode()
155
156 import SamFE
157
158 SamFE.dis = dis
159 SamFE.init(sim, optdir, globals())