Ben Cheng | 25b3c04 | 2013-11-20 14:45:36 -0800 | [diff] [blame] | 1 | /* i386 specific core note handling. |
| 2 | Copyright (C) 2007-2010 Red Hat, Inc. |
| 3 | This file is part of Red Hat elfutils. |
| 4 | |
| 5 | Red Hat elfutils is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by the |
| 7 | Free Software Foundation; version 2 of the License. |
| 8 | |
| 9 | Red Hat elfutils is distributed in the hope that it will be useful, but |
| 10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along |
| 15 | with Red Hat elfutils; if not, write to the Free Software Foundation, |
| 16 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
| 17 | |
| 18 | Red Hat elfutils is an included package of the Open Invention Network. |
| 19 | An included package of the Open Invention Network is a package for which |
| 20 | Open Invention Network licensees cross-license their patents. No patent |
| 21 | license is granted, either expressly or impliedly, by designation as an |
| 22 | included package. Should you wish to participate in the Open Invention |
| 23 | Network licensing program, please visit www.openinventionnetwork.com |
| 24 | <http://www.openinventionnetwork.com>. */ |
| 25 | |
| 26 | #ifdef HAVE_CONFIG_H |
| 27 | # include <config.h> |
| 28 | #endif |
| 29 | |
| 30 | #include <elf.h> |
| 31 | #include <inttypes.h> |
| 32 | #include <stddef.h> |
| 33 | #include <stdio.h> |
| 34 | #include <sys/time.h> |
| 35 | |
| 36 | #define BACKEND i386_ |
| 37 | #include "libebl_CPU.h" |
| 38 | |
| 39 | |
| 40 | static const Ebl_Register_Location prstatus_regs[] = |
| 41 | { |
| 42 | #define GR(at, n, dwreg) \ |
| 43 | { .offset = at * 4, .regno = dwreg, .count = n, .bits = 32 } |
| 44 | #define SR(at, n, dwreg) \ |
| 45 | { .offset = at * 4, .regno = dwreg, .count = n, .bits = 16, .pad = 2 } |
| 46 | |
| 47 | GR (0, 1, 3), /* %ebx */ |
| 48 | GR (1, 2, 1), /* %ecx-%edx */ |
| 49 | GR (3, 2, 6), /* %esi-%edi */ |
| 50 | GR (5, 1, 5), /* %ebp */ |
| 51 | GR (6, 1, 0), /* %eax */ |
| 52 | SR (7, 1, 43), /* %ds */ |
| 53 | SR (8, 1, 40), /* %es */ |
| 54 | SR (9, 1, 44), /* %fs */ |
| 55 | SR (10, 1, 45), /* %gs */ |
| 56 | /* 11, 1, orig_eax */ |
| 57 | GR (12, 1, 8), /* %eip */ |
| 58 | SR (13, 1, 41), /* %cs */ |
| 59 | GR (14, 1, 9), /* eflags */ |
| 60 | GR (15, 1, 4), /* %esp */ |
| 61 | SR (16, 1, 42), /* %ss */ |
| 62 | |
| 63 | #undef GR |
| 64 | #undef SR |
| 65 | }; |
| 66 | #define PRSTATUS_REGS_SIZE (17 * 4) |
| 67 | |
| 68 | #define ULONG uint32_t |
| 69 | #define PID_T int32_t |
| 70 | #define UID_T uint16_t |
| 71 | #define GID_T uint16_t |
| 72 | #define ALIGN_ULONG 4 |
| 73 | #define ALIGN_PID_T 4 |
| 74 | #define ALIGN_UID_T 2 |
| 75 | #define ALIGN_GID_T 2 |
| 76 | #define TYPE_ULONG ELF_T_WORD |
| 77 | #define TYPE_PID_T ELF_T_SWORD |
| 78 | #define TYPE_UID_T ELF_T_HALF |
| 79 | #define TYPE_GID_T ELF_T_HALF |
| 80 | |
| 81 | #define PRSTATUS_REGSET_ITEMS \ |
| 82 | { \ |
| 83 | .name = "orig_eax", .type = ELF_T_SWORD, .format = 'd', \ |
| 84 | .offset = offsetof (struct EBLHOOK(prstatus), pr_reg) + (4 * 11), \ |
| 85 | .group = "register" \ |
| 86 | } |
| 87 | |
| 88 | static const Ebl_Register_Location fpregset_regs[] = |
| 89 | { |
| 90 | { .offset = 0, .regno = 37, .count = 2, .bits = 32 }, /* fctrl-fstat */ |
| 91 | { .offset = 7 * 4, .regno = 11, .count = 8, .bits = 80 }, /* stN */ |
| 92 | }; |
| 93 | #define FPREGSET_SIZE 108 |
| 94 | |
| 95 | static const Ebl_Register_Location prxfpreg_regs[] = |
| 96 | { |
| 97 | { .offset = 0, .regno = 37, .count = 2, .bits = 16 }, /* fctrl-fstat */ |
| 98 | { .offset = 24, .regno = 39, .count = 1, .bits = 32 }, /* mxcsr */ |
| 99 | { .offset = 32, .regno = 11, .count = 8, .bits = 80, .pad = 6 }, /* stN */ |
| 100 | { .offset = 32 + 128, .regno = 21, .count = 8, .bits = 128 }, /* xmm */ |
| 101 | }; |
| 102 | |
| 103 | #define EXTRA_NOTES \ |
| 104 | EXTRA_REGSET (NT_PRXFPREG, 512, prxfpreg_regs) \ |
| 105 | case NT_386_TLS: \ |
| 106 | return tls_info (nhdr->n_descsz, regs_offset, nregloc, reglocs, \ |
| 107 | nitems, items); \ |
| 108 | EXTRA_NOTES_IOPERM |
| 109 | |
| 110 | static const Ebl_Core_Item tls_items[] = |
| 111 | { |
| 112 | { .type = ELF_T_WORD, .offset = 0x0, .format = 'd', .name = "index" }, |
| 113 | { .type = ELF_T_WORD, .offset = 0x4, .format = 'x', .name = "base" }, |
| 114 | { .type = ELF_T_WORD, .offset = 0x8, .format = 'x', .name = "limit" }, |
| 115 | { .type = ELF_T_WORD, .offset = 0xc, .format = 'x', .name = "flags" }, |
| 116 | }; |
| 117 | |
| 118 | static int |
| 119 | tls_info (GElf_Word descsz, GElf_Word *regs_offset, |
| 120 | size_t *nregloc, const Ebl_Register_Location **reglocs, |
| 121 | size_t *nitems, const Ebl_Core_Item **items) |
| 122 | { |
| 123 | if (descsz % 16 != 0) |
| 124 | return 0; |
| 125 | |
| 126 | *regs_offset = 0; |
| 127 | *nregloc = 0; |
| 128 | *reglocs = NULL; |
| 129 | *nitems = sizeof tls_items / sizeof tls_items[0]; |
| 130 | *items = tls_items; |
| 131 | return 1; |
| 132 | } |
| 133 | |
| 134 | #include "x86_corenote.c" |
| 135 | #include "linux-core-note.c" |