This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

thumb

Hello,

I wrote a function which call another function through a pointer of function call.
When I trace the call, as soon as I reach the function the thumb bit is cleared, and of course the program no more run correctly.
When I call the same function directly the thumb bit is not cleared, of course.

What are the mechanism which could clear my thumb bit?

normal call

unsigned char *ip1;
fnEraseFlashSector(ip1 ,0);

special call

ulong ( *tempt_Fct )( ulong );
ulong tempData;
ulong tempData2;
tempData = ((ulong (*)(ulong,ulong))tempt_Fct)(tempData,tempData2);

I need to write generic function calls for RPC.

  • This:

    tempData = ((ulong (*)(ulong,ulong))tempt_Fct)(tempData,tempData2);
    

    is very unhealthy code. You should never get into a situation where you have to cast function pointers like that. Technically, that's quite likely to cause undefined behaviour. Losing a thumb bit on the way might be the least of your worries.

    You've also left out the most crucial past of your "special call" example: how you initialize that function pointer. For all you've allowed us to know, there never was a thumb bit in there to get lost.

    It's up to you to make sure that the function pointer is properly initialized before you use it.

  • Hello,

    I receive on UDP frame some data :
    - address of the function to call
    - number of parameter
    - list of parameter

    I read this data and affect then to their respective terms.
    If you have any idea to do that on another way, I will be pleased

    In all case I don't understand why my thumb bit change in this case.
    note : The function is really called.

    byte *ptrEnq;
    byte *ptrData;
    ulong ( *tempt_Fct )( ulong );
    ulong tempAddr;
    ulong tempData;
    ..........
            tempAddr = Mem_GetUlong(&ptrEnq);             //ptrEnq is automatically increased
            tempSize = Mem_GetByte(&ptrEnq);
            tempData = Mem_GetUlong(&ptrEnq);
            ptrData = (byte *)tempAddr;
            tempt_Fct = (ulong (*)(ulong))ptrData;
    
            switch (tempSize) {
                    case 1:
                            tempData = tempt_Fct(tempData);
                            break;
                    case 2:
                            tempData2 = Mem_GetUlong(&ptrEnq);
                            tempData = ((ulong (*)(ulong,ulong))tempt_Fct)(tempData,tempData2);
                            break;
                    case 3:
                            tempData2 = Mem_GetUlong(&ptrEnq);
                            tempData3 = Mem_GetUlong(&ptrEnq);
                            tempData = ((ulong (*)(ulong,ulong,ulong))tempt_Fct)(tempData,tempData2,tempData3);
                            break;
                    case 4:
                            tempData2 = Mem_GetUlong(&ptrEnq);
                            tempData3 = Mem_GetUlong(&ptrEnq);
                            tempData4 = Mem_GetUlong(&ptrEnq);
                            tempData = ((ulong (*)(ulong,ulong,ulong,ulong))tempt_Fct)(tempData,tempData2,tempData3,tempData4);
                            break;
                    default:
                            tempData = tempt_Fct(tempData);
                            break;
            }
    

  • (1) Setup a function pointer table, call based on parameters received.

    (2) Most likely one of these is the issue (apologies for the link):

    books.google.com/books

  • Thanks a lot T Max,

    you got it.

    The address given on the MAP file need to be corrected to have the lsb reflect the thumb state.
    This is done by the compiler normally. In my case I have to do it manually.

    Well done.

  • Ooops....

    In fact the MAP file is right, but I used the address given by µVision debugger.

    But now I understand what happened and all is OK.
    Thanks a lot.

  • Thanks a lot T Max,

    you got it.

    Actually, I got it first ;-P

    There was indeed no thumb bit in your pointer in the first place, so nothing to get lost.