Skip to content

Add explanatory comment for portFPU_REG_OFFSET in RISC-V port - #1457

Open
wanghengZzz wants to merge 1 commit into
FreeRTOS:mainfrom
wanghengZzz:docs/add-fpu-offset-comment
Open

Add explanatory comment for portFPU_REG_OFFSET in RISC-V port#1457
wanghengZzz wants to merge 1 commit into
FreeRTOS:mainfrom
wanghengZzz:docs/add-fpu-offset-comment

Conversation

@wanghengZzz

Copy link
Copy Markdown
Contributor

Description

Clarify FPU context offset calculation in RISC-V portContext.h

This PR adds an explanatory comment to portFPU_REG_OFFSET() in portContext.h for the RISC-V port to improve code readability and maintainability.

In portContext.h, the macro portFPU_REG_OFFSET( regIndex ) uses ( 2 * portWORD_SIZE ) as the base offset for saving floating-point registers. Without documentation, this offset design is not immediately obvious to developers reading the kernel porting code.

The ( 2 * portWORD_SIZE ) reservation serves two critical purposes:

  1. FCSR Storage: Holds the 32-bit Floating-Point Control and Status Register (fcsr).
  2. Alignment Guarantee: Ensures proper memory/stack alignment across architectures:
    • RV32D: Provides 8-byte natural alignment required for 64-bit double-precision floating-point load/store instructions (fld/fsd).
    • RV64: Maintains the 16-byte stack alignment mandated by the RISC-V ELF PSABI.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Explain that the initial (2 * portWORD_SIZE) offset reserves space for the
fcsr register and maintains proper memory and ABI stack alignment for both
RV32 and RV64 architectures.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant