1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
3 #include <string.h>
4 #include <linux/compiler.h>
5 #include <linux/zalloc.h>
6 #include "../disasm.h"
7
csky__associate_ins_ops(struct arch * arch,const char * name)8 static const struct ins_ops *csky__associate_ins_ops(struct arch *arch,
9 const char *name)
10 {
11 const struct ins_ops *ops = NULL;
12
13 /* catch all kind of jumps */
14 if (!strcmp(name, "bt") ||
15 !strcmp(name, "bf") ||
16 !strcmp(name, "bez") ||
17 !strcmp(name, "bnez") ||
18 !strcmp(name, "bnezad") ||
19 !strcmp(name, "bhsz") ||
20 !strcmp(name, "bhz") ||
21 !strcmp(name, "blsz") ||
22 !strcmp(name, "blz") ||
23 !strcmp(name, "br") ||
24 !strcmp(name, "jmpi") ||
25 !strcmp(name, "jmp"))
26 ops = &jump_ops;
27
28 /* catch function call */
29 if (!strcmp(name, "bsr") ||
30 !strcmp(name, "jsri") ||
31 !strcmp(name, "jsr"))
32 ops = &call_ops;
33
34 /* catch function return */
35 if (!strcmp(name, "rts"))
36 ops = &ret_ops;
37
38 if (ops)
39 arch__associate_ins_ops(arch, name, ops);
40 return ops;
41 }
42
arch__new_csky(const struct e_machine_and_e_flags * id,const char * cpuid __maybe_unused)43 const struct arch *arch__new_csky(const struct e_machine_and_e_flags *id,
44 const char *cpuid __maybe_unused)
45 {
46 struct arch *arch = zalloc(sizeof(*arch));
47
48 if (!arch)
49 return NULL;
50
51 arch->name = "csky";
52 arch->id = *id;
53 arch->objdump.comment_char = '/';
54 arch->associate_instruction_ops = csky__associate_ins_ops;
55 return arch;
56 }
57