image.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Linker script macros to generate Image header fields.
  4. *
  5. * Copyright (C) 2014 ARM Ltd.
  6. */
  7. #ifndef __ARM64_KERNEL_IMAGE_H
  8. #define __ARM64_KERNEL_IMAGE_H
  9. #ifndef LINKER_SCRIPT
  10. #error This file should only be included in vmlinux.lds.S
  11. #endif
  12. #include <asm/image.h>
  13. /*
  14. * There aren't any ELF relocations we can use to endian-swap values known only
  15. * at link time (e.g. the subtraction of two symbol addresses), so we must get
  16. * the linker to endian-swap certain values before emitting them.
  17. *
  18. * Note that, in order for this to work when building the ELF64 PIE executable
  19. * (for KASLR), these values should not be referenced via R_AARCH64_ABS64
  20. * relocations, since these are fixed up at runtime rather than at build time
  21. * when PIE is in effect. So we need to split them up in 32-bit high and low
  22. * words.
  23. */
  24. #ifdef CONFIG_CPU_BIG_ENDIAN
  25. #define DATA_LE32(data) \
  26. ((((data) & 0x000000ff) << 24) | \
  27. (((data) & 0x0000ff00) << 8) | \
  28. (((data) & 0x00ff0000) >> 8) | \
  29. (((data) & 0xff000000) >> 24))
  30. #else
  31. #define DATA_LE32(data) ((data) & 0xffffffff)
  32. #endif
  33. #define DEFINE_IMAGE_LE64(sym, data) \
  34. sym##_lo32 = DATA_LE32((data) & 0xffffffff); \
  35. sym##_hi32 = DATA_LE32((data) >> 32)
  36. #define __HEAD_FLAG(field) (__HEAD_FLAG_##field << \
  37. ARM64_IMAGE_FLAG_##field##_SHIFT)
  38. #ifdef CONFIG_CPU_BIG_ENDIAN
  39. #define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_BE
  40. #else
  41. #define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_LE
  42. #endif
  43. #define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2)
  44. #define __HEAD_FLAG_PHYS_BASE 1
  45. #define __HEAD_FLAGS (__HEAD_FLAG(BE) | \
  46. __HEAD_FLAG(PAGE_SIZE) | \
  47. __HEAD_FLAG(PHYS_BASE))
  48. /*
  49. * These will output as part of the Image header, which should be little-endian
  50. * regardless of the endianness of the kernel. While constant values could be
  51. * endian swapped in head.S, all are done here for consistency.
  52. */
  53. #define HEAD_SYMBOLS \
  54. DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text); \
  55. DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);
  56. #endif /* __ARM64_KERNEL_IMAGE_H */