]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp
Checkpoint initial integration work
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / Utility / RegisterContextLinux_i386.cpp
1 //===-- RegisterContextLinux_i386.cpp --------------------------*- 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 #include "RegisterContextPOSIX_x86.h"
11 #include "RegisterContextLinux_i386.h"
12
13 using namespace lldb_private;
14 using namespace lldb;
15
16 struct GPR
17 {
18     uint32_t ebx;
19     uint32_t ecx;
20     uint32_t edx;
21     uint32_t esi;
22     uint32_t edi;
23     uint32_t ebp;
24     uint32_t eax;
25     uint32_t ds;
26     uint32_t es;
27     uint32_t fs;
28     uint32_t gs;
29     uint32_t orig_eax;
30     uint32_t eip;
31     uint32_t cs;
32     uint32_t eflags;
33     uint32_t esp;
34     uint32_t ss;
35 };
36
37 struct FPR_i386
38 {
39     uint16_t fctrl;         // FPU Control Word (fcw)
40     uint16_t fstat;         // FPU Status Word (fsw)
41     uint8_t ftag;           // FPU Tag Word (ftw)
42     uint8_t reserved_1;     // Reserved
43     uint16_t fop;           // Last Instruction Opcode (fop)
44     union
45     {
46         struct
47         {
48             uint64_t fip;   // Instruction Pointer
49             uint64_t fdp;   // Data Pointer
50         } x86_64;
51         struct
52         {
53             uint32_t fioff;   // FPU IP Offset (fip)
54             uint32_t fiseg;   // FPU IP Selector (fcs)
55             uint32_t fooff;   // FPU Operand Pointer Offset (foo)
56             uint32_t foseg;   // FPU Operand Pointer Selector (fos)
57         } i386_;// Added _ in the end to avoid error with gcc defining i386 in some cases
58     } ptr;
59     uint32_t mxcsr;         // MXCSR Register State
60     uint32_t mxcsrmask;     // MXCSR Mask
61     MMSReg   stmm[8];       // 8*16 bytes for each FP-reg = 128 bytes
62     XMMReg   xmm[8];        // 8*16 bytes for each XMM-reg = 128 bytes
63     uint32_t padding[56];
64 };
65
66 struct UserArea
67 {
68     GPR      regs;          // General purpose registers.
69     int32_t  fpvalid;       // True if FPU is being used.
70     FPR_i386 i387;          // FPU registers.
71     uint32_t tsize;         // Text segment size.
72     uint32_t dsize;         // Data segment size.
73     uint32_t ssize;         // Stack segment size.
74     uint32_t start_code;    // VM address of text.
75     uint32_t start_stack;   // VM address of stack bottom (top in rsp).
76     int32_t  signal;        // Signal causing core dump.
77     int32_t  reserved;      // Unused.
78     uint32_t ar0;           // Location of GPR's.
79     uint32_t fpstate;       // Location of FPR's. Should be a FXSTATE *, but this
80                                 //  has to be 32-bits even on 64-bit systems.
81     uint32_t magic;         // Identifier for core dumps.
82     char     u_comm[32];    // Command causing core dump.
83     uint32_t u_debugreg[8]; // Debug registers (DR0 - DR7).
84 };
85
86 #define DR_SIZE sizeof(((UserArea*)NULL)->u_debugreg[0])
87 #define DR_0_OFFSET 0xFC
88 #define DR_OFFSET(reg_index) \
89     (DR_0_OFFSET + (reg_index * 4))
90 #define FPR_SIZE(reg) sizeof(((FPR_i386*)NULL)->reg)
91
92 //---------------------------------------------------------------------------
93 // Include RegisterInfos_i386 to declare our g_register_infos_i386 structure.
94 //---------------------------------------------------------------------------
95 #define DECLARE_REGISTER_INFOS_I386_STRUCT
96 #include "RegisterInfos_i386.h"
97 #undef DECLARE_REGISTER_INFOS_I386_STRUCT
98
99 RegisterContextLinux_i386::RegisterContextLinux_i386(const ArchSpec &target_arch) :
100     RegisterInfoInterface(target_arch)
101 {
102     RegisterInfo orig_ax = { "orig_eax", NULL, sizeof(((GPR*)NULL)->orig_eax), (LLVM_EXTENSION offsetof(GPR, orig_eax)), eEncodingUint, \
103               eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM }, NULL, NULL };
104     d_register_infos.push_back(orig_ax);
105 }
106
107 size_t
108 RegisterContextLinux_i386::GetGPRSize() const
109 {
110     return sizeof(GPR);
111 }
112
113 const RegisterInfo *
114 RegisterContextLinux_i386::GetRegisterInfo() const
115 {
116     switch (m_target_arch.GetMachine())
117     {
118         case llvm::Triple::x86:            
119         case llvm::Triple::x86_64:
120             return g_register_infos_i386;
121         default:
122             assert(false && "Unhandled target architecture.");
123             return NULL;
124     }
125 }
126
127 uint32_t
128 RegisterContextLinux_i386::GetRegisterCount () const
129 {
130     return static_cast<uint32_t> (sizeof (g_register_infos_i386) / sizeof (g_register_infos_i386 [0]));
131 }
132
133 uint32_t
134 RegisterContextLinux_i386::GetUserRegisterCount () const
135 {
136     return static_cast<uint32_t> (k_num_user_registers_i386);
137 }
138
139 const std::vector<lldb_private::RegisterInfo> *
140 RegisterContextLinux_i386::GetDynamicRegisterInfoP() const
141 {
142     return &d_register_infos;
143 }