mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Currently functions like get_dwarf_regnum only work with the host architecture. Carry the elf machine and flags in struct arch so that in disassembly these can be used to allow cross platform disassembly. Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Anup Patel <anup@brainfault.org> Cc: Yang Jihong <yangjihong@bytedance.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: David S. Miller <davem@davemloft.net> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Shenlin Liang <liangshenlin@eswincomputing.com> Cc: Nick Terrell <terrelln@fb.com> Cc: Guilherme Amadio <amadio@gentoo.org> Cc: Steinar H. Gunderson <sesse@google.com> Cc: Changbin Du <changbin.du@huawei.com> Cc: Alexander Lobakin <aleksander.lobakin@intel.com> Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Guo Ren <guoren@kernel.org> Cc: Masahiro Yamada <masahiroy@kernel.org> Cc: Will Deacon <will@kernel.org> Cc: James Clark <james.clark@linaro.org> Cc: Mike Leach <mike.leach@linaro.org> Cc: Chen Pei <cp0613@linux.alibaba.com> Cc: Leo Yan <leo.yan@linux.dev> Cc: Oliver Upton <oliver.upton@linux.dev> Cc: Aditya Gupta <adityag@linux.ibm.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-riscv@lists.infradead.org Cc: Bibo Mao <maobibo@loongson.cn> Cc: John Garry <john.g.garry@oracle.com> Cc: Atish Patra <atishp@rivosinc.com> Cc: Dima Kogan <dima@secretsauce.net> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: Dr. David Alan Gilbert <linux@treblig.org> Cc: linux-csky@vger.kernel.org Link: https://lore.kernel.org/r/20241108234606.429459-5-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
139 lines
3.3 KiB
C
139 lines
3.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Perf annotate functions.
|
|
*
|
|
* Copyright (C) 2020-2023 Loongson Technology Corporation Limited
|
|
*/
|
|
|
|
static int loongarch_call__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms,
|
|
struct disasm_line *dl __maybe_unused)
|
|
{
|
|
char *c, *endptr, *tok, *name;
|
|
struct map *map = ms->map;
|
|
struct addr_map_symbol target = {
|
|
.ms = { .map = map, },
|
|
};
|
|
|
|
c = strchr(ops->raw, '#');
|
|
if (c++ == NULL)
|
|
return -1;
|
|
|
|
ops->target.addr = strtoull(c, &endptr, 16);
|
|
|
|
name = strchr(endptr, '<');
|
|
name++;
|
|
|
|
if (arch->objdump.skip_functions_char &&
|
|
strchr(name, arch->objdump.skip_functions_char))
|
|
return -1;
|
|
|
|
tok = strchr(name, '>');
|
|
if (tok == NULL)
|
|
return -1;
|
|
|
|
*tok = '\0';
|
|
ops->target.name = strdup(name);
|
|
*tok = '>';
|
|
|
|
if (ops->target.name == NULL)
|
|
return -1;
|
|
|
|
target.addr = map__objdump_2mem(map, ops->target.addr);
|
|
|
|
if (maps__find_ams(ms->maps, &target) == 0 &&
|
|
map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
|
|
ops->target.sym = target.ms.sym;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct ins_ops loongarch_call_ops = {
|
|
.parse = loongarch_call__parse,
|
|
.scnprintf = call__scnprintf,
|
|
};
|
|
|
|
static int loongarch_jump__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms,
|
|
struct disasm_line *dl __maybe_unused)
|
|
{
|
|
struct map *map = ms->map;
|
|
struct symbol *sym = ms->sym;
|
|
struct addr_map_symbol target = {
|
|
.ms = { .map = map, },
|
|
};
|
|
const char *c = strchr(ops->raw, '#');
|
|
u64 start, end;
|
|
|
|
ops->jump.raw_comment = strchr(ops->raw, arch->objdump.comment_char);
|
|
ops->jump.raw_func_start = strchr(ops->raw, '<');
|
|
|
|
if (ops->jump.raw_func_start && c > ops->jump.raw_func_start)
|
|
c = NULL;
|
|
|
|
if (c++ != NULL)
|
|
ops->target.addr = strtoull(c, NULL, 16);
|
|
else
|
|
ops->target.addr = strtoull(ops->raw, NULL, 16);
|
|
|
|
target.addr = map__objdump_2mem(map, ops->target.addr);
|
|
start = map__unmap_ip(map, sym->start);
|
|
end = map__unmap_ip(map, sym->end);
|
|
|
|
ops->target.outside = target.addr < start || target.addr > end;
|
|
|
|
if (maps__find_ams(ms->maps, &target) == 0 &&
|
|
map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
|
|
ops->target.sym = target.ms.sym;
|
|
|
|
if (!ops->target.outside) {
|
|
ops->target.offset = target.addr - start;
|
|
ops->target.offset_avail = true;
|
|
} else {
|
|
ops->target.offset_avail = false;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct ins_ops loongarch_jump_ops = {
|
|
.parse = loongarch_jump__parse,
|
|
.scnprintf = jump__scnprintf,
|
|
};
|
|
|
|
static
|
|
struct ins_ops *loongarch__associate_ins_ops(struct arch *arch, const char *name)
|
|
{
|
|
struct ins_ops *ops = NULL;
|
|
|
|
if (!strcmp(name, "bl"))
|
|
ops = &loongarch_call_ops;
|
|
else if (!strcmp(name, "jirl"))
|
|
ops = &ret_ops;
|
|
else if (!strcmp(name, "b") ||
|
|
!strncmp(name, "beq", 3) ||
|
|
!strncmp(name, "bne", 3) ||
|
|
!strncmp(name, "blt", 3) ||
|
|
!strncmp(name, "bge", 3) ||
|
|
!strncmp(name, "bltu", 4) ||
|
|
!strncmp(name, "bgeu", 4))
|
|
ops = &loongarch_jump_ops;
|
|
else
|
|
return NULL;
|
|
|
|
arch__associate_ins_ops(arch, name, ops);
|
|
|
|
return ops;
|
|
}
|
|
|
|
static
|
|
int loongarch__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
|
|
{
|
|
if (!arch->initialized) {
|
|
arch->associate_instruction_ops = loongarch__associate_ins_ops;
|
|
arch->initialized = true;
|
|
arch->objdump.comment_char = '#';
|
|
arch->e_machine = EM_LOONGARCH;
|
|
arch->e_flags = 0;
|
|
}
|
|
|
|
return 0;
|
|
}
|