1*e69a3d18SMichał Górny //===-- GDBRemoteRegisterFallback.cpp -------------------------------------===//
2*e69a3d18SMichał Górny //
3*e69a3d18SMichał Górny // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e69a3d18SMichał Górny // See https://llvm.org/LICENSE.txt for license information.
5*e69a3d18SMichał Górny // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e69a3d18SMichał Górny //
7*e69a3d18SMichał Górny //===----------------------------------------------------------------------===//
8*e69a3d18SMichał Górny
9*e69a3d18SMichał Górny #include "GDBRemoteRegisterFallback.h"
10*e69a3d18SMichał Górny
11*e69a3d18SMichał Górny namespace lldb_private {
12*e69a3d18SMichał Górny namespace process_gdb_remote {
13*e69a3d18SMichał Górny
14*e69a3d18SMichał Górny #define REG(name, size) \
15*e69a3d18SMichał Górny DynamicRegisterInfo::Register { \
16*e69a3d18SMichał Górny ConstString(#name), empty_alt_name, reg_set, size, LLDB_INVALID_INDEX32, \
17*e69a3d18SMichał Górny lldb::eEncodingUint, lldb::eFormatHex, LLDB_INVALID_REGNUM, \
18*e69a3d18SMichał Górny LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, {}, {} \
19*e69a3d18SMichał Górny }
20*e69a3d18SMichał Górny #define R64(name) REG(name, 8)
21*e69a3d18SMichał Górny #define R32(name) REG(name, 4)
22*e69a3d18SMichał Górny
GetRegisters_aarch64()23*e69a3d18SMichał Górny static std::vector<DynamicRegisterInfo::Register> GetRegisters_aarch64() {
24*e69a3d18SMichał Górny ConstString empty_alt_name;
25*e69a3d18SMichał Górny ConstString reg_set{"general purpose registers"};
26*e69a3d18SMichał Górny
27*e69a3d18SMichał Górny std::vector<DynamicRegisterInfo::Register> registers{
28*e69a3d18SMichał Górny R64(x0), R64(x1), R64(x2), R64(x3), R64(x4), R64(x5), R64(x6),
29*e69a3d18SMichał Górny R64(x7), R64(x8), R64(x9), R64(x10), R64(x11), R64(x12), R64(x13),
30*e69a3d18SMichał Górny R64(x14), R64(x15), R64(x16), R64(x17), R64(x18), R64(x19), R64(x20),
31*e69a3d18SMichał Górny R64(x21), R64(x22), R64(x23), R64(x24), R64(x25), R64(x26), R64(x27),
32*e69a3d18SMichał Górny R64(x28), R64(x29), R64(x30), R64(sp), R64(pc), R32(cpsr),
33*e69a3d18SMichał Górny };
34*e69a3d18SMichał Górny
35*e69a3d18SMichał Górny return registers;
36*e69a3d18SMichał Górny }
37*e69a3d18SMichał Górny
GetRegisters_x86()38*e69a3d18SMichał Górny static std::vector<DynamicRegisterInfo::Register> GetRegisters_x86() {
39*e69a3d18SMichał Górny ConstString empty_alt_name;
40*e69a3d18SMichał Górny ConstString reg_set{"general purpose registers"};
41*e69a3d18SMichał Górny
42*e69a3d18SMichał Górny std::vector<DynamicRegisterInfo::Register> registers{
43*e69a3d18SMichał Górny R32(eax), R32(ecx), R32(edx), R32(ebx), R32(esp), R32(ebp),
44*e69a3d18SMichał Górny R32(esi), R32(edi), R32(eip), R32(eflags), R32(cs), R32(ss),
45*e69a3d18SMichał Górny R32(ds), R32(es), R32(fs), R32(gs),
46*e69a3d18SMichał Górny };
47*e69a3d18SMichał Górny
48*e69a3d18SMichał Górny return registers;
49*e69a3d18SMichał Górny }
50*e69a3d18SMichał Górny
GetRegisters_x86_64()51*e69a3d18SMichał Górny static std::vector<DynamicRegisterInfo::Register> GetRegisters_x86_64() {
52*e69a3d18SMichał Górny ConstString empty_alt_name;
53*e69a3d18SMichał Górny ConstString reg_set{"general purpose registers"};
54*e69a3d18SMichał Górny
55*e69a3d18SMichał Górny std::vector<DynamicRegisterInfo::Register> registers{
56*e69a3d18SMichał Górny R64(rax), R64(rbx), R64(rcx), R64(rdx), R64(rsi), R64(rdi),
57*e69a3d18SMichał Górny R64(rbp), R64(rsp), R64(r8), R64(r9), R64(r10), R64(r11),
58*e69a3d18SMichał Górny R64(r12), R64(r13), R64(r14), R64(r15), R64(rip), R32(eflags),
59*e69a3d18SMichał Górny R32(cs), R32(ss), R32(ds), R32(es), R32(fs), R32(gs),
60*e69a3d18SMichał Górny };
61*e69a3d18SMichał Górny
62*e69a3d18SMichał Górny return registers;
63*e69a3d18SMichał Górny }
64*e69a3d18SMichał Górny
65*e69a3d18SMichał Górny #undef R32
66*e69a3d18SMichał Górny #undef R64
67*e69a3d18SMichał Górny #undef REG
68*e69a3d18SMichał Górny
69*e69a3d18SMichał Górny std::vector<DynamicRegisterInfo::Register>
GetFallbackRegisters(const ArchSpec & arch_to_use)70*e69a3d18SMichał Górny GetFallbackRegisters(const ArchSpec &arch_to_use) {
71*e69a3d18SMichał Górny switch (arch_to_use.GetMachine()) {
72*e69a3d18SMichał Górny case llvm::Triple::aarch64:
73*e69a3d18SMichał Górny return GetRegisters_aarch64();
74*e69a3d18SMichał Górny case llvm::Triple::x86:
75*e69a3d18SMichał Górny return GetRegisters_x86();
76*e69a3d18SMichał Górny case llvm::Triple::x86_64:
77*e69a3d18SMichał Górny return GetRegisters_x86_64();
78*e69a3d18SMichał Górny default:
79*e69a3d18SMichał Górny break;
80*e69a3d18SMichał Górny }
81*e69a3d18SMichał Górny
82*e69a3d18SMichał Górny return {};
83*e69a3d18SMichał Górny }
84*e69a3d18SMichał Górny
85*e69a3d18SMichał Górny } // namespace process_gdb_remote
86*e69a3d18SMichał Górny } // namespace lldb_private
87