bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

BSC 2014.05.C Generated VPI wrapper crashes iverilog sim

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: BSC (Bluespec Compiler)
View previous topic :: View next topic  
Author Message
asutherland



Joined: 16 Dec 2013
Posts: 4

PostPosted: Wed Sep 24, 2014 6:49 pm    Post subject: BSC 2014.05.C Generated VPI wrapper crashes iverilog sim Reply with quote

I have a BDPI function:

import "BDPI" function ActionValue#(Bit#(32)) read_pixel();

The generated vpi_wrapper causes iverilog simulator to crash trying to free a null pointer. This can be corrected by commenting out 3 lines of unused code. (see version below)

Code:
/* VPI wrapper function */
PLI_INT32 read_pixel_calltf(PLI_BYTE8 *user_data)
{
  vpiHandle hCall;
  unsigned int vpi_result;
  vpiHandle *handle_array;
 
  /* retrieve handle array */
  hCall = vpi_handle(vpiSysTfCall, 0);
  handle_array = vpi_get_userdata(hCall);
  if (handle_array == NULL)
  {
    vpiHandle hArgList;
    hArgList = vpi_iterate(vpiArgument, hCall);
    handle_array = malloc(sizeof(vpiHandle) * 1u);
    handle_array[0u] = hCall;
    vpi_put_userdata(hCall, handle_array);
    vpi_free_object(hArgList);    <----------------------------------------------------------------------------
  }
 
  /* create return value */
  make_vpi_result(handle_array[0u], &vpi_result, DIRECT);
 
  /* call the imported C function */
  vpi_result = read_pixel();
 
  /* copy out return value */
  put_vpi_result(handle_array[0u], &vpi_result, DIRECT);
  vpi_free_object(hCall);
 
  return 0;
}


Comment out unused hArgList to correct.
Code:
...
  if (handle_array == NULL)
  {
    //    vpiHandle hArgList;
    // hArgList = vpi_iterate(vpiArgument, hCall);
    handle_array = malloc(sizeof(vpiHandle) * 1u);
    handle_array[0u] = hCall;
    vpi_put_userdata(hCall, handle_array);
    // vpi_free_object(hArgList);
  }
  ...
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 496

PostPosted: Thu Sep 25, 2014 2:10 pm    Post subject: Re: BSC 2014.05.C Generated VPI wrapper crashes iverilog sim Reply with quote

I am able to reproduce this problem, with iverilog 0.9.7. I get this error:
Code:
vvp: vpi_priv.cc:138: PLI_INT32 vpi_free_object(__vpiHandle*): Assertion `ref' failed.
Abort

The example works when using a commercial simulator, though. So it may be a bug in iverilog. I'll have a look. Thank you for reporting this issue.
Back to top
View user's profile Send private message
asutherland



Joined: 16 Dec 2013
Posts: 4

PostPosted: Mon Sep 29, 2014 3:24 pm    Post subject: Reply with quote

Just realized that adding a dummy param is a work around for this.

Obvious, but it took me a while to get there.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: BSC (Bluespec Compiler) All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP