xref: /openbmc/linux/arch/hexagon/include/asm/elf.h (revision 55fd7e02)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * ELF definitions for the Hexagon architecture
4  *
5  * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
6  */
7 
8 #ifndef __ASM_ELF_H
9 #define __ASM_ELF_H
10 
11 #include <asm/ptrace.h>
12 #include <asm/user.h>
13 #include <linux/elf-em.h>
14 
15 struct elf32_hdr;
16 
17 /*
18  * ELF header e_flags defines.
19  */
20 
21 /*  should have stuff like "CPU type" and maybe "ABI version", etc  */
22 
23 /* Hexagon relocations */
24   /* V2 */
25 #define R_HEXAGON_NONE           0
26 #define R_HEXAGON_B22_PCREL      1
27 #define R_HEXAGON_B15_PCREL      2
28 #define R_HEXAGON_B7_PCREL       3
29 #define R_HEXAGON_LO16           4
30 #define R_HEXAGON_HI16           5
31 #define R_HEXAGON_32             6
32 #define R_HEXAGON_16             7
33 #define R_HEXAGON_8              8
34 #define R_HEXAGON_GPREL16_0      9
35 #define R_HEXAGON_GPREL16_1     10
36 #define R_HEXAGON_GPREL16_2     11
37 #define R_HEXAGON_GPREL16_3     12
38 #define R_HEXAGON_HL16          13
39   /* V3 */
40 #define R_HEXAGON_B13_PCREL     14
41   /* V4 */
42 #define R_HEXAGON_B9_PCREL      15
43   /* V4 (extenders) */
44 #define R_HEXAGON_B32_PCREL_X   16
45 #define R_HEXAGON_32_6_X        17
46   /* V4 (extended) */
47 #define R_HEXAGON_B22_PCREL_X   18
48 #define R_HEXAGON_B15_PCREL_X   19
49 #define R_HEXAGON_B13_PCREL_X   20
50 #define R_HEXAGON_B9_PCREL_X    21
51 #define R_HEXAGON_B7_PCREL_X    22
52 #define R_HEXAGON_16_X          23
53 #define R_HEXAGON_12_X          24
54 #define R_HEXAGON_11_X          25
55 #define R_HEXAGON_10_X          26
56 #define R_HEXAGON_9_X           27
57 #define R_HEXAGON_8_X           28
58 #define R_HEXAGON_7_X           29
59 #define R_HEXAGON_6_X           30
60   /* V2 PIC */
61 #define R_HEXAGON_32_PCREL      31
62 #define R_HEXAGON_COPY          32
63 #define R_HEXAGON_GLOB_DAT      33
64 #define R_HEXAGON_JMP_SLOT      34
65 #define R_HEXAGON_RELATIVE      35
66 #define R_HEXAGON_PLT_B22_PCREL 36
67 #define R_HEXAGON_GOTOFF_LO16   37
68 #define R_HEXAGON_GOTOFF_HI16   38
69 #define R_HEXAGON_GOTOFF_32     39
70 #define R_HEXAGON_GOT_LO16      40
71 #define R_HEXAGON_GOT_HI16      41
72 #define R_HEXAGON_GOT_32        42
73 #define R_HEXAGON_GOT_16        43
74 
75 /*
76  * ELF register definitions..
77  */
78 typedef unsigned long elf_greg_t;
79 
80 typedef struct user_regs_struct elf_gregset_t;
81 #define ELF_NGREG (sizeof(elf_gregset_t)/sizeof(unsigned long))
82 
83 /*  Placeholder  */
84 typedef unsigned long elf_fpregset_t;
85 
86 /*
87  * Bypass the whole "regsets" thing for now and use the define.
88  */
89 
90 #if CONFIG_HEXAGON_ARCH_VERSION >= 4
91 #define CS_COPYREGS(DEST,REGS) \
92 do {\
93 	DEST.cs0 = REGS->cs0;\
94 	DEST.cs1 = REGS->cs1;\
95 } while (0)
96 #else
97 #define CS_COPYREGS(DEST,REGS)
98 #endif
99 
100 #define ELF_CORE_COPY_REGS(DEST, REGS)	\
101 do {					\
102 	DEST.r0 = REGS->r00;		\
103 	DEST.r1 = REGS->r01;		\
104 	DEST.r2 = REGS->r02;		\
105 	DEST.r3 = REGS->r03;		\
106 	DEST.r4 = REGS->r04;		\
107 	DEST.r5 = REGS->r05;		\
108 	DEST.r6 = REGS->r06;		\
109 	DEST.r7 = REGS->r07;		\
110 	DEST.r8 = REGS->r08;		\
111 	DEST.r9 = REGS->r09;		\
112 	DEST.r10 = REGS->r10;		\
113 	DEST.r11 = REGS->r11;		\
114 	DEST.r12 = REGS->r12;		\
115 	DEST.r13 = REGS->r13;		\
116 	DEST.r14 = REGS->r14;		\
117 	DEST.r15 = REGS->r15;		\
118 	DEST.r16 = REGS->r16;		\
119 	DEST.r17 = REGS->r17;		\
120 	DEST.r18 = REGS->r18;		\
121 	DEST.r19 = REGS->r19;		\
122 	DEST.r20 = REGS->r20;		\
123 	DEST.r21 = REGS->r21;		\
124 	DEST.r22 = REGS->r22;		\
125 	DEST.r23 = REGS->r23;		\
126 	DEST.r24 = REGS->r24;		\
127 	DEST.r25 = REGS->r25;		\
128 	DEST.r26 = REGS->r26;		\
129 	DEST.r27 = REGS->r27;		\
130 	DEST.r28 = REGS->r28;		\
131 	DEST.r29 = pt_psp(REGS);	\
132 	DEST.r30 = REGS->r30;		\
133 	DEST.r31 = REGS->r31;		\
134 	DEST.sa0 = REGS->sa0;		\
135 	DEST.lc0 = REGS->lc0;		\
136 	DEST.sa1 = REGS->sa1;		\
137 	DEST.lc1 = REGS->lc1;		\
138 	DEST.m0 = REGS->m0;		\
139 	DEST.m1 = REGS->m1;		\
140 	DEST.usr = REGS->usr;		\
141 	DEST.p3_0 = REGS->preds;	\
142 	DEST.gp = REGS->gp;		\
143 	DEST.ugp = REGS->ugp;		\
144 	CS_COPYREGS(DEST,REGS);		\
145 	DEST.pc = pt_elr(REGS);		\
146 	DEST.cause = pt_cause(REGS);	\
147 	DEST.badva = pt_badva(REGS);	\
148 } while (0);
149 
150 /*
151  * This is used to ensure we don't load something for the wrong architecture.
152  * Checks the machine and ABI type.
153  */
154 #define elf_check_arch(hdr)	((hdr)->e_machine == EM_HEXAGON)
155 
156 /*
157  * These are used to set parameters in the core dumps.
158  */
159 #define ELF_CLASS	ELFCLASS32
160 #define ELF_DATA	ELFDATA2LSB
161 #define ELF_ARCH	EM_HEXAGON
162 
163 #if CONFIG_HEXAGON_ARCH_VERSION == 2
164 #define ELF_CORE_EFLAGS 0x1
165 #endif
166 
167 #if CONFIG_HEXAGON_ARCH_VERSION == 3
168 #define ELF_CORE_EFLAGS 0x2
169 #endif
170 
171 #if CONFIG_HEXAGON_ARCH_VERSION == 4
172 #define ELF_CORE_EFLAGS 0x3
173 #endif
174 
175 /*
176  * Some architectures have ld.so set up a pointer to a function
177  * to be registered using atexit, to facilitate cleanup.  So that
178  * static executables will be well-behaved, we would null the register
179  * in question here, in the pt_regs structure passed.  For now,
180  * leave it a null macro.
181  */
182 #define ELF_PLAT_INIT(regs, load_addr) do { } while (0)
183 
184 #define USE_ELF_CORE_DUMP
185 #define CORE_DUMP_USE_REGSET
186 
187 /* Hrm is this going to cause problems for changing PAGE_SIZE?  */
188 #define ELF_EXEC_PAGESIZE	PAGE_SIZE
189 
190 /*
191  * This is the location that an ET_DYN program is loaded if exec'ed.  Typical
192  * use of this is to invoke "./ld.so someprog" to test out a new version of
193  * the loader.  We need to make sure that it is out of the way of the program
194  * that it will "exec", and that there is sufficient room for the brk.
195  */
196 #define ELF_ET_DYN_BASE         0x08000000UL
197 
198 /*
199  * This yields a mask that user programs can use to figure out what
200  * instruction set this cpu supports.
201  */
202 #define ELF_HWCAP	(0)
203 
204 /*
205  * This yields a string that ld.so will use to load implementation
206  * specific libraries for optimization.  This is more specific in
207  * intent than poking at uname or /proc/cpuinfo.
208  */
209 #define ELF_PLATFORM  (NULL)
210 
211 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
212 struct linux_binprm;
213 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
214 				       int uses_interp);
215 
216 
217 #endif
218