* config/tc-xgate.c: Make some functions static. Formatting

style and whitespace fixes.  Wrap overly long lines.  Format
	help message.
This commit is contained in:
Alan Modra
2012-11-06 10:03:32 +00:00
parent b374d0f8d9
commit 234fa27ce0
2 changed files with 336 additions and 372 deletions

View File

@ -1,3 +1,9 @@
2012-11-06 Alan Modra <amodra@gmail.com>
* config/tc-xgate.c: Make some functions static. Formatting
style and whitespace fixes. Wrap overly long lines. Format
help message.
2012-11-06 Alan Modra <amodra@gmail.com> 2012-11-06 Alan Modra <amodra@gmail.com>
* config/tc-tic4x.c: Remove alignment TODO comments. * config/tc-tic4x.c: Remove alignment TODO comments.

View File

@ -60,7 +60,8 @@ struct xgate_opcode_handle
struct xgate_opcode *opc0[MAX_OPCODES]; struct xgate_opcode *opc0[MAX_OPCODES];
}; };
/* XGATE's registers all are 16-bit general purpose. They are numbered according to the specifications. */ /* XGATE's registers all are 16-bit general purpose.
They are numbered according to the specifications. */
typedef enum register_id typedef enum register_id
{ {
REG_NONE = -1, REG_NONE = -1,
@ -95,43 +96,21 @@ typedef struct s_operand
} s_operand; } s_operand;
/* LOCAL FUNCTIONS */ /* Forward declarations. */
static char * static inline char *skip_whitespace (char *);
xgate_parse_exp (char *, expressionS *); static void get_default_target (void);
static inline char * static char *extract_word (char *, char *, int);
skip_whitespace (char *); static struct xgate_opcode *xgate_find_match (struct xgate_opcode_handle *,
static void int, unsigned int);
get_default_target (void); static int cmp_opcode (struct xgate_opcode *, struct xgate_opcode *);
static char * static void xgate_print_table (void);
extract_word (char *, char *, int); static unsigned int xgate_get_operands (char *, s_operand []);
static char * static register_id reg_name_search (char *);
xgate_new_instruction (int size); static op_modifiers xgate_determine_modifiers(char **);
unsigned short static void xgate_scan_operands (struct xgate_opcode *opcode, s_operand []);
xgate_apply_operand (unsigned short, unsigned short *, unsigned short, static unsigned int xgate_parse_operand (struct xgate_opcode *, int *, int,
unsigned char); char **, s_operand);
static struct xgate_opcode *
xgate_find_match (struct xgate_opcode_handle *, int, unsigned int);
static int
cmp_opcode (struct xgate_opcode *, struct xgate_opcode *);
void
xgate_print_syntax (char *);
void
xgate_print_table (void);
unsigned int
xgate_get_operands (char *, s_operand []);
static register_id
reg_name_search (char *);
op_modifiers
xgate_determine_modifiers(char **);
void
xgate_scan_operands (struct xgate_opcode *opcode, s_operand []);
static unsigned int
xgate_parse_operand (struct xgate_opcode *, int *, int where, char **,
s_operand);
/* LOCAL DATA */
static struct hash_control *xgate_hash; static struct hash_control *xgate_hash;
/* Previous opcode. */ /* Previous opcode. */
@ -384,13 +363,12 @@ md_show_usage (FILE * stream)
{ {
get_default_target (); get_default_target ();
fprintf ( fprintf (stream,
stream,
_("\ _("\
Freescale XGATE co-processor options:\n \ Freescale XGATE co-processor options:\n\
-mshort use 16-bit int ABI (default)\n \ -mshort use 16-bit int ABI (default)\n\
-mlong use 32-bit int ABI\n \ -mlong use 32-bit int ABI\n\
-mshort-double use 32-bit double ABI\n \ -mshort-double use 32-bit double ABI\n\
-mlong-double use 64-bit double ABI (default)\n\ -mlong-double use 64-bit double ABI (default)\n\
--mxgate specify the processor variant[default %s]\n\ --mxgate specify the processor variant[default %s]\n\
--print-insn-syntax print the syntax of instruction in case of error\n\ --print-insn-syntax print the syntax of instruction in case of error\n\
@ -412,7 +390,7 @@ xgate_mach (void)
return 0; return 0;
} }
void static void
xgate_print_syntax (char *name) xgate_print_syntax (char *name)
{ {
int i; int i;
@ -453,7 +431,7 @@ xgate_print_syntax (char *name)
} }
} }
void static void
xgate_print_table (void) xgate_print_table (void)
{ {
int i; int i;
@ -554,7 +532,8 @@ md_assemble (char *input_line)
input_line = skip_whitespace (input_line); input_line = skip_whitespace (input_line);
char *macro_inline = input_line; char *macro_inline = input_line;
/* Loop though the macro's opcode list and apply operands to each real opcode. */ /* Loop though the macro's opcode list and apply operands to
each real opcode. */
for (i = 0; *p && i < (opcode->size / 2); i++) for (i = 0; *p && i < (opcode->size / 2); i++)
{ {
/* Loop though macro operand list. */ /* Loop though macro operand list. */
@ -564,15 +543,17 @@ md_assemble (char *input_line)
if (!(opcode_handle = (struct xgate_opcode_handle *) if (!(opcode_handle = (struct xgate_opcode_handle *)
hash_find (xgate_hash, op_name))) hash_find (xgate_hash, op_name)))
{ {
as_bad ( as_bad (_(": processing macro, real opcode handle"
_(": processing macro, real opcode handle not found in hash")); " not found in hash"));
break; break;
} }
else else
{ {
sh_format = xgate_get_operands(input_line, new_operands); sh_format = xgate_get_operands(input_line, new_operands);
macro_opcode = xgate_find_match (opcode_handle, macro_opcode
opcode_handle->number_of_modes, sh_format); = xgate_find_match (opcode_handle,
opcode_handle->number_of_modes,
sh_format);
xgate_scan_operands (macro_opcode, new_operands); xgate_scan_operands (macro_opcode, new_operands);
} }
@ -592,8 +573,7 @@ md_estimate_size_before_relax (fragS *fragp, asection *seg)
/* If symbol is undefined or located in a different section, /* If symbol is undefined or located in a different section,
select the largest supported relocation. */ select the largest supported relocation. */
relax_substateT subtype; relax_substateT subtype;
relax_substateT rlx_state[] = relax_substateT rlx_state[] = { 0, 2 };
{ 0, 2 };
for (subtype = 0; subtype < ARRAY_SIZE (rlx_state); subtype += 2) for (subtype = 0; subtype < ARRAY_SIZE (rlx_state); subtype += 2)
{ {
@ -639,13 +619,9 @@ tc_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp)
reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
if (fixp->fx_r_type == 0) if (fixp->fx_r_type == 0)
{
reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16); reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16);
}
else else
{
reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
}
if (reloc->howto == (reloc_howto_type *) NULL) if (reloc->howto == (reloc_howto_type *) NULL)
{ {
@ -676,11 +652,10 @@ md_apply_fix (fixS * fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
int opcode = 0; int opcode = 0;
ldiv_t result; ldiv_t result;
/* If the fixup is done mark it done so no further symbol resolution will take place. */ /* If the fixup is done mark it done so no further symbol resolution
will take place. */
if (fixP->fx_addsy == (symbolS *) NULL) if (fixP->fx_addsy == (symbolS *) NULL)
{
fixP->fx_done = 1; fixP->fx_done = 1;
}
/* We don't actually support subtracting a symbol. */ /* We don't actually support subtracting a symbol. */
if (fixP->fx_subsy != (symbolS *) NULL) if (fixP->fx_subsy != (symbolS *) NULL)
@ -695,26 +670,34 @@ md_apply_fix (fixS * fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
case R_XGATE_PCREL_9: case R_XGATE_PCREL_9:
if (value < -512 || value > 511) if (value < -512 || value > 511)
as_bad_where (fixP->fx_file, fixP->fx_line, as_bad_where (fixP->fx_file, fixP->fx_line,
_("Value %ld too large for 9-bit PC-relative branch."), value); _("Value %ld too large for 9-bit PC-relative branch."),
value);
result = ldiv (value, 2); /* from bytes to words */ result = ldiv (value, 2); /* from bytes to words */
value = result.quot; value = result.quot;
if (result.rem) if (result.rem)
as_bad_where (fixP->fx_file, fixP->fx_line, _ as_bad_where (fixP->fx_file, fixP->fx_line, _
("Value %ld not aligned by 2 for 9-bit PC-relative branch."), value); ("Value %ld not aligned by 2 for 9-bit"
mask = 0x1FF; /* Clip into 8-bit field FIXME I'm sure there is a more proper place for this */ " PC-relative branch."), value);
/* Clip into 8-bit field.
FIXME I'm sure there is a more proper place for this. */
mask = 0x1FF;
value &= mask; value &= mask;
number_to_chars_bigendian (where, (opcode | value), 2); number_to_chars_bigendian (where, (opcode | value), 2);
break; break;
case R_XGATE_PCREL_10: case R_XGATE_PCREL_10:
if (value < -1024 || value > 1023) if (value < -1024 || value > 1023)
as_bad_where (fixP->fx_file, fixP->fx_line, as_bad_where (fixP->fx_file, fixP->fx_line,
_("Value %ld too large for 10-bit PC-relative branch."), value); _("Value %ld too large for 10-bit PC-relative branch."),
value);
result = ldiv (value, 2); /* from bytes to words */ result = ldiv (value, 2); /* from bytes to words */
value = result.quot; value = result.quot;
if (result.rem) if (result.rem)
as_bad_where (fixP->fx_file, fixP->fx_line, _ as_bad_where (fixP->fx_file, fixP->fx_line, _
("Value %ld not aligned by 2 for 10-bit PC-relative branch."), value); ("Value %ld not aligned by 2 for 10-bit"
mask = 0x3FF; /* Clip into 9-bit field FIXME I'm sure there is a more proper place for this */ " PC-relative branch."), value);
/* Clip into 9-bit field.
FIXME I'm sure there is a more proper place for this. */
mask = 0x3FF;
value &= mask; value &= mask;
number_to_chars_bigendian (where, (opcode | value), 2); number_to_chars_bigendian (where, (opcode | value), 2);
break; break;
@ -864,7 +847,7 @@ xgate_new_instruction (int size)
return f; return f;
} }
unsigned short static unsigned short
xgate_apply_operand (unsigned short new_mask, xgate_apply_operand (unsigned short new_mask,
unsigned short *availiable_mask_bits, unsigned short *availiable_mask_bits,
unsigned short mask, unsigned short mask,
@ -873,13 +856,15 @@ xgate_apply_operand (unsigned short new_mask,
unsigned short n_shifts; unsigned short n_shifts;
unsigned int n_drop_bits; unsigned int n_drop_bits;
/* Shift until you find an available operand bit "1" and record the number of shifts. */ /* Shift until you find an available operand bit "1" and record
the number of shifts. */
for (n_shifts = 0; for (n_shifts = 0;
!(*availiable_mask_bits & SIXTEENTH_BIT) && n_shifts < 16; !(*availiable_mask_bits & SIXTEENTH_BIT) && n_shifts < 16;
n_shifts++) n_shifts++)
*availiable_mask_bits <<= 1; *availiable_mask_bits <<= 1;
/* Shift for the number of bits your operand requires while bits are available. */ /* Shift for the number of bits your operand requires while bits
are available. */
for (n_drop_bits = n_bits; for (n_drop_bits = n_bits;
n_drop_bits && (*availiable_mask_bits & SIXTEENTH_BIT); n_drop_bits && (*availiable_mask_bits & SIXTEENTH_BIT);
--n_drop_bits) --n_drop_bits)
@ -953,7 +938,7 @@ xgate_frob_symbol (symbolS *sym)
return 0; return 0;
} }
unsigned int static unsigned int
xgate_get_operands (char *line, s_operand oprs[]) xgate_get_operands (char *line, s_operand oprs[])
{ {
int num_operands; int num_operands;
@ -1062,7 +1047,7 @@ reg_name_search (char *name)
/* Parse operand modifiers such as inc/dec/hi/low. */ /* Parse operand modifiers such as inc/dec/hi/low. */
op_modifiers static op_modifiers
xgate_determine_modifiers(char **line) xgate_determine_modifiers(char **line)
{ {
char *local_line = line[0]; char *local_line = line[0];
@ -1089,7 +1074,7 @@ xgate_determine_modifiers(char **line)
/* Parse instruction operands. */ /* Parse instruction operands. */
void static void
xgate_scan_operands (struct xgate_opcode *opcode, s_operand oprs[]) xgate_scan_operands (struct xgate_opcode *opcode, s_operand oprs[])
{ {
char *frag = xgate_new_instruction (opcode->size); char *frag = xgate_new_instruction (opcode->size);
@ -1127,12 +1112,14 @@ xgate_scan_operands (struct xgate_opcode *opcode, s_operand oprs[])
first_operand_equals_second = 1; first_operand_equals_second = 1;
++op; ++op;
} }
operand = xgate_parse_operand (opcode, &operand_bit_length, where, &op, oprs[0]); operand = xgate_parse_operand (opcode, &operand_bit_length, where,
&op, oprs[0]);
++op; ++op;
bin = xgate_apply_operand (operand, &oper_mask, bin, operand_bit_length); bin = xgate_apply_operand (operand, &oper_mask, bin, operand_bit_length);
if(first_operand_equals_second) if(first_operand_equals_second)
bin = xgate_apply_operand (operand, &oper_mask, bin, operand_bit_length); bin = xgate_apply_operand (operand, &oper_mask, bin,
operand_bit_length);
/* Parse second operand. */ /* Parse second operand. */
if (*op) if (*op)
{ {
@ -1158,8 +1145,8 @@ xgate_scan_operands (struct xgate_opcode *opcode, s_operand oprs[])
{ {
if (*op == ',') if (*op == ',')
++op; ++op;
operand = xgate_parse_operand (opcode, &operand_bit_length, where, &op, operand = xgate_parse_operand (opcode, &operand_bit_length, where,
oprs[2]); &op, oprs[2]);
bin = xgate_apply_operand (operand, &oper_mask, bin, bin = xgate_apply_operand (operand, &oper_mask, bin,
operand_bit_length); operand_bit_length);
} }
@ -1231,31 +1218,22 @@ xgate_parse_operand (struct xgate_opcode *opcode,
(*op_con)++; (*op_con)++;
op_constraint++; op_constraint++;
if (ISDIGIT (*op_constraint)) if (ISDIGIT (*op_constraint))
{
*bit_width = (int) *op_constraint - '0'; *bit_width = (int) *op_constraint - '0';
}
else if (*op_constraint == 'a') else if (*op_constraint == 'a')
{
*bit_width = 0x0A; *bit_width = 0x0A;
}
else if (*op_constraint == 'f') else if (*op_constraint == 'f')
{
*bit_width = 0x0F; *bit_width = 0x0F;
}
/* http://tigcc.ticalc.org/doc/gnuasm.html#SEC31 */ /* http://tigcc.ticalc.org/doc/gnuasm.html#SEC31 */
if (operand.exp.X_op == O_constant) if (operand.exp.X_op == O_constant)
{ {
op_mask = operand.exp.X_add_number; op_mask = operand.exp.X_add_number;
if (((opcode->name[strlen (opcode->name) - 1] == 'l') && autoHiLo) if (((opcode->name[strlen (opcode->name) - 1] == 'l') && autoHiLo)
|| operand.mod == MOD_LOAD_LOW) || operand.mod == MOD_LOAD_LOW)
{
op_mask &= 0x00FF; op_mask &= 0x00FF;
}
else if (((opcode->name[strlen (opcode->name) - 1]) == 'h' else if (((opcode->name[strlen (opcode->name) - 1]) == 'h'
&& autoHiLo) || operand.mod == MOD_LOAD_HIGH) && autoHiLo) || operand.mod == MOD_LOAD_HIGH)
{
op_mask >>= 8; op_mask >>= 8;
}
/* Make sure it fits. */ /* Make sure it fits. */
for (i = *bit_width; i; i--) for (i = *bit_width; i; i--)
@ -1275,43 +1253,28 @@ xgate_parse_operand (struct xgate_opcode *opcode,
{ {
if (((opcode->name[strlen (opcode->name) - 1] == 'l') if (((opcode->name[strlen (opcode->name) - 1] == 'l')
&& autoHiLo) || operand.mod == MOD_LOAD_LOW) && autoHiLo) || operand.mod == MOD_LOAD_LOW)
{
fix_new_exp (frag_now, where, 2, &operand.exp, FALSE, fix_new_exp (frag_now, where, 2, &operand.exp, FALSE,
BFD_RELOC_XGATE_24); BFD_RELOC_XGATE_24);
}
else if (((opcode->name[strlen (opcode->name) - 1]) == 'h' else if (((opcode->name[strlen (opcode->name) - 1]) == 'h'
&& autoHiLo) || operand.mod == MOD_LOAD_HIGH ) && autoHiLo) || operand.mod == MOD_LOAD_HIGH )
{
fix_new_exp (frag_now, where, 2, &operand.exp, FALSE, fix_new_exp (frag_now, where, 2, &operand.exp, FALSE,
BFD_RELOC_XGATE_IMM8_HI); BFD_RELOC_XGATE_IMM8_HI);
}
else else
{
as_bad (_("you must use a hi/lo directive or 16-bit macro " as_bad (_("you must use a hi/lo directive or 16-bit macro "
"to load a 16-bit value.")); "to load a 16-bit value."));
break;
}
} }
else if (*op_constraint == '5') else if (*op_constraint == '5')
{
fix_new_exp (frag_now, where, 2, &operand.exp, FALSE, fix_new_exp (frag_now, where, 2, &operand.exp, FALSE,
BFD_RELOC_XGATE_IMM5); BFD_RELOC_XGATE_IMM5);
}
else if (*op_constraint == '4') else if (*op_constraint == '4')
{
fix_new_exp (frag_now, where, 2, &operand.exp, FALSE, fix_new_exp (frag_now, where, 2, &operand.exp, FALSE,
BFD_RELOC_XGATE_IMM4); BFD_RELOC_XGATE_IMM4);
}
else if (*op_constraint == '3') else if (*op_constraint == '3')
{
fix_new_exp (frag_now, where, 2, &operand.exp, FALSE, fix_new_exp (frag_now, where, 2, &operand.exp, FALSE,
BFD_RELOC_XGATE_IMM3); BFD_RELOC_XGATE_IMM3);
}
else else
{
as_bad (_(":unknown relocation constraint size")); as_bad (_(":unknown relocation constraint size"));
} }
}
break; break;
case 'c': /* CCR register expected. */ case 'c': /* CCR register expected. */
@ -1333,20 +1296,15 @@ xgate_parse_operand (struct xgate_opcode *opcode,
if (operand.exp.X_op != O_register) if (operand.exp.X_op != O_register)
{ {
if (*op_constraint == '9') if (*op_constraint == '9')
{
fix_new_exp (frag_now, where, 2, &operand.exp, TRUE, fix_new_exp (frag_now, where, 2, &operand.exp, TRUE,
R_XGATE_PCREL_9); R_XGATE_PCREL_9);
}
else if (*op_constraint == 'a') else if (*op_constraint == 'a')
{
fix_new_exp (frag_now, where, 2, &operand.exp, TRUE, fix_new_exp (frag_now, where, 2, &operand.exp, TRUE,
R_XGATE_PCREL_10); R_XGATE_PCREL_10);
} }
}
else else
{ as_fatal (_("Operand `%x' not recognized in fixup8."),
as_fatal (_("Operand `%x' not recognized in fixup8."), operand.exp.X_op); operand.exp.X_op);
}
break; break;
case '?': case '?':
break; break;