2015-04-10 16:44:37 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2014 Wind River Systems, Inc.
|
|
|
|
*
|
2015-10-06 11:00:37 -05:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-04-10 16:44:37 -07:00
|
|
|
*
|
2015-10-06 11:00:37 -05:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-10 16:44:37 -07:00
|
|
|
*
|
2015-10-06 11:00:37 -05:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-04-10 16:44:37 -07:00
|
|
|
*/
|
|
|
|
|
2015-12-04 10:09:39 -05:00
|
|
|
/**
|
|
|
|
* @file
|
2016-10-05 19:43:36 -03:00
|
|
|
* @brief ARM CORTEX-M exception/interrupt exit API
|
2015-12-04 10:09:39 -05:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Provides functions for performing kernel handling when exiting exceptions or
|
|
|
|
* interrupts that are installed directly in the vector table (i.e. that are not
|
|
|
|
* wrapped around by _isr_wrapper()).
|
2015-07-01 17:22:39 -04:00
|
|
|
*/
|
2015-04-10 16:44:37 -07:00
|
|
|
|
|
|
|
#define _ASMLANGUAGE
|
|
|
|
|
2016-11-08 10:36:50 -05:00
|
|
|
#include <kernel_structs.h>
|
|
|
|
#include <offsets_short.h>
|
2015-04-10 16:44:37 -07:00
|
|
|
#include <toolchain.h>
|
2015-05-28 10:56:47 -07:00
|
|
|
#include <arch/cpu.h>
|
2015-04-10 16:44:37 -07:00
|
|
|
|
|
|
|
_ASM_FILE_PROLOGUE
|
|
|
|
|
|
|
|
GTEXT(_ExcExit)
|
|
|
|
GTEXT(_IntExit)
|
2016-11-08 10:36:50 -05:00
|
|
|
GDATA(_kernel)
|
2016-09-12 11:35:26 -04:00
|
|
|
GTEXT(_is_next_thread_current)
|
2016-09-02 16:20:19 -04:00
|
|
|
|
2015-04-10 16:44:37 -07:00
|
|
|
#if CONFIG_GDB_INFO
|
|
|
|
#define _EXIT_EXC_IF_FIBER_PREEMPTED beq _ExcExitWithGdbStub
|
|
|
|
#else
|
2016-10-05 19:43:36 -03:00
|
|
|
#define _EXIT_EXC_IF_FIBER_PREEMPTED beq _EXIT_EXC
|
2015-04-10 16:44:37 -07:00
|
|
|
#endif
|
|
|
|
#define _EXIT_EXC_IF_FIBER_NOT_READY _EXIT_EXC_IF_FIBER_PREEMPTED
|
|
|
|
|
2015-07-01 17:22:39 -04:00
|
|
|
/**
|
|
|
|
*
|
2015-07-01 17:51:40 -04:00
|
|
|
* @brief Kernel housekeeping when exiting interrupt handler installed
|
2015-07-01 17:22:39 -04:00
|
|
|
* directly in vector table
|
|
|
|
*
|
|
|
|
* Kernel allows installing interrupt handlers (ISRs) directly into the vector
|
|
|
|
* table to get the lowest interrupt latency possible. This allows the ISR to be
|
|
|
|
* invoked directly without going through a software interrupt table. However,
|
|
|
|
* upon exiting the ISR, some kernel work must still be performed, namely
|
|
|
|
* possible context switching. While ISRs connected in the software interrupt
|
|
|
|
* table do this automatically via a wrapper, ISRs connected directly in the
|
|
|
|
* vector table must invoke _IntExit() as the *very last* action before
|
|
|
|
* returning.
|
|
|
|
*
|
|
|
|
* e.g.
|
|
|
|
*
|
|
|
|
* void myISR(void)
|
|
|
|
* {
|
|
|
|
* printk("in %s\n", __FUNCTION__);
|
|
|
|
* doStuff();
|
|
|
|
* _IntExit();
|
|
|
|
* }
|
|
|
|
*
|
2015-07-01 17:29:04 -04:00
|
|
|
* @return N/A
|
2015-07-01 17:22:39 -04:00
|
|
|
*/
|
2015-04-10 16:44:37 -07:00
|
|
|
|
|
|
|
SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, _IntExit)
|
|
|
|
|
|
|
|
/* _IntExit falls through to _ExcExit (they are aliases of each other) */
|
|
|
|
|
|
|
|
|
2015-07-01 17:22:39 -04:00
|
|
|
/**
|
|
|
|
*
|
2015-07-01 17:51:40 -04:00
|
|
|
* @brief Kernel housekeeping when exiting exception handler installed
|
2015-07-01 17:22:39 -04:00
|
|
|
* directly in vector table
|
|
|
|
*
|
|
|
|
* See _IntExit().
|
|
|
|
*
|
2015-07-01 17:29:04 -04:00
|
|
|
* @return N/A
|
2015-07-01 17:22:39 -04:00
|
|
|
*/
|
2015-04-10 16:44:37 -07:00
|
|
|
|
|
|
|
SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, _ExcExit)
|
|
|
|
|
2016-11-08 10:36:50 -05:00
|
|
|
ldr r1, =_kernel
|
2015-04-10 16:44:37 -07:00
|
|
|
|
2016-11-08 10:36:50 -05:00
|
|
|
ldr r1, [r1, #_kernel_offset_to_current]
|
|
|
|
ldr r2, [r1, #_thread_offset_to_prio]
|
|
|
|
ldr r3, [r1, #_thread_offset_to_sched_locked]
|
2016-09-02 16:20:19 -04:00
|
|
|
|
2016-11-03 13:00:41 -07:00
|
|
|
/* coop thread ? do not schedule */
|
|
|
|
cmp r2, #0
|
|
|
|
blt _EXIT_EXC
|
2016-09-02 16:20:19 -04:00
|
|
|
|
2016-11-03 13:00:41 -07:00
|
|
|
/* scheduler locked ? do not schedule */
|
|
|
|
cmp r3, #0
|
|
|
|
bgt _EXIT_EXC
|
2016-09-02 16:20:19 -04:00
|
|
|
|
2016-11-03 13:00:41 -07:00
|
|
|
push {lr}
|
2016-11-14 13:48:13 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* _is_next_thread_current() calls _get_next_ready_thread(), which is
|
|
|
|
* supposed to be called only with interrupts locked: interrupts are _not_
|
|
|
|
* locked at this point. However, that is not a problem in this case:
|
|
|
|
*
|
|
|
|
* - Threads can only be added to the ready queue in an ISR, not removed.
|
|
|
|
* Thus, priorities with runnable thread can only be added as well.
|
|
|
|
*
|
|
|
|
* - The PendSV handler is the context that will decide which thread to
|
|
|
|
* run, not the current context.
|
|
|
|
*
|
|
|
|
* - The current decision to pend PendSV or not is started with the ready
|
|
|
|
* queue state that the currently exiting ISR updated: if that state
|
|
|
|
* changes, it can only be to add a thread as runnable, not remove one.
|
|
|
|
*
|
|
|
|
* - The only discrepancy that can happen is if another ISR preempts the
|
|
|
|
* current one and makes another thread than the current the next thread
|
|
|
|
* to run, if the current ISR did not do already that. In that case, even
|
|
|
|
* if the decision is interrupted, the current code running in the higher
|
|
|
|
* priority ISR _will_ take the correct decision to pend PendSV.
|
|
|
|
*/
|
2016-11-03 13:00:41 -07:00
|
|
|
blx _is_next_thread_current
|
2016-10-05 19:43:36 -03:00
|
|
|
#if defined(CONFIG_CPU_CORTEX_M0_M0PLUS)
|
2016-11-03 13:00:41 -07:00
|
|
|
pop {r1}
|
|
|
|
mov lr, r1
|
2016-10-05 19:43:36 -03:00
|
|
|
#else
|
2016-11-03 13:00:41 -07:00
|
|
|
pop {lr}
|
2016-10-05 19:43:36 -03:00
|
|
|
#endif /* CONFIG_CPU_CORTEX_M0_M0PLUS */
|
2016-11-03 13:00:41 -07:00
|
|
|
cmp r0, #0
|
|
|
|
bne _EXIT_EXC
|
2016-09-02 16:20:19 -04:00
|
|
|
|
2015-04-10 16:44:37 -07:00
|
|
|
/* context switch required, pend the PendSV exception */
|
|
|
|
ldr r1, =_SCS_ICSR
|
|
|
|
ldr r2, =_SCS_ICSR_PENDSV
|
|
|
|
str r2, [r1]
|
|
|
|
|
|
|
|
_ExcExitWithGdbStub:
|
|
|
|
|
|
|
|
_GDB_STUB_EXC_EXIT
|
|
|
|
|
2016-10-05 19:43:36 -03:00
|
|
|
_EXIT_EXC:
|
|
|
|
|
2015-04-10 16:44:37 -07:00
|
|
|
bx lr
|