Set up the Stack
Set up the Stack
The Stack
The Stack
The C/C++ compiler uses a
The C/C++ compiler uses a
stack to:
stack to:
Allocate local variables
Allocate local variables
Pass arguments to
Pass arguments to
functions
functions
Save the processor status
Save the processor status
Save the function return
Save the function return
address
address
Save temporary results
Save temporary results
The compiler uses the hardware
The compiler uses the hardware
stack pointer (SP) to
stack pointer (SP) to
manage the stack.
manage the stack.
SP defaults to 0x400 at reset.
SP defaults to 0x400 at reset.
The run
The run
-
-
time stack grows from
time stack grows from
low addresses to higher
low addresses to higher
addresses.
addresses.
Data Memory
Data Memory
64K
64K
0x400
0x400
SP
SP
(reset)
(reset)
.stack
.stack
4M
4M
Caller’s
Caller’s
local
local
vars
vars
Arguments
Arguments
passed on
passed on
stack
stack
Return
Return
address
address
Function
Function
return
return
addr
addr
Temp results
Temp results
The C28x has a 16-bit stack pointer (SP) allowing accesses to the base 64K of memory. The stack
grows from low to high memory and always points to the first
unused
location. The compiler
uses the hardware stack pointer (SP) to manage the stack. The stack size is set by the linker.
Setting Up the Stack
Setting Up the Stack
Boot.
Boot.
asm
asm
sets up SP to
sets up SP to
point at .stack
point at .stack
The .stack section has to
The .stack section has to
be linked into the low 64k
be linked into the low 64k
of data memory. The SP is
of data memory. The SP is
a 16
a 16
-
-
bit register and cannot
bit register and cannot
access addresses beyond
access addresses beyond
64K.
64K.
Stack size is set by the
Stack size is set by the
linker. The linker creates a
linker. The linker creates a
global symbol,
global symbol,
--
--
STACK
STACK
-
-
SIZE, and assigns
SIZE, and assigns
it a value equal to the size
it a value equal to the size
of the stack in bytes.
of the stack in bytes.
(default 1K words)
(default 1K words)
You can change stack size
You can change stack size
at link time by using the
at link time by using the
-
-
stack linker command
stack linker command
option.
option.
Linker command file:
Linker command file:
SECTIONS {
SECTIONS {
.stack :>
.stack :>
RAM
RAM
align=2
align=2
... }
... }
Note: The compiler provides no
Note: The compiler provides no
means to check for stack
means to check for stack
overflow during compilation or at
overflow during compilation or at
runtime. A stack overflow
runtime. A stack overflow
disrupts the run
disrupts the run
-
-
time
time
environment, causing your
environment, causing your
program to fail. Be sure to allow
program to fail. Be sure to allow
enough space for the stack to
enough space for the stack to
grow.
grow.
In order to allocate the stack the linker command file needs to have “align = 2.”
D- 4
C28x – C Programming
Summary of Contents for C28 Series
Page 64: ...Summary 3 16 C28x Peripheral Registers Header Files ...
Page 78: ...Interrupt Sources 4 14 C28x Reset and Interrupts ...
Page 218: ...Lab 9 DSP BIOS 9 22 C28x Using DSP BIOS ...
Page 244: ...Lab 10 Programming the Flash 10 26 C28x System Design ...
Page 273: ...Appendix A eZdsp F2812 C28x Appendix A eZdsp F2812 A 1 ...
Page 276: ...Appendix P2 Expansion Interface A 4 C28x Appendix A eZdsp F2812 ...
Page 277: ...Appendix P4 P8 P7 I O Interface C28x Appendix A eZdsp F2812 A 5 ...
Page 278: ...Appendix A 6 C28x Appendix A eZdsp F2812 ...
Page 279: ...Appendix P5 P9 Analog Interface C28x Appendix A eZdsp F2812 A 7 ...
Page 282: ...Appendix A 10 C28x Appendix A eZdsp F2812 TP1 TP2 Test Points ...