Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: CTContextBase.vr | |
4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
6 | // | |
7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
8 | // | |
9 | // This program is free software; you can redistribute it and/or modify | |
10 | // it under the terms of the GNU General Public License as published by | |
11 | // the Free Software Foundation; version 2 of the License. | |
12 | // | |
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | // | |
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | // | |
22 | // For the avoidance of doubt, and except that if any non-GPL license | |
23 | // choice is available it will apply instead, Sun elects to use only | |
24 | // the General Public License version 2 (GPLv2) at this time for any | |
25 | // software where a choice of GPL license versions is made | |
26 | // available with the language indicating that GPLv2 or any later version | |
27 | // may be used, or where a choice of which version of the GPL is applied is | |
28 | // otherwise unspecified. | |
29 | // | |
30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
31 | // CA 95054 USA or visit www.sun.com if you need additional information or | |
32 | // have any questions. | |
33 | // | |
34 | // ========== Copyright Header End ============================================ | |
35 | #include <vera_defines.vrh> | |
36 | #include "CTVerifObjectBase.vrh" | |
37 | #include "CTStrategyBase.vrh" | |
38 | #include "CTTransactionID.vrh" | |
39 | #include "cReport.vrh" | |
40 | ||
41 | virtual class CTContextBase extends CTVerifObject { | |
42 | integer StratDone = 0; | |
43 | integer NumStrat; | |
44 | string Name = ""; | |
45 | ReportClass ContextReport = new; | |
46 | ||
47 | local bit HangDetect = 0; | |
48 | local integer WaitCount; | |
49 | ||
50 | // This object is a triplet of ID information, but only context ID is set at this level. | |
51 | protected CTTransactionID ID = new; | |
52 | ||
53 | // This object is a reference to a strategy object that could potentially be | |
54 | // instantiated in a test. | |
55 | protected CTStrategyBase MyStrategy; | |
56 | ||
57 | //This tracks the auto-generated context ID numbers | |
58 | local static integer NextContextID = 0; | |
59 | ||
60 | //////////////////////////////////////////////////////////////////////////////////// | |
61 | // These super-class virtual methods should be overridden by concrete | |
62 | // context classes. The step of the Execute template method, represented by each | |
63 | // of these methods, will be skipped if an implementation is not provided in a | |
64 | // concrete class. | |
65 | // | |
66 | // ProvideStrategy | |
67 | // --------------- | |
68 | // The purpose of this method is to provide the next strategy to | |
69 | // be forked off as part of a concurrent group. This method can pass | |
70 | // through a reference to a strategy that was selected and instantiated | |
71 | // in a test, or alternatively, this method can select and instantiate | |
72 | // the strategy itself. There is great flexibility to either approach. | |
73 | virtual protected function CTStrategyBase ProvideStrategy() {} | |
74 | // | |
75 | // FinalizeParms | |
76 | // ------------- | |
77 | // Once a final strategy is selected, its parameters must be finalized. | |
78 | // Like strategies themselves, parameters can either be set in a test or | |
79 | // chosen by the context. This method takes a Strategy and initializes any | |
80 | // parameters that were not set in the context. | |
81 | virtual protected function CTStrategyBase FinalizeParms(CTStrategyBase S) {} | |
82 | // | |
83 | // CheckParms | |
84 | // ---------- | |
85 | // After a final set of parameters is chosen, it can be checked for consistency | |
86 | // before proceeding. This method scans the final parameters to determine | |
87 | // if the set is consistent (i.e., no mutually conflicting or impossible values). | |
88 | // The consequence of finding a bad parameter set is left up to the implementor. | |
89 | // The set can be made consistent (this is the reason that S is a var parameter) | |
90 | // or an error can be signaled. | |
91 | // Note: This task does not need to be implemented. | |
92 | virtual protected task CheckParms(var CTStrategyBase S) {} | |
93 | // | |
94 | // DelayIssue | |
95 | // ---------- | |
96 | // This method controls the rate at which strategies are created and launched. | |
97 | // This is useful for two reasons: | |
98 | // 1. To vary the stimulus for the DUT, it provides a variable delay between the start of | |
99 | // strategies. | |
100 | // 2. It allows prior strategies to make progress while subsequent strategies are in | |
101 | // the process of being created and launched. | |
102 | // | |
103 | // It is *highly recommended* that every derived context defines DelayIssue with | |
104 | // at least a single "@(posedge CLOCK)" to make simulation progress before all | |
105 | // strategies are created. | |
106 | virtual protected task DelayIssue () {} | |
107 | //////////////////////////////////////////////////////////////////////////////////// | |
108 | ||
109 | // Test writers will presuppose that each context has an Execute method. | |
110 | // This Execute template method should be generic enough to be used | |
111 | // by most concrete contexts. However, in rare cases where an alternate | |
112 | // pattern of execution is required, this method can be overridden. | |
113 | // | |
114 | // At the context level, "Execute" is a command to fork a number (NumStrat) of | |
115 | // independent strategy treads. NumStrat is set by the test writer. | |
116 | virtual task Execute() { | |
117 | shadow integer StratNum; //Number assocated with the next strategy to be launched | |
118 | CTStrategyBase FinalStrategy; | |
119 | ||
120 | // The number of strategy threads that are forked (NumStrat) is set | |
121 | // by the client test. | |
122 | ContextReport.report(RTYP_INFO, "Starting Context %s ID = %0d", | |
123 | Name, | |
124 | ID.GetContextID()); | |
125 | for (StratDone = 0, StratNum=1; StratNum<=NumStrat; ++StratNum) { | |
126 | ||
127 | //Wait for a user-defined synchronization event | |
128 | DelayIssue(); | |
129 | ||
130 | // There are five distinct steps in setting up and launching a strategy thread. | |
131 | fork | |
132 | { | |
133 | // Step 1: | |
134 | FinalStrategy = ProvideStrategy(); | |
135 | ||
136 | // Step 2: | |
137 | FinalStrategy = FinalizeParms(FinalStrategy); | |
138 | ||
139 | // Step 3: | |
140 | CheckParms(FinalStrategy); | |
141 | ||
142 | // Step 4: | |
143 | // If it made it this far, give the strategy a unique identifier. | |
144 | FinalStrategy.SetID(ID.GetContextID(), StratNum); | |
145 | ||
146 | // Step 5: | |
147 | // Kick it off. | |
148 | FinalStrategy.RunThread(); | |
149 | ++StratDone; | |
150 | ||
151 | } | |
152 | join none | |
153 | } | |
154 | ||
155 | // This loop works like a breakable wait_child() and | |
156 | // causes Execute to block until all its strategies are | |
157 | // complete. | |
158 | while (StratDone < NumStrat) { | |
159 | ||
160 | if (HangDetect) { | |
161 | --WaitCount; | |
162 | if (WaitCount <= 0) | |
163 | error("Hang Detected In Context %s ID = %0d\n", Name, ID.GetContextID()); | |
164 | } | |
165 | ||
166 | @(posedge CLOCK); | |
167 | } | |
168 | } | |
169 | ||
170 | task new (string Name = "") { | |
171 | //Auto-increment context ID | |
172 | this.Name = Name; | |
173 | ID.SetContextID(++NextContextID); | |
174 | } | |
175 | ||
176 | task SetHangDetect(integer HangTime) { | |
177 | ||
178 | if (HangTime <= 0) | |
179 | HangDetect = 0; | |
180 | else { | |
181 | HangDetect = 1; | |
182 | WaitCount = HangTime; | |
183 | } | |
184 | ||
185 | } | |
186 | ||
187 | } | |
188 |