You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/01/27 09:36:35 UTC

[incubator-nuttx] 01/03: sched/tcbinfo: Fix the compile warning

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit f903a5510277b312469fd9aff7f744108ac71f1e
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Dec 27 11:09:38 2021 +0800

    sched/tcbinfo: Fix the compile warning
    
    Update tcbinfo struct
    
    armv8-m/arm_tcbinfo.c:109:3: warning: excess elements in struct initializer
      109 |   TCB_REG_OFF(REG_S31),
          |   ^~~~~~~~~~~
    armv8-m/arm_tcbinfo.c:109:3: note: (near initialization for 'g_tcbinfo')
    armv8-m/arm_tcbinfo.c:110:3: warning: excess elements in struct initializer
      110 |   0,
          |   ^
    armv8-m/arm_tcbinfo.c:110:3: note: (near initialization for 'g_tcbinfo')
    armv8-m/arm_tcbinfo.c:111:3: warning: excess elements in struct initializer
      111 |   TCB_REG_OFF(REG_FPSCR),
          |   ^~~~~~~~~~~
    armv8-m/arm_tcbinfo.c:111:3: note: (near initialization for 'g_tcbinfo')
    armv8-m/arm_tcbinfo.c:112:3: warning: excess elements in struct initializer
      112 |   0,
          |   ^
    armv8-m/arm_tcbinfo.c:112:3: note: (near initialization for 'g_tcbinfo')
    armv8-m/arm_tcbinfo.c:37:1: warning: missing braces around initializer [-Wmissing-braces]
       37 | {
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Signed-off-by: zhuyanlin <zh...@xiaomi.com>
---
 arch/arm/src/arm/arm_tcbinfo.c         | 29 +++++++++++++++---------
 arch/arm/src/armv6-m/arm_tcbinfo.c     | 37 +++++++++++++++++-------------
 arch/arm/src/armv7-a/arm_tcbinfo.c     | 31 ++++++++++++++-----------
 arch/arm/src/armv7-m/arm_tcbinfo.c     | 41 +++++++++++++++++++---------------
 arch/arm/src/armv7-r/arm_tcbinfo.c     | 31 ++++++++++++++-----------
 arch/arm/src/armv8-m/arm_tcbinfo.c     | 41 +++++++++++++++++++---------------
 arch/risc-v/src/common/riscv_tcbinfo.c | 35 +++++++++++++++++------------
 binfmt/libelf/libelf_coredump.c        |  2 +-
 include/nuttx/sched.h                  | 20 +++++++++++------
 9 files changed, 157 insertions(+), 110 deletions(-)

diff --git a/arch/arm/src/arm/arm_tcbinfo.c b/arch/arm/src/arm/arm_tcbinfo.c
index 2438ded..ad350f5 100644
--- a/arch/arm/src/arm/arm_tcbinfo.c
+++ b/arch/arm/src/arm/arm_tcbinfo.c
@@ -30,20 +30,11 @@
 #include <arch/irq.h>
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
-const struct tcbinfo_s g_tcbinfo =
+static const uint16_t g_reg_offs[] =
 {
-  TCB_PID_OFF,
-  TCB_STATE_OFF,
-  TCB_PRI_OFF,
-#if CONFIG_TASK_NAME_SIZE > 0
-  TCB_NAME_OFF,
-#endif
-
-  XCPTCONTEXT_REGS,
-
   TCB_REG_OFF(REG_R0),
   TCB_REG_OFF(REG_R1),
   TCB_REG_OFF(REG_R2),
@@ -63,6 +54,22 @@ const struct tcbinfo_s g_tcbinfo =
   TCB_REG_OFF(REG_CPSR),
 };
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+const struct tcbinfo_s g_tcbinfo =
+{
+  TCB_PID_OFF,
+  TCB_STATE_OFF,
+  TCB_PRI_OFF,
+  TCB_NAME_OFF,
+  XCPTCONTEXT_REGS,
+  {
+    .p = g_reg_offs,
+  },
+};
+
 #endif
 
 /****************************************************************************
diff --git a/arch/arm/src/armv6-m/arm_tcbinfo.c b/arch/arm/src/armv6-m/arm_tcbinfo.c
index 989fd35..c9f1b2a 100644
--- a/arch/arm/src/armv6-m/arm_tcbinfo.c
+++ b/arch/arm/src/armv6-m/arm_tcbinfo.c
@@ -30,20 +30,11 @@
 #include <arch/irq.h>
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
-const struct tcbinfo_s g_tcbinfo =
+static const uint16_t g_reg_offs[] =
 {
-  TCB_PID_OFF,
-  TCB_STATE_OFF,
-  TCB_PRI_OFF,
-#if CONFIG_TASK_NAME_SIZE > 0
-  TCB_NAME_OFF,
-#endif
-
-  XCPTCONTEXT_REGS,
-
   TCB_REG_OFF(REG_R0),
   TCB_REG_OFF(REG_R1),
   TCB_REG_OFF(REG_R2),
@@ -62,12 +53,28 @@ const struct tcbinfo_s g_tcbinfo =
   TCB_REG_OFF(REG_R15),
   TCB_REG_OFF(REG_XPSR),
 
-  0,
+  0,                        /* msp */
   TCB_REG_OFF(REG_R13),
   TCB_REG_OFF(REG_PRIMASK),
-  0,
-  0,
-  0,
+  0,                        /* basepri */
+  0,                        /* faultmask */
+  0,                        /* control */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+const struct tcbinfo_s g_tcbinfo =
+{
+  TCB_PID_OFF,
+  TCB_STATE_OFF,
+  TCB_PRI_OFF,
+  TCB_NAME_OFF,
+  XCPTCONTEXT_REGS,
+  {
+    .p = g_reg_offs,
+  },
 };
 
 #endif
diff --git a/arch/arm/src/armv7-a/arm_tcbinfo.c b/arch/arm/src/armv7-a/arm_tcbinfo.c
index 84de7bb..5abd5b5 100644
--- a/arch/arm/src/armv7-a/arm_tcbinfo.c
+++ b/arch/arm/src/armv7-a/arm_tcbinfo.c
@@ -30,20 +30,11 @@
 #include <arch/irq.h>
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
-const struct tcbinfo_s g_tcbinfo =
+static const uint16_t g_reg_offs[] =
 {
-  TCB_PID_OFF,
-  TCB_STATE_OFF,
-  TCB_PRI_OFF,
-#if CONFIG_TASK_NAME_SIZE > 0
-  TCB_NAME_OFF,
-#endif
-
-  XCPTCONTEXT_REGS,
-
   TCB_REG_OFF(REG_R0),
   TCB_REG_OFF(REG_R1),
   TCB_REG_OFF(REG_R2),
@@ -101,12 +92,26 @@ const struct tcbinfo_s g_tcbinfo =
 #endif
 
 #ifdef CONFIG_ARCH_FPU
-  0,
   TCB_REG_OFF(REG_FPSCR),
-  0,
 #endif
 };
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+const struct tcbinfo_s g_tcbinfo =
+{
+  TCB_PID_OFF,
+  TCB_STATE_OFF,
+  TCB_PRI_OFF,
+  TCB_NAME_OFF,
+  XCPTCONTEXT_REGS,
+  {
+    .p = g_reg_offs,
+  },
+};
+
 #endif
 
 /****************************************************************************
diff --git a/arch/arm/src/armv7-m/arm_tcbinfo.c b/arch/arm/src/armv7-m/arm_tcbinfo.c
index d9e3321..d212591 100644
--- a/arch/arm/src/armv7-m/arm_tcbinfo.c
+++ b/arch/arm/src/armv7-m/arm_tcbinfo.c
@@ -30,20 +30,11 @@
 #include <arch/irq.h>
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
-const struct tcbinfo_s g_tcbinfo =
+static const uint16_t g_reg_offs[] =
 {
-  TCB_PID_OFF,
-  TCB_STATE_OFF,
-  TCB_PRI_OFF,
-#if CONFIG_TASK_NAME_SIZE > 0
-  TCB_NAME_OFF,
-#endif
-
-  XCPTCONTEXT_REGS,
-
   TCB_REG_OFF(REG_R0),
   TCB_REG_OFF(REG_R1),
   TCB_REG_OFF(REG_R2),
@@ -62,17 +53,17 @@ const struct tcbinfo_s g_tcbinfo =
   TCB_REG_OFF(REG_R15),
   TCB_REG_OFF(REG_XPSR),
 
-  0,
+  0,                            /* msp */
   TCB_REG_OFF(REG_R13),
 #ifdef CONFIG_ARMV7M_USEBASEPRI
-  0,
+  0,                            /* primask */
   TCB_REG_OFF(REG_BASEPRI),
 #else
   TCB_REG_OFF(REG_PRIMASK),
-  0,
+  0,                            /* basepri */
 #endif
-  0,
-  0,
+  0,                            /* faultmask */
+  0,                            /* control */
 
 #ifdef CONFIG_ARCH_FPU
   TCB_REG_OFF(REG_S0),
@@ -107,12 +98,26 @@ const struct tcbinfo_s g_tcbinfo =
   TCB_REG_OFF(REG_S29),
   TCB_REG_OFF(REG_S30),
   TCB_REG_OFF(REG_S31),
-  0,
   TCB_REG_OFF(REG_FPSCR),
-  0,
 #endif
 };
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+const struct tcbinfo_s g_tcbinfo =
+{
+  TCB_PID_OFF,
+  TCB_STATE_OFF,
+  TCB_PRI_OFF,
+  TCB_NAME_OFF,
+  XCPTCONTEXT_REGS,
+  {
+    .p = g_reg_offs,
+  },
+};
+
 #endif
 
 /****************************************************************************
diff --git a/arch/arm/src/armv7-r/arm_tcbinfo.c b/arch/arm/src/armv7-r/arm_tcbinfo.c
index 7124b6b..9caf2f5 100644
--- a/arch/arm/src/armv7-r/arm_tcbinfo.c
+++ b/arch/arm/src/armv7-r/arm_tcbinfo.c
@@ -30,20 +30,11 @@
 #include <arch/irq.h>
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
-const struct tcbinfo_s g_tcbinfo =
+static const uint16_t g_reg_offs[] =
 {
-  TCB_PID_OFF,
-  TCB_STATE_OFF,
-  TCB_PRI_OFF,
-#if CONFIG_TASK_NAME_SIZE > 0
-  TCB_NAME_OFF,
-#endif
-
-  XCPTCONTEXT_REGS,
-
   TCB_REG_OFF(REG_R0),
   TCB_REG_OFF(REG_R1),
   TCB_REG_OFF(REG_R2),
@@ -101,12 +92,26 @@ const struct tcbinfo_s g_tcbinfo =
 #endif
 
 #ifdef CONFIG_ARCH_FPU
-  0,
   TCB_REG_OFF(REG_FPSCR),
-  0,
 #endif
 };
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+const struct tcbinfo_s g_tcbinfo =
+{
+  TCB_PID_OFF,
+  TCB_STATE_OFF,
+  TCB_PRI_OFF,
+  TCB_NAME_OFF,
+  XCPTCONTEXT_REGS,
+  {
+    .p = g_reg_offs,
+  },
+};
+
 #endif
 
 /****************************************************************************
diff --git a/arch/arm/src/armv8-m/arm_tcbinfo.c b/arch/arm/src/armv8-m/arm_tcbinfo.c
index f34eb0f..6ec9219 100644
--- a/arch/arm/src/armv8-m/arm_tcbinfo.c
+++ b/arch/arm/src/armv8-m/arm_tcbinfo.c
@@ -30,20 +30,11 @@
 #include <arch/irq.h>
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
-const struct tcbinfo_s g_tcbinfo =
+static const uint16_t g_reg_offs[] =
 {
-  TCB_PID_OFF,
-  TCB_STATE_OFF,
-  TCB_PRI_OFF,
-#if CONFIG_TASK_NAME_SIZE > 0
-  TCB_NAME_OFF,
-#endif
-
-  XCPTCONTEXT_REGS,
-
   TCB_REG_OFF(REG_R0),
   TCB_REG_OFF(REG_R1),
   TCB_REG_OFF(REG_R2),
@@ -62,17 +53,17 @@ const struct tcbinfo_s g_tcbinfo =
   TCB_REG_OFF(REG_R15),
   TCB_REG_OFF(REG_XPSR),
 
-  0,
+  0,                          /* msp */
   TCB_REG_OFF(REG_R13),
 #ifdef CONFIG_ARMV8M_USEBASEPRI
-  0,
+  0,                          /* primask */
   TCB_REG_OFF(REG_BASEPRI),
 #else
   TCB_REG_OFF(REG_PRIMASK),
-  0,
+  0,                          /* basepri */
 #endif
-  0,
-  0,
+  0,                          /* faultmask */
+  0,                          /* control */
 
 #ifdef CONFIG_ARCH_FPU
   TCB_REG_OFF(REG_S0),
@@ -107,12 +98,26 @@ const struct tcbinfo_s g_tcbinfo =
   TCB_REG_OFF(REG_S29),
   TCB_REG_OFF(REG_S30),
   TCB_REG_OFF(REG_S31),
-  0,
   TCB_REG_OFF(REG_FPSCR),
-  0,
 #endif
 };
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+const struct tcbinfo_s g_tcbinfo =
+{
+  TCB_PID_OFF,
+  TCB_STATE_OFF,
+  TCB_PRI_OFF,
+  TCB_NAME_OFF,
+  XCPTCONTEXT_REGS,
+  {
+    .p = g_reg_offs,
+  },
+};
+
 #endif
 
 /****************************************************************************
diff --git a/arch/risc-v/src/common/riscv_tcbinfo.c b/arch/risc-v/src/common/riscv_tcbinfo.c
index 5599587..bca8cff 100644
--- a/arch/risc-v/src/common/riscv_tcbinfo.c
+++ b/arch/risc-v/src/common/riscv_tcbinfo.c
@@ -30,21 +30,12 @@
 #include <arch/irq.h>
 
 /****************************************************************************
- * Public Data
+ * Private Data
  ****************************************************************************/
 
-const struct tcbinfo_s g_tcbinfo =
+static const uint16_t g_reg_offs[] =
 {
-  TCB_PID_OFF,
-  TCB_STATE_OFF,
-  TCB_PRI_OFF,
-#if CONFIG_TASK_NAME_SIZE > 0
-  TCB_NAME_OFF,
-#endif
-
-  XCPTCONTEXT_REGS,
-
-  0,
+  0,                       /* x0 */
   TCB_REG_OFF(REG_X1_NDX),
   TCB_REG_OFF(REG_X2_NDX),
   TCB_REG_OFF(REG_X3_NDX),
@@ -111,12 +102,28 @@ const struct tcbinfo_s g_tcbinfo =
   TCB_REG_OFF(REG_F29_NDX),
   TCB_REG_OFF(REG_F30_NDX),
   TCB_REG_OFF(REG_F31_NDX),
-  0,
-  0,
+  0,                        /* fflags */
+  0,                        /* frm */
   TCB_REG_OFF(REG_FCSR_NDX),
 #endif
 };
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+const struct tcbinfo_s g_tcbinfo =
+{
+  TCB_PID_OFF,
+  TCB_STATE_OFF,
+  TCB_PRI_OFF,
+  TCB_NAME_OFF,
+  XCPTCONTEXT_REGS,
+  {
+    .p = g_reg_offs,
+  },
+};
+
 #endif
 
 /****************************************************************************
diff --git a/binfmt/libelf/libelf_coredump.c b/binfmt/libelf/libelf_coredump.c
index 2771d2f..a012ce4 100644
--- a/binfmt/libelf/libelf_coredump.c
+++ b/binfmt/libelf/libelf_coredump.c
@@ -247,7 +247,7 @@ static void elf_emit_note_info(FAR struct elf_dumpinfo_s *cinfo)
       for (j = 0; j < ARRAY_SIZE(status.pr_regs); j++)
         {
           status.pr_regs[j] = *(uintptr_t *)((uint8_t *)tcb +
-                                             g_tcbinfo.reg_offs[j]);
+                                             g_tcbinfo.reg_off.p[j]);
         }
 
       elf_emit(cinfo, &status, sizeof(status));
diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index bee03da..05d0de8 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -186,13 +186,15 @@
 #endif
 
 #ifdef CONFIG_DEBUG_TCBINFO
-#  define TCB_PID_OFF                (offsetof(struct tcb_s, pid))
-#  define TCB_STATE_OFF              (offsetof(struct tcb_s, task_state))
-#  define TCB_PRI_OFF                (offsetof(struct tcb_s, sched_priority))
+#  define TCB_PID_OFF                offsetof(struct tcb_s, pid)
+#  define TCB_STATE_OFF              offsetof(struct tcb_s, task_state)
+#  define TCB_PRI_OFF                offsetof(struct tcb_s, sched_priority)
 #if CONFIG_TASK_NAME_SIZE > 0
-#  define TCB_NAME_OFF               (offsetof(struct tcb_s, name))
+#  define TCB_NAME_OFF               offsetof(struct tcb_s, name)
+#else
+#  define TCB_NAME_OFF               0
 #endif
-#  define TCB_REG_OFF(reg)           (offsetof(struct tcb_s, xcp.regs[reg]))
+#  define TCB_REG_OFF(reg)           offsetof(struct tcb_s, xcp.regs[reg])
 #endif
 
 /****************************************************************************
@@ -772,7 +774,7 @@ struct tcbinfo_s
   uint16_t name_off;                     /* Offset of tcb.name              */
   uint16_t reg_num;                      /* Num of regs in tcbinfo.reg_offs */
 
-  /* Offsets of xcp.regs, order in GDB org.gnu.gdb.xxx feature.
+  /* Offset pointer of xcp.regs, order in GDB org.gnu.gdb.xxx feature.
    * Please refer:
    * https://sourceware.org/gdb/current/onlinedocs/gdb/ARM-Features.html
    * https://sourceware.org/gdb/current/onlinedocs/gdb/RISC_002dV-Features
@@ -780,7 +782,11 @@ struct tcbinfo_s
    * value 0: This regsiter was not priovided by NuttX
    */
 
-  uint16_t reg_offs[XCPTCONTEXT_REGS];
+  union
+  {
+    uint8_t       u[8];
+    FAR uint16_t *p;
+  } reg_off;
 };
 #endif