1 /* SPU ELF support for BFD.
3 Copyright (C) 2006-2024 Free Software Foundation, Inc.
5 This file is part of GDB, GAS, and the GNU binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 /* These two enums are from rel_apu/common/spu_asm_format.h */
22 /* definition of instruction format */
37 /* These values describe assembly instruction arguments. They indicate
38 * how to encode, range checking and which relocation to use. */
40 A_T
, /* register at pos 0 */
41 A_A
, /* register at pos 7 */
42 A_B
, /* register at pos 14 */
43 A_C
, /* register at pos 21 */
44 A_S
, /* special purpose register at pos 7 */
45 A_H
, /* channel register at pos 7 */
46 A_P
, /* parenthesis, this has to separate regs from immediates */
72 #define APUOP(TAG,MACFORMAT,OPCODE,MNEMONIC,ASMFORMAT,DEP,PIPE) \
74 #define APUOPFB(TAG,MACFORMAT,OPCODE,FB,MNEMONIC,ASMFORMAT,DEP,PIPE) \
76 #include "opcode/spu-insns.h"
84 spu_iformat insn_type
;
90 #define UNSIGNED_EXTRACT(insn, size, pos) \
91 (((insn) >> (pos)) & ((1u << (size)) - 1))
92 #define SIGNED_EXTRACT(insn, size, pos) \
93 (((int) UNSIGNED_EXTRACT(insn, size, pos) \
94 ^ (1 << ((size) - 1))) - (1 << ((size) - 1)))
96 #define DECODE_INSN_RT(insn) (insn & 0x7f)
97 #define DECODE_INSN_RA(insn) ((insn >> 7) & 0x7f)
98 #define DECODE_INSN_RB(insn) ((insn >> 14) & 0x7f)
99 #define DECODE_INSN_RC(insn) ((insn >> 21) & 0x7f)
101 #define DECODE_INSN_I10(insn) SIGNED_EXTRACT (insn, 10, 14)
102 #define DECODE_INSN_U10(insn) UNSIGNED_EXTRACT (insn, 10, 14)
104 /* For branching, immediate loads, hbr and lqa/stqa. */
105 #define DECODE_INSN_I16(insn) SIGNED_EXTRACT (insn, 16, 7)
106 #define DECODE_INSN_U16(insn) UNSIGNED_EXTRACT (insn, 16, 7)
109 #define DECODE_INSN_U14(insn) UNSIGNED_EXTRACT (insn, 14, 0)
112 #define DECODE_INSN_I18(insn) SIGNED_EXTRACT (insn, 18, 7)
113 #define DECODE_INSN_U18(insn) UNSIGNED_EXTRACT (insn, 18, 7)
115 /* For rotate and shift and generate control mask */
116 #define DECODE_INSN_I7(insn) SIGNED_EXTRACT (insn, 7, 14)
117 #define DECODE_INSN_U7(insn) UNSIGNED_EXTRACT (insn, 7, 14)
119 /* For float <-> int conversion */
120 #define DECODE_INSN_I8(insn) SIGNED_EXTRACT (insn, 8, 14)
121 #define DECODE_INSN_U8(insn) UNSIGNED_EXTRACT (insn, 8, 14)
124 #define DECODE_INSN_I9a(insn) \
125 ((SIGNED_EXTRACT (insn, 2, 23) * 128) | (int) UNSIGNED_EXTRACT (insn, 7, 0))
126 #define DECODE_INSN_I9b(insn) \
127 ((SIGNED_EXTRACT (insn, 2, 14) * 128) | (int) UNSIGNED_EXTRACT (insn, 7, 0))