Fix function to get sp when in unprivileged mode

Alessandro Angelino 2016-04-06 16:14:19 +01:00 committed by Milosch Meriac
parent 4ae6b059e0
commit 3ad0f0a430
1 changed files with 12 additions and 6 deletions

View File

@ -469,8 +469,16 @@ extern "C" uint32_t __HeapLimit;
#undef errno #undef errno
extern "C" int errno; extern "C" int errno;
// For ARM7 only // Stack pointer handling
register unsigned char * stack_ptr __asm ("sp"); #ifdef __ICCARM__
#define __current_sp() __get_SP()
#else
static inline unsigned int __current_sp(void)
{
register unsigned sp asm("sp");
return sp;
}
#endif /* __ICCARM__ */
// Dynamic memory allocation related syscall. // Dynamic memory allocation related syscall.
extern "C" caddr_t _sbrk(int incr) { extern "C" caddr_t _sbrk(int incr) {
@ -478,12 +486,10 @@ extern "C" caddr_t _sbrk(int incr) {
unsigned char* prev_heap = heap; unsigned char* prev_heap = heap;
unsigned char* new_heap = heap + incr; unsigned char* new_heap = heap + incr;
#if defined(TARGET_ARM7) #if defined(TARGET_CORTEX_A)
if (new_heap >= stack_ptr) {
#elif defined(TARGET_CORTEX_A)
if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */ if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */
#else #else
if (new_heap >= (unsigned char*)__get_MSP()) { if (new_heap >= (unsigned char*)__current_sp()) {
#endif #endif
errno = ENOMEM; errno = ENOMEM;
return (caddr_t)-1; return (caddr_t)-1;