2022-06-11 16:32:24 +01:00
|
|
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
2022-11-02 00:05:16 +00:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2022-06-11 16:32:24 +01:00
|
|
|
|
|
|
|
REGISTERS = [
|
|
|
|
*[DrgnRegister(f"r{i}") for i in range(32)],
|
libdrgn: ppc64: fix DWARF link register confusion
The usage of the link register in DWARF is a little confusing. On entry
to a function, the link register contains the address that should be
returned to. However, for DWARF, the link register is usually used as
the CFI return_address_register, which means that in an unwound frame,
it will contain the same thing as the program counter. I initially
thought that this was a mistake, believing that the link register should
contain the _next_ return address. However, after a return (with the blr
instruction), the link register will indeed contain the same address as
the program counter. This is consistent with our documentation of
register values for function call frames: "the register values are the
values when control returns to this frame".
So, rename our internal "ra" register to "lr", expose it to the API, and
add a little more documentation to the ppc64 initial register code.
Fixes: 221a21870459 ("libdrgn: add powerpc stack trace support")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-06-22 02:39:29 +01:00
|
|
|
DrgnRegister("lr"),
|
2022-06-11 16:32:24 +01:00
|
|
|
*[DrgnRegister(f"cr{i}") for i in range(8)],
|
|
|
|
]
|
|
|
|
|
|
|
|
# There are two conflicting definitions of DWARF register numbers after 63. The
|
|
|
|
# original definition appears to be "64-bit PowerPC ELF Application Binary
|
|
|
|
# Interface Supplement" [1]. The GNU toolchain instead uses its own that was
|
|
|
|
# later codified in "Power Architecture 64-Bit ELF V2 ABI Specification" [2].
|
|
|
|
# We use the latter.
|
|
|
|
#
|
|
|
|
# 1: https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html
|
|
|
|
# 2: https://openpowerfoundation.org/specifications/64bitelfabi/
|
|
|
|
REGISTER_LAYOUT = [
|
libdrgn: ppc64: fix DWARF link register confusion
The usage of the link register in DWARF is a little confusing. On entry
to a function, the link register contains the address that should be
returned to. However, for DWARF, the link register is usually used as
the CFI return_address_register, which means that in an unwound frame,
it will contain the same thing as the program counter. I initially
thought that this was a mistake, believing that the link register should
contain the _next_ return address. However, after a return (with the blr
instruction), the link register will indeed contain the same address as
the program counter. This is consistent with our documentation of
register values for function call frames: "the register values are the
values when control returns to this frame".
So, rename our internal "ra" register to "lr", expose it to the API, and
add a little more documentation to the ppc64 initial register code.
Fixes: 221a21870459 ("libdrgn: add powerpc stack trace support")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-06-22 02:39:29 +01:00
|
|
|
DrgnRegisterLayout("lr", size=8, dwarf_number=65),
|
2022-06-11 16:32:24 +01:00
|
|
|
*[DrgnRegisterLayout(f"r{i}", size=8, dwarf_number=i) for i in range(32)],
|
|
|
|
*[DrgnRegisterLayout(f"cr{i}", size=8, dwarf_number=68 + i) for i in range(8)],
|
|
|
|
]
|
2022-11-23 00:51:44 +00:00
|
|
|
|
|
|
|
STACK_POINTER_REGISTER = "r1"
|