12341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen//===-- RegisterContext_x86_64.h ---------------------------*- C++ -*-===//
22341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen//
32341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen//                     The LLVM Compiler Infrastructure
42341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen//
52341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// This file is distributed under the University of Illinois Open Source
62341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// License. See LICENSE.TXT for details.
72341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen//
82341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen//===----------------------------------------------------------------------===//
92341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
102341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#ifndef liblldb_RegisterContext_x86_64_H_
112341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#define liblldb_RegisterContext_x86_64_H_
122341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
132341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#include "lldb/Core/Log.h"
142341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#include "RegisterContextPOSIX.h"
152341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
162341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chenclass ProcessMonitor;
172341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
18dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi// Internal codes for all x86_64 registers.
19dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthienum
20dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi{
21dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_first_gpr,
22dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rax = k_first_gpr,
23dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rbx,
24dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rcx,
25dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rdx,
26dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rdi,
27dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rsi,
28dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rbp,
29dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rsp,
30dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_r8,
31dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_r9,
32dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_r10,
33dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_r11,
34dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_r12,
35dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_r13,
36dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_r14,
37dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_r15,
38dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rip,
39dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_rflags,
40dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_cs,
41dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_fs,
42dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_gs,
43dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_ss,
44dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_ds,
45dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_es,
46de0201e8b6340994303dcd29526d633dcbca676eAshok Thirumurthi    k_first_i386,
47de0201e8b6340994303dcd29526d633dcbca676eAshok Thirumurthi    gpr_eax = k_first_i386,
48dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_ebx,
49dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_ecx,
50dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_edx,
51dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_edi,
52dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_esi,
53dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_ebp,
54dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_esp,
55dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    gpr_eip,
56de0201e8b6340994303dcd29526d633dcbca676eAshok Thirumurthi    gpr_eflags, // eRegisterKindLLDB == 33
57de0201e8b6340994303dcd29526d633dcbca676eAshok Thirumurthi    k_last_i386 = gpr_eflags,
58de0201e8b6340994303dcd29526d633dcbca676eAshok Thirumurthi    k_last_gpr = gpr_eflags,
59dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi
60dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_first_fpr,
61dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_fcw = k_first_fpr,
62dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_fsw,
63dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ftw,
64dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_fop,
65dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ip,
66dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_cs,
67dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_dp,
68dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ds,
69dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_mxcsr,
70dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_mxcsrmask,
71dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_stmm0,
72dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_stmm1,
73dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_stmm2,
74dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_stmm3,
75dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_stmm4,
76dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_stmm5,
77dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_stmm6,
78dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_stmm7,
79dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm0,
80dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm1,
81dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm2,
82dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm3,
83dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm4,
84dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm5,
85dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm6,
86dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm7,
87dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm8,
88dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm9,
89dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm10,
90dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm11,
91dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm12,
92dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm13,
93dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm14,
94dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_xmm15,
95dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_last_fpr = fpu_xmm15,
96dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_first_avx,
97dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm0 = k_first_avx,
98dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm1,
99dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm2,
100dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm3,
101dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm4,
102dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm5,
103dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm6,
104dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm7,
105dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm8,
106dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm9,
107dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm10,
108dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm11,
109dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm12,
110dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm13,
111dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm14,
112dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    fpu_ymm15,
113dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_last_avx = fpu_ymm15,
114dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi
1153d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    dr0,
1163d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    dr1,
1173d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    dr2,
1183d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    dr3,
1193d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    dr4,
1203d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    dr5,
1213d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    dr6,
1223d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    dr7,
1233d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
124dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_num_registers,
125dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_num_gpr_registers = k_last_gpr - k_first_gpr + 1,
126dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_num_fpr_registers = k_last_fpr - k_first_fpr + 1,
127dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    k_num_avx_registers = k_last_avx - k_first_avx + 1
128dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi};
129dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi
1302341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chenclass RegisterContext_x86_64
1312341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen  : public RegisterContextPOSIX
1322341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen{
1332341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chenpublic:
1342341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    RegisterContext_x86_64 (lldb_private::Thread &thread,
135dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi                            uint32_t concrete_frame_idx);
1362341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1372341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    ~RegisterContext_x86_64();
1382341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1392341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    void
1402341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    Invalidate();
1412341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1422341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    void
1432341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    InvalidateAllRegisters();
1442341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1452341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    size_t
1462341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    GetRegisterCount();
1472341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
148dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    virtual size_t
149dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    GetGPRSize() = 0;
150dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi
151dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    virtual unsigned
152dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    GetRegisterSize(unsigned reg);
153dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi
154dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    virtual unsigned
155dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    GetRegisterOffset(unsigned reg);
156dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi
1572341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    const lldb_private::RegisterInfo *
1582989a5aec5b5e313e0885c215681c68151e7c4bbGreg Clayton    GetRegisterInfoAtIndex(size_t reg);
1592341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1602341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    size_t
1612341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    GetRegisterSetCount();
1622341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1632341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    const lldb_private::RegisterSet *
1642989a5aec5b5e313e0885c215681c68151e7c4bbGreg Clayton    GetRegisterSet(size_t set);
1652341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
166c73fedb63ab170d711fb73d198451eb8db710e8dAshok Thirumurthi    unsigned
1672341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    GetRegisterIndexFromOffset(unsigned offset);
1682341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
169c73fedb63ab170d711fb73d198451eb8db710e8dAshok Thirumurthi    const char *
1702341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    GetRegisterName(unsigned reg);
1712341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1722341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    virtual bool
1732341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    ReadRegister(const lldb_private::RegisterInfo *reg_info,
1742341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen                 lldb_private::RegisterValue &value);
1752341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1762341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    bool
1772341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
1782341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1792341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    virtual bool
1802341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    WriteRegister(const lldb_private::RegisterInfo *reg_info,
1812341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen                  const lldb_private::RegisterValue &value);
1822341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1832341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    bool
1842341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
1852341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1862341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    uint32_t
1872341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num);
1882341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
1893d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    uint32_t
1903d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    NumSupportedHardwareWatchpoints();
1913d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
1923d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    uint32_t
1933d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    SetHardwareWatchpoint(lldb::addr_t, size_t size, bool read, bool write);
1943d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
1953d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    bool
19612c5bf31a5a3f96970b4101495ecbcc8449e12f6Matt Kopec    SetHardwareWatchpointWithIndex(lldb::addr_t, size_t size, bool read,
19712c5bf31a5a3f96970b4101495ecbcc8449e12f6Matt Kopec                                   bool write, uint32_t hw_index);
19812c5bf31a5a3f96970b4101495ecbcc8449e12f6Matt Kopec
19912c5bf31a5a3f96970b4101495ecbcc8449e12f6Matt Kopec    bool
2003d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    ClearHardwareWatchpoint(uint32_t hw_index);
2013d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
2022341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    bool
2032341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    HardwareSingleStep(bool enable);
2042341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
2052341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    bool
2062341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    UpdateAfterBreakpoint();
2072341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
2083d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    bool
2093d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    IsWatchpointVacant(uint32_t hw_index);
2103d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
2113d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    bool
2123d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    IsWatchpointHit (uint32_t hw_index);
2133d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
2143d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    lldb::addr_t
2153d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    GetWatchpointAddress (uint32_t hw_index);
2163d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
2173d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    bool
2183d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    ClearWatchpointHits();
2193d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
22066bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    //---------------------------------------------------------------------------
22166bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    // Generic floating-point registers
22266bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    //---------------------------------------------------------------------------
2233d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
2242341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    struct MMSReg
2252341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    {
2262341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint8_t bytes[10];
2272341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint8_t pad[6];
2282341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    };
2292341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
2302341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    struct XMMReg
2312341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    {
23266bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        uint8_t bytes[16]; // 128-bits for each XMM register
2332341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    };
2342341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
23566bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    struct FXSAVE
2362341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    {
2372341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint16_t fcw;
2382341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint16_t fsw;
2392341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint16_t ftw;
2402341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint16_t fop;
2412341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint64_t ip;
2422341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint64_t dp;
2432341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint32_t mxcsr;
2442341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint32_t mxcsrmask;
2452341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        MMSReg   stmm[8];
2462341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        XMMReg   xmm[16];
2472341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen        uint32_t padding[24];
2482341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    };
2492341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
25066bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    //---------------------------------------------------------------------------
25166bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    // Extended floating-point registers
25266bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    //---------------------------------------------------------------------------
25366bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    struct YMMHReg
25466bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    {
25566bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        uint8_t  bytes[16];     // 16 * 8 bits for the high bytes of each YMM register
25666bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    };
25766bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi
25866bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    struct YMMReg
25966bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    {
26066bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        uint8_t  bytes[32];     // 16 * 16 bits for each YMM register
26166bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    };
26266bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi
26366bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    struct YMM
26466bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    {
26566bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        YMMReg   ymm[16];       // assembled from ymmh and xmm registers
26666bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    };
26766bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi
26866bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    struct XSAVE_HDR
26966bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    {
27066bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        uint64_t  xstate_bv;    // OS enabled xstate mask to determine the extended states supported by the processor
27166bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        uint64_t  reserved1[2];
27266bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        uint64_t  reserved2[5];
27366bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    } __attribute__((packed));
27466bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi
27566bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    // x86 extensions to FXSAVE (i.e. for AVX processors)
27666bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    struct XSAVE
27766bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    {
27866bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        FXSAVE    i387;         // floating point registers typical in i387_fxsave_struct
27966bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        XSAVE_HDR header;       // The xsave_hdr_struct can be used to determine if the following extensions are usable
28066bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        YMMHReg   ymmh[16];     // High 16 bytes of each of 16 YMM registers (the low bytes are in FXSAVE.xmm for compatibility with SSE)
28166bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        // Slot any extensions to the register file here
28266bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    } __attribute__((packed, aligned (64)));
28366bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi
28466bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    struct IOVEC
28566bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    {
28666bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        void    *iov_base;      // pointer to XSAVE
28766bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        size_t   iov_len;       // sizeof(XSAVE)
28866bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    };
28966bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi
29066bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    //---------------------------------------------------------------------------
29166bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    // Note: prefer kernel definitions over user-land
29266bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    //---------------------------------------------------------------------------
29366bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    enum FPRType
29466bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    {
29566bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        eNotValid = 0,
29666bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        eFSAVE,  // TODO
29766bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        eFXSAVE,
29866bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        eSOFT,   // TODO
29966bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        eXSAVE
30066bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    };
30166bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi
30266bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    // Floating-point registers
30366bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    struct FPR
30466bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    {
30566bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        // Thread state for the floating-point unit of the processor read by ptrace.
30666bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        union XSTATE {
30766bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi            FXSAVE   fxsave;    // Generic floating-point registers.
30866bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi            XSAVE    xsave;     // x86 extended processor state.
30966bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi        } xstate;
3102341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    };
3112341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
3120852cbb9660c92a448468a8ec7c39fb7245eca57Ashok Thirumurthiprotected:
3130852cbb9660c92a448468a8ec7c39fb7245eca57Ashok Thirumurthi    // Determines if an extended register set is supported on the processor running the inferior process.
3140852cbb9660c92a448468a8ec7c39fb7245eca57Ashok Thirumurthi    virtual bool
3150852cbb9660c92a448468a8ec7c39fb7245eca57Ashok Thirumurthi    IsRegisterSetAvailable(size_t set_index);
3160852cbb9660c92a448468a8ec7c39fb7245eca57Ashok Thirumurthi
317dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    virtual const lldb_private::RegisterInfo *
318dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi    GetRegisterInfo();
319dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthi
3203d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    virtual bool
3213d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    ReadRegister(const unsigned reg, lldb_private::RegisterValue &value);
3223d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
3233d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    virtual bool
3243d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec    WriteRegister(const unsigned reg, const lldb_private::RegisterValue &value);
3253d4d51cd1bdef32ab61ba9e1de75d5a4f4c1dbedMatt Kopec
326dae196da3bf9c181405c9c0c1083069dc007e318Ashok Thirumurthiprivate:
32726aa43bcbccc89d7b52adfed26c545430c021635Ashok Thirumurthi    uint64_t m_gpr[k_num_gpr_registers]; // general purpose registers.
32826aa43bcbccc89d7b52adfed26c545430c021635Ashok Thirumurthi    FPRType  m_fpr_type;                 // determines the type of data stored by union FPR, if any.
32926aa43bcbccc89d7b52adfed26c545430c021635Ashok Thirumurthi    FPR      m_fpr;                      // floating-point registers including extended register sets.
33026aa43bcbccc89d7b52adfed26c545430c021635Ashok Thirumurthi    IOVEC    m_iovec;                    // wrapper for xsave.
33126aa43bcbccc89d7b52adfed26c545430c021635Ashok Thirumurthi    YMM      m_ymm_set;                  // copy of ymmh and xmm register halves.
3322341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
3332341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    ProcessMonitor &GetMonitor();
33466bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi    lldb::ByteOrder GetByteOrder();
33566bd7d7ed3f05ea14fe0630726835ddeb2d07be7Ashok Thirumurthi
33626aa43bcbccc89d7b52adfed26c545430c021635Ashok Thirumurthi    bool CopyXSTATEtoYMM(uint32_t reg, lldb::ByteOrder byte_order);
33726aa43bcbccc89d7b52adfed26c545430c021635Ashok Thirumurthi    bool CopyYMMtoXSTATE(uint32_t reg, lldb::ByteOrder byte_order);
338c73fedb63ab170d711fb73d198451eb8db710e8dAshok Thirumurthi    bool IsFPR(unsigned reg, FPRType fpr_type);
3392341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
3402341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    bool ReadGPR();
3412341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    bool ReadFPR();
3422341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
3432341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    bool WriteGPR();
3442341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen    bool WriteFPR();
3452341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen};
3462341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen
3472341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#endif // #ifndef liblldb_RegisterContext_x86_64_H_
348