xref: /openbmc/linux/arch/arm64/kernel/image.h (revision 8fdf9062)
1 /*
2  * Linker script macros to generate Image header fields.
3  *
4  * Copyright (C) 2014 ARM Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #ifndef __ARM64_KERNEL_IMAGE_H
19 #define __ARM64_KERNEL_IMAGE_H
20 
21 #ifndef LINKER_SCRIPT
22 #error This file should only be included in vmlinux.lds.S
23 #endif
24 
25 #include <asm/image.h>
26 
27 /*
28  * There aren't any ELF relocations we can use to endian-swap values known only
29  * at link time (e.g. the subtraction of two symbol addresses), so we must get
30  * the linker to endian-swap certain values before emitting them.
31  *
32  * Note that, in order for this to work when building the ELF64 PIE executable
33  * (for KASLR), these values should not be referenced via R_AARCH64_ABS64
34  * relocations, since these are fixed up at runtime rather than at build time
35  * when PIE is in effect. So we need to split them up in 32-bit high and low
36  * words.
37  */
38 #ifdef CONFIG_CPU_BIG_ENDIAN
39 #define DATA_LE32(data)				\
40 	((((data) & 0x000000ff) << 24) |	\
41 	 (((data) & 0x0000ff00) << 8)  |	\
42 	 (((data) & 0x00ff0000) >> 8)  |	\
43 	 (((data) & 0xff000000) >> 24))
44 #else
45 #define DATA_LE32(data) ((data) & 0xffffffff)
46 #endif
47 
48 #define DEFINE_IMAGE_LE64(sym, data)				\
49 	sym##_lo32 = DATA_LE32((data) & 0xffffffff);		\
50 	sym##_hi32 = DATA_LE32((data) >> 32)
51 
52 #define __HEAD_FLAG(field)	(__HEAD_FLAG_##field << \
53 					ARM64_IMAGE_FLAG_##field##_SHIFT)
54 
55 #ifdef CONFIG_CPU_BIG_ENDIAN
56 #define __HEAD_FLAG_BE		ARM64_IMAGE_FLAG_BE
57 #else
58 #define __HEAD_FLAG_BE		ARM64_IMAGE_FLAG_LE
59 #endif
60 
61 #define __HEAD_FLAG_PAGE_SIZE	((PAGE_SHIFT - 10) / 2)
62 
63 #define __HEAD_FLAG_PHYS_BASE	1
64 
65 #define __HEAD_FLAGS		(__HEAD_FLAG(BE)	| \
66 				 __HEAD_FLAG(PAGE_SIZE) | \
67 				 __HEAD_FLAG(PHYS_BASE))
68 
69 /*
70  * These will output as part of the Image header, which should be little-endian
71  * regardless of the endianness of the kernel. While constant values could be
72  * endian swapped in head.S, all are done here for consistency.
73  */
74 #define HEAD_SYMBOLS						\
75 	DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text);	\
76 	DEFINE_IMAGE_LE64(_kernel_offset_le, TEXT_OFFSET);	\
77 	DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);
78 
79 #ifdef CONFIG_EFI
80 
81 __efistub_stext_offset = stext - _text;
82 
83 /*
84  * The EFI stub has its own symbol namespace prefixed by __efistub_, to
85  * isolate it from the kernel proper. The following symbols are legally
86  * accessed by the stub, so provide some aliases to make them accessible.
87  * Only include data symbols here, or text symbols of functions that are
88  * guaranteed to be safe when executed at another offset than they were
89  * linked at. The routines below are all implemented in assembler in a
90  * position independent manner
91  */
92 __efistub_memcmp		= __pi_memcmp;
93 __efistub_memchr		= __pi_memchr;
94 __efistub_memcpy		= __pi_memcpy;
95 __efistub_memmove		= __pi_memmove;
96 __efistub_memset		= __pi_memset;
97 __efistub_strlen		= __pi_strlen;
98 __efistub_strnlen		= __pi_strnlen;
99 __efistub_strcmp		= __pi_strcmp;
100 __efistub_strncmp		= __pi_strncmp;
101 __efistub_strrchr		= __pi_strrchr;
102 __efistub___flush_dcache_area	= __pi___flush_dcache_area;
103 
104 #ifdef CONFIG_KASAN
105 __efistub___memcpy		= __pi_memcpy;
106 __efistub___memmove		= __pi_memmove;
107 __efistub___memset		= __pi_memset;
108 #endif
109 
110 __efistub__text			= _text;
111 __efistub__end			= _end;
112 __efistub__edata		= _edata;
113 __efistub_screen_info		= screen_info;
114 
115 #endif
116 
117 #endif /* __ARM64_KERNEL_IMAGE_H */
118