Skip to content

arch: arm: cortex_a_r: Improve support for big endian #72693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 4, 2024

Conversation

sigmundklaa
Copy link
Contributor

This enables support for big endian Cortex A/R devices. The pull request consists of two changes:

  • Set PROPERTY_OUTPUT_FORMAT to elf32-bigarm when CONFIG_BIG_ENDIAN=y
  • Set the endianness bit of the CPSR register, ensuring that the CPU stays in big endian mode when switching to the main thread. Without this, data accesses used the wrong endianness, causing a (very big) headache.

The CPSR issue was the only problem I noticed when porting the TMS570LS1224 big endian Cortex R4F SoC. With this fixed, it seems to work completely fine. My setup is available at https://github.com/OrbitNTNU/zephyr-hw if that is relevant.

@MaureenHelm
Copy link
Member

@ithinuel please take a look

Comment on lines 29 to 34
#if defined(CONFIG_BIG_ENDIAN)
#define E_BIT (1 << 9)
#else
#define E_BIT (0 << 9)
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

Set or un-set E_BIT in thread.c. This file is encoding the BIT position, so the E_BIT position is always 1 << 9 but only set for CONFIG_BIG_ENDIAN.

@@ -94,7 +94,7 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
iframe->a3 = (uint32_t)p2;
iframe->a4 = (uint32_t)p3;

iframe->xpsr = A_BIT | MODE_SYS;
iframe->xpsr = E_BIT | A_BIT | MODE_SYS;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
iframe->xpsr = E_BIT | A_BIT | MODE_SYS;
#if defined(CONFIG_BIG_ENDIAN)
iframe->xpsr = E_BIT | A_BIT | MODE_SYS;
#else
iframe->xpsr = A_BIT | MODE_SYS;
#endif

Comment on lines 29 to 34
#if defined(CONFIG_BIG_ENDIAN)
#define E_BIT (1 << 9)
#else
#define E_BIT (0 << 9)
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#if defined(CONFIG_BIG_ENDIAN)
#define E_BIT (1 << 9)
#else
#define E_BIT (0 << 9)
#endif
#define E_BIT (1 << 9)

@ithinuel
Copy link
Collaborator

These suggestions are essentially what @carlocaione is requesting.

ithinuel
ithinuel previously approved these changes Jun 28, 2024
Copy link
Collaborator

@ithinuel ithinuel left a comment

Choose a reason for hiding this comment

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

A little nitpick is the space style not matching everywhere (on E_BIT definition).
Otherwise LGTM

When this bit is not set, it defaults to 0 (little endian). This
causes issues for big-endian devices, as data will be accessed using
little endian.

Signed-off-by: Sigmund Klåpbakken <sigmundklaa@outlook.com>
Sets the property `PROPERTY_OUTPUT_FORMAT` to `elf32-bigarm` when
`CONFIG_BIG_ENDIAN` is set to `y`.

Signed-off-by: Sigmund Klåpbakken <sigmundklaa@outlook.com>
@sigmundklaa
Copy link
Contributor Author

A little nitpick is the space style not matching everywhere (on E_BIT definition). Otherwise LGTM

Fixed

@nashif nashif merged commit 0f776cf into zephyrproject-rtos:main Jul 4, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: ARM ARM (32-bit) Architecture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants