xref: /qemu/target/hexagon/cpu_bits.h (revision 7fa7aa8114dc5f97f28446a9fe98182d4968be63)
1 /*
2  *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef HEXAGON_CPU_BITS_H
19 #define HEXAGON_CPU_BITS_H
20 
21 #include "qemu/bitops.h"
22 
23 #define PCALIGN 4
24 #define PCALIGN_MASK (PCALIGN - 1)
25 
26 enum hex_event {
27     HEX_EVENT_NONE           = -1,
28     HEX_EVENT_TRAP0          =  0x008,
29 };
30 
31 enum hex_cause {
32     HEX_CAUSE_NONE = -1,
33     HEX_CAUSE_TRAP0 = 0x172,
34     HEX_CAUSE_FETCH_NO_UPAGE =  0x012,
35     HEX_CAUSE_INVALID_PACKET =  0x015,
36     HEX_CAUSE_INVALID_OPCODE =  0x015,
37     HEX_CAUSE_PC_NOT_ALIGNED =  0x01e,
38     HEX_CAUSE_PRIV_NO_UREAD  =  0x024,
39     HEX_CAUSE_PRIV_NO_UWRITE =  0x025,
40 };
41 
42 #define PACKET_WORDS_MAX         4
43 
parse_bits(uint32_t encoding)44 static inline uint32_t parse_bits(uint32_t encoding)
45 {
46     /* The parse bits are [15:14] */
47     return extract32(encoding, 14, 2);
48 }
49 
iclass_bits(uint32_t encoding)50 static inline uint32_t iclass_bits(uint32_t encoding)
51 {
52     /* The instruction class is encoded in bits [31:28] */
53     uint32_t iclass = extract32(encoding, 28, 4);
54     /* If parse bits are zero, this is a duplex */
55     if (parse_bits(encoding) == 0) {
56         iclass += 16;
57     }
58     return iclass;
59 }
60 
is_packet_end(uint32_t endocing)61 static inline bool is_packet_end(uint32_t endocing)
62 {
63     uint32_t bits = parse_bits(endocing);
64     return ((bits == 0x3) || (bits == 0x0));
65 }
66 
67 int disassemble_hexagon(uint32_t *words, int nwords, bfd_vma pc, GString *buf);
68 
69 #endif
70