Add basic context switching logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1777 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
2827157b5f
commit
b0211916c7
@ -45,9 +45,9 @@ CMN_CSRCS = up_allocateheap.c up_assert.c up_blocktask.c up_copystate.c \
|
||||
up_sigdeliver.c up_syscall.c up_unblocktask.c \
|
||||
up_undefinedinsn.c up_usestack.c
|
||||
|
||||
CHIP_ASRCS =
|
||||
CHIP_CSRCS = lm3s_start.c lm3s_syscontrol.c lm3s_irq.c lm3s_timerisr.c \
|
||||
lm3s_lowputc.c lm3s_serial.c
|
||||
CHIP_ASRCS = lm3s_context.S
|
||||
CHIP_CSRCS = lm3s_start.c lm3s_syscontrol.c lm3s_irq.c lm3s_pendsv.c \
|
||||
lm3s_timerisr.c lm3s_lowputc.c lm3s_serial.c
|
||||
|
||||
ifdef CONFIG_NET
|
||||
CHIP_CSRCS += lm3s_ethernet.c
|
||||
|
145
arch/arm/src/lm3s/lm3s_context.S
Normal file
145
arch/arm/src/lm3s/lm3s_context.S
Normal file
@ -0,0 +1,145 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/lm3s/lm3s_context.S
|
||||
* arch/arm/src/chip/lm3s_context.S
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <arch/irq.h>
|
||||
#include "cortexm3_nvic.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Preprocessor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Global Symbols
|
||||
************************************************************************************/
|
||||
|
||||
.syntax unified
|
||||
.thumb
|
||||
.file "lm3s_context.S"
|
||||
|
||||
/************************************************************************************
|
||||
* Macros
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Name: up_saveusercontext
|
||||
*
|
||||
* Description:
|
||||
* Save the current thread context. Full prototype is:
|
||||
*
|
||||
* int up_saveusercontext(uint32 *regs);
|
||||
*
|
||||
* Return:
|
||||
* 0: Normal return
|
||||
* 1: Context switch return
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
.text
|
||||
.thumb_func
|
||||
.globl up_saveusercontext
|
||||
.type up_saveusercontext, function
|
||||
up_saveusercontext:
|
||||
|
||||
/* Perform the System call with R0=0 and R1=regs */
|
||||
|
||||
ldr r2, nvic_intctrl /* R2: Address NVIC INTCTRL registers */
|
||||
ldr r3, [r2, #0] /* R3: Contentx of NVIC INCTRL */
|
||||
orr r3, r3, #NVIC_INTCTRL_PENDSVSET
|
||||
mov r1, r0 /* R1: regs */
|
||||
mov r0, #0 /* R0: 0 means save context (also return value) */
|
||||
str r3, [r2, #0] /* Force Pend SV */
|
||||
|
||||
/* There are two return conditions. On the first return, R0 (the
|
||||
* return value will be zero. On the second return we need to
|
||||
* force R0 to be 1.
|
||||
*/
|
||||
|
||||
add r2, r1, #(4*REG_R0)
|
||||
mov r3, #1
|
||||
str r3, [r2, #0]
|
||||
bx lr /* "normal" return with r0=0 or
|
||||
* context switch with r0=1 */
|
||||
.size up_saveusercontext, .-up_saveusercontext
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Name: up_fullcontextrestore
|
||||
*
|
||||
* Description:
|
||||
* Restore the current thread context. Full prototype is:
|
||||
*
|
||||
* void up_fullcontextrestore(uint32 *regs) __attribute__ ((noreturn));
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
.thumb_func
|
||||
.globl up_fullcontextrestore
|
||||
.type up_fullcontextrestore, function
|
||||
up_fullcontextrestore:
|
||||
|
||||
/* Perform the System call with R0=1 and R1=regs */
|
||||
|
||||
ldr r2, nvic_intctrl /* R2: Address NVIC INTCTRL registers */
|
||||
ldr r3, [r2, #0] /* R3: Contentx of NVIC INCTRL */
|
||||
orr r3, r3, #NVIC_INTCTRL_PENDSVSET
|
||||
mov r1, r0 /* R1: regs */
|
||||
mov r0, #1 /* R0: 1 means restore context */
|
||||
str r3, [r2, #0] /* Force Pend SV */
|
||||
|
||||
/* These call should not return */
|
||||
|
||||
bx lr /* Unnecessary ... will not return */
|
||||
.size up_fullcontextrestore, .-up_fullcontextrestore
|
||||
|
||||
.align 2
|
||||
.type nvic_intctrl, object
|
||||
nvic_intctrl:
|
||||
.word NVIC_INTCTRL
|
||||
.size nvic_intctrl, .-nvic_intctrl
|
||||
.end
|
||||
|
@ -43,6 +43,10 @@
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
#include "lm3s_memorymap.h"
|
||||
#include "lm3s_gpio.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Definitions
|
||||
************************************************************************************/
|
||||
@ -247,6 +251,15 @@ EXTERN void up_clockconfig(void);
|
||||
|
||||
EXTERN int lm3s_configgpio(uint32 bitset);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm3s_pendsv
|
||||
*
|
||||
* Description:
|
||||
* This is PendSV exception handler that performs context switching
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int lm3s_pendsv(int irq, FAR void *context);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
@ -173,6 +173,12 @@ void up_irqinitialize(void)
|
||||
|
||||
current_regs = NULL;
|
||||
|
||||
/* Attach the PendSV exception handler. This is used for performing
|
||||
* context switches.
|
||||
*/
|
||||
|
||||
irq_attach(LMSB_IRQ_PENDSV, lm3s_pendsv);
|
||||
|
||||
/* Attach all processor exceptions (except reset and sys tick) */
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
@ -183,7 +189,6 @@ void up_irqinitialize(void)
|
||||
irq_attach(LMSB_IRQ_USAGEFAULT, lm3s_usagefault);
|
||||
irq_attach(LMSB_IRQ_SVCALL, lm3s_svcall);
|
||||
irq_attach(LMSB_IRQ_DBGMONITOR, lm3s_dbgmonitor);
|
||||
irq_attach(LMSB_IRQ_PENDSV, lm3s_pendsv);
|
||||
irq_attach(LMSB_IRQ_RESERVED, lm3s_reserved);
|
||||
#endif
|
||||
|
||||
@ -368,14 +373,6 @@ int lm3s_dbgmonitor(int irq, FAR void *context)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lm3s_pendsv(int irq, FAR void *context)
|
||||
{
|
||||
(void)irqsave();
|
||||
dbg("PANIC!!! PendSV received\n");
|
||||
PANIC(OSERR_UNEXPECTEDISR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lm3s_reserved(int irq, FAR void *context)
|
||||
{
|
||||
(void)irqsave();
|
||||
|
118
arch/arm/src/lm3s/lm3s_pendsv.c
Normal file
118
arch/arm/src/lm3s/lm3s_pendsv.c
Normal file
@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/lm3s/lm3s_pendsv.c
|
||||
* arch/arm/src/chip/lm3s_pendsv.c
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <arch/irq.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#include "lm3s_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm3xs_pendxv
|
||||
*
|
||||
* Description:
|
||||
* This is PendSV exception handler that performs context switching
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int lm3s_pendsv(int irq, FAR void *context)
|
||||
{
|
||||
uint32 *svregs = (uint32*)context;
|
||||
uint32 *tcbregs = (uint32*)svregs[REG_R1];
|
||||
|
||||
DEBUGASSERT(svregs && svregs == current_regs && tcbregs);
|
||||
|
||||
/* The PendSV software interrupt is called with R0 = PendSV command and R1 =
|
||||
* the TCB register save area.
|
||||
*/
|
||||
|
||||
switch (svregs[REG_R0])
|
||||
{
|
||||
/* R0=0: This is a save context command. In this case, we simply need
|
||||
* to copy the svregs to the tdbregs and return.
|
||||
*/
|
||||
|
||||
case 0:
|
||||
memcpy(tcbregs, svregs, XCPTCONTEXT_SIZE);
|
||||
break;
|
||||
|
||||
/* R1=1: This a restore context command. In this case, we simply need to
|
||||
* set current_regs to tcbrgs. svregs == current_regs is the normal exception
|
||||
* turn. By setting current_regs = tcbregs, we force the return through
|
||||
* the saved context.
|
||||
*/
|
||||
|
||||
case 1:
|
||||
current_regs = tcbregs;
|
||||
break;
|
||||
|
||||
default:
|
||||
PANIC(OSERR_INTERNAL);
|
||||
break;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/lm3s/lm3slm3s_vectors.S
|
||||
* arch/arm/src/lm3s/lm3s_vectors.S
|
||||
* arch/arm/src/chip/lm3s_vectors.S
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
|
Loading…
Reference in New Issue
Block a user