Fixed bug 3317500.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_2.2.x@3048 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2011-06-16 19:58:08 +00:00
parent d0d99a6b8b
commit 9c1f010cb7
7 changed files with 51 additions and 74 deletions

View File

@ -96,7 +96,8 @@ __attribute__((naked))
#endif #endif
void _port_switch_from_isr(void) { void _port_switch_from_isr(void) {
chSchDoRescheduleI(); if (chSchIsRescRequiredExI())
chSchDoRescheduleI();
#if CORTEX_ALTERNATE_SWITCH #if CORTEX_ALTERNATE_SWITCH
SCB_ICSR = ICSR_PENDSVSET; SCB_ICSR = ICSR_PENDSVSET;
port_unlock(); port_unlock();
@ -159,22 +160,18 @@ void _port_switch(Thread *ntp, Thread *otp) {
void _port_irq_epilogue(regarm_t lr) { void _port_irq_epilogue(regarm_t lr) {
if (lr != (regarm_t)0xFFFFFFF1) { if (lr != (regarm_t)0xFFFFFFF1) {
port_lock_from_isr(); register struct extctx *ctxp;
if (chSchIsRescRequiredExI()) {
register struct extctx *ctxp;
/* Adding an artificial exception return context, there is no need to port_lock_from_isr();
populate it fully.*/ /* Adding an artificial exception return context, there is no need to
asm volatile ("mrs %0, PSP" : "=r" (ctxp) : : "memory"); populate it fully.*/
ctxp--; asm volatile ("mrs %0, PSP" : "=r" (ctxp) : : "memory");
asm volatile ("msr PSP, %0" : : "r" (ctxp) : "memory"); ctxp--;
ctxp->pc = _port_switch_from_isr; asm volatile ("msr PSP, %0" : : "r" (ctxp) : "memory");
ctxp->xpsr = (regarm_t)0x01000000; ctxp->pc = _port_switch_from_isr;
/* Note, returning without unlocking is intentional, this is done in ctxp->xpsr = (regarm_t)0x01000000;
order to keep the rest of the context switching atomic.*/ /* Note, returning without unlocking is intentional, this is done in
return; order to keep the rest of the context switching atomic.*/
}
port_unlock_from_isr();
} }
} }

View File

@ -128,12 +128,12 @@ void PendSVVector(void) {
#endif /* CORTEX_SIMPLIFIED_PRIORITY */ #endif /* CORTEX_SIMPLIFIED_PRIORITY */
/** /**
* @brief Reschedule verification and setup after an IRQ. * @brief Exception exit redirection to _port_switch_from_isr().
*/ */
void _port_irq_epilogue(void) { void _port_irq_epilogue(void) {
port_lock_from_isr(); port_lock_from_isr();
if ((SCB_ICSR & ICSR_RETTOBASE) && chSchIsRescRequiredExI()) { if ((SCB_ICSR & ICSR_RETTOBASE)) {
register struct extctx *ctxp; register struct extctx *ctxp;
/* Adding an artificial exception return context, there is no need to /* Adding an artificial exception return context, there is no need to
@ -147,7 +147,6 @@ void _port_irq_epilogue(void) {
order to keep the rest of the context switching atomic.*/ order to keep the rest of the context switching atomic.*/
return; return;
} }
/* ISR exit without context switching.*/
port_unlock_from_isr(); port_unlock_from_isr();
} }
@ -160,7 +159,8 @@ __attribute__((naked))
#endif #endif
void _port_switch_from_isr(void) { void _port_switch_from_isr(void) {
chSchDoRescheduleI(); if (chSchIsRescRequiredExI())
chSchDoRescheduleI();
#if !CORTEX_SIMPLIFIED_PRIORITY || defined(__DOXYGEN__) #if !CORTEX_SIMPLIFIED_PRIORITY || defined(__DOXYGEN__)
asm volatile ("svc #0"); asm volatile ("svc #0");
#else /* CORTEX_SIMPLIFIED_PRIORITY */ #else /* CORTEX_SIMPLIFIED_PRIORITY */

View File

@ -116,7 +116,11 @@ PendSVVector:
*/ */
PUBLIC _port_switch_from_isr PUBLIC _port_switch_from_isr
_port_switch_from_isr: _port_switch_from_isr:
bl chSchIsRescRequiredExI
cmp r0, #0
beq noresch
bl chSchDoRescheduleI bl chSchDoRescheduleI
noresch:
ldr r2, =SCB_ICSR ldr r2, =SCB_ICSR
movs r3, #128 movs r3, #128
#if CORTEX_ALTERNATE_SWITCH #if CORTEX_ALTERNATE_SWITCH
@ -135,25 +139,19 @@ waithere:
*/ */
PUBLIC _port_irq_epilogue PUBLIC _port_irq_epilogue
_port_irq_epilogue: _port_irq_epilogue:
push {r3, lr} push {lr}
adds r0, r0, #15 adds r0, r0, #15
beq stillnested beq skipexit
cpsid i cpsid i
bl chSchIsRescRequiredExI
cmp r0, #0
bne doresch
cpsie i
stillnested
pop {r3, pc}
doresch
mrs r3, PSP mrs r3, PSP
subs r3, r3, #32 subs r3, r3, #32
msr PSP, r3 msr PSP, r3
ldr r2, =_port_switch_from_isr ldr r2, =_port_switch_from_isr
str r2, [r3, #24] str r2, [r3, #24]
movs r2, #128 movs r2, #128
lsls r2, r2, #17 lsls r2, r2, #17
str r2, [r3, #28] str r2, [r3, #28]
pop {r3, pc} skipexit:
pop {pc}
END END

View File

@ -82,7 +82,10 @@ _port_thread_start:
*/ */
PUBLIC _port_switch_from_isr PUBLIC _port_switch_from_isr
_port_switch_from_isr: _port_switch_from_isr:
bl chSchIsRescRequiredExI
cbz r0, .L2
bl chSchDoRescheduleI bl chSchDoRescheduleI
.L2:
#if CORTEX_SIMPLIFIED_PRIORITY #if CORTEX_SIMPLIFIED_PRIORITY
mov r3, #LWRD SCB_ICSR mov r3, #LWRD SCB_ICSR
movt r3, #HWRD SCB_ICSR movt r3, #HWRD SCB_ICSR
@ -108,20 +111,16 @@ _port_irq_epilogue:
mov r3, #LWRD SCB_ICSR mov r3, #LWRD SCB_ICSR
movt r3, #HWRD SCB_ICSR movt r3, #HWRD SCB_ICSR
ldr r3, [r3, #0] ldr r3, [r3, #0]
tst r3, #ICSR_RETTOBASE ands r3, r3, #ICSR_RETTOBASE
bne .L7 bne .L8
#if CORTEX_SIMPLIFIED_PRIORITY #if CORTEX_SIMPLIFIED_PRIORITY
cpsie i cpsie i
#else #else
movs r3, #CORTEX_BASEPRI_DISABLED /* Note, R3 is already zero.*/
msr BASEPRI, r3 msr BASEPRI, r3
#endif #endif
bx lr bx lr
.L7: .L8:
push {r3, lr}
bl chSchIsRescRequiredExI
cmp r0, #0
beq .L4
mrs r3, PSP mrs r3, PSP
subs r3, r3, #EXTCTX_SIZE subs r3, r3, #EXTCTX_SIZE
msr PSP, r3 msr PSP, r3
@ -129,15 +128,7 @@ _port_irq_epilogue:
str r2, [r3, #24] str r2, [r3, #24]
mov r2, #0x01000000 mov r2, #0x01000000
str r2, [r3, #28] str r2, [r3, #28]
pop {r3, pc} bx lr
.L4:
#if CORTEX_SIMPLIFIED_PRIORITY
cpsie i
#else
movs r3, #CORTEX_BASEPRI_DISABLED
msr BASEPRI, r3
#endif
pop {r3, pc}
/* /*
* SVC vector. * SVC vector.

View File

@ -115,7 +115,11 @@ PendSVVector PROC
*/ */
EXPORT _port_switch_from_isr EXPORT _port_switch_from_isr
_port_switch_from_isr PROC _port_switch_from_isr PROC
bl chSchIsRescRequiredExI
cmp r0, #0
beq noresch
bl chSchDoRescheduleI bl chSchDoRescheduleI
noresch
ldr r2, =SCB_ICSR ldr r2, =SCB_ICSR
movs r3, #128 movs r3, #128
#if CORTEX_ALTERNATE_SWITCH #if CORTEX_ALTERNATE_SWITCH
@ -134,26 +138,20 @@ waithere b waithere
*/ */
EXPORT _port_irq_epilogue EXPORT _port_irq_epilogue
_port_irq_epilogue PROC _port_irq_epilogue PROC
push {r3, lr} push {lr}
adds r0, r0, #15 adds r0, r0, #15
beq stillnested beq skipexit
cpsid i cpsid i
bl chSchIsRescRequiredExI
cmp r0, #0
bne doresch
cpsie i
stillnested
pop {r3, pc}
doresch
mrs r3, PSP mrs r3, PSP
subs r3, r3, #32 subs r3, r3, #32
msr PSP, r3 msr PSP, r3
ldr r2, =_port_switch_from_isr ldr r2, =_port_switch_from_isr
str r2, [r3, #24] str r2, [r3, #24]
movs r2, #128 movs r2, #128
lsls r2, r2, #17 lsls r2, r2, #17
str r2, [r3, #28] str r2, [r3, #28]
pop {r3, pc} skipexit
pop {pc}
ENDP ENDP
END END

View File

@ -79,7 +79,10 @@ _port_thread_start PROC
*/ */
EXPORT _port_switch_from_isr EXPORT _port_switch_from_isr
_port_switch_from_isr PROC _port_switch_from_isr PROC
bl chSchIsRescRequiredExI
cbz r0, noreschedule
bl chSchDoRescheduleI bl chSchDoRescheduleI
noreschedule
#if CORTEX_SIMPLIFIED_PRIORITY #if CORTEX_SIMPLIFIED_PRIORITY
mov r3, #SCB_ICSR :AND: 0xFFFF mov r3, #SCB_ICSR :AND: 0xFFFF
movt r3, #SCB_ICSR :SHR: 16 movt r3, #SCB_ICSR :SHR: 16
@ -106,20 +109,16 @@ _port_irq_epilogue PROC
mov r3, #SCB_ICSR :AND: 0xFFFF mov r3, #SCB_ICSR :AND: 0xFFFF
movt r3, #SCB_ICSR :SHR: 16 movt r3, #SCB_ICSR :SHR: 16
ldr r3, [r3, #0] ldr r3, [r3, #0]
tst r3, #ICSR_RETTOBASE ands r3, r3, #ICSR_RETTOBASE
bne skipexit bne skipexit
#if CORTEX_SIMPLIFIED_PRIORITY #if CORTEX_SIMPLIFIED_PRIORITY
cpsie i cpsie i
#else #else
movs r3, #CORTEX_BASEPRI_DISABLED /* Note, R3 is already zero.*/
msr BASEPRI, r3 msr BASEPRI, r3
#endif #endif
bx lr bx lr
skipexit skipexit
push {r3, lr}
bl chSchIsRescRequiredExI
cmp r0, #0
beq noreschedule
mrs r3, PSP mrs r3, PSP
subs r3, r3, #EXTCTX_SIZE subs r3, r3, #EXTCTX_SIZE
msr PSP, r3 msr PSP, r3
@ -127,15 +126,7 @@ skipexit
str r2, [r3, #24] str r2, [r3, #24]
mov r2, #0x01000000 mov r2, #0x01000000
str r2, [r3, #28] str r2, [r3, #28]
pop {r3, pc} bx lr
noreschedule
#if CORTEX_SIMPLIFIED_PRIORITY
cpsie i
#else
movs r3, #CORTEX_BASEPRI_DISABLED
msr BASEPRI, r3
#endif
pop {r3, pc}
ENDP ENDP
/* /*
@ -152,6 +143,7 @@ SVCallVector PROC
movs r3, #CORTEX_BASEPRI_DISABLED movs r3, #CORTEX_BASEPRI_DISABLED
msr BASEPRI, r3 msr BASEPRI, r3
bx lr bx lr
nop
ENDP ENDP
#endif #endif

View File

@ -69,6 +69,7 @@
***************************************************************************** *****************************************************************************
*** 2.2.6 *** *** 2.2.6 ***
- FIX: Fixed race condition in Cortex-Mx ports (bug 3317500).
- FIX: Fixed wrong macro check in STM32 UART driver (bug 3311999). - FIX: Fixed wrong macro check in STM32 UART driver (bug 3311999).
*** 2.2.5 *** *** 2.2.5 ***