[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gEDA: VPI in Icarus Verilog



Stephen Williams <steve@icarus.com> said:

> mjarabek@istop.com said:
> > 1) When a callback is registered using vpi_register_cb() who allocates/
> > owns the memory pointed to by the argument?  The Verilog-1995 standard
> > is not clear on this point, except to say that when the callback is
> > called the pointer to the cb_data structure is not a pointer to the
> > same structure as was passed to the vpi_register_cb() function.
> 
> The simulator allocates and manages that memory. It automatically
> releases it when the callback memory is no longer needed.

That sounds like the desired behaviour. What's odd is that when I print the
value of the cb->value pointer in my callback it is the same as when I called
vpi_register_cb() and vvp complains about:

vpi_callback: value format 134702640 not supported

It smells like a stack trampler, I declared both the time and value structures
as auto variables in my code, and stuffed the address into the pointers. I had
initilized cb->value->format to vpiIntValue when I called vpi_register_cb().
Do the time and value sub-structures also get copied?  When I manually
malloc() these two sub-structures things work much better.

> mjarabek@istop.com said:
> > 2) Callbacks only seem to happen once, yet the standard implies that
> > once a callback has been installed it keeps getting called.
> 
> Could I have got that all wrong? I'll have to research this.

(It probably depends if you grew up a BSD or SysV signal() fan...  ;-)

It seems that a number of the callbacks are one-time only, like for a
particular simulation time event (time increases monotonically?), but most
others like cbValueChange, or cbForce might get called repeatedly when that
event happens to the object.

In your implementation, when re-registering, is it safe to just pass back the
p_cb_data pointer that the callback gets directly to vpi_register_cb() (after
updating the fields) or should I start with a fresh structure? (Am I going to
screw up some internal list, and wind up with a junk pointer to some memory
that has been free()'d somewhere else?)

ie.:
int callback(p_cb_data cb)
{

   /* do callback related things */
   vpi_printf("In callback\n");

   /* re-register */
   cb->reason = cbValueChange; /* re-init fields */
    ...

   vpi_register_cb(cb);  /* NOTE: same pointer as we got */
   return 0;
}	

> mjarabek@istop.com said:
> >  I added a call to `dlerror()' and discovered the real error. 
> 
> I have the same problem. I'd gladly apply a patch to fix this:-)

I will write it.

-- 
--------------------------------------------------
                              Mike Jarabek
                                FPGA/ASIC Designer
   http://www.doncaster.on.ca/~mjarabek
--------------------------------------------------