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
57static 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
77static const Ebl_Register_Location aarch64_fpregset_regs[] =
78  {
79    { .offset = 0, .regno = 64, .count = 32, .bits = 128 }, /* v0..v31 */
80  };
81
82static 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
94static 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#define AARCH64_HWBP_REG(KIND, N)					\
103    {									\
104      .name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', \
105      .offset = 8 + N * 16, .group = "register"				\
106    },									\
107    {									\
108      .name = "DBG" KIND "CR" #N "_EL1", .type = ELF_T_WORD, .format = 'x', \
109      .offset = 16 + N * 16, .group = "register"			\
110    }
111
112#define AARCH64_BP_WP_GROUP(KIND, NAME)					\
113  static const Ebl_Core_Item NAME[] =					\
114    {									\
115      {									\
116	.name = "dbg_info", .type = ELF_T_WORD, .format = 'x',		\
117	.offset = 0, .group = "control"					\
118      },								\
119      /* N.B.: 4 bytes of padding here.  */				\
120									\
121      AARCH64_HWBP_REG(KIND, 0),					\
122      AARCH64_HWBP_REG(KIND, 1),					\
123      AARCH64_HWBP_REG(KIND, 2),					\
124      AARCH64_HWBP_REG(KIND, 3),					\
125      AARCH64_HWBP_REG(KIND, 4),					\
126      AARCH64_HWBP_REG(KIND, 5),					\
127      AARCH64_HWBP_REG(KIND, 6),					\
128      AARCH64_HWBP_REG(KIND, 7),					\
129      AARCH64_HWBP_REG(KIND, 8),					\
130      AARCH64_HWBP_REG(KIND, 9),					\
131      AARCH64_HWBP_REG(KIND, 10),					\
132      AARCH64_HWBP_REG(KIND, 11),					\
133      AARCH64_HWBP_REG(KIND, 12),					\
134      AARCH64_HWBP_REG(KIND, 13),					\
135      AARCH64_HWBP_REG(KIND, 14),					\
136      AARCH64_HWBP_REG(KIND, 15),					\
137									\
138      /* The DBGBVR+DBGBCR pair only takes 12 bytes.  There are 4 bytes	\
139	 of padding at the end of each pair.  The item formatter in	\
140	 readelf can skip those, but the missing 4 bytes at the end of	\
141	 the whole block cause it to assume the whole item bunch	\
142	 repeats, so it loops around to read more.  Insert an explicit	\
143	 (but invisible) padding word.  */				\
144      {									\
145	.name = "", .type = ELF_T_WORD, .format = 'h',			\
146	.offset = 260, .group = "register"				\
147      }									\
148    }
149
150AARCH64_BP_WP_GROUP ("B", aarch64_hw_bp_items);
151AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
152
153#undef AARCH64_BP_WP_GROUP
154#undef AARCH64_HWBP_REG
155
156#define EXTRA_NOTES							\
157  EXTRA_REGSET_ITEMS (NT_FPREGSET, 528,					\
158		      aarch64_fpregset_regs, aarch64_fpregset_items)	\
159  EXTRA_ITEMS (NT_ARM_TLS, 8, aarch64_tls_items)			\
160  EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)		\
161  EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)
162
163#include "linux-core-note.c"
164