SLUAAP6 September 2023 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138128A , UCD3138A , UCD3138A64
There are generally four stacks used in demo codes: user stack, IRQ stack, FIQ stack and supervisor stack. User stack is for background routines, IRQ stack is for standard interrupt routines, FIQ stack is for fast interrupt routines, and supervisor stack is for software interrupt (SWI) routines. Some can have undefined stack and abort stack for exceptions, but they are rarely used in normal cases. The stacks are declared at the top of the load.asm file. Take the following as an example to see how each stack is allocated.
SUP_STACK_TOP .equ 0x6bffc ;Supervisor mode (SWI stack) starts at top of memory
FIQ_STACK_TOP .equ 0x6be00 ;allocate 256 bytes to supervisor stack, then do FIQ stack
IRQ_STACK_TOP .equ 0x6bd00 ;allocate 256 bytes to fiq stack, then start irq stack
USER_STACK_TOP .equ 0x6bb00 ;Allocate 512 bytes to irq stack, regular stack gets rest, down to variables
.global _c_int00
.global $c_int00
With those definitions, this shows that the top of user stack is at address 0x6bb00 and down to variables, IRQ stack is allocated from address 0x6bb00 (bottom) to 0x6bd00 (top), FIQ stack is allocated from address 0x6bd00 (bottom) to 0x6be00 (top), and supervisor stack is allocated from address 0x6be00 (bottom) to 0x6bffc (top).
As for the bottom of user stack, check the .map file, which shows the RAM memory allocation. The .map file is generated by CCS when building the firmware project, and shall be located in the same directory as .x0 file. Following is an example copied from a .map file, and the text shows the variables starts from address 0x6a000 and ends at 0x6a80d. Therefore, the user stack can be down to 0x6a80e.
name origin length used unused attr fill
---------------------- -------- --------- -------- -------- ---- --------
FLASHVECS 00000000 00000020 00000020 00000000 R X
PFLASH 00000020 00007f34 00003d1e 00004216 R X
DEVICEID 00007f54 00000020 0000001f 00000001 R X
FIXTFA 00007f74 00000004 00000000 00000004 R X
FIXCONST 00007f78 00000080 00000000 00000080 R X
FLASHSUM 00007ff8 00000008 00000000 00000008 R X
ROMVECS 00020000 00000020 00000000 00000020 RWIX
ROM 00020020 00001d5e 00000000 00001d5e RWIX
SINE 00021d7e 00000282 00000000 00000282 RWIX
DFLASH 00069800 00000800 00000398 00000468 R X
RAM 0006a000 00001dd0 0000080d 000015c3 RW
RAM_PGM_AREA 0006bdd0 00000080 00000000 00000080 RW
STACKS 0006be50 000001b0 00000000 000001b0 RW
LOOP_MUX 00120000 00000070 0000006c 00000004 RWIX
In some demo codes, there is stack allocation in the .cmd file, in the following. The stack allocation does not take effect, stack allocation is actually done in load.asm.
STACKS (RW) : org = 0x0006BE50, len = 0x000001B0
.stack : { /* total = 400 = 0x190 */
_StackUSER_ = . + 184; /* USER */
_StackFIQ_ = _StackUSER_ + 112; /* FIQ */
_StackIRQ_ = _StackFIQ_ + 84; /* IRQ */
_StackABORT_ = _StackIRQ_ + 4; /* ABORT */
_StackUND_ = _StackABORT_ + 4; /* UND */
_StackSUPER_ = _StackUND_ + 12; /* SUPER */
} > STACKS /* Software System stack */.