1 //===-- RegisterContextPOSIXProcessMonitor_mips64.cpp -----------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #include "lldb/Target/Thread.h"
10 #include "lldb/Utility/DataBufferHeap.h"
11 #include "lldb/Utility/RegisterValue.h"
13 #include "Plugins/Process/Utility/RegisterContextPOSIX_mips64.h"
14 #include "ProcessFreeBSD.h"
15 #include "ProcessMonitor.h"
16 #include "RegisterContextPOSIXProcessMonitor_mips64.h"
18 using namespace lldb_private;
21 #define REG_CONTEXT_SIZE (GetGPRSize())
23 RegisterContextPOSIXProcessMonitor_mips64::
24 RegisterContextPOSIXProcessMonitor_mips64(
25 Thread &thread, uint32_t concrete_frame_idx,
26 lldb_private::RegisterInfoInterface *register_info)
27 : RegisterContextPOSIX_mips64(thread, concrete_frame_idx, register_info) {}
29 ProcessMonitor &RegisterContextPOSIXProcessMonitor_mips64::GetMonitor() {
30 ProcessSP base = CalculateProcess();
31 ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(base.get());
32 return process->GetMonitor();
35 bool RegisterContextPOSIXProcessMonitor_mips64::ReadGPR() {
36 ProcessMonitor &monitor = GetMonitor();
37 return monitor.ReadGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
40 bool RegisterContextPOSIXProcessMonitor_mips64::ReadFPR() {
41 // XXX not yet implemented
45 bool RegisterContextPOSIXProcessMonitor_mips64::WriteGPR() {
46 ProcessMonitor &monitor = GetMonitor();
47 return monitor.WriteGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
50 bool RegisterContextPOSIXProcessMonitor_mips64::WriteFPR() {
51 // XXX not yet implemented
55 bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
56 const unsigned reg, RegisterValue &value) {
57 ProcessMonitor &monitor = GetMonitor();
58 return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg),
59 GetRegisterName(reg), GetRegisterSize(reg),
63 bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
64 const unsigned reg, const RegisterValue &value) {
65 unsigned reg_to_write = reg;
66 RegisterValue value_to_write = value;
68 // Check if this is a subregister of a full register.
69 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
70 if (reg_info->invalidate_regs &&
71 (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
72 RegisterValue full_value;
73 uint32_t full_reg = reg_info->invalidate_regs[0];
74 const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
76 // Read the full register.
77 if (ReadRegister(full_reg_info, full_value)) {
79 ByteOrder byte_order = GetByteOrder();
80 uint8_t dst[RegisterValue::kMaxRegisterByteSize];
82 // Get the bytes for the full register.
83 const uint32_t dest_size = full_value.GetAsMemoryData(
84 full_reg_info, dst, sizeof(dst), byte_order, error);
85 if (error.Success() && dest_size) {
86 uint8_t src[RegisterValue::kMaxRegisterByteSize];
88 // Get the bytes for the source data.
89 const uint32_t src_size = value.GetAsMemoryData(
90 reg_info, src, sizeof(src), byte_order, error);
91 if (error.Success() && src_size && (src_size < dest_size)) {
92 // Copy the src bytes to the destination.
93 memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
94 // Set this full register as the value to write.
95 value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
96 value_to_write.SetType(full_reg_info);
97 reg_to_write = full_reg;
103 ProcessMonitor &monitor = GetMonitor();
104 return monitor.WriteRegisterValue(
105 m_thread.GetID(), GetRegisterOffset(reg_to_write),
106 GetRegisterName(reg_to_write), value_to_write);
109 bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
110 const RegisterInfo *reg_info, RegisterValue &value) {
114 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
120 uint32_t full_reg = reg;
121 bool is_subreg = reg_info->invalidate_regs &&
122 (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
125 // Read the full aligned 64-bit register.
126 full_reg = reg_info->invalidate_regs[0];
129 bool success = ReadRegister(full_reg, value);
132 // If our read was not aligned (for ah,bh,ch,dh), shift our returned
133 // value one byte to the right.
134 if (is_subreg && (reg_info->byte_offset & 0x1))
135 value.SetUInt64(value.GetAsUInt64() >> 8);
137 // If our return byte size was greater than the return value reg size,
138 // then use the type specified by reg_info rather than the uint64_t
140 if (value.GetByteSize() > reg_info->byte_size)
141 value.SetType(reg_info);
149 bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
150 const RegisterInfo *reg_info, const RegisterValue &value) {
151 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
154 return WriteRegister(reg, value);
159 bool RegisterContextPOSIXProcessMonitor_mips64::ReadAllRegisterValues(
160 DataBufferSP &data_sp) {
161 bool success = false;
162 data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
163 if (ReadGPR() && ReadFPR()) {
164 uint8_t *dst = data_sp->GetBytes();
168 ::memcpy(dst, &m_gpr_mips64, GetGPRSize());
174 bool RegisterContextPOSIXProcessMonitor_mips64::WriteAllRegisterValues(
175 const DataBufferSP &data_sp) {
176 bool success = false;
177 if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) {
178 uint8_t *src = data_sp->GetBytes();
180 ::memcpy(&m_gpr_mips64, src, GetGPRSize());
190 uint32_t RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpoint(
191 addr_t addr, size_t size, bool read, bool write) {
192 const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
195 for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index) {
196 if (IsWatchpointVacant(hw_index))
197 return SetHardwareWatchpointWithIndex(addr, size, read, write, hw_index);
200 return LLDB_INVALID_INDEX32;
203 bool RegisterContextPOSIXProcessMonitor_mips64::ClearHardwareWatchpoint(
208 bool RegisterContextPOSIXProcessMonitor_mips64::HardwareSingleStep(
213 bool RegisterContextPOSIXProcessMonitor_mips64::UpdateAfterBreakpoint() {
214 // PC points one byte past the int3 responsible for the breakpoint.
217 if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
224 unsigned RegisterContextPOSIXProcessMonitor_mips64::GetRegisterIndexFromOffset(
227 for (reg = 0; reg < k_num_registers_mips64; reg++) {
228 if (GetRegisterInfo()[reg].byte_offset == offset)
231 assert(reg < k_num_registers_mips64 && "Invalid register offset.");
235 bool RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointHit(
240 bool RegisterContextPOSIXProcessMonitor_mips64::ClearWatchpointHits() {
244 addr_t RegisterContextPOSIXProcessMonitor_mips64::GetWatchpointAddress(
246 return LLDB_INVALID_ADDRESS;
249 bool RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointVacant(
254 bool RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpointWithIndex(
255 addr_t addr, size_t size, bool read, bool write, uint32_t hw_index) {
260 RegisterContextPOSIXProcessMonitor_mips64::NumSupportedHardwareWatchpoints() {