Skip to content

Commit c19defe

Browse files
0xc0170bulislaw
authored andcommitted
cmain IAR: add mbed main
This fixes #4602 issue, mbed_main should be invoked right before the real main
1 parent 654a62e commit c19defe

File tree

1 file changed

+101
-0
lines changed
  • cmsis/TARGET_CORTEX_M/TOOLCHAIN_IAR

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**************************************************
2+
*
3+
* Part two of the system initialization code, contains C-level
4+
* initialization, thumb-2 only variant.
5+
*
6+
* $Revision: 59783 $
7+
*
8+
**************************************************/
9+
/* Copyright 2008-2017, IAR Systems AB.
10+
This source code is the property of IAR Systems. The source code may only
11+
be used together with the IAR Embedded Workbench. Redistribution and use
12+
in source and binary forms, with or without modification, is permitted
13+
provided that the following conditions are met:
14+
- Redistributions of source code, in whole or in part, must retain the
15+
above copyright notice, this list of conditions and the disclaimer below.
16+
- IAR Systems name may not be used to endorse or promote products
17+
derived from this software without specific prior written permission.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
20+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
21+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
22+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
24+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
25+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26+
*/
27+
28+
; --------------------------------------------------
29+
; Module ?cmain, C-level initialization.
30+
;
31+
32+
33+
SECTION SHT$$PREINIT_ARRAY:CONST:NOROOT(2)
34+
SECTION SHT$$INIT_ARRAY:CONST:NOROOT(2)
35+
36+
SECTION .text:CODE:NOROOT(2)
37+
38+
PUBLIC __cmain
39+
;; Keep ?main for legacy reasons, it is accessed in countless instances of cstartup.s around the world...
40+
PUBLIC ?main
41+
EXTWEAK __iar_data_init3
42+
EXTWEAK __iar_argc_argv
43+
EXTERN __low_level_init
44+
EXTERN __call_ctors
45+
EXTERN main
46+
EXTERN exit
47+
EXTERN __iar_dynamic_initialization
48+
EXTERN mbed_sdk_init
49+
EXTERN mbed_main
50+
EXTERN SystemInit
51+
52+
THUMB
53+
__cmain:
54+
?main:
55+
56+
; Initialize segments.
57+
; __segment_init and __low_level_init are assumed to use the same
58+
; instruction set and to be reachable by BL from the ICODE segment
59+
; (it is safest to link them in segment ICODE).
60+
61+
FUNCALL __cmain, __low_level_init
62+
bl __low_level_init
63+
cmp r0,#0
64+
beq ?l1
65+
FUNCALL __cmain, __iar_data_init3
66+
bl __iar_data_init3
67+
MOVS r0,#0 ; No parameters
68+
FUNCALL __cmain, mbed_sdk_init
69+
BL mbed_sdk_init
70+
MOVS r0,#0 ; No parameters
71+
FUNCALL __cmain, __iar_dynamic_initialization
72+
BL __iar_dynamic_initialization ; C++ dynamic initialization
73+
74+
?l1:
75+
REQUIRE ?l3
76+
77+
SECTION .text:CODE:NOROOT(2)
78+
79+
PUBLIC _main
80+
PUBLIC _call_main
81+
THUMB
82+
83+
__iar_init$$done: ; Copy initialization is done
84+
85+
?l3:
86+
_call_main:
87+
MOVS r0,#0 ; No parameters
88+
FUNCALL __cmain, __iar_argc_argv
89+
BL __iar_argc_argv ; Maybe setup command line
90+
91+
MOVS r0,#0 ; No parameters
92+
FUNCALL __cmain, mbed_main
93+
BL mbed_main
94+
95+
FUNCALL __cmain, main
96+
BL main
97+
_main:
98+
FUNCALL __cmain, exit
99+
BL exit
100+
101+
END

0 commit comments

Comments
 (0)