Author: mgorny Date: Fri Jun 21 06:19:34 2019 New Revision: 364042 URL: http://llvm.org/viewvc/llvm-project?rev=364042&view=rev Log: [lldb] [Process] Introduce common helpers to split/recombine YMM data
Introduce two common helpers to take care of splitting and recombining YMM registers to/from XSAVE-like data. Since FreeBSD, Linux and NetBSD all use XSAVE-like data structures but with potentially different field layouts, the function takes two pointers -- to XMM register and to YMM high bits, and copies the data from/to YMMReg type. While at it, remove support for big endian. To mine and Pavel Labath's combined knowledge, there is no such thing on x86. Furthermore, assuming that the YMM register data would be swapped for big endian seems to be a weird assumption. Differential Revision: https://reviews.llvm.org/D63610 Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp lldb/trunk/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp lldb/trunk/source/Plugins/Process/Utility/RegisterContext_x86.h Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp?rev=364042&r1=364041&r2=364042&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp Fri Jun 21 06:19:34 2019 @@ -903,26 +903,13 @@ bool NativeRegisterContextLinux_x86_64:: return false; if (byte_order == lldb::eByteOrderLittle) { - ::memcpy(m_ymm_set.ymm[reg_index - m_reg_info.first_ymm].bytes, - m_xstate->fxsave.xmm[reg_index - m_reg_info.first_ymm].bytes, - sizeof(XMMReg)); - ::memcpy(m_ymm_set.ymm[reg_index - m_reg_info.first_ymm].bytes + - sizeof(XMMReg), - m_xstate->xsave.ymmh[reg_index - m_reg_info.first_ymm].bytes, - sizeof(YMMHReg)); + uint32_t reg_no = reg_index - m_reg_info.first_ymm; + m_ymm_set.ymm[reg_no] = XStateToYMM( + m_xstate->fxsave.xmm[reg_no].bytes, + m_xstate->xsave.ymmh[reg_no].bytes); return true; } - if (byte_order == lldb::eByteOrderBig) { - ::memcpy(m_ymm_set.ymm[reg_index - m_reg_info.first_ymm].bytes + - sizeof(XMMReg), - m_xstate->fxsave.xmm[reg_index - m_reg_info.first_ymm].bytes, - sizeof(XMMReg)); - ::memcpy(m_ymm_set.ymm[reg_index - m_reg_info.first_ymm].bytes, - m_xstate->xsave.ymmh[reg_index - m_reg_info.first_ymm].bytes, - sizeof(YMMHReg)); - return true; - } return false; // unsupported or invalid byte order } @@ -932,22 +919,13 @@ bool NativeRegisterContextLinux_x86_64:: return false; if (byte_order == lldb::eByteOrderLittle) { - ::memcpy(m_xstate->fxsave.xmm[reg - m_reg_info.first_ymm].bytes, - m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes, sizeof(XMMReg)); - ::memcpy(m_xstate->xsave.ymmh[reg - m_reg_info.first_ymm].bytes, - m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes + sizeof(XMMReg), - sizeof(YMMHReg)); + uint32_t reg_no = reg - m_reg_info.first_ymm; + YMMToXState(m_ymm_set.ymm[reg_no], + m_xstate->fxsave.xmm[reg_no].bytes, + m_xstate->xsave.ymmh[reg_no].bytes); return true; } - if (byte_order == lldb::eByteOrderBig) { - ::memcpy(m_xstate->fxsave.xmm[reg - m_reg_info.first_ymm].bytes, - m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes + sizeof(XMMReg), - sizeof(XMMReg)); - ::memcpy(m_xstate->xsave.ymmh[reg - m_reg_info.first_ymm].bytes, - m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes, sizeof(YMMHReg)); - return true; - } return false; // unsupported or invalid byte order } Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp?rev=364042&r1=364041&r2=364042&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp Fri Jun 21 06:19:34 2019 @@ -474,22 +474,13 @@ bool RegisterContextPOSIX_x86::CopyYMMto return false; if (byte_order == eByteOrderLittle) { - ::memcpy(m_fpr.fxsave.xmm[reg - m_reg_info.first_ymm].bytes, - m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes, sizeof(XMMReg)); - ::memcpy(m_fpr.xsave.ymmh[reg - m_reg_info.first_ymm].bytes, - m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes + sizeof(XMMReg), - sizeof(YMMHReg)); + uint32_t reg_no = reg - m_reg_info.first_ymm; + YMMToXState(m_ymm_set.ymm[reg_no], + m_fpr.fxsave.xmm[reg_no].bytes, + m_fpr.xsave.ymmh[reg_no].bytes); return true; } - if (byte_order == eByteOrderBig) { - ::memcpy(m_fpr.fxsave.xmm[reg - m_reg_info.first_ymm].bytes, - m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes + sizeof(XMMReg), - sizeof(XMMReg)); - ::memcpy(m_fpr.xsave.ymmh[reg - m_reg_info.first_ymm].bytes, - m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes, sizeof(YMMHReg)); - return true; - } return false; // unsupported or invalid byte order } @@ -500,24 +491,13 @@ bool RegisterContextPOSIX_x86::CopyXSTAT return false; if (byte_order == eByteOrderLittle) { - ::memcpy(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes, - m_fpr.fxsave.xmm[reg - m_reg_info.first_ymm].bytes, - sizeof(XMMReg)); - ::memcpy(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes + sizeof(XMMReg), - m_fpr.xsave.ymmh[reg - m_reg_info.first_ymm].bytes, - sizeof(YMMHReg)); + uint32_t reg_no = reg - m_reg_info.first_ymm; + m_ymm_set.ymm[reg_no] = XStateToYMM( + m_fpr.fxsave.xmm[reg_no].bytes, + m_fpr.xsave.ymmh[reg_no].bytes); return true; } - if (byte_order == eByteOrderBig) { - ::memcpy(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes + sizeof(XMMReg), - m_fpr.fxsave.xmm[reg - m_reg_info.first_ymm].bytes, - sizeof(XMMReg)); - ::memcpy(m_ymm_set.ymm[reg - m_reg_info.first_ymm].bytes, - m_fpr.xsave.ymmh[reg - m_reg_info.first_ymm].bytes, - sizeof(YMMHReg)); - return true; - } return false; // unsupported or invalid byte order } Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContext_x86.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContext_x86.h?rev=364042&r1=364041&r2=364042&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/RegisterContext_x86.h (original) +++ lldb/trunk/source/Plugins/Process/Utility/RegisterContext_x86.h Fri Jun 21 06:19:34 2019 @@ -353,6 +353,22 @@ union FPR { LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); +// Convenience function to combine YMM register data from XSAVE-style input. +inline YMMReg XStateToYMM(const void* xmm_bytes, const void* ymmh_bytes) { + YMMReg ret; + + ::memcpy(ret.bytes, xmm_bytes, sizeof(XMMReg)); + ::memcpy(ret.bytes + sizeof(XMMReg), ymmh_bytes, sizeof(YMMHReg)); + + return ret; +} + +// Convenience function to copy YMM register data into XSAVE-style output. +inline void YMMToXState(const YMMReg& input, void* xmm_bytes, void* ymmh_bytes) { + ::memcpy(xmm_bytes, input.bytes, sizeof(XMMReg)); + ::memcpy(ymmh_bytes, input.bytes + sizeof(XMMReg), sizeof(YMMHReg)); +} + } // namespace lldb_private #endif _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits