1 //===-- ArchSpec.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ArchSpec_h_
11 #define liblldb_ArchSpec_h_
13 #if defined(__cplusplus)
15 #include "lldb/lldb-forward.h"
16 #include "lldb/Core/ConstString.h"
17 #include "llvm/ADT/Triple.h"
19 namespace lldb_private {
21 struct CoreDefinition;
23 //----------------------------------------------------------------------
24 /// @class ArchSpec ArchSpec.h "lldb/Core/ArchSpec.h"
25 /// @brief An architecture specification class.
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 //----------------------------------------------------------------------
39 eMIPSSubType_mips32r2,
40 eMIPSSubType_mips32r6,
41 eMIPSSubType_mips32el,
42 eMIPSSubType_mips32r2el,
43 eMIPSSubType_mips32r6el,
45 eMIPSSubType_mips64r2,
46 eMIPSSubType_mips64r6,
47 eMIPSSubType_mips64el,
48 eMIPSSubType_mips64r2el,
49 eMIPSSubType_mips64r6el,
52 // Masks for the ases word of an ABI flags structure.
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_O64 = 0x00020000,
73 eMIPSABI_EABI32 = 0x00040000,
74 eMIPSABI_EABI64 = 0x00080000,
75 eMIPSABI_mask = 0x000ff000
78 // MIPS Floating point ABI Values
81 eMIPS_ABI_FP_ANY = 0x00000000,
82 eMIPS_ABI_FP_DOUBLE = 0x00100000, // hard float / -mdouble-float
83 eMIPS_ABI_FP_SINGLE = 0x00200000, // hard float / -msingle-float
84 eMIPS_ABI_FP_SOFT = 0x00300000, // soft float
85 eMIPS_ABI_FP_OLD_64 = 0x00400000, // -mips32r2 -mfp64
86 eMIPS_ABI_FP_XX = 0x00500000, // -mfpxx
87 eMIPS_ABI_FP_64 = 0x00600000, // -mips32r2 -mfp64
88 eMIPS_ABI_FP_64A = 0x00700000, // -mips32r2 -mfp64 -mno-odd-spreg
89 eMIPS_ABI_FP_mask = 0x00700000
92 // ARM specific e_flags
95 eARM_abi_soft_float = 0x00000200,
96 eARM_abi_hard_float = 0x00000400
169 eCore_ppc64_ppc970_64,
175 eCore_sparc9_generic,
183 eCore_x86_64_x86_64h, // Haswell enabled x86_64
184 eCore_hexagon_generic,
185 eCore_hexagon_hexagonv4,
186 eCore_hexagon_hexagonv5,
198 // The following constants are used for wildcard matching only
207 kCore_arm_first = eCore_arm_generic,
208 kCore_arm_last = eCore_arm_xscale,
210 kCore_thumb_first = eCore_thumb,
211 kCore_thumb_last = eCore_thumbv7em,
213 kCore_ppc_first = eCore_ppc_generic,
214 kCore_ppc_last = eCore_ppc_ppc970,
216 kCore_ppc64_first = eCore_ppc64_generic,
217 kCore_ppc64_last = eCore_ppc64_ppc970_64,
219 kCore_x86_32_first = eCore_x86_32_i386,
220 kCore_x86_32_last = eCore_x86_32_i686,
222 kCore_x86_64_first = eCore_x86_64_x86_64,
223 kCore_x86_64_last = eCore_x86_64_x86_64h,
225 kCore_hexagon_first = eCore_hexagon_generic,
226 kCore_hexagon_last = eCore_hexagon_hexagonv5,
228 kCore_kalimba_first = eCore_kalimba3,
229 kCore_kalimba_last = eCore_kalimba5,
231 kCore_mips32_first = eCore_mips32,
232 kCore_mips32_last = eCore_mips32r6,
234 kCore_mips32el_first = eCore_mips32el,
235 kCore_mips32el_last = eCore_mips32r6el,
237 kCore_mips64_first = eCore_mips64,
238 kCore_mips64_last = eCore_mips64r6,
240 kCore_mips64el_first = eCore_mips64el,
241 kCore_mips64el_last = eCore_mips64r6el,
243 kCore_mips_first = eCore_mips32,
244 kCore_mips_last = eCore_mips64r6el
248 typedef void (* StopInfoOverrideCallbackType)(lldb_private::Thread &thread);
250 //------------------------------------------------------------------
251 /// Default constructor.
253 /// Default constructor that initializes the object with invalid
254 /// cpu type and subtype values.
255 //------------------------------------------------------------------
258 //------------------------------------------------------------------
259 /// Constructor over triple.
261 /// Constructs an ArchSpec with properties consistent with the given
263 //------------------------------------------------------------------
265 ArchSpec (const llvm::Triple &triple);
267 ArchSpec (const char *triple_cstr);
269 ArchSpec (const char *triple_cstr, Platform *platform);
270 //------------------------------------------------------------------
271 /// Constructor over architecture name.
273 /// Constructs an ArchSpec with properties consistent with the given
274 /// object type and architecture name.
275 //------------------------------------------------------------------
277 ArchSpec (ArchitectureType arch_type,
279 uint32_t cpu_subtype);
281 //------------------------------------------------------------------
283 //------------------------------------------------------------------
286 //------------------------------------------------------------------
287 /// Assignment operator.
289 /// @param[in] rhs another ArchSpec object to copy.
291 /// @return A const reference to this object.
292 //------------------------------------------------------------------
294 operator= (const ArchSpec& rhs);
297 AutoComplete (const char *name,
298 StringList &matches);
300 //------------------------------------------------------------------
301 /// Returns a static string representing the current architecture.
303 /// @return A static string correcponding to the current
305 //------------------------------------------------------------------
307 GetArchitectureName () const;
309 //-----------------------------------------------------------------
310 /// if MIPS architecture return true.
312 /// @return a boolean value.
313 //-----------------------------------------------------------------
317 //------------------------------------------------------------------
318 /// Returns a string representing current architecture as a target CPU
319 /// for tools like compiler, disassembler etc.
321 /// @return A string representing target CPU for the current
323 //------------------------------------------------------------------
325 GetClangTargetCPU ();
327 //------------------------------------------------------------------
328 /// Clears the object state.
330 /// Clears the object state back to a default invalid state.
331 //------------------------------------------------------------------
335 //------------------------------------------------------------------
336 /// Returns the size in bytes of an address of the current
339 /// @return The byte size of an address of the current architecture.
340 //------------------------------------------------------------------
342 GetAddressByteSize () const;
344 //------------------------------------------------------------------
345 /// Returns a machine family for the current architecture.
347 /// @return An LLVM arch type.
348 //------------------------------------------------------------------
349 llvm::Triple::ArchType
352 //------------------------------------------------------------------
353 /// Returns the distribution id of the architecture.
355 /// This will be something like "ubuntu", "fedora", etc. on Linux.
357 /// @return A ConstString ref containing the distribution id,
358 /// potentially empty.
359 //------------------------------------------------------------------
361 GetDistributionId () const;
363 //------------------------------------------------------------------
364 /// Set the distribution id of the architecture.
366 /// This will be something like "ubuntu", "fedora", etc. on Linux.
367 /// This should be the same value returned by
368 /// HostInfo::GetDistributionId ().
369 ///------------------------------------------------------------------
371 SetDistributionId (const char* distribution_id);
373 //------------------------------------------------------------------
374 /// Tests if this ArchSpec is valid.
376 /// @return True if the current architecture is valid, false
378 //------------------------------------------------------------------
382 return m_core >= eCore_arm_generic && m_core < kNumCores;
386 TripleVendorWasSpecified() const
388 return !m_triple.getVendorName().empty();
392 TripleVendorIsUnspecifiedUnknown() const
394 return m_triple.getVendor() == llvm::Triple::UnknownVendor && m_triple.getVendorName().empty();
398 TripleOSWasSpecified() const
400 return !m_triple.getOSName().empty();
404 TripleEnvironmentWasSpecified () const
406 return !m_triple.getEnvironmentName().empty();
410 TripleOSIsUnspecifiedUnknown() const
412 return m_triple.getOS() == llvm::Triple::UnknownOS && m_triple.getOSName().empty();
415 //------------------------------------------------------------------
416 /// Merges fields from another ArchSpec into this ArchSpec.
418 /// This will use the supplied ArchSpec to fill in any fields of
419 /// the triple in this ArchSpec which were unspecified. This can
420 /// be used to refine a generic ArchSpec with a more specific one.
421 /// For example, if this ArchSpec's triple is something like
422 /// i386-unknown-unknown-unknown, and we have a triple which is
423 /// x64-pc-windows-msvc, then merging that triple into this one
424 /// will result in the triple i386-pc-windows-msvc.
426 //------------------------------------------------------------------
428 MergeFrom(const ArchSpec &other);
430 //------------------------------------------------------------------
431 /// Change the architecture object type, CPU type and OS type.
433 /// @param[in] arch_type The object type of this ArchSpec.
435 /// @param[in] cpu The required CPU type.
437 /// @param[in] os The optional OS type
438 /// The default value of 0 was choosen to from the ELF spec value
439 /// ELFOSABI_NONE. ELF is the only one using this parameter. If another
440 /// format uses this parameter and 0 does not work, use a value over
441 /// 255 because in the ELF header this is value is only a byte.
443 /// @return True if the object, and CPU were successfully set.
445 /// As a side effect, the vendor value is usually set to unknown.
446 /// The exections are
447 /// aarch64-apple-ios
453 /// As a side effect, the os value is usually set to unknown
454 /// The exceptions are
456 /// aarch64-apple-ios
459 /// powerpc-apple-darwin
465 //------------------------------------------------------------------
467 SetArchitecture (ArchitectureType arch_type,
472 //------------------------------------------------------------------
473 /// Returns the byte order for the architecture specification.
475 /// @return The endian enumeration for the current endianness of
476 /// the architecture specification
477 //------------------------------------------------------------------
479 GetByteOrder () const;
481 //------------------------------------------------------------------
482 /// Sets this ArchSpec's byte order.
484 /// In the common case there is no need to call this method as the
485 /// byte order can almost always be determined by the architecture.
486 /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
487 /// and the default/assumed byte order may be incorrect.
488 //------------------------------------------------------------------
490 SetByteOrder (lldb::ByteOrder byte_order)
492 m_byte_order = byte_order;
496 GetMinimumOpcodeByteSize() const;
499 GetMaximumOpcodeByteSize() const;
508 GetMachOCPUType () const;
511 GetMachOCPUSubType () const;
513 //------------------------------------------------------------------
514 /// Architecture data byte width accessor
516 /// @return the size in 8-bit (host) bytes of a minimum addressable
517 /// unit from the Architecture's data bus
518 //------------------------------------------------------------------
520 GetDataByteSize() const;
522 //------------------------------------------------------------------
523 /// Architecture code byte width accessor
525 /// @return the size in 8-bit (host) bytes of a minimum addressable
526 /// unit from the Architecture's code bus
527 //------------------------------------------------------------------
529 GetCodeByteSize() const;
531 //------------------------------------------------------------------
532 /// Architecture tripple accessor.
534 /// @return A triple describing this ArchSpec.
535 //------------------------------------------------------------------
542 //------------------------------------------------------------------
543 /// Architecture tripple accessor.
545 /// @return A triple describing this ArchSpec.
546 //------------------------------------------------------------------
554 DumpTriple(Stream &s) const;
556 //------------------------------------------------------------------
557 /// Architecture tripple setter.
559 /// Configures this ArchSpec according to the given triple. If the
560 /// triple has unknown components in all of the vendor, OS, and
561 /// the optional environment field (i.e. "i386-unknown-unknown")
562 /// then default values are taken from the host. Architecture and
563 /// environment components are used to further resolve the CPU type
564 /// and subtype, endian characteristics, etc.
566 /// @return A triple describing this ArchSpec.
567 //------------------------------------------------------------------
569 SetTriple (const llvm::Triple &triple);
572 SetTriple (const char *triple_cstr);
575 SetTriple (const char *triple_cstr,
578 //------------------------------------------------------------------
579 /// Returns the default endianness of the architecture.
581 /// @return The endian enumeration for the default endianness of
582 /// the architecture.
583 //------------------------------------------------------------------
585 GetDefaultEndian () const;
587 //------------------------------------------------------------------
588 /// Returns true if 'char' is a signed type by defualt in the
589 /// architecture false otherwise
591 /// @return True if 'char' is a signed type by default on the
592 /// architecture and false otherwise.
593 //------------------------------------------------------------------
595 CharIsSignedByDefault () const;
597 //------------------------------------------------------------------
598 /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu
599 /// type match between them.
600 /// e.g. armv7s is not an exact match with armv7 - this would return false
602 /// @return true if the two ArchSpecs match.
603 //------------------------------------------------------------------
605 IsExactMatch (const ArchSpec& rhs) const;
607 //------------------------------------------------------------------
608 /// Compare an ArchSpec to another ArchSpec, requiring a compatible
609 /// cpu type match between them.
610 /// e.g. armv7s is compatible with armv7 - this method would return true
612 /// @return true if the two ArchSpecs are compatible
613 //------------------------------------------------------------------
615 IsCompatibleMatch (const ArchSpec& rhs) const;
617 //------------------------------------------------------------------
618 /// Get a stop info override callback for the current architecture.
620 /// Most platform specific code should go in lldb_private::Platform,
621 /// but there are cases where no matter which platform you are on
622 /// certain things hold true.
624 /// This callback is currently intended to handle cases where a
625 /// program stops at an instruction that won't get executed and it
626 /// allows the stop reasonm, like "breakpoint hit", to be replaced
627 /// with a different stop reason like "no stop reason".
629 /// This is specifically used for ARM in Thumb code when we stop in
630 /// an IT instruction (if/then/else) where the instruction won't get
631 /// executed and therefore it wouldn't be correct to show the program
632 /// stopped at the current PC. The code is generic and applies to all
635 /// @return NULL or a valid stop info override callback for the
636 /// current architecture.
637 //------------------------------------------------------------------
638 StopInfoOverrideCallbackType
639 GetStopInfoOverrideCallback () const;
642 IsFullySpecifiedTriple () const;
645 PiecewiseTripleCompare (const ArchSpec &other,
646 bool &arch_different,
647 bool &vendor_different,
649 bool &os_version_different,
650 bool &env_different);
652 //------------------------------------------------------------------
653 /// Detect whether this architecture uses thumb code exclusively
655 /// Some embedded ARM chips (e.g. the ARM Cortex M0-7 line) can
656 /// only execute the Thumb instructions, never Arm. We should normally
657 /// pick up arm/thumbness from their the processor status bits (cpsr/xpsr)
658 /// or hints on each function - but when doing bare-boards low level
659 /// debugging (especially common with these embedded processors), we may
660 /// not have those things easily accessible.
662 /// @return true if this is an arm ArchSpec which can only execute Thumb
664 //------------------------------------------------------------------
666 IsAlwaysThumbInstructions () const;
675 SetFlags (uint32_t flags)
682 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
684 llvm::Triple m_triple;
686 lldb::ByteOrder m_byte_order;
688 // Additional arch flags which we cannot get from triple and core
689 // For MIPS these are application specific extensions like
690 // micromips, mips16 etc.
693 ConstString m_distribution_id;
695 // Called when m_def or m_entry are changed. Fills in all remaining
696 // members with default values.
698 CoreUpdated (bool update_triple);
701 //------------------------------------------------------------------
702 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
703 /// @brief Less than operator.
705 /// Tests two ArchSpec objects to see if \a lhs is less than \a
708 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
709 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
711 /// @return true if \a lhs is less than \a rhs
712 //------------------------------------------------------------------
713 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
715 } // namespace lldb_private
717 #endif // #if defined(__cplusplus)
718 #endif // #ifndef liblldb_ArchSpec_h_