Johnny Chen | 4baf2e3 | 2011-01-24 18:24:53 +0000 | [diff] [blame] | 1 | //===-- lldb_ARMUtils.h -----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef lldb_ARMUtils_h_ |
| 11 | #define lldb_ARMUtils_h_ |
| 12 | |
Johnny Chen | c3b5bc3 | 2011-01-24 19:50:30 +0000 | [diff] [blame] | 13 | // Common utilities for the ARM/Thumb Instruction Set Architecture. |
Johnny Chen | 4baf2e3 | 2011-01-24 18:24:53 +0000 | [diff] [blame] | 14 | |
| 15 | namespace lldb_private { |
| 16 | |
Johnny Chen | c3b5bc3 | 2011-01-24 19:50:30 +0000 | [diff] [blame] | 17 | // ARM conditions |
| 18 | #define COND_EQ 0x0 |
| 19 | #define COND_NE 0x1 |
| 20 | #define COND_CS 0x2 |
| 21 | #define COND_HS 0x2 |
| 22 | #define COND_CC 0x3 |
| 23 | #define COND_LO 0x3 |
| 24 | #define COND_MI 0x4 |
| 25 | #define COND_PL 0x5 |
| 26 | #define COND_VS 0x6 |
| 27 | #define COND_VC 0x7 |
| 28 | #define COND_HI 0x8 |
| 29 | #define COND_LS 0x9 |
| 30 | #define COND_GE 0xA |
| 31 | #define COND_LT 0xB |
| 32 | #define COND_GT 0xC |
| 33 | #define COND_LE 0xD |
| 34 | #define COND_AL 0xE |
| 35 | #define COND_UNCOND 0xF |
| 36 | |
| 37 | // Masks for CPSR |
| 38 | #define MASK_CPSR_MODE_MASK (0x0000001fu) |
| 39 | #define MASK_CPSR_T (1u << 5) |
| 40 | #define MASK_CPSR_F (1u << 6) |
| 41 | #define MASK_CPSR_I (1u << 7) |
| 42 | #define MASK_CPSR_A (1u << 8) |
| 43 | #define MASK_CPSR_E (1u << 9) |
| 44 | #define MASK_CPSR_GE_MASK (0x000f0000u) |
| 45 | #define MASK_CPSR_J (1u << 24) |
| 46 | #define MASK_CPSR_Q (1u << 27) |
| 47 | #define MASK_CPSR_V (1u << 28) |
| 48 | #define MASK_CPSR_C (1u << 29) |
| 49 | #define MASK_CPSR_Z (1u << 30) |
| 50 | #define MASK_CPSR_N (1u << 31) |
| 51 | |
| 52 | |
Johnny Chen | 4baf2e3 | 2011-01-24 18:24:53 +0000 | [diff] [blame] | 53 | // This function performs the check for the register numbers 13 and 15 that are |
| 54 | // not permitted for many Thumb register specifiers. |
| 55 | static inline bool BadReg(uint32_t n) { return n == 13 || n == 15; } |
| 56 | |
Johnny Chen | 7dc60e1 | 2011-01-24 19:46:32 +0000 | [diff] [blame] | 57 | // Returns an integer result equal to the number of bits of x that are ones. |
| 58 | static inline uint32_t BitCount(uint32_t x) |
| 59 | { |
| 60 | // c accumulates the total bits set in x |
| 61 | uint32_t c; |
| 62 | for (c = 0; x; ++c) |
| 63 | { |
| 64 | x &= x - 1; // clear the least significant bit set |
| 65 | } |
| 66 | return c; |
| 67 | } |
| 68 | |
Johnny Chen | 4baf2e3 | 2011-01-24 18:24:53 +0000 | [diff] [blame] | 69 | } // namespace lldb_private |
| 70 | |
| 71 | #endif // lldb_ARMUtils_h_ |