|
5 | 5 | * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +static int loongarch_call__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms) |
| 9 | +{ |
| 10 | + char *c, *endptr, *tok, *name; |
| 11 | + struct map *map = ms->map; |
| 12 | + struct addr_map_symbol target = { |
| 13 | + .ms = { .map = map, }, |
| 14 | + }; |
| 15 | + |
| 16 | + c = strchr(ops->raw, '#'); |
| 17 | + if (c++ == NULL) |
| 18 | + return -1; |
| 19 | + |
| 20 | + ops->target.addr = strtoull(c, &endptr, 16); |
| 21 | + |
| 22 | + name = strchr(endptr, '<'); |
| 23 | + name++; |
| 24 | + |
| 25 | + if (arch->objdump.skip_functions_char && |
| 26 | + strchr(name, arch->objdump.skip_functions_char)) |
| 27 | + return -1; |
| 28 | + |
| 29 | + tok = strchr(name, '>'); |
| 30 | + if (tok == NULL) |
| 31 | + return -1; |
| 32 | + |
| 33 | + *tok = '\0'; |
| 34 | + ops->target.name = strdup(name); |
| 35 | + *tok = '>'; |
| 36 | + |
| 37 | + if (ops->target.name == NULL) |
| 38 | + return -1; |
| 39 | + |
| 40 | + target.addr = map__objdump_2mem(map, ops->target.addr); |
| 41 | + |
| 42 | + if (maps__find_ams(ms->maps, &target) == 0 && |
| 43 | + map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr) |
| 44 | + ops->target.sym = target.ms.sym; |
| 45 | + |
| 46 | + return 0; |
| 47 | +} |
| 48 | + |
| 49 | +static struct ins_ops loongarch_call_ops = { |
| 50 | + .parse = loongarch_call__parse, |
| 51 | + .scnprintf = call__scnprintf, |
| 52 | +}; |
| 53 | + |
| 54 | +static int loongarch_jump__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms) |
| 55 | +{ |
| 56 | + struct map *map = ms->map; |
| 57 | + struct symbol *sym = ms->sym; |
| 58 | + struct addr_map_symbol target = { |
| 59 | + .ms = { .map = map, }, |
| 60 | + }; |
| 61 | + const char *c = strchr(ops->raw, '#'); |
| 62 | + u64 start, end; |
| 63 | + |
| 64 | + ops->raw_comment = strchr(ops->raw, arch->objdump.comment_char); |
| 65 | + ops->raw_func_start = strchr(ops->raw, '<'); |
| 66 | + |
| 67 | + if (ops->raw_func_start && c > ops->raw_func_start) |
| 68 | + c = NULL; |
| 69 | + |
| 70 | + if (c++ != NULL) |
| 71 | + ops->target.addr = strtoull(c, NULL, 16); |
| 72 | + else |
| 73 | + ops->target.addr = strtoull(ops->raw, NULL, 16); |
| 74 | + |
| 75 | + target.addr = map__objdump_2mem(map, ops->target.addr); |
| 76 | + start = map__unmap_ip(map, sym->start); |
| 77 | + end = map__unmap_ip(map, sym->end); |
| 78 | + |
| 79 | + ops->target.outside = target.addr < start || target.addr > end; |
| 80 | + |
| 81 | + if (maps__find_ams(ms->maps, &target) == 0 && |
| 82 | + map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr) |
| 83 | + ops->target.sym = target.ms.sym; |
| 84 | + |
| 85 | + if (!ops->target.outside) { |
| 86 | + ops->target.offset = target.addr - start; |
| 87 | + ops->target.offset_avail = true; |
| 88 | + } else { |
| 89 | + ops->target.offset_avail = false; |
| 90 | + } |
| 91 | + |
| 92 | + return 0; |
| 93 | +} |
| 94 | + |
| 95 | +static struct ins_ops loongarch_jump_ops = { |
| 96 | + .parse = loongarch_jump__parse, |
| 97 | + .scnprintf = jump__scnprintf, |
| 98 | +}; |
| 99 | + |
8 | 100 | static
|
9 | 101 | struct ins_ops *loongarch__associate_ins_ops(struct arch *arch, const char *name)
|
10 | 102 | {
|
11 | 103 | struct ins_ops *ops = NULL;
|
12 | 104 |
|
13 |
| - if (!strncmp(name, "beqz", 4) || |
14 |
| - !strncmp(name, "bnez", 4) || |
15 |
| - !strncmp(name, "beq", 3) || |
16 |
| - !strncmp(name, "bne", 3) || |
17 |
| - !strncmp(name, "blt", 3) || |
18 |
| - !strncmp(name, "bge", 3) || |
19 |
| - !strncmp(name, "bltu", 4) || |
20 |
| - !strncmp(name, "bgeu", 4) || |
21 |
| - !strncmp(name, "bl", 2)) |
22 |
| - ops = &call_ops; |
23 |
| - else if (!strncmp(name, "jirl", 4)) |
| 105 | + if (!strcmp(name, "bl")) |
| 106 | + ops = &loongarch_call_ops; |
| 107 | + else if (!strcmp(name, "jirl")) |
24 | 108 | ops = &ret_ops;
|
25 |
| - else if (name[0] == 'b') |
26 |
| - ops = &jump_ops; |
| 109 | + else if (!strcmp(name, "b") || |
| 110 | + !strncmp(name, "beq", 3) || |
| 111 | + !strncmp(name, "bne", 3) || |
| 112 | + !strncmp(name, "blt", 3) || |
| 113 | + !strncmp(name, "bge", 3) || |
| 114 | + !strncmp(name, "bltu", 4) || |
| 115 | + !strncmp(name, "bgeu", 4)) |
| 116 | + ops = &loongarch_jump_ops; |
27 | 117 | else
|
28 | 118 | return NULL;
|
29 | 119 |
|
|
0 commit comments