1 // SPDX-License-Identifier: GPL-2.0
2 #include <string.h>
3 #include <linux/compiler.h>
4 #include <linux/zalloc.h>
5 #include "../disasm.h"
6
7 static
riscv64__associate_ins_ops(struct arch * arch,const char * name)8 const struct ins_ops *riscv64__associate_ins_ops(struct arch *arch, const char *name)
9 {
10 const struct ins_ops *ops = NULL;
11
12 if (!strncmp(name, "jal", 3) ||
13 !strncmp(name, "jr", 2) ||
14 !strncmp(name, "call", 4))
15 ops = &call_ops;
16 else if (!strncmp(name, "ret", 3))
17 ops = &ret_ops;
18 else if (name[0] == 'j' || name[0] == 'b')
19 ops = &jump_ops;
20 else
21 return NULL;
22
23 arch__associate_ins_ops(arch, name, ops);
24
25 return ops;
26 }
27
arch__new_riscv64(const struct e_machine_and_e_flags * id,const char * cpuid __maybe_unused)28 const struct arch *arch__new_riscv64(const struct e_machine_and_e_flags *id,
29 const char *cpuid __maybe_unused)
30 {
31 struct arch *arch = zalloc(sizeof(*arch));
32
33 if (!arch)
34 return NULL;
35
36 arch->name = "riscv";
37 arch->id = *id;
38 arch->objdump.comment_char = '#';
39 arch->associate_instruction_ops = riscv64__associate_ins_ops;
40 return arch;
41 }
42