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/Target/Thread.h"
11 #include "lldb/Core/RegisterValue.h"
13 #include "RegisterContextPOSIX_mips64.h"
14 #include "ProcessPOSIX.h"
15 #include "RegisterContextPOSIXProcessMonitor_mips64.h"
16 #include "ProcessMonitor.h"
18 using namespace lldb_private;
21 #define REG_CONTEXT_SIZE (GetGPRSize())
23 RegisterContextPOSIXProcessMonitor_mips64::RegisterContextPOSIXProcessMonitor_mips64(Thread &thread,
24 uint32_t concrete_frame_idx,
25 RegisterInfoInterface *register_info)
26 : RegisterContextPOSIX_mips64(thread, concrete_frame_idx, register_info)
31 RegisterContextPOSIXProcessMonitor_mips64::GetMonitor()
33 ProcessSP base = CalculateProcess();
34 ProcessPOSIX *process = static_cast<ProcessPOSIX*>(base.get());
35 return process->GetMonitor();
39 RegisterContextPOSIXProcessMonitor_mips64::ReadGPR()
41 ProcessMonitor &monitor = GetMonitor();
42 return monitor.ReadGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
46 RegisterContextPOSIXProcessMonitor_mips64::ReadFPR()
48 // XXX not yet implemented
53 RegisterContextPOSIXProcessMonitor_mips64::WriteGPR()
55 ProcessMonitor &monitor = GetMonitor();
56 return monitor.WriteGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
60 RegisterContextPOSIXProcessMonitor_mips64::WriteFPR()
62 // XXX not yet implemented
67 RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(const unsigned reg,
70 ProcessMonitor &monitor = GetMonitor();
71 return monitor.ReadRegisterValue(m_thread.GetID(),
72 GetRegisterOffset(reg),
79 RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(const unsigned reg,
80 const RegisterValue &value)
82 unsigned reg_to_write = reg;
83 RegisterValue value_to_write = value;
85 // Check if this is a subregister of a full register.
86 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
87 if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
89 RegisterValue full_value;
90 uint32_t full_reg = reg_info->invalidate_regs[0];
91 const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
93 // Read the full register.
94 if (ReadRegister(full_reg_info, full_value))
97 ByteOrder byte_order = GetByteOrder();
98 uint8_t dst[RegisterValue::kMaxRegisterByteSize];
100 // Get the bytes for the full register.
101 const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info,
106 if (error.Success() && dest_size)
108 uint8_t src[RegisterValue::kMaxRegisterByteSize];
110 // Get the bytes for the source data.
111 const uint32_t src_size = value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
112 if (error.Success() && src_size && (src_size < dest_size))
114 // Copy the src bytes to the destination.
115 memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
116 // Set this full register as the value to write.
117 value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
118 value_to_write.SetType(full_reg_info);
119 reg_to_write = full_reg;
125 ProcessMonitor &monitor = GetMonitor();
126 return monitor.WriteRegisterValue(m_thread.GetID(),
127 GetRegisterOffset(reg_to_write),
128 GetRegisterName(reg_to_write),
133 RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value)
138 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
147 uint32_t full_reg = reg;
148 bool is_subreg = reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
152 // Read the full aligned 64-bit register.
153 full_reg = reg_info->invalidate_regs[0];
156 bool success = ReadRegister(full_reg, value);
160 // If our read was not aligned (for ah,bh,ch,dh), shift our returned value one byte to the right.
161 if (is_subreg && (reg_info->byte_offset & 0x1))
162 value.SetUInt64(value.GetAsUInt64() >> 8);
164 // If our return byte size was greater than the return value reg size, then
165 // use the type specified by reg_info rather than the uint64_t default
166 if (value.GetByteSize() > reg_info->byte_size)
167 value.SetType(reg_info);
176 RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(const RegisterInfo *reg_info, const RegisterValue &value)
178 const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
181 return WriteRegister(reg, value);
187 RegisterContextPOSIXProcessMonitor_mips64::ReadAllRegisterValues(DataBufferSP &data_sp)
189 bool success = false;
190 data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0));
191 if (data_sp && ReadGPR () && ReadFPR ())
193 uint8_t *dst = data_sp->GetBytes();
198 ::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()