1 /* Disassemble ft32 instructions.
2 Copyright (C) 2013-2022 Free Software Foundation, Inc.
3 Contributed by FTDI (support@ftdichip.com)
5 This file is part of the GNU opcodes library.
7 This library 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, or (at your option)
12 It is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 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
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "opcode/ft32.h"
28 #include "disassemble.h"
30 extern const ft32_opc_info_t ft32_opc_info
[128];
32 static fprintf_ftype fpr
;
36 sign_extend (int bit
, int value
)
38 int onebit
= (1 << bit
);
39 return (value
& (onebit
- 1)) - (value
& onebit
);
43 ft32_opcode1 (unsigned int iword
,
44 struct disassemble_info
*info
)
46 const ft32_opc_info_t
*oo
;
48 for (oo
= ft32_opc_info
; oo
->name
; oo
++)
49 if ((iword
& oo
->mask
) == oo
->bits
)
57 fpr (stream
, "%s", oo
->name
);
59 fpr (stream
, ".%c ", "bsl"[(iword
>> FT32_FLD_DW_BIT
) & 3]);
72 imm
= ((iword
>> FT32_FLD_CB_BIT
) & ((1 << FT32_FLD_CB_SIZ
) - 1)) << 4;
73 imm
|= ((iword
>> FT32_FLD_CV_BIT
) & ((1 << FT32_FLD_CV_SIZ
) - 1));
76 case 0x00: fpr (stream
, "nz"); break;
77 case 0x01: fpr (stream
, "z"); break;
78 case 0x10: fpr (stream
, "ae"); break;
79 case 0x11: fpr (stream
, "b"); break;
80 case 0x20: fpr (stream
, "no"); break;
81 case 0x21: fpr (stream
, "o"); break;
82 case 0x30: fpr (stream
, "ns"); break;
83 case 0x31: fpr (stream
, "s"); break;
84 case 0x40: fpr (stream
, "lt"); break;
85 case 0x41: fpr (stream
, "gte"); break;
86 case 0x50: fpr (stream
, "lte"); break;
87 case 0x51: fpr (stream
, "gt"); break;
88 case 0x60: fpr (stream
, "be"); break;
89 case 0x61: fpr (stream
, "a"); break;
91 fpr (stream
, "%d,$r30,%d", (imm
>> 4), (imm
& 1));
96 imm
= (iword
>> FT32_FLD_CB_BIT
) & ((1 << FT32_FLD_CB_SIZ
) - 1);
97 fpr (stream
, "%d", imm
);
100 fpr (stream
, "$r%d", (iword
>> FT32_FLD_R_D_BIT
) & 0x1f);
103 imm
= (iword
>> FT32_FLD_CR_BIT
) & ((1 << FT32_FLD_CR_SIZ
) - 1);
104 fpr (stream
, "$r%d", 28 + imm
);
107 imm
= (iword
>> FT32_FLD_CV_BIT
) & ((1 << FT32_FLD_CV_SIZ
) - 1);
108 fpr (stream
, "%d", imm
);
111 fpr (stream
, "$r%d", (iword
>> FT32_FLD_R_1_BIT
) & 0x1f);
114 imm
= (iword
>> FT32_FLD_RIMM_BIT
) & ((1 << FT32_FLD_RIMM_SIZ
) - 1);
116 fpr (stream
, "%d", sign_extend (9, imm
));
118 fpr (stream
, "$r%d", imm
& 0x1f);
121 fpr (stream
, "$r%d", (iword
>> FT32_FLD_R_2_BIT
) & 0x1f);
124 imm
= iword
& ((1 << FT32_FLD_K20_SIZ
) - 1);
125 fpr (stream
, "%d", sign_extend (19, imm
));
128 imm
= (iword
& ((1 << FT32_FLD_PA_SIZ
) - 1)) << 2;
129 info
->print_address_func ((bfd_vma
) imm
, info
);
132 imm
= iword
& ((1 << FT32_FLD_AA_SIZ
) - 1);
133 info
->print_address_func ((1 << 23) | (bfd_vma
) imm
, info
);
136 imm
= iword
& ((1 << FT32_FLD_K16_SIZ
) - 1);
137 fpr (stream
, "%d", imm
);
140 imm
= iword
& ((1 << FT32_FLD_K15_SIZ
) - 1);
141 fpr (stream
, "%d", sign_extend (14, imm
));
143 case FT32_FLD_R_D_POST
:
144 fpr (stream
, "$r%d", (iword
>> FT32_FLD_R_D_BIT
) & 0x1f);
146 case FT32_FLD_R_1_POST
:
147 fpr (stream
, "$r%d", (iword
>> FT32_FLD_R_1_BIT
) & 0x1f);
163 ft32_opcode (bfd_vma addr ATTRIBUTE_UNUSED
,
165 struct disassemble_info
*info
)
168 if (ft32_decode_shortcode ((unsigned int) addr
, iword
, sc
))
170 ft32_opcode1 (sc
[0], info
);
172 ft32_opcode1 (sc
[1], info
);
175 ft32_opcode1 (iword
, info
);
179 print_insn_ft32 (bfd_vma addr
, struct disassemble_info
*info
)
182 stream
= info
->stream
;
186 fpr
= info
->fprintf_func
;
188 if ((status
= info
->read_memory_func (addr
, buffer
, 4, info
)))
191 iword
= bfd_getl32 (buffer
);
193 fpr (stream
, "%08x ", iword
);
195 ft32_opcode (addr
, iword
, info
);
200 info
->memory_error_func (status
, addr
, info
);