Skip to content

Commit fb6aa3e

Browse files
committed
Clean up ARM toolchain heap+stack setup in targets
ARM Compiler 6.13 testing revealed linker errors pointing out conflicting use of `__user_setup_stackheap` and `__user_initial_stackheap` in some targets. Remove the unwanted `__user_initial_stackheap` from the targets - the setup is centralised in the common platform code. Looking into this, a number of other issues were highlighted * Almost all targets had `__initial_sp` hardcoded in assembler, rather than getting it from the scatter file. This was behind issue #11313. Fix this generally. * A few targets' `__initial_sp` values did not match the scatter file layout, in some cases meaning they were overlapping heap space. They now all use the area reserved in the scatter file. If any problems are seen, then there is an error in the scatter file. * A number of targets were reserving unneeded space for heap and stack in their startup assembler, on top of the space reserved in the scatter file, so wasting a few K. A couple were using that space for the stack, rather than the space in the scatter file. To clarify expected behaviour: * Each scatter file contains empty regions `ARM_LIB_HEAP` and `ARM_LIB_STACK` to reserve space. `ARM_LIB_STACK` is sized by the macro `MBED_BOOT_STACK_SIZE`, which is set by the tools. `ARM_LIB_HEAP` is generally the space left over after static RAM and stack. * The address of the end of `ARM_LIB_STACK` is written into the vector table and on reset the CPU sets MSP to that address. * The common platform code in Mbed OS provides `__user_setup_stackheap` for the ARM library. The ARM library calls this during startup, and it calls `__mbed_user_setup_stackheap`. * The default weak definition of `__mbed_user_setup_stackheap` does not modify SP, so we remain on the boot stack, and the heap is set to the region described by `ARM_LIB_HEAP`. If `ARM_LIB_HEAP` doesn't exist, then the heap is the space from the end of the used data in `RW_IRAM1` to the start of `ARM_LIB_STACK`. * Targets can override `__mbed_user_setup_stackheap` if they want. Currently only Renesas (ARMv7-A class) devices do. * If microlib is in use, then it doesn't call `__user_setup_stackheap`. Instead it just finds and uses `ARM_LIB_STACK` and `ARM_LIB_HEAP` itself.
1 parent 1dac871 commit fb6aa3e

File tree

260 files changed

+536
-2223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+536
-2223
lines changed

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
;
3636
;******************************************************************************
3737

38-
#include "../memory_zones.h"
39-
40-
__initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
41-
4238
PRESERVE8
4339
THUMB
4440

@@ -48,8 +44,9 @@ __initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4844
EXPORT __Vectors
4945
EXPORT __Vectors_End
5046
EXPORT __Vectors_Size
47+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
5148

52-
__Vectors DCD __initial_sp ; Top of Stack
49+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
5350
DCD Reset_Handler ; Reset Handler
5451
DCD NMI_Handler ; NMI Handler
5552
DCD HardFault_Handler ; Hard Fault Handler

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
;
3636
;******************************************************************************
3737

38-
#include "../memory_zones.h"
39-
40-
__initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
41-
4238
PRESERVE8
4339
THUMB
4440

@@ -48,8 +44,9 @@ __initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4844
EXPORT __Vectors
4945
EXPORT __Vectors_End
5046
EXPORT __Vectors_Size
47+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
5148

52-
__Vectors DCD __initial_sp ; Top of Stack
49+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
5350
DCD Reset_Handler ; Reset Handler
5451
DCD NMI_Handler ; NMI Handler
5552
DCD HardFault_Handler ; Hard Fault Handler

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M3/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
;
3636
;******************************************************************************
3737

38-
#include "../memory_zones.h"
39-
40-
__initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
41-
4238
PRESERVE8
4339
THUMB
4440

@@ -48,8 +44,9 @@ __initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4844
EXPORT __Vectors
4945
EXPORT __Vectors_End
5046
EXPORT __Vectors_Size
47+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
5148

52-
__Vectors DCD __initial_sp ; Top of Stack
49+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
5350
DCD Reset_Handler ; Reset Handler
5451
DCD NMI_Handler ; NMI Handler
5552
DCD HardFault_Handler ; Hard Fault Handler

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M4/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
;
3636
;******************************************************************************
3737

38-
#include "../memory_zones.h"
39-
40-
__initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
41-
4238
PRESERVE8
4339
THUMB
4440

@@ -48,8 +44,9 @@ __initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4844
EXPORT __Vectors
4945
EXPORT __Vectors_End
5046
EXPORT __Vectors_Size
47+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
5148

52-
__Vectors DCD __initial_sp ; Top of Stack
49+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
5350
DCD Reset_Handler ; Reset Handler
5451
DCD NMI_Handler ; NMI Handler
5552
DCD HardFault_Handler ; Hard Fault Handler

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M7/device/TOOLCHAIN_ARM_STD/startup_CMSDK_CM7.S

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
;
3636
;******************************************************************************
3737

38-
#include "../memory_zones.h"
39-
40-
__initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
41-
4238
PRESERVE8
4339
THUMB
4440

@@ -48,8 +44,9 @@ __initial_sp EQU ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4844
EXPORT __Vectors
4945
EXPORT __Vectors_End
5046
EXPORT __Vectors_Size
47+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
5148

52-
__Vectors DCD __initial_sp ; Top of Stack
49+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
5350
DCD Reset_Handler ; Reset Handler
5451
DCD NMI_Handler ; NMI Handler
5552
DCD HardFault_Handler ; Hard Fault Handler

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
* This file is derivative of CMSIS V5.00 startup_ARMCM3.s
2323
*/
2424

25-
#include "../memory_zones.h"
26-
27-
__initial_sp EQU ZBT_SSRAM23_START + ZBT_SSRAM23_SIZE ; Top of ZBT SSRAM2 and 3, used for data
28-
2925
PRESERVE8
3026
THUMB
3127

@@ -36,8 +32,9 @@ __initial_sp EQU ZBT_SSRAM23_START + ZBT_SSRAM23_SIZE ; Top of ZBT SSRAM2
3632
EXPORT __Vectors
3733
EXPORT __Vectors_End
3834
EXPORT __Vectors_Size
35+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
3936

40-
__Vectors DCD __initial_sp ; Top of Stack
37+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
4138
DCD Reset_Handler ; Reset Handler
4239
DCD NMI_Handler ; NMI Handler
4340
DCD HardFault_Handler ; Hard Fault Handler

targets/TARGET_ARM_SSG/TARGET_IOTSS/TARGET_IOTSS_BEID/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,6 @@
3434
; CMSDK_BEID Device
3535
;
3636
;******************************************************************************
37-
;
38-
;-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
39-
;
40-
41-
42-
; <h> Stack Configuration
43-
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
44-
; </h>
45-
46-
Stack_Size EQU 0x00004000
47-
48-
AREA STACK, NOINIT, READWRITE, ALIGN=3
49-
Stack_Mem SPACE Stack_Size
50-
__initial_sp
51-
52-
53-
; <h> Heap Configuration
54-
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
55-
; </h>
56-
57-
Heap_Size EQU 0x00001000
58-
59-
AREA HEAP, NOINIT, READWRITE, ALIGN=3
60-
__heap_base
61-
Heap_Mem SPACE Heap_Size
62-
__heap_limit
6337

6438

6539
PRESERVE8
@@ -72,8 +46,9 @@ __heap_limit
7246
EXPORT __Vectors
7347
EXPORT __Vectors_End
7448
EXPORT __Vectors_Size
49+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
7550

76-
__Vectors DCD __initial_sp ; Top of Stack
51+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
7752
DCD Reset_Handler ; Reset Handler
7853
DCD NMI_Handler ; NMI Handler
7954
DCD HardFault_Handler ; Hard Fault Handler
@@ -329,30 +304,4 @@ MPS2_SPI4_IRQHandler
329304
ALIGN
330305

331306

332-
; User Initial Stack & Heap
333-
334-
IF :DEF:__MICROLIB
335-
336-
EXPORT __initial_sp
337-
EXPORT __heap_base
338-
EXPORT __heap_limit
339-
340-
ELSE
341-
342-
IMPORT __use_two_region_memory
343-
EXPORT __user_initial_stackheap
344-
345-
__user_initial_stackheap PROC
346-
LDR R0, = Heap_Mem
347-
LDR R1, =(Stack_Mem + Stack_Size)
348-
LDR R2, = (Heap_Mem + Heap_Size)
349-
LDR R3, = Stack_Mem
350-
BX LR
351-
ENDP
352-
353-
ALIGN
354-
355-
ENDIF
356-
357-
358307
END

targets/TARGET_ARM_SSG/TARGET_MPS2/TARGET_MPS2_M0/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,6 @@
3434
; CMSDK_CM0 Device
3535
;
3636
;******************************************************************************
37-
;
38-
;-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
39-
;
40-
41-
; <h> Heap Configuration
42-
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
43-
; </h>
44-
45-
Heap_Size EQU 0x00000400
46-
47-
AREA HEAP, NOINIT, READWRITE, ALIGN=3
48-
__heap_base
49-
Heap_Mem SPACE Heap_Size
50-
__heap_limit
51-
52-
; <h> Stack Configuration
53-
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
54-
; </h>
55-
56-
Stack_Size EQU 0x00001000
57-
58-
AREA STACK, NOINIT, READWRITE, ALIGN=3
59-
Stack_Mem SPACE Stack_Size
60-
61-
__initial_sp EQU 0x20400000
6237

6338
PRESERVE8
6439
THUMB
@@ -70,8 +45,9 @@ __initial_sp EQU 0x20400000
7045
EXPORT __Vectors
7146
EXPORT __Vectors_End
7247
EXPORT __Vectors_Size
48+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
7349

74-
__Vectors DCD __initial_sp ; Top of Stack
50+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
7551
DCD Reset_Handler ; Reset Handler
7652
DCD NMI_Handler ; NMI Handler
7753
DCD HardFault_Handler ; Hard Fault Handler
@@ -239,30 +215,4 @@ PORT0_7_Handler
239215
ALIGN
240216

241217

242-
; User Initial Stack & Heap
243-
244-
IF :DEF:__MICROLIB
245-
246-
EXPORT __initial_sp
247-
EXPORT __heap_base
248-
EXPORT __heap_limit
249-
250-
ELSE
251-
252-
IMPORT __use_two_region_memory
253-
EXPORT __user_initial_stackheap
254-
255-
__user_initial_stackheap PROC
256-
LDR R0, = Heap_Mem
257-
LDR R1, =(Stack_Mem + Stack_Size)
258-
LDR R2, = (Heap_Mem + Heap_Size)
259-
LDR R3, = Stack_Mem
260-
BX LR
261-
ENDP
262-
263-
ALIGN
264-
265-
ENDIF
266-
267-
268218
END

targets/TARGET_ARM_SSG/TARGET_MPS2/TARGET_MPS2_M0P/device/TOOLCHAIN_ARM_STD/startup_MPS2.S

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,6 @@
3434
; CMSDK_CM0P Device
3535
;
3636
;******************************************************************************
37-
;
38-
;-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
39-
;
40-
41-
; <h> Heap Configuration
42-
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
43-
; </h>
44-
45-
Heap_Size EQU 0x00000400
46-
47-
AREA HEAP, NOINIT, READWRITE, ALIGN=3
48-
__heap_base
49-
Heap_Mem SPACE Heap_Size
50-
__heap_limit
51-
52-
; <h> Stack Configuration
53-
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
54-
; </h>
55-
56-
Stack_Size EQU 0x00001000
57-
58-
AREA STACK, NOINIT, READWRITE, ALIGN=3
59-
Stack_Mem SPACE Stack_Size
60-
61-
__initial_sp EQU 0x20400000
6237

6338
PRESERVE8
6439
THUMB
@@ -70,8 +45,9 @@ __initial_sp EQU 0x20400000
7045
EXPORT __Vectors
7146
EXPORT __Vectors_End
7247
EXPORT __Vectors_Size
48+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
7349

74-
__Vectors DCD __initial_sp ; Top of Stack
50+
__Vectors DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack
7551
DCD Reset_Handler ; Reset Handler
7652
DCD NMI_Handler ; NMI Handler
7753
DCD HardFault_Handler ; Hard Fault Handler
@@ -239,30 +215,4 @@ PORT0_7_Handler
239215
ALIGN
240216

241217

242-
; User Initial Stack & Heap
243-
244-
IF :DEF:__MICROLIB
245-
246-
EXPORT __initial_sp
247-
EXPORT __heap_base
248-
EXPORT __heap_limit
249-
250-
ELSE
251-
252-
IMPORT __use_two_region_memory
253-
EXPORT __user_initial_stackheap
254-
255-
__user_initial_stackheap PROC
256-
LDR R0, = Heap_Mem
257-
LDR R1, =(Stack_Mem + Stack_Size)
258-
LDR R2, = (Heap_Mem + Heap_Size)
259-
LDR R3, = Stack_Mem
260-
BX LR
261-
ENDP
262-
263-
ALIGN
264-
265-
ENDIF
266-
267-
268218
END

0 commit comments

Comments
 (0)