-
Notifications
You must be signed in to change notification settings - Fork 3k
Initialization steps in toolchains #2160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b2d3c5d
1348301
1bf78fd
9c93aa8
a633829
6ae979f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,13 +149,21 @@ static inline int openmode_to_posix(int openmode) { | |
return posix; | ||
} | ||
|
||
extern "C" WEAK void mbed_sdk_init(void); | ||
extern "C" WEAK void mbed_sdk_init(void) { | ||
} | ||
|
||
extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) { | ||
#if defined(__MICROLIB) && (__ARMCC_VERSION>5030000) | ||
// Before version 5.03, we were using a patched version of microlib with proper names | ||
// This is the workaround that the microlib author suggested us | ||
static int n = 0; | ||
static int mbed_sdk_inited = 0; | ||
if (!mbed_sdk_inited) { | ||
mbed_sdk_inited = 1; | ||
mbed_sdk_init(); | ||
} | ||
if (!std::strcmp(name, ":tt")) return n++; | ||
|
||
#else | ||
/* Use the posix convention that stdin,out,err are filehandles 0,1,2. | ||
*/ | ||
|
@@ -502,7 +510,7 @@ extern "C" void software_init_hook(void) | |
mbed_die(); | ||
} | ||
#endif/* FEATURE_UVISOR */ | ||
|
||
mbed_sdk_init(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is before the RTOS has been initialized which might case problems on other devices. I'll trigger testing to check this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, with this patch, mbed_sdk_init is called before RTOS initialization. Good to have tests on other platforms - thanks ! |
||
software_init_hook_rtos(); | ||
} | ||
#endif | ||
|
@@ -517,23 +525,22 @@ extern "C" WEAK void mbed_main(void); | |
extern "C" WEAK void mbed_main(void) { | ||
} | ||
|
||
extern "C" WEAK void mbed_sdk_init(void); | ||
extern "C" WEAK void mbed_sdk_init(void) { | ||
} | ||
|
||
#if defined(TOOLCHAIN_ARM) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mbed_sdk_init for ARMCC is moved to before the RTOS is initialized, but is still called in GCC after the RTOS has been initialized. This behavior should be unified across the toolchains. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I changed the place where mbed_sdk_init is called in commit: |
||
extern "C" int $Super$$main(void); | ||
|
||
extern "C" int $Sub$$main(void) { | ||
mbed_sdk_init(); | ||
mbed_main(); | ||
return $Super$$main(); | ||
} | ||
|
||
extern "C" void _platform_post_stackheap_init (void) { | ||
mbed_sdk_init(); | ||
} | ||
|
||
#elif defined(TOOLCHAIN_GCC) | ||
extern "C" int __real_main(void); | ||
|
||
extern "C" int __wrap_main(void) { | ||
mbed_sdk_init(); | ||
mbed_main(); | ||
return __real_main(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is mbed_sdk_init only being called on _open for microlib? Also, here mbed_sdk_inited is checked, but it is not checked below so this might get called twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c1728p9: it just happen that _open "seems" to be called on every init and that we are looking for a path that is called after RAM init and before C++ object initialization. If you happen to know another alternative, that would be welcome.
Here is what I wrote in commit message :
In uARM, the library's hook _platform_post_stackheap_init does not seem to
exist and I couldnot find a documentation describing the initialisation
flow. All we know is that _open is called after RAM init and before the
C++ init, so this is a working placeholder.
This is maybe not acceptable so a uARM lib expert may propose a better
hook to fullfil the requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c1728p9 About being called twice, I think that various calls are under different #defines - the one in _open is only for uARM toolchain, the other calls are in case of GCC or ARM toolchain. But I may be wrong, which line to you suspect to be the 2nd call ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. I didn't notice the define wrapping it before.