18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __GENELF_H__
38c2ecf20Sopenharmony_ci#define __GENELF_H__
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/* genelf.c */
68c2ecf20Sopenharmony_ciint jit_write_elf(int fd, uint64_t code_addr, const char *sym,
78c2ecf20Sopenharmony_ci		  const void *code, int csize, void *debug, int nr_debug_entries,
88c2ecf20Sopenharmony_ci		  void *unwinding, uint64_t unwinding_header_size, uint64_t unwinding_size);
98c2ecf20Sopenharmony_ci#ifdef HAVE_DWARF_SUPPORT
108c2ecf20Sopenharmony_ci/* genelf_debug.c */
118c2ecf20Sopenharmony_ciint jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries);
128c2ecf20Sopenharmony_ci#endif
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#if   defined(__arm__)
158c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_ARM
168c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS32
178c2ecf20Sopenharmony_ci#elif defined(__aarch64__)
188c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_AARCH64
198c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS64
208c2ecf20Sopenharmony_ci#elif defined(__x86_64__)
218c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_X86_64
228c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS64
238c2ecf20Sopenharmony_ci#elif defined(__i386__)
248c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_386
258c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS32
268c2ecf20Sopenharmony_ci#elif defined(__powerpc64__)
278c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_PPC64
288c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS64
298c2ecf20Sopenharmony_ci#elif defined(__powerpc__)
308c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_PPC
318c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS32
328c2ecf20Sopenharmony_ci#elif defined(__sparc__) && defined(__arch64__)
338c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_SPARCV9
348c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS64
358c2ecf20Sopenharmony_ci#elif defined(__sparc__)
368c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_SPARC
378c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS32
388c2ecf20Sopenharmony_ci#elif defined(__s390x__)
398c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_S390
408c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS64
418c2ecf20Sopenharmony_ci#elif defined(__loongarch__)
428c2ecf20Sopenharmony_ci#define GEN_ELF_ARCH	EM_LOONGARCH
438c2ecf20Sopenharmony_ci#define GEN_ELF_CLASS	ELFCLASS64
448c2ecf20Sopenharmony_ci#else
458c2ecf20Sopenharmony_ci#error "unsupported architecture"
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#if __BYTE_ORDER == __BIG_ENDIAN
498c2ecf20Sopenharmony_ci#define GEN_ELF_ENDIAN	ELFDATA2MSB
508c2ecf20Sopenharmony_ci#else
518c2ecf20Sopenharmony_ci#define GEN_ELF_ENDIAN	ELFDATA2LSB
528c2ecf20Sopenharmony_ci#endif
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#if GEN_ELF_CLASS == ELFCLASS64
558c2ecf20Sopenharmony_ci#define elf_newehdr	elf64_newehdr
568c2ecf20Sopenharmony_ci#define elf_newphdr	elf64_newphdr
578c2ecf20Sopenharmony_ci#define elf_getshdr	elf64_getshdr
588c2ecf20Sopenharmony_ci#define Elf_Ehdr	Elf64_Ehdr
598c2ecf20Sopenharmony_ci#define Elf_Phdr	Elf64_Phdr
608c2ecf20Sopenharmony_ci#define Elf_Shdr	Elf64_Shdr
618c2ecf20Sopenharmony_ci#define Elf_Sym		Elf64_Sym
628c2ecf20Sopenharmony_ci#define ELF_ST_TYPE(a)	ELF64_ST_TYPE(a)
638c2ecf20Sopenharmony_ci#define ELF_ST_BIND(a)	ELF64_ST_BIND(a)
648c2ecf20Sopenharmony_ci#define ELF_ST_VIS(a)	ELF64_ST_VISIBILITY(a)
658c2ecf20Sopenharmony_ci#else
668c2ecf20Sopenharmony_ci#define elf_newehdr	elf32_newehdr
678c2ecf20Sopenharmony_ci#define elf_newphdr	elf32_newphdr
688c2ecf20Sopenharmony_ci#define elf_getshdr	elf32_getshdr
698c2ecf20Sopenharmony_ci#define Elf_Ehdr	Elf32_Ehdr
708c2ecf20Sopenharmony_ci#define Elf_Phdr	Elf32_Phdr
718c2ecf20Sopenharmony_ci#define Elf_Shdr	Elf32_Shdr
728c2ecf20Sopenharmony_ci#define Elf_Sym		Elf32_Sym
738c2ecf20Sopenharmony_ci#define ELF_ST_TYPE(a)	ELF32_ST_TYPE(a)
748c2ecf20Sopenharmony_ci#define ELF_ST_BIND(a)	ELF32_ST_BIND(a)
758c2ecf20Sopenharmony_ci#define ELF_ST_VIS(a)	ELF32_ST_VISIBILITY(a)
768c2ecf20Sopenharmony_ci#endif
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* The .text section is directly after the ELF header */
798c2ecf20Sopenharmony_ci#define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr)
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#endif
82