| 1 |
16 |
HanySalah |
//
|
| 2 |
|
|
// -------------------------------------------------------------
|
| 3 |
|
|
// Copyright 2004-2009 Synopsys, Inc.
|
| 4 |
|
|
// Copyright 2010-2011 Mentor Graphics Corporation
|
| 5 |
|
|
// Copyright 2010 Cadence Design Systems, Inc.
|
| 6 |
|
|
// All Rights Reserved Worldwide
|
| 7 |
|
|
//
|
| 8 |
|
|
// Licensed under the Apache License, Version 2.0 (the
|
| 9 |
|
|
// "License"); you may not use this file except in
|
| 10 |
|
|
// compliance with the License. You may obtain a copy of
|
| 11 |
|
|
// the License at
|
| 12 |
|
|
//
|
| 13 |
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
|
|
//
|
| 15 |
|
|
// Unless required by applicable law or agreed to in
|
| 16 |
|
|
// writing, software distributed under the License is
|
| 17 |
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
| 18 |
|
|
// CONDITIONS OF ANY KIND, either express or implied. See
|
| 19 |
|
|
// the License for the specific language governing
|
| 20 |
|
|
// permissions and limitations under the License.
|
| 21 |
|
|
// -------------------------------------------------------------
|
| 22 |
|
|
//
|
| 23 |
|
|
|
| 24 |
|
|
typedef class uvm_reg_cbs;
|
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
|
|
//------------------------------------------------------------------------------
|
| 28 |
|
|
// Class: uvm_reg_backdoor
|
| 29 |
|
|
//
|
| 30 |
|
|
// Base class for user-defined back-door register and memory access.
|
| 31 |
|
|
//
|
| 32 |
|
|
// This class can be extended by users to provide user-specific back-door access
|
| 33 |
|
|
// to registers and memories that are not implemented in pure SystemVerilog
|
| 34 |
|
|
// or that are not accessible using the default DPI backdoor mechanism.
|
| 35 |
|
|
//------------------------------------------------------------------------------
|
| 36 |
|
|
|
| 37 |
|
|
class uvm_reg_backdoor extends uvm_object;
|
| 38 |
|
|
|
| 39 |
|
|
// Function: new
|
| 40 |
|
|
//
|
| 41 |
|
|
// Create an instance of this class
|
| 42 |
|
|
//
|
| 43 |
|
|
// Create an instance of the user-defined backdoor class
|
| 44 |
|
|
// for the specified register or memory
|
| 45 |
|
|
//
|
| 46 |
|
|
function new(string name = "");
|
| 47 |
|
|
super.new(name);
|
| 48 |
|
|
endfunction: new
|
| 49 |
|
|
|
| 50 |
|
|
|
| 51 |
|
|
// Task: do_pre_read
|
| 52 |
|
|
//
|
| 53 |
|
|
// Execute the pre-read callbacks
|
| 54 |
|
|
//
|
| 55 |
|
|
// This method ~must~ be called as the first statement in
|
| 56 |
|
|
// a user extension of the method.
|
| 57 |
|
|
//
|
| 58 |
|
|
protected task do_pre_read(uvm_reg_item rw);
|
| 59 |
|
|
pre_read(rw);
|
| 60 |
|
|
`uvm_do_obj_callbacks(uvm_reg_backdoor, uvm_reg_cbs, this,
|
| 61 |
|
|
pre_read(rw))
|
| 62 |
|
|
endtask
|
| 63 |
|
|
|
| 64 |
|
|
|
| 65 |
|
|
// Task: do_post_read
|
| 66 |
|
|
//
|
| 67 |
|
|
// Execute the post-read callbacks
|
| 68 |
|
|
//
|
| 69 |
|
|
// This method ~must~ be called as the last statement in
|
| 70 |
|
|
// a user extension of the method.
|
| 71 |
|
|
//
|
| 72 |
|
|
protected task do_post_read(uvm_reg_item rw);
|
| 73 |
|
|
uvm_callback_iter#(uvm_reg_backdoor, uvm_reg_cbs) iter = new(this);
|
| 74 |
|
|
for(uvm_reg_cbs cb = iter.last(); cb != null; cb=iter.prev())
|
| 75 |
|
|
cb.decode(rw.value);
|
| 76 |
|
|
`uvm_do_obj_callbacks(uvm_reg_backdoor,uvm_reg_cbs,this,post_read(rw))
|
| 77 |
|
|
post_read(rw);
|
| 78 |
|
|
endtask
|
| 79 |
|
|
|
| 80 |
|
|
|
| 81 |
|
|
// Task: do_pre_write
|
| 82 |
|
|
//
|
| 83 |
|
|
// Execute the pre-write callbacks
|
| 84 |
|
|
//
|
| 85 |
|
|
// This method ~must~ be called as the first statement in
|
| 86 |
|
|
// a user extension of the method.
|
| 87 |
|
|
//
|
| 88 |
|
|
protected task do_pre_write(uvm_reg_item rw);
|
| 89 |
|
|
uvm_callback_iter#(uvm_reg_backdoor, uvm_reg_cbs) iter = new(this);
|
| 90 |
|
|
pre_write(rw);
|
| 91 |
|
|
`uvm_do_obj_callbacks(uvm_reg_backdoor,uvm_reg_cbs,this,pre_write(rw))
|
| 92 |
|
|
for(uvm_reg_cbs cb = iter.first(); cb != null; cb = iter.next())
|
| 93 |
|
|
cb.encode(rw.value);
|
| 94 |
|
|
endtask
|
| 95 |
|
|
|
| 96 |
|
|
|
| 97 |
|
|
// Task: do_post_write
|
| 98 |
|
|
//
|
| 99 |
|
|
// Execute the post-write callbacks
|
| 100 |
|
|
//
|
| 101 |
|
|
// This method ~must~ be called as the last statement in
|
| 102 |
|
|
// a user extension of the method.
|
| 103 |
|
|
//
|
| 104 |
|
|
protected task do_post_write(uvm_reg_item rw);
|
| 105 |
|
|
`uvm_do_obj_callbacks(uvm_reg_backdoor,uvm_reg_cbs,this,post_write(rw))
|
| 106 |
|
|
post_write(rw);
|
| 107 |
|
|
endtask
|
| 108 |
|
|
|
| 109 |
|
|
|
| 110 |
|
|
// Task: write
|
| 111 |
|
|
//
|
| 112 |
|
|
// User-defined backdoor write operation.
|
| 113 |
|
|
//
|
| 114 |
|
|
// Call .
|
| 115 |
|
|
// Deposit the specified value in the specified register HDL implementation.
|
| 116 |
|
|
// Call .
|
| 117 |
|
|
// Returns an indication of the success of the operation.
|
| 118 |
|
|
//
|
| 119 |
|
|
extern virtual task write(uvm_reg_item rw);
|
| 120 |
|
|
|
| 121 |
|
|
|
| 122 |
|
|
// Task: read
|
| 123 |
|
|
//
|
| 124 |
|
|
// User-defined backdoor read operation.
|
| 125 |
|
|
//
|
| 126 |
|
|
// Overload this method only if the backdoor requires the use of task.
|
| 127 |
|
|
//
|
| 128 |
|
|
// Call .
|
| 129 |
|
|
// Peek the current value of the specified HDL implementation.
|
| 130 |
|
|
// Call .
|
| 131 |
|
|
// Returns the current value and an indication of the success of
|
| 132 |
|
|
// the operation.
|
| 133 |
|
|
//
|
| 134 |
|
|
// By default, calls .
|
| 135 |
|
|
//
|
| 136 |
|
|
extern virtual task read(uvm_reg_item rw);
|
| 137 |
|
|
|
| 138 |
|
|
|
| 139 |
|
|
// Function: read_func
|
| 140 |
|
|
//
|
| 141 |
|
|
// User-defined backdoor read operation.
|
| 142 |
|
|
//
|
| 143 |
|
|
// Peek the current value in the HDL implementation.
|
| 144 |
|
|
// Returns the current value and an indication of the success of
|
| 145 |
|
|
// the operation.
|
| 146 |
|
|
//
|
| 147 |
|
|
extern virtual function void read_func(uvm_reg_item rw);
|
| 148 |
|
|
|
| 149 |
|
|
|
| 150 |
|
|
// Function: is_auto_updated
|
| 151 |
|
|
//
|
| 152 |
|
|
// Indicates if wait_for_change() method is implemented
|
| 153 |
|
|
//
|
| 154 |
|
|
// Implement to return TRUE if and only if
|
| 155 |
|
|
// is implemented to watch for changes
|
| 156 |
|
|
// in the HDL implementation of the specified field
|
| 157 |
|
|
//
|
| 158 |
|
|
extern virtual function bit is_auto_updated(uvm_reg_field field);
|
| 159 |
|
|
|
| 160 |
|
|
|
| 161 |
|
|
// Task: wait_for_change
|
| 162 |
|
|
//
|
| 163 |
|
|
// Wait for a change in the value of the register or memory
|
| 164 |
|
|
// element in the DUT.
|
| 165 |
|
|
//
|
| 166 |
|
|
// When this method returns, the mirror value for the register
|
| 167 |
|
|
// corresponding to this instance of the backdoor class will be updated
|
| 168 |
|
|
// via a backdoor read operation.
|
| 169 |
|
|
//
|
| 170 |
|
|
extern virtual local task wait_for_change(uvm_object element);
|
| 171 |
|
|
|
| 172 |
|
|
|
| 173 |
|
|
/*local*/ extern function void start_update_thread(uvm_object element);
|
| 174 |
|
|
/*local*/ extern function void kill_update_thread(uvm_object element);
|
| 175 |
|
|
/*local*/ extern function bit has_update_threads();
|
| 176 |
|
|
|
| 177 |
|
|
|
| 178 |
|
|
// Task: pre_read
|
| 179 |
|
|
//
|
| 180 |
|
|
// Called before user-defined backdoor register read.
|
| 181 |
|
|
//
|
| 182 |
|
|
// The registered callback methods are invoked after the invocation
|
| 183 |
|
|
// of this method.
|
| 184 |
|
|
//
|
| 185 |
|
|
virtual task pre_read(uvm_reg_item rw); endtask
|
| 186 |
|
|
|
| 187 |
|
|
|
| 188 |
|
|
// Task: post_read
|
| 189 |
|
|
//
|
| 190 |
|
|
// Called after user-defined backdoor register read.
|
| 191 |
|
|
//
|
| 192 |
|
|
// The registered callback methods are invoked before the invocation
|
| 193 |
|
|
// of this method.
|
| 194 |
|
|
//
|
| 195 |
|
|
virtual task post_read(uvm_reg_item rw); endtask
|
| 196 |
|
|
|
| 197 |
|
|
|
| 198 |
|
|
// Task: pre_write
|
| 199 |
|
|
//
|
| 200 |
|
|
// Called before user-defined backdoor register write.
|
| 201 |
|
|
//
|
| 202 |
|
|
// The registered callback methods are invoked after the invocation
|
| 203 |
|
|
// of this method.
|
| 204 |
|
|
//
|
| 205 |
|
|
// The written value, if modified, modifies the actual value that
|
| 206 |
|
|
// will be written.
|
| 207 |
|
|
//
|
| 208 |
|
|
virtual task pre_write(uvm_reg_item rw); endtask
|
| 209 |
|
|
|
| 210 |
|
|
|
| 211 |
|
|
// Task: post_write
|
| 212 |
|
|
//
|
| 213 |
|
|
// Called after user-defined backdoor register write.
|
| 214 |
|
|
//
|
| 215 |
|
|
// The registered callback methods are invoked before the invocation
|
| 216 |
|
|
// of this method.
|
| 217 |
|
|
//
|
| 218 |
|
|
virtual task post_write(uvm_reg_item rw); endtask
|
| 219 |
|
|
|
| 220 |
|
|
|
| 221 |
|
|
string fname;
|
| 222 |
|
|
int lineno;
|
| 223 |
|
|
|
| 224 |
|
|
`ifdef UVM_USE_PROCESS_CONTAINER
|
| 225 |
|
|
local process_container_c m_update_thread[uvm_object];
|
| 226 |
|
|
`else
|
| 227 |
|
|
local process m_update_thread[uvm_object];
|
| 228 |
|
|
`endif
|
| 229 |
|
|
|
| 230 |
|
|
`uvm_object_utils(uvm_reg_backdoor)
|
| 231 |
|
|
`uvm_register_cb(uvm_reg_backdoor, uvm_reg_cbs)
|
| 232 |
|
|
|
| 233 |
|
|
|
| 234 |
|
|
endclass: uvm_reg_backdoor
|
| 235 |
|
|
|
| 236 |
|
|
|
| 237 |
|
|
//------------------------------------------------------------------------------
|
| 238 |
|
|
// IMPLEMENTATION
|
| 239 |
|
|
//------------------------------------------------------------------------------
|
| 240 |
|
|
|
| 241 |
|
|
|
| 242 |
|
|
// is_auto_updated
|
| 243 |
|
|
|
| 244 |
|
|
function bit uvm_reg_backdoor::is_auto_updated(uvm_reg_field field);
|
| 245 |
|
|
return 0;
|
| 246 |
|
|
endfunction
|
| 247 |
|
|
|
| 248 |
|
|
|
| 249 |
|
|
// wait_for_change
|
| 250 |
|
|
|
| 251 |
|
|
task uvm_reg_backdoor::wait_for_change(uvm_object element);
|
| 252 |
|
|
`uvm_fatal("RegModel", "uvm_reg_backdoor::wait_for_change() method has not been overloaded");
|
| 253 |
|
|
endtask
|
| 254 |
|
|
|
| 255 |
|
|
|
| 256 |
|
|
// start_update_thread
|
| 257 |
|
|
|
| 258 |
|
|
function void uvm_reg_backdoor::start_update_thread(uvm_object element);
|
| 259 |
|
|
uvm_reg rg;
|
| 260 |
|
|
if (this.m_update_thread.exists(element)) begin
|
| 261 |
|
|
this.kill_update_thread(element);
|
| 262 |
|
|
end
|
| 263 |
|
|
if (!$cast(rg,element))
|
| 264 |
|
|
return; // only regs supported at this time
|
| 265 |
|
|
|
| 266 |
|
|
fork
|
| 267 |
|
|
begin
|
| 268 |
|
|
uvm_reg_field fields[$];
|
| 269 |
|
|
|
| 270 |
|
|
`ifdef UVM_USE_PROCESS_CONTAINER
|
| 271 |
|
|
this.m_update_thread[element] = new(process::self());
|
| 272 |
|
|
`else
|
| 273 |
|
|
this.m_update_thread[element] = process::self();
|
| 274 |
|
|
`endif
|
| 275 |
|
|
|
| 276 |
|
|
rg.get_fields(fields);
|
| 277 |
|
|
forever begin
|
| 278 |
|
|
uvm_status_e status;
|
| 279 |
|
|
uvm_reg_data_t val;
|
| 280 |
|
|
uvm_reg_item r_item = new("bd_r_item");
|
| 281 |
|
|
r_item.element = rg;
|
| 282 |
|
|
r_item.element_kind = UVM_REG;
|
| 283 |
|
|
this.read(r_item);
|
| 284 |
|
|
val = r_item.value[0];
|
| 285 |
|
|
if (r_item.status != UVM_IS_OK) begin
|
| 286 |
|
|
`uvm_error("RegModel", $sformatf("Backdoor read of register '%s' failed.",
|
| 287 |
|
|
rg.get_name()));
|
| 288 |
|
|
end
|
| 289 |
|
|
foreach (fields[i]) begin
|
| 290 |
|
|
if (this.is_auto_updated(fields[i])) begin
|
| 291 |
|
|
r_item.value[0] = (val >> fields[i].get_lsb_pos()) &
|
| 292 |
|
|
((1 << fields[i].get_n_bits())-1);
|
| 293 |
|
|
fields[i].do_predict(r_item);
|
| 294 |
|
|
end
|
| 295 |
|
|
end
|
| 296 |
|
|
this.wait_for_change(element);
|
| 297 |
|
|
end
|
| 298 |
|
|
end
|
| 299 |
|
|
join_none
|
| 300 |
|
|
endfunction
|
| 301 |
|
|
|
| 302 |
|
|
|
| 303 |
|
|
// kill_update_thread
|
| 304 |
|
|
|
| 305 |
|
|
function void uvm_reg_backdoor::kill_update_thread(uvm_object element);
|
| 306 |
|
|
if (this.m_update_thread.exists(element)) begin
|
| 307 |
|
|
|
| 308 |
|
|
`ifdef UVM_USE_PROCESS_CONTAINER
|
| 309 |
|
|
this.m_update_thread[element].p.kill();
|
| 310 |
|
|
`else
|
| 311 |
|
|
this.m_update_thread[element].kill();
|
| 312 |
|
|
`endif
|
| 313 |
|
|
|
| 314 |
|
|
this.m_update_thread.delete(element);
|
| 315 |
|
|
end
|
| 316 |
|
|
endfunction
|
| 317 |
|
|
|
| 318 |
|
|
|
| 319 |
|
|
// has_update_threads
|
| 320 |
|
|
|
| 321 |
|
|
function bit uvm_reg_backdoor::has_update_threads();
|
| 322 |
|
|
return this.m_update_thread.num() > 0;
|
| 323 |
|
|
endfunction
|
| 324 |
|
|
|
| 325 |
|
|
|
| 326 |
|
|
// write
|
| 327 |
|
|
|
| 328 |
|
|
task uvm_reg_backdoor::write(uvm_reg_item rw);
|
| 329 |
|
|
`uvm_fatal("RegModel", "uvm_reg_backdoor::write() method has not been overloaded");
|
| 330 |
|
|
endtask
|
| 331 |
|
|
|
| 332 |
|
|
|
| 333 |
|
|
// read
|
| 334 |
|
|
|
| 335 |
|
|
task uvm_reg_backdoor::read(uvm_reg_item rw);
|
| 336 |
|
|
do_pre_read(rw);
|
| 337 |
|
|
read_func(rw);
|
| 338 |
|
|
do_post_read(rw);
|
| 339 |
|
|
endtask
|
| 340 |
|
|
|
| 341 |
|
|
|
| 342 |
|
|
// read_func
|
| 343 |
|
|
|
| 344 |
|
|
function void uvm_reg_backdoor::read_func(uvm_reg_item rw);
|
| 345 |
|
|
`uvm_fatal("RegModel", "uvm_reg_backdoor::read_func() method has not been overloaded");
|
| 346 |
|
|
rw.status = UVM_NOT_OK;
|
| 347 |
|
|
endfunction
|