# ========== Copyright Header Begin ==========================================
# OpenSPARC T2 Processor File: Pfe_Strand.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 ============================================
class GetAttrError(Exception):
return "The strand has no getable state member '"+self
.name
+"'"
class DelAttrError(Exception):
return "Strand attributes such as "+self
.name
+" can not be deleted"
class SetAttrError(Exception):
return "The strand has no setable state member '"+name
+"'"
class TrapLevelZeroError(Exception):
return "Trap state can not be accessed when tl=0"
def __geterror_fun__(name
,strand
):
def __seterror_fun__(name
,strand
,value
):
return lambda strand
: __geterror_fun__(name
,strand
)
return lambda strand
,value
: __seterror_fun__(name
,strand
,value
)
def __gettl_check__(strand
):
tl
= Strand
.__getfun
__['tl'](strand
)
raise TrapLevelZeroError()
def __gettt__(strand
): return TrapStack
.__getfun
__['tt'](strand
,__gettl_check__(strand
))
def __settt__(strand
,value
): TrapStack
.__setfun
__['tt'](strand
,__gettl_check__(strand
),value
)
def __gettpc__(strand
): return TrapStack
.__getfun
__['tpc'](strand
,__gettl_check__(strand
))
def __settpc__(strand
,value
): TrapStack
.__setfun
__['tpc'](strand
,__gettl_check__(strand
),value
)
def __gettnpc__(strand
): return TrapStack
.__getfun
__['tnpc'](strand
,__gettl_check__(strand
))
def __settnpc__(strand
,value
): TrapStack
.__setfun
__['tnpc'](strand
,__gettl_check__(strand
),value
)
def __gettstate__(strand
): return TrapStack
.__getfun
__['tstate'](strand
,__gettl_check__(strand
))
def __settstate__(strand
,value
): TrapStack
.__setfun
__['tstate'](strand
,__gettl_check__(strand
),value
)
def __gethtstate__(strand
): return TrapStack
.__getfun
__['htstate'](strand
,__gettl_check__(strand
))
def __sethtstate__(strand
,value
): TrapStack
.__setfun
__['htstate'](strand
,__gettl_check__(strand
),value
)
'htstate': __gethtstate__
'htstate': __sethtstate__
for i
in ['pc', 'npc', 'cwp', 'cansave', 'canrestore', 'otherwin', 'cleanwin', 'wstate',
'y', 'asi', 'ccr', 'fsr', 'gsr', 'fprs', 'pil', 'softint',
'tl', 'gl', 'pstate', 'hpstate', 'tba', 'htba', 'hver', 'hintp',
'tick', 'stick', 'tick_cmpr', 'stick_cmpr', 'hstick_cmpr', 'rstv_addr'
'max_tl', 'max_gl', 'max_ptl', 'max_pgl','max_wp','strand_id']:
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
__irf__
= ['g%d' % i
for i
in range(0,8)]\
+ ['o%d' % i
for i
in range(0,8)]\
+ ['l%d' % i
for i
in range(0,8)]\
+ ['i%d' % i
for i
in range(0,8)]
__frf__
= ['f%d' % i
for i
in range(0,64)]
__drf__
= ['d%d' % i
for i
in range(0,64,2)]
__qrf__
= ['q%d' % i
for i
in range(0,64,4)]
__asr__
= ['asr%d' % i
for i
in range(0,32)]
__pr__
= ['pr%d' % i
for i
in range(0,32)]
__hpr__
= ['hpr%d' % i
for i
in range(0,32)]
__sim__
= ['sim%d' % i
for i
in range(0,32)]
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
__getfun__
[i
] = __geterror__(i
)
__setfun__
[i
] = __seterror__(i
)
def __init__(self
,strand
,ref
):
self
.__dict
__['__strand__'] = strand
self
.__dict
__['ref'] = ref
self
.__dict
__['inst_tlb'] = {}
self
.__dict
__['data_tlb'] = {}
self
.__dict
__['brk'] = {}
self
.__dict
__['t'] = TrapStack(strand
)
self
.__dict
__['g'] = GlobalStack(strand
)
self
.__dict
__['w'] = WindowStack(strand
)
self
.__dict
__['__listing__'] = 0
self
.__dict
__['__verify__'] = False
self
.__dict
__['__ras__'] = False
def __getattr__(self
,name
):
if Strand
.__getfun
__.has_key(name
):
return Strand
.__getfun
__[name
](self
.__strand
__)
def __setattr__(self
,name
,data
):
if Strand
.__setfun
__.has_key(name
):
return Strand
.__setfun
__[name
](self
.__strand
__,data
)
#self.__dict__[name] = data
if self
.__dict
__.has_key(name
):
self
.__dict
__[name
] = data
# print 'Cant set. No strand attribute %s\n' % (name,)
return 'Cant set. No strand attribute %s\n' % (name
,)
self
.__dict
__[name
] = data
def __delattr__(self
,name
):
elif name
== '__strand__' or name
== 't':
return "<Strand instance>"
return "<Strand instance>"
#------------------------------------------------------------------------
# mode switching related interface
#------------------------------------------------------------------------
def lstmode(self
,lstval
= None):
lstmode() switches the strand to listing mode based on the value of lstval
a value of 0 disables the list mode.
a value of 1 enables the list mode where the executed instruction along
with the sideeffects are displayed.
a value of 2 enables the list mode where only the executed instruction
w/o an argument the current listing mode is returned
elif type(lstval
) != int:
self
.__listing
__ = lstval
self
.step
= self
.__lststep
__
if self
.__dict
__.has_key('__lstnames__'):
for r
in self
.__lstnames
__:
if r
in ['tt','tpc','tnpc','tstate','htstate']:
self
.__lststate
__[r
] = None
self
.__lststate
__[r
] = getattr(self
,r
)
for r
in self
.__lststate
__:
self
.__lststate
__[r
] = getattr(self
,r
)
self
.step
= self
.__runstep
__
vrfmode() switches the strand to verification mode when on=True, e.g turn of optimisations for
run mode. This means that every load/store and instruction fetch goes through the
rasmode() switches the strand into ras mode when on=True, expects vrfmode to be on
#------------------------------------------------------------------------
#------------------------------------------------------------------------
def va2pa(self
,va
,ctx
=None,pid
=None):
def ra2pa(self
,ra
,pid
=None):
#------------------------------------------------------------------------
#------------------------------------------------------------------------
def available(self
,on
=None):
def enable(self
,on
=None):
def running(self
,on
=None):
def stepping(self
,on
=None):
#------------------------------------------------------------------------
#------------------------------------------------------------------------
step() steps the simulator n instructions forward
The method is switched between __runstep__ and __lststep__ by lstmode()
def __runstep__(self
,n
=None):
runstep() steps the simulator n instruction without echoing inpstr to output
def __lststep__(self
,n
=None):
lststep() steps the simulator n instruction and echo instr to output
def __init__(self
,strand
,tl
):
self
.__dict
__['strand'] = strand
def __getattr__(self
,name
):
return TrapStack
.__getfun
__[name
](self
.strand
,self
.tl
)
def __setattr__(self
,name
,value
):
return TrapStack
.__setfun
__[name
](self
.strand
,self
.tl
,value
)
for field
in ['tt','tpc','tnpc','tstate','htstate']:
__getfun__
[field
] = __geterror__(field
)
__setfun__
[field
] = __seterror__(field
)
def __init__(self
,strand
):
for tl
in range(1,TrapStack
.MAXTL
):
self
.trap_stack
[tl
] = TrapStackEntry(strand
,tl
)
def __getitem__(self
,index
):
raise TrapLevelZeroError()
return self
.trap_stack
[index
]
def __init__(self
,strand
,gl
):
self
.__dict
__['strand'] = strand
def __getattr__(self
,name
):
return GlobalStack
.__getfun
__[name
](self
.strand
,self
.gl
)
def __setattr__(self
,name
,value
):
return GlobalStack
.__setfun
__[name
](self
.strand
,self
.gl
,value
)
def __getitem__(self
,index
):
return GlobalStack
.__getfun
__[index
](self
.strand
,self
.gl
)
def setitem__(self
,index
,value
):
return GlobalStack
.__setfun
__[index
](self
.strand
,self
.gl
,value
)
for r
in ['g%d' % i
for i
in range(0,8)]:
__getfun__
[r
] = __geterror__(r
)
__setfun__
[r
] = __seterror__(r
)
def __init__(self
,strand
):
for gl
in range(0,GlobalStack
.MAXGL
+ 1):
self
.global_stack
[gl
] = GlobalStackEntry(strand
,gl
)
def __getitem__(self
,index
):
return self
.global_stack
[index
]
def __init__(self
,strand
,win
):
self
.__dict
__['strand'] = strand
self
.__dict
__['win'] = win
def __getattr__(self
,name
):
return WindowStack
.__getfun
__[name
](self
.strand
,self
.win
)
def __setattr__(self
,name
,value
):
return WindowStack
.__setfun
__[name
](self
.strand
,self
.win
,value
)
def __getitem__(self
,index
):
return WindowStack
.__getfun
__[index
](self
.strand
,self
.win
)
def __setitem__(self
,index
,value
):
return WindowStack
.__setfun
__[index
](self
.strand
,self
.win
,value
)
for r
in Strand
.__irf
__[8:]:
__getfun__
[r
] = __geterror__(r
)
__setfun__
[r
] = __seterror__(r
)
def __init__(self
,strand
):
for win
in range(0,WindowStack
.MAXWP
):
self
.window_stack
[win
] = WindowRegEntry(strand
,win
)
def __getitem__(self
,index
):
return self
.window_stack
[index
]