Skip to content

Commit 165c663

Browse files
VladimirUmekTomoYamanaka
authored andcommitted
RTX5: fixed nesting interrupt handling (Cortex-A)
1 parent b6c4139 commit 165c663

File tree

3 files changed

+60
-30
lines changed
  • rtos/TARGET_CORTEX/rtx5/RTX/Source

3 files changed

+60
-30
lines changed

rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_CORTEX_A/irq_ca.S

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ IRQ_Handler\
178178
CPS #MODE_SVC ; Change to SVC mode
179179
PUSH {R0-R3, R12, LR} ; Save APCS corruptible registers
180180

181+
LDR R3, =IRQ_NestLevel
182+
LDR R2, [R3]
183+
ADD R2, R2, #1 ; Increment IRQ nesting level
184+
STR R2, [R3]
185+
181186
MOV R3, SP ; Move SP into R3
182187
AND R3, R3, #4 ; Get stack adjustment to ensure 8-byte alignment
183188
SUB SP, SP, R3 ; Adjust stack
@@ -186,11 +191,6 @@ IRQ_Handler\
186191
BLX IRQ_GetActiveIRQ ; Retrieve interrupt ID into R0
187192
MOV R4, R0 ; Move interrupt ID to R4
188193

189-
LDR R1, =IRQ_NestLevel
190-
LDR R3, [R1] ; Load IRQ nest level and increment it
191-
ADD R3, R3, #1
192-
STR R3, [R1]
193-
194194
BLX IRQ_GetHandler ; Retrieve interrupt handler address for current ID
195195
CMP R0, #0 ; Check if handler address is 0
196196
BEQ IRQ_End ; If 0, end interrupt and return
@@ -203,11 +203,10 @@ IRQ_End
203203
MOV R0, R4 ; Move interrupt ID to R0
204204
BLX IRQ_EndOfInterrupt ; Signal end of interrupt
205205

206-
LDR R2, =IRQ_NestLevel
207-
LDR R1, [R2] ; Load IRQ nest level and
208-
SUBS R1, R1, #1 ; decrement it
209-
STR R1, [R2]
210-
BNE IRQ_Exit ; Not zero, exit from IRQ handler
206+
LDR R3, =IRQ_NestLevel
207+
LDR R2, [R3] ; Load IRQ nest level
208+
CMP R2, #1
209+
BNE IRQ_Exit ; Nesting interrupts, exit from IRQ handler
211210

212211
LDR R0, =SVC_Active
213212
LDRB R0, [R0] ; Load SVC_Active flag
@@ -252,12 +251,23 @@ IRQ_SwitchCheck
252251

253252
POP {R3, R4} ; Restore stack adjustment(R3) and user data(R4)
254253
ADD SP, SP, R3 ; Unadjust stack
254+
255+
LDR R3, =IRQ_NestLevel
256+
LDR R2, [R3]
257+
SUBS R2, R2, #1 ; Decrement IRQ nesting level
258+
STR R2, [R3]
259+
255260
B osRtxContextSwitch
256261

257262
IRQ_Exit
258263
POP {R3, R4} ; Restore stack adjustment(R3) and user data(R4)
259264
ADD SP, SP, R3 ; Unadjust stack
260265

266+
LDR R3, =IRQ_NestLevel
267+
LDR R2, [R3]
268+
SUBS R2, R2, #1 ; Decrement IRQ nesting level
269+
STR R2, [R3]
270+
261271
POP {R0-R3, R12, LR} ; Restore stacked APCS registers
262272
RFEFD SP! ; Return from IRQ handler
263273

rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_CORTEX_A/irq_ca.S

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ IRQ_Handler:
184184
CPS #MODE_SVC // Change to SVC mode
185185
PUSH {R0-R3, R12, LR} // Save APCS corruptible registers
186186

187+
LDR R3, =IRQ_NestLevel
188+
LDR R2, [R3]
189+
ADD R2, R2, #1 // Increment IRQ nesting level
190+
STR R2, [R3]
191+
187192
MOV R3, SP // Move SP into R3
188193
AND R3, R3, #4 // Get stack adjustment to ensure 8-byte alignment
189194
SUB SP, SP, R3 // Adjust stack
@@ -192,11 +197,6 @@ IRQ_Handler:
192197
BLX IRQ_GetActiveIRQ // Retrieve interrupt ID into R0
193198
MOV R4, R0 // Move interrupt ID to R4
194199

195-
LDR R1, =IRQ_NestLevel
196-
LDR R3, [R1] // Load IRQ nest level and increment it
197-
ADD R3, R3, #1
198-
STR R3, [R1]
199-
200200
BLX IRQ_GetHandler // Retrieve interrupt handler address for current ID
201201
CMP R0, #0 // Check if handler address is 0
202202
BEQ IRQ_End // If 0, end interrupt and return
@@ -209,11 +209,10 @@ IRQ_End:
209209
MOV R0, R4 // Move interrupt ID to R0
210210
BLX IRQ_EndOfInterrupt // Signal end of interrupt
211211

212-
LDR R2, =IRQ_NestLevel
213-
LDR R1, [R2] // Load IRQ nest level and
214-
SUBS R1, R1, #1 // decrement it
215-
STR R1, [R2]
216-
BNE IRQ_Exit // Not zero, exit from IRQ handler
212+
LDR R3, =IRQ_NestLevel
213+
LDR R2, [R3] // Load IRQ nest level
214+
CMP R2, #1
215+
BNE IRQ_Exit // Nesting interrupts, exit from IRQ handler
217216

218217
LDR R0, =SVC_Active
219218
LDRB R0, [R0] // Load SVC_Active flag
@@ -258,12 +257,23 @@ IRQ_SwitchCheck:
258257

259258
POP {R3, R4} // Restore stack adjustment(R3) and user data(R4)
260259
ADD SP, SP, R3 // Unadjust stack
260+
261+
LDR R3, =IRQ_NestLevel
262+
LDR R2, [R3]
263+
SUBS R2, R2, #1 // Decrement IRQ nesting level
264+
STR R2, [R3]
265+
261266
B osRtxContextSwitch
262267

263268
IRQ_Exit:
264269
POP {R3, R4} // Restore stack adjustment(R3) and user data(R4)
265270
ADD SP, SP, R3 // Unadjust stack
266271

272+
LDR R3, =IRQ_NestLevel
273+
LDR R2, [R3]
274+
SUBS R2, R2, #1 // Decrement IRQ nesting level
275+
STR R2, [R3]
276+
267277
POP {R0-R3, R12, LR} // Restore stacked APCS registers
268278
RFEFD SP! // Return from IRQ handler
269279

rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_CORTEX_A/irq_ca.S

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ IRQ_Handler
169169
CPS #MODE_SVC ; Change to SVC mode
170170
PUSH {R0-R3, R12, LR} ; Save APCS corruptible registers
171171

172+
LDR R3, =IRQ_NestLevel
173+
LDR R2, [R3]
174+
ADD R2, R2, #1 ; Increment IRQ nesting level
175+
STR R2, [R3]
176+
172177
MOV R3, SP ; Move SP into R3
173178
AND R3, R3, #4 ; Get stack adjustment to ensure 8-byte alignment
174179
SUB SP, SP, R3 ; Adjust stack
@@ -177,11 +182,6 @@ IRQ_Handler
177182
BLX IRQ_GetActiveIRQ ; Retrieve interrupt ID into R0
178183
MOV R4, R0 ; Move interrupt ID to R4
179184

180-
LDR R1, =IRQ_NestLevel
181-
LDR R3, [R1] ; Load IRQ nest level and increment it
182-
ADD R3, R3, #1
183-
STR R3, [R1]
184-
185185
BLX IRQ_GetHandler ; Retrieve interrupt handler address for current ID
186186
CMP R0, #0 ; Check if handler address is 0
187187
BEQ IRQ_End ; If 0, end interrupt and return
@@ -194,11 +194,10 @@ IRQ_End
194194
MOV R0, R4 ; Move interrupt ID to R0
195195
BLX IRQ_EndOfInterrupt ; Signal end of interrupt
196196

197-
LDR R2, =IRQ_NestLevel
198-
LDR R1, [R2] ; Load IRQ nest level and
199-
SUBS R1, R1, #1 ; decrement it
200-
STR R1, [R2]
201-
BNE IRQ_Exit ; Not zero, exit from IRQ handler
197+
LDR R3, =IRQ_NestLevel
198+
LDR R2, [R3] ; Load IRQ nest level
199+
CMP R2, #1
200+
BNE IRQ_Exit ; Nesting interrupts, exit from IRQ handler
202201

203202
LDR R0, =SVC_Active
204203
LDRB R0, [R0] ; Load SVC_Active flag
@@ -243,12 +242,23 @@ IRQ_SwitchCheck
243242

244243
POP {R3, R4} ; Restore stack adjustment(R3) and user data(R4)
245244
ADD SP, SP, R3 ; Unadjust stack
245+
246+
LDR R3, =IRQ_NestLevel
247+
LDR R2, [R3]
248+
SUBS R2, R2, #1 ; Decrement IRQ nesting level
249+
STR R2, [R3]
250+
246251
B osRtxContextSwitch
247252

248253
IRQ_Exit
249254
POP {R3, R4} ; Restore stack adjustment(R3) and user data(R4)
250255
ADD SP, SP, R3 ; Unadjust stack
251256

257+
LDR R3, =IRQ_NestLevel
258+
LDR R2, [R3]
259+
SUBS R2, R2, #1 ; Decrement IRQ nesting level
260+
STR R2, [R3]
261+
252262
POP {R0-R3, R12, LR} ; Restore stacked APCS registers
253263
RFEFD SP! ; Return from IRQ handler
254264

0 commit comments

Comments
 (0)