LLDB  mainline
RegisterInfoPOSIX_loongarch64.cpp
Go to the documentation of this file.
1 //===-- RegisterInfoPOSIX_loongarch64.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 <cassert>
10 #include <lldb/Utility/Flags.h>
11 #include <stddef.h>
12 
13 #include "lldb/lldb-defines.h"
14 #include "llvm/Support/Compiler.h"
15 
17 
18 #define GPR_OFFSET(idx) ((idx)*8 + 0)
19 #define FPR_OFFSET(idx) ((idx)*8 + sizeof(RegisterInfoPOSIX_loongarch64::GPR))
20 #define FCC_OFFSET(idx) ((idx)*1 + 32 * 8 + sizeof(RegisterInfoPOSIX_loongarch64::GPR))
21 #define FCSR_OFFSET (8 * 1 + 32 * 8 + sizeof(RegisterInfoPOSIX_loongarch64::GPR))
22 
23 #define REG_CONTEXT_SIZE \
24  (sizeof(RegisterInfoPOSIX_loongarch64::GPR) + \
25  sizeof(RegisterInfoPOSIX_loongarch64::FPR))
26 
27 #define DECLARE_REGISTER_INFOS_LOONGARCH64_STRUCT
29 #undef DECLARE_REGISTER_INFOS_LOONGARCH64_STRUCT
30 
31 const lldb_private::RegisterInfo *
33  const lldb_private::ArchSpec &target_arch) {
34  switch (target_arch.GetMachine()) {
35  case llvm::Triple::loongarch64:
36  return g_register_infos_loongarch64;
37  default:
38  assert(false && "Unhandled target architecture.");
39  return nullptr;
40  }
41 }
42 
44  const lldb_private::ArchSpec &target_arch) {
45  switch (target_arch.GetMachine()) {
46  case llvm::Triple::loongarch64:
47  return static_cast<uint32_t>(sizeof(g_register_infos_loongarch64) /
48  sizeof(g_register_infos_loongarch64[0]));
49  default:
50  assert(false && "Unhandled target architecture.");
51  return 0;
52  }
53 }
54 
55 // Number of register sets provided by this context.
56 enum {
60 };
61 
62 // LoongArch64 general purpose registers.
80 
81 static_assert(((sizeof g_gpr_regnums_loongarch64 /
82  sizeof g_gpr_regnums_loongarch64[0]) -
83  1) == k_num_gpr_registers,
84  "g_gpr_regnums_loongarch64 has wrong number of register infos");
85 
86 // LoongArch64 floating point registers.
102 
103 static_assert(((sizeof g_fpr_regnums_loongarch64 /
104  sizeof g_fpr_regnums_loongarch64[0]) -
105  1) == k_num_fpr_registers,
106  "g_fpr_regnums_loongarch64 has wrong number of register infos");
107 
108 // Register sets for LoongArch64.
109 static const lldb_private::RegisterSet
111  {"General Purpose Registers", "gpr", k_num_gpr_registers,
113  {"Floating Point Registers", "fpr", k_num_fpr_registers,
115 
117  const lldb_private::ArchSpec &target_arch, lldb_private::Flags flags)
118  : lldb_private::RegisterInfoAndSetInterface(target_arch),
119  m_register_info_p(GetRegisterInfoPtr(target_arch)),
120  m_register_info_count(GetRegisterInfoCount(target_arch)) {}
121 
123  return m_register_info_count;
124 }
125 
127  return sizeof(struct RegisterInfoPOSIX_loongarch64::GPR);
128 }
129 
131  return sizeof(struct RegisterInfoPOSIX_loongarch64::FPR);
132 }
133 
134 const lldb_private::RegisterInfo *
136  return m_register_info_p;
137 }
138 
140  return k_num_register_sets;
141 }
142 
144  uint32_t reg_index) const {
145  // coverity[unsigned_compare]
146  if (reg_index >= gpr_first_loongarch && reg_index <= gpr_last_loongarch)
147  return GPRegSet;
148  if (reg_index >= fpr_first_loongarch && reg_index <= fpr_last_loongarch)
149  return FPRegSet;
150  return LLDB_INVALID_REGNUM;
151 }
152 
153 const lldb_private::RegisterSet *
155  if (set_index < GetRegisterSetCount())
156  return &g_reg_sets_loongarch64[set_index];
157  return nullptr;
158 }
gpr_r6_loongarch
@ gpr_r6_loongarch
Definition: lldb-loongarch-register-enums.h:25
gpr_badv_loongarch
@ gpr_badv_loongarch
Definition: lldb-loongarch-register-enums.h:53
fpr_f25_loongarch
@ fpr_f25_loongarch
Definition: lldb-loongarch-register-enums.h:124
g_gpr_regnums_loongarch64
static const uint32_t g_gpr_regnums_loongarch64[]
Definition: RegisterInfoPOSIX_loongarch64.cpp:63
gpr_r23_loongarch
@ gpr_r23_loongarch
Definition: lldb-loongarch-register-enums.h:42
RegisterInfoPOSIX_loongarch64::GetRegisterSet
const lldb_private::RegisterSet * GetRegisterSet(size_t reg_set) const override
Definition: RegisterInfoPOSIX_loongarch64.cpp:154
RegisterInfoPOSIX_loongarch64::GetRegisterInfo
const lldb_private::RegisterInfo * GetRegisterInfo() const override
Definition: RegisterInfoPOSIX_loongarch64.cpp:135
fpr_f31_loongarch
@ fpr_f31_loongarch
Definition: lldb-loongarch-register-enums.h:130
fpr_fcc6_loongarch
@ fpr_fcc6_loongarch
Definition: lldb-loongarch-register-enums.h:137
gpr_r9_loongarch
@ gpr_r9_loongarch
Definition: lldb-loongarch-register-enums.h:28
lldb_private::ArchSpec
Definition: ArchSpec.h:32
gpr_r16_loongarch
@ gpr_r16_loongarch
Definition: lldb-loongarch-register-enums.h:35
RegisterInfoPOSIX_loongarch64::GetRegisterInfoCount
static uint32_t GetRegisterInfoCount(const lldb_private::ArchSpec &target_arch)
Definition: RegisterInfoPOSIX_loongarch64.cpp:43
LLDB_INVALID_REGNUM
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:79
gpr_pc_loongarch
@ gpr_pc_loongarch
Definition: lldb-loongarch-register-enums.h:52
fpr_f19_loongarch
@ fpr_f19_loongarch
Definition: lldb-loongarch-register-enums.h:118
fpr_f4_loongarch
@ fpr_f4_loongarch
Definition: lldb-loongarch-register-enums.h:103
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:678
gpr_r14_loongarch
@ gpr_r14_loongarch
Definition: lldb-loongarch-register-enums.h:33
gpr_r1_loongarch
@ gpr_r1_loongarch
Definition: lldb-loongarch-register-enums.h:20
fpr_f18_loongarch
@ fpr_f18_loongarch
Definition: lldb-loongarch-register-enums.h:117
fpr_f2_loongarch
@ fpr_f2_loongarch
Definition: lldb-loongarch-register-enums.h:101
lldb-defines.h
gpr_r28_loongarch
@ gpr_r28_loongarch
Definition: lldb-loongarch-register-enums.h:47
gpr_r21_loongarch
@ gpr_r21_loongarch
Definition: lldb-loongarch-register-enums.h:40
fpr_f9_loongarch
@ fpr_f9_loongarch
Definition: lldb-loongarch-register-enums.h:108
fpr_f12_loongarch
@ fpr_f12_loongarch
Definition: lldb-loongarch-register-enums.h:111
fpr_f14_loongarch
@ fpr_f14_loongarch
Definition: lldb-loongarch-register-enums.h:113
gpr_reserved1_loongarch
@ gpr_reserved1_loongarch
Definition: lldb-loongarch-register-enums.h:55
RegisterInfoPOSIX_loongarch64::GetRegisterCount
uint32_t GetRegisterCount() const override
Definition: RegisterInfoPOSIX_loongarch64.cpp:122
RegisterInfoPOSIX_loongarch64::GetRegisterSetCount
size_t GetRegisterSetCount() const override
Definition: RegisterInfoPOSIX_loongarch64.cpp:139
lldb_private::Flags
Definition: Flags.h:22
fpr_f24_loongarch
@ fpr_f24_loongarch
Definition: lldb-loongarch-register-enums.h:123
RegisterInfoPOSIX_loongarch64::RegisterInfoPOSIX_loongarch64
RegisterInfoPOSIX_loongarch64(const lldb_private::ArchSpec &target_arch, lldb_private::Flags flags)
Definition: RegisterInfoPOSIX_loongarch64.cpp:116
GetRegisterInfoCount
static uint32_t GetRegisterInfoCount(const ArchSpec &target_arch)
Definition: RegisterContextLinux_s390x.cpp:30
gpr_r27_loongarch
@ gpr_r27_loongarch
Definition: lldb-loongarch-register-enums.h:46
fpr_f21_loongarch
@ fpr_f21_loongarch
Definition: lldb-loongarch-register-enums.h:120
gpr_reserved9_loongarch
@ gpr_reserved9_loongarch
Definition: lldb-loongarch-register-enums.h:63
fpr_f0_loongarch
@ fpr_f0_loongarch
Definition: lldb-loongarch-register-enums.h:99
gpr_r11_loongarch
@ gpr_r11_loongarch
Definition: lldb-loongarch-register-enums.h:30
fpr_first_loongarch
@ fpr_first_loongarch
Definition: lldb-loongarch-register-enums.h:98
fpr_f11_loongarch
@ fpr_f11_loongarch
Definition: lldb-loongarch-register-enums.h:110
fpr_f3_loongarch
@ fpr_f3_loongarch
Definition: lldb-loongarch-register-enums.h:102
gpr_r26_loongarch
@ gpr_r26_loongarch
Definition: lldb-loongarch-register-enums.h:45
fpr_f7_loongarch
@ fpr_f7_loongarch
Definition: lldb-loongarch-register-enums.h:106
RegisterInfoPOSIX_loongarch64::FPRegSet
@ FPRegSet
Definition: RegisterInfoPOSIX_loongarch64.h:28
gpr_r18_loongarch
@ gpr_r18_loongarch
Definition: lldb-loongarch-register-enums.h:37
gpr_orig_a0_loongarch
@ gpr_orig_a0_loongarch
Definition: lldb-loongarch-register-enums.h:51
gpr_r19_loongarch
@ gpr_r19_loongarch
Definition: lldb-loongarch-register-enums.h:38
gpr_r8_loongarch
@ gpr_r8_loongarch
Definition: lldb-loongarch-register-enums.h:27
fpr_f8_loongarch
@ fpr_f8_loongarch
Definition: lldb-loongarch-register-enums.h:107
RegisterInfoPOSIX_loongarch64::GetGPRSize
size_t GetGPRSize() const override
Definition: RegisterInfoPOSIX_loongarch64.cpp:126
fpr_f16_loongarch
@ fpr_f16_loongarch
Definition: lldb-loongarch-register-enums.h:115
gpr_r10_loongarch
@ gpr_r10_loongarch
Definition: lldb-loongarch-register-enums.h:29
gpr_reserved0_loongarch
@ gpr_reserved0_loongarch
Definition: lldb-loongarch-register-enums.h:54
fpr_f28_loongarch
@ fpr_f28_loongarch
Definition: lldb-loongarch-register-enums.h:127
fpr_f20_loongarch
@ fpr_f20_loongarch
Definition: lldb-loongarch-register-enums.h:119
fpr_f29_loongarch
@ fpr_f29_loongarch
Definition: lldb-loongarch-register-enums.h:128
fpr_fcc2_loongarch
@ fpr_fcc2_loongarch
Definition: lldb-loongarch-register-enums.h:133
gpr_r3_loongarch
@ gpr_r3_loongarch
Definition: lldb-loongarch-register-enums.h:22
gpr_r0_loongarch
@ gpr_r0_loongarch
Definition: lldb-loongarch-register-enums.h:19
fpr_f13_loongarch
@ fpr_f13_loongarch
Definition: lldb-loongarch-register-enums.h:112
RegisterInfoPOSIX_loongarch64::m_register_info_p
const lldb_private::RegisterInfo * m_register_info_p
Definition: RegisterInfoPOSIX_loongarch64.h:65
gpr_r20_loongarch
@ gpr_r20_loongarch
Definition: lldb-loongarch-register-enums.h:39
fpr_fcc1_loongarch
@ fpr_fcc1_loongarch
Definition: lldb-loongarch-register-enums.h:132
gpr_r29_loongarch
@ gpr_r29_loongarch
Definition: lldb-loongarch-register-enums.h:48
gpr_reserved5_loongarch
@ gpr_reserved5_loongarch
Definition: lldb-loongarch-register-enums.h:59
gpr_r15_loongarch
@ gpr_r15_loongarch
Definition: lldb-loongarch-register-enums.h:34
fpr_fcc7_loongarch
@ fpr_fcc7_loongarch
Definition: lldb-loongarch-register-enums.h:138
fpr_f15_loongarch
@ fpr_f15_loongarch
Definition: lldb-loongarch-register-enums.h:114
gpr_r17_loongarch
@ gpr_r17_loongarch
Definition: lldb-loongarch-register-enums.h:36
gpr_reserved4_loongarch
@ gpr_reserved4_loongarch
Definition: lldb-loongarch-register-enums.h:58
k_num_register_sets
@ k_num_register_sets
Definition: RegisterInfoPOSIX_loongarch64.cpp:59
gpr_reserved2_loongarch
@ gpr_reserved2_loongarch
Definition: lldb-loongarch-register-enums.h:56
RegisterInfoPOSIX_loongarch64::m_register_info_count
uint32_t m_register_info_count
Definition: RegisterInfoPOSIX_loongarch64.h:66
RegisterInfoPOSIX_loongarch64::GetFPRSize
size_t GetFPRSize() const override
Definition: RegisterInfoPOSIX_loongarch64.cpp:130
g_reg_sets_loongarch64
static const lldb_private::RegisterSet g_reg_sets_loongarch64[k_num_register_sets]
Definition: RegisterInfoPOSIX_loongarch64.cpp:110
gpr_r25_loongarch
@ gpr_r25_loongarch
Definition: lldb-loongarch-register-enums.h:44
fpr_f26_loongarch
@ fpr_f26_loongarch
Definition: lldb-loongarch-register-enums.h:125
gpr_r2_loongarch
@ gpr_r2_loongarch
Definition: lldb-loongarch-register-enums.h:21
gpr_r31_loongarch
@ gpr_r31_loongarch
Definition: lldb-loongarch-register-enums.h:50
fpr_fcc5_loongarch
@ fpr_fcc5_loongarch
Definition: lldb-loongarch-register-enums.h:136
RegisterInfoPOSIX_loongarch64::FPR
Definition: RegisterInfoPOSIX_loongarch64.h:40
uint32_t
RegisterInfoPOSIX_loongarch64::GPR
Definition: RegisterInfoPOSIX_loongarch64.h:31
gpr_r7_loongarch
@ gpr_r7_loongarch
Definition: lldb-loongarch-register-enums.h:26
fpr_f27_loongarch
@ fpr_f27_loongarch
Definition: lldb-loongarch-register-enums.h:126
gpr_last_loongarch
@ gpr_last_loongarch
Definition: lldb-loongarch-register-enums.h:64
gpr_reserved8_loongarch
@ gpr_reserved8_loongarch
Definition: lldb-loongarch-register-enums.h:62
fpr_f10_loongarch
@ fpr_f10_loongarch
Definition: lldb-loongarch-register-enums.h:109
fpr_f22_loongarch
@ fpr_f22_loongarch
Definition: lldb-loongarch-register-enums.h:121
fpr_f6_loongarch
@ fpr_f6_loongarch
Definition: lldb-loongarch-register-enums.h:105
gpr_r22_loongarch
@ gpr_r22_loongarch
Definition: lldb-loongarch-register-enums.h:41
fpr_fcsr_loongarch
@ fpr_fcsr_loongarch
Definition: lldb-loongarch-register-enums.h:139
k_num_fpr_registers
@ k_num_fpr_registers
Definition: RegisterInfoPOSIX_loongarch64.cpp:58
gpr_r24_loongarch
@ gpr_r24_loongarch
Definition: lldb-loongarch-register-enums.h:43
fpr_fcc4_loongarch
@ fpr_fcc4_loongarch
Definition: lldb-loongarch-register-enums.h:135
g_fpr_regnums_loongarch64
static const uint32_t g_fpr_regnums_loongarch64[]
Definition: RegisterInfoPOSIX_loongarch64.cpp:87
fpr_f30_loongarch
@ fpr_f30_loongarch
Definition: lldb-loongarch-register-enums.h:129
k_num_gpr_registers
@ k_num_gpr_registers
Definition: RegisterInfoPOSIX_loongarch64.cpp:57
gpr_r5_loongarch
@ gpr_r5_loongarch
Definition: lldb-loongarch-register-enums.h:24
gpr_r12_loongarch
@ gpr_r12_loongarch
Definition: lldb-loongarch-register-enums.h:31
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
gpr_reserved3_loongarch
@ gpr_reserved3_loongarch
Definition: lldb-loongarch-register-enums.h:57
fpr_last_loongarch
@ fpr_last_loongarch
Definition: lldb-loongarch-register-enums.h:140
gpr_reserved7_loongarch
@ gpr_reserved7_loongarch
Definition: lldb-loongarch-register-enums.h:61
RegisterInfoPOSIX_loongarch64.h
gpr_r13_loongarch
@ gpr_r13_loongarch
Definition: lldb-loongarch-register-enums.h:32
gpr_first_loongarch
@ gpr_first_loongarch
Definition: lldb-loongarch-register-enums.h:18
fpr_f1_loongarch
@ fpr_f1_loongarch
Definition: lldb-loongarch-register-enums.h:100
Flags.h
RegisterInfos_loongarch64.h
RegisterInfoPOSIX_loongarch64::GetRegisterInfoPtr
static const lldb_private::RegisterInfo * GetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch)
Definition: RegisterInfoPOSIX_loongarch64.cpp:32
RegisterInfoPOSIX_loongarch64::GPRegSet
@ GPRegSet
Definition: RegisterInfoPOSIX_loongarch64.h:27
fpr_fcc0_loongarch
@ fpr_fcc0_loongarch
Definition: lldb-loongarch-register-enums.h:131
gpr_r4_loongarch
@ gpr_r4_loongarch
Definition: lldb-loongarch-register-enums.h:23
fpr_f5_loongarch
@ fpr_f5_loongarch
Definition: lldb-loongarch-register-enums.h:104
fpr_f17_loongarch
@ fpr_f17_loongarch
Definition: lldb-loongarch-register-enums.h:116
gpr_reserved6_loongarch
@ gpr_reserved6_loongarch
Definition: lldb-loongarch-register-enums.h:60
RegisterInfoPOSIX_loongarch64::GetRegisterSetFromRegisterIndex
size_t GetRegisterSetFromRegisterIndex(uint32_t reg_index) const override
Definition: RegisterInfoPOSIX_loongarch64.cpp:143
fpr_f23_loongarch
@ fpr_f23_loongarch
Definition: lldb-loongarch-register-enums.h:122
gpr_r30_loongarch
@ gpr_r30_loongarch
Definition: lldb-loongarch-register-enums.h:49
fpr_fcc3_loongarch
@ fpr_fcc3_loongarch
Definition: lldb-loongarch-register-enums.h:134
GetRegisterInfoPtr
static const RegisterInfo * GetRegisterInfoPtr(const ArchSpec &target_arch)
Definition: RegisterContextLinux_s390x.cpp:20