1 //===-- RegisterContextPOSIXProcessMonitor_mips64.h ------------*- 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/Core/DataBufferHeap.h"
11 #include "lldb/Core/RegisterValue.h"
12 #include "lldb/Target/Thread.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::RegisterContextPOSIXProcessMonitor_mips64(Thread &thread,
25 uint32_t concrete_frame_idx,
26 lldb_private::RegisterInfoInterface *register_info)
27 : RegisterContextPOSIX_mips64(thread, concrete_frame_idx, register_info)
32 RegisterContextPOSIXProcessMonitor_mips64::GetMonitor()
34 ProcessSP base = CalculateProcess();
35 ProcessFreeBSD *process = static_cast<ProcessFreeBSD*>(base.get());
36 return process->GetMonitor();
40 RegisterContextPOSIXProcessMonitor_mips64::ReadGPR()
42 ProcessMonitor &monitor = GetMonitor();
43 return monitor.ReadGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
47 RegisterContextPOSIXProcessMonitor_mips64::ReadFPR()
49 // XXX not yet implemented
54 RegisterContextPOSIXProcessMonitor_mips64::WriteGPR()
56 ProcessMonitor &monitor = GetMonitor();
57 return monitor.WriteGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
61 RegisterContextPOSIXProcessMonitor_mips64::WriteFPR()
63 // XXX not yet implemented
68 RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(const unsigned reg,
71 ProcessMonitor &monitor = GetMonitor();
72 return monitor.ReadRegisterValue(m_thread.GetID(),
73 GetRegisterOffset(reg),
80 RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(const unsigned reg,
81 const RegisterValue &value)
83 unsigned reg_to_write = reg;
84 RegisterValue value_to_write = value;
86 // Check if this is a subregister of a full register.
87 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
88 if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
90 RegisterValue full_value;
91 uint32_t full_reg = reg_info->invalidate_regs[0];
92 const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
94 // Read the full register.
95 if (ReadRegister(full_reg_info, full_value))
98 ByteOrder byte_order = GetByteOrder();
99 uint8_t dst[RegisterValue::kMaxRegisterByteSize];
101 // Get the bytes for the full register.
102 const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info,
107 if (error.Success() && dest_size)
109 uint8_t src[RegisterValue::kMaxRegisterByteSize];
111 // Get the bytes for the source data.
112 const uint32_t src_size = value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
113 if (error.Success() && src_size && (src_size < dest_size))
115 // Copy the src bytes to the destination.
116 memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
117 // Set this full register as the value to write.
118 value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
119 value_to_write.SetType(full_reg_info);
120 reg_to_write = full_reg;
126 ProcessMonitor &monitor = GetMonitor();
127 return monitor.WriteRegisterValue(m_thread.GetID(),
128 GetRegisterOffset(reg_to_write),
129 GetRegisterName(reg_to_write),
134 RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value)
139 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
148 uint32_t full_reg = reg;
149 bool is_subreg = reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
153 // Read the full aligned 64-bit register.
154 full_reg = reg_info->invalidate_regs[0];
157 bool success = ReadRegister(full_reg, value);
161 // If our read was not aligned (for ah,bh,ch,dh), shift our returned value one byte to the right.
162 if (is_subreg && (reg_info->byte_offset & 0x1))
163 value.SetUInt64(value.GetAsUInt64() >> 8);
165 // If our return byte size was greater than the return value reg size, then
166 // use the type specified by reg_info rather than the uint64_t default
167 if (value.GetByteSize() > reg_info->byte_size)
168 value.SetType(reg_info);
177 RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(const RegisterInfo *reg_info, const RegisterValue &value)
179 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
182 return WriteRegister(reg, value);
188 RegisterContextPOSIXProcessMonitor_mips64::ReadAllRegisterValues(DataBufferSP &data_sp)
190 bool success = false;
191 data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0));
192 if (data_sp && ReadGPR () && ReadFPR ())
194 uint8_t *dst = data_sp->GetBytes();
199 ::memcpy (dst, &m_gpr_mips64, GetGPRSize());
206 RegisterContextPOSIXProcessMonitor_mips64::WriteAllRegisterValues(const DataBufferSP &data_sp)
208 bool success = false;
209 if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE)
211 uint8_t *src = data_sp->GetBytes();
214 ::memcpy (&m_gpr_mips64, src, GetGPRSize());
226 RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpoint(addr_t addr, size_t size,
227 bool read, bool write)
229 const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
232 for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index)
234 if (IsWatchpointVacant(hw_index))
235 return SetHardwareWatchpointWithIndex(addr, size,
240 return LLDB_INVALID_INDEX32;
244 RegisterContextPOSIXProcessMonitor_mips64::ClearHardwareWatchpoint(uint32_t hw_index)
250 RegisterContextPOSIXProcessMonitor_mips64::HardwareSingleStep(bool enable)
256 RegisterContextPOSIXProcessMonitor_mips64::UpdateAfterBreakpoint()
258 // PC points one byte past the int3 responsible for the breakpoint.
261 if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
269 RegisterContextPOSIXProcessMonitor_mips64::GetRegisterIndexFromOffset(unsigned offset)
272 for (reg = 0; reg < k_num_registers_mips64; reg++)
274 if (GetRegisterInfo()[reg].byte_offset == offset)
277 assert(reg < k_num_registers_mips64 && "Invalid register offset.");
282 RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointHit(uint32_t hw_index)
288 RegisterContextPOSIXProcessMonitor_mips64::ClearWatchpointHits()
294 RegisterContextPOSIXProcessMonitor_mips64::GetWatchpointAddress(uint32_t hw_index)
296 return LLDB_INVALID_ADDRESS;
300 RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointVacant(uint32_t hw_index)
306 RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpointWithIndex(addr_t addr, size_t size,
307 bool read, bool write,
314 RegisterContextPOSIXProcessMonitor_mips64::NumSupportedHardwareWatchpoints()