1 //===-- RegisterUtilities.h -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_REGISTERUTILITIES_H
11 #define LLDB_REGISTERUTILITIES_H
12 
13 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
14 #include "lldb/Utility/DataExtractor.h"
15 
16 namespace lldb_private {
17 /// Core files PT_NOTE segment descriptor types
18 
19 namespace FREEBSD {
20 enum {
21   NT_PRSTATUS = 1,
22   NT_FPREGSET,
23   NT_PRPSINFO,
24   NT_THRMISC = 7,
25   NT_PROCSTAT_AUXV = 16,
26   NT_PPC_VMX = 0x100
27 };
28 }
29 
30 namespace NETBSD {
31 enum { NT_PROCINFO = 1, NT_AUXV, NT_AMD64_REGS = 33, NT_AMD64_FPREGS = 35 };
32 }
33 
34 namespace OPENBSD {
35 enum {
36   NT_PROCINFO = 10,
37   NT_AUXV = 11,
38   NT_REGS = 20,
39   NT_FPREGS = 21,
40 };
41 }
42 
43 namespace LINUX {
44 enum {
45   NT_PRSTATUS = 1,
46   NT_FPREGSET,
47   NT_PRPSINFO,
48   NT_TASKSTRUCT,
49   NT_PLATFORM,
50   NT_AUXV,
51   NT_FILE = 0x46494c45,
52   NT_SIGINFO = 0x53494749,
53   NT_PPC_VMX = 0x100,
54   NT_PPC_VSX = 0x102,
55   NT_PRXFPREG = 0x46e62b7f,
56 };
57 }
58 
59 struct CoreNote {
60   ELFNote info;
61   DataExtractor data;
62 };
63 
64 // A structure describing how to find a register set in a core file from a given
65 // OS.
66 struct RegsetDesc {
67   // OS to which this entry applies to. Must not be UnknownOS.
68   llvm::Triple::OSType OS;
69 
70   // Architecture to which this entry applies to. Can be UnknownArch, in which
71   // case it applies to all architectures of a given OS.
72   llvm::Triple::ArchType Arch;
73 
74   // The note type under which the register set can be found.
75   uint32_t Note;
76 };
77 
78 // Returns the register set in Notes which corresponds to the specified Triple
79 // according to the list of register set descriptions in RegsetDescs. The list
80 // is scanned linearly, so you can use a more specific entry (e.g. linux-i386)
81 // to override a more general entry (e.g. general linux), as long as you place
82 // it earlier in the list. If a register set is not found, it returns an empty
83 // DataExtractor.
84 DataExtractor getRegset(llvm::ArrayRef<CoreNote> Notes,
85                         const llvm::Triple &Triple,
86                         llvm::ArrayRef<RegsetDesc> RegsetDescs);
87 
88 constexpr RegsetDesc FPR_Desc[] = {
89     {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, FREEBSD::NT_FPREGSET},
90     // In a i386 core file NT_FPREGSET is present, but it's not the result
91     // of the FXSAVE instruction like in 64 bit files.
92     // The result from FXSAVE is in NT_PRXFPREG for i386 core files
93     {llvm::Triple::Linux, llvm::Triple::x86, LINUX::NT_PRXFPREG},
94     {llvm::Triple::Linux, llvm::Triple::UnknownArch, LINUX::NT_FPREGSET},
95     {llvm::Triple::NetBSD, llvm::Triple::x86_64, NETBSD::NT_AMD64_FPREGS},
96     {llvm::Triple::OpenBSD, llvm::Triple::UnknownArch, OPENBSD::NT_FPREGS},
97 };
98 
99 constexpr RegsetDesc PPC_VMX_Desc[] = {
100     {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, FREEBSD::NT_PPC_VMX},
101     {llvm::Triple::Linux, llvm::Triple::UnknownArch, LINUX::NT_PPC_VMX},
102 };
103 
104 constexpr RegsetDesc PPC_VSX_Desc[] = {
105     {llvm::Triple::Linux, llvm::Triple::UnknownArch, LINUX::NT_PPC_VSX},
106 };
107 
108 } // namespace lldb_private
109 
110 #endif // #ifndef LLDB_REGISTERUTILITIES_H
111