xref: /linux/tools/perf/util/annotate-arch/annotate-mips.c (revision 07b972ff09f45cfb7acd20cd9b3769c6975bc434)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <string.h>
3 #include <linux/compiler.h>
4 #include "../disasm.h"
5 
6 static
7 const struct ins_ops *mips__associate_ins_ops(struct arch *arch, const char *name)
8 {
9 	const struct ins_ops *ops = NULL;
10 
11 	if (!strncmp(name, "bal", 3) ||
12 	    !strncmp(name, "bgezal", 6) ||
13 	    !strncmp(name, "bltzal", 6) ||
14 	    !strncmp(name, "bgtzal", 6) ||
15 	    !strncmp(name, "blezal", 6) ||
16 	    !strncmp(name, "beqzal", 6) ||
17 	    !strncmp(name, "bnezal", 6) ||
18 	    !strncmp(name, "bgtzl", 5) ||
19 	    !strncmp(name, "bltzl", 5) ||
20 	    !strncmp(name, "bgezl", 5) ||
21 	    !strncmp(name, "blezl", 5) ||
22 	    !strncmp(name, "jialc", 5) ||
23 	    !strncmp(name, "beql", 4) ||
24 	    !strncmp(name, "bnel", 4) ||
25 	    !strncmp(name, "jal", 3))
26 		ops = &call_ops;
27 	else if (!strncmp(name, "jr", 2))
28 		ops = &ret_ops;
29 	else if (name[0] == 'j' || name[0] == 'b')
30 		ops = &jump_ops;
31 	else
32 		return NULL;
33 
34 	arch__associate_ins_ops(arch, name, ops);
35 
36 	return ops;
37 }
38 
39 int mips__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
40 {
41 	if (!arch->initialized) {
42 		arch->associate_instruction_ops = mips__associate_ins_ops;
43 		arch->initialized = true;
44 		arch->objdump.comment_char = '#';
45 	}
46 
47 	return 0;
48 }
49