1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <objtool/check.h>
6 #include <objtool/elf.h>
7 #include <objtool/arch.h>
8 #include <objtool/warn.h>
9 #include <objtool/builtin.h>
10 #include <objtool/endianness.h>
11
arch_ftrace_match(char * name)12 int arch_ftrace_match(char *name)
13 {
14 return !strcmp(name, "_mcount");
15 }
16
arch_dest_reloc_offset(int addend)17 unsigned long arch_dest_reloc_offset(int addend)
18 {
19 return addend;
20 }
21
arch_callee_saved_reg(unsigned char reg)22 bool arch_callee_saved_reg(unsigned char reg)
23 {
24 return false;
25 }
26
arch_decode_hint_reg(u8 sp_reg,int * base)27 int arch_decode_hint_reg(u8 sp_reg, int *base)
28 {
29 exit(-1);
30 }
31
arch_nop_insn(int len)32 const char *arch_nop_insn(int len)
33 {
34 exit(-1);
35 }
36
arch_ret_insn(int len)37 const char *arch_ret_insn(int len)
38 {
39 exit(-1);
40 }
41
arch_decode_instruction(struct objtool_file * file,const struct section * sec,unsigned long offset,unsigned int maxlen,struct instruction * insn)42 int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
43 unsigned long offset, unsigned int maxlen,
44 struct instruction *insn)
45 {
46 unsigned int opcode;
47 enum insn_type typ;
48 unsigned long imm;
49 u32 ins;
50
51 ins = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
52 opcode = ins >> 26;
53 typ = INSN_OTHER;
54 imm = 0;
55
56 switch (opcode) {
57 case 18: /* b[l][a] */
58 if ((ins & 3) == 1) /* bl */
59 typ = INSN_CALL;
60
61 imm = ins & 0x3fffffc;
62 if (imm & 0x2000000)
63 imm -= 0x4000000;
64 break;
65 }
66
67 if (opcode == 1)
68 insn->len = 8;
69 else
70 insn->len = 4;
71
72 insn->type = typ;
73 insn->immediate = imm;
74
75 return 0;
76 }
77
arch_jump_destination(struct instruction * insn)78 unsigned long arch_jump_destination(struct instruction *insn)
79 {
80 return insn->offset + insn->immediate;
81 }
82
arch_pc_relative_reloc(struct reloc * reloc)83 bool arch_pc_relative_reloc(struct reloc *reloc)
84 {
85 /*
86 * The powerpc build only allows certain relocation types, see
87 * relocs_check.sh, and none of those accepted are PC relative.
88 */
89 return false;
90 }
91
arch_initial_func_cfi_state(struct cfi_init_state * state)92 void arch_initial_func_cfi_state(struct cfi_init_state *state)
93 {
94 int i;
95
96 for (i = 0; i < CFI_NUM_REGS; i++) {
97 state->regs[i].base = CFI_UNDEFINED;
98 state->regs[i].offset = 0;
99 }
100
101 /* initial CFA (call frame address) */
102 state->cfa.base = CFI_SP;
103 state->cfa.offset = 0;
104
105 /* initial LR (return address) */
106 state->regs[CFI_RA].base = CFI_CFA;
107 state->regs[CFI_RA].offset = 0;
108 }
109