Ouss4 commented on a change in pull request #5541:
URL: https://github.com/apache/incubator-nuttx/pull/5541#discussion_r809863305



##########
File path: arch/xtensa/src/common/xtensa_swint.c
##########
@@ -94,16 +102,79 @@ int xtensa_svcall(int irq, void *context, void *arg)
 
       case SYS_save_context:
         {
+          DEBUGASSERT(regs[REG_A3] != 0);
+          memcpy((uint32_t *)regs[REG_A3], regs, (4 * XCPTCONTEXT_REGS));
         }
         break;
+
+      /* A2=SYS_restore_context:  This a restore context command:

Review comment:
       ```suggestion
         /* A2=SYS_restore_context:  This is a restore context command:
   ```

##########
File path: arch/xtensa/src/common/xtensa_swint.c
##########
@@ -94,16 +102,79 @@ int xtensa_svcall(int irq, void *context, void *arg)
 
       case SYS_save_context:
         {
+          DEBUGASSERT(regs[REG_A3] != 0);
+          memcpy((uint32_t *)regs[REG_A3], regs, (4 * XCPTCONTEXT_REGS));
         }
         break;
+
+      /* A2=SYS_restore_context:  This a restore context command:
+       *
+       * void xtensa_fullcontextrestore(uint32_t *restoreregs)
+       *      noreturn_function;
+       *
+       * At this point, the following values are saved in context:
+       *
+       *   A2 = SYS_restore_context
+       *   A3 = restoreregs
+       *
+       * In this case, we simply need to set CURRENT_REGS to restore
+       * register area referenced in the saved A3. context == CURRENT_REGS
+       * is the normal exception return.  By setting CURRENT_REGS =
+       * context[A3], we force the return to the saved context referenced
+       * in A3.
+       */
+
+      case SYS_restore_context:
+        {
+          DEBUGASSERT(regs[REG_A3] != 0);
+          CURRENT_REGS = (uint32_t *)regs[REG_A3];
+        }
+        break;
+
+      /* A2=SYS_switch_context:  This a switch context command:

Review comment:
       ```suggestion
         /* A2=SYS_switch_context:  This is a switch context command:
   ```

##########
File path: arch/xtensa/src/common/xtensa_swi.h
##########
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * arch/xtensa/src/common/xtensa_swi.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_XTENSA_SRC_COMMON_XTENSA_SWI_H
+#define __ARCH_XTENSA_SRC_COMMON_XTENSA_SWI_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <arch/xtensa/core.h>
+#include <arch/xtensa/xtensa_corebits.h>
+
+/* Select software interrupt number for context-switch.
+ * The SW interrupt level must larger than XCHAL_SYSCALL_LEVEL
+ * and not larger than XCHAL_EXCM_LEVEL.
+ * For that it can generate interupt when up_irq_save.
+ * and not generate interupt when up_irq_disable.
+ * Otherwise return error if no one interrupt find.
+ */

Review comment:
       ```suggestion
   /* Select the software interrupt number for context-switch.
    * The SW interrupt level must be greater than XCHAL_SYSCALL_LEVEL
    * and less than XCHAL_EXCM_LEVEL.
    * So that we can generate an interrupt when up_irq_save is called.
    * and not generate interrupt when up_irq_disable is called.
    * Return an error if no suitable software interrupt was found.
    */
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to