From 8f88c268c2e343fee167be7ccaba5520532faad1 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 26 Dec 2011 16:24:43 +0000 Subject: [PATCH] Fix an PIC32 error in scheduling of signal handlers git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4229 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- apps/examples/ostest/mqueue.c | 6 ++--- nuttx/arch/mips/src/common/up_exit.c | 13 +++++++--- .../mips/src/mips32/up_schedulesigaction.c | 24 ++++++++++++------- nuttx/arch/mips/src/mips32/up_sigdeliver.c | 5 ++-- nuttx/sched/pthread_completejoin.c | 10 ++++---- nuttx/sched/pthread_exit.c | 8 ++++--- nuttx/sched/pthread_join.c | 4 ++-- nuttx/sched/pthread_kill.c | 8 +++---- nuttx/sched/sig_kill.c | 2 +- nuttx/sched/sig_received.c | 2 +- 10 files changed, 50 insertions(+), 32 deletions(-) diff --git a/apps/examples/ostest/mqueue.c b/apps/examples/ostest/mqueue.c index 95e6bbfc83..39ef76a53b 100644 --- a/apps/examples/ostest/mqueue.c +++ b/apps/examples/ostest/mqueue.c @@ -1,8 +1,8 @@ /************************************************************************** * apps/examples/ostest/mqueue.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -219,7 +219,7 @@ static void *receiver_thread(void *arg) } else { - printf("receiver_thread: mq_receive interrupted!\n", i); + printf("receiver_thread: mq_receive interrupted!\n"); } } else if (nbytes != TEST_MSGLEN) diff --git a/nuttx/arch/mips/src/common/up_exit.c b/nuttx/arch/mips/src/common/up_exit.c index cf6b25fda4..f82b473304 100644 --- a/nuttx/arch/mips/src/common/up_exit.c +++ b/nuttx/arch/mips/src/common/up_exit.c @@ -1,8 +1,8 @@ /**************************************************************************** - * arch/mips/src.common/up_exit.c + * arch/mips/src/common/up_exit.c * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -171,5 +172,11 @@ void _exit(int status) /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); + + /* up_fullcontextrestore() should not return but could if the software + * interrupts are disabled. + */ + + PANIC(OSERR_INTERNAL); } diff --git a/nuttx/arch/mips/src/mips32/up_schedulesigaction.c b/nuttx/arch/mips/src/mips32/up_schedulesigaction.c index 7f4f0a0c98..f81fd890a7 100644 --- a/nuttx/arch/mips/src/mips32/up_schedulesigaction.c +++ b/nuttx/arch/mips/src/mips32/up_schedulesigaction.c @@ -2,7 +2,7 @@ * arch/mips/src/mips32/up_schedulesigaction.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -150,9 +150,9 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) else { - /* Save the return lr and cpsr and one scratch register - * These will be restored by the signal trampoline after - * the signals have been delivered. + /* Save the return EPC and STATUS registers. These will be + * restored by the signal trampoline after the signals have + * been delivered. */ tcb->xcp.sigdeliver = sigdeliver; @@ -174,6 +174,10 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) */ up_savestate(tcb->xcp.regs); + + svdbg("PC/STATUS Saved: %08x/%08x New: %08x/%08x\n", + tcb->xcp.saved_epc, tcb->xcp.saved_status, + current_regs[REG_EPC], current_regs[REG_STATUS]); } } @@ -185,9 +189,9 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) else { - /* Save the return lr and cpsr and one scratch register - * These will be restored by the signal trampoline after - * the signals have been delivered. + /* Save the return EPC and STATUS registers. These will be + * restored by the signal trampoline after the signals have + * been delivered. */ tcb->xcp.sigdeliver = sigdeliver; @@ -199,10 +203,14 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) */ tcb->xcp.regs[REG_EPC] = (uint32_t)up_sigdeliver; - status = current_regs[REG_STATUS]; + status = tcb->xcp.regs[REG_STATUS]; status &= ~CP0_STATUS_IM_MASK; status |= CP0_STATUS_IM_SWINTS; tcb->xcp.regs[REG_STATUS] = status; + + svdbg("PC/STATUS Saved: %08x/%08x New: %08x/%08x\n", + tcb->xcp.saved_epc, tcb->xcp.saved_status, + tcb->xcp.regs[REG_EPC], tcb->xcp.regs[REG_STATUS]); } irqrestore(flags); diff --git a/nuttx/arch/mips/src/mips32/up_sigdeliver.c b/nuttx/arch/mips/src/mips32/up_sigdeliver.c index 7a291b58ba..cf0ac944eb 100644 --- a/nuttx/arch/mips/src/mips32/up_sigdeliver.c +++ b/nuttx/arch/mips/src/mips32/up_sigdeliver.c @@ -2,7 +2,7 @@ * arch/mips/src/mips32/up_sigdeliver.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -126,7 +126,8 @@ void up_sigdeliver(void) * errno that is needed by the user logic (it is probably EINTR). */ - sdbg("Resuming\n"); + svdbg("Resuming EPC: %08x STATUS: %08x\n", regs[REG_EPC], regs[REG_STATUS]); + (void)irqsave(); rtcb->pterrno = saved_errno; diff --git a/nuttx/sched/pthread_completejoin.c b/nuttx/sched/pthread_completejoin.c index fff3b46cf2..fa7c2a443a 100644 --- a/nuttx/sched/pthread_completejoin.c +++ b/nuttx/sched/pthread_completejoin.c @@ -1,8 +1,8 @@ /************************************************************************ * sched/pthread_completejoin.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -83,7 +83,7 @@ static bool pthread_notifywaiters(FAR join_t *pjoin) int ntasks_waiting; int status; - sdbg("pjoin=0x%p\n", pjoin); + svdbg("pjoin=0x%p\n", pjoin); /* Are any tasks waiting for our exit value? */ @@ -148,7 +148,7 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) { FAR join_t *pjoin; - sdbg("process_id=%d exit_value=%p\n", pid, exit_value); + svdbg("pid=%d exit_value=%p\n", pid, exit_value); /* First, find thread's structure in the private data set. */ @@ -156,7 +156,7 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) pjoin = pthread_findjoininfo(pid); if (!pjoin) { - + sdbg("Could not find join info, pid=%d\n", pid); (void)pthread_givesemaphore(&g_join_semaphore); return ERROR; } diff --git a/nuttx/sched/pthread_exit.c b/nuttx/sched/pthread_exit.c index c320bbb104..31ac623627 100644 --- a/nuttx/sched/pthread_exit.c +++ b/nuttx/sched/pthread_exit.c @@ -1,8 +1,8 @@ /************************************************************************ * sched/pthread_exit.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,7 +45,9 @@ #include #include #include + #include + #include "pthread_internal.h" /************************************************************************ @@ -111,7 +113,7 @@ void pthread_exit(FAR void *exit_value) status = pthread_completejoin(getpid(), exit_value); if (status != OK) { - /* Assume that the join completion failured becuase this + /* Assume that the join completion failured because this * not really a pthread. Exit by calling exit() to flush * and close all file descriptors and calling atexit() * functions. diff --git a/nuttx/sched/pthread_join.c b/nuttx/sched/pthread_join.c index 4684b4f98c..b4f60a7c95 100644 --- a/nuttx/sched/pthread_join.c +++ b/nuttx/sched/pthread_join.c @@ -1,8 +1,8 @@ /**************************************************************************** * pthread_join.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/sched/pthread_kill.c b/nuttx/sched/pthread_kill.c index 171b309420..f876220f7a 100644 --- a/nuttx/sched/pthread_kill.c +++ b/nuttx/sched/pthread_kill.c @@ -1,8 +1,8 @@ /************************************************************************ * sched/pthread_kill.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -83,11 +83,11 @@ int pthread_kill(pthread_t thread, int signo) { int ret; - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); ret = kill((pid_t)thread, signo); if (ret != OK) { - ret = *get_errno_ptr(); + ret = get_errno(); } return ret; } diff --git a/nuttx/sched/sig_kill.c b/nuttx/sched/sig_kill.c index 5e91250883..1573a17a96 100644 --- a/nuttx/sched/sig_kill.c +++ b/nuttx/sched/sig_kill.c @@ -2,7 +2,7 @@ * sched/sig_kill.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/sched/sig_received.c b/nuttx/sched/sig_received.c index 26727dfbcf..f92e07146b 100644 --- a/nuttx/sched/sig_received.c +++ b/nuttx/sched/sig_received.c @@ -2,7 +2,7 @@ * sched/sig_received.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions