707a395435d8d4df9e04712140592dc62ba3372f
[platform/upstream/elfutils.git] / backends / ppc_corenote.c
1 /* PowerPC specific core note handling.
2    Copyright (C) 2007, 2008 Red Hat, Inc.
3    This file is part of elfutils.
4
5    This file is free software; you can redistribute it and/or modify
6    it under the terms of either
7
8      * the GNU Lesser General Public License as published by the Free
9        Software Foundation; either version 3 of the License, or (at
10        your option) any later version
11
12    or
13
14      * the GNU General Public License as published by the Free
15        Software Foundation; either version 2 of the License, or (at
16        your option) any later version
17
18    or both in parallel, as here.
19
20    elfutils is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23    General Public License for more details.
24
25    You should have received copies of the GNU General Public License and
26    the GNU Lesser General Public License along with this program.  If
27    not, see <http://www.gnu.org/licenses/>.  */
28
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32
33 #include <elf.h>
34 #include <inttypes.h>
35 #include <stddef.h>
36 #include <stdio.h>
37 #include <sys/time.h>
38
39 #ifndef BITS
40 # define BITS           32
41 # define BACKEND        ppc_
42 #else
43 # define BITS           64
44 # define BACKEND        ppc64_
45 #endif
46 #include "libebl_CPU.h"
47
48 static const Ebl_Register_Location prstatus_regs[] =
49   {
50 #define GR(at, n, dwreg)                                                \
51     { .offset = at * BITS/8, .regno = dwreg, .count = n, .bits = BITS }
52
53     GR (0, 32, 0),              /* r0-r31 */
54     /*  32, 1,                     nip */
55     GR (33, 1, 66),             /* msr */
56     /*  34, 1,                     orig_gpr3 */
57     GR (35, 1, 109),            /* ctr */
58     GR (36, 1, 108),            /* lr */
59     GR (37, 1, 101),            /* xer */
60     GR (38, 1, 64),             /* cr */
61     GR (39, 1, 100),            /* mq */
62     /*  40, 1,                     trap */
63     GR (41, 1, 119),            /* dar */
64     GR (42, 1, 118),            /* dsisr */
65
66 #undef  GR
67   };
68 #define PRSTATUS_REGS_SIZE      (BITS / 8 * 48)
69
70 static const Ebl_Register_Location fpregset_regs[] =
71   {
72     { .offset = 0, .regno = 32, .count = 32, .bits = 64 }, /* f0-f31 */
73     { .offset = 32 * 8 + 4, .regno = 65, .count = 1, .bits = 32 } /* fpscr */
74   };
75 #define FPREGSET_SIZE           (33 * 8)
76
77 static const Ebl_Register_Location altivec_regs[] =
78   {
79     /* vr0-vr31 */
80     { .offset = 0, .regno = 1124, .count = 32, .bits = 128 },
81     /* vscr XXX 67 is an unofficial assignment */
82     { .offset = 32 * 16, .regno = 67, .count = 1, .bits = 32, .pad = 12 },
83     /* vrsave */
84     { .offset = 33 * 16, .regno = 356, .count = 1, .bits = 32, .pad = 12 }
85   };
86
87 static const Ebl_Register_Location spe_regs[] =
88   {
89     /* evr0-evr31
90     { .offset = 0, .regno = ???, .count = 32, .bits = 32 },
91      * acc *
92     { .offset = 32 * 4, .regno = ???, .count = 1, .bits = 64 }, */
93     /* spefscr */
94     { .offset = 34 * 4, .regno = 612, .count = 1, .bits = 32 }
95   };
96
97 #define EXTRA_NOTES \
98   EXTRA_REGSET (NT_PPC_VMX, 34 * 16, altivec_regs) \
99   EXTRA_REGSET (NT_PPC_SPE, 35 * 4, spe_regs)
100
101 #if BITS == 32
102 # define ULONG                  uint32_t
103 # define ALIGN_ULONG            4
104 # define TYPE_ULONG             ELF_T_WORD
105 # define TYPE_LONG              ELF_T_SWORD
106 #else
107 # define ULONG                  uint64_t
108 # define ALIGN_ULONG            8
109 # define TYPE_ULONG             ELF_T_XWORD
110 # define TYPE_LONG              ELF_T_SXWORD
111 #endif
112 #define PID_T                   int32_t
113 #define UID_T                   uint32_t
114 #define GID_T                   uint32_t
115 #define ALIGN_PID_T             4
116 #define ALIGN_UID_T             4
117 #define ALIGN_GID_T             4
118 #define TYPE_PID_T              ELF_T_SWORD
119 #define TYPE_UID_T              ELF_T_WORD
120 #define TYPE_GID_T              ELF_T_WORD
121
122 #define PRSTATUS_REGSET_ITEMS                                                 \
123   {                                                                           \
124     .name = "nip", .type = ELF_T_ADDR, .format = 'x',                         \
125     .offset = offsetof (struct EBLHOOK(prstatus), pr_reg[32]),                \
126     .group = "register"                                                       \
127   },                                                                          \
128   {                                                                           \
129     .name = "orig_gpr3", .type = TYPE_LONG, .format = 'd',                    \
130     .offset = offsetof (struct EBLHOOK(prstatus), pr_reg[34]),                \
131     .group = "register"                                                       \
132   }
133
134 #include "linux-core-note.c"