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
F97298877: D42565.diff
Sat, Sep 28, 1:20 PM
Unknown Object (File)
Tue, Sep 24, 8:39 AM
Unknown Object (File)
Tue, Sep 24, 8:36 AM
Unknown Object (File)
Mon, Sep 23, 1:12 PM
Unknown Object (File)
Mon, Sep 23, 5:44 AM
Unknown Object (File)
Mon, Sep 23, 1:32 AM
Unknown Object (File)
Sun, Sep 22, 2:56 AM
Unknown Object (File)
Wed, Sep 18, 4:14 PM
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 Not Applicable
Unit
Tests Not Applicable