This is an automated email from Gerrit. "Mateus Campaner Hercules <mchercu...@gmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7478
-- gerrit commit ca38e918f157ca44d4f2d5ca33a56c13f94e2a4e Author: Mateus Campaner Hercules <mchercu...@gmail.com> Date: Wed Feb 15 13:19:08 2023 -0300 Add MPU detection logic to FreeRTOS thread's stack parsing. Created a variable holding true if a default mpu is available on target and it's enabled. Both FreeRTOS cortex-m4 & cortex-m3 ports with MPU target the default peripheral from ARM. If target is based on armv7m, it will have a MPU_TYPE register, as it's noted as always implemented by ARM documentation. This register's DREGION byte indicates if a proper MPU is available on target. As said before only the default MPU is supported by this code snippet. Signed-off-by: Mateus Campaner Hercules <mchercu...@gmail.com> Change-Id: I47da134bd6a8fef4fe0127c45836a08bb28315d8 diff --git a/src/rtos/FreeRTOS.c b/src/rtos/FreeRTOS.c index 0dbe019792..dbd9cb97db 100644 --- a/src/rtos/FreeRTOS.c +++ b/src/rtos/FreeRTOS.c @@ -448,6 +448,36 @@ static int freertos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, } } + /* Check for armv7m with *implemented* MPU, i.e. some vendors use a custom implementation */ + int cm4_mpu_enabled = 0; + if (is_armv7m(armv7m_target)) { + /* MPU_TYPE is always implemented on armv7m */ + uint32_t mpu_type; + + retval = target_read_u32(rtos->target, MPU_TYPE, &mpu_type); + if (retval != ERROR_OK) { + LOG_ERROR("Could not read MPU_TYPE register to check if MPU is implemented"); + return -1; + } + + /* Check if DREGION is not zero */ + if (mpu_type & 0x0000FF00) { + uint32_t mpu_ctrl; + + retval = target_read_u32(rtos->target, MPU_CTRL, &mpu_ctrl); + if (retval != ERROR_OK) { + LOG_ERROR("Could not read MPU_CTRL on a mpu present core"); + return -1; + } + + /* Check if ENABLE bit of MPU_CTRL is enabled */ + if (mpu_ctrl & 0x00000001) { + /* Found target with enabled MPU */ + cm4_mpu_enabled = 1; + } + } + } + if (cm4_fpu_enabled == 1) { /* Read the LR to decide between stacking with or without FPU */ uint32_t lr_svc = 0; --