@@ -920,25 +920,33 @@ __asm(".global __use_no_semihosting\n\t");
920
920
#endif
921
921
#endif
922
922
923
- #if !defined(HEAP_START)
923
+ // Through weak-reference, we can check if ARM_LIB_HEAP is defined at run-time.
924
+ // If ARM_LIB_HEAP is defined, we can fix heap allocation.
925
+ extern MBED_WEAK uint32_t Image$$ARM_LIB_HEAP$$ZI$$Base[];
926
+ extern MBED_WEAK uint32_t Image$$ARM_LIB_HEAP$$ZI$$Length[];
927
+ extern MBED_WEAK uint32_t Image$$ARM_LIB_HEAP$$ZI$$Limit[];
928
+
924
929
// Heap here is considered starting after ZI ends to Stack start
925
930
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
926
931
extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[];
927
- #define HEAP_START Image$$RW_IRAM1$$ZI$$Limit
928
- #define HEAP_SIZE ((uint32_t )((uint32_t ) Image$$ARM_LIB_STACK$$ZI$$Base - (uint32_t ) HEAP_START))
929
- #endif
930
-
931
- #define HEAP_LIMIT ((uint32_t )((uint32_t )HEAP_START + (uint32_t )HEAP_SIZE))
932
932
933
933
extern " C" MBED_WEAK __value_in_regs struct __initial_stackheap _mbed_user_setup_stackheap (uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3)
934
934
{
935
- uint32_t heap_base = (uint32_t )HEAP_START;
935
+ // Define heap by assuming one-region
936
+ uint32_t heap_base = (uint32_t )Image$$RW_IRAM1$$ZI$$Limit;
937
+ uint32_t heap_limit = (uint32_t )Image$$ARM_LIB_STACK$$ZI$$Base;
936
938
struct __initial_stackheap r;
937
939
940
+ // Fix heap if ARM_LIB_HEAP is defined
941
+ if (Image$$ARM_LIB_HEAP$$ZI$$Length) {
942
+ heap_base = (uint32_t ) Image$$ARM_LIB_HEAP$$ZI$$Base;
943
+ heap_limit = (uint32_t ) Image$$ARM_LIB_HEAP$$ZI$$Limit;
944
+ }
945
+
938
946
// Ensure heap_base is 8-byte aligned
939
947
heap_base = (heap_base + 7 ) & ~0x7 ;
940
- r.heap_base = ( uint32_t ) heap_base;
941
- r.heap_limit = ( uint32_t )HEAP_LIMIT ;
948
+ r.heap_base = heap_base;
949
+ r.heap_limit = heap_limit ;
942
950
943
951
return r;
944
952
}
@@ -948,7 +956,17 @@ extern "C" __value_in_regs struct __argc_argv $Super$$__rt_lib_init(unsigned hea
948
956
949
957
extern " C" __value_in_regs struct __argc_argv $Sub$$__rt_lib_init(unsigned heapbase, unsigned heaptop)
950
958
{
951
- return $Super$$__rt_lib_init ((unsigned )HEAP_START, (unsigned )HEAP_LIMIT);
959
+ // Define heap by assuming one-region
960
+ uint32_t heap_base = (uint32_t )Image$$RW_IRAM1$$ZI$$Limit;
961
+ uint32_t heap_limit = (uint32_t )Image$$ARM_LIB_STACK$$ZI$$Base;
962
+
963
+ // Fix heap if ARM_LIB_HEAP is defined
964
+ if (Image$$ARM_LIB_HEAP$$ZI$$Length) {
965
+ heap_base = (uint32_t ) Image$$ARM_LIB_HEAP$$ZI$$Base;
966
+ heap_limit = (uint32_t ) Image$$ARM_LIB_HEAP$$ZI$$Limit;
967
+ }
968
+
969
+ return $Super$$__rt_lib_init ((unsigned )heap_base, (unsigned )heap_limit);
952
970
}
953
971
#endif
954
972
0 commit comments