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_mask = 0x000ff000
145 eCore_ppc64_ppc970_64,
149 eCore_sparc9_generic,
157 eCore_x86_64_x86_64h, // Haswell enabled x86_64
158 eCore_hexagon_generic,
159 eCore_hexagon_hexagonv4,
160 eCore_hexagon_hexagonv5,
172 // The following constants are used for wildcard matching only
181 kCore_arm_first = eCore_arm_generic,
182 kCore_arm_last = eCore_arm_xscale,
184 kCore_thumb_first = eCore_thumb,
185 kCore_thumb_last = eCore_thumbv7em,
187 kCore_ppc_first = eCore_ppc_generic,
188 kCore_ppc_last = eCore_ppc_ppc970,
190 kCore_ppc64_first = eCore_ppc64_generic,
191 kCore_ppc64_last = eCore_ppc64_ppc970_64,
193 kCore_x86_32_first = eCore_x86_32_i386,
194 kCore_x86_32_last = eCore_x86_32_i686,
196 kCore_x86_64_first = eCore_x86_64_x86_64,
197 kCore_x86_64_last = eCore_x86_64_x86_64h,
199 kCore_hexagon_first = eCore_hexagon_generic,
200 kCore_hexagon_last = eCore_hexagon_hexagonv5,
202 kCore_kalimba_first = eCore_kalimba3,
203 kCore_kalimba_last = eCore_kalimba5,
205 kCore_mips32_first = eCore_mips32,
206 kCore_mips32_last = eCore_mips32r6,
208 kCore_mips32el_first = eCore_mips32el,
209 kCore_mips32el_last = eCore_mips32r6el,
211 kCore_mips64_first = eCore_mips64,
212 kCore_mips64_last = eCore_mips64r6,
214 kCore_mips64el_first = eCore_mips64el,
215 kCore_mips64el_last = eCore_mips64r6el,
217 kCore_mips_first = eCore_mips32,
218 kCore_mips_last = eCore_mips64r6el
222 typedef void (* StopInfoOverrideCallbackType)(lldb_private::Thread &thread);
224 //------------------------------------------------------------------
225 /// Default constructor.
227 /// Default constructor that initializes the object with invalid
228 /// cpu type and subtype values.
229 //------------------------------------------------------------------
232 //------------------------------------------------------------------
233 /// Constructor over triple.
235 /// Constructs an ArchSpec with properties consistent with the given
237 //------------------------------------------------------------------
239 ArchSpec (const llvm::Triple &triple);
241 ArchSpec (const char *triple_cstr);
243 ArchSpec (const char *triple_cstr, Platform *platform);
244 //------------------------------------------------------------------
245 /// Constructor over architecture name.
247 /// Constructs an ArchSpec with properties consistent with the given
248 /// object type and architecture name.
249 //------------------------------------------------------------------
251 ArchSpec (ArchitectureType arch_type,
253 uint32_t cpu_subtype);
255 //------------------------------------------------------------------
257 //------------------------------------------------------------------
260 //------------------------------------------------------------------
261 /// Assignment operator.
263 /// @param[in] rhs another ArchSpec object to copy.
265 /// @return A const reference to this object.
266 //------------------------------------------------------------------
268 operator= (const ArchSpec& rhs);
271 AutoComplete (const char *name,
272 StringList &matches);
274 //------------------------------------------------------------------
275 /// Returns a static string representing the current architecture.
277 /// @return A static string correcponding to the current
279 //------------------------------------------------------------------
281 GetArchitectureName () const;
283 //------------------------------------------------------------------
284 /// Clears the object state.
286 /// Clears the object state back to a default invalid state.
287 //------------------------------------------------------------------
291 //------------------------------------------------------------------
292 /// Returns the size in bytes of an address of the current
295 /// @return The byte size of an address of the current architecture.
296 //------------------------------------------------------------------
298 GetAddressByteSize () const;
300 //------------------------------------------------------------------
301 /// Returns a machine family for the current architecture.
303 /// @return An LLVM arch type.
304 //------------------------------------------------------------------
305 llvm::Triple::ArchType
308 //------------------------------------------------------------------
309 /// Returns the distribution id of the architecture.
311 /// This will be something like "ubuntu", "fedora", etc. on Linux.
313 /// @return A ConstString ref containing the distribution id,
314 /// potentially empty.
315 //------------------------------------------------------------------
317 GetDistributionId () const;
319 //------------------------------------------------------------------
320 /// Set the distribution id of the architecture.
322 /// This will be something like "ubuntu", "fedora", etc. on Linux.
323 /// This should be the same value returned by
324 /// HostInfo::GetDistributionId ().
325 ///------------------------------------------------------------------
327 SetDistributionId (const char* distribution_id);
329 //------------------------------------------------------------------
330 /// Tests if this ArchSpec is valid.
332 /// @return True if the current architecture is valid, false
334 //------------------------------------------------------------------
338 return m_core >= eCore_arm_generic && m_core < kNumCores;
342 TripleVendorWasSpecified() const
344 return !m_triple.getVendorName().empty();
348 TripleVendorIsUnspecifiedUnknown() const
350 return m_triple.getVendor() == llvm::Triple::UnknownVendor && m_triple.getVendorName().empty();
354 TripleOSWasSpecified() const
356 return !m_triple.getOSName().empty();
360 TripleEnvironmentWasSpecified () const
362 return !m_triple.getEnvironmentName().empty();
366 TripleOSIsUnspecifiedUnknown() const
368 return m_triple.getOS() == llvm::Triple::UnknownOS && m_triple.getOSName().empty();
371 //------------------------------------------------------------------
372 /// Merges fields from another ArchSpec into this ArchSpec.
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.
382 //------------------------------------------------------------------
384 MergeFrom(const ArchSpec &other);
386 //------------------------------------------------------------------
387 /// Change the architecture object type, CPU type and OS type.
389 /// @param[in] arch_type The object type of this ArchSpec.
391 /// @param[in] cpu The required CPU type.
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.
399 /// @return True if the object, and CPU were successfully set.
401 /// As a side effect, the vendor value is usually set to unknown.
402 /// The exections are
403 /// aarch64-apple-ios
409 /// As a side effect, the os value is usually set to unknown
410 /// The exceptions are
412 /// aarch64-apple-ios
415 /// powerpc-apple-darwin
421 //------------------------------------------------------------------
423 SetArchitecture (ArchitectureType arch_type,
428 //------------------------------------------------------------------
429 /// Returns the byte order for the architecture specification.
431 /// @return The endian enumeration for the current endianness of
432 /// the architecture specification
433 //------------------------------------------------------------------
435 GetByteOrder () const;
437 //------------------------------------------------------------------
438 /// Sets this ArchSpec's byte order.
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 //------------------------------------------------------------------
446 SetByteOrder (lldb::ByteOrder byte_order)
448 m_byte_order = byte_order;
452 GetMinimumOpcodeByteSize() const;
455 GetMaximumOpcodeByteSize() const;
464 GetMachOCPUType () const;
467 GetMachOCPUSubType () const;
469 //------------------------------------------------------------------
470 /// Architecture data byte width accessor
472 /// @return the size in 8-bit (host) bytes of a minimum addressable
473 /// unit from the Architecture's data bus
474 //------------------------------------------------------------------
476 GetDataByteSize() const;
478 //------------------------------------------------------------------
479 /// Architecture code byte width accessor
481 /// @return the size in 8-bit (host) bytes of a minimum addressable
482 /// unit from the Architecture's code bus
483 //------------------------------------------------------------------
485 GetCodeByteSize() const;
487 //------------------------------------------------------------------
488 /// Architecture tripple accessor.
490 /// @return A triple describing this ArchSpec.
491 //------------------------------------------------------------------
498 //------------------------------------------------------------------
499 /// Architecture tripple accessor.
501 /// @return A triple describing this ArchSpec.
502 //------------------------------------------------------------------
510 DumpTriple(Stream &s) const;
512 //------------------------------------------------------------------
513 /// Architecture tripple setter.
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.
522 /// @return A triple describing this ArchSpec.
523 //------------------------------------------------------------------
525 SetTriple (const llvm::Triple &triple);
528 SetTriple (const char *triple_cstr);
531 SetTriple (const char *triple_cstr,
534 //------------------------------------------------------------------
535 /// Returns the default endianness of the architecture.
537 /// @return The endian enumeration for the default endianness of
538 /// the architecture.
539 //------------------------------------------------------------------
541 GetDefaultEndian () const;
543 //------------------------------------------------------------------
544 /// Returns true if 'char' is a signed type by defualt in the
545 /// architecture false otherwise
547 /// @return True if 'char' is a signed type by default on the
548 /// architecture and false otherwise.
549 //------------------------------------------------------------------
551 CharIsSignedByDefault () const;
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
558 /// @return true if the two ArchSpecs match.
559 //------------------------------------------------------------------
561 IsExactMatch (const ArchSpec& rhs) const;
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
568 /// @return true if the two ArchSpecs are compatible
569 //------------------------------------------------------------------
571 IsCompatibleMatch (const ArchSpec& rhs) const;
573 //------------------------------------------------------------------
574 /// Get a stop info override callback for the current architecture.
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.
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".
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
591 /// @return NULL or a valid stop info override callback for the
592 /// current architecture.
593 //------------------------------------------------------------------
594 StopInfoOverrideCallbackType
595 GetStopInfoOverrideCallback () const;
598 IsFullySpecifiedTriple () const;
601 PiecewiseTripleCompare (const ArchSpec &other,
602 bool &arch_different,
603 bool &vendor_different,
605 bool &os_version_different,
606 bool &env_different);
615 SetFlags (uint32_t flags)
622 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
624 llvm::Triple m_triple;
626 lldb::ByteOrder m_byte_order;
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.
633 ConstString m_distribution_id;
635 // Called when m_def or m_entry are changed. Fills in all remaining
636 // members with default values.
638 CoreUpdated (bool update_triple);
641 //------------------------------------------------------------------
642 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
643 /// @brief Less than operator.
645 /// Tests two ArchSpec objects to see if \a lhs is less than \a
648 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
649 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
651 /// @return true if \a lhs is less than \a rhs
652 //------------------------------------------------------------------
653 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
655 } // namespace lldb_private
657 #endif // #if defined(__cplusplus)
658 #endif // #ifndef liblldb_ArchSpec_h_