Saving the stack pointer

Language Environment® provides two fields, CEECAA_SAVSTACK and CEECAA_SAVSTACK_ASYNC, where the stack pointer can be saved.

For either field, when the stack pointer does not point to the stack, the user code must not use Language Environment interfaces, nor invoke a routine that uses Language Environment interfaces. This includes implicitly referencing a DLL.

CEECAA_SAVSTACK
This field can be used by an application or a compiler to save the stack pointer before calling a routine by using OS_NOSTACK linkage. After the call returns, the CEECAA_SAVSTACK field must be set back to zero.

The value in CEECAA_SAVSTACK is used as the current stack frame in the following conditions:

  1. The Language Environment ESPIE exit routine, ESTAE exit routine, or signal interface routine (SIR) gets control.
  2. The value in CEECAA_SAVSTACK is not zero.

For asynchronous signal processing, typically the interrupt PSW is outside the routine that owns the stack frame and the signal is put back.

The c macro __LE_SAVSTACK_ADDR, which is defined in the sample header file, <edcwccwi.h>, is the address of the CEECAA_SAVSTACK field.

CEECAA_SAVSTACK_ASYNC
This field can be used by applications that have large sections of code that does not require access to the Language Environment stack but can benefit from having an additional register available. The CEECAA_SAVSTACK_ASYNC field is a pointer to the field where the stack pointer will be saved. Language Environment initializes CEECAA_SAVSTACK_ASYNC to zero. The application needs to set up the field where the stack pointer will be saved and store the address of that field in CEECAA_SAVSTACK_ASYNC. The storage for the field must be in the application key and persist for the life of the thread.

When the application sets CEECAA_SAVSTACK_ASYNC, appropriate action needs to be taken if CEECAA_SAVSTACK_ASYNC is not zero. Because it is possible to directly access the field where the stack pointer will be stored, consider the consequences if some part of the application is doing so.

Whenever the Language Environment stack is being used, either CEECAA_SAVSTACK_ASYNC must be zero or the field pointed to by CEECAA_SAVSTACK_ASYNC must be zero.

The value in the field pointed to by CEECAA_SAVSTACK_ASYNC is used as the current stack frame in the following conditions:

  1. The Language Environment ESPIE exit routine, ESTAE exit routine, or signal interface routine (SIR) gets control.
  2. CEECAA_SAVSTACK_ASYNC is not zero.
  3. The value in the field pointed to by CEECAA_SAVSTACK_ASYNC is not zero.

For asynchronous signal processing, the signal is always handled as if the interrupt PSW was inside the routine that owns the stack frame.

The c macro __LE_SAVSTACK_ASYNC_ADDR defined in sample header file <edcwccwi.h> is the address of the CEECAA_SAVSTACK_ASYNC field.