Friday, November 11, 2011

NULL pointer dereference error in OVM

Spent long time cracking your head how to get rid of this error?


The first thing to notice when we see "pointer" is that this is related to memory allocation. There are two conditions on which we get this error.
  • When memory is not yet available for this particular object (the name of the object will be available in the error description).
  • Memory is available (object already created), but the handle which we declared may not have a connection(reference) to it.
OVM is highly typed becasue of OOP. It creates a chain of objects in OVM object hierarchy and the configuration mechanism gives the links to them all. If we want to use out of reference object's handle, we need to refer the object first.  This is done by configuration, which is generally done inside build() task, but can be done also in initial blocks inside module/program block.

Use the following code initially once:
      set_config_object("*","object_name", object_name_handle, .clone(0));

Use the following check whenever you want to use this object out side the scope:
    object_class_name object_name_handle;
    ovm_object              ovm_object_handle;
    if (!this.get_config_object("object_name_handle",ovm_object_handle,.clone(0)))
    begin
        `ovm_info(report_id,"object_name_handle is not instantiated",OVM_MEDIUM);
        return;
    end
    if (!$cast(object_name_handle, ovm_object_handle))
    begin
        `ovm_error(report_id, "object_name_handle cast failed");
    end

Thursday, January 13, 2011

links for the technial replies

http://www.systemverilog.in/forum/showthread.php?tid=155
http://www.systemverilog.in/forum/showthread.php?tid=143

Saturday, January 1, 2011

Why Associative Arrays (Hashes, as they are called in Perl) ??

I have gone through the topic “Associative Arrays” many times in System Verilog LRM and was wondering what was so great about it. We can have index other than integers type....characters, strings, or even arrays. So what???

One of my colleagues also have given example for this: For selecting 4 ports of a SoC; he used an associative array, but with indexes of type integer only....

The example below which I came across gives correct idea of Associative arrays and importance of it.
Searching a pattern in a list and finding the number of occurrences of it......

Inputfile.txt                       Outputfile.txt

test1                Pass           test1       2
test2                Pass           test2       2
test1                Fail           test4       1
test3                Fail
test1                Fail
test4                Pass
test1                Pass
test2                Pass 

We need to search how many times a test passed and then print it. See the below code, how easily it can be done with the help of associative arrays(hashes).


#!/usr/bin/perl
open(INPUT_FILE, "inputfile.txt");
while($inputline = <INPUT_FILE>)
{
   @word = split(/\s+/, $inputline);
   if($word[1] = "PASS")
   {
      $test = $word[0];
      $associative_array{$test}+= 1;
   }
}

foreach $test (sort keys(%associative_array))
{
   print "$test: $associative_array{$test}\n";
}

Here we need not worry about keeping track of the word count and total entries in the list. The word we are looking itself is made the index and this reduces the complexity.