1*5cc817beSMichał Górny //===-- RegisterContextNetBSD_i386.cpp -------------------------*- C++ -*-===//
2*5cc817beSMichał Górny //
3*5cc817beSMichał Górny // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*5cc817beSMichał Górny // See https://llvm.org/LICENSE.txt for license information.
5*5cc817beSMichał Górny // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*5cc817beSMichał Górny //
7*5cc817beSMichał Górny //===---------------------------------------------------------------------===//
8*5cc817beSMichał Górny 
9*5cc817beSMichał Górny #include "RegisterContextNetBSD_i386.h"
10*5cc817beSMichał Górny #include "RegisterContextPOSIX_x86.h"
11*5cc817beSMichał Górny 
12*5cc817beSMichał Górny using namespace lldb_private;
13*5cc817beSMichał Górny using namespace lldb;
14*5cc817beSMichał Górny 
15*5cc817beSMichał Górny // this needs to match 'struct reg'
16*5cc817beSMichał Górny struct GPR {
17*5cc817beSMichał Górny   uint32_t eax;
18*5cc817beSMichał Górny   uint32_t ecx;
19*5cc817beSMichał Górny   uint32_t edx;
20*5cc817beSMichał Górny   uint32_t ebx;
21*5cc817beSMichał Górny   uint32_t esp;
22*5cc817beSMichał Górny   uint32_t ebp;
23*5cc817beSMichał Górny   uint32_t esi;
24*5cc817beSMichał Górny   uint32_t edi;
25*5cc817beSMichał Górny   uint32_t eip;
26*5cc817beSMichał Górny   uint32_t eflags;
27*5cc817beSMichał Górny   uint32_t cs;
28*5cc817beSMichał Górny   uint32_t ss;
29*5cc817beSMichał Górny   uint32_t ds;
30*5cc817beSMichał Górny   uint32_t es;
31*5cc817beSMichał Górny   uint32_t fs;
32*5cc817beSMichał Górny   uint32_t gs;
33*5cc817beSMichał Górny };
34*5cc817beSMichał Górny 
35*5cc817beSMichał Górny struct FPR_i386 {
36*5cc817beSMichał Górny   uint16_t fctrl;     // FPU Control Word (fcw)
37*5cc817beSMichał Górny   uint16_t fstat;     // FPU Status Word (fsw)
38*5cc817beSMichał Górny   uint16_t ftag;      // FPU Tag Word (ftw)
39*5cc817beSMichał Górny   uint16_t fop;       // Last Instruction Opcode (fop)
40*5cc817beSMichał Górny   union {
41*5cc817beSMichał Górny     struct {
42*5cc817beSMichał Górny       uint64_t fip; // Instruction Pointer
43*5cc817beSMichał Górny       uint64_t fdp; // Data Pointer
44*5cc817beSMichał Górny     } x86_64;
45*5cc817beSMichał Górny     struct {
46*5cc817beSMichał Górny       uint32_t fioff; // FPU IP Offset (fip)
47*5cc817beSMichał Górny       uint32_t fiseg; // FPU IP Selector (fcs)
48*5cc817beSMichał Górny       uint32_t fooff; // FPU Operand Pointer Offset (foo)
49*5cc817beSMichał Górny       uint32_t foseg; // FPU Operand Pointer Selector (fos)
50*5cc817beSMichał Górny     } i386_; // Added _ in the end to avoid error with gcc defining i386 in some
51*5cc817beSMichał Górny              // cases
52*5cc817beSMichał Górny   } ptr;
53*5cc817beSMichał Górny   uint32_t mxcsr;     // MXCSR Register State
54*5cc817beSMichał Górny   uint32_t mxcsrmask; // MXCSR Mask
55*5cc817beSMichał Górny   MMSReg stmm[8];     // 8*16 bytes for each FP-reg = 128 bytes
56*5cc817beSMichał Górny   XMMReg xmm[8];      // 8*16 bytes for each XMM-reg = 128 bytes
57*5cc817beSMichał Górny   uint32_t padding[56];
58*5cc817beSMichał Górny };
59*5cc817beSMichał Górny 
60*5cc817beSMichał Górny struct UserArea {
61*5cc817beSMichał Górny   GPR gpr;
62*5cc817beSMichał Górny   FPR_i386 i387;
63*5cc817beSMichał Górny   uint32_t u_debugreg[8]; // Debug registers (DR0 - DR7).
64*5cc817beSMichał Górny   uint32_t tlsbase;
65*5cc817beSMichał Górny };
66*5cc817beSMichał Górny 
67*5cc817beSMichał Górny #define DR_SIZE sizeof(((UserArea *)NULL)->u_debugreg[0])
68*5cc817beSMichał Górny #define DR_OFFSET(reg_index)                                                   \
69*5cc817beSMichał Górny   (LLVM_EXTENSION offsetof(UserArea, u_debugreg[reg_index]))
70*5cc817beSMichał Górny 
71*5cc817beSMichał Górny // Include RegisterInfos_i386 to declare our g_register_infos_i386 structure.
72*5cc817beSMichał Górny #define DECLARE_REGISTER_INFOS_I386_STRUCT
73*5cc817beSMichał Górny #include "RegisterInfos_i386.h"
74*5cc817beSMichał Górny #undef DECLARE_REGISTER_INFOS_I386_STRUCT
75*5cc817beSMichał Górny 
RegisterContextNetBSD_i386(const ArchSpec & target_arch)76*5cc817beSMichał Górny RegisterContextNetBSD_i386::RegisterContextNetBSD_i386(
77*5cc817beSMichał Górny     const ArchSpec &target_arch)
78*5cc817beSMichał Górny     : RegisterInfoInterface(target_arch) {}
79*5cc817beSMichał Górny 
GetGPRSize() const80*5cc817beSMichał Górny size_t RegisterContextNetBSD_i386::GetGPRSize() const { return sizeof(GPR); }
81*5cc817beSMichał Górny 
GetRegisterInfo() const82*5cc817beSMichał Górny const RegisterInfo *RegisterContextNetBSD_i386::GetRegisterInfo() const {
83*5cc817beSMichał Górny   switch (m_target_arch.GetMachine()) {
84*5cc817beSMichał Górny   case llvm::Triple::x86:
85*5cc817beSMichał Górny   case llvm::Triple::x86_64:
86*5cc817beSMichał Górny     return g_register_infos_i386;
87*5cc817beSMichał Górny   default:
88*5cc817beSMichał Górny     assert(false && "Unhandled target architecture.");
89*5cc817beSMichał Górny     return nullptr;
90*5cc817beSMichał Górny   }
91*5cc817beSMichał Górny }
92*5cc817beSMichał Górny 
GetRegisterCount() const93*5cc817beSMichał Górny uint32_t RegisterContextNetBSD_i386::GetRegisterCount() const {
94*5cc817beSMichał Górny   return static_cast<uint32_t>(sizeof(g_register_infos_i386) /
95*5cc817beSMichał Górny                                sizeof(g_register_infos_i386[0]));
96*5cc817beSMichał Górny }
97