Skip to content
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

Update for ARMCC6 #13

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions common/mbed_alloc_wrappers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stddef.h>







#include <stdio.h>




#include <string.h>




#include <stdlib.h>

/******************************************************************************/
/* GCC memory allocation wrappers */
/******************************************************************************/

#if defined(TOOLCHAIN_GCC)

extern "C" {
void *__real__malloc_r(struct _reent *r, size_t size);
void *__real__memalign_r(struct _reent *r, size_t alignment, size_t bytes);
void *__real__realloc_r(struct _reent *r, void *ptr, size_t size);
void __real__free_r(struct _reent *r, void *ptr);
void *__real__calloc_r(struct _reent *r, size_t nmemb, size_t size);
void *malloc_wrapper(struct _reent *r, size_t size, void *caller);
void free_wrapper(struct _reent *r, void *ptr, void *caller);
}


extern "C" void *__wrap__malloc_r(struct _reent *r, size_t size)
{
return malloc_wrapper(r, size, __builtin_extract_return_addr(__builtin_return_address(0)));
}

extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
{
void *ptr = NULL;
ptr = __real__malloc_r(r, size);
return ptr;
}

extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
{
void *new_ptr = NULL;
new_ptr = __real__realloc_r(r, ptr, size);
return new_ptr;
}

extern "C" void __wrap__free_r(struct _reent *r, void *ptr)
{
free_wrapper(r, ptr, __builtin_extract_return_addr(__builtin_return_address(0)));
}

extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
{
__real__free_r(r, ptr);
}

extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size)
{
void *ptr = NULL;
ptr = __real__calloc_r(r, nmemb, size);
return ptr;
}

extern "C" void *__wrap__memalign_r(struct _reent *r, size_t alignment, size_t bytes)
{
return __real__memalign_r(r, alignment, bytes);
}

#endif // #if defined(TOOLCHAIN_GCC)
34 changes: 34 additions & 0 deletions common/retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,40 @@ extern "C" void exit(int return_code) {
} //namespace std
#endif

#if defined(TOOLCHAIN_GCC)

/*
* Depending on how newlib is configured, it is often not enough to define
* __aeabi_atexit, __cxa_atexit and __cxa_finalize in order to override the
* behavior regarding the registration of handlers with atexit.
*
* To overcome this limitation, exit and atexit are overriden here.
*/
extern "C" {

/**
* @brief Retarget of exit for GCC.
* @details Unlike the standard version, this function doesn't call any function
* registered with atexit before calling _exit.
*/
void __wrap_exit(int return_code)
{
_exit(return_code);
}

/**
* @brief Retarget atexit from GCC.
* @details This function will always fail and never register any handler to be
* called at exit.
*/
int __wrap_atexit(void (*func)())
{
return 1;
}

}

#endif

namespace mbed {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ extern "C" {
#include <rt_misc.h>
#include <stdint.h>

#if __ARMCC_VERSION >= 6000000
#include <arm_compat.h>
#endif


extern char Image$$RW_IRAM1$$ZI$$Limit[];

extern __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MEMORY
{
FLASH (rx) : ORIGIN = 0x00016000, LENGTH = 0x2A000
FLASH (rx) : ORIGIN = 0x00018000, LENGTH = 0x28000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was done because an overlapping soft device.
Is it possible that during testing a different soft device than yotta was used?
We need to double check that the same version of soft device is used in yotta and mbed-cli.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geowor01 please could you check

@microbit-carlos I've not got ARMCC6 to test this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed upstream in ARMmbed/mbed-os@dfcb2c6.
The armcc5 linker file already contains what we think might be the right value:


We still need to figure out which linker file yotta is using to make sure the micro:bit builds with Yotta and GCC are use the same address.

RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000
}

Expand Down