1 //===-- RegisterContextWindows_x86_64.cpp ---------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "RegisterContextWindows_x86_64.h"
10 #include "RegisterContext_x86.h"
11 #include "lldb-x86-register-enums.h"
12
13 #include <vector>
14
15 using namespace lldb_private;
16 using namespace lldb;
17
18 namespace {
19 typedef struct _GPR {
20 uint64_t rax;
21 uint64_t rcx;
22 uint64_t rdx;
23 uint64_t rbx;
24 uint64_t rsp;
25 uint64_t rbp;
26 uint64_t rsi;
27 uint64_t rdi;
28 uint64_t r8;
29 uint64_t r9;
30 uint64_t r10;
31 uint64_t r11;
32 uint64_t r12;
33 uint64_t r13;
34 uint64_t r14;
35 uint64_t r15;
36 uint64_t rip;
37 uint64_t rflags;
38 uint16_t cs;
39 uint16_t fs;
40 uint16_t gs;
41 uint16_t ss;
42 uint16_t ds;
43 uint16_t es;
44 } GPR;
45
46 #define GPR_OFFSET(regname) (LLVM_EXTENSION offsetof(GPR, regname))
47 #define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
48 { \
49 #reg, alt, sizeof(((GPR *)nullptr)->reg), GPR_OFFSET(reg), eEncodingUint, \
50 eFormatHex, \
51 {kind1, kind2, kind3, kind4, lldb_##reg##_x86_64 }, nullptr, nullptr, \
52 nullptr, \
53 }
54
55 typedef struct _FPReg {
56 XMMReg xmm0;
57 XMMReg xmm1;
58 XMMReg xmm2;
59 XMMReg xmm3;
60 XMMReg xmm4;
61 XMMReg xmm5;
62 XMMReg xmm6;
63 XMMReg xmm7;
64 XMMReg xmm8;
65 XMMReg xmm9;
66 XMMReg xmm10;
67 XMMReg xmm11;
68 XMMReg xmm12;
69 XMMReg xmm13;
70 XMMReg xmm14;
71 XMMReg xmm15;
72 } FPReg;
73
74 #define FPR_OFFSET(regname) \
75 (sizeof(GPR) + LLVM_EXTENSION offsetof(FPReg, regname))
76
77 #define DEFINE_XMM(reg) \
78 { \
79 #reg, NULL, sizeof(((FPReg *)nullptr)->reg), FPR_OFFSET(reg), \
80 eEncodingUint, eFormatVectorOfUInt64, \
81 {dwarf_##reg##_x86_64, dwarf_##reg##_x86_64, LLDB_INVALID_REGNUM, \
82 LLDB_INVALID_REGNUM, lldb_##reg##_x86_64 }, \
83 nullptr, nullptr, nullptr, \
84 }
85
86 // clang-format off
87 static RegisterInfo g_register_infos_x86_64[] = {
88 // General purpose registers EH_Frame DWARF Generic Process Plugin
89 // =========================== ================== ================ ========================= ====================
90 DEFINE_GPR(rax, nullptr, dwarf_rax_x86_64, dwarf_rax_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
91 DEFINE_GPR(rbx, nullptr, dwarf_rbx_x86_64, dwarf_rbx_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
92 DEFINE_GPR(rcx, nullptr, dwarf_rcx_x86_64, dwarf_rcx_x86_64, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM),
93 DEFINE_GPR(rdx, nullptr, dwarf_rdx_x86_64, dwarf_rdx_x86_64, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM),
94 DEFINE_GPR(rdi, nullptr, dwarf_rdi_x86_64, dwarf_rdi_x86_64, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM),
95 DEFINE_GPR(rsi, nullptr, dwarf_rsi_x86_64, dwarf_rsi_x86_64, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM),
96 DEFINE_GPR(rbp, nullptr, dwarf_rbp_x86_64, dwarf_rbp_x86_64, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM),
97 DEFINE_GPR(rsp, nullptr, dwarf_rsp_x86_64, dwarf_rsp_x86_64, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM),
98 DEFINE_GPR(r8, nullptr, dwarf_r8_x86_64, dwarf_r8_x86_64, LLDB_REGNUM_GENERIC_ARG5, LLDB_INVALID_REGNUM),
99 DEFINE_GPR(r9, nullptr, dwarf_r9_x86_64, dwarf_r9_x86_64, LLDB_REGNUM_GENERIC_ARG6, LLDB_INVALID_REGNUM),
100 DEFINE_GPR(r10, nullptr, dwarf_r10_x86_64, dwarf_r10_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
101 DEFINE_GPR(r11, nullptr, dwarf_r11_x86_64, dwarf_r11_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
102 DEFINE_GPR(r12, nullptr, dwarf_r12_x86_64, dwarf_r12_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
103 DEFINE_GPR(r13, nullptr, dwarf_r13_x86_64, dwarf_r13_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
104 DEFINE_GPR(r14, nullptr, dwarf_r14_x86_64, dwarf_r14_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
105 DEFINE_GPR(r15, nullptr, dwarf_r15_x86_64, dwarf_r15_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
106 DEFINE_GPR(rip, nullptr, dwarf_rip_x86_64, dwarf_rip_x86_64, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM),
107 DEFINE_GPR(rflags, nullptr, dwarf_rflags_x86_64, dwarf_rflags_x86_64, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM),
108 DEFINE_GPR(cs, nullptr, dwarf_cs_x86_64, dwarf_cs_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
109 DEFINE_GPR(fs, nullptr, dwarf_fs_x86_64, dwarf_fs_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
110 DEFINE_GPR(gs, nullptr, dwarf_gs_x86_64, dwarf_gs_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
111 DEFINE_GPR(ss, nullptr, dwarf_ss_x86_64, dwarf_ss_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
112 DEFINE_GPR(ds, nullptr, dwarf_ds_x86_64, dwarf_ds_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
113 DEFINE_GPR(es, nullptr, dwarf_es_x86_64, dwarf_es_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
114 DEFINE_XMM(xmm0),
115 DEFINE_XMM(xmm1),
116 DEFINE_XMM(xmm2),
117 DEFINE_XMM(xmm3),
118 DEFINE_XMM(xmm4),
119 DEFINE_XMM(xmm5),
120 DEFINE_XMM(xmm6),
121 DEFINE_XMM(xmm7),
122 DEFINE_XMM(xmm8),
123 DEFINE_XMM(xmm9),
124 DEFINE_XMM(xmm10),
125 DEFINE_XMM(xmm11),
126 DEFINE_XMM(xmm12),
127 DEFINE_XMM(xmm13),
128 DEFINE_XMM(xmm14),
129 DEFINE_XMM(xmm15)
130 };
131 // clang-format on
132 } // namespace
133
RegisterContextWindows_x86_64(const ArchSpec & target_arch)134 RegisterContextWindows_x86_64::RegisterContextWindows_x86_64(
135 const ArchSpec &target_arch)
136 : lldb_private::RegisterInfoInterface(target_arch) {
137 assert(target_arch.GetMachine() == llvm::Triple::x86_64);
138 }
139
GetRegisterInfo() const140 const RegisterInfo *RegisterContextWindows_x86_64::GetRegisterInfo() const {
141 return g_register_infos_x86_64;
142 }
143
GetRegisterCount() const144 uint32_t RegisterContextWindows_x86_64::GetRegisterCount() const {
145 return std::size(g_register_infos_x86_64);
146 }
147
GetUserRegisterCount() const148 uint32_t RegisterContextWindows_x86_64::GetUserRegisterCount() const {
149 return std::size(g_register_infos_x86_64);
150 }
151
GetGPRSize() const152 size_t RegisterContextWindows_x86_64::GetGPRSize() const { return sizeof(GPR); }
153