Page MenuHomeFreeBSD

arm64: Use adrp + :lo12: to load globals from asm
ClosedPublic

Authored by andrew on Nov 13 2023, 5:17 PM.
Tags
None
Referenced Files
F102739447: D42565.id130019.diff
Sat, Nov 16, 1:56 PM
Unknown Object (File)
Sun, Nov 10, 3:06 PM
Unknown Object (File)
Mon, Oct 28, 1:17 PM
Unknown Object (File)
Oct 10 2024, 3:31 PM
Unknown Object (File)
Sep 28 2024, 3:25 PM
Unknown Object (File)
Sep 28 2024, 1:20 PM
Unknown Object (File)
Sep 24 2024, 8:39 AM
Unknown Object (File)
Sep 24 2024, 8:36 AM
Subscribers

Details

Summary

When loading a global variable we can use a pseudo-instruction similar
to "ldr, xn, =global" to load the address of the symbol. As this is
unlikely to be supported by a mov instruction a pc-relative load is
used, with the absolute address written at the end of the function so
it will be loaded.

This load can be partially replaced with an adrp instruction. This
generates the address, aligned to a 4k boundary, using a pc-relative
addition. Because the address is 4k-aligned we then update reading the
global variable using a load with the offset of the load the low
12-bits of the global. Arm64 assemblers have :lo12: to support this,
e.g. "ldr xn, [xn, :lo12:global]".

The only remaining users of "ldr, xn, =global" that I can find are
executed from the physical address space the kernel was loaded in and
need an address in the kernels virtual address space. Because of this
they can't use adrp.

Sponsored by: Arm Ltd

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 54388
Build 51278: arc lint + arc unit