summaryrefslogtreecommitdiff
path: root/opcodes/tic30-dis.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2005-07-01 11:16:33 +0000
committerNick Clifton <nickc@redhat.com>2005-07-01 11:16:33 +0000
commit3dab4ae989818bdf66191ec925eb7853d2540d82 (patch)
tree3bb738a6b161ddff067f17a6999294b9721c58aa /opcodes/tic30-dis.c
parent110107edc3240d21acd2b8d4f55090eeb4c9972e (diff)
downloadbinutils-redhat-3dab4ae989818bdf66191ec925eb7853d2540d82.tar.gz
Update function declarations to ISO C90 formatting
Diffstat (limited to 'opcodes/tic30-dis.c')
-rw-r--r--opcodes/tic30-dis.c446
1 files changed, 219 insertions, 227 deletions
diff --git a/opcodes/tic30-dis.c b/opcodes/tic30-dis.c
index 8373403f87..eac6c4571d 100644
--- a/opcodes/tic30-dis.c
+++ b/opcodes/tic30-dis.c
@@ -1,5 +1,5 @@
/* Disassembly routines for TMS320C30 architecture
- Copyright 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+ Copyright 1998, 1999, 2000, 2002, 2005 Free Software Foundation, Inc.
Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
This program is free software; you can redistribute it and/or modify
@@ -66,63 +66,8 @@ struct instruction
partemplate *ptm;
};
-int get_tic30_instruction PARAMS ((unsigned long, struct instruction *));
-int print_two_operand
- PARAMS ((disassemble_info *, unsigned long, struct instruction *));
-int print_three_operand
- PARAMS ((disassemble_info *, unsigned long, struct instruction *));
-int print_par_insn
- PARAMS ((disassemble_info *, unsigned long, struct instruction *));
-int print_branch
- PARAMS ((disassemble_info *, unsigned long, struct instruction *));
-int get_indirect_operand PARAMS ((unsigned short, int, char *));
-int get_register_operand PARAMS ((unsigned char, char *));
-int cnvt_tmsfloat_ieee PARAMS ((unsigned long, int, float *));
-
-int
-print_insn_tic30 (pc, info)
- bfd_vma pc;
- disassemble_info *info;
-{
- unsigned long insn_word;
- struct instruction insn = { 0, NULL, NULL };
- bfd_vma bufaddr = pc - info->buffer_vma;
- /* Obtain the current instruction word from the buffer. */
- insn_word = (*(info->buffer + bufaddr) << 24) | (*(info->buffer + bufaddr + 1) << 16) |
- (*(info->buffer + bufaddr + 2) << 8) | *(info->buffer + bufaddr + 3);
- _pc = pc / 4;
- /* Get the instruction refered to by the current instruction word
- and print it out based on its type. */
- if (!get_tic30_instruction (insn_word, &insn))
- return -1;
- switch (GET_TYPE (insn_word))
- {
- case TWO_OPERAND_1:
- case TWO_OPERAND_2:
- if (!print_two_operand (info, insn_word, &insn))
- return -1;
- break;
- case THREE_OPERAND:
- if (!print_three_operand (info, insn_word, &insn))
- return -1;
- break;
- case PAR_STORE:
- case MUL_ADDS:
- if (!print_par_insn (info, insn_word, &insn))
- return -1;
- break;
- case BRANCHES:
- if (!print_branch (info, insn_word, &insn))
- return -1;
- break;
- }
- return 4;
-}
-
-int
-get_tic30_instruction (insn_word, insn)
- unsigned long insn_word;
- struct instruction *insn;
+static int
+get_tic30_instruction (unsigned long insn_word, struct instruction *insn)
{
switch (GET_TYPE (insn_word))
{
@@ -132,6 +77,7 @@ get_tic30_instruction (insn_word, insn)
insn->type = NORMAL_INSN;
{
template *current_optab = (template *) tic30_optab;
+
for (; current_optab < tic30_optab_end; current_optab++)
{
if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
@@ -153,15 +99,18 @@ get_tic30_instruction (insn_word, insn)
}
}
break;
+
case PAR_STORE:
insn->type = PARALLEL_INSN;
{
partemplate *current_optab = (partemplate *) tic30_paroptab;
+
for (; current_optab < tic30_paroptab_end; current_optab++)
{
if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
{
- if ((current_optab->base_opcode & PAR_STORE_IDEN) == (insn_word & PAR_STORE_IDEN))
+ if ((current_optab->base_opcode & PAR_STORE_IDEN)
+ == (insn_word & PAR_STORE_IDEN))
{
insn->ptm = current_optab;
break;
@@ -170,15 +119,18 @@ get_tic30_instruction (insn_word, insn)
}
}
break;
+
case MUL_ADDS:
insn->type = PARALLEL_INSN;
{
partemplate *current_optab = (partemplate *) tic30_paroptab;
+
for (; current_optab < tic30_paroptab_end; current_optab++)
{
if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
{
- if ((current_optab->base_opcode & MUL_ADD_IDEN) == (insn_word & MUL_ADD_IDEN))
+ if ((current_optab->base_opcode & MUL_ADD_IDEN)
+ == (insn_word & MUL_ADD_IDEN))
{
insn->ptm = current_optab;
break;
@@ -187,17 +139,20 @@ get_tic30_instruction (insn_word, insn)
}
}
break;
+
case BRANCHES:
insn->type = NORMAL_INSN;
{
template *current_optab = (template *) tic30_optab;
+
for (; current_optab < tic30_optab_end; current_optab++)
{
if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
{
if (current_optab->operand_types[0] & Imm24)
{
- if ((current_optab->base_opcode & BR_IMM_IDEN) == (insn_word & BR_IMM_IDEN))
+ if ((current_optab->base_opcode & BR_IMM_IDEN)
+ == (insn_word & BR_IMM_IDEN))
{
insn->tm = current_optab;
break;
@@ -205,7 +160,8 @@ get_tic30_instruction (insn_word, insn)
}
else if (current_optab->operands > 0)
{
- if ((current_optab->base_opcode & BR_COND_IDEN) == (insn_word & BR_COND_IDEN))
+ if ((current_optab->base_opcode & BR_COND_IDEN)
+ == (insn_word & BR_COND_IDEN))
{
insn->tm = current_optab;
break;
@@ -213,7 +169,8 @@ get_tic30_instruction (insn_word, insn)
}
else
{
- if ((current_optab->base_opcode & (BR_COND_IDEN | 0x00800000)) == (insn_word & (BR_COND_IDEN | 0x00800000)))
+ if ((current_optab->base_opcode & (BR_COND_IDEN | 0x00800000))
+ == (insn_word & (BR_COND_IDEN | 0x00800000)))
{
insn->tm = current_optab;
break;
@@ -229,17 +186,156 @@ get_tic30_instruction (insn_word, insn)
return 1;
}
-int
-print_two_operand (info, insn_word, insn)
- disassemble_info *info;
- unsigned long insn_word;
- struct instruction *insn;
+static int
+get_register_operand (unsigned char fragment, char *buffer)
+{
+ const reg *current_reg = tic30_regtab;
+
+ if (buffer == NULL)
+ return 0;
+ for (; current_reg < tic30_regtab_end; current_reg++)
+ {
+ if ((fragment & 0x1F) == current_reg->opcode)
+ {
+ strcpy (buffer, current_reg->name);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static int
+get_indirect_operand (unsigned short fragment,
+ int size,
+ char *buffer)
+{
+ unsigned char mod;
+ unsigned arnum;
+ unsigned char disp;
+
+ if (buffer == NULL)
+ return 0;
+ /* Determine which bits identify the sections of the indirect
+ operand based on the size in bytes. */
+ switch (size)
+ {
+ case 1:
+ mod = (fragment & 0x00F8) >> 3;
+ arnum = (fragment & 0x0007);
+ disp = 0;
+ break;
+ case 2:
+ mod = (fragment & 0xF800) >> 11;
+ arnum = (fragment & 0x0700) >> 8;
+ disp = (fragment & 0x00FF);
+ break;
+ default:
+ return 0;
+ }
+ {
+ const ind_addr_type *current_ind = tic30_indaddr_tab;
+
+ for (; current_ind < tic30_indaddrtab_end; current_ind++)
+ {
+ if (current_ind->modfield == mod)
+ {
+ if (current_ind->displacement == IMPLIED_DISP && size == 2)
+ continue;
+
+ else
+ {
+ size_t i, len;
+ int bufcnt;
+
+ len = strlen (current_ind->syntax);
+ for (i = 0, bufcnt = 0; i < len; i++, bufcnt++)
+ {
+ buffer[bufcnt] = current_ind->syntax[i];
+ if (buffer[bufcnt - 1] == 'a' && buffer[bufcnt] == 'r')
+ buffer[++bufcnt] = arnum + '0';
+ if (buffer[bufcnt] == '('
+ && current_ind->displacement == DISP_REQUIRED)
+ {
+ sprintf (&buffer[bufcnt + 1], "%u", disp);
+ bufcnt += strlen (&buffer[bufcnt + 1]);
+ }
+ }
+ buffer[bufcnt + 1] = '\0';
+ break;
+ }
+ }
+ }
+ }
+ return 1;
+}
+
+static int
+cnvt_tmsfloat_ieee (unsigned long tmsfloat, int size, float *ieeefloat)
+{
+ unsigned long exp, sign, mant;
+ union
+ {
+ unsigned long l;
+ float f;
+ } val;
+
+ if (size == 2)
+ {
+ if ((tmsfloat & 0x0000F000) == 0x00008000)
+ tmsfloat = 0x80000000;
+ else
+ {
+ tmsfloat <<= 16;
+ tmsfloat = (long) tmsfloat >> 4;
+ }
+ }
+ exp = tmsfloat & 0xFF000000;
+ if (exp == 0x80000000)
+ {
+ *ieeefloat = 0.0;
+ return 1;
+ }
+ exp += 0x7F000000;
+ sign = (tmsfloat & 0x00800000) << 8;
+ mant = tmsfloat & 0x007FFFFF;
+ if (exp == 0xFF000000)
+ {
+ if (mant == 0)
+ *ieeefloat = ERANGE;
+ if (sign == 0)
+ *ieeefloat = 1.0 / 0.0;
+ else
+ *ieeefloat = -1.0 / 0.0;
+ return 1;
+ }
+ exp >>= 1;
+ if (sign)
+ {
+ mant = (~mant) & 0x007FFFFF;
+ mant += 1;
+ exp += mant & 0x00800000;
+ exp &= 0x7F800000;
+ mant &= 0x007FFFFF;
+ }
+ if (tmsfloat == 0x80000000)
+ sign = mant = exp = 0;
+ tmsfloat = sign | exp | mant;
+ val.l = tmsfloat;
+ *ieeefloat = val.f;
+ return 1;
+}
+
+static int
+print_two_operand (disassemble_info *info,
+ unsigned long insn_word,
+ struct instruction *insn)
{
char name[12];
char operand[2][13] =
{
{0},
- {0}};
+ {0}
+ };
float f_number;
if (insn->tm == NULL)
@@ -249,7 +345,8 @@ print_two_operand (info, insn_word, insn)
{
int src_op, dest_op;
/* Determine whether instruction is a store or a normal instruction. */
- if ((insn->tm->operand_types[1] & (Direct | Indirect)) == (Direct | Indirect))
+ if ((insn->tm->operand_types[1] & (Direct | Indirect))
+ == (Direct | Indirect))
{
src_op = 1;
dest_op = 0;
@@ -306,9 +403,7 @@ print_two_operand (info, insn_word, insn)
else if (insn->tm->operands == 1)
{
if (insn->tm->opcode_modifier == StackOp)
- {
- get_register_operand ((insn_word & 0x001F0000) >> 16, operand[0]);
- }
+ get_register_operand ((insn_word & 0x001F0000) >> 16, operand[0]);
}
/* Output instruction to stream. */
info->fprintf_func (info->stream, " %s %s%c%s", name,
@@ -318,17 +413,17 @@ print_two_operand (info, insn_word, insn)
return 1;
}
-int
-print_three_operand (info, insn_word, insn)
- disassemble_info *info;
- unsigned long insn_word;
- struct instruction *insn;
+static int
+print_three_operand (disassemble_info *info,
+ unsigned long insn_word,
+ struct instruction *insn)
{
char operand[3][13] =
{
{0},
{0},
- {0}};
+ {0}
+ };
if (insn->tm == NULL)
return 0;
@@ -362,11 +457,10 @@ print_three_operand (info, insn_word, insn)
return 1;
}
-int
-print_par_insn (info, insn_word, insn)
- disassemble_info *info;
- unsigned long insn_word;
- struct instruction *insn;
+static int
+print_par_insn (disassemble_info *info,
+ unsigned long insn_word,
+ struct instruction *insn)
{
size_t i, len;
char *name1, *name2;
@@ -375,11 +469,14 @@ print_par_insn (info, insn_word, insn)
{
{0},
{0},
- {0}},
+ {0}
+ },
{
{0},
{0},
- {0}}};
+ {0}
+ }
+ };
if (insn->ptm == NULL)
return 0;
@@ -484,16 +581,16 @@ print_par_insn (info, insn_word, insn)
return 1;
}
-int
-print_branch (info, insn_word, insn)
- disassemble_info *info;
- unsigned long insn_word;
- struct instruction *insn;
+static int
+print_branch (disassemble_info *info,
+ unsigned long insn_word,
+ struct instruction *insn)
{
char operand[2][13] =
{
{0},
- {0}};
+ {0}
+ };
unsigned long address;
int print_label = 0;
@@ -571,145 +668,40 @@ print_branch (info, insn_word, insn)
}
int
-get_indirect_operand (fragment, size, buffer)
- unsigned short fragment;
- int size;
- char *buffer;
+print_insn_tic30 (bfd_vma pc, disassemble_info *info)
{
- unsigned char mod;
- unsigned arnum;
- unsigned char disp;
+ unsigned long insn_word;
+ struct instruction insn = { 0, NULL, NULL };
+ bfd_vma bufaddr = pc - info->buffer_vma;
- if (buffer == NULL)
- return 0;
- /* Determine which bits identify the sections of the indirect
- operand based on the size in bytes. */
- switch (size)
+ /* Obtain the current instruction word from the buffer. */
+ insn_word = (*(info->buffer + bufaddr) << 24) | (*(info->buffer + bufaddr + 1) << 16) |
+ (*(info->buffer + bufaddr + 2) << 8) | *(info->buffer + bufaddr + 3);
+ _pc = pc / 4;
+ /* Get the instruction refered to by the current instruction word
+ and print it out based on its type. */
+ if (!get_tic30_instruction (insn_word, &insn))
+ return -1;
+ switch (GET_TYPE (insn_word))
{
- case 1:
- mod = (fragment & 0x00F8) >> 3;
- arnum = (fragment & 0x0007);
- disp = 0;
+ case TWO_OPERAND_1:
+ case TWO_OPERAND_2:
+ if (!print_two_operand (info, insn_word, &insn))
+ return -1;
break;
- case 2:
- mod = (fragment & 0xF800) >> 11;
- arnum = (fragment & 0x0700) >> 8;
- disp = (fragment & 0x00FF);
+ case THREE_OPERAND:
+ if (!print_three_operand (info, insn_word, &insn))
+ return -1;
+ break;
+ case PAR_STORE:
+ case MUL_ADDS:
+ if (!print_par_insn (info, insn_word, &insn))
+ return -1;
+ break;
+ case BRANCHES:
+ if (!print_branch (info, insn_word, &insn))
+ return -1;
break;
- default:
- return 0;
- }
- {
- const ind_addr_type *current_ind = tic30_indaddr_tab;
- for (; current_ind < tic30_indaddrtab_end; current_ind++)
- {
- if (current_ind->modfield == mod)
- {
- if (current_ind->displacement == IMPLIED_DISP && size == 2)
- {
- continue;
- }
- else
- {
- size_t i, len;
- int bufcnt;
-
- len = strlen (current_ind->syntax);
- for (i = 0, bufcnt = 0; i < len; i++, bufcnt++)
- {
- buffer[bufcnt] = current_ind->syntax[i];
- if (buffer[bufcnt - 1] == 'a' && buffer[bufcnt] == 'r')
- buffer[++bufcnt] = arnum + '0';
- if (buffer[bufcnt] == '('
- && current_ind->displacement == DISP_REQUIRED)
- {
- sprintf (&buffer[bufcnt + 1], "%u", disp);
- bufcnt += strlen (&buffer[bufcnt + 1]);
- }
- }
- buffer[bufcnt + 1] = '\0';
- break;
- }
- }
- }
- }
- return 1;
-}
-
-int
-get_register_operand (fragment, buffer)
- unsigned char fragment;
- char *buffer;
-{
- const reg *current_reg = tic30_regtab;
-
- if (buffer == NULL)
- return 0;
- for (; current_reg < tic30_regtab_end; current_reg++)
- {
- if ((fragment & 0x1F) == current_reg->opcode)
- {
- strcpy (buffer, current_reg->name);
- return 1;
- }
- }
- return 0;
-}
-
-int
-cnvt_tmsfloat_ieee (tmsfloat, size, ieeefloat)
- unsigned long tmsfloat;
- int size;
- float *ieeefloat;
-{
- unsigned long exp, sign, mant;
- union {
- unsigned long l;
- float f;
- } val;
-
- if (size == 2)
- {
- if ((tmsfloat & 0x0000F000) == 0x00008000)
- tmsfloat = 0x80000000;
- else
- {
- tmsfloat <<= 16;
- tmsfloat = (long) tmsfloat >> 4;
- }
- }
- exp = tmsfloat & 0xFF000000;
- if (exp == 0x80000000)
- {
- *ieeefloat = 0.0;
- return 1;
- }
- exp += 0x7F000000;
- sign = (tmsfloat & 0x00800000) << 8;
- mant = tmsfloat & 0x007FFFFF;
- if (exp == 0xFF000000)
- {
- if (mant == 0)
- *ieeefloat = ERANGE;
- if (sign == 0)
- *ieeefloat = 1.0 / 0.0;
- else
- *ieeefloat = -1.0 / 0.0;
- return 1;
- }
- exp >>= 1;
- if (sign)
- {
- mant = (~mant) & 0x007FFFFF;
- mant += 1;
- exp += mant & 0x00800000;
- exp &= 0x7F800000;
- mant &= 0x007FFFFF;
}
- if (tmsfloat == 0x80000000)
- sign = mant = exp = 0;
- tmsfloat = sign | exp | mant;
- val.l = tmsfloat;
- *ieeefloat = val.f;
- return 1;
+ return 4;
}