Dear All,
I would like to allocate a buffer with only 32b-pointer at SystemVerilog for a 32b-pointer C system.
Following is my example code, printf at C shows the pointer always be 64b.
How can I generate buffer allocated at SystemVerilog with only 32b-pointer?
Many thanks~
SystemVerilog
import "DPI-C" function void C_FUNC(output int unsigned dwBaseAddr [`MAX_SIZE]
output chandle m_Buff);
import "DPI-C" function chandle malloc(int unsigned size);
int unsigned dwBaseAddr [`MAX_SIZE];
chandle m_Buff;
initial begin
C_FUNC(dwBaseAddr);
m_Buff = malloc(10);
end
=======================================================
C code
void
C_FUNC(unsigned int* pStatic_Buff
void** pHdl_Buff)
{
unsigned int* ptC_Buff; // In C system, pointer's bits only 32
ptC_Buff = pStatic_Buff;
printf("First data pStatic_Buff = %2x\n", pStatic_Buff[0]); // It'ok, program ran smoothly
printf("First data C_Buff = %2x\n", ptC_Buff[0]); // when program step this, it always gets segmentation fault
//printf("[C_printf] SV_Addr = 0x%16lx, C_Addr = 0x%16lx \n", pStatic_Buff, ptC_Buff);
//printf("[C_printf] Addr = %16lx\n", pHdl_Buff);
}
=================================================================
When I ran SIM_FUNC simulation with C_FUNC, it got segmentation fault.
After printf message,
It was easy to find that the buffer pointer(pStatic_Buff) at SIM_FUNC was 64 bit-width base, but in C_FUNC, ptC_Buff was declared as 32 bit-width. so C can’t identify ptC_Buff0.
In my C code, I have developed programs for 32 bit-width pointer. I would like to know if SV’s pointer could be as 32-bitwidth.
You don’t declare pointers as being 32 or 64-bit; it’s determined how you compile your code, You need to make sure your C compiler and simulators are both using the same size pointers.
In reply to vatics_r89162:
You don’t declare pointers as being 32 or 64-bit; it’s determined how you compile your code, You need to make sure your C compiler and simulators are both using the same size pointers.
Actually, I force pointer type as 32-bit(company’s policy). So is it possible to force pointer type as 32-bit?