1257752Semaste//===-- RegisterContextLinux_i386.cpp --------------------------*- C++ -*-===//
2257752Semaste//
3257752Semaste//                     The LLVM Compiler Infrastructure
4257752Semaste//
5257752Semaste// This file is distributed under the University of Illinois Open Source
6257752Semaste// License. See LICENSE.TXT for details.
7257752Semaste//
8257752Semaste//===---------------------------------------------------------------------===//
9257752Semaste
10257752Semaste#include "RegisterContextPOSIX_x86.h"
11257752Semaste#include "RegisterContextLinux_i386.h"
12257752Semaste
13257752Semasteusing namespace lldb_private;
14257752Semasteusing namespace lldb;
15257752Semaste
16257752Semastestruct GPR
17257752Semaste{
18257752Semaste    uint32_t ebx;
19257752Semaste    uint32_t ecx;
20257752Semaste    uint32_t edx;
21257752Semaste    uint32_t esi;
22257752Semaste    uint32_t edi;
23257752Semaste    uint32_t ebp;
24257752Semaste    uint32_t eax;
25257752Semaste    uint32_t ds;
26257752Semaste    uint32_t es;
27257752Semaste    uint32_t fs;
28257752Semaste    uint32_t gs;
29257752Semaste    uint32_t orig_ax;
30257752Semaste    uint32_t eip;
31257752Semaste    uint32_t cs;
32257752Semaste    uint32_t eflags;
33257752Semaste    uint32_t esp;
34257752Semaste    uint32_t ss;
35257752Semaste};
36257752Semaste
37257752Semastestruct UserArea
38257752Semaste{
39257752Semaste    GPR      regs;          // General purpose registers.
40257752Semaste    int32_t  fpvalid;       // True if FPU is being used.
41257752Semaste    FXSAVE   i387;          // FPU registers.
42257752Semaste    uint32_t tsize;         // Text segment size.
43257752Semaste    uint32_t dsize;         // Data segment size.
44257752Semaste    uint32_t ssize;         // Stack segment size.
45257752Semaste    uint32_t start_code;    // VM address of text.
46257752Semaste    uint32_t start_stack;   // VM address of stack bottom (top in rsp).
47257752Semaste    int32_t  signal;        // Signal causing core dump.
48257752Semaste    int32_t  reserved;      // Unused.
49257752Semaste    uint32_t ar0;           // Location of GPR's.
50257752Semaste    uint32_t fpstate;       // Location of FPR's. Should be a FXSTATE *, but this
51257752Semaste	                        //  has to be 32-bits even on 64-bit systems.
52257752Semaste    uint32_t magic;         // Identifier for core dumps.
53257752Semaste    char     u_comm[32];    // Command causing core dump.
54257752Semaste    uint32_t u_debugreg[8]; // Debug registers (DR0 - DR7).
55257752Semaste};
56257752Semaste
57257752Semaste#define DR_SIZE sizeof(UserArea::u_debugreg[0])
58257752Semaste#define DR_OFFSET(reg_index) \
59257752Semaste    (LLVM_EXTENSION offsetof(UserArea, u_debugreg[reg_index]))
60257752Semaste
61257752Semaste//---------------------------------------------------------------------------
62257752Semaste// Include RegisterInfos_i386 to declare our g_register_infos_i386 structure.
63257752Semaste//---------------------------------------------------------------------------
64257752Semaste#define DECLARE_REGISTER_INFOS_I386_STRUCT
65257752Semaste#include "RegisterInfos_i386.h"
66257752Semaste#undef DECLARE_REGISTER_INFOS_I386_STRUCT
67257752Semaste
68257752SemasteRegisterContextLinux_i386::RegisterContextLinux_i386(const ArchSpec &target_arch) :
69257752Semaste    RegisterInfoInterface(target_arch)
70257752Semaste{
71257752Semaste}
72257752Semaste
73257752SemasteRegisterContextLinux_i386::~RegisterContextLinux_i386()
74257752Semaste{
75257752Semaste}
76257752Semaste
77257752Semastesize_t
78257752SemasteRegisterContextLinux_i386::GetGPRSize()
79257752Semaste{
80257752Semaste    return sizeof(GPR);
81257752Semaste}
82257752Semaste
83257752Semasteconst RegisterInfo *
84257752SemasteRegisterContextLinux_i386::GetRegisterInfo()
85257752Semaste{
86257752Semaste    switch (m_target_arch.GetCore())
87257752Semaste    {
88257752Semaste        case ArchSpec::eCore_x86_32_i386:
89257752Semaste        case ArchSpec::eCore_x86_32_i486:
90257752Semaste        case ArchSpec::eCore_x86_32_i486sx:
91257752Semaste            return g_register_infos_i386;
92257752Semaste        default:
93257752Semaste            assert(false && "Unhandled target architecture.");
94257752Semaste            return NULL;
95257752Semaste    }
96257752Semaste}
97