Short Stack info macro

Discussion to talk about software related topics only.
Post Reply
User avatar
dciliske
Posts: 623
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Short Stack info macro

Post by dciliske »

Here's a short little Stack info macro I wrote while working on TLS. It requires that Stack checking is turned on in UCOS.

It reports,
  • Top of current stack
  • Current stack pointer
  • Space remaining in stack
  • Bottom of the stack

Code: Select all

#include <ucos.h>
char * GetSP_ext()
{
    asm( ".global GetSP");
    asm( "GetSP:");
    asm( "  move.l %sp, %d0");
    asm( "  rts");
}
#define SHOW_STACK_DEPTH() \
{\
    iprintf("Stack at line %d of file %s.\n", __LINE__, __FILE__);\
    iprintf("Top        -- Current    --   Rem   -- Bottom\n%p -- %p -- %7d-- %p\n", \
            OSTCBCur->OSTCBStkTop, GetSP(), GetSP() - (char *)OSTCBCur->OSTCBStkBot, OSTCBCur->OSTCBStkBot);\
}
-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
Post Reply