10b57cec5SDimitry Andric //===-- ArchSpec.h ----------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef LLDB_UTILITY_ARCHSPEC_H 100b57cec5SDimitry Andric #define LLDB_UTILITY_ARCHSPEC_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "lldb/Utility/CompletionRequest.h" 130b57cec5SDimitry Andric #include "lldb/lldb-enumerations.h" 140b57cec5SDimitry Andric #include "lldb/lldb-forward.h" 150b57cec5SDimitry Andric #include "lldb/lldb-private-enumerations.h" 160b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h" 17*06c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h" 180b57cec5SDimitry Andric #include <cstddef> 190b57cec5SDimitry Andric #include <cstdint> 200b57cec5SDimitry Andric #include <string> 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric namespace lldb_private { 230b57cec5SDimitry Andric 240b57cec5SDimitry Andric /// \class ArchSpec ArchSpec.h "lldb/Utility/ArchSpec.h" An architecture 250b57cec5SDimitry Andric /// specification class. 260b57cec5SDimitry Andric /// 270b57cec5SDimitry Andric /// A class designed to be created from a cpu type and subtype, a 280b57cec5SDimitry Andric /// string representation, or an llvm::Triple. Keeping all of the conversions 290b57cec5SDimitry Andric /// of strings to architecture enumeration values confined to this class 300b57cec5SDimitry Andric /// allows new architecture support to be added easily. 310b57cec5SDimitry Andric class ArchSpec { 320b57cec5SDimitry Andric public: 330b57cec5SDimitry Andric enum MIPSSubType { 340b57cec5SDimitry Andric eMIPSSubType_unknown, 350b57cec5SDimitry Andric eMIPSSubType_mips32, 360b57cec5SDimitry Andric eMIPSSubType_mips32r2, 370b57cec5SDimitry Andric eMIPSSubType_mips32r6, 380b57cec5SDimitry Andric eMIPSSubType_mips32el, 390b57cec5SDimitry Andric eMIPSSubType_mips32r2el, 400b57cec5SDimitry Andric eMIPSSubType_mips32r6el, 410b57cec5SDimitry Andric eMIPSSubType_mips64, 420b57cec5SDimitry Andric eMIPSSubType_mips64r2, 430b57cec5SDimitry Andric eMIPSSubType_mips64r6, 440b57cec5SDimitry Andric eMIPSSubType_mips64el, 450b57cec5SDimitry Andric eMIPSSubType_mips64r2el, 460b57cec5SDimitry Andric eMIPSSubType_mips64r6el, 470b57cec5SDimitry Andric }; 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric // Masks for the ases word of an ABI flags structure. 500b57cec5SDimitry Andric enum MIPSASE { 510b57cec5SDimitry Andric eMIPSAse_dsp = 0x00000001, // DSP ASE 520b57cec5SDimitry Andric eMIPSAse_dspr2 = 0x00000002, // DSP R2 ASE 530b57cec5SDimitry Andric eMIPSAse_eva = 0x00000004, // Enhanced VA Scheme 540b57cec5SDimitry Andric eMIPSAse_mcu = 0x00000008, // MCU (MicroController) ASE 550b57cec5SDimitry Andric eMIPSAse_mdmx = 0x00000010, // MDMX ASE 560b57cec5SDimitry Andric eMIPSAse_mips3d = 0x00000020, // MIPS-3D ASE 570b57cec5SDimitry Andric eMIPSAse_mt = 0x00000040, // MT ASE 580b57cec5SDimitry Andric eMIPSAse_smartmips = 0x00000080, // SmartMIPS ASE 590b57cec5SDimitry Andric eMIPSAse_virt = 0x00000100, // VZ ASE 600b57cec5SDimitry Andric eMIPSAse_msa = 0x00000200, // MSA ASE 610b57cec5SDimitry Andric eMIPSAse_mips16 = 0x00000400, // MIPS16 ASE 620b57cec5SDimitry Andric eMIPSAse_micromips = 0x00000800, // MICROMIPS ASE 630b57cec5SDimitry Andric eMIPSAse_xpa = 0x00001000, // XPA ASE 640b57cec5SDimitry Andric eMIPSAse_mask = 0x00001fff, 650b57cec5SDimitry Andric eMIPSABI_O32 = 0x00002000, 660b57cec5SDimitry Andric eMIPSABI_N32 = 0x00004000, 670b57cec5SDimitry Andric eMIPSABI_N64 = 0x00008000, 680b57cec5SDimitry Andric eMIPSABI_O64 = 0x00020000, 690b57cec5SDimitry Andric eMIPSABI_EABI32 = 0x00040000, 700b57cec5SDimitry Andric eMIPSABI_EABI64 = 0x00080000, 710b57cec5SDimitry Andric eMIPSABI_mask = 0x000ff000 720b57cec5SDimitry Andric }; 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric // MIPS Floating point ABI Values 750b57cec5SDimitry Andric enum MIPS_ABI_FP { 760b57cec5SDimitry Andric eMIPS_ABI_FP_ANY = 0x00000000, 770b57cec5SDimitry Andric eMIPS_ABI_FP_DOUBLE = 0x00100000, // hard float / -mdouble-float 780b57cec5SDimitry Andric eMIPS_ABI_FP_SINGLE = 0x00200000, // hard float / -msingle-float 790b57cec5SDimitry Andric eMIPS_ABI_FP_SOFT = 0x00300000, // soft float 800b57cec5SDimitry Andric eMIPS_ABI_FP_OLD_64 = 0x00400000, // -mips32r2 -mfp64 810b57cec5SDimitry Andric eMIPS_ABI_FP_XX = 0x00500000, // -mfpxx 820b57cec5SDimitry Andric eMIPS_ABI_FP_64 = 0x00600000, // -mips32r2 -mfp64 830b57cec5SDimitry Andric eMIPS_ABI_FP_64A = 0x00700000, // -mips32r2 -mfp64 -mno-odd-spreg 840b57cec5SDimitry Andric eMIPS_ABI_FP_mask = 0x00700000 850b57cec5SDimitry Andric }; 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric // ARM specific e_flags 880b57cec5SDimitry Andric enum ARMeflags { 890b57cec5SDimitry Andric eARM_abi_soft_float = 0x00000200, 900b57cec5SDimitry Andric eARM_abi_hard_float = 0x00000400 910b57cec5SDimitry Andric }; 920b57cec5SDimitry Andric 9381ad6265SDimitry Andric enum RISCVeflags { 9481ad6265SDimitry Andric eRISCV_rvc = 0x00000001, /// RVC, +c 9581ad6265SDimitry Andric eRISCV_float_abi_soft = 0x00000000, /// soft float 9681ad6265SDimitry Andric eRISCV_float_abi_single = 0x00000002, /// single precision floating point, +f 9781ad6265SDimitry Andric eRISCV_float_abi_double = 0x00000004, /// double precision floating point, +d 9881ad6265SDimitry Andric eRISCV_float_abi_quad = 0x00000006, /// quad precision floating point, +q 9981ad6265SDimitry Andric eRISCV_float_abi_mask = 0x00000006, 10081ad6265SDimitry Andric eRISCV_rve = 0x00000008, /// RVE, +e 10181ad6265SDimitry Andric eRISCV_tso = 0x00000010, /// RVTSO (total store ordering) 10281ad6265SDimitry Andric }; 10381ad6265SDimitry Andric 104e8d8bef9SDimitry Andric enum RISCVSubType { 105e8d8bef9SDimitry Andric eRISCVSubType_unknown, 106e8d8bef9SDimitry Andric eRISCVSubType_riscv32, 107e8d8bef9SDimitry Andric eRISCVSubType_riscv64, 108e8d8bef9SDimitry Andric }; 109e8d8bef9SDimitry Andric 110bdd1243dSDimitry Andric enum LoongArchSubType { 111bdd1243dSDimitry Andric eLoongArchSubType_unknown, 112bdd1243dSDimitry Andric eLoongArchSubType_loongarch32, 113bdd1243dSDimitry Andric eLoongArchSubType_loongarch64, 114bdd1243dSDimitry Andric }; 115bdd1243dSDimitry Andric 1160b57cec5SDimitry Andric enum Core { 1170b57cec5SDimitry Andric eCore_arm_generic, 1180b57cec5SDimitry Andric eCore_arm_armv4, 1190b57cec5SDimitry Andric eCore_arm_armv4t, 1200b57cec5SDimitry Andric eCore_arm_armv5, 1210b57cec5SDimitry Andric eCore_arm_armv5e, 1220b57cec5SDimitry Andric eCore_arm_armv5t, 1230b57cec5SDimitry Andric eCore_arm_armv6, 1240b57cec5SDimitry Andric eCore_arm_armv6m, 1250b57cec5SDimitry Andric eCore_arm_armv7, 126480093f4SDimitry Andric eCore_arm_armv7l, 1270b57cec5SDimitry Andric eCore_arm_armv7f, 1280b57cec5SDimitry Andric eCore_arm_armv7s, 1290b57cec5SDimitry Andric eCore_arm_armv7k, 1300b57cec5SDimitry Andric eCore_arm_armv7m, 1310b57cec5SDimitry Andric eCore_arm_armv7em, 1320b57cec5SDimitry Andric eCore_arm_xscale, 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andric eCore_thumb, 1350b57cec5SDimitry Andric eCore_thumbv4t, 1360b57cec5SDimitry Andric eCore_thumbv5, 1370b57cec5SDimitry Andric eCore_thumbv5e, 1380b57cec5SDimitry Andric eCore_thumbv6, 1390b57cec5SDimitry Andric eCore_thumbv6m, 1400b57cec5SDimitry Andric eCore_thumbv7, 1410b57cec5SDimitry Andric eCore_thumbv7s, 1420b57cec5SDimitry Andric eCore_thumbv7k, 1430b57cec5SDimitry Andric eCore_thumbv7f, 1440b57cec5SDimitry Andric eCore_thumbv7m, 1450b57cec5SDimitry Andric eCore_thumbv7em, 1460b57cec5SDimitry Andric eCore_arm_arm64, 1470b57cec5SDimitry Andric eCore_arm_armv8, 148480093f4SDimitry Andric eCore_arm_armv8l, 149e8d8bef9SDimitry Andric eCore_arm_arm64e, 1509dba64beSDimitry Andric eCore_arm_arm64_32, 1510b57cec5SDimitry Andric eCore_arm_aarch64, 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andric eCore_mips32, 1540b57cec5SDimitry Andric eCore_mips32r2, 1550b57cec5SDimitry Andric eCore_mips32r3, 1560b57cec5SDimitry Andric eCore_mips32r5, 1570b57cec5SDimitry Andric eCore_mips32r6, 1580b57cec5SDimitry Andric eCore_mips32el, 1590b57cec5SDimitry Andric eCore_mips32r2el, 1600b57cec5SDimitry Andric eCore_mips32r3el, 1610b57cec5SDimitry Andric eCore_mips32r5el, 1620b57cec5SDimitry Andric eCore_mips32r6el, 1630b57cec5SDimitry Andric eCore_mips64, 1640b57cec5SDimitry Andric eCore_mips64r2, 1650b57cec5SDimitry Andric eCore_mips64r3, 1660b57cec5SDimitry Andric eCore_mips64r5, 1670b57cec5SDimitry Andric eCore_mips64r6, 1680b57cec5SDimitry Andric eCore_mips64el, 1690b57cec5SDimitry Andric eCore_mips64r2el, 1700b57cec5SDimitry Andric eCore_mips64r3el, 1710b57cec5SDimitry Andric eCore_mips64r5el, 1720b57cec5SDimitry Andric eCore_mips64r6el, 1730b57cec5SDimitry Andric 174*06c3fb27SDimitry Andric eCore_msp430, 175*06c3fb27SDimitry Andric 1760b57cec5SDimitry Andric eCore_ppc_generic, 1770b57cec5SDimitry Andric eCore_ppc_ppc601, 1780b57cec5SDimitry Andric eCore_ppc_ppc602, 1790b57cec5SDimitry Andric eCore_ppc_ppc603, 1800b57cec5SDimitry Andric eCore_ppc_ppc603e, 1810b57cec5SDimitry Andric eCore_ppc_ppc603ev, 1820b57cec5SDimitry Andric eCore_ppc_ppc604, 1830b57cec5SDimitry Andric eCore_ppc_ppc604e, 1840b57cec5SDimitry Andric eCore_ppc_ppc620, 1850b57cec5SDimitry Andric eCore_ppc_ppc750, 1860b57cec5SDimitry Andric eCore_ppc_ppc7400, 1870b57cec5SDimitry Andric eCore_ppc_ppc7450, 1880b57cec5SDimitry Andric eCore_ppc_ppc970, 1890b57cec5SDimitry Andric 1900b57cec5SDimitry Andric eCore_ppc64le_generic, 1910b57cec5SDimitry Andric eCore_ppc64_generic, 1920b57cec5SDimitry Andric eCore_ppc64_ppc970_64, 1930b57cec5SDimitry Andric 1940b57cec5SDimitry Andric eCore_s390x_generic, 1950b57cec5SDimitry Andric 1960b57cec5SDimitry Andric eCore_sparc_generic, 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andric eCore_sparc9_generic, 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andric eCore_x86_32_i386, 2010b57cec5SDimitry Andric eCore_x86_32_i486, 2020b57cec5SDimitry Andric eCore_x86_32_i486sx, 2030b57cec5SDimitry Andric eCore_x86_32_i686, 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andric eCore_x86_64_x86_64, 2060b57cec5SDimitry Andric eCore_x86_64_x86_64h, // Haswell enabled x86_64 2070b57cec5SDimitry Andric eCore_hexagon_generic, 2080b57cec5SDimitry Andric eCore_hexagon_hexagonv4, 2090b57cec5SDimitry Andric eCore_hexagon_hexagonv5, 2100b57cec5SDimitry Andric 211e8d8bef9SDimitry Andric eCore_riscv32, 212e8d8bef9SDimitry Andric eCore_riscv64, 213e8d8bef9SDimitry Andric 214bdd1243dSDimitry Andric eCore_loongarch32, 215bdd1243dSDimitry Andric eCore_loongarch64, 216bdd1243dSDimitry Andric 2170b57cec5SDimitry Andric eCore_uknownMach32, 2180b57cec5SDimitry Andric eCore_uknownMach64, 2190b57cec5SDimitry Andric 2209dba64beSDimitry Andric eCore_arc, // little endian ARC 2219dba64beSDimitry Andric 2225ffd83dbSDimitry Andric eCore_avr, 2235ffd83dbSDimitry Andric 2245ffd83dbSDimitry Andric eCore_wasm32, 2255ffd83dbSDimitry Andric 2260b57cec5SDimitry Andric kNumCores, 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric kCore_invalid, 2290b57cec5SDimitry Andric // The following constants are used for wildcard matching only 2300b57cec5SDimitry Andric kCore_any, 2310b57cec5SDimitry Andric kCore_arm_any, 2320b57cec5SDimitry Andric kCore_ppc_any, 2330b57cec5SDimitry Andric kCore_ppc64_any, 2340b57cec5SDimitry Andric kCore_x86_32_any, 2350b57cec5SDimitry Andric kCore_x86_64_any, 2360b57cec5SDimitry Andric kCore_hexagon_any, 2370b57cec5SDimitry Andric 2380b57cec5SDimitry Andric kCore_arm_first = eCore_arm_generic, 2390b57cec5SDimitry Andric kCore_arm_last = eCore_arm_xscale, 2400b57cec5SDimitry Andric 2410b57cec5SDimitry Andric kCore_thumb_first = eCore_thumb, 2420b57cec5SDimitry Andric kCore_thumb_last = eCore_thumbv7em, 2430b57cec5SDimitry Andric 2440b57cec5SDimitry Andric kCore_ppc_first = eCore_ppc_generic, 2450b57cec5SDimitry Andric kCore_ppc_last = eCore_ppc_ppc970, 2460b57cec5SDimitry Andric 2470b57cec5SDimitry Andric kCore_ppc64_first = eCore_ppc64_generic, 2480b57cec5SDimitry Andric kCore_ppc64_last = eCore_ppc64_ppc970_64, 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andric kCore_x86_32_first = eCore_x86_32_i386, 2510b57cec5SDimitry Andric kCore_x86_32_last = eCore_x86_32_i686, 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric kCore_x86_64_first = eCore_x86_64_x86_64, 2540b57cec5SDimitry Andric kCore_x86_64_last = eCore_x86_64_x86_64h, 2550b57cec5SDimitry Andric 2560b57cec5SDimitry Andric kCore_hexagon_first = eCore_hexagon_generic, 2570b57cec5SDimitry Andric kCore_hexagon_last = eCore_hexagon_hexagonv5, 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric kCore_mips32_first = eCore_mips32, 2600b57cec5SDimitry Andric kCore_mips32_last = eCore_mips32r6, 2610b57cec5SDimitry Andric 2620b57cec5SDimitry Andric kCore_mips32el_first = eCore_mips32el, 2630b57cec5SDimitry Andric kCore_mips32el_last = eCore_mips32r6el, 2640b57cec5SDimitry Andric 2650b57cec5SDimitry Andric kCore_mips64_first = eCore_mips64, 2660b57cec5SDimitry Andric kCore_mips64_last = eCore_mips64r6, 2670b57cec5SDimitry Andric 2680b57cec5SDimitry Andric kCore_mips64el_first = eCore_mips64el, 2690b57cec5SDimitry Andric kCore_mips64el_last = eCore_mips64r6el, 2700b57cec5SDimitry Andric 2710b57cec5SDimitry Andric kCore_mips_first = eCore_mips32, 2720b57cec5SDimitry Andric kCore_mips_last = eCore_mips64r6el 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric }; 2750b57cec5SDimitry Andric 2760b57cec5SDimitry Andric /// Default constructor. 2770b57cec5SDimitry Andric /// 2780b57cec5SDimitry Andric /// Default constructor that initializes the object with invalid cpu type 2790b57cec5SDimitry Andric /// and subtype values. 2800b57cec5SDimitry Andric ArchSpec(); 2810b57cec5SDimitry Andric 2820b57cec5SDimitry Andric /// Constructor over triple. 2830b57cec5SDimitry Andric /// 2840b57cec5SDimitry Andric /// Constructs an ArchSpec with properties consistent with the given Triple. 2850b57cec5SDimitry Andric explicit ArchSpec(const llvm::Triple &triple); 2860b57cec5SDimitry Andric explicit ArchSpec(const char *triple_cstr); 2870b57cec5SDimitry Andric explicit ArchSpec(llvm::StringRef triple_str); 2880b57cec5SDimitry Andric /// Constructor over architecture name. 2890b57cec5SDimitry Andric /// 2900b57cec5SDimitry Andric /// Constructs an ArchSpec with properties consistent with the given object 2910b57cec5SDimitry Andric /// type and architecture name. 2920b57cec5SDimitry Andric explicit ArchSpec(ArchitectureType arch_type, uint32_t cpu_type, 2930b57cec5SDimitry Andric uint32_t cpu_subtype); 2940b57cec5SDimitry Andric 2950b57cec5SDimitry Andric /// Destructor. 2960b57cec5SDimitry Andric ~ArchSpec(); 2970b57cec5SDimitry Andric 2980b57cec5SDimitry Andric /// Returns true if the OS, vendor and environment fields of the triple are 2990b57cec5SDimitry Andric /// unset. The triple is expected to be normalized 3000b57cec5SDimitry Andric /// (llvm::Triple::normalize). 3010b57cec5SDimitry Andric static bool ContainsOnlyArch(const llvm::Triple &normalized_triple); 3020b57cec5SDimitry Andric 3030b57cec5SDimitry Andric static void ListSupportedArchNames(StringList &list); 3049dba64beSDimitry Andric static void AutoComplete(CompletionRequest &request); 3050b57cec5SDimitry Andric 3060b57cec5SDimitry Andric /// Returns a static string representing the current architecture. 3070b57cec5SDimitry Andric /// 3080b57cec5SDimitry Andric /// \return A static string corresponding to the current 3090b57cec5SDimitry Andric /// architecture. 3100b57cec5SDimitry Andric const char *GetArchitectureName() const; 3110b57cec5SDimitry Andric 3120b57cec5SDimitry Andric /// if MIPS architecture return true. 3130b57cec5SDimitry Andric /// 3140b57cec5SDimitry Andric /// \return a boolean value. 3150b57cec5SDimitry Andric bool IsMIPS() const; 3160b57cec5SDimitry Andric 3170b57cec5SDimitry Andric /// Returns a string representing current architecture as a target CPU for 3180b57cec5SDimitry Andric /// tools like compiler, disassembler etc. 3190b57cec5SDimitry Andric /// 3200b57cec5SDimitry Andric /// \return A string representing target CPU for the current 3210b57cec5SDimitry Andric /// architecture. 3220b57cec5SDimitry Andric std::string GetClangTargetCPU() const; 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andric /// Return a string representing target application ABI. 3250b57cec5SDimitry Andric /// 3260b57cec5SDimitry Andric /// \return A string representing target application ABI. 3270b57cec5SDimitry Andric std::string GetTargetABI() const; 3280b57cec5SDimitry Andric 3290b57cec5SDimitry Andric /// Clears the object state. 3300b57cec5SDimitry Andric /// 3310b57cec5SDimitry Andric /// Clears the object state back to a default invalid state. 3320b57cec5SDimitry Andric void Clear(); 3330b57cec5SDimitry Andric 3340b57cec5SDimitry Andric /// Returns the size in bytes of an address of the current architecture. 3350b57cec5SDimitry Andric /// 3360b57cec5SDimitry Andric /// \return The byte size of an address of the current architecture. 3370b57cec5SDimitry Andric uint32_t GetAddressByteSize() const; 3380b57cec5SDimitry Andric 3390b57cec5SDimitry Andric /// Returns a machine family for the current architecture. 3400b57cec5SDimitry Andric /// 3410b57cec5SDimitry Andric /// \return An LLVM arch type. 3420b57cec5SDimitry Andric llvm::Triple::ArchType GetMachine() const; 3430b57cec5SDimitry Andric 3440b57cec5SDimitry Andric /// Tests if this ArchSpec is valid. 3450b57cec5SDimitry Andric /// 3460b57cec5SDimitry Andric /// \return True if the current architecture is valid, false 3470b57cec5SDimitry Andric /// otherwise. IsValid()3480b57cec5SDimitry Andric bool IsValid() const { 3490b57cec5SDimitry Andric return m_core >= eCore_arm_generic && m_core < kNumCores; 3500b57cec5SDimitry Andric } 3510b57cec5SDimitry Andric explicit operator bool() const { return IsValid(); } 3520b57cec5SDimitry Andric TripleVendorWasSpecified()3530b57cec5SDimitry Andric bool TripleVendorWasSpecified() const { 3540b57cec5SDimitry Andric return !m_triple.getVendorName().empty(); 3550b57cec5SDimitry Andric } 3560b57cec5SDimitry Andric TripleOSWasSpecified()3570b57cec5SDimitry Andric bool TripleOSWasSpecified() const { return !m_triple.getOSName().empty(); } 3580b57cec5SDimitry Andric TripleEnvironmentWasSpecified()3590b57cec5SDimitry Andric bool TripleEnvironmentWasSpecified() const { 3600b57cec5SDimitry Andric return m_triple.hasEnvironment(); 3610b57cec5SDimitry Andric } 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andric /// Merges fields from another ArchSpec into this ArchSpec. 3640b57cec5SDimitry Andric /// 3650b57cec5SDimitry Andric /// This will use the supplied ArchSpec to fill in any fields of the triple 3660b57cec5SDimitry Andric /// in this ArchSpec which were unspecified. This can be used to refine a 3670b57cec5SDimitry Andric /// generic ArchSpec with a more specific one. For example, if this 3680b57cec5SDimitry Andric /// ArchSpec's triple is something like i386-unknown-unknown-unknown, and we 3690b57cec5SDimitry Andric /// have a triple which is x64-pc-windows-msvc, then merging that triple 3700b57cec5SDimitry Andric /// into this one will result in the triple i386-pc-windows-msvc. 3710b57cec5SDimitry Andric /// 3720b57cec5SDimitry Andric void MergeFrom(const ArchSpec &other); 3730b57cec5SDimitry Andric 3740b57cec5SDimitry Andric /// Change the architecture object type, CPU type and OS type. 3750b57cec5SDimitry Andric /// 3760b57cec5SDimitry Andric /// \param[in] arch_type The object type of this ArchSpec. 3770b57cec5SDimitry Andric /// 3780b57cec5SDimitry Andric /// \param[in] cpu The required CPU type. 3790b57cec5SDimitry Andric /// 3800b57cec5SDimitry Andric /// \param[in] os The optional OS type 3810b57cec5SDimitry Andric /// The default value of 0 was chosen to from the ELF spec value 3820b57cec5SDimitry Andric /// ELFOSABI_NONE. ELF is the only one using this parameter. If another 3830b57cec5SDimitry Andric /// format uses this parameter and 0 does not work, use a value over 3840b57cec5SDimitry Andric /// 255 because in the ELF header this is value is only a byte. 3850b57cec5SDimitry Andric /// 3860b57cec5SDimitry Andric /// \return True if the object, and CPU were successfully set. 3870b57cec5SDimitry Andric /// 3880b57cec5SDimitry Andric /// As a side effect, the vendor value is usually set to unknown. The 3890b57cec5SDimitry Andric /// exceptions are 3900b57cec5SDimitry Andric /// aarch64-apple-ios 3910b57cec5SDimitry Andric /// arm-apple-ios 3920b57cec5SDimitry Andric /// thumb-apple-ios 3930b57cec5SDimitry Andric /// x86-apple- 3940b57cec5SDimitry Andric /// x86_64-apple- 3950b57cec5SDimitry Andric /// 3960b57cec5SDimitry Andric /// As a side effect, the os value is usually set to unknown The exceptions 3970b57cec5SDimitry Andric /// are 3980b57cec5SDimitry Andric /// *-*-aix 3990b57cec5SDimitry Andric /// aarch64-apple-ios 4000b57cec5SDimitry Andric /// arm-apple-ios 4010b57cec5SDimitry Andric /// thumb-apple-ios 4020b57cec5SDimitry Andric /// powerpc-apple-darwin 4030b57cec5SDimitry Andric /// *-*-freebsd 4040b57cec5SDimitry Andric /// *-*-linux 4050b57cec5SDimitry Andric /// *-*-netbsd 4060b57cec5SDimitry Andric /// *-*-openbsd 4070b57cec5SDimitry Andric /// *-*-solaris 4080b57cec5SDimitry Andric bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, 4090b57cec5SDimitry Andric uint32_t os = 0); 4100b57cec5SDimitry Andric 4110b57cec5SDimitry Andric /// Returns the byte order for the architecture specification. 4120b57cec5SDimitry Andric /// 4130b57cec5SDimitry Andric /// \return The endian enumeration for the current endianness of 4140b57cec5SDimitry Andric /// the architecture specification 4150b57cec5SDimitry Andric lldb::ByteOrder GetByteOrder() const; 4160b57cec5SDimitry Andric 4170b57cec5SDimitry Andric /// Sets this ArchSpec's byte order. 4180b57cec5SDimitry Andric /// 4190b57cec5SDimitry Andric /// In the common case there is no need to call this method as the byte 4200b57cec5SDimitry Andric /// order can almost always be determined by the architecture. However, many 4210b57cec5SDimitry Andric /// CPU's are bi-endian (ARM, Alpha, PowerPC, etc) and the default/assumed 4220b57cec5SDimitry Andric /// byte order may be incorrect. SetByteOrder(lldb::ByteOrder byte_order)4230b57cec5SDimitry Andric void SetByteOrder(lldb::ByteOrder byte_order) { m_byte_order = byte_order; } 4240b57cec5SDimitry Andric 4250b57cec5SDimitry Andric uint32_t GetMinimumOpcodeByteSize() const; 4260b57cec5SDimitry Andric 4270b57cec5SDimitry Andric uint32_t GetMaximumOpcodeByteSize() const; 4280b57cec5SDimitry Andric GetCore()4290b57cec5SDimitry Andric Core GetCore() const { return m_core; } 4300b57cec5SDimitry Andric 4310b57cec5SDimitry Andric uint32_t GetMachOCPUType() const; 4320b57cec5SDimitry Andric 4330b57cec5SDimitry Andric uint32_t GetMachOCPUSubType() const; 4340b57cec5SDimitry Andric 4350b57cec5SDimitry Andric /// Architecture data byte width accessor 4360b57cec5SDimitry Andric /// 4370b57cec5SDimitry Andric /// \return the size in 8-bit (host) bytes of a minimum addressable unit 4380b57cec5SDimitry Andric /// from the Architecture's data bus 4390b57cec5SDimitry Andric uint32_t GetDataByteSize() const; 4400b57cec5SDimitry Andric 4410b57cec5SDimitry Andric /// Architecture code byte width accessor 4420b57cec5SDimitry Andric /// 4430b57cec5SDimitry Andric /// \return the size in 8-bit (host) bytes of a minimum addressable unit 4440b57cec5SDimitry Andric /// from the Architecture's code bus 4450b57cec5SDimitry Andric uint32_t GetCodeByteSize() const; 4460b57cec5SDimitry Andric 4470b57cec5SDimitry Andric /// Architecture triple accessor. 4480b57cec5SDimitry Andric /// 4490b57cec5SDimitry Andric /// \return A triple describing this ArchSpec. GetTriple()4500b57cec5SDimitry Andric llvm::Triple &GetTriple() { return m_triple; } 4510b57cec5SDimitry Andric 4520b57cec5SDimitry Andric /// Architecture triple accessor. 4530b57cec5SDimitry Andric /// 4540b57cec5SDimitry Andric /// \return A triple describing this ArchSpec. GetTriple()4550b57cec5SDimitry Andric const llvm::Triple &GetTriple() const { return m_triple; } 4560b57cec5SDimitry Andric 457480093f4SDimitry Andric void DumpTriple(llvm::raw_ostream &s) const; 4580b57cec5SDimitry Andric 4590b57cec5SDimitry Andric /// Architecture triple setter. 4600b57cec5SDimitry Andric /// 4610b57cec5SDimitry Andric /// Configures this ArchSpec according to the given triple. If the triple 4620b57cec5SDimitry Andric /// has unknown components in all of the vendor, OS, and the optional 4630b57cec5SDimitry Andric /// environment field (i.e. "i386-unknown-unknown") then default values are 4640b57cec5SDimitry Andric /// taken from the host. Architecture and environment components are used 4650b57cec5SDimitry Andric /// to further resolve the CPU type and subtype, endian characteristics, 4660b57cec5SDimitry Andric /// etc. 4670b57cec5SDimitry Andric /// 4680b57cec5SDimitry Andric /// \return A triple describing this ArchSpec. 4690b57cec5SDimitry Andric bool SetTriple(const llvm::Triple &triple); 4700b57cec5SDimitry Andric 4710b57cec5SDimitry Andric bool SetTriple(llvm::StringRef triple_str); 4720b57cec5SDimitry Andric 4730b57cec5SDimitry Andric /// Returns the default endianness of the architecture. 4740b57cec5SDimitry Andric /// 4750b57cec5SDimitry Andric /// \return The endian enumeration for the default endianness of 4760b57cec5SDimitry Andric /// the architecture. 4770b57cec5SDimitry Andric lldb::ByteOrder GetDefaultEndian() const; 4780b57cec5SDimitry Andric 4790b57cec5SDimitry Andric /// Returns true if 'char' is a signed type by default in the architecture 4800b57cec5SDimitry Andric /// false otherwise 4810b57cec5SDimitry Andric /// 4820b57cec5SDimitry Andric /// \return True if 'char' is a signed type by default on the 4830b57cec5SDimitry Andric /// architecture and false otherwise. 4840b57cec5SDimitry Andric bool CharIsSignedByDefault() const; 4850b57cec5SDimitry Andric 486bdd1243dSDimitry Andric enum MatchType : bool { CompatibleMatch, ExactMatch }; 487bdd1243dSDimitry Andric 488bdd1243dSDimitry Andric /// Compare this ArchSpec to another ArchSpec. \a match specifies the kind of 489bdd1243dSDimitry Andric /// matching that is to be done. CompatibleMatch requires only a compatible 490bdd1243dSDimitry Andric /// cpu type (e.g., armv7s is compatible with armv7). ExactMatch requires an 491bdd1243dSDimitry Andric /// exact match (armv7s is not an exact match with armv7). 4920b57cec5SDimitry Andric /// 4930b57cec5SDimitry Andric /// \return true if the two ArchSpecs match. 494bdd1243dSDimitry Andric bool IsMatch(const ArchSpec &rhs, MatchType match) const; 4950b57cec5SDimitry Andric 496bdd1243dSDimitry Andric /// Shorthand for IsMatch(rhs, ExactMatch). IsExactMatch(const ArchSpec & rhs)497bdd1243dSDimitry Andric bool IsExactMatch(const ArchSpec &rhs) const { 498bdd1243dSDimitry Andric return IsMatch(rhs, ExactMatch); 499bdd1243dSDimitry Andric } 500bdd1243dSDimitry Andric 501bdd1243dSDimitry Andric /// Shorthand for IsMatch(rhs, CompatibleMatch). IsCompatibleMatch(const ArchSpec & rhs)502bdd1243dSDimitry Andric bool IsCompatibleMatch(const ArchSpec &rhs) const { 503bdd1243dSDimitry Andric return IsMatch(rhs, CompatibleMatch); 504bdd1243dSDimitry Andric } 5050b57cec5SDimitry Andric 5060b57cec5SDimitry Andric bool IsFullySpecifiedTriple() const; 5070b57cec5SDimitry Andric 5080b57cec5SDimitry Andric /// Detect whether this architecture uses thumb code exclusively 5090b57cec5SDimitry Andric /// 5100b57cec5SDimitry Andric /// Some embedded ARM chips (e.g. the ARM Cortex M0-7 line) can only execute 5110b57cec5SDimitry Andric /// the Thumb instructions, never Arm. We should normally pick up 5120b57cec5SDimitry Andric /// arm/thumbness from their the processor status bits (cpsr/xpsr) or hints 5130b57cec5SDimitry Andric /// on each function - but when doing bare-boards low level debugging 5140b57cec5SDimitry Andric /// (especially common with these embedded processors), we may not have 5150b57cec5SDimitry Andric /// those things easily accessible. 5160b57cec5SDimitry Andric /// 5170b57cec5SDimitry Andric /// \return true if this is an arm ArchSpec which can only execute Thumb 5180b57cec5SDimitry Andric /// instructions 5190b57cec5SDimitry Andric bool IsAlwaysThumbInstructions() const; 5200b57cec5SDimitry Andric GetFlags()5210b57cec5SDimitry Andric uint32_t GetFlags() const { return m_flags; } 5220b57cec5SDimitry Andric SetFlags(uint32_t flags)5230b57cec5SDimitry Andric void SetFlags(uint32_t flags) { m_flags = flags; } 5240b57cec5SDimitry Andric 525e8d8bef9SDimitry Andric void SetFlags(const std::string &elf_abi); 5260b57cec5SDimitry Andric 5270b57cec5SDimitry Andric protected: 5280b57cec5SDimitry Andric void UpdateCore(); 5290b57cec5SDimitry Andric 5300b57cec5SDimitry Andric llvm::Triple m_triple; 5310b57cec5SDimitry Andric Core m_core = kCore_invalid; 5320b57cec5SDimitry Andric lldb::ByteOrder m_byte_order = lldb::eByteOrderInvalid; 5330b57cec5SDimitry Andric 5340b57cec5SDimitry Andric // Additional arch flags which we cannot get from triple and core For MIPS 5350b57cec5SDimitry Andric // these are application specific extensions like micromips, mips16 etc. 5360b57cec5SDimitry Andric uint32_t m_flags = 0; 5370b57cec5SDimitry Andric 5380b57cec5SDimitry Andric // Called when m_def or m_entry are changed. Fills in all remaining members 5390b57cec5SDimitry Andric // with default values. 5400b57cec5SDimitry Andric void CoreUpdated(bool update_triple); 5410b57cec5SDimitry Andric }; 5420b57cec5SDimitry Andric 5430b57cec5SDimitry Andric /// \fn bool operator< (const ArchSpec& lhs, const ArchSpec& rhs) Less than 5440b57cec5SDimitry Andric /// operator. 5450b57cec5SDimitry Andric /// 5460b57cec5SDimitry Andric /// Tests two ArchSpec objects to see if \a lhs is less than \a rhs. 5470b57cec5SDimitry Andric /// 5480b57cec5SDimitry Andric /// \param[in] lhs The Left Hand Side ArchSpec object to compare. \param[in] 5490b57cec5SDimitry Andric /// rhs The Left Hand Side ArchSpec object to compare. 5500b57cec5SDimitry Andric /// 5510b57cec5SDimitry Andric /// \return true if \a lhs is less than \a rhs 5520b57cec5SDimitry Andric bool operator<(const ArchSpec &lhs, const ArchSpec &rhs); 5530b57cec5SDimitry Andric bool operator==(const ArchSpec &lhs, const ArchSpec &rhs); 5540b57cec5SDimitry Andric 5550b57cec5SDimitry Andric bool ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch); 5560b57cec5SDimitry Andric 5570b57cec5SDimitry Andric } // namespace lldb_private 5580b57cec5SDimitry Andric 5595ffd83dbSDimitry Andric #endif // LLDB_UTILITY_ARCHSPEC_H 560