1a2c1d73bSMark Rutland /* 2a2c1d73bSMark Rutland * Linker script macros to generate Image header fields. 3a2c1d73bSMark Rutland * 4a2c1d73bSMark Rutland * Copyright (C) 2014 ARM Ltd. 5a2c1d73bSMark Rutland * 6a2c1d73bSMark Rutland * This program is free software; you can redistribute it and/or modify 7a2c1d73bSMark Rutland * it under the terms of the GNU General Public License version 2 as 8a2c1d73bSMark Rutland * published by the Free Software Foundation. 9a2c1d73bSMark Rutland * 10a2c1d73bSMark Rutland * This program is distributed in the hope that it will be useful, 11a2c1d73bSMark Rutland * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a2c1d73bSMark Rutland * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a2c1d73bSMark Rutland * GNU General Public License for more details. 14a2c1d73bSMark Rutland * 15a2c1d73bSMark Rutland * You should have received a copy of the GNU General Public License 16a2c1d73bSMark Rutland * along with this program. If not, see <http://www.gnu.org/licenses/>. 17a2c1d73bSMark Rutland */ 18*f56063c5SAKASHI Takahiro #ifndef __ARM64_KERNEL_IMAGE_H 19*f56063c5SAKASHI Takahiro #define __ARM64_KERNEL_IMAGE_H 20a2c1d73bSMark Rutland 21a2c1d73bSMark Rutland #ifndef LINKER_SCRIPT 22a2c1d73bSMark Rutland #error This file should only be included in vmlinux.lds.S 23a2c1d73bSMark Rutland #endif 24a2c1d73bSMark Rutland 25*f56063c5SAKASHI Takahiro #include <asm/image.h> 26*f56063c5SAKASHI Takahiro 27a2c1d73bSMark Rutland /* 28a2c1d73bSMark Rutland * There aren't any ELF relocations we can use to endian-swap values known only 29a2c1d73bSMark Rutland * at link time (e.g. the subtraction of two symbol addresses), so we must get 30a2c1d73bSMark Rutland * the linker to endian-swap certain values before emitting them. 316ad1fe5dSArd Biesheuvel * 326ad1fe5dSArd Biesheuvel * Note that, in order for this to work when building the ELF64 PIE executable 336ad1fe5dSArd Biesheuvel * (for KASLR), these values should not be referenced via R_AARCH64_ABS64 346ad1fe5dSArd Biesheuvel * relocations, since these are fixed up at runtime rather than at build time 356ad1fe5dSArd Biesheuvel * when PIE is in effect. So we need to split them up in 32-bit high and low 366ad1fe5dSArd Biesheuvel * words. 37a2c1d73bSMark Rutland */ 38a2c1d73bSMark Rutland #ifdef CONFIG_CPU_BIG_ENDIAN 396ad1fe5dSArd Biesheuvel #define DATA_LE32(data) \ 406ad1fe5dSArd Biesheuvel ((((data) & 0x000000ff) << 24) | \ 416ad1fe5dSArd Biesheuvel (((data) & 0x0000ff00) << 8) | \ 426ad1fe5dSArd Biesheuvel (((data) & 0x00ff0000) >> 8) | \ 436ad1fe5dSArd Biesheuvel (((data) & 0xff000000) >> 24)) 44a2c1d73bSMark Rutland #else 456ad1fe5dSArd Biesheuvel #define DATA_LE32(data) ((data) & 0xffffffff) 46a2c1d73bSMark Rutland #endif 47a2c1d73bSMark Rutland 486ad1fe5dSArd Biesheuvel #define DEFINE_IMAGE_LE64(sym, data) \ 496ad1fe5dSArd Biesheuvel sym##_lo32 = DATA_LE32((data) & 0xffffffff); \ 506ad1fe5dSArd Biesheuvel sym##_hi32 = DATA_LE32((data) >> 32) 516ad1fe5dSArd Biesheuvel 52*f56063c5SAKASHI Takahiro #define __HEAD_FLAG(field) (__HEAD_FLAG_##field << \ 53*f56063c5SAKASHI Takahiro ARM64_IMAGE_FLAG_##field##_SHIFT) 54*f56063c5SAKASHI Takahiro 55a2c1d73bSMark Rutland #ifdef CONFIG_CPU_BIG_ENDIAN 56*f56063c5SAKASHI Takahiro #define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_BE 57a2c1d73bSMark Rutland #else 58*f56063c5SAKASHI Takahiro #define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_LE 59a2c1d73bSMark Rutland #endif 60a2c1d73bSMark Rutland 619d372c9fSArd Biesheuvel #define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2) 629d372c9fSArd Biesheuvel 63a7f8de16SArd Biesheuvel #define __HEAD_FLAG_PHYS_BASE 1 64a7f8de16SArd Biesheuvel 65*f56063c5SAKASHI Takahiro #define __HEAD_FLAGS (__HEAD_FLAG(BE) | \ 66*f56063c5SAKASHI Takahiro __HEAD_FLAG(PAGE_SIZE) | \ 67*f56063c5SAKASHI Takahiro __HEAD_FLAG(PHYS_BASE)) 68a2c1d73bSMark Rutland 69a2c1d73bSMark Rutland /* 70a2c1d73bSMark Rutland * These will output as part of the Image header, which should be little-endian 71a2c1d73bSMark Rutland * regardless of the endianness of the kernel. While constant values could be 72a2c1d73bSMark Rutland * endian swapped in head.S, all are done here for consistency. 73a2c1d73bSMark Rutland */ 74a2c1d73bSMark Rutland #define HEAD_SYMBOLS \ 756ad1fe5dSArd Biesheuvel DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text); \ 766ad1fe5dSArd Biesheuvel DEFINE_IMAGE_LE64(_kernel_offset_le, TEXT_OFFSET); \ 776ad1fe5dSArd Biesheuvel DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS); 78a2c1d73bSMark Rutland 79e8f3010fSArd Biesheuvel #ifdef CONFIG_EFI 80e8f3010fSArd Biesheuvel 81546c8c44SArd Biesheuvel __efistub_stext_offset = stext - _text; 82546c8c44SArd Biesheuvel 83e8f3010fSArd Biesheuvel /* 8475feee3dSArd Biesheuvel * Prevent the symbol aliases below from being emitted into the kallsyms 8575feee3dSArd Biesheuvel * table, by forcing them to be absolute symbols (which are conveniently 8675feee3dSArd Biesheuvel * ignored by scripts/kallsyms) rather than section relative symbols. 8775feee3dSArd Biesheuvel * The distinction is only relevant for partial linking, and only for symbols 8875feee3dSArd Biesheuvel * that are defined within a section declaration (which is not the case for 8975feee3dSArd Biesheuvel * the definitions below) so the resulting values will be identical. 9075feee3dSArd Biesheuvel */ 9175feee3dSArd Biesheuvel #define KALLSYMS_HIDE(sym) ABSOLUTE(sym) 9275feee3dSArd Biesheuvel 9375feee3dSArd Biesheuvel /* 94e8f3010fSArd Biesheuvel * The EFI stub has its own symbol namespace prefixed by __efistub_, to 95e8f3010fSArd Biesheuvel * isolate it from the kernel proper. The following symbols are legally 96e8f3010fSArd Biesheuvel * accessed by the stub, so provide some aliases to make them accessible. 97e8f3010fSArd Biesheuvel * Only include data symbols here, or text symbols of functions that are 98e8f3010fSArd Biesheuvel * guaranteed to be safe when executed at another offset than they were 99e8f3010fSArd Biesheuvel * linked at. The routines below are all implemented in assembler in a 100e8f3010fSArd Biesheuvel * position independent manner 101e8f3010fSArd Biesheuvel */ 10275feee3dSArd Biesheuvel __efistub_memcmp = KALLSYMS_HIDE(__pi_memcmp); 10375feee3dSArd Biesheuvel __efistub_memchr = KALLSYMS_HIDE(__pi_memchr); 10475feee3dSArd Biesheuvel __efistub_memcpy = KALLSYMS_HIDE(__pi_memcpy); 10575feee3dSArd Biesheuvel __efistub_memmove = KALLSYMS_HIDE(__pi_memmove); 10675feee3dSArd Biesheuvel __efistub_memset = KALLSYMS_HIDE(__pi_memset); 10775feee3dSArd Biesheuvel __efistub_strlen = KALLSYMS_HIDE(__pi_strlen); 1087f4e3462SThierry Reding __efistub_strnlen = KALLSYMS_HIDE(__pi_strnlen); 10975feee3dSArd Biesheuvel __efistub_strcmp = KALLSYMS_HIDE(__pi_strcmp); 11075feee3dSArd Biesheuvel __efistub_strncmp = KALLSYMS_HIDE(__pi_strncmp); 111fdfb69a7SRob Herring __efistub_strrchr = KALLSYMS_HIDE(__pi_strrchr); 11275feee3dSArd Biesheuvel __efistub___flush_dcache_area = KALLSYMS_HIDE(__pi___flush_dcache_area); 113e8f3010fSArd Biesheuvel 11439d114ddSAndrey Ryabinin #ifdef CONFIG_KASAN 11575feee3dSArd Biesheuvel __efistub___memcpy = KALLSYMS_HIDE(__pi_memcpy); 11675feee3dSArd Biesheuvel __efistub___memmove = KALLSYMS_HIDE(__pi_memmove); 11775feee3dSArd Biesheuvel __efistub___memset = KALLSYMS_HIDE(__pi_memset); 11839d114ddSAndrey Ryabinin #endif 11939d114ddSAndrey Ryabinin 12075feee3dSArd Biesheuvel __efistub__text = KALLSYMS_HIDE(_text); 12175feee3dSArd Biesheuvel __efistub__end = KALLSYMS_HIDE(_end); 12275feee3dSArd Biesheuvel __efistub__edata = KALLSYMS_HIDE(_edata); 12357fdb89aSArd Biesheuvel __efistub_screen_info = KALLSYMS_HIDE(screen_info); 124e8f3010fSArd Biesheuvel 125e8f3010fSArd Biesheuvel #endif 126e8f3010fSArd Biesheuvel 127*f56063c5SAKASHI Takahiro #endif /* __ARM64_KERNEL_IMAGE_H */ 128