Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / py / sam.py
# ========== Copyright Header Begin ==========================================
#
# OpenSPARC T2 Processor File: sam.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 ============================================
### startup file for py interpreter
import sam
import sys
# get the system type defitions from vcpu.h
class SAM_SysType:
VCPU_IMPL_VER_SPITFIRE = 0x00001000
VCPU_IMPL_VER_SPITFIRE = 0x00001000
VCPU_IMPL_VER_BLACKBIRD = 0x00001100
VCPU_IMPL_VER_SABRE = 0x00001200
VCPU_IMPL_VER_SAPPHIRE = 0x00001300
VCPU_IMPL_VER_CHEETAH = 0x00001400
VCPU_IMPL_VER_CHPLUS = 0x00001500
VCPU_IMPL_VER_SUN4U = 0x00001000
VCPU_IMPL_VER_N1 = 0x00002300
VCPU_IMPL_VER_N2 = 0x00002410
VCPU_IMPL_VER_SUN4V = 0x00002000
VCPU_IMPL_VER_MASK = 0x00ffffff
VCPU_IMPL_SIM_BLAZE = 0x01000000
VCPU_IMPL_SIM_RIESLING = 0x02000000
VCPU_IMPL_SIM_VONK = 0x03000000
VCPU_IMPL_SIM_MASK = 0xff000000
sys_type = sam.sys_type()
# Vonk PFE stuff, only for N2, and others of the ilk
# Mask out the upper 8 bits
if (sys_type & SAM_SysType.VCPU_IMPL_VER_MASK) >= SAM_SysType.VCPU_IMPL_VER_N2:
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)
SAM_Python = None
SAM_Model = None
SAM_Model_Instance = None
sim = None
if sys_type == SAM_SysType.VCPU_IMPL_VER_N2:
SAM_Python = __import__('N2_Python')
SAM_Model = __import__('N2_Model')
SAM_Model_Instance = SAM_Python.n2_model
sim = SAM_Model.Model(SAM_Memory(),SS_Io.Io(SAM_Python.get_io()),SAM_Model_Instance(sam.sys_pntr(0)))
SAM_Model.hexmode()
elif sys_type == SAM_SysType.VCPU_IMPL_VER_RK:
SAM_Python = __import__('Rk_Python')
SAM_Model = __import__('Rk_Model')
SAM_Model_Instance = SAM_Python.rk_model
sim = SAM_Model.Model(SAM_Memory(),SAM_Model_Instance(sam.sys_pntr(0)))
SAM_Model.hexmode()
# import some functions from SAM_Model
if SAM_Model != None:
asm = SAM_Model.asm
dis = SAM_Model.dis
decmode = SAM_Model.decmode
hexmode = SAM_Model.hexmode
del(SAM_Model_Instance)
del(SAM_Python)
del(Pfe_Memory)
del(SS_Io)
del(SAM_Memory)
del(sys_type)
del(SAM_SysType)
# Import the SAM UI functions, they can be overridden by
# specializations
cmd_dict = sam.get_cmd_dict()
for cmd in cmd_dict.keys():
if cmd == "":
continue
exec(cmd_dict[cmd])
exec('sam.'+cmd+' = sam_'+cmd)
exec('del sam_'+cmd)
del(cmd_dict)
del(cmd)
# Define the add/delete UI functions
def del_ui(cmd):
exec('del sam.'+cmd)
def add_ui(help,cmd):
str = "def sam_%s(args=\"\"):\n" % (cmd,)
str = str + " \"\"\"%s\n" % (help,)
str = str + " \"\"\"\n"
str = str + " sam.ui_exec(\"%s \" + args)" % (cmd,)
exec(str)
exec('sam.'+cmd+' = sam_'+cmd)
exec('del sam_'+cmd)
# register the command add and delete functions with sam
sam.set_cmd_del_fn(del_ui)
sam.set_cmd_add_fn(add_ui)