Skip to content

Conversation

Rbb666
Copy link
Member

@Rbb666 Rbb666 commented Aug 18, 2025

添加HardFault_Handler中针对浮点寄存器的保存,可以为后续coredump提供浮点寄存器

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@Rbb666 Rbb666 requested a review from Copilot August 18, 2025 14:48
@Rbb666 Rbb666 requested a review from aozima August 18, 2025 14:49
Copilot

This comment was marked as outdated.

@Rbb666 Rbb666 requested review from Copilot and Guozhanxin August 19, 2025 01:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the HardFault_Handler for ARM Cortex-M4 to properly save floating point registers (s16-s31) when a hard fault occurs. This improvement provides better coredump support by preserving the complete floating point context.

  • Adds conditional saving of FPU registers d8-d15 (corresponding to s16-s31) when FPU is active
  • Replaces dummy flag with proper FPU context flag based on EXC_RETURN[4] bit
  • Maintains consistency across three assembly implementations (RVDS, IAR, GCC)

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
libcpu/arm/cortex-m4/context_rvds.S Adds FPU register saving and proper flag handling for RVDS assembler
libcpu/arm/cortex-m4/context_iar.S Adds FPU register saving and proper flag handling for IAR assembler
libcpu/arm/cortex-m4/context_gcc.S Adds FPU register saving and proper flag handling for GCC assembler

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -236,10 +236,21 @@ HardFault_Handler PROC
MRSEQ r0, msp ; [2]=0 ==> Z=1, get fault context from handler.
MRSNE r0, psp ; [2]=1 ==> Z=0, get fault context from thread.

IF {FPU} != "SoftVFP"
TST lr, #0x10 ; if(!EXC_RETURN[4])
VSTMFDEQ r0!, {d8 - d15} ; push FPU register s16~s31
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly states 's16~s31' but the instruction saves double precision registers d8-d15. The comment should be corrected to 'd8-d15' or explain that these correspond to s16-s31 in single precision mode.

Suggested change
VSTMFDEQ r0!, {d8 - d15} ; push FPU register s16~s31
VSTMFDEQ r0!, {d8 - d15} ; push FPU register d8~d15 (corresponds to s16~s31 in single precision mode)

Copilot uses AI. Check for mistakes.

#if defined ( __ARMVFP__ )
TST lr, #0x10 ; if(!EXC_RETURN[4])
BNE skip_push_fpu
VSTMDB r0!, {d8 - d15} ; push FPU register s16~s31
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly states 's16~s31' but the instruction saves double precision registers d8-d15. The comment should be corrected to 'd8-d15' or explain that these correspond to s16-s31 in single precision mode.

Suggested change
VSTMDB r0!, {d8 - d15} ; push FPU register s16~s31
VSTMDB r0!, {d8 - d15} ; push FPU registers d8-d15 (corresponds to s16~s31 in single precision mode)

Copilot uses AI. Check for mistakes.

#if defined (__VFP_FP__) && !defined(__SOFTFP__)
TST lr, #0x10 /* if(!EXC_RETURN[4]) */
IT EQ
VSTMDBEQ r0!, {d8 - d15} /* push FPU register s16~s31 */
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly states 's16~s31' but the instruction saves double precision registers d8-d15. The comment should be corrected to 'd8-d15' or explain that these correspond to s16-s31 in single precision mode.

Suggested change
VSTMDBEQ r0!, {d8 - d15} /* push FPU register s16~s31 */
VSTMDBEQ r0!, {d8 - d15} /* push FPU registers d8-d15 (corresponds to s16~s31 in single precision mode) */

Copilot uses AI. Check for mistakes.

@@ -236,10 +236,21 @@ HardFault_Handler PROC
MRSEQ r0, msp ; [2]=0 ==> Z=1, get fault context from handler.
MRSNE r0, psp ; [2]=1 ==> Z=0, get fault context from thread.

IF {FPU} != "SoftVFP"
TST lr, #0x10 ; if(!EXC_RETURN[4])
VSTMFDEQ r0!, {d8 - d15} ; push FPU register s16~s31
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VSTMFDEQ instruction uses full descending stack mode, but this is inconsistent with the STMFD instructions used elsewhere. Consider using VSTMDBEQ for consistency with decrement before operation mode.

Suggested change
VSTMFDEQ r0!, {d8 - d15} ; push FPU register s16~s31
VSTMDBEQ r0!, {d8 - d15} ; push FPU register s16~s31

Copilot uses AI. Check for mistakes.

@Rbb666 Rbb666 merged commit 990fc23 into RT-Thread:master Aug 19, 2025
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants