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
141 eCore_ppc64_ppc970_64,
145 eCore_sparc9_generic,
153 eCore_x86_64_x86_64h, // Haswell enabled x86_64
154 eCore_hexagon_generic,
155 eCore_hexagon_hexagonv4,
156 eCore_hexagon_hexagonv5,
168 // The following constants are used for wildcard matching only
177 kCore_arm_first = eCore_arm_generic,
178 kCore_arm_last = eCore_arm_xscale,
180 kCore_thumb_first = eCore_thumb,
181 kCore_thumb_last = eCore_thumbv7em,
183 kCore_ppc_first = eCore_ppc_generic,
184 kCore_ppc_last = eCore_ppc_ppc970,
186 kCore_ppc64_first = eCore_ppc64_generic,
187 kCore_ppc64_last = eCore_ppc64_ppc970_64,
189 kCore_x86_32_first = eCore_x86_32_i386,
190 kCore_x86_32_last = eCore_x86_32_i686,
192 kCore_x86_64_first = eCore_x86_64_x86_64,
193 kCore_x86_64_last = eCore_x86_64_x86_64h,
195 kCore_hexagon_first = eCore_hexagon_generic,
196 kCore_hexagon_last = eCore_hexagon_hexagonv5,
198 kCore_kalimba_first = eCore_kalimba3,
199 kCore_kalimba_last = eCore_kalimba5,
201 kCore_mips32_first = eCore_mips32,
202 kCore_mips32_last = eCore_mips32r6,
204 kCore_mips32el_first = eCore_mips32el,
205 kCore_mips32el_last = eCore_mips32r6el,
207 kCore_mips64_first = eCore_mips64,
208 kCore_mips64_last = eCore_mips64r6,
210 kCore_mips64el_first = eCore_mips64el,
211 kCore_mips64el_last = eCore_mips64r6el
214 typedef void (* StopInfoOverrideCallbackType)(lldb_private::Thread &thread);
216 //------------------------------------------------------------------
217 /// Default constructor.
219 /// Default constructor that initializes the object with invalid
220 /// cpu type and subtype values.
221 //------------------------------------------------------------------
224 //------------------------------------------------------------------
225 /// Constructor over triple.
227 /// Constructs an ArchSpec with properties consistent with the given
229 //------------------------------------------------------------------
231 ArchSpec (const llvm::Triple &triple);
233 ArchSpec (const char *triple_cstr);
235 ArchSpec (const char *triple_cstr, Platform *platform);
236 //------------------------------------------------------------------
237 /// Constructor over architecture name.
239 /// Constructs an ArchSpec with properties consistent with the given
240 /// object type and architecture name.
241 //------------------------------------------------------------------
243 ArchSpec (ArchitectureType arch_type,
245 uint32_t cpu_subtype);
247 //------------------------------------------------------------------
249 //------------------------------------------------------------------
252 //------------------------------------------------------------------
253 /// Assignment operator.
255 /// @param[in] rhs another ArchSpec object to copy.
257 /// @return A const reference to this object.
258 //------------------------------------------------------------------
260 operator= (const ArchSpec& rhs);
263 AutoComplete (const char *name,
264 StringList &matches);
266 //------------------------------------------------------------------
267 /// Returns a static string representing the current architecture.
269 /// @return A static string correcponding to the current
271 //------------------------------------------------------------------
273 GetArchitectureName () const;
275 //------------------------------------------------------------------
276 /// Clears the object state.
278 /// Clears the object state back to a default invalid state.
279 //------------------------------------------------------------------
283 //------------------------------------------------------------------
284 /// Returns the size in bytes of an address of the current
287 /// @return The byte size of an address of the current architecture.
288 //------------------------------------------------------------------
290 GetAddressByteSize () const;
292 //------------------------------------------------------------------
293 /// Returns a machine family for the current architecture.
295 /// @return An LLVM arch type.
296 //------------------------------------------------------------------
297 llvm::Triple::ArchType
300 //------------------------------------------------------------------
301 /// Returns the distribution id of the architecture.
303 /// This will be something like "ubuntu", "fedora", etc. on Linux.
305 /// @return A ConstString ref containing the distribution id,
306 /// potentially empty.
307 //------------------------------------------------------------------
309 GetDistributionId () const;
311 //------------------------------------------------------------------
312 /// Set the distribution id of the architecture.
314 /// This will be something like "ubuntu", "fedora", etc. on Linux.
315 /// This should be the same value returned by
316 /// HostInfo::GetDistributionId ().
317 ///------------------------------------------------------------------
319 SetDistributionId (const char* distribution_id);
321 //------------------------------------------------------------------
322 /// Tests if this ArchSpec is valid.
324 /// @return True if the current architecture is valid, false
326 //------------------------------------------------------------------
330 return m_core >= eCore_arm_generic && m_core < kNumCores;
334 TripleVendorWasSpecified() const
336 return !m_triple.getVendorName().empty();
340 TripleOSWasSpecified() const
342 return !m_triple.getOSName().empty();
345 //------------------------------------------------------------------
346 /// Merges fields from another ArchSpec into this ArchSpec.
348 /// This will use the supplied ArchSpec to fill in any fields of
349 /// the triple in this ArchSpec which were unspecified. This can
350 /// be used to refine a generic ArchSpec with a more specific one.
351 /// For example, if this ArchSpec's triple is something like
352 /// i386-unknown-unknown-unknown, and we have a triple which is
353 /// x64-pc-windows-msvc, then merging that triple into this one
354 /// will result in the triple i386-pc-windows-msvc.
356 //------------------------------------------------------------------
358 MergeFrom(const ArchSpec &other);
360 //------------------------------------------------------------------
361 /// Change the architecture object type, CPU type and OS type.
363 /// @param[in] arch_type The object type of this ArchSpec.
365 /// @param[in] cpu The required CPU type.
367 /// @param[in] os The optional OS type
368 /// The default value of 0 was choosen to from the ELF spec value
369 /// ELFOSABI_NONE. ELF is the only one using this parameter. If another
370 /// format uses this parameter and 0 does not work, use a value over
371 /// 255 because in the ELF header this is value is only a byte.
373 /// @return True if the object, and CPU were successfully set.
375 /// As a side effect, the vendor value is usually set to unknown.
376 /// The exections are
377 /// aarch64-apple-ios
383 /// As a side effect, the os value is usually set to unknown
384 /// The exceptions are
386 /// aarch64-apple-ios
389 /// powerpc-apple-darwin
395 //------------------------------------------------------------------
397 SetArchitecture (ArchitectureType arch_type,
402 //------------------------------------------------------------------
403 /// Returns the byte order for the architecture specification.
405 /// @return The endian enumeration for the current endianness of
406 /// the architecture specification
407 //------------------------------------------------------------------
409 GetByteOrder () const;
411 //------------------------------------------------------------------
412 /// Sets this ArchSpec's byte order.
414 /// In the common case there is no need to call this method as the
415 /// byte order can almost always be determined by the architecture.
416 /// However, many CPU's are bi-endian (ARM, Alpha, PowerPC, etc)
417 /// and the default/assumed byte order may be incorrect.
418 //------------------------------------------------------------------
420 SetByteOrder (lldb::ByteOrder byte_order)
422 m_byte_order = byte_order;
426 GetMinimumOpcodeByteSize() const;
429 GetMaximumOpcodeByteSize() const;
438 GetMachOCPUType () const;
441 GetMachOCPUSubType () const;
443 //------------------------------------------------------------------
444 /// Architecture data byte width accessor
446 /// @return the size in 8-bit (host) bytes of a minimum addressable
447 /// unit from the Architecture's data bus
448 //------------------------------------------------------------------
450 GetDataByteSize() const;
452 //------------------------------------------------------------------
453 /// Architecture code byte width accessor
455 /// @return the size in 8-bit (host) bytes of a minimum addressable
456 /// unit from the Architecture's code bus
457 //------------------------------------------------------------------
459 GetCodeByteSize() const;
461 //------------------------------------------------------------------
462 /// Architecture tripple accessor.
464 /// @return A triple describing this ArchSpec.
465 //------------------------------------------------------------------
472 //------------------------------------------------------------------
473 /// Architecture tripple accessor.
475 /// @return A triple describing this ArchSpec.
476 //------------------------------------------------------------------
483 //------------------------------------------------------------------
484 /// Architecture tripple setter.
486 /// Configures this ArchSpec according to the given triple. If the
487 /// triple has unknown components in all of the vendor, OS, and
488 /// the optional environment field (i.e. "i386-unknown-unknown")
489 /// then default values are taken from the host. Architecture and
490 /// environment components are used to further resolve the CPU type
491 /// and subtype, endian characteristics, etc.
493 /// @return A triple describing this ArchSpec.
494 //------------------------------------------------------------------
496 SetTriple (const llvm::Triple &triple);
499 SetTriple (const char *triple_cstr);
502 SetTriple (const char *triple_cstr,
505 //------------------------------------------------------------------
506 /// Returns the default endianness of the architecture.
508 /// @return The endian enumeration for the default endianness of
509 /// the architecture.
510 //------------------------------------------------------------------
512 GetDefaultEndian () const;
514 //------------------------------------------------------------------
515 /// Returns true if 'char' is a signed type by defualt in the
516 /// architecture false otherwise
518 /// @return True if 'char' is a signed type by default on the
519 /// architecture and false otherwise.
520 //------------------------------------------------------------------
522 CharIsSignedByDefault () const;
524 //------------------------------------------------------------------
525 /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu
526 /// type match between them.
527 /// e.g. armv7s is not an exact match with armv7 - this would return false
529 /// @return true if the two ArchSpecs match.
530 //------------------------------------------------------------------
532 IsExactMatch (const ArchSpec& rhs) const;
534 //------------------------------------------------------------------
535 /// Compare an ArchSpec to another ArchSpec, requiring a compatible
536 /// cpu type match between them.
537 /// e.g. armv7s is compatible with armv7 - this method would return true
539 /// @return true if the two ArchSpecs are compatible
540 //------------------------------------------------------------------
542 IsCompatibleMatch (const ArchSpec& rhs) const;
544 //------------------------------------------------------------------
545 /// Get a stop info override callback for the current architecture.
547 /// Most platform specific code should go in lldb_private::Platform,
548 /// but there are cases where no matter which platform you are on
549 /// certain things hold true.
551 /// This callback is currently intended to handle cases where a
552 /// program stops at an instruction that won't get executed and it
553 /// allows the stop reasonm, like "breakpoint hit", to be replaced
554 /// with a different stop reason like "no stop reason".
556 /// This is specifically used for ARM in Thumb code when we stop in
557 /// an IT instruction (if/then/else) where the instruction won't get
558 /// executed and therefore it wouldn't be correct to show the program
559 /// stopped at the current PC. The code is generic and applies to all
562 /// @return NULL or a valid stop info override callback for the
563 /// current architecture.
564 //------------------------------------------------------------------
565 StopInfoOverrideCallbackType
566 GetStopInfoOverrideCallback () const;
575 SetFlags (uint32_t flags)
582 IsEqualTo (const ArchSpec& rhs, bool exact_match) const;
584 llvm::Triple m_triple;
586 lldb::ByteOrder m_byte_order;
588 // Additional arch flags which we cannot get from triple and core
589 // For MIPS these are application specific extensions like
590 // micromips, mips16 etc.
593 ConstString m_distribution_id;
595 // Called when m_def or m_entry are changed. Fills in all remaining
596 // members with default values.
598 CoreUpdated (bool update_triple);
601 //------------------------------------------------------------------
602 /// @fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs)
603 /// @brief Less than operator.
605 /// Tests two ArchSpec objects to see if \a lhs is less than \a
608 /// @param[in] lhs The Left Hand Side ArchSpec object to compare.
609 /// @param[in] rhs The Left Hand Side ArchSpec object to compare.
611 /// @return true if \a lhs is less than \a rhs
612 //------------------------------------------------------------------
613 bool operator< (const ArchSpec& lhs, const ArchSpec& rhs);
615 } // namespace lldb_private
617 #endif // #if defined(__cplusplus)
618 #endif // #ifndef liblldb_ArchSpec_h_