1 //===-- RegisterContextPOSIXProcessMonitor_mips64.cpp -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Target/Thread.h"
11 #include "lldb/Utility/DataBufferHeap.h"
12 #include "lldb/Utility/RegisterValue.h"
14 #include "Plugins/Process/Utility/RegisterContextPOSIX_mips64.h"
15 #include "ProcessFreeBSD.h"
16 #include "ProcessMonitor.h"
17 #include "RegisterContextPOSIXProcessMonitor_mips64.h"
19 using namespace lldb_private;
22 #define REG_CONTEXT_SIZE (GetGPRSize())
24 RegisterContextPOSIXProcessMonitor_mips64::
25 RegisterContextPOSIXProcessMonitor_mips64(
26 Thread &thread, uint32_t concrete_frame_idx,
27 lldb_private::RegisterInfoInterface *register_info)
28 : RegisterContextPOSIX_mips64(thread, concrete_frame_idx, register_info) {}
30 ProcessMonitor &RegisterContextPOSIXProcessMonitor_mips64::GetMonitor() {
31 ProcessSP base = CalculateProcess();
32 ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(base.get());
33 return process->GetMonitor();
36 bool RegisterContextPOSIXProcessMonitor_mips64::ReadGPR() {
37 ProcessMonitor &monitor = GetMonitor();
38 return monitor.ReadGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
41 bool RegisterContextPOSIXProcessMonitor_mips64::ReadFPR() {
42 // XXX not yet implemented
46 bool RegisterContextPOSIXProcessMonitor_mips64::WriteGPR() {
47 ProcessMonitor &monitor = GetMonitor();
48 return monitor.WriteGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
51 bool RegisterContextPOSIXProcessMonitor_mips64::WriteFPR() {
52 // XXX not yet implemented
56 bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
57 const unsigned reg, RegisterValue &value) {
58 ProcessMonitor &monitor = GetMonitor();
59 return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg),
60 GetRegisterName(reg), GetRegisterSize(reg),
64 bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
65 const unsigned reg, const RegisterValue &value) {
66 unsigned reg_to_write = reg;
67 RegisterValue value_to_write = value;
69 // Check if this is a subregister of a full register.
70 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
71 if (reg_info->invalidate_regs &&
72 (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
73 RegisterValue full_value;
74 uint32_t full_reg = reg_info->invalidate_regs[0];
75 const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
77 // Read the full register.
78 if (ReadRegister(full_reg_info, full_value)) {
80 ByteOrder byte_order = GetByteOrder();
81 uint8_t dst[RegisterValue::kMaxRegisterByteSize];
83 // Get the bytes for the full register.
84 const uint32_t dest_size = full_value.GetAsMemoryData(
85 full_reg_info, dst, sizeof(dst), byte_order, error);
86 if (error.Success() && dest_size) {
87 uint8_t src[RegisterValue::kMaxRegisterByteSize];
89 // Get the bytes for the source data.
90 const uint32_t src_size = value.GetAsMemoryData(
91 reg_info, src, sizeof(src), byte_order, error);
92 if (error.Success() && src_size && (src_size < dest_size)) {
93 // Copy the src bytes to the destination.
94 memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
95 // Set this full register as the value to write.
96 value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
97 value_to_write.SetType(full_reg_info);
98 reg_to_write = full_reg;
104 ProcessMonitor &monitor = GetMonitor();
105 return monitor.WriteRegisterValue(
106 m_thread.GetID(), GetRegisterOffset(reg_to_write),
107 GetRegisterName(reg_to_write), value_to_write);
110 bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
111 const RegisterInfo *reg_info, RegisterValue &value) {
115 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
121 uint32_t full_reg = reg;
122 bool is_subreg = reg_info->invalidate_regs &&
123 (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
126 // Read the full aligned 64-bit register.
127 full_reg = reg_info->invalidate_regs[0];
130 bool success = ReadRegister(full_reg, value);
133 // If our read was not aligned (for ah,bh,ch,dh), shift our returned
134 // value one byte to the right.
135 if (is_subreg && (reg_info->byte_offset & 0x1))
136 value.SetUInt64(value.GetAsUInt64() >> 8);
138 // If our return byte size was greater than the return value reg size,
139 // then use the type specified by reg_info rather than the uint64_t
141 if (value.GetByteSize() > reg_info->byte_size)
142 value.SetType(reg_info);
150 bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
151 const RegisterInfo *reg_info, const RegisterValue &value) {
152 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
155 return WriteRegister(reg, value);
160 bool RegisterContextPOSIXProcessMonitor_mips64::ReadAllRegisterValues(
161 DataBufferSP &data_sp) {
162 bool success = false;
163 data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
164 if (data_sp && ReadGPR() && ReadFPR()) {
165 uint8_t *dst = data_sp->GetBytes();
169 ::memcpy(dst, &m_gpr_mips64, GetGPRSize());
175 bool RegisterContextPOSIXProcessMonitor_mips64::WriteAllRegisterValues(
176 const DataBufferSP &data_sp) {
177 bool success = false;
178 if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) {
179 uint8_t *src = data_sp->GetBytes();
181 ::memcpy(&m_gpr_mips64, src, GetGPRSize());
191 uint32_t RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpoint(
192 addr_t addr, size_t size, bool read, bool write) {
193 const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
196 for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index) {
197 if (IsWatchpointVacant(hw_index))
198 return SetHardwareWatchpointWithIndex(addr, size, read, write, hw_index);
201 return LLDB_INVALID_INDEX32;
204 bool RegisterContextPOSIXProcessMonitor_mips64::ClearHardwareWatchpoint(
209 bool RegisterContextPOSIXProcessMonitor_mips64::HardwareSingleStep(
214 bool RegisterContextPOSIXProcessMonitor_mips64::UpdateAfterBreakpoint() {
215 // PC points one byte past the int3 responsible for the breakpoint.
218 if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
225 unsigned RegisterContextPOSIXProcessMonitor_mips64::GetRegisterIndexFromOffset(
228 for (reg = 0; reg < k_num_registers_mips64; reg++) {
229 if (GetRegisterInfo()[reg].byte_offset == offset)
232 assert(reg < k_num_registers_mips64 && "Invalid register offset.");
236 bool RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointHit(
241 bool RegisterContextPOSIXProcessMonitor_mips64::ClearWatchpointHits() {
245 addr_t RegisterContextPOSIXProcessMonitor_mips64::GetWatchpointAddress(
247 return LLDB_INVALID_ADDRESS;
250 bool RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointVacant(
255 bool RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpointWithIndex(
256 addr_t addr, size_t size, bool read, bool write, uint32_t hw_index) {
261 RegisterContextPOSIXProcessMonitor_mips64::NumSupportedHardwareWatchpoints() {