This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Function pointer size issue with TSK_create in a converted project (DSPBIOS to SYSBIOS)

Other Parts Discussed in Thread: SYSBIOS

In a converted project I am running into an issue where the arguments passed to a task don't get passed properly. I have a work-around, but I'd like to know the root-cause for the issue.

I pass 2 pointers in a C++ module like so:

TSK_Attrs tsk_attrs = TSK_ATTRS;
tsk_attrs.stacksize = 4096;
tsk_attrs.priority = 15;
tsk_attrs.name = "MyClass::SomeFunction";
TSK_create((Fxn)(&MyClass::ThreadStarter), &tsk_attrs, this, (&MyClass::SomeFunction));

The C++ portion is not strictly necessary, but for convenience member pointers are used to start the "actual" thread from the function "ThreadStarter":

typedef void (MyClass::* ThreadFunc)(void);

int MyClass::ThreadStarter(MyClass* pthis, ThreadFunc pfunc) {
  (pthis->*pfunc)();
  return 0;
}

This works fine in the current DSP/BIOS implementation, but in the SYSBIOS conversion project, there's an issue: When the arguments get pushed to the stack, a size of 8 bytes per pointer seems to be assumed. However, when the ThreadStarter() function is called later on by the function "dynamicGlue()" (in tsk.c), the arguments are assumed to be individual 4 byte values. This of course fails miserably....

My main question is: what is the reason for this mechanism breaking? I am using the same cgtools for both the old DSP/BIOS project and the new SYSBIOS conversion.

Here's another thread which has some information regarding the functions used: 

These are the tools I am using (the processor is a C6474):

cgtools 7.4.8 (ELF)

C64x+ PDK: 1.0.0.06
DSPLIB C64x+ 3.4.0.0
EDMA3 LLD: 2.11.5
IPC: 1.24.3.32
MCSDK 1.0.0.08
NDK: 2.24.1.18
SYSBIOS: 6.35.4.50
XDCtools 3.25.4.88

Thanks,

Dirk

  • Could you post a small CCS program with the issue?

    Thanks,

    Todd

  • I'll get something together later today. Thanks!
  • We found the issue (well, at least the cause of it): in changing from DSP/BIOS to SYSBIOS I also changed from COFF to ELF eabi. Because of the way parameters are passed in COFF, a pointer to member function is stored as a structure like explained in 7.2.1.8 of SPRU187U.
    With COFF, when you pass arguments to a variadic function (like TSK_create()), the address of the structure (32-bit) gets stored on the stack. No problems here. With ELF, something different seems to be happening. I am unsure as to the exact details yet, but something goes wrong in this process. We suspect stack alignment is causing problems and don't think this is actually something wrong with ELF.

    The fix for us was easy and since SYSBIOS its TSK_create equivalent changed anyway this is not a problem.

    If I get to it I will update this page for he community when I know more.

    This wiki was also very helpful: processors.wiki.ti.com/.../C6000_EABI_Migration

    Cheers,
    Dirk