From 017ed0b582f6170bd0eb1c2b503cc3e7efc07e60 Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Fri, 5 Nov 2010 02:18:32 +0000
Subject: [PATCH] Fix excepion handling reg save

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3074 42af7a65-404d-4744-a932-0658087f49c3
---
 arch/avr/src/avr32/up_exceptions.S         | 4 ++--
 arch/avr/src/avr32/up_fullcontextrestore.S | 5 ++++-
 arch/avr/src/avr32/up_sigdeliver.c         | 8 +++++++-
 configs/avr32dev1/README.txt               | 4 ++++
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/avr/src/avr32/up_exceptions.S b/arch/avr/src/avr32/up_exceptions.S
index d7686e3d0a..4a7ade6fde 100755
--- a/arch/avr/src/avr32/up_exceptions.S
+++ b/arch/avr/src/avr32/up_exceptions.S
@@ -233,8 +233,8 @@ avr32_xcptcommon:
 /*     xx xx xx xx xx xx xx xx xx SR PC LI 12 11 10 SR PC                   */
 /*                                ^                       ^+8*4             */
 
-	ld.w	r11, sp[4*4]
-	ld.w	r12, sp[5*4]
+	ld.w	r12, sp[4*4]
+	ld.w	r11, sp[5*4]
 	stm		--sp, r11-r12
 
 /* Save r8 and r8:                                                          */
diff --git a/arch/avr/src/avr32/up_fullcontextrestore.S b/arch/avr/src/avr32/up_fullcontextrestore.S
index c883c58c7e..3d99721801 100755
--- a/arch/avr/src/avr32/up_fullcontextrestore.S
+++ b/arch/avr/src/avr32/up_fullcontextrestore.S
@@ -70,7 +70,10 @@
  *      pointer (hence, interrupts must be disabled), and (b) there is the
  *      very real possibility that the new stack pointer might overlap with
  *      the register save area and stack usage in this function might corrupt
- *      the register save data before the state is restored.
+ *      the register save data before the state is restored.  It turns that
+ *      an extra 3 words in the register save structure size will protect its
+ *      contents (because that is the number of temporaries pushed onto the
+ *      stack).
  *
  * Input Parameters:
  *   r12 = A pointer to the register save area of the thread to be restored.
diff --git a/arch/avr/src/avr32/up_sigdeliver.c b/arch/avr/src/avr32/up_sigdeliver.c
index b000f118a8..c886694829 100644
--- a/arch/avr/src/avr32/up_sigdeliver.c
+++ b/arch/avr/src/avr32/up_sigdeliver.c
@@ -82,7 +82,11 @@
 void up_sigdeliver(void)
 {
   _TCB  *rtcb = (_TCB*)g_readytorun.head;
+#if 0
   uint32_t regs[XCPTCONTEXT_REGS+3];  /* Why +3? See below */
+#else
+  uint32_t regs[XCPTCONTEXT_REGS];
+#endif
   sig_deliver_t sigdeliver;
 
   /* Save the errno.  This must be preserved throughout the signal handling
@@ -140,7 +144,9 @@ void up_sigdeliver(void)
    *      dangerous because there is the very real possibility that the new
    *      stack pointer might overlap with the register save area and hat stack
    *      usage in up_fullcontextrestore might corrupt the register save data
-   *      before the state is restored.
+   *      before the state is restored.  At present, there does not appear to
+   *      be any stack overlap problems.  If there were, then adding 3 words
+   *      to the size of register save structure size will protect its contents.
    */
 
   up_ledoff(LED_SIGNAL);
diff --git a/configs/avr32dev1/README.txt b/configs/avr32dev1/README.txt
index 98e65c231e..8b3cc271ad 100755
--- a/configs/avr32dev1/README.txt
+++ b/configs/avr32dev1/README.txt
@@ -432,4 +432,8 @@ Where <subdir> is one of the following:
     This configuration directory, performs a simple OS test using
     examples/ostest.
 
+    NOTE: Round-robin scheduling is disabled in this test because
+    the RR test in examples/ostest declares data structures that
+    are too large for the poor little uc3 SRAM.
+
 
-- 
GitLab