Keil Logo

STACK Linker Directive

Abbreviation

ST

Arguments

STACK (segment 〚(address)〛 〚, ...〛)

Default

None.

µVision

Options — BL51 Locate — Stack Segments.

Description

The STACK directive locates segments in the uppermost IDATA memory space that is typically reserved for the hardware stack.

This directive is specified as follows:

STACK (segment 〚(address)〛 〚, ...〛)

Where

segment is the name of a segment.
address is a physical address at which the segment is to be located. If the address is not specified, the segment is located prior to the stack. If the address is specified, the segment is located at that address. If the stack is not specifically located using the STACK directive, it is located after the last segment specified with the STACK directive.

Typical target programs locate the stack at the top of IDATA memory starting immediately after the list IDATA or DATA variable and ending at the last byte of IDATA. The stack is identified as the ?STACK segment. The stack pointer is initialized by the Startup Code to point to the beginning of this segment.

As the target program executes, return addresses and data that are pushed on the stack are stored in the ?STACK memory area. Segments you locate after the ?STACK segment could be overwritten by stack accesses or could overwrite return addresses that have been pushed onto the stack.

Note

  • Use of the STACK directive to locate the ?STACK segment is typically not required.
  • The STACK directive is typically used with assembly programs that have several stack segments.
  • Use extreme caution when using the STACK directive. Improper use may result in a target program that crashes or that corrupts DATA and IDATA variables.
  • The BL51 Linker allows you to use wildcards when locating program segments. For example, ?PR?*?MYFILE may be used to represent all program segments from the MYFILE source file.
See Also

BIT, CODE, DATA, IDATA, PDATA, PRECEDE, RAMSIZE, XDATA

Example

By default, the compiler and linker work together to locate the stack at the end of IDATA memory. For example:

LINK MAP OF MODULE:  Measure (MEASURE)

TYPE    BASE      LENGTH    RELOCATION   SEGMENT NAME
-----------------------------------------------------
* * * * * * *   D A T A   M E M O R Y   * * * * * * *
REG     0000H     0008H     ABSOLUTE     "REG BANK 0"
REG     0008H     0008H     ABSOLUTE     "REG BANK 1"
DATA    0010H     0001H     UNIT         ?DT?GETCHAR
IDATA   0011H     000FH     UNIT         _IDATA_GROUP_
.
.
.
IDATA   0066H     0010H     UNIT         ?ID?MEASURE
IDATA   0076H     0003H     UNIT         ?ID?MCOMMAND
IDATA   0079H     0001H     UNIT         ?STACK

The STACK directive may be used to relocate the ?ID?MEASURE segment at the top of IDATA just before the stack. For example:

BL51 ... STACK(?ID?MEASURE)

Causes the following memory map changes.

LINK MAP OF MODULE:  Measure (MEASURE)

TYPE    BASE      LENGTH    RELOCATION   SEGMENT NAME
-----------------------------------------------------
* * * * * * *   D A T A   M E M O R Y   * * * * * * *
REG     0000H     0008H     ABSOLUTE     "REG BANK 0"
REG     0008H     0008H     ABSOLUTE     "REG BANK 1"
DATA    0010H     0001H     UNIT         ?DT?GETCHAR
IDATA   0011H     000FH     UNIT         _IDATA_GROUP_
.
.
.
IDATA   0066H     0003H     UNIT         ?ID?MCOMMAND
IDATA   0069H     0010H     UNIT         ?ID?MEASURE
IDATA   0079H     0001H     UNIT         ?STACK

The STACK directive may be used to relocate the ?ID?MEASURE segment at the very top of memory. For example:

BL51 ... STACK(?STACK(069h),?ID?MEASURE(0F0h))

Causes the following memory map changes.

LINK MAP OF MODULE:  Measure (MEASURE)

TYPE    BASE      LENGTH    RELOCATION   SEGMENT NAME
-----------------------------------------------------
* * * * * * *   D A T A   M E M O R Y   * * * * * * *
REG     0000H     0008H     ABSOLUTE     "REG BANK 0"
REG     0008H     0008H     ABSOLUTE     "REG BANK 1"
DATA    0010H     0001H     UNIT         ?DT?GETCHAR
IDATA   0011H     000FH     UNIT         _IDATA_GROUP_
.
.
.
IDATA   0066H     0003H     UNIT         ?ID?MCOMMAND
IDATA   0069H     0001H     UNIT         ?STACK
        006AH     0086H                  *** GAP ***
IDATA   00F0H     0010H     UNIT         ?ID?MEASURE
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.