Search code examples
clinuxassemblypowerpc

Extract Program Counter (Instruction Pointer) in signal handler (ppc64)


In a signal handler under Linux, one has access to the saved context (all register values) of the suspended thread. These register values are obviously architecture dependent. For example, for a PowerPC Little Endian (ppcle) architecture, ucontext->uc_regs->gp_regs is an array that contains the values of the general purpose registers.

For certain architectures there are also defines (e.g., the REG_XXX defines for x86-64) which identify the purpose of the registers. For ppc64le such definitions are missing. How can I figure out which registers are which? The little IBM documentation available did not help...


Solution

  • I'm not aware of this being documented anywhere. However, setup_sigcontext for ppc64 fills in the gp_regs array from a struct pt_regs that forms part of the task state. Therefore, that struct can be taken as a guide for which registers are which. There is also a set of PT_Rxxx defines immediately below the definition of that struct, which confirms bits of the mapping that are not immediately obvious from the struct (e.g. general purpose register 1 is indeed in gp_regs[1]).