]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/ArchSpec.h
Merge ^/head r293280 through r293429.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / ArchSpec.h
1 //===-- ArchSpec.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 liblldb_ArchSpec_h_
11 #define liblldb_ArchSpec_h_
12
13 #if defined(__cplusplus)
14
15 #include "lldb/lldb-forward.h"
16 #include "lldb/Core/ConstString.h"
17 #include "llvm/ADT/Triple.h"
18
19 namespace lldb_private {
20
21 struct CoreDefinition;    
22
23 //----------------------------------------------------------------------
24 /// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h"
25 /// @brief An architecture specification class.
26 ///
27 /// A class designed to be created from a cpu type and subtype, a
28 /// string representation, or an llvm::Triple.  Keeping all of the
29 /// conversions of strings to architecture enumeration values confined
30 /// to this class allows new architecture support to be added easily.
31 //----------------------------------------------------------------------
32 class ArchSpec
33 {
34 public:
35     enum MIPSSubType
36     {
37         eMIPSSubType_unknown,
38         eMIPSSubType_mips32,
39         eMIPSSubType_mips32r2,
40         eMIPSSubType_mips32r6,
41         eMIPSSubType_mips32el,
42         eMIPSSubType_mips32r2el,
43         eMIPSSubType_mips32r6el,
44         eMIPSSubType_mips64,
45         eMIPSSubType_mips64r2,
46         eMIPSSubType_mips64r6,
47         eMIPSSubType_mips64el,
48         eMIPSSubType_mips64r2el,
49         eMIPSSubType_mips64r6el,
50     };
51
52     // Masks for the ases word of an ABI flags structure.
53     enum MIPSASE
54     {
55         eMIPSAse_dsp        = 0x00000001,   // DSP ASE
56         eMIPSAse_dspr2      = 0x00000002,   // DSP R2 ASE
57         eMIPSAse_eva        = 0x00000004,   // Enhanced VA Scheme
58         eMIPSAse_mcu        = 0x00000008,   // MCU (MicroController) ASE
59         eMIPSAse_mdmx       = 0x00000010,   // MDMX ASE
60         eMIPSAse_mips3d     = 0x00000020,   // MIPS-3D ASE
61         eMIPSAse_mt         = 0x00000040,   // MT ASE
62         eMIPSAse_smartmips  = 0x00000080,   // SmartMIPS ASE
63         eMIPSAse_virt       = 0x00000100,   // VZ ASE
64         eMIPSAse_msa        = 0x00000200,   // MSA ASE
65         eMIPSAse_mips16     = 0x00000400,   // MIPS16 ASE
66         eMIPSAse_micromips  = 0x00000800,   // MICROMIPS ASE
67         eMIPSAse_xpa        = 0x00001000,   // XPA ASE
68         eMIPSAse_mask       = 0x00001fff,
69         eMIPSABI_O32        = 0x00002000,
70         eMIPSABI_N32        = 0x00004000,
71         eMIPSABI_N64        = 0x00008000,
72         eMIPSABI_mask       = 0x000ff000
73     };
74
75     enum Core
76     {
77         eCore_arm_generic,
78         eCore_arm_armv4,
79         eCore_arm_armv4t,
80         eCore_arm_armv5,
81         eCore_arm_armv5e,
82         eCore_arm_armv5t,
83         eCore_arm_armv6,
84         eCore_arm_armv6m,
85         eCore_arm_armv7,
86         eCore_arm_armv7f,
87         eCore_arm_armv7s,
88         eCore_arm_armv7k,
89         eCore_arm_armv7m,
90         eCore_arm_armv7em,
91         eCore_arm_xscale,  
92
93         eCore_thumb,
94         eCore_thumbv4t,
95         eCore_thumbv5,
96         eCore_thumbv5e,
97         eCore_thumbv6,
98         eCore_thumbv6m,
99         eCore_thumbv7,
100         eCore_thumbv7s,
101         eCore_thumbv7k,
102         eCore_thumbv7f,
103         eCore_thumbv7m,
104         eCore_thumbv7em,
105         eCore_arm_arm64,
106         eCore_arm_armv8,
107         eCore_arm_aarch64,
108
109         eCore_mips32,
110         eCore_mips32r2,
111         eCore_mips32r3,
112         eCore_mips32r5,
113         eCore_mips32r6,
114         eCore_mips32el,
115         eCore_mips32r2el,
116         eCore_mips32r3el,
117         eCore_mips32r5el,
118         eCore_mips32r6el,
119         eCore_mips64,
120         eCore_mips64r2,
121         eCore_mips64r3,
122         eCore_mips64r5,
123         eCore_mips64r6,
124         eCore_mips64el,
125         eCore_mips64r2el,
126         eCore_mips64r3el,
127         eCore_mips64r5el,
128         eCore_mips64r6el,
129
130         eCore_ppc_generic,
131         eCore_ppc_ppc601,
132         eCore_ppc_ppc602,
133         eCore_ppc_ppc603,
134         eCore_ppc_ppc603e,
135         eCore_ppc_ppc603ev,
136         eCore_ppc_ppc604,
137         eCore_ppc_ppc604e,
138         eCore_ppc_ppc620,
139         eCore_ppc_ppc750,
140         eCore_ppc_ppc7400,
141         eCore_ppc_ppc7450,
142         eCore_ppc_ppc970,
143         
144         eCore_ppc64_generic,
145         eCore_ppc64_ppc970_64,
146         
147         eCore_sparc_generic,
148         
149         eCore_sparc9_generic,
150         
151         eCore_x86_32_i386,
152         eCore_x86_32_i486,
153         eCore_x86_32_i486sx,
154         eCore_x86_32_i686,
155         
156         eCore_x86_64_x86_64,
157         eCore_x86_64_x86_64h, // Haswell enabled x86_64
158         eCore_hexagon_generic,
159         eCore_hexagon_hexagonv4,
160         eCore_hexagon_hexagonv5,
161
162         eCore_uknownMach32,
163         eCore_uknownMach64,
164
165         eCore_kalimba3,
166         eCore_kalimba4,
167         eCore_kalimba5,
168
169         kNumCores,
170
171         kCore_invalid,
172         // The following constants are used for wildcard matching only
173         kCore_any,
174         kCore_arm_any,
175         kCore_ppc_any,
176         kCore_ppc64_any,
177         kCore_x86_32_any,
178         kCore_x86_64_any,
179         kCore_hexagon_any,
180
181         kCore_arm_first     = eCore_arm_generic,
182         kCore_arm_last      = eCore_arm_xscale,
183
184         kCore_thumb_first   = eCore_thumb,
185         kCore_thumb_last    = eCore_thumbv7em,
186
187         kCore_ppc_first     = eCore_ppc_generic,
188         kCore_ppc_last      = eCore_ppc_ppc970,
189
190         kCore_ppc64_first   = eCore_ppc64_generic,
191         kCore_ppc64_last    = eCore_ppc64_ppc970_64,
192
193         kCore_x86_32_first  = eCore_x86_32_i386,
194         kCore_x86_32_last   = eCore_x86_32_i686,
195
196         kCore_x86_64_first  = eCore_x86_64_x86_64,
197         kCore_x86_64_last   = eCore_x86_64_x86_64h,
198
199         kCore_hexagon_first  = eCore_hexagon_generic,
200         kCore_hexagon_last   = eCore_hexagon_hexagonv5,
201
202         kCore_kalimba_first = eCore_kalimba3,
203         kCore_kalimba_last = eCore_kalimba5,
204
205         kCore_mips32_first  = eCore_mips32,
206         kCore_mips32_last   = eCore_mips32r6,
207
208         kCore_mips32el_first  = eCore_mips32el,
209         kCore_mips32el_last   = eCore_mips32r6el,
210
211         kCore_mips64_first  = eCore_mips64,
212         kCore_mips64_last   = eCore_mips64r6,
213
214         kCore_mips64el_first  = eCore_mips64el,
215         kCore_mips64el_last   = eCore_mips64r6el,
216
217         kCore_mips_first  = eCore_mips32,
218         kCore_mips_last   = eCore_mips64r6el
219
220     };
221
222     typedef void (* StopInfoOverrideCallbackType)(lldb_private::Thread &thread);
223
224     //------------------------------------------------------------------
225     /// Default constructor.
226     ///
227     /// Default constructor that initializes the object with invalid
228     /// cpu type and subtype values.
229     //------------------------------------------------------------------
230     ArchSpec ();
231
232     //------------------------------------------------------------------
233     /// Constructor over triple.
234     ///
235     /// Constructs an ArchSpec with properties consistent with the given
236     /// Triple.
237     //------------------------------------------------------------------
238     explicit 
239     ArchSpec (const llvm::Triple &triple);
240     explicit 
241     ArchSpec (const char *triple_cstr);
242     explicit 
243     ArchSpec (const char *triple_cstr, Platform *platform);
244     //------------------------------------------------------------------
245     /// Constructor over architecture name.
246     ///
247     /// Constructs an ArchSpec with properties consistent with the given
248     /// object type and architecture name.
249     //------------------------------------------------------------------
250     explicit 
251     ArchSpec (ArchitectureType arch_type,
252               uint32_t cpu_type,
253               uint32_t cpu_subtype);
254
255     //------------------------------------------------------------------
256     /// Destructor.
257     //------------------------------------------------------------------
258     ~ArchSpec ();
259
260     //------------------------------------------------------------------
261     /// Assignment operator.
262     ///
263     /// @param[in] rhs another ArchSpec object to copy.
264     ///
265     /// @return A const reference to this object.
266     //------------------------------------------------------------------
267     const ArchSpec&
268     operator= (const ArchSpec& rhs);
269
270     static size_t
271     AutoComplete (const char *name, 
272                   StringList &matches);
273
274     //------------------------------------------------------------------
275     /// Returns a static string representing the current architecture.
276     ///
277     /// @return A static string correcponding to the current
278     ///         architecture.
279     //------------------------------------------------------------------
280     const char *
281     GetArchitectureName () const;
282
283     //------------------------------------------------------------------
284     /// Clears the object state.
285     ///
286     /// Clears the object state back to a default invalid state.
287     //------------------------------------------------------------------
288     void
289     Clear ();
290
291     //------------------------------------------------------------------
292     /// Returns the size in bytes of an address of the current
293     /// architecture.
294     ///
295     /// @return The byte size of an address of the current architecture.
296     //------------------------------------------------------------------
297     uint32_t
298     GetAddressByteSize () const;
299
300     //------------------------------------------------------------------
301     /// Returns a machine family for the current architecture.
302     ///
303     /// @return An LLVM arch type.
304     //------------------------------------------------------------------
305     llvm::Triple::ArchType
306     GetMachine () const;
307
308     //------------------------------------------------------------------
309     /// Returns the distribution id of the architecture.
310     ///
311     /// This will be something like "ubuntu", "fedora", etc. on Linux.
312     ///
313     /// @return A ConstString ref containing the distribution id,
314     ///         potentially empty.
315     //------------------------------------------------------------------
316     const ConstString&
317     GetDistributionId () const;
318
319     //------------------------------------------------------------------
320     /// Set the distribution id of the architecture.
321     ///
322     /// This will be something like "ubuntu", "fedora", etc. on Linux.
323     /// This should be the same value returned by
324     /// HostInfo::GetDistributionId ().
325     ///------------------------------------------------------------------
326     void
327     SetDistributionId (const char* distribution_id);
328
329     //------------------------------------------------------------------
330     /// Tests if this ArchSpec is valid.
331     ///
332     /// @return True if the current architecture is valid, false
333     ///         otherwise.
334     //------------------------------------------------------------------
335     bool
336     IsValid () const
337     {
338         return m_core >= eCore_arm_generic && m_core < kNumCores;
339     }
340
341     bool
342     TripleVendorWasSpecified() const
343     {
344         return !m_triple.getVendorName().empty();
345     }
346
347     bool
348     TripleVendorIsUnspecifiedUnknown() const
349     {
350         return m_triple.getVendor() == llvm::Triple::UnknownVendor && m_triple.getVendorName().empty();
351     }
352
353     bool
354     TripleOSWasSpecified() const
355     {
356         return !m_triple.getOSName().empty();
357     }
358     
359     bool
360     TripleEnvironmentWasSpecified () const
361     {
362         return !m_triple.getEnvironmentName().empty();
363     }
364
365     bool
366     TripleOSIsUnspecifiedUnknown() const
367     {
368         return m_triple.getOS() == llvm::Triple::UnknownOS && m_triple.getOSName().empty();
369     }
370
371     //------------------------------------------------------------------
372     /// Merges fields from another ArchSpec into this ArchSpec.
373     ///
374     /// This will use the supplied ArchSpec to fill in any fields of
375     /// the triple in this ArchSpec which were unspecified.  This can
376     /// be used to refine a generic ArchSpec with a more specific one.
377     /// For example, if this ArchSpec's triple is something like
378     /// i386-unknown-unknown-unknown, and we have a triple which is
379     /// x64-pc-windows-msvc, then merging that triple into this one
380     /// will result in the triple i386-pc-windows-msvc.
381     ///
382     //------------------------------------------------------------------
383     void
384     MergeFrom(const ArchSpec &other);
385     
386     //------------------------------------------------------------------
387     /// Change the architecture object type, CPU type and OS type.
388     ///
389     /// @param[in] arch_type The object type of this ArchSpec.
390     ///
391     /// @param[in] cpu The required CPU type.
392     ///
393     /// @param[in] os The optional OS type
394     /// The default value of 0 was choosen to from the ELF spec value
395     /// ELFOSABI_NONE.  ELF is the only one using this parameter.  If another
396     /// format uses this parameter and 0 does not work, use a value over
397     /// 255 because in the ELF header this is value is only a byte.
398     ///
399     /// @return True if the object, and CPU were successfully set.
400     ///
401     /// As a side effect, the vendor value is usually set to unknown.
402     /// The exections are
403     ///   aarch64-apple-ios
404     ///   arm-apple-ios
405     ///   thumb-apple-ios
406     ///   x86-apple-
407     ///   x86_64-apple-
408     ///
409     /// As a side effect, the os value is usually set to unknown
410     /// The exceptions are
411     ///   *-*-aix
412     ///   aarch64-apple-ios
413     ///   arm-apple-ios
414     ///   thumb-apple-ios
415     ///   powerpc-apple-darwin
416     ///   *-*-freebsd
417     ///   *-*-linux
418     ///   *-*-netbsd
419     ///   *-*-openbsd
420     ///   *-*-solaris
421     //------------------------------------------------------------------
422     bool
423     SetArchitecture (ArchitectureType arch_type, 
424                      uint32_t cpu,
425                      uint32_t sub,
426                      uint32_t os = 0);
427
428     //------------------------------------------------------------------
429     /// Returns the byte order for the architecture specification.
430     ///
431     /// @return The endian enumeration for the current endianness of
432     ///     the architecture specification
433     //------------------------------------------------------------------
434     lldb::ByteOrder
435     GetByteOrder () const;
436
437     //------------------------------------------------------------------
438     /// Sets this ArchSpec's byte order.
439     ///
440     /// In the common case there is no need to call this method as the
441     /// byte order can almost always be determined by the architecture.
442     /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
443     /// and the default/assumed byte order may be incorrect.
444     //------------------------------------------------------------------
445     void
446     SetByteOrder (lldb::ByteOrder byte_order)
447     {
448         m_byte_order = byte_order;
449     }
450
451     uint32_t
452     GetMinimumOpcodeByteSize() const;
453
454     uint32_t
455     GetMaximumOpcodeByteSize() const;
456
457     Core
458     GetCore () const
459     {
460         return m_core;
461     }
462
463     uint32_t
464     GetMachOCPUType () const;
465
466     uint32_t
467     GetMachOCPUSubType () const;
468
469     //------------------------------------------------------------------
470     /// Architecture data byte width accessor
471     ///
472     /// @return the size in 8-bit (host) bytes of a minimum addressable
473     /// unit from the Architecture's data bus
474     //------------------------------------------------------------------
475     uint32_t
476     GetDataByteSize() const;
477
478     //------------------------------------------------------------------
479     /// Architecture code byte width accessor
480     ///
481     /// @return the size in 8-bit (host) bytes of a minimum addressable
482     /// unit from the Architecture's code bus
483     //------------------------------------------------------------------
484     uint32_t
485     GetCodeByteSize() const;
486  
487     //------------------------------------------------------------------
488     /// Architecture tripple accessor.
489     ///
490     /// @return A triple describing this ArchSpec.
491     //------------------------------------------------------------------
492     llvm::Triple &
493     GetTriple ()
494     {
495         return m_triple;
496     }
497
498     //------------------------------------------------------------------
499     /// Architecture tripple accessor.
500     ///
501     /// @return A triple describing this ArchSpec.
502     //------------------------------------------------------------------
503     const llvm::Triple &
504     GetTriple () const
505     {
506         return m_triple;
507     }
508
509     void
510     DumpTriple(Stream &s) const;
511
512     //------------------------------------------------------------------
513     /// Architecture tripple setter.
514     ///
515     /// Configures this ArchSpec according to the given triple.  If the 
516     /// triple has unknown components in all of the vendor, OS, and 
517     /// the optional environment field (i.e. "i386-unknown-unknown")
518     /// then default values are taken from the host.  Architecture and
519     /// environment components are used to further resolve the CPU type
520     /// and subtype, endian characteristics, etc.
521     ///
522     /// @return A triple describing this ArchSpec.
523     //------------------------------------------------------------------
524     bool
525     SetTriple (const llvm::Triple &triple);
526
527     bool
528     SetTriple (const char *triple_cstr);
529
530     bool
531     SetTriple (const char *triple_cstr,
532                Platform *platform);
533     
534     //------------------------------------------------------------------
535     /// Returns the default endianness of the architecture.
536     ///
537     /// @return The endian enumeration for the default endianness of
538     ///         the architecture.
539     //------------------------------------------------------------------
540     lldb::ByteOrder
541     GetDefaultEndian () const;
542
543     //------------------------------------------------------------------
544     /// Returns true if 'char' is a signed type by defualt in the 
545     /// architecture false otherwise
546     ///
547     /// @return True if 'char' is a signed type by default on the
548     ///         architecture and false otherwise.
549     //------------------------------------------------------------------
550     bool
551     CharIsSignedByDefault () const;
552
553     //------------------------------------------------------------------
554     /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu
555     /// type match between them.
556     /// e.g. armv7s is not an exact match with armv7 - this would return false
557     ///
558     /// @return true if the two ArchSpecs match.
559     //------------------------------------------------------------------
560     bool
561     IsExactMatch (const ArchSpec& rhs) const;
562
563     //------------------------------------------------------------------
564     /// Compare an ArchSpec to another ArchSpec, requiring a compatible
565     /// cpu type match between them.  
566     /// e.g. armv7s is compatible with armv7 - this method would return true
567     ///
568     /// @return true if the two ArchSpecs are compatible
569     //------------------------------------------------------------------
570     bool
571     IsCompatibleMatch (const ArchSpec& rhs) const;
572
573     //------------------------------------------------------------------
574     /// Get a stop info override callback for the current architecture.
575     ///
576     /// Most platform specific code should go in lldb_private::Platform,
577     /// but there are cases where no matter which platform you are on
578     /// certain things hold true.
579     ///
580     /// This callback is currently intended to handle cases where a
581     /// program stops at an instruction that won't get executed and it
582     /// allows the stop reasonm, like "breakpoint hit", to be replaced
583     /// with a different stop reason like "no stop reason".
584     ///
585     /// This is specifically used for ARM in Thumb code when we stop in
586     /// an IT instruction (if/then/else) where the instruction won't get
587     /// executed and therefore it wouldn't be correct to show the program
588     /// stopped at the current PC. The code is generic and applies to all
589     /// ARM CPUs.
590     ///
591     /// @return NULL or a valid stop info override callback for the
592     ///     current architecture.
593     //------------------------------------------------------------------
594     StopInfoOverrideCallbackType
595     GetStopInfoOverrideCallback () const;
596     
597     bool
598     IsFullySpecifiedTriple () const;
599
600     void
601     PiecewiseTripleCompare (const ArchSpec &other,
602                             bool &arch_different,
603                             bool &vendor_different,
604                             bool &os_different,
605                             bool &os_version_different,
606                             bool &env_different);
607     
608     uint32_t
609     GetFlags () const
610     {
611         return m_flags;
612     }
613
614     void
615     SetFlags (uint32_t flags)
616     {
617         m_flags = flags;
618     }
619
620 protected:
621     bool
622     IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
623
624     llvm::Triple m_triple;
625     Core m_core;
626     lldb::ByteOrder m_byte_order;
627
628     // Additional arch flags which we cannot get from triple and core
629     // For MIPS these are application specific extensions like 
630     // micromips, mips16 etc.
631     uint32_t m_flags;
632
633     ConstString m_distribution_id;
634
635     // Called when m_def or m_entry are changed.  Fills in all remaining
636     // members with default values.
637     void
638     CoreUpdated (bool update_triple);
639 };
640
641 //------------------------------------------------------------------
642 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
643 /// @brief Less than operator.
644 ///
645 /// Tests two ArchSpec objects to see if \a lhs is less than \a
646 /// rhs.
647 ///
648 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
649 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
650 ///
651 /// @return true if \a lhs is less than \a rhs
652 //------------------------------------------------------------------
653 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
654
655 } // namespace lldb_private
656
657 #endif  // #if defined(__cplusplus)
658 #endif  // #ifndef liblldb_ArchSpec_h_