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.

Need to know DSP/BIOS 5.20 Task control structure, want to see where the PC was/is.

Expert 2875 points

Hi,

I would like to know where the PC was for a given task.

But the following structure does not have program counter.

struct KNL_Obj

{    

QUE_Elem    ready;          /* ready/semaphore queue elem */     
QUE_Elem    alarm;          /* alarm queue elem */     
QUE_Elem    setpri;         /* set priority queue elem */     
QUE_Handle  queue;          /* task's ready queue */     
Int         priority;       /* task priority */     
Uns         mask;           /* 1 << priority */     
Ptr         sp;             /* current stack pointer */     
Uns         timeout;        /* timeout value */     
Int         mode;           /* KNL_BLOCKED, KNL_READY,... */     
/*      *  This STS Object is used to measure the time from when the task is      
*  made ready, until the function TSK_deltatime() is called.  When the      
*  task is made ready, the STS object is "set" to the current time.      */      
STS_Obj     *sts;     Bool        signalled;      /* pending task waken up by sem or timeout */ 
}; 
 
Thank you for the help.
 
Regards,
Steve
  • Hi Steve --

    We don't save the program counter for a given thread since it would almost always be at the same place within the code that switches tasks.   The 'sp' points to the stack for a given task.  You can look at that stack in memory and try to decode the return address stack, but unfortunately, we don't have direct support for this today.

    -Karl-

  • Hi Karl,

    Thanks for the replay.   The stack contains the return address only if it saves the B3.  Usually the first return address on the stack is TWO levels up.  The currently return address is in B3.

    My question is:  when a thread is made ready, where does it get the address to start running?  The thread PC has to be saved somewhere.   Could it be on the system stack?

    I have a case a thread is not running any more and like to know where it got lost.

    Thank you.

    Regards,

    Steve

  • Any comments?

  • The PC for a task that has previously run but is currently NOT running will be at an internal symbol "label1" within the "_KNL_switch" function. When the task is made ready again, the kernel calls "KNL_switch" which pushes the current task's context on the current task's stack, saves the SP into that task object's sp field, then switches the SP to point to the new task's sp field, unwinds the stack and returns through the path that called KNL_switch in the new task thread.

    I hope this helps...

    Alan

  • Thanks for the help.  I did not find "label1" within the function.  But I found the PC.

  • I'm having the same need. It seems you found a solution. Could you share the final details? I also need the PC of where a task is executing and am looking at this at the time of a task swap.

    Thanks!

  • Carl,

    Run your program and try to follow Alan DeMar's post.  I believe he described it pretty thorough.  Put a breakpiont on the _KNL_switch symbol that he mentions.

    Judah