Skip to content

Commit 65b4e72

Browse files
committed
Modify IRQ handler processing without RTOS at Cortex-A IAR Compiler
In case of unusing RTOS, there is no processing against IRQ handler and it causes a linker error. Therefore, I added this processing with WEAK attribute. Also I added cmain.S file at cmsis/TARGET_CORTEX_A folder.
1 parent dd8d8ea commit 65b4e72

File tree

3 files changed

+275
-0
lines changed
  • cmsis/TARGET_CORTEX_A/TOOLCHAIN_IAR
  • targets/TARGET_RENESAS/TARGET_RZ_A1XX

3 files changed

+275
-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
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2013-2018 Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the License); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* -----------------------------------------------------------------------------
19+
*
20+
* Project: CMSIS-RTOS RTX
21+
* Title: Cortex-A Exception handlers
22+
*
23+
* -----------------------------------------------------------------------------
24+
*/
25+
26+
NAME irq_weak.S
27+
28+
MODE_SVC EQU 0x13
29+
30+
PRESERVE8
31+
32+
SECTION .text:CODE:NOROOT(2)
33+
34+
PUBWEAK Undef_Handler
35+
Undef_Handler
36+
B .
37+
38+
PUBWEAK SVC_Handler
39+
SVC_Handler
40+
B .
41+
42+
PUBWEAK PAbt_Handler
43+
PAbt_Handler
44+
B .
45+
46+
PUBWEAK DAbt_Handler
47+
DAbt_Handler
48+
B .
49+
50+
PUBWEAK IRQ_Handler
51+
IRQ_Handler
52+
IMPORT IRQ_GetActiveIRQ
53+
IMPORT IRQ_GetHandler
54+
IMPORT IRQ_EndOfInterrupt
55+
56+
SUB LR, LR, #4 ; Pre-adjust LR
57+
SRSFD SP!, #MODE_SVC ; Save LR_irq and SPSR_irq on to the SVC stack
58+
CPS #MODE_SVC ; Change to SVC mode
59+
PUSH {R0-R3, R12, LR} ; Save APCS corruptible registers
60+
61+
MOV R3, SP ; Move SP into R3
62+
AND R3, R3, #4 ; Get stack adjustment to ensure 8-byte alignment
63+
SUB SP, SP, R3 ; Adjust stack
64+
PUSH {R3, R4} ; Store stack adjustment(R3) and user data(R4)
65+
66+
BLX IRQ_GetActiveIRQ ; Retrieve interrupt ID into R0
67+
MOV R4, R0 ; Move interrupt ID to R4
68+
69+
BLX IRQ_GetHandler ; Retrieve interrupt handler address for current ID
70+
CMP R0, #0 ; Check if handler address is 0
71+
BEQ IRQ_End ; If 0, end interrupt and return
72+
73+
CPSIE i ; Re-enable interrupts
74+
BLX R0 ; Call IRQ handler
75+
CPSID i ; Disable interrupts
76+
77+
IRQ_End
78+
MOV R0, R4 ; Move interrupt ID to R0
79+
BLX IRQ_EndOfInterrupt ; Signal end of interrupt
80+
81+
POP {R3, R4} ; Restore stack adjustment(R3) and user data(R4)
82+
ADD SP, SP, R3 ; Unadjust stack
83+
84+
POP {R0-R3, R12, LR} ; Restore stacked APCS registers
85+
RFEFD SP! ; Return from IRQ handler
86+
87+
END
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2013-2018 Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the License); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* -----------------------------------------------------------------------------
19+
*
20+
* Project: CMSIS-RTOS RTX
21+
* Title: Cortex-A Exception handlers
22+
*
23+
* -----------------------------------------------------------------------------
24+
*/
25+
26+
NAME irq_weak.S
27+
28+
MODE_SVC EQU 0x13
29+
30+
PRESERVE8
31+
32+
SECTION .text:CODE:NOROOT(2)
33+
34+
PUBWEAK Undef_Handler
35+
Undef_Handler
36+
B .
37+
38+
PUBWEAK SVC_Handler
39+
SVC_Handler
40+
B .
41+
42+
PUBWEAK PAbt_Handler
43+
PAbt_Handler
44+
B .
45+
46+
PUBWEAK DAbt_Handler
47+
DAbt_Handler
48+
B .
49+
50+
PUBWEAK IRQ_Handler
51+
IRQ_Handler
52+
IMPORT IRQ_GetActiveIRQ
53+
IMPORT IRQ_GetHandler
54+
IMPORT IRQ_EndOfInterrupt
55+
56+
SUB LR, LR, #4 ; Pre-adjust LR
57+
SRSFD SP!, #MODE_SVC ; Save LR_irq and SPSR_irq on to the SVC stack
58+
CPS #MODE_SVC ; Change to SVC mode
59+
PUSH {R0-R3, R12, LR} ; Save APCS corruptible registers
60+
61+
MOV R3, SP ; Move SP into R3
62+
AND R3, R3, #4 ; Get stack adjustment to ensure 8-byte alignment
63+
SUB SP, SP, R3 ; Adjust stack
64+
PUSH {R3, R4} ; Store stack adjustment(R3) and user data(R4)
65+
66+
BLX IRQ_GetActiveIRQ ; Retrieve interrupt ID into R0
67+
MOV R4, R0 ; Move interrupt ID to R4
68+
69+
BLX IRQ_GetHandler ; Retrieve interrupt handler address for current ID
70+
CMP R0, #0 ; Check if handler address is 0
71+
BEQ IRQ_End ; If 0, end interrupt and return
72+
73+
CPSIE i ; Re-enable interrupts
74+
BLX R0 ; Call IRQ handler
75+
CPSID i ; Disable interrupts
76+
77+
IRQ_End
78+
MOV R0, R4 ; Move interrupt ID to R0
79+
BLX IRQ_EndOfInterrupt ; Signal end of interrupt
80+
81+
POP {R3, R4} ; Restore stack adjustment(R3) and user data(R4)
82+
ADD SP, SP, R3 ; Unadjust stack
83+
84+
POP {R0-R3, R12, LR} ; Restore stacked APCS registers
85+
RFEFD SP! ; Return from IRQ handler
86+
87+
END

0 commit comments

Comments
 (0)