ARMCC - Initialize RTOS before standard library

Initialize the RTOS before initializing the standard library.  This
allows C++ constructors to be called in a well defined thread context.
pull/1730/head
Russ Butler 2016-04-27 17:26:46 -05:00 committed by 0xc0170
parent a0fd520408
commit ac727e270e
1 changed files with 44 additions and 7 deletions

View File

@ -269,8 +269,8 @@ __attribute__((used)) void _mutex_release (OS_ID *mutex) {
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
/* Main Thread definition */ /* Main Thread definition */
extern int main (void); extern void pre_main (void);
osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1U, 0U, NULL}; osThreadDef_t os_thread_def_main = {(os_pthread)pre_main, osPriorityNormal, 1U, 0U, NULL};
// This define should be probably moved to the CMSIS layer // This define should be probably moved to the CMSIS layer
#if defined(TARGET_LPC1768) #if defined(TARGET_LPC1768)
@ -460,6 +460,32 @@ void _main_init (void) {
} }
#else #else
void * armcc_heap_base;
void * armcc_heap_top;
__asm void pre_main (void)
{
IMPORT __rt_lib_init
IMPORT main
IMPORT armcc_heap_base
IMPORT armcc_heap_top
LDR R0,=armcc_heap_base
LDR R1,=armcc_heap_top
LDR R0,[R0]
LDR R1,[R1]
/* Save link register (keep 8 byte alignment with dummy r4) */
push {r4, lr}
BL __rt_lib_init
/* Restore link register and branch so when main returns it
* goes to the thread destroy function.
*/
pop {r4, lr}
B main
ALIGN
}
/* The single memory model is checking for stack collision at run time, verifing /* The single memory model is checking for stack collision at run time, verifing
that the heap pointer is underneath the stack pointer. that the heap pointer is underneath the stack pointer.
@ -471,7 +497,8 @@ void _main_init (void) {
__asm void __rt_entry (void) { __asm void __rt_entry (void) {
IMPORT __user_setup_stackheap IMPORT __user_setup_stackheap
IMPORT __rt_lib_init IMPORT armcc_heap_base
IMPORT armcc_heap_top
IMPORT os_thread_def_main IMPORT os_thread_def_main
IMPORT osKernelInitialize IMPORT osKernelInitialize
#ifdef __MBED_CMSIS_RTOS_CM #ifdef __MBED_CMSIS_RTOS_CM
@ -479,11 +506,20 @@ __asm void __rt_entry (void) {
#endif #endif
IMPORT osKernelStart IMPORT osKernelStart
IMPORT osThreadCreate IMPORT osThreadCreate
IMPORT exit
/* __user_setup_stackheap returns:
* - Heap base in r0 (if the program uses the heap).
* - Stack base in sp.
* - Heap limit in r2 (if the program uses the heap and uses two-region memory).
*
* More info can be found in:
* ARM Compiler ARM C and C++ Libraries and Floating-Point Support User Guide
*/
BL __user_setup_stackheap BL __user_setup_stackheap
MOV R1,R2 LDR R3,=armcc_heap_base
BL __rt_lib_init LDR R4,=armcc_heap_top
STR R0,[R3]
STR R2,[R4]
BL osKernelInitialize BL osKernelInitialize
#ifdef __MBED_CMSIS_RTOS_CM #ifdef __MBED_CMSIS_RTOS_CM
BL set_main_stack BL set_main_stack
@ -492,7 +528,8 @@ __asm void __rt_entry (void) {
MOVS R1,#0 MOVS R1,#0
BL osThreadCreate BL osThreadCreate
BL osKernelStart BL osKernelStart
BL exit /* osKernelStart should not return */
B .
ALIGN ALIGN
} }