diff options
Diffstat (limited to 'nuttx/arch/z16/src')
-rw-r--r-- | nuttx/arch/z16/src/common/up_allocateheap.c | 8 | ||||
-rw-r--r-- | nuttx/arch/z16/src/common/up_initialize.c | 2 | ||||
-rw-r--r-- | nuttx/arch/z16/src/common/up_initialstate.c | 2 | ||||
-rw-r--r-- | nuttx/arch/z16/src/common/up_internal.h | 2 | ||||
-rw-r--r-- | nuttx/arch/z16/src/common/up_sigdeliver.c | 2 | ||||
-rwxr-xr-x | nuttx/arch/z16/src/z16f/z16f_head.S | 38 | ||||
-rwxr-xr-x | nuttx/arch/z16/src/z16f/z16f_restoreusercontext.S | 210 | ||||
-rw-r--r-- | nuttx/arch/z16/src/z16f/z16f_sysexec.c | 6 |
8 files changed, 147 insertions, 123 deletions
diff --git a/nuttx/arch/z16/src/common/up_allocateheap.c b/nuttx/arch/z16/src/common/up_allocateheap.c index 015b6c978..62d96e0b3 100644 --- a/nuttx/arch/z16/src/common/up_allocateheap.c +++ b/nuttx/arch/z16/src/common/up_allocateheap.c @@ -57,13 +57,13 @@ */ #ifndef CONFIG_HEAP1_BASE - extern _Far unsigned long far_heaptop; - #define CONFIG_HEAP1_BASE ((unsigned long)&far_heaptop) + extern _Far unsigned long far_heapbot; + #define CONFIG_HEAP1_BASE ((unsigned long)&far_heapbot) #endif #ifndef CONFIG_HEAP1_END - extern _Far unsigned long far_heapbot; - #define CONFIG_HEAP1_END ((unsigned long)&far_heapbot) + extern _Far unsigned long far_heaptop; + #define CONFIG_HEAP1_END ((unsigned long)&far_heaptop) #endif /**************************************************************************** diff --git a/nuttx/arch/z16/src/common/up_initialize.c b/nuttx/arch/z16/src/common/up_initialize.c index 0f54beb4f..8a30d33ad 100644 --- a/nuttx/arch/z16/src/common/up_initialize.c +++ b/nuttx/arch/z16/src/common/up_initialize.c @@ -66,7 +66,7 @@ * interrupt processing. */ -chipreg_t *current_regs; +FAR chipreg_t *current_regs; /**************************************************************************** * Private Types diff --git a/nuttx/arch/z16/src/common/up_initialstate.c b/nuttx/arch/z16/src/common/up_initialstate.c index acb5c31f1..d41e303bd 100644 --- a/nuttx/arch/z16/src/common/up_initialstate.c +++ b/nuttx/arch/z16/src/common/up_initialstate.c @@ -84,7 +84,7 @@ void up_initial_state(_TCB *tcb) memset(&tcb->xcp, 0, sizeof(struct xcptcontext)); #ifndef CONFIG_SUPPRESS_INTERRUPTS - tcb->xcp.regs[REG_FLAGS] = (uint16)(Z16F_CNTRL_FLAGS_IRQE << 8); /* IRQE flag will enable interrupts */ + tcb->xcp.regs[REG_FLAGS] = (uint16)Z16F_CNTRL_FLAGS_IRQE; /* IRQE flag will enable interrupts */ #endif reg32[REG_SP/2] = (uint32)tcb->adj_stack_ptr; reg32[REG_PC/2] = (uint32)tcb->start; diff --git a/nuttx/arch/z16/src/common/up_internal.h b/nuttx/arch/z16/src/common/up_internal.h index 206fdc98a..f6acb97a6 100644 --- a/nuttx/arch/z16/src/common/up_internal.h +++ b/nuttx/arch/z16/src/common/up_internal.h @@ -85,7 +85,7 @@ typedef void (*up_vector_t)(void); * interrupt processing. */ -extern chipreg_t *current_regs; +extern FAR chipreg_t *current_regs; #endif /**************************************************************************** diff --git a/nuttx/arch/z16/src/common/up_sigdeliver.c b/nuttx/arch/z16/src/common/up_sigdeliver.c index 8360b032a..59b40715d 100644 --- a/nuttx/arch/z16/src/common/up_sigdeliver.c +++ b/nuttx/arch/z16/src/common/up_sigdeliver.c @@ -118,7 +118,7 @@ void up_sigdeliver(void) /* Then restore the task interrupt state. */ - if ((reg[REG_FLAGS] & (Z16F_CNTRL_FLAGS_IRQE << 8)) != 0) + if ((reg[REG_FLAGS] & Z16F_CNTRL_FLAGS_IRQE) != 0) { EI(); } diff --git a/nuttx/arch/z16/src/z16f/z16f_head.S b/nuttx/arch/z16/src/z16f/z16f_head.S index 85bfc04ef..2a1871aae 100755 --- a/nuttx/arch/z16/src/z16f/z16f_head.S +++ b/nuttx/arch/z16/src/z16f/z16f_head.S @@ -270,12 +270,12 @@ _halt2: /* _z16f_sysexec() should not return */ _timer2_isr: pushmlo <r0-r7> /* Save r0-r7 on the stack */ - ld r1, #Z16F_IRQ_TIMER0 /* r1 = Timer 2 IRQ number */ + ld r1, #Z16F_IRQ_TIMER2 /* r1 = Timer 2 IRQ number */ jp _common_isr /* Join common interrupt handling logic */ _timer1_isr: pushmlo <r0-r7> /* Save r0-r7 on the stack */ - ld r1, #Z16F_IRQ_TIMER0 /* r1 = Timer 1 IRQ number */ + ld r1, #Z16F_IRQ_TIMER1 /* r1 = Timer 1 IRQ number */ jp _common_isr /* Join common interrupt handling logic */ _timer0_isr: @@ -397,7 +397,7 @@ _c0_isr: * * On entry: * - * r0 = IRQ number + * r1 = IRQ number * * And the stack contains the following: * @@ -409,8 +409,8 @@ _c0_isr: * TOS[20-23] = r5 * TOS[24-27] = r6 * TOS[28-31] = r7 - * TOS[32-33] = return PC - * TOS[34-35] = flags (with padding) + * TOS[32-35] = return PC + * TOS[36-37] = flags (with padding) * **************************************************************************/ @@ -419,9 +419,9 @@ _common_isr: * push that as the saved value of r15=sp */ - ld r1, #-36 /* See stack accounting above */ - add r1, sp /* r1 = Value of the SP before the interrupt */ - push r1 /* Push r1 in the spot for the saved SP */ + ld r2, #(9*4+2) /* See stack accounting above */ + add r2, sp /* r1 = Value of the SP before the interrupt */ + push r2 /* Push r1 in the spot for the saved SP */ /* Save all of the remaining registers */ @@ -439,16 +439,34 @@ _common_isr: * to use to return from the interrupt in r0. This may or may not be the * same value as sp. */ + + cp r0, sp /* Check if we are performing a context switch */ + jp nz, _common_switch /* Jump if yes, else use faster return */ + popmhi <r8-r14> /* Restore r8-r14 */ + add sp, #4 /* Skip over restore of r15=sp */ + popmlo <r0-r7> /* Restore r0-r7 */ + iret + /* We are not returning to the same thread that was interrupted. In this case, + * r0 is not in the stack but, instead, refers to a storage structure in the TCB + */ + +_common_switch: ld sp, 2*REG_SP(r0) /* sp=Value of SP on return from interrupt */ ld.w r1, 2*REG_FLAGS(r0) /* r1=padded flags value */ push.w r1 /* Push padded flags value onto the stack */ ld r1, 2*REG_PC(r0) /* r1=return address */ push r1 /* Push the return address onto the stack */ + ld r7, 2*REG_R7(r0) /* Recover saved r7 */ + push r7 /* And save on the stack so that we can use r7 */ + ld r7, sp /* r7=saved sp */ - ld sp, r0 /* sp=Value of SP at call to _up_doirq */ + ld sp, r0 /* sp=Pointer to register save structure */ popmhi <r8-r14> /* Restore r8-r14 */ - popmlo <r0-r7> /* Restore r0-r7 */ + add sp, #4 /* Skip over restore of r15=sp */ + popmlo <r0-r6> /* Restore r0-r6 */ + ld sp, r7 /* Switch back to the correct stack */ + pop r7 /* Recover r7 from the stack */ iret /* Return from interrupt */ end diff --git a/nuttx/arch/z16/src/z16f/z16f_restoreusercontext.S b/nuttx/arch/z16/src/z16f/z16f_restoreusercontext.S index 447ba1124..f983499ba 100755 --- a/nuttx/arch/z16/src/z16f/z16f_restoreusercontext.S +++ b/nuttx/arch/z16/src/z16f/z16f_restoreusercontext.S @@ -1,105 +1,105 @@ -/*************************************************************************
- * arch/z16/src/z16f/z16f_restoreusercontext.asm
- *
- * Copyright (C) 2008 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 "chip/chip.h"
-
-/*************************************************************************
- * External References / External Definitions
- *************************************************************************/
-
- xdef _up_restoreusercontext
-
-/*************************************************************************
- * Data Allocation
- *************************************************************************/
-
- define CODESEG, SPACE=EROM
- segment CODESEG
-
-/*************************************************************************
- * Code
- *************************************************************************/
-
-/*************************************************************************
- * Name: up_restoreusercontext
- *
- * Description:
- * Restore the current user context.
- *
- * Parameters:
- * r1: pointer to the register save array in the XCPT structure
- *
- *************************************************************************/
-
-_up_restoreusercontext:
- /* Disable interrupts throughout the following */
-
- di
-
- /* Set up the stack for return */
-
- ld sp, 2*REG_SP(r1) /* sp=Value of SP on return */
- ld r2, 2*REG_PC(r1) /* r2=return address */
- push r1 /* Push the return address onto the stack */
-
- /* Retore r8-r18 */
-
- ld sp, r1 /* sp=Value of SP at call to _up_doirq */
- popmhi <r8-r14> /* Restore r8-r14 */
-
- /* Test if interrupts should be enabled upon return */
-
- ld.w r2, 2*REG_FLAGS(r1) /* r2=padded flags value */
- tm r2, #(Z16F_CNTRL_FLAGS_IRQE << 8) /* Test (shifted) IRQE bit */
- jp z, _up_returndisabled /* Jump if interrupts should remain disabled */
-
- /* Return with interrupts enabled */
-
- popmlo <r0-r7> /* Restore r0-r7 */
- ei /* Enable interrupts and return */
- ret
-
- /* Return with interrupts disabled */
-
-_up_returndisabled:
- popmlo <r0-r7> /* Restore r0-r7 */
- ret
- end
+/************************************************************************* + * arch/z16/src/z16f/z16f_restoreusercontext.asm + * + * Copyright (C) 2008 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 "chip/chip.h" + +/************************************************************************* + * External References / External Definitions + *************************************************************************/ + + xdef _up_restoreusercontext + +/************************************************************************* + * Data Allocation + *************************************************************************/ + + define CODESEG, SPACE=EROM + segment CODESEG + +/************************************************************************* + * Code + *************************************************************************/ + +/************************************************************************* + * Name: up_restoreusercontext + * + * Description: + * Restore the current user context. + * + * Parameters: + * r1: pointer to the register save array in the XCPT structure + * + *************************************************************************/ + +_up_restoreusercontext: + /* Disable interrupts throughout the following */ + + di + + /* Set up the stack for return */ + + ld sp, 2*REG_SP(r1) /* sp=Value of SP on return */ + ld r2, 2*REG_PC(r1) /* r2=return address */ + push r1 /* Push the return address onto the stack */ + + /* Retore r8-r18 */ + + ld sp, r1 /* sp=Value of SP at call to _up_doirq */ + popmhi <r8-r14> /* Restore r8-r14 */ + + /* Test if interrupts should be enabled upon return */ + + ld.w r2, 2*REG_FLAGS(r1) /* r2=padded flags value */ + tm r2, #Z16F_CNTRL_FLAGS_IRQE /* Test IRQE bit */ + jp z, _up_returndisabled /* Jump if interrupts should remain disabled */ + + /* Return with interrupts enabled */ + + popmlo <r0-r7> /* Restore r0-r7 */ + ei /* Enable interrupts and return */ + ret + + /* Return with interrupts disabled */ + +_up_returndisabled: + popmlo <r0-r7> /* Restore r0-r7 */ + ret + end diff --git a/nuttx/arch/z16/src/z16f/z16f_sysexec.c b/nuttx/arch/z16/src/z16f/z16f_sysexec.c index 8ee91764c..e492bab6e 100644 --- a/nuttx/arch/z16/src/z16f/z16f_sysexec.c +++ b/nuttx/arch/z16/src/z16f/z16f_sysexec.c @@ -82,6 +82,12 @@ void z16f_sysexec(FAR chipreg_t *regs) { int errcode = OSERR_ERREXCEPTION; uint16 excp; + + /* Save that register reference so that it can be used for built-in + * diagnostics. + */ + + current_regs = regs; /* The cause of the the system exception is indicated in the SYSEXCPH&L * registers |