• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* AArch64 specific core note handling.
2    Copyright (C) 2013 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 #define BACKEND aarch64_
40 #include "libebl_CPU.h"
41 
42 #define	ULONG			uint64_t
43 #define PID_T			int32_t
44 #define	UID_T			uint32_t
45 #define	GID_T			uint32_t
46 #define ALIGN_ULONG		8
47 #define ALIGN_PID_T		4
48 #define ALIGN_UID_T		4
49 #define ALIGN_GID_T		4
50 #define TYPE_ULONG		ELF_T_XWORD
51 #define TYPE_PID_T		ELF_T_SWORD
52 #define TYPE_UID_T		ELF_T_WORD
53 #define TYPE_GID_T		ELF_T_WORD
54 
55 #define PRSTATUS_REGS_SIZE	(34 * 8)
56 
57 static const Ebl_Register_Location prstatus_regs[] =
58   {
59     { .offset = 0, .regno = 0, .count = 32, .bits = 64 }, /* x0..x30, sp */
60   };
61 
62 #define PRSTATUS_REGSET_ITEMS						\
63   {									\
64     .name = "pc", .type = ELF_T_XWORD, .format = 'x',			\
65     .offset = (offsetof (struct EBLHOOK(prstatus), pr_reg)		\
66 	       + PRSTATUS_REGS_SIZE - 16),				\
67     .group = "register",						\
68     .pc_register = true							\
69   },									\
70   {									\
71     .name = "pstate", .type = ELF_T_XWORD, .format = 'x',		\
72     .offset = (offsetof (struct EBLHOOK(prstatus), pr_reg)		\
73 	       + PRSTATUS_REGS_SIZE - 8),				\
74     .group = "register"							\
75   }
76 
77 static const Ebl_Register_Location aarch64_fpregset_regs[] =
78   {
79     { .offset = 0, .regno = 64, .count = 32, .bits = 128 }, /* v0..v31 */
80   };
81 
82 static const Ebl_Core_Item aarch64_fpregset_items[] =
83   {
84     {
85       .name = "fpsr", .type = ELF_T_WORD, .format = 'x',
86       .offset = 512, .group = "register"
87     },
88     {
89       .name = "fpcr", .type = ELF_T_WORD, .format = 'x',
90       .offset = 516, .group = "register"
91     }
92   };
93 
94 static const Ebl_Core_Item aarch64_tls_items[] =
95   {
96     {
97       .name = "tls", .type = ELF_T_XWORD, .format = 'x',
98       .offset = 0, .group = "register"
99     }
100   };
101 
102 static const Ebl_Core_Item aarch64_syscall_items [] =
103   {
104     {
105       .name = "syscall", .type = ELF_T_WORD, .format = 'x',
106       .offset = 0, .group = "register"
107     }
108   };
109 
110 #define AARCH64_HWBP_REG(KIND, N)					\
111     {									\
112       .name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', \
113       .offset = 8 + N * 16, .group = "register"				\
114     },									\
115     {									\
116       .name = "DBG" KIND "CR" #N "_EL1", .type = ELF_T_WORD, .format = 'x', \
117       .offset = 16 + N * 16, .group = "register"			\
118     }
119 
120 #define AARCH64_BP_WP_GROUP(KIND, NAME)					\
121   static const Ebl_Core_Item NAME[] =					\
122     {									\
123       {									\
124 	.name = "dbg_info", .type = ELF_T_WORD, .format = 'x',		\
125 	.offset = 0, .group = "control"					\
126       },								\
127       /* N.B.: 4 bytes of padding here.  */				\
128 									\
129       AARCH64_HWBP_REG(KIND, 0),					\
130       AARCH64_HWBP_REG(KIND, 1),					\
131       AARCH64_HWBP_REG(KIND, 2),					\
132       AARCH64_HWBP_REG(KIND, 3),					\
133       AARCH64_HWBP_REG(KIND, 4),					\
134       AARCH64_HWBP_REG(KIND, 5),					\
135       AARCH64_HWBP_REG(KIND, 6),					\
136       AARCH64_HWBP_REG(KIND, 7),					\
137       AARCH64_HWBP_REG(KIND, 8),					\
138       AARCH64_HWBP_REG(KIND, 9),					\
139       AARCH64_HWBP_REG(KIND, 10),					\
140       AARCH64_HWBP_REG(KIND, 11),					\
141       AARCH64_HWBP_REG(KIND, 12),					\
142       AARCH64_HWBP_REG(KIND, 13),					\
143       AARCH64_HWBP_REG(KIND, 14),					\
144       AARCH64_HWBP_REG(KIND, 15),					\
145 									\
146       /* The DBGBVR+DBGBCR pair only takes 12 bytes.  There are 4 bytes	\
147 	 of padding at the end of each pair.  The item formatter in	\
148 	 readelf can skip those, but the missing 4 bytes at the end of	\
149 	 the whole block cause it to assume the whole item bunch	\
150 	 repeats, so it loops around to read more.  Insert an explicit	\
151 	 (but invisible) padding word.  */				\
152       {									\
153 	.name = "", .type = ELF_T_WORD, .format = 'h',			\
154 	.offset = 260, .group = "register"				\
155       }									\
156     }
157 
158 AARCH64_BP_WP_GROUP ("B", aarch64_hw_bp_items);
159 AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
160 
161 #undef AARCH64_BP_WP_GROUP
162 #undef AARCH64_HWBP_REG
163 
164 #define EXTRA_NOTES							\
165   EXTRA_REGSET_ITEMS (NT_FPREGSET, 528,					\
166 		      aarch64_fpregset_regs, aarch64_fpregset_items)	\
167   EXTRA_ITEMS (NT_ARM_TLS, 8, aarch64_tls_items)			\
168   EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)		\
169   EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)		\
170   EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items)
171 
172 #include "linux-core-note.c"
173