/src/elfutils/backends/x86_64_regs.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Register names and numbers for x86-64 DWARF. |
2 | | Copyright (C) 2005, 2006, 2007 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 <assert.h> |
34 | | #include <dwarf.h> |
35 | | #include <string.h> |
36 | | |
37 | | #define BACKEND x86_64_ |
38 | | #include "libebl_CPU.h" |
39 | | |
40 | | ssize_t |
41 | | x86_64_register_info (Ebl *ebl __attribute__ ((unused)), |
42 | | int regno, char *name, size_t namelen, |
43 | | const char **prefix, const char **setname, |
44 | | int *bits, int *type) |
45 | 0 | { |
46 | 0 | if (name == NULL) |
47 | 0 | return 67; |
48 | | |
49 | 0 | if (regno < 0 || regno > 66 || namelen < 7) |
50 | 0 | return -1; |
51 | | |
52 | 0 | *prefix = "%"; |
53 | 0 | *bits = 64; |
54 | 0 | *type = DW_ATE_unsigned; |
55 | 0 | if (regno < 17) |
56 | 0 | { |
57 | 0 | *setname = "integer"; |
58 | 0 | *type = DW_ATE_signed; |
59 | 0 | } |
60 | 0 | else if (regno < 33) |
61 | 0 | { |
62 | 0 | *setname = "SSE"; |
63 | 0 | *bits = 128; |
64 | 0 | } |
65 | 0 | else if (regno < 41) |
66 | 0 | { |
67 | 0 | *setname = "x87"; |
68 | 0 | *type = DW_ATE_float; |
69 | 0 | *bits = 80; |
70 | 0 | } |
71 | 0 | else if (regno < 49) |
72 | 0 | *setname = "MMX"; |
73 | 0 | else if (regno > 49 && regno < 60) |
74 | 0 | { |
75 | 0 | *setname = "segment"; |
76 | 0 | *bits = 16; |
77 | 0 | } |
78 | 0 | else |
79 | 0 | *setname = "control"; |
80 | |
|
81 | 0 | switch (regno) |
82 | 0 | { |
83 | 0 | static const char baseregs[][2] = |
84 | 0 | { |
85 | 0 | {'a', 'x'}, |
86 | 0 | {'d', 'x'}, |
87 | 0 | {'c', 'x'}, |
88 | 0 | {'b', 'x'}, |
89 | 0 | {'s', 'i'}, |
90 | 0 | {'d', 'i'}, |
91 | 0 | {'b', 'p'}, |
92 | 0 | {'s', 'p'}, |
93 | 0 | }; |
94 | | |
95 | 0 | case 6 ... 7: |
96 | 0 | *type = DW_ATE_address; |
97 | 0 | FALLTHROUGH; |
98 | 0 | case 0 ... 5: |
99 | 0 | name[0] = 'r'; |
100 | 0 | name[1] = baseregs[regno][0]; |
101 | 0 | name[2] = baseregs[regno][1]; |
102 | 0 | namelen = 3; |
103 | 0 | break; |
104 | | |
105 | 0 | case 8 ... 9: |
106 | 0 | name[0] = 'r'; |
107 | 0 | name[1] = regno - 8 + '8'; |
108 | 0 | namelen = 2; |
109 | 0 | break; |
110 | | |
111 | 0 | case 10 ... 15: |
112 | 0 | name[0] = 'r'; |
113 | 0 | name[1] = '1'; |
114 | 0 | name[2] = regno - 10 + '0'; |
115 | 0 | namelen = 3; |
116 | 0 | break; |
117 | | |
118 | 0 | case 16: |
119 | 0 | *type = DW_ATE_address; |
120 | 0 | name[0] = 'r'; |
121 | 0 | name[1] = 'i'; |
122 | 0 | name[2] = 'p'; |
123 | 0 | namelen = 3; |
124 | 0 | break; |
125 | | |
126 | 0 | case 17 ... 26: |
127 | 0 | name[0] = 'x'; |
128 | 0 | name[1] = 'm'; |
129 | 0 | name[2] = 'm'; |
130 | 0 | name[3] = regno - 17 + '0'; |
131 | 0 | namelen = 4; |
132 | 0 | break; |
133 | | |
134 | 0 | case 27 ... 32: |
135 | 0 | name[0] = 'x'; |
136 | 0 | name[1] = 'm'; |
137 | 0 | name[2] = 'm'; |
138 | 0 | name[3] = '1'; |
139 | 0 | name[4] = regno - 27 + '0'; |
140 | 0 | namelen = 5; |
141 | 0 | break; |
142 | | |
143 | 0 | case 33 ... 40: |
144 | 0 | name[0] = 's'; |
145 | 0 | name[1] = 't'; |
146 | 0 | name[2] = regno - 33 + '0'; |
147 | 0 | namelen = 3; |
148 | 0 | break; |
149 | | |
150 | 0 | case 41 ... 48: |
151 | 0 | name[0] = 'm'; |
152 | 0 | name[1] = 'm'; |
153 | 0 | name[2] = regno - 41 + '0'; |
154 | 0 | namelen = 3; |
155 | 0 | break; |
156 | | |
157 | 0 | case 50 ... 55: |
158 | 0 | name[0] = "ecsdfg"[regno - 50]; |
159 | 0 | name[1] = 's'; |
160 | 0 | namelen = 2; |
161 | 0 | break; |
162 | | |
163 | 0 | case 58 ... 59: |
164 | 0 | *type = DW_ATE_address; |
165 | 0 | *bits = 64; |
166 | 0 | name[0] = regno - 58 + 'f'; |
167 | 0 | return stpcpy (&name[1], "s.base") + 1 - name; |
168 | | |
169 | 0 | case 49: |
170 | 0 | *setname = "integer"; |
171 | 0 | return stpcpy (name, "rflags") + 1 - name; |
172 | 0 | case 62: |
173 | 0 | return stpcpy (name, "tr") + 1 - name; |
174 | 0 | case 63: |
175 | 0 | return stpcpy (name, "ldtr") + 1 - name; |
176 | 0 | case 64: |
177 | 0 | return stpcpy (name, "mxcsr") + 1 - name; |
178 | | |
179 | 0 | case 65 ... 66: |
180 | 0 | *bits = 16; |
181 | 0 | name[0] = 'f'; |
182 | 0 | name[1] = "cs"[regno - 65]; |
183 | 0 | name[2] = 'w'; |
184 | 0 | namelen = 3; |
185 | 0 | break; |
186 | | |
187 | 0 | default: |
188 | 0 | return 0; |
189 | 0 | } |
190 | | |
191 | 0 | name[namelen++] = '\0'; |
192 | 0 | return namelen; |
193 | 0 | } |