diff --git a/arch/z80/include/z8/irq.h b/arch/z80/include/z8/irq.h index 7e8dbf699e24788cb33d0384d000fae7cb112f0b..049c8b84cda5350ec6b7c45001f22885afa31b98 100644 --- a/arch/z80/include/z8/irq.h +++ b/arch/z80/include/z8/irq.h @@ -300,7 +300,7 @@ struct xcptcontext /* The following retains that state during signal execution */ uint16 saved_pc; /* Saved return address */ - uint16 saved_i; /* Saved interrupt state */ + uint16 saved_irqctl; /* Saved interrupt state */ #endif }; #endif diff --git a/arch/z80/src/common/up_arch.h b/arch/z80/src/common/up_arch.h index 5ef0b932c71a7437d6223b979751e05929e8dc5f..ff53010dbd820b3f424d52e0535a39f0c9b6b069 100644 --- a/arch/z80/src/common/up_arch.h +++ b/arch/z80/src/common/up_arch.h @@ -52,19 +52,4 @@ * Definitions ************************************************************************************/ -/************************************************************************************ - * Inline Functions - ************************************************************************************/ - -#ifndef __ASSEMBLY__ - -# define getreg8(a) (*(volatile ubyte *)(a)) -# define putreg8(v,a) (*(volatile ubyte *)(a) = (v)) -# define getreg32(a) (*(volatile uint32 *)(a)) -# define putreg32(v,a) (*(volatile uint32 *)(a) = (v)) -# define getreg(a) getreg16(1) -# define putreg(v,a) putreg16(v,a) - -#endif - #endif /* __UP_ARCH_H */ diff --git a/arch/z80/src/z8/chip.h b/arch/z80/src/z8/chip.h index 99b058404ca78041a16d6ce550e25270da727afd..be216f1e04f94592ff482ca10a80fff29f344029 100644 --- a/arch/z80/src/z8/chip.h +++ b/arch/z80/src/z8/chip.h @@ -45,6 +45,14 @@ * Definitions ************************************************************************************/ +/* Hexadecimal Representation *******************************************************/ + +#ifdef __ASSEMBLY__ +# define _HX(h) %##h +#else +# define _HX(w) 0x##h +#endif + /* Memory Map * * 64Kb Program Memory (64K series) @@ -60,6 +68,28 @@ * f00 - fff : 256 byte control register area */ +/* Special Function Registers ******************************************************* + * + * Because of the many different ez80 configurations, we will rely on the + * ZDS-II header file, ez8.h, to provide the correct addresses for each register. + */ + +/* Register access macros *********************************************************** + * + * The register access mechanism provided in ez8.h differs from the useful in other + * NuttX architectures. The following NuttX common macros will at least make the + * access compatible at the source level (however, strict type check is lost). + */ + +#ifndef __ASSEMBLY__ +# define getreg8(a) (a) +# define putreg8(v,a) ((a) = (v)) +# define getreg16(a) (a) +# define putreg16(v,a) ((a) = (v)) +# define getreg32(a) (a) +# define putreg32(v,a) ((a) = (v)) +#endif /* __ASSEMBLY__ */ + /************************************************************************************ * Public Function Prototypes ************************************************************************************/ diff --git a/arch/z80/src/z8/z8_irq.c b/arch/z80/src/z8/z8_irq.c index d3a46bf178c78411f4afe16f5b43957a1197e595..38f24a968675cfefc1f8f24631b0aa74876210ef 100644 --- a/arch/z80/src/z8/z8_irq.c +++ b/arch/z80/src/z8/z8_irq.c @@ -44,6 +44,8 @@ #include <nuttx/arch.h> #include <nuttx/irq.h> +#include <ez8.h> + #include "chip/switch.h" #include "up_internal.h" @@ -81,6 +83,19 @@ struct z8_irqstate_s g_z8irqstate; irqstate_t irqsave(void) { + /* Bit 7 (IRQE) of the IRQCTL register determines if interrupts were + * enabled when this function was called. + */ + + register irqstate_t retval = getreg8(IRQCTL); + + /* Disable interrupts */ + + DI(); + + /* Return the previous interrupt state */ + + return retval; } /**************************************************************************** @@ -93,4 +108,14 @@ irqstate_t irqsave(void) void irqrestore(irqstate_t flags) { + /* Bit 7 (IRQE) of the IRQCTL register determines if interrupts were + * enabled when irqsave() was called. + */ + + if ((flags & 0x80) != 0) + { + /* The IRQE bit was set, re-enable interrupts */ + + EI(); + } } diff --git a/arch/z80/src/z8/z8_schedulesigaction.c b/arch/z80/src/z8/z8_schedulesigaction.c index ad02f0137c51b803544eaf52e7031b1f2e547fa1..fd9e715202b5b2465597d7341332bbc8070cf509 100644 --- a/arch/z80/src/z8/z8_schedulesigaction.c +++ b/arch/z80/src/z8/z8_schedulesigaction.c @@ -76,12 +76,12 @@ static void z8_sigsetup(FAR _TCB *tcb, sig_deliver_t sigdeliver, FAR chipreg_t * tcb->xcp.sigdeliver = sigdeliver; tcb->xcp.saved_pc = regs[XCPT_PC]; - tcb->xcp.saved_i = regs[XCPT_I]; + tcb->xcp.saved_irqctl = regs[XCPT_IRQCTL]; /* Then set up to vector to the trampoline with interrupts disabled */ - regs[XCPT_PC] = (chipreg_t)up_sigdeliver; - regs[XCPT_I] = 0; + regs[XCPT_PC] = (chipreg_t)up_sigdeliver; + regs[XCPT_IRQCTL] = 0; } /**************************************************************************** diff --git a/arch/z80/src/z8/z8_sigdeliver.c b/arch/z80/src/z8/z8_sigdeliver.c index 857db51e5baf089b1ce10b0564794347729da52b..8ba3c552ebe8ed6ecd551c027cb6c6df44e0d8d7 100644 --- a/arch/z80/src/z8/z8_sigdeliver.c +++ b/arch/z80/src/z8/z8_sigdeliver.c @@ -64,6 +64,21 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: z8_copystate + ****************************************************************************/ + +/* Maybe a little faster than most memcpy's */ + +static void z8_copystate(FAR chipreg_t *dest, FAR const chipreg_t *src) +{ + int i; + for (i = 0; i < XCPTCONTEXT_REGS; i++) + { + *dest++ = *src++; + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -83,7 +98,7 @@ void up_sigdeliver(void) { #ifndef CONFIG_DISABLE_SIGNALS FAR _TCB *rtcb = (_TCB*)g_readytorun.head; - chipret_t regs[XCPTCONTEXT_REGS]; + chipreg_t regs[XCPTCONTEXT_REGS]; sig_deliver_t sigdeliver; /* Save the errno. This must be preserved throughout the signal handling @@ -102,8 +117,8 @@ void up_sigdeliver(void) /* Save the real return state on the stack. */ z8_copystate(regs, rtcb->xcp.regs); - regs[XCPT_PC] = rtcb->xcp.saved_pc; - regs[XCPT_I] = rtcb->xcp.saved_i; + regs[XCPT_PC] = rtcb->xcp.saved_pc; + regs[XCPT_IRQCTL] = rtcb->xcp.saved_irqctl; /* Get a local copy of the sigdeliver function pointer. We do this so * that we can nullify the sigdeliver function point in the TCB and accept @@ -115,7 +130,7 @@ void up_sigdeliver(void) /* Then restore the task interrupt state. */ - irqrestore(regs[XCPT_I]); + irqrestore(regs[XCPT_IRQCTL]); /* Deliver the signals */ @@ -134,7 +149,7 @@ void up_sigdeliver(void) */ up_ledoff(LED_SIGNAL); - z8_restoreusercontext(regs); + z8_restorecontext(regs); #endif } diff --git a/arch/z80/src/z80/chip.h b/arch/z80/src/z80/chip.h index d5c36bd19f43b47a25cebe0f5dda204144a6d809..b960e481fbcdaef5bb569aa6e258ad844d514699 100644 --- a/arch/z80/src/z80/chip.h +++ b/arch/z80/src/z80/chip.h @@ -45,7 +45,7 @@ * Definitions ************************************************************************************/ -/* Bits in the Z80 FLAGS register */ +/* Bits in the Z80 FLAGS register ***************************************************/ #define Z80_C_FLAG 0x01 /* Bit 0: Carry flag */ #define Z80_N_FLAG 0x02 /* Bit 1: Add/Subtract flag */ @@ -54,6 +54,18 @@ #define Z80_Z_FLAG 0x40 /* Bit 5: Zero flag */ #define Z80_S_FLAG 0x80 /* Bit 7: Sign flag */ +/* Register access macros ***********************************************************/ + +#ifndef __ASSEMBLY__ + +# define getreg8(a) (*(volatile ubyte *)(a)) +# define putreg8(v,a) (*(volatile ubyte *)(a) = (v)) +# define getreg32(a) (*(volatile uint32 *)(a)) +# define putreg32(v,a) (*(volatile uint32 *)(a) = (v)) +# define getreg(a) getreg16(1) +# define putreg(v,a) putreg16(v,a) + +#endif /************************************************************************************ * Public Function Prototypes ************************************************************************************/