1 //===-- RegisterContextNetBSD_x86_64.cpp ----------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "RegisterContextNetBSD_x86_64.h"
10 #include "RegisterContextNetBSD_i386.h"
11 #include "RegisterContextPOSIX_x86.h"
12 #include "llvm/Support/Compiler.h"
13 #include "llvm/TargetParser/Triple.h"
17 using namespace lldb_private
;
20 // src/sys/arch/amd64/include/frame_regs.h
32 uint64_t r14
; /* 10 */
33 uint64_t r15
; /* 11 */
34 uint64_t rbp
; /* 12 */
35 uint64_t rbx
; /* 13 */
36 uint64_t rax
; /* 14 */
41 uint64_t trapno
; /* 19 */
42 uint64_t err
; /* 20 */
43 uint64_t rip
; /* 21 */
45 uint64_t rflags
; /* 23 */
46 uint64_t rsp
; /* 24 */
51 uint64_t dr
[16]; /* debug registers */
52 /* Index 0-3: debug address registers */
53 /* Index 4-5: reserved */
54 /* Index 6: debug status */
55 /* Index 7: debug control */
56 /* Index 8-15: reserved */
60 * src/sys/arch/amd64/include/mcontext.h
63 * __gregset_t __gregs;
64 * __greg_t _mc_tlsbase;
65 * __fpregset_t __fpregs;
76 #define DR_OFFSET(reg_index) \
77 (LLVM_EXTENSION offsetof(UserArea, dbg) + \
78 LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
81 // Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
83 #define DECLARE_REGISTER_INFOS_X86_64_STRUCT
84 #include "RegisterInfos_x86_64.h"
85 #undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
87 static std::vector
<lldb_private::RegisterInfo
> &GetPrivateRegisterInfoVector() {
88 static std::vector
<lldb_private::RegisterInfo
> g_register_infos
;
89 return g_register_infos
;
92 static const RegisterInfo
*
93 GetRegisterInfo_i386(const lldb_private::ArchSpec
&arch
) {
94 std::vector
<lldb_private::RegisterInfo
> &g_register_infos
=
95 GetPrivateRegisterInfoVector();
97 // Allocate RegisterInfo only once
98 if (g_register_infos
.empty()) {
99 // Copy the register information from base class
100 std::unique_ptr
<RegisterContextNetBSD_i386
> reg_interface(
101 new RegisterContextNetBSD_i386(arch
));
102 const RegisterInfo
*base_info
= reg_interface
->GetRegisterInfo();
103 g_register_infos
.insert(g_register_infos
.end(), &base_info
[0],
104 &base_info
[k_num_registers_i386
]);
106 // Include RegisterInfos_x86_64 to update the g_register_infos structure
107 // with x86_64 offsets.
108 #define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
109 #include "RegisterInfos_x86_64.h"
110 #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
113 return &g_register_infos
[0];
116 static const RegisterInfo
*
117 PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec
&target_arch
) {
118 switch (target_arch
.GetMachine()) {
119 case llvm::Triple::x86
:
120 return GetRegisterInfo_i386(target_arch
);
121 case llvm::Triple::x86_64
:
122 return g_register_infos_x86_64
;
124 assert(false && "Unhandled target architecture.");
130 PrivateGetRegisterCount(const lldb_private::ArchSpec
&target_arch
) {
131 switch (target_arch
.GetMachine()) {
132 case llvm::Triple::x86
: {
133 assert(!GetPrivateRegisterInfoVector().empty() &&
134 "i386 register info not yet filled.");
135 return static_cast<uint32_t>(GetPrivateRegisterInfoVector().size());
137 case llvm::Triple::x86_64
:
138 return static_cast<uint32_t>(sizeof(g_register_infos_x86_64
) /
139 sizeof(g_register_infos_x86_64
[0]));
141 assert(false && "Unhandled target architecture.");
147 PrivateGetUserRegisterCount(const lldb_private::ArchSpec
&target_arch
) {
148 switch (target_arch
.GetMachine()) {
149 case llvm::Triple::x86
:
150 return static_cast<uint32_t>(k_num_user_registers_i386
);
151 case llvm::Triple::x86_64
:
152 return static_cast<uint32_t>(k_num_user_registers_x86_64
);
154 assert(false && "Unhandled target architecture.");
159 RegisterContextNetBSD_x86_64::RegisterContextNetBSD_x86_64(
160 const ArchSpec
&target_arch
)
161 : lldb_private::RegisterInfoInterface(target_arch
),
162 m_register_info_p(PrivateGetRegisterInfoPtr(target_arch
)),
163 m_register_count(PrivateGetRegisterCount(target_arch
)),
164 m_user_register_count(PrivateGetUserRegisterCount(target_arch
)) {}
166 size_t RegisterContextNetBSD_x86_64::GetGPRSize() const { return sizeof(GPR
); }
168 const RegisterInfo
*RegisterContextNetBSD_x86_64::GetRegisterInfo() const {
169 return m_register_info_p
;
172 uint32_t RegisterContextNetBSD_x86_64::GetRegisterCount() const {
173 return m_register_count
;
176 uint32_t RegisterContextNetBSD_x86_64::GetUserRegisterCount() const {
177 return m_user_register_count
;