@@ -904,76 +904,59 @@ extern "C" long PREFIX(_flen)(FILEHANDLE fh)
904
904
return size;
905
905
}
906
906
907
- #if defined(TARGET_NUVOTON) || defined(TARGET_RZ_A1XX)
908
- extern char Image$$ARM_LIB_HEAP$$ZI$$Base[];
909
- extern char Image$$ARM_LIB_STACK$$ZI$$Base[];
910
- extern char Image$$ARM_LIB_HEAP$$ZI$$Limit[];
911
- #define HEAP_BASE (Image$$ARM_LIB_HEAP$$ZI$$Base)
912
- #define HEAP_LIMIT (Image$$ARM_LIB_HEAP$$ZI$$Limit)
913
- #define STACK_BASE (Image$$ARM_LIB_STACK$$ZI$$Base)
907
+ #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
908
+ __asm (" .global __use_two_region_memory\n\t " );
909
+ __asm (" .global __use_no_semihosting\n\t " );
914
910
#else
915
- extern char Image$$RW_IRAM1$$ZI$$Limit[];
916
- extern char Image$$ARM_LIB_STACK$$ZI$$Base[];
917
- #define HEAP_BASE (Image$$RW_IRAM1$$ZI$$Limit)
918
- #define HEAP_LIMIT (Image$$ARM_LIB_STACK$$ZI$$Base)
919
- #define STACK_BASE (Image$$ARM_LIB_STACK$$ZI$$Base)
911
+ #pragma import(__use_two_region_memory)
920
912
#endif
921
913
914
+ extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Length[];
915
+ extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
916
+
917
+ extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[];
918
+
919
+ extern uint32_t Image$$ARM_LIB_HEAP$$ZI$$Base[];
920
+ extern uint32_t Image$$ARM_LIB_HEAP$$ZI$$Length[];
921
+
922
+ #if !defined(ISR_STACK_SIZE)
923
+ #define ISR_STACK_START Image$$ARM_LIB_STACK$$ZI$$Base
924
+ #define ISR_STACK_SIZE Image$$ARM_LIB_STACK$$ZI$$Length
925
+ #endif
926
+
927
+ #if !defined(HEAP_START)
928
+ #if defined(Image$$ARM_LIB_HEAP$$ZI$$Base) && defined(Image$$ARM_LIB_HEAP$$ZI$$Length)
929
+ #define HEAP_START Image$$ARM_LIB_HEAP$$ZI$$Base
930
+ #define HEAP_SIZE Image$$ARM_LIB_HEAP$$ZI$$Length
931
+ #else
932
+ // Heap here is considered starting after ZI ends to Stack start
933
+ #define HEAP_START Image$$RW_IRAM1$$ZI$$Limit
934
+ #define HEAP_SIZE ((uint32_t )(ISR_STACK_START - HEAP_START))
935
+ #endif
936
+ #endif
937
+
938
+ #define HEAP_LIMIT (HEAP_START + HEAP_SIZE)
939
+
922
940
extern __value_in_regs struct __initial_stackheap _mbed_user_setup_stackheap (uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3)
923
941
{
924
942
struct __initial_stackheap r;
925
- r.heap_base = (uint32_t )HEAP_BASE ;
943
+ r.heap_base = (uint32_t )HEAP_START ;
926
944
r.heap_limit = (uint32_t )HEAP_LIMIT;
945
+
927
946
return r;
928
947
}
929
948
930
- #ifndef MBED_CONF_RTOS_PRESENT
931
-
932
- /* The single region memory model would check stack collision at run time, verifying that
933
- * the heap pointer is underneath the stack pointer. With two-region memory model/RTOS-less or
934
- * multiple threads(stacks)/RTOS, the check gets meaningless and we must disable it. */
935
- #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
936
- __asm (" .global __use_two_region_memory\n\t " );
937
- __asm (" .global __use_no_semihosting\n\t " );
938
- #else
939
- #pragma import(__use_two_region_memory)
940
- #endif
941
-
942
- /* Fix __user_setup_stackheap and ARM_LIB_STACK/ARM_LIB_HEAP cannot co-exist in RTOS-less build
943
- *
944
- * According AN241 (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0241b/index.html),
945
- * __rt_entry has the following call sequence:
946
- * 1. _platform_pre_stackheap_init
947
- * 2. __user_setup_stackheap or setup the Stack Pointer (SP) by another method
948
- * 3. _platform_post_stackheap_init
949
- * 4. __rt_lib_init
950
- * 5. _platform_post_lib_init
951
- * 6. main()
952
- * 7. exit()
953
- *
954
- * Per our check, when __user_setup_stackheap and ARM_LIB_STACK/ARM_LIB_HEAP co-exist, neither
955
- * does __user_setup_stackheap get called and nor is ARM_LIB_HEAP used to get heap base/limit,
956
- * which are required to pass to __rt_lib_init later. To fix the issue, by subclass'ing
957
- * __rt_lib_init, heap base/limit are replaced with Image$$ARM_LIB_HEAP$$ZI$$Base/Limit if
958
- * ARM_LIB_HEAP region is defined in scatter file.
959
- *
960
- * The overriding __rt_lib_init is needed only for rtos-less code. For rtos code, __rt_entry is
961
- * overridden and the overriding __rt_lib_init here gets meaningless.
962
- */
963
949
extern " C" extern __value_in_regs struct __argc_argv $Super$$__rt_lib_init(unsigned heapbase, unsigned heaptop);
964
950
965
951
extern " C" __value_in_regs struct __argc_argv $Sub$$__rt_lib_init(unsigned heapbase, unsigned heaptop)
966
952
{
967
- return $Super$$__rt_lib_init ((unsigned )HEAP_BASE , (unsigned )HEAP_LIMIT);
953
+ return $Super$$__rt_lib_init ((unsigned )HEAP_START , (unsigned )HEAP_LIMIT);
968
954
}
969
955
970
- #endif
971
-
972
956
extern " C" __value_in_regs struct __initial_stackheap __user_setup_stackheap (uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3)
973
957
{
974
958
return _mbed_user_setup_stackheap (R0, R1, R2, R3);
975
959
}
976
-
977
960
#endif
978
961
979
962
0 commit comments