aboutsummaryrefslogtreecommitdiffstats
path: root/target-arm/it_helper.h
blob: 79821741734ad9f2a2fc66a76ac585392b526a58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Copyright (C) 2007-2010 The Android Open Source Project
**
** This software is licensed under the terms of the GNU General Public
** License version 2, as published by the Free Software Foundation, and
** may be copied, distributed, and modified under those terms.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
*/

/*
 * Contains implementation of helper routines for IT block support.
 */

#ifndef QEMU_TARGET_ARM_IT_HELPER_H
#define QEMU_TARGET_ARM_IT_HELPER_H

/* Gets condition bits from ITSTATE.
 * Return:
 *  ITSTATE condition bits in the low 4 bits of the returned value.
 */
static inline uint8_t
itstate_cond(uint8_t itstate)
{
    return (itstate >> 4) & 0xf;
}

/* Checks if ITSTATE defines the last instruction in an IT block.
 * Param:
 *  itstate - ITSTATE for an instruction in an IT block.
 * Return:
 *  boolean: 1 if an instruction is the last instruction in its IT block,
 *  or zero if there are more instruction in the IT block.
 */
static inline int
itstate_is_last_it_insn(uint8_t itstate)
{
    return (itstate & 0x7) == 0;
}

/* Checks if ITSTATE suggests that an IT block instruction is being translated.
 * Return:
 *  boolean: 1 if an IT block instruction is being translated, or zero if
 *  a "normal" instruction is being translated.
 */
static inline int
itstate_is_in_it_block(uint8_t itstate)
{
    return (itstate & 0xff) != 0;
}

/* Advances ITSTATE to the next instruction in an IT block.
 * Param:
 *  itstate - ITSTATE of the currently executing instruction.
 * Retunn:
 *  ITSTATE for the next instruction in an IT block, or zero is currently
 *  executing instruction was the last IT block instruction.
 */
static inline uint8_t
itstate_advance(uint8_t itstate)
{
    if (itstate_is_last_it_insn(itstate)) {
        return 0;
    } else {
        return (itstate & 0xe0) | ((itstate & 0xf) << 1);
    }
}

/* Checks if given THUMB instruction is an IT instruction.
 * Param:
 *  insn - THUMB instruction to check.
 * Return:
 *  boolean: 1 if instruction is IT instruction, or zero otherwise.
 */
static inline int
is_it_insn(uint16_t insn)
{
    return (insn & 0xff00) == 0xbf00 && (insn & 0x000f) != 0;
}

#endif  // QEMU_TARGET_ARM_IT_HELPER_H