We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hallo
I wonder if there are any good methodes of calculating the stack size for ex user or IRQ stack size? Is there any "best practice"?
Or is it just add up the size of data structures and/ot ISR's??
/Thomas
I just did some simple/stupid tests trying to understand something about "REQUIRE8 and PRESERVE8 and 'align and grow the stack in 8-byte'"
1. In the LPC2300.s, I set the IRQ_Stack_Size to 0x00000104 (260), and add a PRESERVE8 to this LPC2300.s file, it can still be compiled without any errors and warnings. So, I guess, PRESERVE8 will not do anything for the programmer (For example: check the stack/variable size).
2. I add a REQUIRE8 to the LPC2300.s, it can still be compiled, but I get some warnings:
source\LPC2300.s(887): warning: A1549W: Setting of REQUIRE8 but not PRESERVE8 is unusual
unusual???
linking... .\object\Product-01.axf: Warning: L6306W: '~PRES8' section lpc2300.o(RESET) should not use the address of 'REQ8' function Reset_Handler. .\object\Product-01.axf: Warning: L6306W: '~PRES8' section lpc2300.o(RESET) should not use the address of 'REQ8' function Undef_Handler. .\object\Product-01.axf: Warning: L6306W: '~PRES8' section lpc2300.o(RESET) should not use the address of 'REQ8' function PAbt_Handler. .\object\Product-01.axf: Warning: L6306W: '~PRES8' section lpc2300.o(RESET) should not use the address of 'REQ8' function DAbt_Handler. .\object\Product-01.axf: Warning: L6306W: '~PRES8' section lpc2300.o(RESET) should not use the address of 'REQ8' function IRQ_Handler. .\object\Product-01.axf: Warning: L6306W: '~PRES8' section lpc2300.o(RESET) should not use the address of 'REQ8' function FIQ_Handler.
So, I guess, even the KEIL's library does not align and grow the stack in 8-byte steps for the ARM processor.
From project.map:
lpc2300.o(RESET) refers to SWI_RTX.o(SWI_RTX) for SWI_Handler lpc2300.o(RESET) refers to lpc2300.o(STACK) for Stack_Top lpc2300.o(RESET) refers to __main.o(!!!main) for __main lpc2300.o(RESET) refers (Special) to stkheap2.o(.text) for __use_two_region_memory
John,
Have a look here:
"L6238E: <objname>(<secname>) contains invalid call from '<attr1>' function to '<attr2>' function <sym>. This linker error is given where a stack alignment conflict is detected in object code. The "ABI for the ARM Architecture" demands that code maintains 8-byte stack alignment at its interfaces. This allows efficient use of LDRD and STRD instructions (in ARM Architecture 5TE and later) to access 8-byte-aligned "double" and "long long" data types. Symbols like '~PRES8' and 'REQ8' are "Build Attributes" of the objects. PRES8 means the object PREServes 8-byte alignment of the stack. ~PRES8 means the object does NOT preserve 8-byte alignment of the stack (~ meaning NOT). REQ8 means the object REQuires 8-byte alignment of the stack. This link error typically occurs in two cases: 1) where assembler code (that does not preserve 8-byte stack alignment) calls compiled C/C++ code (that requires 8-byte stack alignment). 2) when attempting to link legacy objects with RVCT 3.x objects. Legacy objects that do not have these attributes are treated as '~PRES8', even if they do actually happen to preserve 8-byte alignment. For example: Error: L6238E: foo.o(.text) contains invalid call from '~PRES8' function to 'REQ8' function foobar This means that there is a function in the object foo.o (in the section named .text) that does not preserve 8-byte stack alignment, but which is trying to call function foobar that requires 8-byte stack alignment. A similar warning that may be encountered is: Warning: L6306W: '~PRES8' section foo.o(.text) should not use the address of 'REQ8' function foobar where the address of an external symbol is being referred to. There are two possible solutions to work-around this issue: 1) Rebuild all your objects/libraries using RVCT 3.x. If you have any assembler files, you will need to check that all instructions preserve 8-byte stack alignment, and if necessary, correct them. e.g. change: STMFD sp!, {r0-r3, lr} ; push an odd number of registers to STMFD sp!, {r0-r3, r12, lr} ; push an even number of registers The assembler will automatically mark the object with the PRES8 attribute if all instructions preserve 8-byte stack alignment, so it is no longer necessary to add the PRESERVE8 directive to the top of each assembler file. 2) If you have any legacy objects/libraries that cannot be rebuilt, either because you do not have the source code, or because the old objects must not be rebuilt (e.g. for qualification/certification reasons), then you must inspect the legacy objects to check whether they preserve 8-byte alignment or not. Use "fromelf -c" to disassemble the object code. C/C++ code compiled with ADS 1.1 or later will normally preserve 8-byte alignment, but assembled code will not. If your objects do indeed preserve 8-byte alignment, then the linker error L6238E can be suppressed with the use of "--diag_suppress 6238" on the linker command line. By using this, you are effectively saying "I guarantee that these objects are PRES8". The linker warning L6306W is suppressible with "--diag_suppress 6306". More information about linking with legacy objects/libraries and the "--apcs /adsabi" is given at: ">www.arm.com/.../1242.html"