Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
targets/TARGET_NUVOTON/TOOLCHAIN_ARM/sys.cpp@188:60408c49b6d4, 2018-09-20 (annotated)
- Committer:
- WaleedElmughrabi
- Date:
- Thu Sep 20 16:11:23 2018 +0000
- Revision:
- 188:60408c49b6d4
- Parent:
- 187:0387e8f68319
Fork modified for BG96 error
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| AnnaBridge | 187:0387e8f68319 | 1 | /* mbed Microcontroller Library - stackheap |
| AnnaBridge | 187:0387e8f68319 | 2 | * Copyright (C) 2009-2011 ARM Limited. All rights reserved. |
| AnnaBridge | 187:0387e8f68319 | 3 | * |
| AnnaBridge | 187:0387e8f68319 | 4 | * Setup a fixed single stack/heap memory model, |
| AnnaBridge | 187:0387e8f68319 | 5 | * between the top of the RW/ZI region and the stackpointer |
| AnnaBridge | 187:0387e8f68319 | 6 | */ |
| AnnaBridge | 187:0387e8f68319 | 7 | |
| AnnaBridge | 187:0387e8f68319 | 8 | #ifdef __cplusplus |
| AnnaBridge | 187:0387e8f68319 | 9 | extern "C" { |
| AnnaBridge | 187:0387e8f68319 | 10 | #endif |
| AnnaBridge | 187:0387e8f68319 | 11 | |
| AnnaBridge | 187:0387e8f68319 | 12 | #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) |
| AnnaBridge | 187:0387e8f68319 | 13 | #include <arm_compat.h> |
| AnnaBridge | 187:0387e8f68319 | 14 | #endif |
| AnnaBridge | 187:0387e8f68319 | 15 | |
| AnnaBridge | 187:0387e8f68319 | 16 | #include <rt_misc.h> |
| AnnaBridge | 187:0387e8f68319 | 17 | #include <stdint.h> |
| AnnaBridge | 187:0387e8f68319 | 18 | |
| AnnaBridge | 187:0387e8f68319 | 19 | extern char Image$$ARM_LIB_STACK$$ZI$$Limit[]; |
| AnnaBridge | 187:0387e8f68319 | 20 | extern char Image$$ARM_LIB_HEAP$$Base[]; |
| AnnaBridge | 187:0387e8f68319 | 21 | extern char Image$$ARM_LIB_HEAP$$ZI$$Limit[]; |
| AnnaBridge | 187:0387e8f68319 | 22 | extern __value_in_regs struct __initial_stackheap _mbed_user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) { |
| AnnaBridge | 187:0387e8f68319 | 23 | |
| AnnaBridge | 187:0387e8f68319 | 24 | struct __initial_stackheap r; |
| AnnaBridge | 187:0387e8f68319 | 25 | r.heap_base = (uint32_t)Image$$ARM_LIB_HEAP$$Base; |
| AnnaBridge | 187:0387e8f68319 | 26 | r.heap_limit = (uint32_t)Image$$ARM_LIB_HEAP$$ZI$$Limit; |
| AnnaBridge | 187:0387e8f68319 | 27 | return r; |
| AnnaBridge | 187:0387e8f68319 | 28 | } |
| AnnaBridge | 187:0387e8f68319 | 29 | |
| AnnaBridge | 187:0387e8f68319 | 30 | #if !defined(MBED_CONF_RTOS_PRESENT) || !MBED_CONF_RTOS_PRESENT |
| AnnaBridge | 187:0387e8f68319 | 31 | |
| AnnaBridge | 187:0387e8f68319 | 32 | /* The single region memory model would check stack collision at run time, verifying that |
| AnnaBridge | 187:0387e8f68319 | 33 | * the heap pointer is underneath the stack pointer. With two-region memory model/RTOS-less or |
| AnnaBridge | 187:0387e8f68319 | 34 | * multiple threads(stacks)/RTOS, the check gets meaningless and we must disable it. */ |
| AnnaBridge | 187:0387e8f68319 | 35 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) |
| AnnaBridge | 187:0387e8f68319 | 36 | __asm(".global __use_two_region_memory\n\t"); |
| AnnaBridge | 187:0387e8f68319 | 37 | __asm(".global __use_no_semihosting\n\t"); |
| AnnaBridge | 187:0387e8f68319 | 38 | #else |
| AnnaBridge | 187:0387e8f68319 | 39 | #pragma import(__use_two_region_memory) |
| AnnaBridge | 187:0387e8f68319 | 40 | #endif |
| AnnaBridge | 187:0387e8f68319 | 41 | |
| AnnaBridge | 187:0387e8f68319 | 42 | /* Fix __user_setup_stackheap and ARM_LIB_STACK/ARM_LIB_HEAP cannot co-exist in RTOS-less build |
| AnnaBridge | 187:0387e8f68319 | 43 | * |
| AnnaBridge | 187:0387e8f68319 | 44 | * According AN241 (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0241b/index.html), |
| AnnaBridge | 187:0387e8f68319 | 45 | * __rt_entry has the following call sequence: |
| AnnaBridge | 187:0387e8f68319 | 46 | * 1. _platform_pre_stackheap_init |
| AnnaBridge | 187:0387e8f68319 | 47 | * 2. __user_setup_stackheap or setup the Stack Pointer (SP) by another method |
| AnnaBridge | 187:0387e8f68319 | 48 | * 3. _platform_post_stackheap_init |
| AnnaBridge | 187:0387e8f68319 | 49 | * 4. __rt_lib_init |
| AnnaBridge | 187:0387e8f68319 | 50 | * 5. _platform_post_lib_init |
| AnnaBridge | 187:0387e8f68319 | 51 | * 6. main() |
| AnnaBridge | 187:0387e8f68319 | 52 | * 7. exit() |
| AnnaBridge | 187:0387e8f68319 | 53 | * |
| AnnaBridge | 187:0387e8f68319 | 54 | * Per our check, when __user_setup_stackheap and ARM_LIB_STACK/ARM_LIB_HEAP co-exist, neither |
| AnnaBridge | 187:0387e8f68319 | 55 | * does __user_setup_stackheap get called and nor is ARM_LIB_HEAP used to get heap base/limit, |
| AnnaBridge | 187:0387e8f68319 | 56 | * which are required to pass to __rt_lib_init later. To fix the issue, by subclass'ing |
| AnnaBridge | 187:0387e8f68319 | 57 | * __rt_lib_init, heap base/limit are replaced with Image$$ARM_LIB_HEAP$$ZI$$Base/Limit if |
| AnnaBridge | 187:0387e8f68319 | 58 | * ARM_LIB_HEAP region is defined in scatter file. |
| AnnaBridge | 187:0387e8f68319 | 59 | * |
| AnnaBridge | 187:0387e8f68319 | 60 | * The overriding __rt_lib_init is needed only for rtos-less code. For rtos code, __rt_entry is |
| AnnaBridge | 187:0387e8f68319 | 61 | * overridden and the overriding __rt_lib_init here gets meaningless. |
| AnnaBridge | 187:0387e8f68319 | 62 | */ |
| AnnaBridge | 187:0387e8f68319 | 63 | extern __value_in_regs struct __argc_argv $Super$$__rt_lib_init(unsigned heapbase, unsigned heaptop); |
| AnnaBridge | 187:0387e8f68319 | 64 | |
| AnnaBridge | 187:0387e8f68319 | 65 | __value_in_regs struct __argc_argv $Sub$$__rt_lib_init (unsigned heapbase, unsigned heaptop) |
| AnnaBridge | 187:0387e8f68319 | 66 | { |
| AnnaBridge | 187:0387e8f68319 | 67 | return $Super$$__rt_lib_init((unsigned) Image$$ARM_LIB_HEAP$$Base, (unsigned) Image$$ARM_LIB_HEAP$$ZI$$Limit); |
| AnnaBridge | 187:0387e8f68319 | 68 | } |
| AnnaBridge | 187:0387e8f68319 | 69 | |
| AnnaBridge | 187:0387e8f68319 | 70 | #endif |
| AnnaBridge | 187:0387e8f68319 | 71 | |
| AnnaBridge | 187:0387e8f68319 | 72 | #ifdef __cplusplus |
| AnnaBridge | 187:0387e8f68319 | 73 | } |
| AnnaBridge | 187:0387e8f68319 | 74 | #endif |
