1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
9 #include <asm-generic/module.h>
11 #define RELA_STACK_DEPTH 16
19 struct mod_arch_specific {
20 struct mod_section got;
21 struct mod_section plt;
22 struct mod_section plt_idx;
24 /* For CONFIG_DYNAMIC_FTRACE */
25 struct plt_entry *ftrace_trampolines;
39 struct plt_idx_entry {
43 Elf_Addr module_emit_got_entry(struct module *mod, Elf_Shdr *sechdrs, Elf_Addr val);
44 Elf_Addr module_emit_plt_entry(struct module *mod, Elf_Shdr *sechdrs, Elf_Addr val);
46 static inline struct got_entry emit_got_entry(Elf_Addr val)
48 return (struct got_entry) { val };
51 static inline struct plt_entry emit_plt_entry(unsigned long val)
53 u32 lu12iw, lu32id, lu52id, jirl;
55 lu12iw = larch_insn_gen_lu12iw(LOONGARCH_GPR_T1, ADDR_IMM(val, LU12IW));
56 lu32id = larch_insn_gen_lu32id(LOONGARCH_GPR_T1, ADDR_IMM(val, LU32ID));
57 lu52id = larch_insn_gen_lu52id(LOONGARCH_GPR_T1, LOONGARCH_GPR_T1, ADDR_IMM(val, LU52ID));
58 jirl = larch_insn_gen_jirl(0, LOONGARCH_GPR_T1, ADDR_IMM(val, ORI));
60 return (struct plt_entry) { lu12iw, lu32id, lu52id, jirl };
63 static inline struct plt_idx_entry emit_plt_idx_entry(unsigned long val)
65 return (struct plt_idx_entry) { val };
68 static inline int get_plt_idx(unsigned long val, Elf_Shdr *sechdrs, const struct mod_section *sec)
71 struct plt_idx_entry *plt_idx = (struct plt_idx_entry *)sechdrs[sec->shndx].sh_addr;
73 for (i = 0; i < sec->num_entries; i++) {
74 if (plt_idx[i].symbol_addr == val)
81 static inline struct plt_entry *get_plt_entry(unsigned long val,
83 const struct mod_section *sec_plt,
84 const struct mod_section *sec_plt_idx)
86 int plt_idx = get_plt_idx(val, sechdrs, sec_plt_idx);
87 struct plt_entry *plt = (struct plt_entry *)sechdrs[sec_plt->shndx].sh_addr;
95 static inline struct got_entry *get_got_entry(Elf_Addr val,
97 const struct mod_section *sec)
100 struct got_entry *got = (struct got_entry *)sechdrs[sec->shndx].sh_addr;
102 for (i = 0; i < sec->num_entries; i++)
103 if (got[i].symbol_addr == val)
108 #endif /* _ASM_MODULE_H */