Skip to content
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

arch/arm64: fix boot stage prints with CONFIG_ARCH_EARLY_PRINT=y #15901

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gpoulios
Copy link
Contributor

Summary

boot_stage_puts used by early assembly head, calls arm64_lowputc() for each character of the string to be printed in a loop. During that loop it uses x1 as the pointer to the next character to be printed. However, x1 is clobbered[1] by arm64_lowputc(), resulting in undefined behaviour (only the first character of the string is guaranteed to be printed).

Fix this by using x9 instead. Despite x9 not currently being used by any other instruction in arm64_head.S, save it on entry, and restore it on exit.

[1] Observed clobbering behaviour with arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64.

Impact

The change does not affect users, build processes, hardware, documentation or security compatibility.

The only notable effect should be the early console messages in arm64 builds being fully (and more reliably) visible when configured with CONFIG_ARCH_EARLY_PRINT=y.

Testing

  • Toolchain: arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64
  • Target: imx93evk:nsh
  • Extra config: CONFIG_ARCH_EARLY_PRINT=y

WIthout the change, early boot stage messages would appear as:

---[other messages here]

With the change, early boot stage messages are:

- Boot from EL2
- Boot from EL1
- Boot to C runtime for OS Initialize
[other messages here]

`boot_stage_puts` used by early asm calls arm64_lowputc() for each
character in a loop. During that loop it uses x1 as the pointer to
the next character to be printed. However, x1 is clobbered by
arm64_lowputc(), resulting in undefined behaviour (only the first
character of the string is guaranteed to be printed).

Fix this by using x9 instead. Despite x9 not currently being used
by any other instruction in arm64_head.S, save it on entry, and
restore it on exit.

Signed-off-by: George Poulios <[email protected]>
@github-actions github-actions bot added Arch: arm64 Issues related to ARM64 (64-bit) architecture Size: XS The size of the change in this PR is very small labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: arm64 Issues related to ARM64 (64-bit) architecture Size: XS The size of the change in this PR is very small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant