1//===-- RegisterContext_i386.h ------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_RegisterContext_i386_h_
11#define liblldb_RegisterContext_i386_h_
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/Core/Log.h"
18#include "RegisterContextPOSIX.h"
19
20class RegisterContext_i386 : public RegisterContextPOSIX
21{
22public:
23    RegisterContext_i386(lldb_private::Thread &thread,
24                              uint32_t concreate_frame_idx);
25
26    ~RegisterContext_i386();
27
28    void
29    Invalidate();
30
31    void
32    InvalidateAllRegisters();
33
34    size_t
35    GetRegisterCount();
36
37    const lldb_private::RegisterInfo *
38    GetRegisterInfoAtIndex(size_t reg);
39
40    size_t
41    GetRegisterSetCount();
42
43    const lldb_private::RegisterSet *
44    GetRegisterSet(size_t set);
45
46    unsigned
47    GetRegisterIndexFromOffset(unsigned offset);
48
49    const char *
50    GetRegisterName(unsigned reg);
51
52    bool
53    ReadRegisterValue(uint32_t reg, lldb_private::Scalar &value);
54
55    bool
56    ReadRegisterBytes(uint32_t reg, lldb_private::DataExtractor &data);
57
58    virtual bool
59    ReadRegister(const lldb_private::RegisterInfo *reg_info,
60                 lldb_private::RegisterValue &value);
61
62    bool
63    ReadAllRegisterValues(lldb::DataBufferSP &data_sp);
64
65    bool
66    WriteRegisterValue(uint32_t reg, const lldb_private::Scalar &value);
67
68    bool
69    WriteRegisterBytes(uint32_t reg, lldb_private::DataExtractor &data,
70                       uint32_t data_offset = 0);
71
72    virtual bool
73    WriteRegister(const lldb_private::RegisterInfo *reg_info,
74                  const lldb_private::RegisterValue &value);
75
76    bool
77    WriteAllRegisterValues(const lldb::DataBufferSP &data_sp);
78
79    uint32_t
80    ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num);
81
82    bool
83    HardwareSingleStep(bool enable);
84
85    bool
86    UpdateAfterBreakpoint();
87
88    struct GPR
89    {
90        uint32_t ebx;
91        uint32_t ecx;
92        uint32_t edx;
93        uint32_t esi;
94        uint32_t edi;
95        uint32_t ebp;
96        uint32_t eax;
97        uint32_t ds;
98        uint32_t es;
99        uint32_t fs;
100        uint32_t gs;
101        uint32_t orig_ax;
102        uint32_t eip;
103        uint32_t cs;
104        uint32_t eflags;
105        uint32_t esp;
106        uint32_t ss;
107    };
108
109    struct MMSReg
110    {
111        uint8_t bytes[8];
112    };
113
114    struct XMMReg
115    {
116        uint8_t bytes[16];
117    };
118
119    struct FPU
120    {
121        uint16_t    fcw;
122        uint16_t    fsw;
123        uint16_t    ftw;
124        uint16_t    fop;
125        uint32_t    ip;
126        uint32_t    cs;
127        uint32_t    foo;
128        uint32_t    fos;
129        uint32_t    mxcsr;
130        uint32_t    reserved;
131        MMSReg      stmm[8];
132        XMMReg      xmm[8];
133        uint32_t    pad[56];
134    };
135
136    // A user area like this no longer exists on FreeBSD
137    // making this a Linux artifact. Nonetheless, it is safe
138    // leaving it here while the code is being cleaned up and generalized.
139
140    struct UserArea
141    {
142        GPR      regs;          // General purpose registers.
143        int32_t  fpvalid;       // True if FPU is being used.
144        FPU      i387;          // FPU registers.
145        uint32_t tsize;         // Text segment size.
146        uint32_t dsize;         // Data segment size.
147        uint32_t ssize;         // Stack segment size.
148        uint32_t start_code;    // VM address of text.
149        uint32_t start_stack;   // VM address of stack bottom (top in rsp).
150        int32_t  signal;        // Signal causing core dump.
151        int32_t  reserved;      // Unused.
152        uint32_t ar0;           // Location of GPR's.
153        FPU*     fpstate;       // Location of FPR's.
154        uint32_t magic;         // Identifier for core dumps.
155        char     u_comm[32];    // Command causing core dump.
156        uint32_t u_debugreg[8]; // Debug registers (DR0 - DR7).
157    };
158private:
159    UserArea user;
160
161    ProcessMonitor &GetMonitor();
162
163    void LogGPR(const char *title);
164
165    bool ReadGPR();
166    bool ReadFPR();
167};
168
169#endif // #ifndef liblldb_RegisterContext_i386_h_
170