#3779 assigned defect

arm_switch_reg undeclared when building libdebugger/rtems-debugger-arm

Reported by: Andrei Chichak Owned by: Chris Johns
Priority: normal Milestone:
Component: lib/debugger Version:
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description

host is MacOS 10.14.6

target is stm32f4

configure string is:
$HOME/quick-start/src/rtems/configure \

--prefix=$HOME/quick-start/rtems/5 \
--target=arm-rtems5 \
--enable-rtemsbsp=stm32f4 \
--enable-tests \
--disable-networking \
--enable-posix

I am building off of a head pull of the tools and RTOS source as of Monday August 5, late evening GMT-7.

I believe the important error message is:
/Users/andreichichak/quick-start/src/rtems/c/src/../../cpukit/libdebugger/rtems-debugger-arm.c:1308:53: error: 'arm_switch_reg' undeclared (first use in this function)

#define EXCEPTION_ENTRY_EXC() (void) arm_switch_reg


/Users/andreichichak/quick-start/src/rtems/c/src/../../cpukit/libdebugger/rtems-debugger-arm.c:1324:3: note: in expansion of macro 'EXCEPTION_ENTRY_EXC'

EXCEPTION_ENTRY_EXC();

/Users/andreichichak/quick-start/src/rtems/c/src/../../cpukit/libdebugger/rtems-debugger-arm.c:1308:53: note: each undeclared identifier is reported only once for each function it appears in

#define EXCEPTION_ENTRY_EXC() (void) arm_switch_reg


/Users/andreichichak/quick-start/src/rtems/c/src/../../cpukit/libdebugger/rtems-debugger-arm.c:1324:3: note: in expansion of macro 'EXCEPTION_ENTRY_EXC'

EXCEPTION_ENTRY_EXC();

Change History (8)

comment:1 Changed on Oct 1, 2019 at 12:13:53 PM by sprhawk

I'm new to rtems. I also encountered this problem.
I dig into source code, in
commit:8798372261ed1:cpukit/libdebugger/rtems-debugger-arm.c:83-95:

#if !ARM_THUMB_ONLY && defined(__thumb__)
  #define ARM_SWITCH_REG       uint32_t arm_switch_reg
  #define ARM_SWITCH_REG_ASM   [arm_switch_reg] "=&r" (arm_switch_reg)
  #define ARM_SWITCH_REG_ASM_L ARM_SWITCH_REG_ASM,
  #define ASM_ARM_MODE         ".align 2\nbx pc\n.arm\n"
  #define ASM_THUMB_MODE       "add %[arm_switch_reg], pc, #1\nbx %[arm_switch_reg]\n.thumb\n"
#else
  #define ARM_SWITCH_REG
  #define ARM_SWITCH_REG_ASM
  #define ARM_SWITCH_REG_ASM_L
  #define ASM_ARM_MODE
  #define ASM_THUMB_MODE
#endif

here, code for stm32f4 is compiled with flag -mpu cortex-m4, which is ARM_THUMB_ONLY, ARM_ARCH_7M, so above defines will result ARM_SWITCH_REG to empty.

in line 1592, 1593,

it is defined as

#elif defined(ARM_MULTILIB_ARCH_V7M)
  #define EXCEPTION_ENTRY_EXC()               (void) arm_switch_reg

when compiled, it will report undeclared identifier arm_switch_reg

comment:2 Changed on Oct 1, 2019 at 1:06:20 PM by sprhawk

I think if there is no need for arm_switch_reg, how about I void exception_entry_exc()?

  • cpukit/libdebugger/rtems-debugger-arm.c

    From 46c1bd458196ff694ce04e74f68695fc620a7a65 Mon Sep 17 00:00:00 2001
    From: YANG HONGBO <sprhawk@gmail.com>
    Date: Tue, 1 Oct 2019 20:51:03 +0800
    Subject: [PATCH] try to fix failure building for STM32F4
    
    ---
     cpukit/libdebugger/rtems-debugger-arm.c | 9 +++++++--
     1 file changed, 7 insertions(+), 2 deletions(-)
    
    diff --git a/cpukit/libdebugger/rtems-debugger-arm.c b/cpukit/libdebugger/rtems-debugger-arm.c
    index 3d5dea0ab7..eefc83eed5 100644
    a b target_exception(CPU_Exception_frame* frame) 
    15901590 #define EXCEPTION_EXIT_THREAD(_frame)       EXCEPTION_EXIT_THREAD_V4(_frame)
    15911591 #define EXCEPTION_EXIT_EXC()                EXCEPTION_EXIT_EXC_V4()
    15921592#elif defined(ARM_MULTILIB_ARCH_V7M)
    1593  #define EXCEPTION_ENTRY_EXC()               (void) arm_switch_reg
     1593 #if ARM_THUMB_ONLY
     1594  #define EXCEPTION_ENTRY_EXC()               (void)NULL
     1595  #define EXCEPTION_EXIT_EXC()                (void)NULL
     1596 #else
     1597  #define EXCEPTION_ENTRY_EXC()               (void) arm_switch_reg
     1598  #define EXCEPTION_EXIT_EXC()                (void) arm_switch_reg
     1599 #endif
    15941600 #define EXCEPTION_ENTRY_THREAD(_frame)      (_frame) = NULL
    15951601 #define EXCEPTION_EXIT_THREAD(_frame)       (_frame) = NULL
    1596  #define EXCEPTION_EXIT_EXC()                (void) arm_switch_reg
    15971602#else
    15981603 #error ARM architecture is not supported.
    15991604#endif

comment:3 in reply to:  2 ; Changed on Oct 1, 2019 at 11:40:23 PM by Chris Johns

Replying to sprhawk:

I think if there is no need for arm_switch_reg, how about I void exception_entry_exc()?

I am not so sure.

  • cpukit/libdebugger/rtems-debugger-arm.c

    From 46c1bd458196ff694ce04e74f68695fc620a7a65 Mon Sep 17 00:00:00 2001
    From: YANG HONGBO <sprhawk@gmail.com>
    Date: Tue, 1 Oct 2019 20:51:03 +0800
    Subject: [PATCH] try to fix failure building for STM32F4
    
    ---
     cpukit/libdebugger/rtems-debugger-arm.c | 9 +++++++--
     1 file changed, 7 insertions(+), 2 deletions(-)
    
    diff --git a/cpukit/libdebugger/rtems-debugger-arm.c b/cpukit/libdebugger/rtems-debugger-arm.c
    index 3d5dea0ab7..eefc83eed5 100644
    a b target_exception(CPU_Exception_frame* frame) 
    15901590 #define EXCEPTION_EXIT_THREAD(_frame)       EXCEPTION_EXIT_THREAD_V4(_frame)
    15911591 #define EXCEPTION_EXIT_EXC()                EXCEPTION_EXIT_EXC_V4()
    15921592#elif defined(ARM_MULTILIB_ARCH_V7M)
    1593  #define EXCEPTION_ENTRY_EXC()               (void) arm_switch_reg
     1593 #if ARM_THUMB_ONLY
     1594  #define EXCEPTION_ENTRY_EXC()               (void)NULL
     1595  #define EXCEPTION_EXIT_EXC()                (void)NULL

I do not think this would work. It means NULL is being loaded as the address. I am not familiar with the specifics of this model. Is ARM mode active when entering an exception? If so we need to switch to thumb mode and to do this we need a valid arm_switch_reg.

What is your configure command line for RTEMS and I will see what is broken in the build?

comment:4 in reply to:  3 Changed on Oct 2, 2019 at 12:03:27 AM by sprhawk

Replying to Chris Johns:

Replying to sprhawk:

I think if there is no need for arm_switch_reg, how about I void exception_entry_exc()?

I am not so sure.

  • cpukit/libdebugger/rtems-debugger-arm.c

    From 46c1bd458196ff694ce04e74f68695fc620a7a65 Mon Sep 17 00:00:00 2001
    From: YANG HONGBO <sprhawk@gmail.com>
    Date: Tue, 1 Oct 2019 20:51:03 +0800
    Subject: [PATCH] try to fix failure building for STM32F4
    
    ---
     cpukit/libdebugger/rtems-debugger-arm.c | 9 +++++++--
     1 file changed, 7 insertions(+), 2 deletions(-)
    
    diff --git a/cpukit/libdebugger/rtems-debugger-arm.c b/cpukit/libdebugger/rtems-debugger-arm.c
    index 3d5dea0ab7..eefc83eed5 100644
    a b target_exception(CPU_Exception_frame* frame) 
    15901590 #define EXCEPTION_EXIT_THREAD(_frame)       EXCEPTION_EXIT_THREAD_V4(_frame)
    15911591 #define EXCEPTION_EXIT_EXC()                EXCEPTION_EXIT_EXC_V4()
    15921592#elif defined(ARM_MULTILIB_ARCH_V7M)
    1593  #define EXCEPTION_ENTRY_EXC()               (void) arm_switch_reg
     1593 #if ARM_THUMB_ONLY
     1594  #define EXCEPTION_ENTRY_EXC()               (void)NULL
     1595  #define EXCEPTION_EXIT_EXC()                (void)NULL

I do not think this would work. It means NULL is being loaded as the address. I am not familiar with the specifics of this model. Is ARM mode active when entering an exception? If so we need to switch to thumb mode and to do this we need a valid arm_switch_reg.

The STM32F4 has a core of cortex-m4, which is ARMv7M instruction set, which is thumb only,

What is your configure command line for RTEMS and I will see what is broken in the build?

I used command similar as the ticket reported:

../rtems_5/configure --prefix=$RTEMS_ROOT_DIR --target=arm-rtems5 --enable-rtemsbsp=stm32f4 --disable-networking --enable-posix --disable-cxx --enable-tests=samples --disable-smp --disable-multiprocessing; make

comment:5 in reply to:  3 ; Changed on Oct 2, 2019 at 12:30:49 AM by sprhawk

Replying to Chris Johns:

Replying to sprhawk:

I think if there is no need for arm_switch_reg, how about I void exception_entry_exc()?

I am not so sure.

  • cpukit/libdebugger/rtems-debugger-arm.c

    From 46c1bd458196ff694ce04e74f68695fc620a7a65 Mon Sep 17 00:00:00 2001
    From: YANG HONGBO <sprhawk@gmail.com>
    Date: Tue, 1 Oct 2019 20:51:03 +0800
    Subject: [PATCH] try to fix failure building for STM32F4
    
    ---
     cpukit/libdebugger/rtems-debugger-arm.c | 9 +++++++--
     1 file changed, 7 insertions(+), 2 deletions(-)
    
    diff --git a/cpukit/libdebugger/rtems-debugger-arm.c b/cpukit/libdebugger/rtems-debugger-arm.c
    index 3d5dea0ab7..eefc83eed5 100644
    a b target_exception(CPU_Exception_frame* frame) 
    15901590 #define EXCEPTION_EXIT_THREAD(_frame)       EXCEPTION_EXIT_THREAD_V4(_frame)
    15911591 #define EXCEPTION_EXIT_EXC()                EXCEPTION_EXIT_EXC_V4()
    15921592#elif defined(ARM_MULTILIB_ARCH_V7M)
    1593  #define EXCEPTION_ENTRY_EXC()               (void) arm_switch_reg
     1593 #if ARM_THUMB_ONLY
     1594  #define EXCEPTION_ENTRY_EXC()               (void)NULL
     1595  #define EXCEPTION_EXIT_EXC()                (void)NULL

I do not think this would work. It means NULL is being loaded as the address. I am not familiar with the specifics of this model. Is ARM mode active when entering an exception? If so we need to switch to thumb mode and to do this we need a valid arm_switch_reg.

What is your configure command line for RTEMS and I will see what is broken in the build?

I think you are right, I should simply put it empty instead?

  • cpukit/libdebugger/rtems-debugger-arm.c

    From c3caf01a5674bc4da2b926d118bf5df5baa1fe4f Mon Sep 17 00:00:00 2001
    From: YANG HONGBO <yanghongbo@iotpi.io>
    Date: Wed, 2 Oct 2019 08:12:41 +0800
    Subject: [PATCH] empty EXCEPTION_ENTRY_EXC when cpu is ARM_THUMB_ONLY
    
    ---
     cpukit/libdebugger/rtems-debugger-arm.c | 15 +++++++++++----
     1 file changed, 11 insertions(+), 4 deletions(-)
    
    diff --git a/cpukit/libdebugger/rtems-debugger-arm.c b/cpukit/libdebugger/rtems-debugger-arm.c
    index 3d5dea0ab7..92b3b586b4 100644
    a b target_exception(CPU_Exception_frame* frame) 
    15901590 #define EXCEPTION_EXIT_THREAD(_frame)       EXCEPTION_EXIT_THREAD_V4(_frame)
    15911591 #define EXCEPTION_EXIT_EXC()                EXCEPTION_EXIT_EXC_V4()
    15921592#elif defined(ARM_MULTILIB_ARCH_V7M)
    1593  #define EXCEPTION_ENTRY_EXC()               (void) arm_switch_reg
    1594  #define EXCEPTION_ENTRY_THREAD(_frame)      (_frame) = NULL
    1595  #define EXCEPTION_EXIT_THREAD(_frame)       (_frame) = NULL
    1596  #define EXCEPTION_EXIT_EXC()                (void) arm_switch_reg
     1593 #if ARM_THUMB_ONLY
     1594  #define EXCEPTION_ENTRY_EXC()
     1595  #define EXCEPTION_ENTRY_THREAD(_frame)      (_frame) = NULL
     1596  #define EXCEPTION_EXIT_THREAD(_frame)       (_frame) = NULL
     1597  #define EXCEPTION_EXIT_EXC()
     1598 #else
     1599  #define EXCEPTION_ENTRY_EXC()               (void) arm_switch_reg
     1600  #define EXCEPTION_ENTRY_THREAD(_frame)      (_frame) = NULL
     1601  #define EXCEPTION_EXIT_THREAD(_frame)       (_frame) = NULL
     1602  #define EXCEPTION_EXIT_EXC()                (void) arm_switch_reg
     1603 #endif
    15971604#else
    15981605 #error ARM architecture is not supported.
    15991606#endif

comment:6 in reply to:  5 ; Changed on Oct 2, 2019 at 1:07:36 AM by Chris Johns

Replying to sprhawk:

Replying to Chris Johns:

I do not think this would work. It means NULL is being loaded as the address. I am not familiar with the specifics of this model. Is ARM mode active when entering an exception? If so we need to switch to thumb mode and to do this we need a valid arm_switch_reg.

What is your configure command line for RTEMS and I will see what is broken in the build?

I think you are right, I should simply put it empty instead?

I am not sure. If the ARM to thumb code is being used then a variable is needed.

What is your configure command line?

comment:7 in reply to:  6 ; Changed on Oct 2, 2019 at 1:18:24 AM by sprhawk

Replying to Chris Johns:

What is your configure command line?

It was

../rtems_5/configure --prefix=$RTEMS_ROOT_DIR --target=arm-rtems5 --enable-rtemsbsp=stm32f4 --disable-networking --enable-posix --disable-cxx --enable-tests=samples --disable-smp --disable-multiprocessing; make

If cortex-m4 is thumb only, I think it should not have the operation to switch from ARM to thumb due to it lacks of ARM instructions

comment:8 in reply to:  7 Changed on Oct 2, 2019 at 1:59:49 AM by Chris Johns

Replying to sprhawk:

Replying to Chris Johns:

What is your configure command line?

It was

../rtems_5/configure --prefix=$RTEMS_ROOT_DIR --target=arm-rtems5 --enable-rtemsbsp=stm32f4 --disable-networking --enable-posix --disable-cxx --enable-tests=samples --disable-smp --disable-multiprocessing; make

Thanks.

If cortex-m4 is thumb only, I think it should not have the operation to switch from ARM to thumb due to it lacks of ARM instructions

Ah ok, this would make sense. I would need to check over the code to make sure it is clean. Maybe the change is around the defines for the switching near the top. If they are blank there is no switch and no issue?

Note: See TracTickets for help on using tickets.