This is the mail archive of the frysk@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PPC64 core-file GP register formats/order


Roland McGrath wrote:
I'm not sure what to do, but I cannot find the expectations of register order in a core file for PPC64. On other architectures the order is defined in:

struct user_regs_struct

Ha! Your optimism is quaint, dear fellow. That might be true on as many as three or four architectures. But that amount of consistency was only there to fool you into a false sense of security.

I guess gregset_t, which is defined in /usr/include/sys/ucontext.h as below, is the general answer.


 /* Type for general register.  */
typedef long int greg_t;

/* Number of general registers.  */
#define NGREG   23

/* Container for all general registers.  */
typedef greg_t gregset_t[NGREG];

On x86 and x86_64, an array to define the number of each register is followed:

#ifdef __USE_GNU
/* Number of each register in the `gregset_t' array.  */
enum
{
  REG_R8 = 0,
# define REG_R8         REG_R8
  REG_R9,
# define REG_R9         REG_R9
  REG_R10,
# define REG_R10        REG_R10
  REG_R11,
# define REG_R11        REG_R11
......

But on ppc64, there is no such an array in /usr/include/sys/ucontext.h.

eu-readelf only has a tiny bit of core note format printing support,
in fact only for i386 and x86_64.

I'm not really sure what to tell you as the general answer to find this
info.  I read the kernel source, but it's not so consistently written
across different architectures that you can necessarily answer the question
with the kernel source unless you are very familiar with reading it.

For all the architectures you probably care about, it so happens I've
already bothered to know, at least for one moment in the recent past.
The core file note formats are the basis for the machine-specific
"regset" format layouts in the utrace kernel interfaces.  I've had to
recapitulate those layouts when writing format compatibility code in
the userland test harness intended for developing modules based on
utrace (the "ntrace" tarball in http://redhat.com/~roland/utrace/).

For powerpc the elf_gregset_t format (sys/procfs.h) matches
this kernel data structure (asm-powerpc/ptrace.h):

struct pt_regs {
	unsigned long gpr[32];
	unsigned long nip;
	unsigned long msr;
	unsigned long orig_gpr3;	/* Used for restarting system calls */
	unsigned long ctr;
	unsigned long link;
	unsigned long xer;
	unsigned long ccr;
#ifdef __powerpc64__
	unsigned long softe;		/* Soft enabled/disabled */
#else
	unsigned long mq;		/* 601 only (not used at present) */
					/* Used on APUS to hold IPL value. */
#endif
	unsigned long trap;		/* Reason for being here */
	/* N.B. for critical exceptions on 4xx, the dar and dsisr
	   fields are overloaded to hold srr0 and srr1. */
	unsigned long dar;		/* Fault registers */
	unsigned long dsisr;		/* on 4xx/Book-E used for ESR */
	unsigned long result;		/* Result of a system call */
};


Same-named struct also exist in the system header file: /usr/include/asm-ppc64/ptrace.h, but there are two structures: one for 32-bit program, the other for 64-bit program:


#define PPC_REG unsigned long
struct pt_regs {
        PPC_REG gpr[32];
        PPC_REG nip;
        PPC_REG msr;
        PPC_REG orig_gpr3;      /* Used for restarting system calls */
        PPC_REG ctr;
        PPC_REG link;
        PPC_REG xer;
        PPC_REG ccr;
        PPC_REG softe;          /* Soft enabled/disabled */
        PPC_REG trap;           /* Reason for being here */
        PPC_REG dar;            /* Fault registers */
        PPC_REG dsisr;
        PPC_REG result;         /* Result of a system call */
};

#define PPC_REG_32 unsigned int
struct pt_regs32 {
        PPC_REG_32 gpr[32];
        PPC_REG_32 nip;
        PPC_REG_32 msr;
        PPC_REG_32 orig_gpr3;   /* Used for restarting system calls */
        PPC_REG_32 ctr;
        PPC_REG_32 link;
        PPC_REG_32 xer;
        PPC_REG_32 ccr;
        PPC_REG_32 mq;          /* 601 only (not used at present) */
                                /* Used on APUS to hold IPL value. */
        PPC_REG_32 trap;                /* Reason for being here */
        PPC_REG_32 dar;         /* Fault registers */
        PPC_REG_32 dsisr;
        PPC_REG_32 result;      /* Result of a system call */
};

It looks the same as the kernel strucuture.

Though, there is one problem confusing me all the time: why asm-powerpc replace asm-ppc64 in the kernel?

Regards
- Wu Zhou


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]