15ffd83dbSDimitry Andric //===-- RegisterContextFreeBSD_i386.cpp -----------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===---------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "RegisterContextFreeBSD_i386.h"
100b57cec5SDimitry Andric #include "RegisterContextPOSIX_x86.h"
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric using namespace lldb_private;
130b57cec5SDimitry Andric using namespace lldb;
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric // http://svnweb.freebsd.org/base/head/sys/x86/include/reg.h
160b57cec5SDimitry Andric struct GPR {
170b57cec5SDimitry Andric   uint32_t fs;
180b57cec5SDimitry Andric   uint32_t es;
190b57cec5SDimitry Andric   uint32_t ds;
200b57cec5SDimitry Andric   uint32_t edi;
210b57cec5SDimitry Andric   uint32_t esi;
220b57cec5SDimitry Andric   uint32_t ebp;
230b57cec5SDimitry Andric   uint32_t isp;
240b57cec5SDimitry Andric   uint32_t ebx;
250b57cec5SDimitry Andric   uint32_t edx;
260b57cec5SDimitry Andric   uint32_t ecx;
270b57cec5SDimitry Andric   uint32_t eax;
280b57cec5SDimitry Andric   uint32_t trapno;
290b57cec5SDimitry Andric   uint32_t err;
300b57cec5SDimitry Andric   uint32_t eip;
310b57cec5SDimitry Andric   uint32_t cs;
320b57cec5SDimitry Andric   uint32_t eflags;
330b57cec5SDimitry Andric   uint32_t esp;
340b57cec5SDimitry Andric   uint32_t ss;
350b57cec5SDimitry Andric   uint32_t gs;
360b57cec5SDimitry Andric };
370b57cec5SDimitry Andric 
38e8d8bef9SDimitry Andric struct DBG {
390b57cec5SDimitry Andric   uint32_t dr[8]; /* debug registers */
400b57cec5SDimitry Andric                   /* Index 0-3: debug address registers */
410b57cec5SDimitry Andric                   /* Index 4-5: reserved */
420b57cec5SDimitry Andric                   /* Index 6: debug status */
430b57cec5SDimitry Andric                   /* Index 7: debug control */
440b57cec5SDimitry Andric };
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric using FPR_i386 = FXSAVE;
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric struct UserArea {
490b57cec5SDimitry Andric   GPR gpr;
500b57cec5SDimitry Andric   FPR_i386 i387;
51e8d8bef9SDimitry Andric   DBG dbg;
520b57cec5SDimitry Andric };
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric #define DR_SIZE sizeof(uint32_t)
55e8d8bef9SDimitry Andric #define DR_OFFSET(reg_index)                                                   \
56e8d8bef9SDimitry Andric   (LLVM_EXTENSION offsetof(UserArea, dbg) +                                    \
57e8d8bef9SDimitry Andric    LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric // Include RegisterInfos_i386 to declare our g_register_infos_i386 structure.
600b57cec5SDimitry Andric #define DECLARE_REGISTER_INFOS_I386_STRUCT
610b57cec5SDimitry Andric #include "RegisterInfos_i386.h"
620b57cec5SDimitry Andric #undef DECLARE_REGISTER_INFOS_I386_STRUCT
630b57cec5SDimitry Andric 
RegisterContextFreeBSD_i386(const ArchSpec & target_arch)640b57cec5SDimitry Andric RegisterContextFreeBSD_i386::RegisterContextFreeBSD_i386(
650b57cec5SDimitry Andric     const ArchSpec &target_arch)
660b57cec5SDimitry Andric     : RegisterInfoInterface(target_arch) {}
670b57cec5SDimitry Andric 
GetGPRSize() const680b57cec5SDimitry Andric size_t RegisterContextFreeBSD_i386::GetGPRSize() const { return sizeof(GPR); }
690b57cec5SDimitry Andric 
GetRegisterInfo() const700b57cec5SDimitry Andric const RegisterInfo *RegisterContextFreeBSD_i386::GetRegisterInfo() const {
71bdd1243dSDimitry Andric   switch (GetTargetArchitecture().GetMachine()) {
720b57cec5SDimitry Andric   case llvm::Triple::x86:
730b57cec5SDimitry Andric     return g_register_infos_i386;
740b57cec5SDimitry Andric   default:
750b57cec5SDimitry Andric     assert(false && "Unhandled target architecture.");
760b57cec5SDimitry Andric     return nullptr;
770b57cec5SDimitry Andric   }
780b57cec5SDimitry Andric }
790b57cec5SDimitry Andric 
GetRegisterCount() const800b57cec5SDimitry Andric uint32_t RegisterContextFreeBSD_i386::GetRegisterCount() const {
810b57cec5SDimitry Andric   return static_cast<uint32_t>(sizeof(g_register_infos_i386) /
820b57cec5SDimitry Andric                                sizeof(g_register_infos_i386[0]));
830b57cec5SDimitry Andric }
84