Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Process/Utility/ARMDefines.h
39642 views
//===-- ARMDefines.h --------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_ARMDEFINES_H9#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_ARMDEFINES_H1011#include "llvm/Support/ErrorHandling.h"1213#include <cassert>14#include <cstdint>1516// Common definitions for the ARM/Thumb Instruction Set Architecture.1718namespace lldb_private {1920// ARM shifter types21enum ARM_ShifterType {22SRType_LSL,23SRType_LSR,24SRType_ASR,25SRType_ROR,26SRType_RRX,27SRType_Invalid28};2930// ARM conditions // Meaning (integer) Meaning (floating-point)31// Condition flags32#define COND_EQ \330x0 // Equal Equal Z == 134#define COND_NE \350x1 // Not equal Not equal, or unordered Z == 036#define COND_CS \370x2 // Carry set >, ==, or unordered C == 138#define COND_HS 0x239#define COND_CC \400x3 // Carry clear Less than C == 041#define COND_LO 0x342#define COND_MI \430x4 // Minus, negative Less than N == 144#define COND_PL \450x5 // Plus, positive or zero >, ==, or unordered N == 046#define COND_VS \470x6 // Overflow Unordered V == 148#define COND_VC \490x7 // No overflow Not unordered V == 050#define COND_HI \510x8 // Unsigned higher Greater than, or unordered C == 1 and Z ==52// 053#define COND_LS \540x9 // Unsigned lower or same Less than or equal C == 0 or Z ==55// 156#define COND_GE \570xA // Greater than or equal Greater than or equal N == V58#define COND_LT \590xB // Less than Less than, or unordered N != V60#define COND_GT \610xC // Greater than Greater than Z == 0 and N ==62// V63#define COND_LE \640xD // Less than or equal <, ==, or unordered Z == 1 or N !=65// V66#define COND_AL \670xE // Always (unconditional) Always (unconditional) Any68#define COND_UNCOND 0xF6970static inline const char *ARMCondCodeToString(uint32_t CC) {71switch (CC) {72case COND_EQ:73return "eq";74case COND_NE:75return "ne";76case COND_HS:77return "hs";78case COND_LO:79return "lo";80case COND_MI:81return "mi";82case COND_PL:83return "pl";84case COND_VS:85return "vs";86case COND_VC:87return "vc";88case COND_HI:89return "hi";90case COND_LS:91return "ls";92case COND_GE:93return "ge";94case COND_LT:95return "lt";96case COND_GT:97return "gt";98case COND_LE:99return "le";100case COND_AL:101return "al";102}103llvm_unreachable("Unknown condition code");104}105106static inline bool ARMConditionPassed(const uint32_t condition,107const uint32_t cpsr) {108const uint32_t cpsr_n = (cpsr >> 31) & 1u; // Negative condition code flag109const uint32_t cpsr_z = (cpsr >> 30) & 1u; // Zero condition code flag110const uint32_t cpsr_c = (cpsr >> 29) & 1u; // Carry condition code flag111const uint32_t cpsr_v = (cpsr >> 28) & 1u; // Overflow condition code flag112113switch (condition) {114case COND_EQ:115return (cpsr_z == 1);116case COND_NE:117return (cpsr_z == 0);118case COND_CS:119return (cpsr_c == 1);120case COND_CC:121return (cpsr_c == 0);122case COND_MI:123return (cpsr_n == 1);124case COND_PL:125return (cpsr_n == 0);126case COND_VS:127return (cpsr_v == 1);128case COND_VC:129return (cpsr_v == 0);130case COND_HI:131return ((cpsr_c == 1) && (cpsr_z == 0));132case COND_LS:133return ((cpsr_c == 0) || (cpsr_z == 1));134case COND_GE:135return (cpsr_n == cpsr_v);136case COND_LT:137return (cpsr_n != cpsr_v);138case COND_GT:139return ((cpsr_z == 0) && (cpsr_n == cpsr_v));140case COND_LE:141return ((cpsr_z == 1) || (cpsr_n != cpsr_v));142case COND_AL:143case COND_UNCOND:144default:145return true;146}147return false;148}149150// Bit positions for CPSR151#define CPSR_T_POS 5152#define CPSR_F_POS 6153#define CPSR_I_POS 7154#define CPSR_A_POS 8155#define CPSR_E_POS 9156#define CPSR_J_POS 24157#define CPSR_Q_POS 27158#define CPSR_V_POS 28159#define CPSR_C_POS 29160#define CPSR_Z_POS 30161#define CPSR_N_POS 31162163// CPSR mode definitions164#define CPSR_MODE_USR 0x10u165#define CPSR_MODE_FIQ 0x11u166#define CPSR_MODE_IRQ 0x12u167#define CPSR_MODE_SVC 0x13u168#define CPSR_MODE_ABT 0x17u169#define CPSR_MODE_UND 0x1bu170#define CPSR_MODE_SYS 0x1fu171172// Masks for CPSR173#define MASK_CPSR_MODE_MASK (0x0000001fu)174#define MASK_CPSR_IT_MASK (0x0600fc00u)175#define MASK_CPSR_T (1u << CPSR_T_POS)176#define MASK_CPSR_F (1u << CPSR_F_POS)177#define MASK_CPSR_I (1u << CPSR_I_POS)178#define MASK_CPSR_A (1u << CPSR_A_POS)179#define MASK_CPSR_E (1u << CPSR_E_POS)180#define MASK_CPSR_GE_MASK (0x000f0000u)181#define MASK_CPSR_J (1u << CPSR_J_POS)182#define MASK_CPSR_Q (1u << CPSR_Q_POS)183#define MASK_CPSR_V (1u << CPSR_V_POS)184#define MASK_CPSR_C (1u << CPSR_C_POS)185#define MASK_CPSR_Z (1u << CPSR_Z_POS)186#define MASK_CPSR_N (1u << CPSR_N_POS)187188} // namespace lldb_private189190#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_ARMDEFINES_H191192193