Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Nov 2023 18:23:27 +0000
From:      Jessica Clarke <jrtc27@freebsd.org>
To:        Andrew Turner <andrew@FreeBSD.org>
Cc:        "src-committers@freebsd.org" <src-committers@FreeBSD.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@FreeBSD.org>, "dev-commits-src-main@freebsd.org" <dev-commits-src-main@FreeBSD.org>
Subject:   Re: git: 7eb26be9c808 - main - arm64: Use adrp + :lo12: to load globals from asm
Message-ID:  <D367E2EC-71AC-4EA0-B95D-161B950C1442@freebsd.org>
In-Reply-To: <202311151812.3AFICH9p077368@gitrepo.freebsd.org>
References:  <202311151812.3AFICH9p077368@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 15 Nov 2023, at 18:12, Andrew Turner <andrew@FreeBSD.org> wrote:
>=20
> The branch main has been updated by andrew:
>=20
> URL: =
https://cgit.FreeBSD.org/src/commit/?id=3D7eb26be9c8080686f64fdc0a28e5ae78=
39bbc82d
>=20
> commit 7eb26be9c8080686f64fdc0a28e5ae7839bbc82d
> Author:     Andrew Turner <andrew@FreeBSD.org>
> AuthorDate: 2023-11-11 09:27:30 +0000
> Commit:     Andrew Turner <andrew@FreeBSD.org>
> CommitDate: 2023-11-15 18:05:08 +0000
>=20
>    arm64: Use adrp + :lo12: to load globals from asm
>=20
>    When loading a global variable we can use a pseudo-instruction =
similar
>    to "ldr, xn, =3Dglobal" 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.
>=20
>    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]".
>=20
>    The only remaining users of "ldr, xn, =3Dglobal" 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.
>=20
>    Sponsored by:   Arm Ltd
>    Differential Revision:  https://reviews.freebsd.org/D42565

I assume the motivation for this, which seems to be missing from the
description, is that it removes an unnecessary level of indirection,
rather than that there are issues with the PC-relative load literal
instruction not working, given that I doubt we=E2=80=99re hitting the 1 =
MiB
literal pool offset range limit in hand-written assembly?

Jess




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?D367E2EC-71AC-4EA0-B95D-161B950C1442>