LLDB mainline
RegisterContext_x86.cpp
Go to the documentation of this file.
1//===-- RegisterContext_x86.cpp ---------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
11#include "lldb/lldb-defines.h"
12
13using namespace lldb_private;
14
31
52
85
134
139
144
161
178
195
212
213// Convert the 8-bit abridged FPU Tag Word (as found in FXSAVE) to the full
214// 16-bit FPU Tag Word (as found in FSAVE, and used by gdb protocol). This
215// requires knowing the values of the ST(i) registers and the FPU Status Word.
216uint16_t lldb_private::AbridgedToFullTagWord(uint8_t abridged_tw, uint16_t sw,
217 llvm::ArrayRef<MMSReg> st_regs) {
218 // Tag word is using internal FPU register numbering rather than ST(i).
219 // Mapping to ST(i): i = FPU regno - TOP (Status Word, bits 11:13).
220 // Here we start with FPU reg 7 and go down.
221 int st = 7 - ((sw >> 11) & 7);
222 uint16_t tw = 0;
223 for (uint8_t mask = 0x80; mask != 0; mask >>= 1) {
224 tw <<= 2;
225 if (abridged_tw & mask) {
226 // The register is non-empty, so we need to check the value of ST(i).
227 uint16_t exp =
228 st_regs[st].comp.sign_exp & 0x7fff; // Discard the sign bit.
229 if (exp == 0) {
230 if (st_regs[st].comp.mantissa == 0)
231 tw |= 1; // Zero
232 else
233 tw |= 2; // Denormal
234 } else if (exp == 0x7fff)
235 tw |= 2; // Infinity or NaN
236 // 0 if normal number
237 } else
238 tw |= 3; // Empty register
239
240 // Rotate ST down.
241 st = (st - 1) & 7;
242 }
243
244 return tw;
245}
246
247// Convert the 16-bit FPU Tag Word to the abridged 8-bit value, to be written
248// into FXSAVE.
250 uint8_t abridged_tw = 0;
251 for (uint16_t mask = 0xc000; mask != 0; mask >>= 2) {
252 abridged_tw <<= 1;
253 // full TW uses 11 for empty registers, aTW uses 0
254 if ((tw & mask) != mask)
255 abridged_tw |= 1;
256 }
257 return abridged_tw;
258}
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
uint16_t AbridgedToFullTagWord(uint8_t abridged_tw, uint16_t sw, llvm::ArrayRef< MMSReg > st_regs)
uint8_t FullToAbridgedTagWord(uint16_t tw)