1263363Semaste//===-- RegisterContextFreeBSD_x86_64.cpp ----------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===---------------------------------------------------------------------===//
9254721Semaste
10263363Semaste#include <vector>
11263363Semaste#include "RegisterContextPOSIX_x86.h"
12263363Semaste#include "RegisterContextFreeBSD_i386.h"
13254721Semaste#include "RegisterContextFreeBSD_x86_64.h"
14254721Semaste
15254721Semasteusing namespace lldb_private;
16263363Semasteusing namespace lldb;
17254721Semaste
18263363Semaste// http://svnweb.freebsd.org/base/head/sys/x86/include/reg.h
19254721Semastetypedef struct _GPR
20254721Semaste{
21254721Semaste    uint64_t r15;
22254721Semaste    uint64_t r14;
23254721Semaste    uint64_t r13;
24254721Semaste    uint64_t r12;
25254721Semaste    uint64_t r11;
26254721Semaste    uint64_t r10;
27254721Semaste    uint64_t r9;
28254721Semaste    uint64_t r8;
29254721Semaste    uint64_t rdi;
30254721Semaste    uint64_t rsi;
31254721Semaste    uint64_t rbp;
32254721Semaste    uint64_t rbx;
33254721Semaste    uint64_t rdx;
34254721Semaste    uint64_t rcx;
35254721Semaste    uint64_t rax;
36254721Semaste    uint32_t trapno;
37254721Semaste    uint16_t fs;
38254721Semaste    uint16_t gs;
39254721Semaste    uint32_t err;
40254721Semaste    uint16_t es;
41254721Semaste    uint16_t ds;
42254721Semaste    uint64_t rip;
43254721Semaste    uint64_t cs;
44254721Semaste    uint64_t rflags;
45254721Semaste    uint64_t rsp;
46254721Semaste    uint64_t ss;
47254721Semaste} GPR;
48254721Semaste
49269024Semastestruct dbreg {
50269024Semaste       uint64_t  dr[16];  /* debug registers */
51269024Semaste                          /* Index 0-3: debug address registers */
52269024Semaste                          /* Index 4-5: reserved */
53269024Semaste                          /* Index 6: debug status */
54269024Semaste                          /* Index 7: debug control */
55269024Semaste                          /* Index 8-15: reserved */
56269024Semaste};
57263363Semaste
58269024Semaste#define DR_SIZE sizeof(uint64_t)
59269024Semaste#define DR_OFFSET(reg_index) \
60269024Semaste    (LLVM_EXTENSION offsetof(dbreg, dr[reg_index]))
61269024Semaste
62269024Semaste
63263363Semaste//---------------------------------------------------------------------------
64263363Semaste// Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64 structure.
65263363Semaste//---------------------------------------------------------------------------
66263363Semaste#define DECLARE_REGISTER_INFOS_X86_64_STRUCT
67263363Semaste#include "RegisterInfos_x86_64.h"
68263363Semaste#undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
69263363Semaste
70263363Semastestatic const RegisterInfo *
71263363SemasteGetRegisterInfo_i386(const lldb_private::ArchSpec& arch)
72263363Semaste{
73263363Semaste    static std::vector<lldb_private::RegisterInfo> g_register_infos;
74263363Semaste
75263363Semaste    // Allocate RegisterInfo only once
76263363Semaste    if (g_register_infos.empty())
77263363Semaste    {
78263363Semaste        // Copy the register information from base class
79263363Semaste        std::unique_ptr<RegisterContextFreeBSD_i386> reg_interface(new RegisterContextFreeBSD_i386 (arch));
80263363Semaste        const RegisterInfo *base_info = reg_interface->GetRegisterInfo();
81263363Semaste        g_register_infos.insert(g_register_infos.end(), &base_info[0], &base_info[k_num_registers_i386]);
82263363Semaste
83263363Semaste        //---------------------------------------------------------------------------
84263363Semaste        // Include RegisterInfos_x86_64 to update the g_register_infos structure
85263363Semaste        //  with x86_64 offsets.
86263363Semaste        //---------------------------------------------------------------------------
87263363Semaste        #define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
88263363Semaste        #include "RegisterInfos_x86_64.h"
89263363Semaste        #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
90263363Semaste    }
91263363Semaste
92263363Semaste    return &g_register_infos[0];
93254721Semaste}
94254721Semaste
95263363SemasteRegisterContextFreeBSD_x86_64::RegisterContextFreeBSD_x86_64(const ArchSpec &target_arch) :
96263363Semaste    RegisterInfoInterface(target_arch)
97263363Semaste{
98263363Semaste}
99254721Semaste
100263363SemasteRegisterContextFreeBSD_x86_64::~RegisterContextFreeBSD_x86_64()
101254721Semaste{
102254721Semaste}
103254721Semaste
104254721Semastesize_t
105254721SemasteRegisterContextFreeBSD_x86_64::GetGPRSize()
106254721Semaste{
107254721Semaste    return sizeof(GPR);
108254721Semaste}
109254721Semaste
110254721Semasteconst RegisterInfo *
111254721SemasteRegisterContextFreeBSD_x86_64::GetRegisterInfo()
112254721Semaste{
113263363Semaste    switch (m_target_arch.GetCore())
114254721Semaste    {
115263363Semaste        case ArchSpec::eCore_x86_32_i386:
116263363Semaste        case ArchSpec::eCore_x86_32_i486:
117263363Semaste        case ArchSpec::eCore_x86_32_i486sx:
118263363Semaste            return GetRegisterInfo_i386 (m_target_arch);
119263363Semaste        case ArchSpec::eCore_x86_64_x86_64:
120263363Semaste            return g_register_infos_x86_64;
121263363Semaste        default:
122263363Semaste            assert(false && "Unhandled target architecture.");
123263363Semaste            return NULL;
124254721Semaste    }
125254721Semaste}
126254721Semaste
127