162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * include/asm-xtensa/elf.h
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * ELF register definitions
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
762306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
862306a36Sopenharmony_ci * for more details.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * Copyright (C) 2001 - 2005 Tensilica Inc.
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifndef _XTENSA_ELF_H
1462306a36Sopenharmony_ci#define _XTENSA_ELF_H
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <asm/ptrace.h>
1762306a36Sopenharmony_ci#include <asm/coprocessor.h>
1862306a36Sopenharmony_ci#include <linux/elf-em.h>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* Xtensa processor ELF architecture-magic number */
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define EM_XTENSA_OLD	0xABC7
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci/* Xtensa relocations defined by the ABIs */
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define R_XTENSA_NONE           0
2762306a36Sopenharmony_ci#define R_XTENSA_32             1
2862306a36Sopenharmony_ci#define R_XTENSA_RTLD           2
2962306a36Sopenharmony_ci#define R_XTENSA_GLOB_DAT       3
3062306a36Sopenharmony_ci#define R_XTENSA_JMP_SLOT       4
3162306a36Sopenharmony_ci#define R_XTENSA_RELATIVE       5
3262306a36Sopenharmony_ci#define R_XTENSA_PLT            6
3362306a36Sopenharmony_ci#define R_XTENSA_OP0            8
3462306a36Sopenharmony_ci#define R_XTENSA_OP1            9
3562306a36Sopenharmony_ci#define R_XTENSA_OP2            10
3662306a36Sopenharmony_ci#define R_XTENSA_ASM_EXPAND	11
3762306a36Sopenharmony_ci#define R_XTENSA_ASM_SIMPLIFY	12
3862306a36Sopenharmony_ci#define R_XTENSA_GNU_VTINHERIT	15
3962306a36Sopenharmony_ci#define R_XTENSA_GNU_VTENTRY	16
4062306a36Sopenharmony_ci#define R_XTENSA_DIFF8		17
4162306a36Sopenharmony_ci#define R_XTENSA_DIFF16		18
4262306a36Sopenharmony_ci#define R_XTENSA_DIFF32		19
4362306a36Sopenharmony_ci#define R_XTENSA_SLOT0_OP	20
4462306a36Sopenharmony_ci#define R_XTENSA_SLOT1_OP	21
4562306a36Sopenharmony_ci#define R_XTENSA_SLOT2_OP	22
4662306a36Sopenharmony_ci#define R_XTENSA_SLOT3_OP	23
4762306a36Sopenharmony_ci#define R_XTENSA_SLOT4_OP	24
4862306a36Sopenharmony_ci#define R_XTENSA_SLOT5_OP	25
4962306a36Sopenharmony_ci#define R_XTENSA_SLOT6_OP	26
5062306a36Sopenharmony_ci#define R_XTENSA_SLOT7_OP	27
5162306a36Sopenharmony_ci#define R_XTENSA_SLOT8_OP	28
5262306a36Sopenharmony_ci#define R_XTENSA_SLOT9_OP	29
5362306a36Sopenharmony_ci#define R_XTENSA_SLOT10_OP	30
5462306a36Sopenharmony_ci#define R_XTENSA_SLOT11_OP	31
5562306a36Sopenharmony_ci#define R_XTENSA_SLOT12_OP	32
5662306a36Sopenharmony_ci#define R_XTENSA_SLOT13_OP	33
5762306a36Sopenharmony_ci#define R_XTENSA_SLOT14_OP	34
5862306a36Sopenharmony_ci#define R_XTENSA_SLOT0_ALT	35
5962306a36Sopenharmony_ci#define R_XTENSA_SLOT1_ALT	36
6062306a36Sopenharmony_ci#define R_XTENSA_SLOT2_ALT	37
6162306a36Sopenharmony_ci#define R_XTENSA_SLOT3_ALT	38
6262306a36Sopenharmony_ci#define R_XTENSA_SLOT4_ALT	39
6362306a36Sopenharmony_ci#define R_XTENSA_SLOT5_ALT	40
6462306a36Sopenharmony_ci#define R_XTENSA_SLOT6_ALT	41
6562306a36Sopenharmony_ci#define R_XTENSA_SLOT7_ALT	42
6662306a36Sopenharmony_ci#define R_XTENSA_SLOT8_ALT	43
6762306a36Sopenharmony_ci#define R_XTENSA_SLOT9_ALT	44
6862306a36Sopenharmony_ci#define R_XTENSA_SLOT10_ALT	45
6962306a36Sopenharmony_ci#define R_XTENSA_SLOT11_ALT	46
7062306a36Sopenharmony_ci#define R_XTENSA_SLOT12_ALT	47
7162306a36Sopenharmony_ci#define R_XTENSA_SLOT13_ALT	48
7262306a36Sopenharmony_ci#define R_XTENSA_SLOT14_ALT	49
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/* ELF register definitions. This is needed for core dump support.  */
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_citypedef unsigned long elf_greg_t;
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_citypedef struct user_pt_regs xtensa_gregset_t;
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define ELF_NGREG	(sizeof(xtensa_gregset_t) / sizeof(elf_greg_t))
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_citypedef elf_greg_t elf_gregset_t[ELF_NGREG];
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#define ELF_NFPREG	18
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_citypedef unsigned int elf_fpreg_t;
8762306a36Sopenharmony_citypedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci/*
9062306a36Sopenharmony_ci * This is used to ensure we don't load something for the wrong architecture.
9162306a36Sopenharmony_ci */
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci#define elf_check_arch(x) ( ( (x)->e_machine == EM_XTENSA )  || \
9462306a36Sopenharmony_ci			    ( (x)->e_machine == EM_XTENSA_OLD ) )
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define ELFOSABI_XTENSA_FDPIC 65
9762306a36Sopenharmony_ci#define elf_check_fdpic(x) ((x)->e_ident[EI_OSABI] == ELFOSABI_XTENSA_FDPIC)
9862306a36Sopenharmony_ci#define ELF_FDPIC_CORE_EFLAGS 0
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci/*
10162306a36Sopenharmony_ci * These are used to set parameters in the core dumps.
10262306a36Sopenharmony_ci */
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#ifdef __XTENSA_EL__
10562306a36Sopenharmony_ci# define ELF_DATA	ELFDATA2LSB
10662306a36Sopenharmony_ci#elif defined(__XTENSA_EB__)
10762306a36Sopenharmony_ci# define ELF_DATA	ELFDATA2MSB
10862306a36Sopenharmony_ci#else
10962306a36Sopenharmony_ci# error processor byte order undefined!
11062306a36Sopenharmony_ci#endif
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#define ELF_CLASS	ELFCLASS32
11362306a36Sopenharmony_ci#define ELF_ARCH	EM_XTENSA
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define ELF_EXEC_PAGESIZE	PAGE_SIZE
11662306a36Sopenharmony_ci#define CORE_DUMP_USE_REGSET
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/*
11962306a36Sopenharmony_ci * This is the location that an ET_DYN program is loaded if exec'ed.  Typical
12062306a36Sopenharmony_ci * use of this is to invoke "./ld.so someprog" to test out a new version of
12162306a36Sopenharmony_ci * the loader.  We need to make sure that it is out of the way of the program
12262306a36Sopenharmony_ci * that it will "exec", and that there is sufficient room for the brk.
12362306a36Sopenharmony_ci */
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci#define ELF_ET_DYN_BASE         (2 * TASK_SIZE / 3)
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci/*
12862306a36Sopenharmony_ci * This yields a mask that user programs can use to figure out what
12962306a36Sopenharmony_ci * instruction set this CPU supports.  This could be done in user space,
13062306a36Sopenharmony_ci * but it's not easy, and we've already done it here.
13162306a36Sopenharmony_ci */
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci#define ELF_HWCAP	(0)
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/*
13662306a36Sopenharmony_ci * This yields a string that ld.so will use to load implementation
13762306a36Sopenharmony_ci * specific libraries for optimization.  This is more specific in
13862306a36Sopenharmony_ci * intent than poking at uname or /proc/cpuinfo.
13962306a36Sopenharmony_ci * For the moment, we have only optimizations for the Intel generations,
14062306a36Sopenharmony_ci * but that could change...
14162306a36Sopenharmony_ci */
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci#define ELF_PLATFORM  (NULL)
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/*
14662306a36Sopenharmony_ci * The Xtensa processor ABI says that when the program starts, a2
14762306a36Sopenharmony_ci * contains a pointer to a function which might be registered using
14862306a36Sopenharmony_ci * `atexit'.  This provides a mean for the dynamic linker to call
14962306a36Sopenharmony_ci * DT_FINI functions for shared libraries that have been loaded before
15062306a36Sopenharmony_ci * the code runs.
15162306a36Sopenharmony_ci *
15262306a36Sopenharmony_ci * A value of 0 tells we have no such handler.
15362306a36Sopenharmony_ci *
15462306a36Sopenharmony_ci * We might as well make sure everything else is cleared too (except
15562306a36Sopenharmony_ci * for the stack pointer in a1), just to make things more
15662306a36Sopenharmony_ci * deterministic.  Also, clearing a0 terminates debugger backtraces.
15762306a36Sopenharmony_ci */
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci#define ELF_PLAT_INIT(_r, load_addr) \
16062306a36Sopenharmony_ci	do { \
16162306a36Sopenharmony_ci		(_r)->areg[0]  = 0; /*(_r)->areg[1] = 0;*/ \
16262306a36Sopenharmony_ci		(_r)->areg[2]  = 0; (_r)->areg[3]  = 0; \
16362306a36Sopenharmony_ci		(_r)->areg[4]  = 0; (_r)->areg[5]  = 0; \
16462306a36Sopenharmony_ci		(_r)->areg[6]  = 0; (_r)->areg[7]  = 0; \
16562306a36Sopenharmony_ci		(_r)->areg[8]  = 0; (_r)->areg[9]  = 0; \
16662306a36Sopenharmony_ci		(_r)->areg[10] = 0; (_r)->areg[11] = 0; \
16762306a36Sopenharmony_ci		(_r)->areg[12] = 0; (_r)->areg[13] = 0; \
16862306a36Sopenharmony_ci		(_r)->areg[14] = 0; (_r)->areg[15] = 0; \
16962306a36Sopenharmony_ci	} while (0)
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
17262306a36Sopenharmony_ci	do { \
17362306a36Sopenharmony_ci		(_r)->areg[4] = _exec_map_addr; \
17462306a36Sopenharmony_ci		(_r)->areg[5] = _interp_map_addr; \
17562306a36Sopenharmony_ci		(_r)->areg[6] = dynamic_addr; \
17662306a36Sopenharmony_ci	} while (0)
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_citypedef struct {
17962306a36Sopenharmony_ci	xtregs_opt_t	opt;
18062306a36Sopenharmony_ci	xtregs_user_t	user;
18162306a36Sopenharmony_ci#if XTENSA_HAVE_COPROCESSORS
18262306a36Sopenharmony_ci	xtregs_cp0_t	cp0;
18362306a36Sopenharmony_ci	xtregs_cp1_t	cp1;
18462306a36Sopenharmony_ci	xtregs_cp2_t	cp2;
18562306a36Sopenharmony_ci	xtregs_cp3_t	cp3;
18662306a36Sopenharmony_ci	xtregs_cp4_t	cp4;
18762306a36Sopenharmony_ci	xtregs_cp5_t	cp5;
18862306a36Sopenharmony_ci	xtregs_cp6_t	cp6;
18962306a36Sopenharmony_ci	xtregs_cp7_t	cp7;
19062306a36Sopenharmony_ci#endif
19162306a36Sopenharmony_ci} elf_xtregs_t;
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci#define SET_PERSONALITY(ex) \
19462306a36Sopenharmony_ci	set_personality(PER_LINUX_32BIT | (current->personality & (~PER_MASK)))
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#endif	/* _XTENSA_ELF_H */
197