1 //===-- RegisterContextLinux_arm64.cpp -------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===---------------------------------------------------------------------===//
9
10 #include <stddef.h>
11 #include <vector>
12 #include <cassert>
13
14 #include "llvm/Support/Compiler.h"
15 #include "lldb/lldb-defines.h"
16
17 #include "RegisterContextLinux_arm64.h"
18
19 // Based on RegisterContextDarwin_arm64.cpp
20 #define GPR_OFFSET(idx) ((idx) * 8)
21 #define GPR_OFFSET_NAME(reg) (LLVM_EXTENSION offsetof (RegisterContextLinux_arm64::GPR, reg))
22
23 #define FPU_OFFSET(idx) ((idx) * 16 + sizeof (RegisterContextLinux_arm64::GPR))
24 #define FPU_OFFSET_NAME(reg) (LLVM_EXTENSION offsetof (RegisterContextLinux_arm64::FPU, reg))
25
26 #define EXC_OFFSET_NAME(reg) (LLVM_EXTENSION offsetof (RegisterContextLinux_arm64::EXC, reg) + sizeof (RegisterContextLinux_arm64::GPR) + sizeof (RegisterContextLinux_arm64::FPU))
27 #define DBG_OFFSET_NAME(reg) (LLVM_EXTENSION offsetof (RegisterContextLinux_arm64::DBG, reg) + sizeof (RegisterContextLinux_arm64::GPR) + sizeof (RegisterContextLinux_arm64::FPU) + sizeof (RegisterContextLinux_arm64::EXC))
28
29 #define DEFINE_DBG(reg, i) #reg, NULL, sizeof(((RegisterContextLinux_arm64::DBG *)NULL)->reg[i]), DBG_OFFSET_NAME(reg[i]), lldb::eEncodingUint, lldb::eFormatHex, { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, dbg_##reg##i }, NULL, NULL
30 #define REG_CONTEXT_SIZE (sizeof (RegisterContextLinux_arm64::GPR) + sizeof (RegisterContextLinux_arm64::FPU) + sizeof (RegisterContextLinux_arm64::EXC))
31
32
33 //-----------------------------------------------------------------------------
34 // Include RegisterInfos_arm64 to declare our g_register_infos_arm64 structure.
35 //-----------------------------------------------------------------------------
36 #define DECLARE_REGISTER_INFOS_ARM64_STRUCT
37 #include "RegisterInfos_arm64.h"
38 #undef DECLARE_REGISTER_INFOS_ARM64_STRUCT
39
40 static const lldb_private::RegisterInfo *
GetRegisterInfoPtr(const lldb_private::ArchSpec & target_arch)41 GetRegisterInfoPtr (const lldb_private::ArchSpec &target_arch)
42 {
43 switch (target_arch.GetMachine())
44 {
45 case llvm::Triple::aarch64:
46 return g_register_infos_arm64;
47 default:
48 assert(false && "Unhandled target architecture.");
49 return NULL;
50 }
51 }
52
53 static uint32_t
GetRegisterInfoCount(const lldb_private::ArchSpec & target_arch)54 GetRegisterInfoCount(const lldb_private::ArchSpec &target_arch)
55 {
56 switch (target_arch.GetMachine())
57 {
58 case llvm::Triple::aarch64:
59 return static_cast<uint32_t>(sizeof(g_register_infos_arm64) / sizeof(g_register_infos_arm64[0]));
60 default:
61 assert(false && "Unhandled target architecture.");
62 return 0;
63 }
64 }
65
RegisterContextLinux_arm64(const lldb_private::ArchSpec & target_arch)66 RegisterContextLinux_arm64::RegisterContextLinux_arm64(const lldb_private::ArchSpec &target_arch) :
67 lldb_private::RegisterInfoInterface(target_arch),
68 m_register_info_p(GetRegisterInfoPtr(target_arch)),
69 m_register_info_count(GetRegisterInfoCount(target_arch))
70 {
71 }
72
73 size_t
GetGPRSize() const74 RegisterContextLinux_arm64::GetGPRSize() const
75 {
76 return sizeof(struct RegisterContextLinux_arm64::GPR);
77 }
78
79 const lldb_private::RegisterInfo *
GetRegisterInfo() const80 RegisterContextLinux_arm64::GetRegisterInfo() const
81 {
82 return m_register_info_p;
83 }
84
85 uint32_t
GetRegisterCount() const86 RegisterContextLinux_arm64::GetRegisterCount() const
87 {
88 return m_register_info_count;
89 }
90