Skip to content

Conversation

@Saiiijchan
Copy link
Contributor

The index 0 and 1 are stored for general register which should depends on XLEN.

Description

Test Steps

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.

The index 0 and 1 are general register which should depends on
_XLEN_.

Signed-off-by: wangfei_chen <[email protected]>
@Saiiijchan Saiiijchan requested a review from a team as a code owner March 13, 2025 06:06
@aggarg
Copy link
Member

aggarg commented Mar 13, 2025

There are the following 4 possible configurations and the corressponding offsets:

XLEN=4, FLEN=8          XLEN=8, FLEN=4          XLEN=4, FLEN=4          XLEN=8, FLEN=8
| Offset | Register |   | Offset | Register |   | Offset | Register |   | Offset | Register |
|--------|----------|   |--------|----------|   |--------|----------|   |--------|----------|
| 0      | pxCode   |   | 0      | pxCode   |   | 0      | pxCode   |   | 0      | pxCode   |
| 4      | mstatus  |   | 8      | mstatus  |   | 4      | mstatus  |   | 8      | mstatus  |
| 8      | f0       |   | 16     | f0       |   | 8      | f0       |   | 16     | f0       |
| 16     | f1       |   | 20     | f1       |   | 12     | f1       |   | 24     | f1       |
| 24     | f2       |   | 24     | f2       |   | 16     | f2       |   | 32     | f2       |
| 32     | f3       |   | 28     | f3       |   | 20     | f3       |   | 40     | f3       |
| 40     | f4       |   | 32     | f4       |   | 24     | f4       |   | 48     | f4       |
| 48     | f5       |   | 36     | f5       |   | 28     | f5       |   | 56     | f5       |
| 56     | f6       |   | 40     | f6       |   | 32     | f6       |   | 64     | f6       |
| 64     | f7       |   | 44     | f7       |   | 36     | f7       |   | 72     | f7       |
| 72     | f8       |   | 48     | f8       |   | 40     | f8       |   | 80     | f8       |
| 80     | f9       |   | 52     | f9       |   | 44     | f9       |   | 88     | f9       |
| 88     | f10      |   | 56     | f10      |   | 48     | f10      |   | 96     | f10      |
| 96     | f11      |   | 60     | f11      |   | 52     | f11      |   | 104    | f11      |
| 104    | f12      |   | 64     | f12      |   | 56     | f12      |   | 112    | f12      |
| 112    | f13      |   | 68     | f13      |   | 60     | f13      |   | 120    | f13      |
| 120    | f14      |   | 72     | f14      |   | 64     | f14      |   | 128    | f14      |
| 128    | f15      |   | 76     | f15      |   | 68     | f15      |   | 136    | f15      |
| 136    | f16      |   | 80     | f16      |   | 72     | f16      |   | 144    | f16      |
| 144    | f17      |   | 84     | f17      |   | 76     | f17      |   | 152    | f17      |
| 152    | f18      |   | 88     | f18      |   | 80     | f18      |   | 160    | f18      |
| 160    | f19      |   | 92     | f19      |   | 84     | f19      |   | 168    | f19      |
| 168    | f20      |   | 96     | f20      |   | 88     | f20      |   | 176    | f20      |
| 176    | f21      |   | 100    | f21      |   | 92     | f21      |   | 184    | f21      |
| 184    | f22      |   | 104    | f22      |   | 96     | f22      |   | 192    | f22      |
| 192    | f23      |   | 108    | f23      |   | 100    | f23      |   | 200    | f23      |
| 200    | f24      |   | 112    | f24      |   | 104    | f24      |   | 208    | f24      |
| 208    | f25      |   | 116    | f25      |   | 108    | f25      |   | 216    | f25      |
| 216    | f26      |   | 120    | f26      |   | 112    | f26      |   | 224    | f26      |
| 224    | f27      |   | 124    | f27      |   | 116    | f27      |   | 232    | f27      |
| 232    | f28      |   | 128    | f28      |   | 120    | f28      |   | 240    | f28      |
| 240    | f29      |   | 132    | f29      |   | 124    | f29      |   | 248    | f29      |
| 248    | f30      |   | 136    | f30      |   | 128    | f30      |   | 256    | f30      |
| 256    | f31      |   | 140    | f31      |   | 132    | f31      |   | 264    | f31      |
| 264    | fcsr     |   | 144    | fcsr     |   | 136    | fcsr     |   | 272    | fcsr     |

The correct formula to calculate the offset should be ( 2 * portWORD_SIZE ) + ( regIndex * portFPU_REG_SIZE ).

Signed-off-by: Gaurav Aggarwal <[email protected]>
@sonarqubecloud
Copy link

@Saiiijchan
Copy link
Contributor Author

It looks good to me, thanks for refine.

@aggarg aggarg merged commit 64fd929 into FreeRTOS:main Mar 13, 2025
17 checks passed
@Saiiijchan Saiiijchan deleted the refine_fpu_context_offset branch March 14, 2025 01:12
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.

4 participants