Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / samfe / src / SamUtility.py
CommitLineData
920dae64
AT
1# ========== Copyright Header Begin ==========================================
2#
3# OpenSPARC T2 Processor File: SamUtility.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# collection of utility functions
23#
24
25pfeSim = None
26
27def initSamUtility(sim):
28 """
29 this function must be called first before other functions in this file
30 can be used.
31 """
32 global pfeSim
33 pfeSim = sim
34
35
36def lstmode(on=None):
37 """
38 set display mode:
39 0 - silent mode
40 1 - display instr & register delta
41 2 - display instr
42 """
43 global pfeSim
44 for s in pfeSim.s:
45 s.lstmode(on)
46
47
48def stepx(sid=[-1], n=1, d=1):
49 """
50 execute instructions among strands in round-rabin order
51 sid: the strands to be included in the execution, -1 means all strands
52 n: number of instructions to be executed per strand
53 d: number of instructions to be executed per iteration
54 """
55 global pfeSim
56 ss = []
57 if -1 in sid:
58 # include all strands
59 ss = pfeSim.s
60 else:
61 # otherwise only selected strand(s)
62 for id in sid:
63 ss.append(pfeSim.s[id])
64 while n > d:
65 for s in ss:
66 brk = s.step(d)
67 if brk > 0:
68 # this strand hits a breakpoint, stop execution,
69 # return remaining instruction count
70 return n-(d-brk)
71 n -= d
72 for s in ss:
73 brk = s.step(n)
74 if brk > 0:
75 # this strand hits a breakpoint, stop execution,
76 # return remaining instruction count
77 return brk