Skip to content

Conversation

sauleThsQuin
Copy link
Contributor

Title

fix[RL78 Port] incorrect register image for pvParameters in FAR mode (#1316)

Description

In the RL78 FAR data model, pxPortInitialiseStack() did not correctly
initialize the register image in the task stack for the parameter (pvParameters).

The saved A:DE registers were filled with dummy values instead of the actual pointer value.

As a result, when the first context restore occurred, the compiler's function prologue read a corrupted parameter from the register image.

This only affected FAR builds; NEAR model was not impacted.

This patch updates the RL78 FAR path so that the register image matches the RL78 calling convention:
DE = low 16 bits of pvParameters
A = high 8 bits of pvParameters (via AX register image, X = 0)

With this change, tasks in FAR model receive the correct parameter at entry, while NEAR model remains unchanged.

Test Steps

  • Build FreeRTOS for RL78 with FAR data model.
  • Create a task with xTaskCreate(task, "name", stack, pvParameters, prio, NULL).
  • Inspect pvParameters inside the task:

Before fix: value corrupted (dummy registers A:DE = 0x1111/0xDEDE).

After fix: value matches the pointer passed to xTaskCreate.

Confirm no regression with NEAR model build.

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

#1316

@sauleThsQuin sauleThsQuin requested a review from a team as a code owner September 8, 2025 09:36
@aggarg
Copy link
Member

aggarg commented Sep 9, 2025

@KeitaKashima What do you think about this change?

@KeitaKashima
Copy link
Contributor

@aggarg san

@KeitaKashima What do you think about this change?

My team will check the code. Could you please have some time to check it in about one or two weeks?

@aggarg
Copy link
Member

aggarg commented Sep 9, 2025

@KeitaKashima Of course. Take your time. Thank you for your help with the review!

@KeitaKashima
Copy link
Contributor

@aggarg
I am sorry that my team needs more time than I expected.

@TakeoTakahashi2020 and @ShunichiroNakamura of my team members, will check and answer the result.

@aggarg
Copy link
Member

aggarg commented Sep 17, 2025

@KeitaKashima No worries at all! Please take your time.

ShunichiroNakamura

This comment was marked as resolved.

@aggarg
Copy link
Member

aggarg commented Sep 29, 2025

@ShunichiroNakamura and @TakeoTakahashi2020, thank you for reviewing the code.

@sauleThsQuin Would you please address the comments?

@sauleThsQuin sauleThsQuin force-pushed the fix/rl78-port-far-param-init branch 3 times, most recently from 4898f93 to 1612072 Compare October 3, 2025 06:37
@ShunichiroNakamura
Copy link

@aggarg
We have confirmed that the changes in portable/IAR/RL78/port.c are no problem.

@aggarg
Copy link
Member

aggarg commented Oct 6, 2025

@ShunichiroNakamura Thank you so much!

@sauleThsQuin The diff shows changes in a lot of unrelated files. Would you please fix them so that we can merge the PR?

@sauleThsQuin sauleThsQuin force-pushed the fix/rl78-port-far-param-init branch from 1612072 to 48794de Compare October 6, 2025 06:39
…FreeRTOS#1316) In the RL78 FAR data model, pxPortInitialiseStack() did not initialize the register image for the task parameter (pvParameters) correctly. A:DE registers were saved with dummy values instead of the actual pointer. Effect: on first context restore the function prologue read a corrupted parameter. NEAR builds were not affected. This patch aligns the FAR path with the calling convention and compiler version: - IAR V2: pass pvParameters via registers → DE = low 16 bits, A = high 8 - IAR V1 (fallback): keep legacy stack write Also keeps the original stack-frame layout and updates the comment to reflect that pointer sizes depend on __DATA_MODEL__. Result: tasks in FAR receive the correct parameter at entry; NEAR remains unchanged.
@sauleThsQuin sauleThsQuin force-pushed the fix/rl78-port-far-param-init branch from 88e8962 to 3453311 Compare October 6, 2025 06:43
@moninom1 moninom1 changed the title fix[RL78 Port] incorrect register image for pvParameters in FAR mode (#1316) Fix[RL78 Port] incorrect register image for pvParameters in FAR mode (#1316) Oct 6, 2025
@moninom1 moninom1 changed the title Fix[RL78 Port] incorrect register image for pvParameters in FAR mode (#1316) Fix[RL78 Port] Incorrect register image for pvParameters in FAR mode (#1316) Oct 6, 2025
@aggarg aggarg merged commit a1f6e1f into FreeRTOS:main Oct 6, 2025
24 of 25 checks passed
@sauleThsQuin
Copy link
Contributor Author

Thanks for the reviews and feedback.
I appreciate the guidance and I'm glad the fix has been merged.

@sauleThsQuin sauleThsQuin deleted the fix/rl78-port-far-param-init branch October 6, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants