User guide

38 DC 900-1338I
Protocol Software Toolkit Programmer Guide
In user state, the USP is the current stack pointer. In supervisor state, the ISP (usually
called the system stack pointer, or SSP) is current. The current stack pointer is swapped
automatically by the processor into general register A7 when the privilege level changes,
so that register A7 is always used as the stack pointer, regardless of the processors state.
A stack pointer is pre-decremented when an element is added to the stack (pushed) and
post-incremented when an element is removed (popped). Stacks therefore grow from
higher to lower memory addresses, and the stack pointer always contains the address of
the element currently at the top of the stack.
During its initialization, OS/Impact allocates space for the system stack and initializes
the SSP. The system stack is used whenever the processor is in supervisor state. This
includes system calls and all interrupt service routines, including those associated with
user applications.
You must allocate stack space for each application task you create and specify the initial
stack pointer in the task initialization structure (see Section 4.2.2 on page 72). The ini-
tial stack pointer should be specified as the ending address of the stack space plus one.
For example, if a tasks stack space is 0x40016000 through 0x400163FF, the initial stack
pointer should be specified as 0x40016400. OS/Impact saves this initial value in the task
control block as the current stack pointer. When the task is dispatched, OS/Impact ini-
tializes the USP to the stack address saved in the task control block. When the task is
preempted, the tasks state (the contents of the general registers) is saved on its stack
and the current USP is again saved in the task control block.
When allocating a tasks stack, you must consider the space required at the deepest level
of nested subroutine calls, and allow 66 bytes for the registers saved when the task is
preempted. You need not allocate additional stack space for interrupt service routines,
as the USP is not used for interrupt processing.