xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/spu.h (revision aab831cebf6361fb2b518a47c70732e608d9abd2)
198b9484cSchristos /* SPU ELF support for BFD.
298b9484cSchristos 
3*aab831ceSchristos    Copyright (C) 2006-2024 Free Software Foundation, Inc.
498b9484cSchristos 
598b9484cSchristos    This file is part of GDB, GAS, and the GNU binutils.
698b9484cSchristos 
798b9484cSchristos    This program is free software; you can redistribute it and/or modify
898b9484cSchristos    it under the terms of the GNU General Public License as published by
998b9484cSchristos    the Free Software Foundation; either version 3 of the License, or
1098b9484cSchristos    (at your option) any later version.
1198b9484cSchristos 
1298b9484cSchristos    This program is distributed in the hope that it will be useful,
1398b9484cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1498b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1598b9484cSchristos    GNU General Public License for more details.
1698b9484cSchristos 
1798b9484cSchristos    You should have received a copy of the GNU General Public License
1898b9484cSchristos    along with this program; if not, write to the Free Software Foundation,
1998b9484cSchristos    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2098b9484cSchristos 
2198b9484cSchristos /* These two enums are from rel_apu/common/spu_asm_format.h */
2298b9484cSchristos /* definition of instruction format */
2398b9484cSchristos typedef enum {
2498b9484cSchristos   RRR,
2598b9484cSchristos   RI18,
2698b9484cSchristos   RI16,
2798b9484cSchristos   RI10,
2898b9484cSchristos   RI8,
2998b9484cSchristos   RI7,
3098b9484cSchristos   RR,
3198b9484cSchristos   LBT,
3298b9484cSchristos   LBTI,
3398b9484cSchristos   IDATA,
3498b9484cSchristos   UNKNOWN_IFORMAT
3598b9484cSchristos } spu_iformat;
3698b9484cSchristos 
3798b9484cSchristos /* These values describe assembly instruction arguments.  They indicate
3898b9484cSchristos  * how to encode, range checking and which relocation to use. */
3998b9484cSchristos typedef enum {
4098b9484cSchristos   A_T,  /* register at pos 0 */
4198b9484cSchristos   A_A,  /* register at pos 7 */
4298b9484cSchristos   A_B,  /* register at pos 14 */
4398b9484cSchristos   A_C,  /* register at pos 21 */
4498b9484cSchristos   A_S,  /* special purpose register at pos 7 */
4598b9484cSchristos   A_H,  /* channel register at pos 7 */
4698b9484cSchristos   A_P,  /* parenthesis, this has to separate regs from immediates */
4798b9484cSchristos   A_S3,
4898b9484cSchristos   A_S6,
4998b9484cSchristos   A_S7N,
5098b9484cSchristos   A_S7,
5198b9484cSchristos   A_U7A,
5298b9484cSchristos   A_U7B,
5398b9484cSchristos   A_S10B,
5498b9484cSchristos   A_S10,
5598b9484cSchristos   A_S11,
5698b9484cSchristos   A_S11I,
5798b9484cSchristos   A_S14,
5898b9484cSchristos   A_S16,
5998b9484cSchristos   A_S18,
6098b9484cSchristos   A_R18,
6198b9484cSchristos   A_U3,
6298b9484cSchristos   A_U5,
6398b9484cSchristos   A_U6,
6498b9484cSchristos   A_U7,
6598b9484cSchristos   A_U14,
6698b9484cSchristos   A_X16,
6798b9484cSchristos   A_U18,
6898b9484cSchristos   A_MAX
6998b9484cSchristos } spu_aformat;
7098b9484cSchristos 
7198b9484cSchristos enum spu_insns {
7298b9484cSchristos #define APUOP(TAG,MACFORMAT,OPCODE,MNEMONIC,ASMFORMAT,DEP,PIPE) \
7398b9484cSchristos 	TAG,
7498b9484cSchristos #define APUOPFB(TAG,MACFORMAT,OPCODE,FB,MNEMONIC,ASMFORMAT,DEP,PIPE) \
7598b9484cSchristos 	TAG,
7698b9484cSchristos #include "opcode/spu-insns.h"
7798b9484cSchristos #undef APUOP
7898b9484cSchristos #undef APUOPFB
7998b9484cSchristos         M_SPU_MAX
8098b9484cSchristos };
8198b9484cSchristos 
8298b9484cSchristos struct spu_opcode
8398b9484cSchristos {
8498b9484cSchristos    spu_iformat insn_type;
8598b9484cSchristos    unsigned int opcode;
86ba340e45Schristos    const char *mnemonic;
8798b9484cSchristos    int arg[5];
8898b9484cSchristos };
8998b9484cSchristos 
908dffb485Schristos #define UNSIGNED_EXTRACT(insn, size, pos)	\
918dffb485Schristos   (((insn) >> (pos)) & ((1u << (size)) - 1))
928dffb485Schristos #define SIGNED_EXTRACT(insn, size, pos)			\
938dffb485Schristos   (((int) UNSIGNED_EXTRACT(insn, size, pos)		\
948dffb485Schristos     ^ (1 << ((size) - 1))) - (1 << ((size) - 1)))
9598b9484cSchristos 
9698b9484cSchristos #define DECODE_INSN_RT(insn) (insn & 0x7f)
9798b9484cSchristos #define DECODE_INSN_RA(insn) ((insn >> 7) & 0x7f)
9898b9484cSchristos #define DECODE_INSN_RB(insn) ((insn >> 14) & 0x7f)
9998b9484cSchristos #define DECODE_INSN_RC(insn) ((insn >> 21) & 0x7f)
10098b9484cSchristos 
10198b9484cSchristos #define DECODE_INSN_I10(insn) SIGNED_EXTRACT (insn, 10, 14)
10298b9484cSchristos #define DECODE_INSN_U10(insn) UNSIGNED_EXTRACT (insn, 10, 14)
10398b9484cSchristos 
10498b9484cSchristos /* For branching, immediate loads, hbr and  lqa/stqa. */
10598b9484cSchristos #define DECODE_INSN_I16(insn) SIGNED_EXTRACT (insn, 16, 7)
10698b9484cSchristos #define DECODE_INSN_U16(insn) UNSIGNED_EXTRACT (insn, 16, 7)
10798b9484cSchristos 
10898b9484cSchristos /* for stop */
10998b9484cSchristos #define DECODE_INSN_U14(insn) UNSIGNED_EXTRACT (insn, 14, 0)
11098b9484cSchristos 
11198b9484cSchristos /* For ila */
11298b9484cSchristos #define DECODE_INSN_I18(insn) SIGNED_EXTRACT (insn, 18, 7)
11398b9484cSchristos #define DECODE_INSN_U18(insn) UNSIGNED_EXTRACT (insn, 18, 7)
11498b9484cSchristos 
11598b9484cSchristos /* For rotate and shift and generate control mask */
11698b9484cSchristos #define DECODE_INSN_I7(insn) SIGNED_EXTRACT (insn, 7, 14)
11798b9484cSchristos #define DECODE_INSN_U7(insn) UNSIGNED_EXTRACT (insn, 7, 14)
11898b9484cSchristos 
11998b9484cSchristos /* For float <-> int conversion */
12098b9484cSchristos #define DECODE_INSN_I8(insn) SIGNED_EXTRACT (insn, 8, 14)
12198b9484cSchristos #define DECODE_INSN_U8(insn) UNSIGNED_EXTRACT (insn, 8, 14)
12298b9484cSchristos 
12398b9484cSchristos /* For hbr  */
1248dffb485Schristos #define DECODE_INSN_I9a(insn) \
1258dffb485Schristos   ((SIGNED_EXTRACT (insn, 2, 23) * 128) | (int) UNSIGNED_EXTRACT (insn, 7, 0))
1268dffb485Schristos #define DECODE_INSN_I9b(insn) \
1278dffb485Schristos   ((SIGNED_EXTRACT (insn, 2, 14) * 128) | (int) UNSIGNED_EXTRACT (insn, 7, 0))
12898b9484cSchristos 
129