LLDB  mainline
RegisterContextLinux_mips64.cpp
Go to the documentation of this file.
1 //===-- RegisterContextLinux_mips64.cpp ------------------------*- C++ -*-===//
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 
10 #include <stddef.h>
11 #include <vector>
12 
13 // For eh_frame and DWARF Register numbers
15 
16 // For GP and FP buffers
17 #include "RegisterContext_mips.h"
18 
19 // Internal codes for all mips32 and mips64 registers
21 
22 using namespace lldb;
23 using namespace lldb_private;
24 
25 // Include RegisterInfos_mips64 to declare our g_register_infos_mips64
26 // structure.
27 #define DECLARE_REGISTER_INFOS_MIPS64_STRUCT
28 #define LINUX_MIPS64
29 #include "RegisterInfos_mips64.h"
30 #undef LINUX_MIPS64
31 #undef DECLARE_REGISTER_INFOS_MIPS64_STRUCT
32 
33 // Include RegisterInfos_mips to declare our g_register_infos_mips structure.
34 #define DECLARE_REGISTER_INFOS_MIPS_STRUCT
35 #include "RegisterInfos_mips.h"
36 #undef DECLARE_REGISTER_INFOS_MIPS_STRUCT
37 
38 // mips64 general purpose registers.
53  LLDB_INVALID_REGNUM // register sets need to end with this flag
54 };
55 
56 static_assert((sizeof(g_gp_regnums_mips64) / sizeof(g_gp_regnums_mips64[0])) -
57  1 ==
59  "g_gp_regnums_mips64 has wrong number of register infos");
60 
61 // mips64 floating point registers.
72  LLDB_INVALID_REGNUM // register sets need to end with this flag
73 };
74 
75 static_assert((sizeof(g_fp_regnums_mips64) / sizeof(g_fp_regnums_mips64[0])) -
76  1 ==
78  "g_fp_regnums_mips64 has wrong number of register infos");
79 
80 // mips64 MSA registers.
92  LLDB_INVALID_REGNUM // register sets need to end with this flag
93 };
94 
95 static_assert((sizeof(g_msa_regnums_mips64) / sizeof(g_msa_regnums_mips64[0])) -
96  1 ==
98  "g_msa_regnums_mips64 has wrong number of register infos");
99 
100 // Number of register sets provided by this context.
101 constexpr size_t k_num_register_sets = 3;
102 
103 // Register sets for mips64.
104 static const RegisterSet g_reg_sets_mips64[k_num_register_sets] = {
105  {"General Purpose Registers", "gpr", k_num_gpr_registers_mips64,
106  g_gp_regnums_mips64},
107  {"Floating Point Registers", "fpu", k_num_fpr_registers_mips64,
108  g_fp_regnums_mips64},
109  {"MSA Registers", "msa", k_num_msa_registers_mips64, g_msa_regnums_mips64},
110 };
111 
112 const RegisterSet *
114  if (set >= k_num_register_sets)
115  return nullptr;
116 
117  switch (m_target_arch.GetMachine()) {
118  case llvm::Triple::mips64:
119  case llvm::Triple::mips64el:
120  return &g_reg_sets_mips64[set];
121  default:
122  assert(false && "Unhandled target architecture.");
123  return nullptr;
124  }
125  return nullptr;
126 }
127 
128 size_t
130  return k_num_register_sets;
131 }
132 
133 static const RegisterInfo *GetRegisterInfoPtr(const ArchSpec &target_arch) {
134  switch (target_arch.GetMachine()) {
135  case llvm::Triple::mips64:
136  case llvm::Triple::mips64el:
138  case llvm::Triple::mips:
139  case llvm::Triple::mipsel:
140  return g_register_infos_mips;
141  default:
142  assert(false && "Unhandled target architecture.");
143  return nullptr;
144  }
145 }
146 
147 static uint32_t GetRegisterInfoCount(const ArchSpec &target_arch) {
148  switch (target_arch.GetMachine()) {
149  case llvm::Triple::mips64:
150  case llvm::Triple::mips64el:
151  return static_cast<uint32_t>(sizeof(g_register_infos_mips64) /
152  sizeof(g_register_infos_mips64[0]));
153  case llvm::Triple::mips:
154  case llvm::Triple::mipsel:
155  return static_cast<uint32_t>(sizeof(g_register_infos_mips) /
156  sizeof(g_register_infos_mips[0]));
157  default:
158  assert(false && "Unhandled target architecture.");
159  return 0;
160  }
161 }
162 
164  bool msa_present) {
165  switch (target_arch.GetMachine()) {
166  case llvm::Triple::mips:
167  case llvm::Triple::mipsel:
168  if (msa_present)
169  return static_cast<uint32_t>(k_num_user_registers_mips);
170  return static_cast<uint32_t>(k_num_user_registers_mips -
172  case llvm::Triple::mips64el:
173  case llvm::Triple::mips64:
174  if (msa_present)
175  return static_cast<uint32_t>(k_num_user_registers_mips64);
176  return static_cast<uint32_t>(k_num_user_registers_mips64 -
178  default:
179  assert(false && "Unhandled target architecture.");
180  return 0;
181  }
182 }
183 
185  const ArchSpec &target_arch, bool msa_present)
186  : lldb_private::RegisterInfoInterface(target_arch),
187  m_register_info_p(GetRegisterInfoPtr(target_arch)),
188  m_register_info_count(GetRegisterInfoCount(target_arch)),
189  m_user_register_count(
190  GetUserRegisterInfoCount(target_arch, msa_present)) {}
191 
193  return sizeof(GPR_linux_mips);
194 }
195 
196 const RegisterInfo *RegisterContextLinux_mips64::GetRegisterInfo() const {
197  return m_register_info_p;
198 }
199 
201  return m_register_info_count;
202 }
203 
205  return m_user_register_count;
206 }
207 
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
const lldb_private::RegisterSet * GetRegisterSet(size_t set) const
RegisterInfo interface to patch RegisterInfo structure for archs.
An architecture specification class.
Definition: ArchSpec.h:32
const uint32_t g_msa_regnums_mips64[]
uint32_t GetUserRegisterInfoCount(const ArchSpec &target_arch, bool msa_present)
const lldb_private::RegisterInfo * GetRegisterInfo() const override
const uint32_t g_gp_regnums_mips64[]
RegisterContextLinux_mips64(const lldb_private::ArchSpec &target_arch, bool msa_present=true)
static const RegisterSet g_reg_sets_mips64[k_num_register_sets]
Definition: SBAddress.h:15
static const RegisterInfo g_register_infos_mips64[]
uint32_t GetRegisterCount() const override
const uint32_t g_fp_regnums_mips64[]
uint32_t GetUserRegisterCount() const override
static const RegisterInfo * GetRegisterInfoPtr(const ArchSpec &target_arch)
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:726
constexpr size_t k_num_register_sets
static uint32_t GetRegisterInfoCount(const ArchSpec &target_arch)
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90