Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / py / sam.py
CommitLineData
920dae64
AT
1# ========== Copyright Header Begin ==========================================
2#
3# OpenSPARC T2 Processor File: sam.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### startup file for py interpreter
22import sam
23import sys
24
25
26# get the system type defitions from vcpu.h
27class SAM_SysType:
28 VCPU_IMPL_VER_SPITFIRE = 0x00001000
29 VCPU_IMPL_VER_SPITFIRE = 0x00001000
30 VCPU_IMPL_VER_BLACKBIRD = 0x00001100
31 VCPU_IMPL_VER_SABRE = 0x00001200
32 VCPU_IMPL_VER_SAPPHIRE = 0x00001300
33 VCPU_IMPL_VER_CHEETAH = 0x00001400
34 VCPU_IMPL_VER_CHPLUS = 0x00001500
35 VCPU_IMPL_VER_SUN4U = 0x00001000
36
37 VCPU_IMPL_VER_N1 = 0x00002300
38 VCPU_IMPL_VER_N2 = 0x00002410
39 VCPU_IMPL_VER_SUN4V = 0x00002000
40 VCPU_IMPL_VER_MASK = 0x00ffffff
41
42 VCPU_IMPL_SIM_BLAZE = 0x01000000
43 VCPU_IMPL_SIM_RIESLING = 0x02000000
44 VCPU_IMPL_SIM_VONK = 0x03000000
45 VCPU_IMPL_SIM_MASK = 0xff000000
46
47
48sys_type = sam.sys_type()
49
50# Vonk PFE stuff, only for N2, and others of the ilk
51# Mask out the upper 8 bits
52if (sys_type & SAM_SysType.VCPU_IMPL_VER_MASK) >= SAM_SysType.VCPU_IMPL_VER_N2:
53
54 import Pfe_Memory
55 import SS_Io
56
57 class SAM_Memory(Pfe_Memory.Memory):
58 def __init__(self):
59 Pfe_Memory.Memory.__init__(self)
60
61 def load(self,filename,base=None):
62 if base==None:
63 sam.ui_exec('load img '+filename)
64 else:
65 sam.ui_exec('load bin '+filename+' '+str(base))
66
67 def save(self,filename,base,size):
68 sam.ui_exec('memdump '+filename+' '+str(base)+' '+str(size))
69
70 def __ldb__(self,addr): return sam.mem_ld8(addr)
71 def __ldh__(self,addr): return sam.mem_ld16(addr)
72 def __ldw__(self,addr): return sam.mem_ld32(addr)
73 def __ldx__(self,addr): return sam.mem_ld64(addr)
74
75 def __stb__(self,addr,data): sam.mem_st8(addr,data)
76 def __sth__(self,addr,data): sam.mem_st16(addr,data)
77 def __stw__(self,addr,data): sam.mem_st32(addr,data)
78 def __stx__(self,addr,data): sam.mem_st64(addr,data)
79
80 SAM_Python = None
81 SAM_Model = None
82 SAM_Model_Instance = None
83 sim = None
84
85 if sys_type == SAM_SysType.VCPU_IMPL_VER_N2:
86 SAM_Python = __import__('N2_Python')
87 SAM_Model = __import__('N2_Model')
88 SAM_Model_Instance = SAM_Python.n2_model
89 sim = SAM_Model.Model(SAM_Memory(),SS_Io.Io(SAM_Python.get_io()),SAM_Model_Instance(sam.sys_pntr(0)))
90 SAM_Model.hexmode()
91
92 elif sys_type == SAM_SysType.VCPU_IMPL_VER_RK:
93 SAM_Python = __import__('Rk_Python')
94 SAM_Model = __import__('Rk_Model')
95 SAM_Model_Instance = SAM_Python.rk_model
96 sim = SAM_Model.Model(SAM_Memory(),SAM_Model_Instance(sam.sys_pntr(0)))
97 SAM_Model.hexmode()
98
99 # import some functions from SAM_Model
100
101 if SAM_Model != None:
102 asm = SAM_Model.asm
103 dis = SAM_Model.dis
104 decmode = SAM_Model.decmode
105 hexmode = SAM_Model.hexmode
106
107 del(SAM_Model_Instance)
108 del(SAM_Python)
109 del(Pfe_Memory)
110 del(SS_Io)
111 del(SAM_Memory)
112
113del(sys_type)
114del(SAM_SysType)
115
116# Import the SAM UI functions, they can be overridden by
117# specializations
118
119cmd_dict = sam.get_cmd_dict()
120for cmd in cmd_dict.keys():
121 if cmd == "":
122 continue
123 exec(cmd_dict[cmd])
124 exec('sam.'+cmd+' = sam_'+cmd)
125 exec('del sam_'+cmd)
126
127del(cmd_dict)
128del(cmd)
129
130# Define the add/delete UI functions
131
132def del_ui(cmd):
133 exec('del sam.'+cmd)
134
135def add_ui(help,cmd):
136 str = "def sam_%s(args=\"\"):\n" % (cmd,)
137 str = str + " \"\"\"%s\n" % (help,)
138 str = str + " \"\"\"\n"
139 str = str + " sam.ui_exec(\"%s \" + args)" % (cmd,)
140 exec(str)
141 exec('sam.'+cmd+' = sam_'+cmd)
142 exec('del sam_'+cmd)
143
144# register the command add and delete functions with sam
145
146sam.set_cmd_del_fn(del_ui)
147sam.set_cmd_add_fn(add_ui)