From f903a5510277b312469fd9aff7f744108ac71f1e Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 27 Dec 2021 11:09:38 +0800 Subject: [PATCH] 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 Signed-off-by: zhuyanlin --- 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 2438ded272..ad350f5c97 100644 --- a/arch/arm/src/arm/arm_tcbinfo.c +++ b/arch/arm/src/arm/arm_tcbinfo.c @@ -30,20 +30,11 @@ #include /**************************************************************************** - * 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 989fd353b7..c9f1b2aed0 100644 --- a/arch/arm/src/armv6-m/arm_tcbinfo.c +++ b/arch/arm/src/armv6-m/arm_tcbinfo.c @@ -30,20 +30,11 @@ #include /**************************************************************************** - * 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 84de7bbbb0..5abd5b5143 100644 --- a/arch/arm/src/armv7-a/arm_tcbinfo.c +++ b/arch/arm/src/armv7-a/arm_tcbinfo.c @@ -30,20 +30,11 @@ #include /**************************************************************************** - * 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 d9e3321a97..d212591ace 100644 --- a/arch/arm/src/armv7-m/arm_tcbinfo.c +++ b/arch/arm/src/armv7-m/arm_tcbinfo.c @@ -30,20 +30,11 @@ #include /**************************************************************************** - * 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 7124b6b3c4..9caf2f5140 100644 --- a/arch/arm/src/armv7-r/arm_tcbinfo.c +++ b/arch/arm/src/armv7-r/arm_tcbinfo.c @@ -30,20 +30,11 @@ #include /**************************************************************************** - * 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 f34eb0f608..6ec9219342 100644 --- a/arch/arm/src/armv8-m/arm_tcbinfo.c +++ b/arch/arm/src/armv8-m/arm_tcbinfo.c @@ -30,20 +30,11 @@ #include /**************************************************************************** - * 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 5599587132..bca8cff149 100644 --- a/arch/risc-v/src/common/riscv_tcbinfo.c +++ b/arch/risc-v/src/common/riscv_tcbinfo.c @@ -30,21 +30,12 @@ #include /**************************************************************************** - * 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 2771d2f852..a012ce441c 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 bee03da488..05d0de897e 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