162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef _ASM_NIOS2_ELF_H
762306a36Sopenharmony_ci#define _ASM_NIOS2_ELF_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <uapi/asm/elf.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/*
1262306a36Sopenharmony_ci * This is used to ensure we don't load something for the wrong architecture.
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_ci#define elf_check_arch(x) ((x)->e_machine == EM_ALTERA_NIOS2)
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define ELF_PLAT_INIT(_r, load_addr)
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#define CORE_DUMP_USE_REGSET
1962306a36Sopenharmony_ci#define ELF_EXEC_PAGESIZE	4096
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
2262306a36Sopenharmony_ci   use of this is to invoke "./ld.so someprog" to test out a new version of
2362306a36Sopenharmony_ci   the loader.  We need to make sure that it is out of the way of the program
2462306a36Sopenharmony_ci   that it will "exec", and that there is sufficient room for the brk.  */
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define ELF_ET_DYN_BASE		0xD0000000UL
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
2962306a36Sopenharmony_ci   now struct_user_regs, they are different) */
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define ARCH_HAS_SETUP_ADDITIONAL_PAGES	1
3262306a36Sopenharmony_cistruct linux_binprm;
3362306a36Sopenharmony_ciextern int arch_setup_additional_pages(struct linux_binprm *bprm,
3462306a36Sopenharmony_ci	int uses_interp);
3562306a36Sopenharmony_ci#define ELF_CORE_COPY_REGS(pr_reg, regs)				\
3662306a36Sopenharmony_ci{ do {									\
3762306a36Sopenharmony_ci	/* Bleech. */							\
3862306a36Sopenharmony_ci	pr_reg[0]  = regs->r8;						\
3962306a36Sopenharmony_ci	pr_reg[1]  = regs->r9;						\
4062306a36Sopenharmony_ci	pr_reg[2]  = regs->r10;						\
4162306a36Sopenharmony_ci	pr_reg[3]  = regs->r11;						\
4262306a36Sopenharmony_ci	pr_reg[4]  = regs->r12;						\
4362306a36Sopenharmony_ci	pr_reg[5]  = regs->r13;						\
4462306a36Sopenharmony_ci	pr_reg[6]  = regs->r14;						\
4562306a36Sopenharmony_ci	pr_reg[7]  = regs->r15;						\
4662306a36Sopenharmony_ci	pr_reg[8]  = regs->r1;						\
4762306a36Sopenharmony_ci	pr_reg[9]  = regs->r2;						\
4862306a36Sopenharmony_ci	pr_reg[10] = regs->r3;						\
4962306a36Sopenharmony_ci	pr_reg[11] = regs->r4;						\
5062306a36Sopenharmony_ci	pr_reg[12] = regs->r5;						\
5162306a36Sopenharmony_ci	pr_reg[13] = regs->r6;						\
5262306a36Sopenharmony_ci	pr_reg[14] = regs->r7;						\
5362306a36Sopenharmony_ci	pr_reg[15] = regs->orig_r2;					\
5462306a36Sopenharmony_ci	pr_reg[16] = regs->ra;						\
5562306a36Sopenharmony_ci	pr_reg[17] = regs->fp;						\
5662306a36Sopenharmony_ci	pr_reg[18] = regs->sp;						\
5762306a36Sopenharmony_ci	pr_reg[19] = regs->gp;						\
5862306a36Sopenharmony_ci	pr_reg[20] = regs->estatus;					\
5962306a36Sopenharmony_ci	pr_reg[21] = regs->ea;						\
6062306a36Sopenharmony_ci	pr_reg[22] = regs->orig_r7;					\
6162306a36Sopenharmony_ci	{								\
6262306a36Sopenharmony_ci		struct switch_stack *sw = ((struct switch_stack *)regs) - 1; \
6362306a36Sopenharmony_ci		pr_reg[23] = sw->r16;					\
6462306a36Sopenharmony_ci		pr_reg[24] = sw->r17;					\
6562306a36Sopenharmony_ci		pr_reg[25] = sw->r18;					\
6662306a36Sopenharmony_ci		pr_reg[26] = sw->r19;					\
6762306a36Sopenharmony_ci		pr_reg[27] = sw->r20;					\
6862306a36Sopenharmony_ci		pr_reg[28] = sw->r21;					\
6962306a36Sopenharmony_ci		pr_reg[29] = sw->r22;					\
7062306a36Sopenharmony_ci		pr_reg[30] = sw->r23;					\
7162306a36Sopenharmony_ci		pr_reg[31] = sw->fp;					\
7262306a36Sopenharmony_ci		pr_reg[32] = sw->gp;					\
7362306a36Sopenharmony_ci		pr_reg[33] = sw->ra;					\
7462306a36Sopenharmony_ci	}								\
7562306a36Sopenharmony_ci} while (0); }
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/* This yields a mask that user programs can use to figure out what
7862306a36Sopenharmony_ci   instruction set this cpu supports.  */
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define ELF_HWCAP	(0)
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci/* This yields a string that ld.so will use to load implementation
8362306a36Sopenharmony_ci   specific libraries for optimization.  This is more specific in
8462306a36Sopenharmony_ci   intent than poking at uname or /proc/cpuinfo.  */
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#define ELF_PLATFORM  (NULL)
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#endif /* _ASM_NIOS2_ELF_H */
89