1 //===-- RegisterContext_x86.cpp ---------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "RegisterContext_x86.h"
11 using namespace lldb_private
;
13 // Convert the 8-bit abridged FPU Tag Word (as found in FXSAVE) to the full
14 // 16-bit FPU Tag Word (as found in FSAVE, and used by gdb protocol). This
15 // requires knowing the values of the ST(i) registers and the FPU Status Word.
16 uint16_t lldb_private::AbridgedToFullTagWord(uint8_t abridged_tw
, uint16_t sw
,
17 llvm::ArrayRef
<MMSReg
> st_regs
) {
18 // Tag word is using internal FPU register numbering rather than ST(i).
19 // Mapping to ST(i): i = FPU regno - TOP (Status Word, bits 11:13).
20 // Here we start with FPU reg 7 and go down.
21 int st
= 7 - ((sw
>> 11) & 7);
23 for (uint8_t mask
= 0x80; mask
!= 0; mask
>>= 1) {
25 if (abridged_tw
& mask
) {
26 // The register is non-empty, so we need to check the value of ST(i).
28 st_regs
[st
].comp
.sign_exp
& 0x7fff; // Discard the sign bit.
30 if (st_regs
[st
].comp
.mantissa
== 0)
34 } else if (exp
== 0x7fff)
35 tw
|= 2; // Infinity or NaN
38 tw
|= 3; // Empty register
47 // Convert the 16-bit FPU Tag Word to the abridged 8-bit value, to be written
49 uint8_t lldb_private::FullToAbridgedTagWord(uint16_t tw
) {
50 uint8_t abridged_tw
= 0;
51 for (uint16_t mask
= 0xc000; mask
!= 0; mask
>>= 2) {
53 // full TW uses 11 for empty registers, aTW uses 0
54 if ((tw
& mask
) != mask
)