OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #ifndef CRASHPAD_SNAPSHOT_SNAPSHOT_CPU_CONTEXT_H_ | 15 #ifndef CRASHPAD_SNAPSHOT_SNAPSHOT_CPU_CONTEXT_H_ |
16 #define CRASHPAD_SNAPSHOT_SNAPSHOT_CPU_CONTEXT_H_ | 16 #define CRASHPAD_SNAPSHOT_SNAPSHOT_CPU_CONTEXT_H_ |
17 | 17 |
18 #include <stdint.h> | 18 #include <stdint.h> |
19 | 19 |
20 #include "snapshot/cpu_architecture.h" | 20 #include "snapshot/cpu_architecture.h" |
21 | 21 |
22 namespace crashpad { | 22 namespace crashpad { |
23 | 23 |
24 //! \brief A context structure carrying 32-bit x86 CPU state. | 24 //! \brief A context structure carrying 32-bit x86 CPU state. |
25 struct CPUContextX86 { | 25 struct CPUContextX86 { |
26 using X87Register = uint8_t[10]; | 26 using X87Register = uint8_t[10]; |
27 | 27 |
| 28 struct Fsave { |
| 29 uint16_t fcw; // FPU control word |
| 30 uint16_t reserved_1; |
| 31 uint16_t fsw; // FPU status word |
| 32 uint16_t reserved_2; |
| 33 uint16_t ftw; // full FPU tag word |
| 34 uint16_t reserved_3; |
| 35 uint32_t fpu_ip; // FPU instruction pointer offset |
| 36 uint16_t fpu_cs; // FPU instruction pointer segment selector |
| 37 uint16_t fop; // FPU opcode |
| 38 uint32_t fpu_dp; // FPU data pointer offset |
| 39 uint16_t fpu_ds; // FPU data pointer segment selector |
| 40 uint16_t reserved_4; |
| 41 X87Register st[8]; |
| 42 }; |
| 43 |
28 union X87OrMMXRegister { | 44 union X87OrMMXRegister { |
29 struct { | 45 struct { |
30 X87Register st; | 46 X87Register st; |
31 uint8_t st_reserved[6]; | 47 uint8_t st_reserved[6]; |
32 }; | 48 }; |
33 struct { | 49 struct { |
34 uint8_t mm_value[8]; | 50 uint8_t mm_value[8]; |
35 uint8_t mm_reserved[8]; | 51 uint8_t mm_reserved[8]; |
36 }; | 52 }; |
37 }; | 53 }; |
(...skipping 13 matching lines...) Expand all Loading... |
51 uint16_t fpu_ds; // FPU data pointer segment selector | 67 uint16_t fpu_ds; // FPU data pointer segment selector |
52 uint16_t reserved_3; | 68 uint16_t reserved_3; |
53 uint32_t mxcsr; // multimedia extensions status and control register | 69 uint32_t mxcsr; // multimedia extensions status and control register |
54 uint32_t mxcsr_mask; // valid bits in mxcsr | 70 uint32_t mxcsr_mask; // valid bits in mxcsr |
55 X87OrMMXRegister st_mm[8]; | 71 X87OrMMXRegister st_mm[8]; |
56 XMMRegister xmm[8]; | 72 XMMRegister xmm[8]; |
57 uint8_t reserved_4[176]; | 73 uint8_t reserved_4[176]; |
58 uint8_t available[48]; | 74 uint8_t available[48]; |
59 }; | 75 }; |
60 | 76 |
| 77 //! \brief Converts an `fxsave` area to an `fsave` area. |
| 78 //! |
| 79 //! `fsave` state is restricted to the x87 FPU, while `fxsave` state includes |
| 80 //! state related to the x87 FPU as well as state specific to SSE. |
| 81 //! |
| 82 //! As the `fxsave` format is a superset of the `fsave` format, this operation |
| 83 //! fully populates the `fsave` area. `fsave` uses the full 16-bit form for |
| 84 //! the x87 floating-point tag word, so FxsaveToFsaveTagWord() is used to |
| 85 //! derive Fsave::ftw from the abridged 8-bit form used by `fxsave`. Reserved |
| 86 //! fields in \a fsave are set to `0`. |
| 87 //! |
| 88 //! \param[in] fxsave The `fxsave` area to convert. |
| 89 //! \param[out] fsave The `fsave` area to populate. |
| 90 //! |
| 91 //! \sa FsaveToFxsave() |
| 92 static void FxsaveToFsave(const Fxsave& fxsave, Fsave* fsave); |
| 93 |
| 94 //! \brief Converts an `fsave` area to an `fxsave` area. |
| 95 //! |
| 96 //! `fsave` state is restricted to the x87 FPU, while `fxsave` state includes |
| 97 //! state related to the x87 FPU as well as state specific to SSE. |
| 98 //! |
| 99 //! As the `fsave` format is a subset of the `fxsave` format, this operation |
| 100 //! cannot fully populate the `fxsave` area. Fields in \a fxsave that have no |
| 101 //! equivalent in \a fsave are set to `0`, including Fxsave::mxcsr, |
| 102 //! Fxsave::mxcsr_mask, Fxsave::xmm, and Fxsave::available. |
| 103 //! FsaveToFxsaveTagWord() is used to derive Fxsave::ftw from the full 16-bit |
| 104 //! form used by `fsave`. Reserved fields in \a fxsave are set to `0`. |
| 105 //! |
| 106 //! \param[in] fsave The `fsave` area to convert. |
| 107 //! \param[out] fxsave The `fxsave` area to populate. |
| 108 //! |
| 109 //! \sa FxsaveToFsave() |
| 110 static void FsaveToFxsave(const Fsave& fsave, Fxsave* fxsave); |
| 111 |
61 //! \brief Converts x87 floating-point tag words from `fxsave` (abridged, | 112 //! \brief Converts x87 floating-point tag words from `fxsave` (abridged, |
62 //! 8-bit) to `fsave` (full, 16-bit) form. | 113 //! 8-bit) to `fsave` (full, 16-bit) form. |
63 //! | 114 //! |
64 //! `fxsave` stores the x87 floating-point tag word in abridged 8-bit form, | 115 //! `fxsave` stores the x87 floating-point tag word in abridged 8-bit form, |
65 //! and `fsave` stores it in full 16-bit form. Some users, notably | 116 //! and `fsave` stores it in full 16-bit form. Some users, notably |
66 //! MinidumpContextX86::float_save::tag_word, require the full 16-bit form, | 117 //! CPUContextX86::Fsave::ftw, require the full 16-bit form, where most other |
67 //! where most other contemporary code uses `fxsave` and thus the abridged | 118 //! contemporary code uses `fxsave` and thus the abridged 8-bit form found in |
68 //! 8-bit form found in CPUContextX86::Fxsave::ftw. | 119 //! CPUContextX86::Fxsave::ftw. |
69 //! | 120 //! |
70 //! This function converts an abridged tag word to the full version by using | 121 //! This function converts an abridged tag word to the full version by using |
71 //! the abridged tag word and the contents of the registers it describes. See | 122 //! the abridged tag word and the contents of the registers it describes. See |
72 //! Intel Software Developer’s Manual, Volume 2A: Instruction Set Reference | 123 //! Intel Software Developer’s Manual, Volume 2A: Instruction Set Reference |
73 //! A-M (253666-052), 3.2 “FXSAVE”, specifically, the notes on the abridged | 124 //! A-M (253666-052), 3.2 “FXSAVE”, specifically, the notes on the abridged |
74 //! FTW and recreating the FSAVE format, and AMD Architecture Programmer’s | 125 //! FTW and recreating the FSAVE format, and AMD Architecture Programmer’s |
75 //! Manual, Volume 2: System Programming (24593-3.24), “FXSAVE Format for x87 | 126 //! Manual, Volume 2: System Programming (24593-3.24), “FXSAVE Format for x87 |
76 //! Tag Word”. | 127 //! Tag Word”. |
77 //! | 128 //! |
| 129 //! \sa FsaveToFxsaveTagWord() |
| 130 //! |
78 //! \param[in] fsw The FPU status word, used to map logical \a st_mm registers | 131 //! \param[in] fsw The FPU status word, used to map logical \a st_mm registers |
79 //! to their physical counterparts. This can be taken from | 132 //! to their physical counterparts. This can be taken from |
80 //! CPUContextX86::Fxsave::fsw. | 133 //! CPUContextX86::Fxsave::fsw. |
81 //! \param[in] fxsave_tag The abridged FPU tag word. This can be taken from | 134 //! \param[in] fxsave_tag The abridged FPU tag word. This can be taken from |
82 //! CPUContextX86::Fxsave::ftw. | 135 //! CPUContextX86::Fxsave::ftw. |
83 //! \param[in] st_mm The floating-point registers in logical order. This can | 136 //! \param[in] st_mm The floating-point registers in logical order. This can |
84 //! be taken from CPUContextX86::Fxsave::st_mm. | 137 //! be taken from CPUContextX86::Fxsave::st_mm. |
85 //! | 138 //! |
86 //! \return The full FPU tag word. | 139 //! \return The full FPU tag word. |
87 static uint16_t FxsaveToFsaveTagWord( | 140 static uint16_t FxsaveToFsaveTagWord( |
88 uint16_t fsw, uint8_t fxsave_tag, const X87OrMMXRegister st_mm[8]); | 141 uint16_t fsw, uint8_t fxsave_tag, const X87OrMMXRegister st_mm[8]); |
89 | 142 |
| 143 //! \brief Converts x87 floating-point tag words from `fsave` (full, 16-bit) |
| 144 //! to `fxsave` (abridged, 8-bit) form. |
| 145 //! |
| 146 //! This function performs the inverse operation of FxsaveToFsaveTagWord(). |
| 147 //! |
| 148 //! \param[in] fsave_tag The full FPU tag word. |
| 149 //! |
| 150 //! \return The abridged FPU tag word. |
| 151 static uint8_t FsaveToFxsaveTagWord(uint16_t fsave_tag); |
| 152 |
90 // Integer registers. | 153 // Integer registers. |
91 uint32_t eax; | 154 uint32_t eax; |
92 uint32_t ebx; | 155 uint32_t ebx; |
93 uint32_t ecx; | 156 uint32_t ecx; |
94 uint32_t edx; | 157 uint32_t edx; |
95 uint32_t edi; // destination index | 158 uint32_t edi; // destination index |
96 uint32_t esi; // source index | 159 uint32_t esi; // source index |
97 uint32_t ebp; // base pointer | 160 uint32_t ebp; // base pointer |
98 uint32_t esp; // stack pointer | 161 uint32_t esp; // stack pointer |
99 uint32_t eip; // instruction pointer | 162 uint32_t eip; // instruction pointer |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 CPUArchitecture architecture; | 273 CPUArchitecture architecture; |
211 union { | 274 union { |
212 CPUContextX86* x86; | 275 CPUContextX86* x86; |
213 CPUContextX86_64* x86_64; | 276 CPUContextX86_64* x86_64; |
214 }; | 277 }; |
215 }; | 278 }; |
216 | 279 |
217 } // namespace crashpad | 280 } // namespace crashpad |
218 | 281 |
219 #endif // CRASHPAD_SNAPSHOT_SNAPSHOT_CPU_CONTEXT_H_ | 282 #endif // CRASHPAD_SNAPSHOT_SNAPSHOT_CPU_CONTEXT_H_ |
OLD | NEW |