• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* x86-64 specific core note handling.
2    Copyright (C) 2005, 2007, 2008 Red Hat, Inc.
3    Copyright (C) H.J. Lu <hjl.tools@gmail.com>, 2015.
4    This file is part of elfutils.
5 
6    This file is free software; you can redistribute it and/or modify
7    it under the terms of either
8 
9      * the GNU Lesser General Public License as published by the Free
10        Software Foundation; either version 3 of the License, or (at
11        your option) any later version
12 
13    or
14 
15      * the GNU General Public License as published by the Free
16        Software Foundation; either version 2 of the License, or (at
17        your option) any later version
18 
19    or both in parallel, as here.
20 
21    elfutils is distributed in the hope that it will be useful, but
22    WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24    General Public License for more details.
25 
26    You should have received copies of the GNU General Public License and
27    the GNU Lesser General Public License along with this program.  If
28    not, see <http://www.gnu.org/licenses/>.  */
29 
30 #ifdef HAVE_CONFIG_H
31 # include <config.h>
32 #endif
33 
34 #include <elf.h>
35 #include <inttypes.h>
36 #include <stddef.h>
37 #include <stdio.h>
38 #include <sys/time.h>
39 
40 #ifndef BITS
41 # define BITS 		64
42 # define BACKEND	x86_64_
43 #else
44 # define BITS 		32
45 # define BACKEND	x32_
46 #endif
47 #include "libebl_CPU.h"
48 
49 
50 static const Ebl_Register_Location prstatus_regs[] =
51   {
52 #define GR(at, n, dwreg)						\
53     { .offset = at * 8, .regno = dwreg, .count = n, .bits = 64 }
54 #define SR(at, n, dwreg)						\
55     { .offset = at * 8, .regno = dwreg, .count = n, .bits = 16, .pad = 6 }
56 
57     GR (0, 1, 15),		/* %r15 */
58     GR (1, 1, 14),		/* %r14 */
59     GR (2, 1, 13),		/* %r13 */
60     GR (3, 1, 12),		/* %r12 */
61     GR (4, 1, 6),		/* %rbp */
62     GR (5, 1, 3),		/* %rbx */
63     GR (6, 1, 11),		/* %r11 */
64     GR (7, 1, 10),		/* %r10 */
65     GR (8, 1, 9),		/* %r9 */
66     GR (9, 1, 8),		/* %r8 */
67     GR (10,1, 0),		/* %rax */
68     GR (11,1, 2),		/* %rcx */
69     GR (12,1, 1),		/* %rdx */
70     GR (13,2, 4),		/* %rsi-%rdi */
71     /*  15,1,			    orig_rax */
72     GR (16,1, 16),		/* %rip */
73     SR (17,1, 51),		/* %cs */
74     GR (18,1, 49),		/* %rFLAGS */
75     GR (19,1, 7),		/* %rsp */
76     SR (20,1, 52),		/* %ss */
77     GR (21,2, 58),		/* %fs.base-%gs.base */
78     SR (23,1, 53),		/* %ds */
79     SR (24,1, 50),		/* %es */
80     SR (25,2, 54),		/* %fs-%gs */
81 
82 #undef	GR
83 #undef	SR
84   };
85 #define PRSTATUS_REGS_SIZE	(27 * 8)
86 
87 #if BITS == 32
88 # define ULONG			uint32_t
89 # define ALIGN_ULONG		4
90 # define TYPE_ULONG		ELF_T_WORD
91 # define PRPSINFO_UID_T		uint16_t
92 # define ALIGN_PRPSINFO_UID_T	2
93 # define TYPE_PRPSINFO_UID_T	ELF_T_HALF
94 # define PRPSINFO_GID_T		uint16_t
95 # define ALIGN_PRPSINFO_GID_T	2
96 # define TYPE_PRPSINFO_GID_T	ELF_T_HALF
97 #else
98 # define ULONG			uint64_t
99 # define ALIGN_ULONG		8
100 # define TYPE_ULONG		ELF_T_XWORD
101 # define PRPSINFO_UID_T		uint32_t
102 # define ALIGN_PRPSINFO_UID_T	4
103 # define TYPE_PRPSINFO_UID_T	TYPE_UID_T
104 # define PRPSINFO_GID_T		uint32_t
105 # define ALIGN_PRPSINFO_GID_T	4
106 # define TYPE_PRPSINFO_GID_T	TYPE_GID_T
107 #endif
108 #define PR_REG			uint64_t
109 #define ALIGN_PR_REG		8
110 #define PID_T			int32_t
111 #define	UID_T			uint32_t
112 #define	GID_T			uint32_t
113 #define ALIGN_PID_T		4
114 #define ALIGN_UID_T		4
115 #define ALIGN_GID_T		4
116 #define TYPE_PID_T		ELF_T_SWORD
117 #define TYPE_UID_T		ELF_T_SWORD
118 #define TYPE_GID_T		ELF_T_SWORD
119 
120 #define PRSTATUS_REGSET_ITEMS						      \
121   {									      \
122     .name = "orig_rax", .type = ELF_T_SXWORD, .format = 'd',		      \
123     .offset = offsetof (struct EBLHOOK(prstatus), pr_reg) + (8 * 15),	      \
124     .group = "register"	       			  	       	 	      \
125   }
126 
127 static const Ebl_Register_Location fpregset_regs[] =
128   {
129     { .offset = 0, .regno = 65, .count = 2, .bits = 16 }, /* fcw-fsw */
130     { .offset = 24, .regno = 64, .count = 1, .bits = 32 }, /* mxcsr */
131     { .offset = 32, .regno = 33, .count = 8, .bits = 80, .pad = 6 }, /* stN */
132     { .offset = 32 + 128, .regno = 17, .count = 16, .bits = 128 }, /* xmm */
133   };
134 #define FPREGSET_SIZE	512
135 
136 #define	EXTRA_NOTES	EXTRA_NOTES_IOPERM
137 
138 #include "x86_corenote.c"
139 #include "linux-core-note.c"
140