1 //===-- RegisterContextPOSIX_powerpc.cpp ----------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 #include "lldb/Target/Process.h"
14 #include "lldb/Target/Target.h"
15 #include "lldb/Target/Thread.h"
16 #include "lldb/Utility/DataBufferHeap.h"
17 #include "lldb/Utility/DataExtractor.h"
18 #include "lldb/Utility/Endian.h"
19 #include "lldb/Utility/RegisterValue.h"
20 #include "lldb/Utility/Scalar.h"
21 #include "llvm/Support/Compiler.h"
23 #include "RegisterContextPOSIX_powerpc.h"
25 using namespace lldb_private
;
28 static const uint32_t g_gpr_regnums
[] = {
29 gpr_r0_powerpc
, gpr_r1_powerpc
, gpr_r2_powerpc
, gpr_r3_powerpc
,
30 gpr_r4_powerpc
, gpr_r5_powerpc
, gpr_r6_powerpc
, gpr_r7_powerpc
,
31 gpr_r8_powerpc
, gpr_r9_powerpc
, gpr_r10_powerpc
, gpr_r11_powerpc
,
32 gpr_r12_powerpc
, gpr_r13_powerpc
, gpr_r14_powerpc
, gpr_r15_powerpc
,
33 gpr_r16_powerpc
, gpr_r17_powerpc
, gpr_r18_powerpc
, gpr_r19_powerpc
,
34 gpr_r20_powerpc
, gpr_r21_powerpc
, gpr_r22_powerpc
, gpr_r23_powerpc
,
35 gpr_r24_powerpc
, gpr_r25_powerpc
, gpr_r26_powerpc
, gpr_r27_powerpc
,
36 gpr_r28_powerpc
, gpr_r29_powerpc
, gpr_r30_powerpc
, gpr_r31_powerpc
,
37 gpr_lr_powerpc
, gpr_cr_powerpc
, gpr_xer_powerpc
, gpr_ctr_powerpc
,
41 static const uint32_t g_fpr_regnums
[] = {
42 fpr_f0_powerpc
, fpr_f1_powerpc
, fpr_f2_powerpc
, fpr_f3_powerpc
,
43 fpr_f4_powerpc
, fpr_f5_powerpc
, fpr_f6_powerpc
, fpr_f7_powerpc
,
44 fpr_f8_powerpc
, fpr_f9_powerpc
, fpr_f10_powerpc
, fpr_f11_powerpc
,
45 fpr_f12_powerpc
, fpr_f13_powerpc
, fpr_f14_powerpc
, fpr_f15_powerpc
,
46 fpr_f16_powerpc
, fpr_f17_powerpc
, fpr_f18_powerpc
, fpr_f19_powerpc
,
47 fpr_f20_powerpc
, fpr_f21_powerpc
, fpr_f22_powerpc
, fpr_f23_powerpc
,
48 fpr_f24_powerpc
, fpr_f25_powerpc
, fpr_f26_powerpc
, fpr_f27_powerpc
,
49 fpr_f28_powerpc
, fpr_f29_powerpc
, fpr_f30_powerpc
, fpr_f31_powerpc
,
53 static const uint32_t g_vmx_regnums
[] = {
54 vmx_v0_powerpc
, vmx_v1_powerpc
, vmx_v2_powerpc
, vmx_v3_powerpc
,
55 vmx_v4_powerpc
, vmx_v5_powerpc
, vmx_v6_powerpc
, vmx_v7_powerpc
,
56 vmx_v8_powerpc
, vmx_v9_powerpc
, vmx_v10_powerpc
, vmx_v11_powerpc
,
57 vmx_v12_powerpc
, vmx_v13_powerpc
, vmx_v14_powerpc
, vmx_v15_powerpc
,
58 vmx_v16_powerpc
, vmx_v17_powerpc
, vmx_v18_powerpc
, vmx_v19_powerpc
,
59 vmx_v20_powerpc
, vmx_v21_powerpc
, vmx_v22_powerpc
, vmx_v23_powerpc
,
60 vmx_v24_powerpc
, vmx_v25_powerpc
, vmx_v26_powerpc
, vmx_v27_powerpc
,
61 vmx_v28_powerpc
, vmx_v29_powerpc
, vmx_v30_powerpc
, vmx_v31_powerpc
,
62 vmx_vrsave_powerpc
, vmx_vscr_powerpc
,
65 // Number of register sets provided by this context.
66 enum { k_num_register_sets
= 3 };
68 static const RegisterSet g_reg_sets_powerpc
[k_num_register_sets
] = {
69 {"General Purpose Registers", "gpr", k_num_gpr_registers_powerpc
,
71 {"Floating Point Registers", "fpr", k_num_fpr_registers_powerpc
,
73 {"Altivec/VMX Registers", "vmx", k_num_vmx_registers_powerpc
,
77 static_assert(k_first_gpr_powerpc
== 0,
78 "GPRs must index starting at 0, or fix IsGPR()");
79 bool RegisterContextPOSIX_powerpc::IsGPR(unsigned reg
) {
80 return (reg
<= k_last_gpr_powerpc
); // GPR's come first.
83 bool RegisterContextPOSIX_powerpc::IsFPR(unsigned reg
) {
84 return (reg
>= k_first_fpr
) && (reg
<= k_last_fpr
);
87 bool RegisterContextPOSIX_powerpc::IsVMX(unsigned reg
) {
88 return (reg
>= k_first_vmx
) && (reg
<= k_last_vmx
);
91 RegisterContextPOSIX_powerpc::RegisterContextPOSIX_powerpc(
92 Thread
&thread
, uint32_t concrete_frame_idx
,
93 RegisterInfoInterface
*register_info
)
94 : RegisterContext(thread
, concrete_frame_idx
) {
95 m_register_info_up
.reset(register_info
);
98 RegisterContextPOSIX_powerpc::~RegisterContextPOSIX_powerpc() = default;
100 void RegisterContextPOSIX_powerpc::Invalidate() {}
102 void RegisterContextPOSIX_powerpc::InvalidateAllRegisters() {}
104 unsigned RegisterContextPOSIX_powerpc::GetRegisterOffset(unsigned reg
) {
105 assert(reg
< k_num_registers_powerpc
&& "Invalid register number.");
106 return GetRegisterInfo()[reg
].byte_offset
;
109 unsigned RegisterContextPOSIX_powerpc::GetRegisterSize(unsigned reg
) {
110 assert(reg
< k_num_registers_powerpc
&& "Invalid register number.");
111 return GetRegisterInfo()[reg
].byte_size
;
114 size_t RegisterContextPOSIX_powerpc::GetRegisterCount() {
115 size_t num_registers
= k_num_registers_powerpc
;
116 return num_registers
;
119 size_t RegisterContextPOSIX_powerpc::GetGPRSize() {
120 return m_register_info_up
->GetGPRSize();
123 const RegisterInfo
*RegisterContextPOSIX_powerpc::GetRegisterInfo() {
124 // Commonly, this method is overridden and g_register_infos is copied and
125 // specialized. So, use GetRegisterInfo() rather than g_register_infos in
127 return m_register_info_up
->GetRegisterInfo();
131 RegisterContextPOSIX_powerpc::GetRegisterInfoAtIndex(size_t reg
) {
132 if (reg
< k_num_registers_powerpc
)
133 return &GetRegisterInfo()[reg
];
138 size_t RegisterContextPOSIX_powerpc::GetRegisterSetCount() {
140 for (size_t set
= 0; set
< k_num_register_sets
; ++set
) {
141 if (IsRegisterSetAvailable(set
))
148 const RegisterSet
*RegisterContextPOSIX_powerpc::GetRegisterSet(size_t set
) {
149 if (IsRegisterSetAvailable(set
))
150 return &g_reg_sets_powerpc
[set
];
155 const char *RegisterContextPOSIX_powerpc::GetRegisterName(unsigned reg
) {
156 assert(reg
< k_num_registers_powerpc
&& "Invalid register offset.");
157 return GetRegisterInfo()[reg
].name
;
160 bool RegisterContextPOSIX_powerpc::IsRegisterSetAvailable(size_t set_index
) {
161 size_t num_sets
= k_num_register_sets
;
163 return (set_index
< num_sets
);