/* tc-hppa.c -- Assemble for the PA
- Copyright 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 1989-2015 Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
seen in each subspace. */
static label_symbol_struct *label_symbols_rootp = NULL;
-/* Holds the last field selector. */
-static int hppa_field_selector;
-
/* Nonzero when strict matching is enabled. Zero otherwise.
Each opcode in the table has a flag which indicates whether or
#define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
#define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
+/* Store immediate values of shift/deposit/extract functions. */
+
+#define SAVE_IMMEDIATE(VALUE) \
+ { \
+ if (immediate_check) \
+ { \
+ if (pos == -1) \
+ pos = (VALUE); \
+ else if (len == -1) \
+ len = (VALUE); \
+ } \
+ }
+
/* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
main loop after insertion. */
hppa_field_selector is set by the parse_cons_expression_hppa. */
void
-cons_fix_new_hppa (fragS *frag, int where, int size, expressionS *exp)
+cons_fix_new_hppa (fragS *frag, int where, int size, expressionS *exp,
+ int hppa_field_selector)
{
unsigned int rel_type;
fix_new_hppa (frag, where, size,
(symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
hppa_field_selector, size * 8, 0, 0);
-
- /* Reset field selector to its default state. */
- hppa_field_selector = 0;
}
/* Mark (via expr_end) the end of an expression (I think). FIXME. */
if (fixp->fx_addsy == 0)
return &no_relocs;
- assert (hppa_fixp != 0);
- assert (section != 0);
+ gas_assert (hppa_fixp != 0);
+ gas_assert (section != 0);
reloc = xmalloc (sizeof (arelent));
/* ??? It might be better to hide this +8 stuff in tc_cfi_emit_pcrel_expr,
undefine DIFF_EXPR_OK, and let these sorts of complex expressions fail
when R_HPPA_COMPLEX == R_PARISC_UNIMPLEMENTED. */
- if (fixp->fx_r_type == R_HPPA_COMPLEX && fixp->fx_pcrel)
+ if (fixp->fx_r_type == (bfd_reloc_code_real_type) R_HPPA_COMPLEX
+ && fixp->fx_pcrel)
{
fixp->fx_r_type = R_HPPA_PCREL_CALL;
fixp->fx_offset += 8;
switch (fixp->fx_r_type)
{
default:
- assert (n_relocs == 1);
+ gas_assert (n_relocs == 1);
code = *codes[0];
(bfd_reloc_code_real_type) code);
reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
- assert (reloc->howto && (unsigned int) code == reloc->howto->type);
+ gas_assert (reloc->howto && (unsigned int) code == reloc->howto->type);
break;
}
#else /* OBJ_SOM */
/* The only time we ever use a R_COMP2 fixup is for the difference
of two symbols. With that in mind we fill in all four
relocs now and break out of the loop. */
- assert (i == 1);
+ gas_assert (i == 1);
relocs[0]->sym_ptr_ptr
= (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
relocs[0]->howto
register, so... */
have_prefix = TRUE;
}
- else if (S_GET_SEGMENT (sym) == &bfd_abs_section)
+ else if (S_GET_SEGMENT (sym) == bfd_abs_section_ptr)
num = S_GET_VALUE (sym);
else if (!strict)
{
/* Parse a .byte, .word, .long expression for the HPPA. Called by
cons via the TC_PARSE_CONS_EXPRESSION macro. */
-void
+int
parse_cons_expression_hppa (expressionS *exp)
{
- hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
+ int hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
expression (exp);
+ return hppa_field_selector;
}
/* Evaluate an absolute expression EXP which may be modified by
save_in = input_line_pointer;
input_line_pointer = *strp;
expression (&insn->exp);
- /* This is not perfect, but is a huge improvement over doing nothing.
+ expr_end = input_line_pointer;
+ input_line_pointer = save_in;
+ if (insn->exp.X_op != O_constant)
+ {
+ /* We have a non-match in strict mode. */
+ if (!strict)
+ as_bad (_("Bad segment (should be absolute)."));
+ return 0;
+ }
+ return evaluate_absolute (insn);
+}
+
+/* Get an absolute number. The input string is terminated at the
+ first whitespace character. */
+
+static int
+pa_get_number (struct pa_it *insn, char **strp)
+{
+ char *save_in;
+ char *s, c;
+ int result;
+
+ save_in = input_line_pointer;
+ input_line_pointer = *strp;
- The PA assembly syntax is ambiguous in a variety of ways. Consider
+ /* The PA assembly syntax is ambiguous in a variety of ways. Consider
this string "4 %r5" Is that the number 4 followed by the register
- r5, or is that 4 MOD r5?
+ r5, or is that 4 MOD r5? This situation occurs for example in the
+ coprocessor load and store instructions. Previously, calling
+ pa_get_absolute_expression directly results in r5 being entered
+ in the symbol table.
- If we get a modulo expression when looking for an absolute, we try
- again cutting off the input string at the first whitespace character. */
- if (insn->exp.X_op == O_modulus)
- {
- char *s, c;
- int retval;
+ So, when looking for an absolute number, we cut off the input string
+ at the first whitespace character. Thus, expressions should generally
+ contain no whitespace. */
- input_line_pointer = *strp;
- s = *strp;
- while (*s != ',' && *s != ' ' && *s != '\t')
- s++;
+ s = *strp;
+ while (*s != ',' && *s != ' ' && *s != '\t')
+ s++;
- c = *s;
- *s = 0;
+ c = *s;
+ *s = 0;
- retval = pa_get_absolute_expression (insn, strp);
+ result = pa_get_absolute_expression (insn, strp);
- input_line_pointer = save_in;
- *s = c;
- return evaluate_absolute (insn);
- }
- /* When in strict mode we have a non-match, fix up the pointers
- and return to our caller. */
- if (insn->exp.X_op != O_constant && strict)
- {
- expr_end = input_line_pointer;
- input_line_pointer = save_in;
- return 0;
- }
- if (insn->exp.X_op != O_constant)
- {
- as_bad (_("Bad segment (should be absolute)."));
- expr_end = input_line_pointer;
- input_line_pointer = save_in;
- return 0;
- }
- expr_end = input_line_pointer;
input_line_pointer = save_in;
- return evaluate_absolute (insn);
+ *s = c;
+ return result;
}
/* Given an argument location specification return the associated
const char *args;
int match = FALSE;
int comma = 0;
- int cmpltr, nullif, flag, cond, num;
+ int cmpltr, nullif, flag, cond, need_cond, num;
+ int immediate_check = 0, pos = -1, len = -1;
unsigned long opcode;
struct pa_opcode *insn;
/* Look up the opcode in the hash table. */
if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
{
- as_bad ("Unknown opcode: `%s'", str);
+ as_bad (_("Unknown opcode: `%s'"), str);
return;
}
opcode = insn->match;
strict = (insn->flags & FLAG_STRICT);
memset (&the_insn, 0, sizeof (the_insn));
+ need_cond = 1;
the_insn.reloc = R_HPPA_NONE;
break;
s = expr_end;
CHECK_FIELD (num, 32, 1, 0);
+ SAVE_IMMEDIATE(num);
INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
/* Handle a 5 bit immediate at 15. */
else
break;
+ /* Condition is not required with "dc". */
+ need_cond = 0;
INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
/* Handle 32 bit carry for ADD. */
else
break;
+ /* Condition is not required with "db". */
+ need_cond = 0;
INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
/* Handle 32 bit borrow for SUB. */
as_bad (_("Invalid Add Condition: %s"), name);
*s = c;
}
+ /* Except with "dc", we have a match failure with
+ 'A' if we don't have a doubleword condition. */
+ else if (*args == 'A' && need_cond)
+ break;
+
opcode |= cmpltr << 13;
INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
s += 2;
}
else
- as_bad (_("Invalid Bit Branch Condition: %c"), *s);
+ as_bad (_("Invalid Branch On Bit Condition: %c"), *s);
}
+ else
+ as_bad (_("Missing Branch On Bit Condition"));
+
INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 15);
/* Handle a compare/subtract condition. */
name);
*s = c;
}
+ /* Except with "db", we have a match failure with
+ 'S' if we don't have a doubleword condition. */
+ else if (*args == 'S' && need_cond)
+ break;
+
opcode |= cmpltr << 13;
INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
- /* Handle a logical instruction condition. */
+ /* Handle a logical instruction condition. */
case 'L':
case 'l':
cmpltr = 0;
as_bad (_("Invalid Logical Instruction Condition."));
*s = c;
}
+ /* 32-bit is default for no condition. */
+ else if (*args == 'L')
+ break;
+
opcode |= cmpltr << 13;
INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
case 'x':
case 'y':
cmpltr = 0;
+ /* Check immediate values in shift/extract/deposit
+ * instructions if they will give undefined behaviour. */
+ immediate_check = 1;
if (*s == ',')
{
save_s = s++;
as_bad (_("Invalid Shift/Extract/Deposit Condition."));
*s = c;
}
+
INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
/* Handle a unit instruction condition. */
flag = 0;
if (*s == ',')
{
+ int uxor;
s++;
/* 64 bit conditions. */
else if (*s == '*')
break;
+ /* The uxor instruction only supports unit conditions
+ not involving carries. */
+ uxor = (opcode & 0xfc000fc0) == 0x08000380;
if (strncasecmp (s, "sbz", 3) == 0)
{
cmpltr = 2;
cmpltr = 3;
s += 3;
}
- else if (strncasecmp (s, "sdc", 3) == 0)
+ else if (!uxor && strncasecmp (s, "sdc", 3) == 0)
{
cmpltr = 4;
s += 3;
}
- else if (strncasecmp (s, "sbc", 3) == 0)
+ else if (!uxor && strncasecmp (s, "sbc", 3) == 0)
{
cmpltr = 6;
s += 3;
}
- else if (strncasecmp (s, "shc", 3) == 0)
+ else if (!uxor && strncasecmp (s, "shc", 3) == 0)
{
cmpltr = 7;
s += 3;
flag = 1;
s += 3;
}
- else if (strncasecmp (s, "ndc", 3) == 0)
+ else if (!uxor && strncasecmp (s, "ndc", 3) == 0)
{
cmpltr = 4;
flag = 1;
s += 3;
}
- else if (strncasecmp (s, "nbc", 3) == 0)
+ else if (!uxor && strncasecmp (s, "nbc", 3) == 0)
{
cmpltr = 6;
flag = 1;
s += 3;
}
- else if (strncasecmp (s, "nhc", 3) == 0)
+ else if (!uxor && strncasecmp (s, "nhc", 3) == 0)
{
cmpltr = 7;
flag = 1;
flag = 0;
s += 3;
}
- else if (strncasecmp (s, "swc", 3) == 0)
+ else if (!uxor && strncasecmp (s, "swc", 3) == 0)
{
cmpltr = 5;
flag = 0;
flag = 1;
s += 3;
}
- else if (strncasecmp (s, "nwc", 3) == 0)
+ else if (!uxor && strncasecmp (s, "nwc", 3) == 0)
{
cmpltr = 5;
flag = 1;
else if (*args != 'U' || (*s != ' ' && *s != '\t'))
as_bad (_("Invalid Unit Instruction Condition."));
}
+ /* 32-bit is default for no condition. */
+ else if (*args == 'U')
+ break;
+
opcode |= cmpltr << 13;
INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
break;
s = expr_end;
CHECK_FIELD (num, 31, 0, strict);
+ SAVE_IMMEDIATE(num);
INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
/* Handle a 6 bit shift count at 20,22:26. */
break;
s = expr_end;
CHECK_FIELD (num, 63, 0, strict);
+ SAVE_IMMEDIATE(num);
num = 63 - num;
opcode |= (num & 0x20) << 6;
INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
break;
s = expr_end;
CHECK_FIELD (num, 64, 1, strict);
+ SAVE_IMMEDIATE(num);
num--;
opcode |= (num & 0x20) << 3;
num = 31 - (num & 0x1f);
break;
s = expr_end;
CHECK_FIELD (num, 64, 1, strict);
+ SAVE_IMMEDIATE(num);
num--;
opcode |= (num & 0x20) << 7;
num = 31 - (num & 0x1f);
break;
s = expr_end;
CHECK_FIELD (num, 31, 0, strict);
+ SAVE_IMMEDIATE(num);
INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
/* Handle a 6 bit bit position at 20,22:26. */
break;
s = expr_end;
CHECK_FIELD (num, 63, 0, strict);
+ SAVE_IMMEDIATE(num);
opcode |= (num & 0x20) << 6;
INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
case 'v':
if (*s++ != ',')
as_bad (_("Invalid SFU identifier"));
- num = pa_get_absolute_expression (&the_insn, &s);
+ num = pa_get_number (&the_insn, &s);
if (strict && the_insn.exp.X_op != O_constant)
break;
s = expr_end;
/* Handle a 20 bit SOP field for spop0. */
case 'O':
- num = pa_get_absolute_expression (&the_insn, &s);
+ num = pa_get_number (&the_insn, &s);
if (strict && the_insn.exp.X_op != O_constant)
break;
s = expr_end;
/* Handle a 15bit SOP field for spop1. */
case 'o':
- num = pa_get_absolute_expression (&the_insn, &s);
+ num = pa_get_number (&the_insn, &s);
if (strict && the_insn.exp.X_op != O_constant)
break;
s = expr_end;
/* Handle a 10bit SOP field for spop3. */
case '0':
- num = pa_get_absolute_expression (&the_insn, &s);
+ num = pa_get_number (&the_insn, &s);
if (strict && the_insn.exp.X_op != O_constant)
break;
s = expr_end;
/* Handle a 15 bit SOP field for spop2. */
case '1':
- num = pa_get_absolute_expression (&the_insn, &s);
+ num = pa_get_number (&the_insn, &s);
if (strict && the_insn.exp.X_op != O_constant)
break;
s = expr_end;
case 'u':
if (*s++ != ',')
as_bad (_("Invalid COPR identifier"));
- num = pa_get_absolute_expression (&the_insn, &s);
+ num = pa_get_number (&the_insn, &s);
if (strict && the_insn.exp.X_op != O_constant)
break;
s = expr_end;
/* Handle a 22bit SOP field for copr. */
case '2':
- num = pa_get_absolute_expression (&the_insn, &s);
+ num = pa_get_number (&the_insn, &s);
if (strict && the_insn.exp.X_op != O_constant)
break;
s = expr_end;
case 't':
if (!pa_parse_number (&s, 3))
break;
- num = (pa_number & ~FP_REG_RSEL) - FP_REG_BASE;
+ /* RSEL should not be set. */
+ if (pa_number & FP_REG_RSEL)
+ break;
+ num = pa_number - FP_REG_BASE;
CHECK_FIELD (num, 31, 0, 0);
INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
break;
}
+ if (immediate_check)
+ {
+ if (pos != -1 && len != -1 && pos < len - 1)
+ as_warn (_("Immediates %d and %d will give undefined behavior."),
+ pos, len);
+ }
+
the_insn.opcode = opcode;
}
char *to;
/* The had better be something to assemble. */
- assert (str);
+ gas_assert (str);
/* If we are within a procedure definition, make sure we've
defined a label for the procedure; handle case where the
subsegT save_subseg;
unsigned int unwind;
int reloc;
- char *p;
+ char *name, *p;
+ symbolS *symbolP;
if ((bfd_get_section_flags (stdoutput, now_seg)
& (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
!= (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
return;
+ if (call_info->start_symbol == NULL)
+ /* This can happen if there were errors earlier on in the assembly. */
+ return;
+
+ /* Replace the start symbol with a local symbol that will be reduced
+ to a section offset. This avoids problems with weak functions with
+ multiple definitions, etc. */
+ name = xmalloc (strlen ("L$\001start_")
+ + strlen (S_GET_NAME (call_info->start_symbol))
+ + 1);
+ strcpy (name, "L$\001start_");
+ strcat (name, S_GET_NAME (call_info->start_symbol));
+
+ /* If we have a .procend preceded by a .exit, then the symbol will have
+ already been defined. In that case, we don't want another unwind
+ entry. */
+ symbolP = symbol_find (name);
+ if (symbolP)
+ {
+ xfree (name);
+ return;
+ }
+ else
+ {
+ symbolP = symbol_new (name, now_seg,
+ S_GET_VALUE (call_info->start_symbol), frag_now);
+ gas_assert (symbolP);
+ S_CLEAR_EXTERNAL (symbolP);
+ symbol_table_insert (symbolP);
+ }
+
reloc = R_PARISC_SEGREL32;
save_seg = now_seg;
save_subseg = now_subseg;
/* Relocation info. for start offset of the function. */
md_number_to_chars (p, 0, 4);
fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
- call_info->start_symbol, (offsetT) 0,
+ symbolP, (offsetT) 0,
(expressionS *) NULL, 0, reloc,
e_fsel, 32, 0, 0);
symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
frag_now);
- assert (symbolP);
+ gas_assert (symbolP);
S_CLEAR_EXTERNAL (symbolP);
symbol_table_insert (symbolP);
}
/* Mark the end of the function, stuff away the location of the frag
for the end of the function, and finally call pa_build_unwind_subspace
to add an entry in the unwind table. */
+ (void) where;
hppa_elf_mark_end_of_function ();
pa_build_unwind_subspace (last_call_info);
#else
to the SOM BFD backend. */
#ifdef obj_set_symbol_type
obj_set_symbol_type (bfdsym, (int) type);
+#else
+ (void) type;
#endif
/* Now that the type of the exported symbol has been handled,
arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
#if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
symbol_arg_reloc_info (symbolP) |= arg_reloc;
+#else
+ (void) arg_reloc;
#endif
*input_line_pointer = c;
}
arg_reloc = pa_build_arg_reloc (name);
#if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
symbol_arg_reloc_info (symbolP) |= arg_reloc;
+#else
+ (void) arg_reloc;
#endif
*input_line_pointer = c;
}
{
char *name, *ss_name, c;
char loadable, code_only, comdat, common, dup_common, zero, sort;
- int i, access, space_index, alignment, quadrant, applicable, flags;
+ int i, access_ctr, space_index, alignment, quadrant, applicable, flags;
sd_chain_struct *space;
ssd_chain_struct *ssd;
asection *section;
/* Load default values. */
sort = 0;
- access = 0x7f;
+ access_ctr = 0x7f;
loadable = 1;
comdat = 0;
common = 0;
space_index = pa_def_subspaces[i].space_index;
alignment = pa_def_subspaces[i].alignment;
quadrant = pa_def_subspaces[i].quadrant;
- access = pa_def_subspaces[i].access;
+ access_ctr = pa_def_subspaces[i].access;
sort = pa_def_subspaces[i].sort;
break;
}
{
*input_line_pointer = c;
input_line_pointer++;
- access = get_absolute_expression ();
+ access_ctr = get_absolute_expression ();
}
else if ((strncasecmp (name, "sort", 4) == 0))
{
current_subspace = update_subspace (space, ss_name, loadable,
code_only, comdat, common,
- dup_common, sort, zero, access,
+ dup_common, sort, zero, access_ctr,
space_index, alignment, quadrant,
section);
else
current_subspace = create_new_subspace (space, ss_name, loadable,
code_only, comdat, common,
dup_common, zero, sort,
- access, space_index,
+ access_ctr, space_index,
alignment, quadrant, section);
demand_empty_rest_of_line ();
int dup_common,
int is_zero ATTRIBUTE_UNUSED,
int sort,
- int access,
+ int access_ctr,
int space_index ATTRIBUTE_UNUSED,
int alignment ATTRIBUTE_UNUSED,
int quadrant,
}
#ifdef obj_set_subsection_attributes
- obj_set_subsection_attributes (seg, space->sd_seg, access, sort,
+ obj_set_subsection_attributes (seg, space->sd_seg, access_ctr, sort,
quadrant, comdat, common, dup_common);
#endif
int dup_common,
int sort,
int zero ATTRIBUTE_UNUSED,
- int access,
+ int access_ctr,
int space_index ATTRIBUTE_UNUSED,
int alignment ATTRIBUTE_UNUSED,
int quadrant,
chain_entry = is_defined_subspace (name);
#ifdef obj_set_subsection_attributes
- obj_set_subsection_attributes (section, space->sd_seg, access, sort,
+ obj_set_subsection_attributes (section, space->sd_seg, access_ctr, sort,
quadrant, comdat, common, dup_common);
#endif
return 1;
#endif
- assert (fixp->fx_addsy != NULL);
+ gas_assert (fixp->fx_addsy != NULL);
/* Ensure we emit a relocation for global symbols so that dynamic
linking works. */
{
p = regname + 2;
regnum = strtoul (p, &q, 10);
+#if TARGET_ARCH_SIZE == 64
if (p == q || *q || regnum <= 4 || regnum >= 32)
return -1;
regnum += 32 - 4;
+#else
+ if (p == q
+ || (*q && ((*q != 'L' && *q != 'R') || *(q + 1)))
+ || regnum <= 4 || regnum >= 32)
+ return -1;
+ regnum = (regnum - 4) * 2 + 32;
+ if (*q == 'R')
+ regnum++;
+#endif
}
return regnum;
}