/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Linker script macros to generate Image header fields.3*4* Copyright (C) 2014 ARM Ltd.5*/6#ifndef __ARM64_KERNEL_IMAGE_H7#define __ARM64_KERNEL_IMAGE_H89#ifndef LINKER_SCRIPT10#error This file should only be included in vmlinux.lds.S11#endif1213#include <asm/image.h>1415/*16* There aren't any ELF relocations we can use to endian-swap values known only17* at link time (e.g. the subtraction of two symbol addresses), so we must get18* the linker to endian-swap certain values before emitting them.19*20* Note that, in order for this to work when building the ELF64 PIE executable21* (for KASLR), these values should not be referenced via R_AARCH64_ABS6422* relocations, since these are fixed up at runtime rather than at build time23* when PIE is in effect. So we need to split them up in 32-bit high and low24* words.25*/26#ifdef CONFIG_CPU_BIG_ENDIAN27#define DATA_LE32(data) \28((((data) & 0x000000ff) << 24) | \29(((data) & 0x0000ff00) << 8) | \30(((data) & 0x00ff0000) >> 8) | \31(((data) & 0xff000000) >> 24))32#else33#define DATA_LE32(data) ((data) & 0xffffffff)34#endif3536#define DEFINE_IMAGE_LE64(sym, data) \37sym##_lo32 = DATA_LE32((data) & 0xffffffff); \38sym##_hi32 = DATA_LE32((data) >> 32)3940#define __HEAD_FLAG(field) (__HEAD_FLAG_##field << \41ARM64_IMAGE_FLAG_##field##_SHIFT)4243#ifdef CONFIG_CPU_BIG_ENDIAN44#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_BE45#else46#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_LE47#endif4849#define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2)5051#define __HEAD_FLAG_PHYS_BASE 15253#define __HEAD_FLAGS (__HEAD_FLAG(BE) | \54__HEAD_FLAG(PAGE_SIZE) | \55__HEAD_FLAG(PHYS_BASE))5657/*58* These will output as part of the Image header, which should be little-endian59* regardless of the endianness of the kernel. While constant values could be60* endian swapped in head.S, all are done here for consistency.61*/62#define HEAD_SYMBOLS \63DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text); \64DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);6566#endif /* __ARM64_KERNEL_IMAGE_H */676869