aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gas/ChangeLog5
-rw-r--r--gas/config/tc-avr.c390
-rw-r--r--gas/config/tc-ns32k.c978
3 files changed, 745 insertions, 628 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index c728a04..760622e 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,8 @@
+2000-07-27 Kazu Hirata <kazu@hxi.com>
+
+ * config/tc-avr.c: Fix formatting.
+ * config/tc-ns32k.c: Likewise.
+
2000-07-27 Alan Modra <alan@linuxcare.com.au>
* config/tc-d10v.c (find_opcode): Remove extraneous `='.
diff --git a/gas/config/tc-avr.c b/gas/config/tc-avr.c
index 8e7b304..cb5c426 100644
--- a/gas/config/tc-avr.c
+++ b/gas/config/tc-avr.c
@@ -29,7 +29,7 @@ struct avr_opcodes_s
{
char *name;
char *constraints;
- int insn_size; /* in words */
+ int insn_size; /* In words. */
int isa;
unsigned int bin_opcode;
};
@@ -43,7 +43,6 @@ struct avr_opcodes_s avr_opcodes[] =
{NULL, NULL, 0, 0, 0}
};
-
const char comment_chars[] = ";";
const char line_comment_chars[] = "#";
const char line_separator_chars[] = "$";
@@ -91,7 +90,6 @@ static struct mcu_type_s mcu_types[] =
{NULL, 0, 0}
};
-
/* Current MCU type. */
static struct mcu_type_s default_mcu = {"avr2", AVR_ISA_2xxx,bfd_mach_avr2};
static struct mcu_type_s *avr_mcu = &default_mcu;
@@ -99,9 +97,9 @@ static struct mcu_type_s *avr_mcu = &default_mcu;
/* AVR target-specific switches. */
struct avr_opt_s
{
- int all_opcodes; /* -mall-opcodes: accept all known AVR opcodes */
- int no_skip_bug; /* -mno-skip-bug: no warnings for skipping 2-word insns */
- int no_wrap; /* -mno-wrap: reject rjmp/rcall with 8K wrap-around */
+ int all_opcodes; /* -mall-opcodes: accept all known AVR opcodes */
+ int no_skip_bug; /* -mno-skip-bug: no warnings for skipping 2-word insns */
+ int no_wrap; /* -mno-wrap: reject rjmp/rcall with 8K wrap-around */
};
static struct avr_opt_s avr_opt = { 0, 0, 0 };
@@ -120,17 +118,16 @@ const pseudo_typeS md_pseudo_table[] =
#define LDI_IMMEDIATE(x) (((x) & 0xf) | (((x) << 4) & 0xf00))
static void show_mcu_list (FILE *stream);
-static char * skip_space (char * s);
-static char * extract_word (char *from, char *to, int limit);
+static char *skip_space (char *s);
+static char *extract_word (char *from, char *to, int limit);
static unsigned int avr_operand (struct avr_opcodes_s *opcode,
int where, char *op, char **line);
static unsigned int avr_operands (struct avr_opcodes_s *opcode, char **line);
-static unsigned int avr_get_constant (char * str, int max);
-static char *parse_exp (char *s, expressionS * op);
+static unsigned int avr_get_constant (char *str, int max);
+static char *parse_exp (char *s, expressionS *op);
static bfd_reloc_code_real_type avr_ldi_expression (expressionS *exp);
long md_pcrel_from_section PARAMS ((fixS *, segT));
-
#define EXP_MOD_NAME(i) exp_mod[i].name
#define EXP_MOD_RELOC(i) exp_mod[i].reloc
#define EXP_MOD_NEG_RELOC(i) exp_mod[i].neg_reloc
@@ -138,13 +135,14 @@ long md_pcrel_from_section PARAMS ((fixS *, segT));
struct exp_mod_s
{
- char * name;
+ char *name;
bfd_reloc_code_real_type reloc;
bfd_reloc_code_real_type neg_reloc;
int have_pm;
};
-static struct exp_mod_s exp_mod[] = {
+static struct exp_mod_s exp_mod[] =
+{
{"hh8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 1},
{"pm_hh8", BFD_RELOC_AVR_HH8_LDI_PM, BFD_RELOC_AVR_HH8_LDI_PM_NEG, 0},
{"hi8", BFD_RELOC_AVR_HI8_LDI, BFD_RELOC_AVR_HI8_LDI_NEG, 1},
@@ -166,45 +164,49 @@ static struct hash_control *avr_mod_hash;
#define OPTION_NO_SKIP_BUG (OPTION_MD_BASE + 2)
#define OPTION_NO_WRAP (OPTION_MD_BASE + 3)
-struct option md_longopts[] = {
+struct option md_longopts[] =
+{
{ "mmcu", required_argument, NULL, OPTION_MMCU },
{ "mall-opcodes", no_argument, NULL, OPTION_ALL_OPCODES },
{ "mno-skip-bug", no_argument, NULL, OPTION_NO_SKIP_BUG },
{ "mno-wrap", no_argument, NULL, OPTION_NO_WRAP },
{ NULL, no_argument, NULL, 0 }
};
-size_t md_longopts_size = sizeof(md_longopts);
+size_t md_longopts_size = sizeof (md_longopts);
/* Display nicely formatted list of known MCU names. */
+
static void
-show_mcu_list (FILE *stream)
+show_mcu_list (stream)
+ FILE *stream;
{
int i, x;
fprintf (stream, _("Known MCU names:"));
x = 1000;
+
for (i = 0; mcu_types[i].name; i++)
{
int len = strlen (mcu_types[i].name);
+
x += len + 1;
+
if (x < 75)
- {
- fprintf (stream, " %s", mcu_types[i].name);
- }
+ fprintf (stream, " %s", mcu_types[i].name);
else
{
fprintf (stream, "\n %s", mcu_types[i].name);
x = len + 2;
}
}
- fprintf (stream, "\n");
+
+ fprintf (stream, "\n");
}
-
static inline char *
skip_space (s)
- char * s;
+ char *s;
{
while (*s == ' ' || *s == '\t')
++s;
@@ -212,6 +214,7 @@ skip_space (s)
}
/* Extract one word from FROM and copy it to TO. */
+
static char *
extract_word (char *from, char *to, int limit)
{
@@ -222,13 +225,15 @@ extract_word (char *from, char *to, int limit)
/* Drop leading whitespace. */
from = skip_space (from);
*to = 0;
+
/* Find the op code end. */
- for (op_start = op_end = from; *op_end != 0 && is_part_of_name(*op_end); )
+ for (op_start = op_end = from; *op_end != 0 && is_part_of_name (*op_end);)
{
to[size++] = *op_end++;
if (size + 1 >= limit)
break;
}
+
to[size] = 0;
return op_end;
}
@@ -244,7 +249,7 @@ md_estimate_size_before_relax (fragp, seg)
void
md_show_usage (stream)
- FILE *stream;
+ FILE *stream;
{
fprintf (stream,
_("AVR options:\n"
@@ -269,8 +274,9 @@ static void
avr_set_arch (dummy)
int dummy ATTRIBUTE_UNUSED;
{
- char * str;
- str = (char *)alloca (20);
+ char *str;
+
+ str = (char *) alloca (20);
input_line_pointer = extract_word (input_line_pointer, str, 20);
md_parse_option (OPTION_MMCU, str);
bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
@@ -293,7 +299,7 @@ md_parse_option (c, arg)
char *arg1 = arg;
do
- *t = tolower(*arg1++);
+ *t = tolower (*arg1++);
while (*t++);
}
@@ -310,7 +316,6 @@ md_parse_option (c, arg)
/* It is OK to redefine mcu type within the same avr[1-5] bfd machine
type - this for allows passing -mmcu=... via gcc ASM_SPEC as well
as .arch ... in the asm output at the same time. */
-
if (avr_mcu == &default_mcu || avr_mcu->mach == mcu_types[i].mach)
avr_mcu = &mcu_types[i];
else
@@ -328,20 +333,22 @@ md_parse_option (c, arg)
avr_opt.no_wrap = 1;
return 1;
}
+
return 0;
}
symbolS *
-md_undefined_symbol(name)
+md_undefined_symbol (name)
char *name ATTRIBUTE_UNUSED;
{
return 0;
}
-/* Convert a string pointed to by input_line_pointer into a floating point
- constant of type `type', and store the appropriate bytes to `*litP'.
- The number of LITTLENUMS emitted is stored in `*sizeP'. Returns NULL if
- OK, or an error message otherwise. */
+/* Turn a string in input_line_pointer into a floating point constant
+ of type TYPE, and store the appropriate bytes in *LITP. The number
+ of LITTLENUMS emitted is stored in *SIZEP. An error message is
+ returned, or NULL on OK. */
+
char *
md_atof (type, litP, sizeP)
int type;
@@ -371,54 +378,53 @@ md_atof (type, litP, sizeP)
input_line_pointer = t;
*sizeP = prec * sizeof (LITTLENUM_TYPE);
+
/* This loop outputs the LITTLENUMs in REVERSE order. */
for (wordP = words + prec - 1; prec--;)
{
md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE));
litP += sizeof (LITTLENUM_TYPE);
}
+
return NULL;
}
void
md_convert_frag (abfd, sec, fragP)
- bfd *abfd ATTRIBUTE_UNUSED;
- asection *sec ATTRIBUTE_UNUSED;
- fragS *fragP ATTRIBUTE_UNUSED;
+ bfd *abfd ATTRIBUTE_UNUSED;
+ asection *sec ATTRIBUTE_UNUSED;
+ fragS *fragP ATTRIBUTE_UNUSED;
{
abort ();
}
-
void
md_begin ()
{
unsigned int i;
struct avr_opcodes_s *opcode;
- avr_hash = hash_new();
+ avr_hash = hash_new ();
/* Insert unique names into hash table. This hash table then provides a
quick index to the first opcode with a particular name in the opcode
table. */
-
for (opcode = avr_opcodes; opcode->name; opcode++)
hash_insert (avr_hash, opcode->name, (char *) opcode);
avr_mod_hash = hash_new ();
for (i = 0; i < sizeof (exp_mod) / sizeof (exp_mod[0]); ++i)
- hash_insert (avr_mod_hash, EXP_MOD_NAME(i), (void*)(i+10));
-
+ hash_insert (avr_mod_hash, EXP_MOD_NAME (i), (void *) (i + 10));
+
bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
}
-
/* Resolve STR as a constant expression and return the result.
- If result greater than MAX then error. */
+ If result greater than MAX then error. */
static unsigned int
avr_get_constant (str, max)
- char * str;
+ char *str;
int max;
{
expressionS ex;
@@ -430,13 +436,13 @@ avr_get_constant (str, max)
as_bad (_("constant value required"));
if (ex.X_add_number > max || ex.X_add_number < 0)
- as_bad (_("number must be less than %d"), max+1);
+ as_bad (_("number must be less than %d"), max + 1);
+
return ex.X_add_number;
}
-
/* Parse instruction operands.
- Returns binary opcode. */
+ Return binary opcode. */
static unsigned int
avr_operands (opcode, line)
@@ -448,7 +454,7 @@ avr_operands (opcode, line)
char *frag = frag_more (opcode->insn_size * 2);
char *str = *line;
int where = frag - frag_now->fr_literal;
- static unsigned int prev = 0; /* previous opcode */
+ static unsigned int prev = 0; /* Previous opcode. */
/* Opcode have operands. */
if (*op)
@@ -469,6 +475,7 @@ avr_operands (opcode, line)
{
if (*op == ',')
++op;
+
if (*op == '=')
{
reg2 = reg1;
@@ -487,6 +494,7 @@ avr_operands (opcode, line)
reg2 = avr_operand (opcode, where, op, &str);
}
+
if (reg1_present && reg2_present)
reg2 = (reg2 & 0xf) | ((reg2 << 5) & 0x200);
else if (reg2_present)
@@ -520,20 +528,19 @@ avr_operands (opcode, line)
as_warn (_("skipping two-word instruction"));
}
- bfd_putl32 ((bfd_vma)bin, frag);
+ bfd_putl32 ((bfd_vma) bin, frag);
}
else
- bfd_putl16 ((bfd_vma)bin, frag);
+ bfd_putl16 ((bfd_vma) bin, frag);
prev = bin;
*line = str;
return bin;
}
-
/* Parse one instruction operand.
- Returns operand bitmask. Also fixups can be generated. */
-
+ Return operand bitmask. Also fixups can be generated. */
+
static unsigned int
avr_operand (opcode, where, op, line)
struct avr_opcodes_s *opcode;
@@ -553,71 +560,70 @@ avr_operand (opcode, where, op, line)
case 'r':
case 'a':
case 'v':
- {
- op_mask = -1;
-
- if (*str == 'r' || *str == 'R')
- {
- char r_name[20];
-
- str = extract_word (str, r_name, sizeof (r_name));
- if (isdigit(r_name[1]))
- {
- if (r_name[2] == '\0')
- op_mask = r_name[1] - '0';
- else if (r_name[1] != '0'
- && isdigit(r_name[2])
- && r_name[3] == '\0')
- op_mask = (r_name[1] - '0') * 10 + r_name[2] - '0';
- }
- }
- else
- {
- op_mask = avr_get_constant (str, 31);
- str = input_line_pointer;
- }
-
- if (op_mask <= 31)
- {
- switch (*op)
- {
- case 'a':
- if (op_mask < 16 || op_mask > 23)
- as_bad (_("register r16-r23 required"));
- op_mask -= 16;
- break;
-
- case 'd':
- if (op_mask < 16)
- as_bad (_("register number above 15 required"));
- op_mask -= 16;
- break;
-
- case 'v':
- if (op_mask & 1)
- as_bad (_("even register number required"));
- op_mask >>= 1;
- break;
-
- case 'w':
- op_mask -= 24;
- if (op_mask & 1 || op_mask > 6)
- as_bad (_("register r24, r26, r28 or r30 required"));
- op_mask >>= 1;
- break;
- }
- break;
- }
- as_bad (_("register name or number from 0 to 31 required"));
- }
+ op_mask = -1;
+
+ if (*str == 'r' || *str == 'R')
+ {
+ char r_name[20];
+
+ str = extract_word (str, r_name, sizeof (r_name));
+ if (isdigit (r_name[1]))
+ {
+ if (r_name[2] == '\0')
+ op_mask = r_name[1] - '0';
+ else if (r_name[1] != '0'
+ && isdigit (r_name[2])
+ && r_name[3] == '\0')
+ op_mask = (r_name[1] - '0') * 10 + r_name[2] - '0';
+ }
+ }
+ else
+ {
+ op_mask = avr_get_constant (str, 31);
+ str = input_line_pointer;
+ }
+
+ if (op_mask <= 31)
+ {
+ switch (*op)
+ {
+ case 'a':
+ if (op_mask < 16 || op_mask > 23)
+ as_bad (_("register r16-r23 required"));
+ op_mask -= 16;
+ break;
+
+ case 'd':
+ if (op_mask < 16)
+ as_bad (_("register number above 15 required"));
+ op_mask -= 16;
+ break;
+
+ case 'v':
+ if (op_mask & 1)
+ as_bad (_("even register number required"));
+ op_mask >>= 1;
+ break;
+
+ case 'w':
+ op_mask -= 24;
+ if (op_mask & 1 || op_mask > 6)
+ as_bad (_("register r24, r26, r28 or r30 required"));
+ op_mask >>= 1;
+ break;
+ }
+ break;
+ }
+ as_bad (_("register name or number from 0 to 31 required"));
break;
case 'e':
{
char c;
+
if (*str == '-')
{
- str = skip_space (str+1);
+ str = skip_space (str + 1);
op_mask = 0x1002;
}
c = tolower (*str);
@@ -628,7 +634,7 @@ avr_operand (opcode, where, op, line)
else if (c != 'z')
as_bad (_("pointer register (X, Y or Z) required"));
- str = skip_space (str+1);
+ str = skip_space (str + 1);
if (*str == '+')
{
++str;
@@ -639,7 +645,6 @@ avr_operand (opcode, where, op, line)
/* avr1 can do "ld r,Z" and "st Z,r" but no other pointer
registers, no predecrement, no postincrement. */
-
if (!avr_opt.all_opcodes && (op_mask & 0x100F)
&& !(avr_mcu->isa & AVR_ISA_SRAM))
as_bad (_("addressing mode not supported"));
@@ -647,25 +652,25 @@ avr_operand (opcode, where, op, line)
break;
case 'z':
- {
- if (*str == '-')
- as_bad (_("can't predecrement"));
-
- if (! (*str == 'z' || *str == 'Z'))
- as_bad (_("pointer register Z required"));
-
- str = skip_space (str + 1);
- if (*str == '+')
- {
- ++str;
- op_mask |= 1;
- }
- }
+ if (*str == '-')
+ as_bad (_("can't predecrement"));
+
+ if (! (*str == 'z' || *str == 'Z'))
+ as_bad (_("pointer register Z required"));
+
+ str = skip_space (str + 1);
+
+ if (*str == '+')
+ {
+ ++str;
+ op_mask |= 1;
+ }
break;
case 'b':
{
char c = tolower (*str++);
+
if (c == 'y')
op_mask |= 0x8;
else if (c != 'z')
@@ -682,47 +687,36 @@ avr_operand (opcode, where, op, line)
break;
case 'h':
- {
- str = parse_exp (str, &op_expr);
- fix_new_exp (frag_now, where, opcode->insn_size * 2,
- &op_expr, false, BFD_RELOC_AVR_CALL);
-
- }
+ str = parse_exp (str, &op_expr);
+ fix_new_exp (frag_now, where, opcode->insn_size * 2,
+ &op_expr, false, BFD_RELOC_AVR_CALL);
break;
case 'L':
- {
- str = parse_exp (str, &op_expr);
- fix_new_exp (frag_now, where, opcode->insn_size * 2,
- &op_expr, true, BFD_RELOC_AVR_13_PCREL);
-
- }
+ str = parse_exp (str, &op_expr);
+ fix_new_exp (frag_now, where, opcode->insn_size * 2,
+ &op_expr, true, BFD_RELOC_AVR_13_PCREL);
break;
case 'l':
- {
- str = parse_exp (str, &op_expr);
- fix_new_exp (frag_now, where, opcode->insn_size * 2,
- &op_expr, true, BFD_RELOC_AVR_7_PCREL);
-
- }
+ str = parse_exp (str, &op_expr);
+ fix_new_exp (frag_now, where, opcode->insn_size * 2,
+ &op_expr, true, BFD_RELOC_AVR_7_PCREL);
break;
case 'i':
- {
- str = parse_exp (str, &op_expr);
- fix_new_exp (frag_now, where+2, opcode->insn_size * 2,
- &op_expr, false, BFD_RELOC_16);
-
- }
+ str = parse_exp (str, &op_expr);
+ fix_new_exp (frag_now, where + 2, opcode->insn_size * 2,
+ &op_expr, false, BFD_RELOC_16);
break;
case 'M':
{
bfd_reloc_code_real_type r_type;
- input_line_pointer = str;
- r_type = avr_ldi_expression (&op_expr);
- str = input_line_pointer;
+
+ input_line_pointer = str;
+ r_type = avr_ldi_expression (&op_expr);
+ str = input_line_pointer;
fix_new_exp (frag_now, where, 3,
&op_expr, false, r_type);
}
@@ -731,6 +725,7 @@ avr_operand (opcode, where, op, line)
case 'n':
{
unsigned int x;
+
x = ~avr_get_constant (str, 255);
str = input_line_pointer;
op_mask |= (x & 0xf) | ((x << 4) & 0xf00);
@@ -740,6 +735,7 @@ avr_operand (opcode, where, op, line)
case 'K':
{
unsigned int x;
+
x = avr_get_constant (str, 63);
str = input_line_pointer;
op_mask |= (x & 0xf) | ((x & 0x30) << 2);
@@ -750,6 +746,7 @@ avr_operand (opcode, where, op, line)
case 's':
{
unsigned int x;
+
x = avr_get_constant (str, 7);
str = input_line_pointer;
if (*op == 'S')
@@ -761,6 +758,7 @@ avr_operand (opcode, where, op, line)
case 'P':
{
unsigned int x;
+
x = avr_get_constant (str, 63);
str = input_line_pointer;
op_mask |= (x & 0xf) | ((x & 0x30) << 5);
@@ -770,22 +768,27 @@ avr_operand (opcode, where, op, line)
case 'p':
{
unsigned int x;
+
x = avr_get_constant (str, 31);
str = input_line_pointer;
op_mask |= x << 3;
}
break;
+
case '?':
break;
+
default:
as_bad (_("unknown constraint `%c'"), *op);
}
+
*line = str;
return op_mask;
}
/* GAS will call this function for each section at the end of the assembly,
to permit the CPU backend to adjust the alignment of a section. */
+
valueT
md_section_align (seg, addr)
asection *seg;
@@ -800,20 +803,23 @@ md_section_align (seg, addr)
relative adjustment should be made. On many processors, the base
of a PC relative instruction is the next instruction, so this
macro would return the length of an instruction. */
+
long
md_pcrel_from_section (fixp, sec)
fixS *fixp;
segT sec;
{
- if (fixp->fx_addsy != (symbolS *)NULL
+ if (fixp->fx_addsy != (symbolS *) NULL
&& (!S_IS_DEFINED (fixp->fx_addsy)
|| (S_GET_SEGMENT (fixp->fx_addsy) != sec)))
return 0;
+
return fixp->fx_frag->fr_address + fixp->fx_where;
}
/* GAS will call this for each fixup. It should store the correct
- value in the object file. */
+ value in the object file. */
+
int
md_apply_fix3 (fixp, valuep, seg)
fixS *fixp;
@@ -832,6 +838,7 @@ md_apply_fix3 (fixp, valuep, seg)
else if (fixp->fx_pcrel)
{
segT s = S_GET_SEGMENT (fixp->fx_addsy);
+
if (fixp->fx_addsy && (s == seg || s == absolute_section))
{
value = S_GET_VALUE (fixp->fx_addsy) + *valuep;
@@ -843,6 +850,7 @@ md_apply_fix3 (fixp, valuep, seg)
else
{
value = fixp->fx_offset;
+
if (fixp->fx_subsy != (symbolS *) NULL)
{
if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
@@ -853,11 +861,12 @@ md_apply_fix3 (fixp, valuep, seg)
else
{
/* We don't actually support subtracting a symbol. */
- as_bad_where (fixp->fx_file, fixp->fx_line,
+ as_bad_where (fixp->fx_file, fixp->fx_line,
_("expression too complex"));
}
}
}
+
switch (fixp->fx_r_type)
{
default:
@@ -884,9 +893,11 @@ md_apply_fix3 (fixp, valuep, seg)
if (value & 1)
as_bad_where (fixp->fx_file, fixp->fx_line,
_("odd address operand: %ld"), value);
+
/* Instruction addresses are always right-shifted by 1. */
value >>= 1;
--value; /* Correct PC. */
+
if (value < -64 || value > 63)
as_bad_where (fixp->fx_file, fixp->fx_line,
_("operand out of range: %ld"), value);
@@ -898,6 +909,7 @@ md_apply_fix3 (fixp, valuep, seg)
if (value & 1)
as_bad_where (fixp->fx_file, fixp->fx_line,
_("odd address operand: %ld"), value);
+
/* Instruction addresses are always right-shifted by 1. */
value >>= 1;
--value; /* Correct PC. */
@@ -923,7 +935,7 @@ md_apply_fix3 (fixp, valuep, seg)
break;
case BFD_RELOC_AVR_16_PM:
- bfd_putl16 ((bfd_vma) (value>>1), where);
+ bfd_putl16 ((bfd_vma) (value >> 1), where);
break;
case BFD_RELOC_AVR_LO8_LDI:
@@ -993,6 +1005,7 @@ md_apply_fix3 (fixp, valuep, seg)
case BFD_RELOC_AVR_CALL:
{
unsigned long x;
+
x = bfd_getl16 (where);
if (value & 1)
as_bad_where (fixp->fx_file, fixp->fx_line,
@@ -1000,13 +1013,13 @@ md_apply_fix3 (fixp, valuep, seg)
value >>= 1;
x |= ((value & 0x10000) | ((value << 3) & 0x1f00000)) >> 16;
bfd_putl16 ((bfd_vma) x, where);
- bfd_putl16 ((bfd_vma) (value & 0xffff), where+2);
+ bfd_putl16 ((bfd_vma) (value & 0xffff), where + 2);
}
break;
default:
- as_fatal ( _("line %d: unknown relocation type: 0x%x"),
- fixp->fx_line, fixp->fx_r_type);
+ as_fatal (_("line %d: unknown relocation type: 0x%x"),
+ fixp->fx_line, fixp->fx_r_type);
break;
}
}
@@ -1030,13 +1043,12 @@ md_apply_fix3 (fixp, valuep, seg)
return 0;
}
-
/* A `BFD_ASSEMBLER' GAS will call this to generate a reloc. GAS
will pass the resulting reloc to `bfd_install_relocation'. This
currently works poorly, as `bfd_install_relocation' often does the
wrong thing, and instances of `tc_gen_reloc' have been written to
work around the problems, which in turns makes it difficult to fix
- `bfd_install_relocation'. */
+ `bfd_install_relocation'. */
/* If while processing a fixup, a reloc really needs to be created
then it is done here. */
@@ -1058,8 +1070,8 @@ tc_gen_reloc (seg, fixp)
if (reloc->howto == (reloc_howto_type *) NULL)
{
as_bad_where (fixp->fx_file, fixp->fx_line,
- _("reloc %d not supported by object file format"),
- (int)fixp->fx_r_type);
+ _("reloc %d not supported by object file format"),
+ (int) fixp->fx_r_type);
return NULL;
}
@@ -1072,15 +1084,14 @@ tc_gen_reloc (seg, fixp)
return reloc;
}
-
void
md_assemble (str)
char *str;
{
- struct avr_opcodes_s * opcode;
+ struct avr_opcodes_s *opcode;
char op[11];
- str = skip_space (extract_word (str, op, sizeof(op)));
+ str = skip_space (extract_word (str, op, sizeof (op)));
if (!op[0])
as_bad (_("can't find opcode "));
@@ -1095,7 +1106,7 @@ md_assemble (str)
/* Special case for opcodes with optional operands (lpm, elpm) -
version with operands exists in avr_opcodes[] in the next entry. */
-
+
if (*str && *opcode->constraints == '?')
++opcode;
@@ -1114,10 +1125,11 @@ md_assemble (str)
}
/* Parse ordinary expression. */
+
static char *
parse_exp (s, op)
char *s;
- expressionS * op;
+ expressionS *op;
{
input_line_pointer = s;
expression (op);
@@ -1126,14 +1138,13 @@ parse_exp (s, op)
return input_line_pointer;
}
-
/* Parse special expressions (needed for LDI command):
xx8 (address)
xx8 (-address)
pm_xx8 (address)
pm_xx8 (-address)
- where xx is: hh, hi, lo
-*/
+ where xx is: hh, hi, lo. */
+
static bfd_reloc_code_real_type
avr_ldi_expression (exp)
expressionS *exp;
@@ -1145,28 +1156,35 @@ avr_ldi_expression (exp)
tmp = str;
str = extract_word (str, op, sizeof (op));
+
if (op[0])
{
mod = (int) hash_find (avr_mod_hash, op);
+
if (mod)
{
int closes = 0;
+
mod -= 10;
str = skip_space (str);
+
if (*str == '(')
{
int neg_p = 0;
+
++str;
+
if (strncmp ("pm(", str, 3) == 0
|| strncmp ("-(pm(", str, 5) == 0)
{
- if (HAVE_PM_P(mod))
+ if (HAVE_PM_P (mod))
{
++mod;
++closes;
}
else
as_bad (_("illegal expression"));
+
if (*str == '-')
{
neg_p = 1;
@@ -1176,14 +1194,17 @@ avr_ldi_expression (exp)
else
str += 3;
}
+
if (*str == '-' && *(str + 1) == '(')
{
neg_p ^= 1;
++closes;
str += 2;
}
+
input_line_pointer = str;
expression (exp);
+
do
{
if (*input_line_pointer != ')')
@@ -1194,14 +1215,16 @@ avr_ldi_expression (exp)
input_line_pointer++;
}
while (closes--);
+
return neg_p ? EXP_MOD_NEG_RELOC (mod) : EXP_MOD_RELOC (mod);
}
}
}
+
input_line_pointer = tmp;
expression (exp);
- /* Warn about expressions that fail to use lo8(). */
+ /* Warn about expressions that fail to use lo8 (). */
if (exp->X_op == O_constant)
{
int x = exp->X_add_number;
@@ -1215,18 +1238,19 @@ avr_ldi_expression (exp)
}
/* Flag to pass `pm' mode between `avr_parse_cons_expression' and
- `avr_cons_fix_new' */
+ `avr_cons_fix_new'. */
static int exp_mod_pm = 0;
/* Parse special CONS expression: pm (expression)
which is used for addressing to a program memory.
- Relocation: BFD_RELOC_AVR_16_PM */
+ Relocation: BFD_RELOC_AVR_16_PM. */
+
void
avr_parse_cons_expression (exp, nbytes)
expressionS *exp;
int nbytes;
{
- char * tmp;
+ char *tmp;
exp_mod_pm = 0;
@@ -1234,16 +1258,19 @@ avr_parse_cons_expression (exp, nbytes)
if (nbytes == 2)
{
- char * pm_name = "pm";
+ char *pm_name = "pm";
int len = strlen (pm_name);
+
if (strncasecmp (input_line_pointer, pm_name, len) == 0)
{
input_line_pointer = skip_space (input_line_pointer + len);
+
if (*input_line_pointer == '(')
{
input_line_pointer = skip_space (input_line_pointer + 1);
exp_mod_pm = 1;
expression (exp);
+
if (*input_line_pointer == ')')
++input_line_pointer;
else
@@ -1251,16 +1278,19 @@ avr_parse_cons_expression (exp, nbytes)
as_bad (_("`)' required"));
exp_mod_pm = 0;
}
+
return;
}
+
input_line_pointer = tmp;
}
}
+
expression (exp);
}
void
-avr_cons_fix_new(frag, where, nbytes, exp)
+avr_cons_fix_new (frag, where, nbytes, exp)
fragS *frag;
int where;
int nbytes;
diff --git a/gas/config/tc-ns32k.c b/gas/config/tc-ns32k.c
index 97f66e6..de4bbc5 100644
--- a/gas/config/tc-ns32k.c
+++ b/gas/config/tc-ns32k.c
@@ -1,5 +1,5 @@
/* ns32k.c -- Assemble on the National Semiconductor 32k series
- Copyright (C) 1987, 92, 93, 94, 95, 96, 97, 98, 1999
+ Copyright (C) 1987, 92, 93, 94, 95, 96, 97, 98, 1999, 2000
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
@@ -19,7 +19,7 @@
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
-/*#define SHOW_NUM 1*//* uncomment for debugging */
+/*#define SHOW_NUM 1*//* Uncomment for debugging. */
#include <stdio.h>
#include <ctype.h>
@@ -29,13 +29,13 @@
#include "obstack.h"
-/* Macros */
-#define IIF_ENTRIES 13 /* number of entries in iif */
-#define PRIVATE_SIZE 256 /* size of my garbage memory */
+/* Macros. */
+#define IIF_ENTRIES 13 /* Number of entries in iif. */
+#define PRIVATE_SIZE 256 /* Size of my garbage memory. */
#define MAX_ARGS 4
#define DEFAULT -1 /* addr_mode returns this value when
plain constant or label is
- encountered */
+ encountered. */
#define IIF(ptr,a1,c1,e1,g1,i1,k1,m1,o1,q1,s1,u1) \
iif.iifP[ptr].type= a1; \
@@ -63,6 +63,7 @@
const char comment_chars[] = "#";
const char line_comment_chars[] = LINE_COMMENT_CHARS;
const char line_separator_chars[] = ";";
+
#if !defined(ABSOLUTE_PREFIX) && !defined(IMMEDIATE_PREFIX)
#define ABSOLUTE_PREFIX '@' /* One or the other MUST be defined */
#endif
@@ -85,29 +86,29 @@ struct addr_mode
};
typedef struct addr_mode addr_modeS;
-
-char *freeptr, *freeptr_static; /* points at some number of free bytes */
+char *freeptr, *freeptr_static; /* Points at some number of free bytes. */
struct hash_control *inst_hash_handle;
-struct ns32k_opcode *desc; /* pointer at description of instruction */
+struct ns32k_opcode *desc; /* Pointer at description of instruction. */
addr_modeS addr_modeP;
const char EXP_CHARS[] = "eE";
-const char FLT_CHARS[] = "fd"; /* we don't want to support lowercase, do we */
+const char FLT_CHARS[] = "fd"; /* We don't want to support lowercase,
+ do we? */
/* UPPERCASE denotes live names when an instruction is built, IIF is
* used as an intermediate form to store the actual parts of the
* instruction. A ns32k machine instruction can be divided into a
* couple of sub PARTs. When an instruction is assembled the
* appropriate PART get an assignment. When an IIF has been completed
- * it is converted to a FRAGment as specified in AS.H */
+ * it is converted to a FRAGment as specified in AS.H. */
-/* internal structs */
+/* Internal structs. */
struct ns32k_option
- {
- char *pattern;
- unsigned long or;
- unsigned long and;
- };
+{
+ char *pattern;
+ unsigned long or;
+ unsigned long and;
+};
typedef struct
{
@@ -132,56 +133,57 @@ struct int_ins_form
int instr_size; /* Max size of instruction in bytes. */
iif_entryT iifP[IIF_ENTRIES + 1];
};
+
struct int_ins_form iif;
expressionS exprP;
char *input_line_pointer;
-/* description of the PARTs in IIF
- *object[n]:
- * 0 total length in bytes of entries in iif
- * 1 opcode
- * 2 index_byte_a
- * 3 index_byte_b
- * 4 disp_a_1
- * 5 disp_a_2
- * 6 disp_b_1
- * 7 disp_b_2
- * 8 imm_a
- * 9 imm_b
- * 10 implied1
- * 11 implied2
- *
- * For every entry there is a datalength in bytes. This is stored in size[n].
- * 0, the objectlength is not explicitly given by the instruction
- * and the operand is undefined. This is a case for relaxation.
- * Reserve 4 bytes for the final object.
- *
- * 1, the entry contains one byte
- * 2, the entry contains two bytes
- * 3, the entry contains three bytes
- * 4, the entry contains four bytes
- * etc
- *
- * Furthermore, every entry has a data type identifier in type[n].
- *
- * 0, the entry is void, ignore it.
- * 1, the entry is a binary number.
- * 2, the entry is a pointer at an expression.
- * Where expression may be as simple as a single '1',
- * and as complicated as foo-bar+12,
- * foo and bar may be undefined but suffixed by :{b|w|d} to
- * control the length of the object.
- *
- * 3, the entry is a pointer at a bignum struct
- *
- *
- * The low-order-byte coresponds to low physical memory.
- * Obviously a FRAGment must be created for each valid disp in PART whose
- * datalength is undefined (to bad) .
- * The case where just the expression is undefined is less severe and is
- * handled by fix. Here the number of bytes in the objectfile is known.
- * With this representation we simplify the assembly and separates the
- * machine dependent/independent parts in a more clean way (said OE)
- */
+
+/* Description of the PARTs in IIF
+ object[n]:
+ 0 total length in bytes of entries in iif
+ 1 opcode
+ 2 index_byte_a
+ 3 index_byte_b
+ 4 disp_a_1
+ 5 disp_a_2
+ 6 disp_b_1
+ 7 disp_b_2
+ 8 imm_a
+ 9 imm_b
+ 10 implied1
+ 11 implied2
+
+ For every entry there is a datalength in bytes. This is stored in size[n].
+ 0, the objectlength is not explicitly given by the instruction
+ and the operand is undefined. This is a case for relaxation.
+ Reserve 4 bytes for the final object.
+
+ 1, the entry contains one byte
+ 2, the entry contains two bytes
+ 3, the entry contains three bytes
+ 4, the entry contains four bytes
+ etc
+
+ Furthermore, every entry has a data type identifier in type[n].
+
+ 0, the entry is void, ignore it.
+ 1, the entry is a binary number.
+ 2, the entry is a pointer at an expression.
+ Where expression may be as simple as a single '1',
+ and as complicated as foo-bar+12,
+ foo and bar may be undefined but suffixed by :{b|w|d} to
+ control the length of the object.
+
+ 3, the entry is a pointer at a bignum struct
+
+
+ The low-order-byte coresponds to low physical memory.
+ Obviously a FRAGment must be created for each valid disp in PART whose
+ datalength is undefined (to bad) .
+ The case where just the expression is undefined is less severe and is
+ handled by fix. Here the number of bytes in the objectfile is known.
+ With this representation we simplify the assembly and separates the
+ machine dependent/independent parts in a more clean way (said OE). */
struct ns32k_option opt1[] = /* restore, exit */
{
@@ -311,20 +313,20 @@ struct ns32k_option *mmureg = mmureg_032;
const pseudo_typeS md_pseudo_table[] =
-{ /* so far empty */
+{ /* So far empty. */
{0, 0, 0}
};
#define IND(x,y) (((x)<<2)+(y))
-/* those are index's to relax groups in md_relax_table ie it must be
+/* Those are index's to relax groups in md_relax_table ie it must be
multiplied by 4 to point at a group start. Viz IND(x,y) Se function
- relax_segment in write.c for more info */
+ relax_segment in write.c for more info. */
#define BRANCH 1
#define PCREL 2
-/* those are index's to entries in a relax group */
+/* Those are index's to entries in a relax group. */
#define BYTE 0
#define WORD 1
@@ -337,8 +339,7 @@ const pseudo_typeS md_pseudo_table[] =
displacement base-adjust as there are other routines that must
consider this. Also, as we have two various offset-adjusts in the
ns32k (acb versus br/brs/jsr/bcond), two set of limits would have
- had to be used. Now we dont have to think about that. */
-
+ had to be used. Now we dont have to think about that. */
const relax_typeS md_relax_table[] =
{
@@ -354,7 +355,7 @@ const relax_typeS md_relax_table[] =
};
/* Array used to test if mode contains displacements.
- Value is true if mode contains displacement. */
+ Value is true if mode contains displacement. */
char disp_test[] =
{0, 0, 0, 0, 0, 0, 0, 0,
@@ -362,7 +363,7 @@ char disp_test[] =
1, 1, 1, 0, 0, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 1};
-/* Array used to calculate max size of displacements */
+/* Array used to calculate max size of displacements. */
char disp_size[] =
{4, 1, 2, 0, 4};
@@ -371,14 +372,14 @@ static void evaluate_expr PARAMS ((expressionS * resultP, char *ptr));
static void md_number_to_disp PARAMS ((char *buf, long val, int n));
static void md_number_to_imm PARAMS ((char *buf, long val, int n));
-/* Parses a general operand into an addressingmode struct
+/* Parse a general operand into an addressingmode struct
+
+ In: pointer at operand in ascii form
+ pointer at addr_mode struct for result
+ the level of recursion. (always 0 or 1)
- in: pointer at operand in ascii form
- pointer at addr_mode struct for result
- the level of recursion. (always 0 or 1)
+ Out: data in addr_mode struct. */
- out: data in addr_mode struct
- */
int
addr_mode (operand, addr_modeP, recursive_level)
char *operand;
@@ -390,6 +391,7 @@ addr_mode (operand, addr_modeP, recursive_level)
register int strl;
register int mode;
int j;
+
mode = DEFAULT; /* default */
addr_modeP->scaled_mode = 0; /* why not */
addr_modeP->scaled_reg = 0; /* if 0, not scaled index */
@@ -402,22 +404,23 @@ addr_mode (operand, addr_modeP, recursive_level)
addr_modeP->disp[0] = NULL;
addr_modeP->disp[1] = NULL;
str = operand;
+
if (str[0] == 0)
- {
- return (0);
- } /* we don't want this */
+ return 0;
+
strl = strlen (str);
+
switch (str[0])
{
- /* the following three case statements controls the mode-chars
- this is the place to ed if you want to change them */
+ /* The following three case statements controls the mode-chars
+ this is the place to ed if you want to change them. */
#ifdef ABSOLUTE_PREFIX
case ABSOLUTE_PREFIX:
if (str[strl - 1] == ']')
break;
addr_modeP->mode = 21; /* absolute */
addr_modeP->disp[0] = str + 1;
- return (-1);
+ return -1;
#endif
#ifdef IMMEDIATE_PREFIX
case IMMEDIATE_PREFIX:
@@ -425,7 +428,7 @@ addr_mode (operand, addr_modeP, recursive_level)
break;
addr_modeP->mode = 20; /* immediate */
addr_modeP->disp[0] = str + 1;
- return (-1);
+ return -1;
#endif
case '.':
if (str[strl - 1] != ']')
@@ -438,11 +441,11 @@ addr_mode (operand, addr_modeP, recursive_level)
{
addr_modeP->mode = 27; /* pc-relativ */
addr_modeP->disp[0] = str + 2;
- return (-1);
+ return -1;
}
default:
as_warn (_("Invalid syntax in PC-relative addressing mode"));
- return (0);
+ return 0;
}
}
break;
@@ -471,13 +474,17 @@ addr_mode (operand, addr_modeP, recursive_level)
str[j] = '\000'; /* null terminate disp[0] */
addr_modeP->disp[1] = str + j + 2;
addr_modeP->mode = 22;
- return (-1);
+ return -1;
}
}
break;
- default:;
+
+ default:
+ ;
}
+
strl = strlen (str);
+
switch (strl)
{
case 2:
@@ -485,21 +492,31 @@ addr_mode (operand, addr_modeP, recursive_level)
{
case 'f':
addr_modeP->float_flag = 1;
+ /* Drop through. */
case 'r':
if (str[1] >= '0' && str[1] < '8')
{
addr_modeP->mode = str[1] - '0';
- return (-1);
+ return -1;
}
+ break;
+ default:
+ break;
}
+ /* Drop through. */
+
case 3:
if (!strncmp (str, "tos", 3))
{
addr_modeP->mode = 23; /* TopOfStack */
- return (-1);
+ return -1;
}
- default:;
+ break;
+
+ default:
+ break;
}
+
if (strl > 4)
{
if (str[strl - 1] == ')')
@@ -507,22 +524,18 @@ addr_mode (operand, addr_modeP, recursive_level)
if (str[strl - 2] == ')')
{
if (!strncmp (&str[strl - 5], "(fp", 3))
- {
- mode = 16; /* Memory Relative */
- }
- if (!strncmp (&str[strl - 5], "(sp", 3))
- {
- mode = 17;
- }
- if (!strncmp (&str[strl - 5], "(sb", 3))
- {
- mode = 18;
- }
+ mode = 16; /* Memory Relative. */
+ else if (!strncmp (&str[strl - 5], "(sp", 3))
+ mode = 17;
+ else if (!strncmp (&str[strl - 5], "(sb", 3))
+ mode = 18;
+
if (mode != DEFAULT)
- { /* memory relative */
+ { /* Memory relative. */
addr_modeP->mode = mode;
- j = strl - 5; /* temp for end of disp[0] */
+ j = strl - 5; /* Temp for end of disp[0]. */
i = 0;
+
do
{
strl -= 1;
@@ -532,18 +545,22 @@ addr_mode (operand, addr_modeP, recursive_level)
i--;
}
while (strl > -1 && i != 0);
+
if (i != 0)
{
as_warn (_("Invalid syntax in Memory Relative addressing mode"));
return (0);
}
+
addr_modeP->disp[1] = str;
addr_modeP->disp[0] = str + strl + 1;
- str[j] = '\000'; /* null terminate disp[0] */
- str[strl] = '\000'; /* null terminate disp[1] */
- return (-1);
+ str[j] = '\000'; /* Null terminate disp[0] . */
+ str[strl] = '\000'; /* Null terminate disp[1]. */
+
+ return -1;
}
}
+
switch (str[strl - 3])
{
case 'r':
@@ -555,35 +572,32 @@ addr_mode (operand, addr_modeP, recursive_level)
addr_modeP->mode = str[strl - 2] - '0' + 8;
addr_modeP->disp[0] = str;
str[strl - 4] = 0;
- return (-1); /* reg rel */
+ return -1; /* reg rel */
}
+ /* Drop through. */
+
default:
if (!strncmp (&str[strl - 4], "(fp", 3))
- {
- mode = 24;
- }
- if (!strncmp (&str[strl - 4], "(sp", 3))
- {
- mode = 25;
- }
- if (!strncmp (&str[strl - 4], "(sb", 3))
- {
- mode = 26;
- }
- if (!strncmp (&str[strl - 4], "(pc", 3))
- {
- mode = 27;
- }
+ mode = 24;
+ else if (!strncmp (&str[strl - 4], "(sp", 3))
+ mode = 25;
+ else if (!strncmp (&str[strl - 4], "(sb", 3))
+ mode = 26;
+ else if (!strncmp (&str[strl - 4], "(pc", 3))
+ mode = 27;
+
if (mode != DEFAULT)
{
addr_modeP->mode = mode;
addr_modeP->disp[0] = str;
str[strl - 4] = '\0';
- return (-1); /* memory space */
+
+ return -1; /* Memory space. */
}
}
}
- /* no trailing ')' do we have a ']' ? */
+
+ /* No trailing ')' do we have a ']' ? */
if (str[strl - 1] == ']')
{
switch (str[strl - 2])
@@ -600,41 +614,44 @@ addr_mode (operand, addr_modeP, recursive_level)
case 'q':
mode = 31;
break;
- default:;
+ default:
as_warn (_("Invalid scaled-indexed mode, use (b,w,d,q)"));
+
if (str[strl - 3] != ':' || str[strl - 6] != '['
|| str[strl - 5] == 'r' || str[strl - 4] < '0'
|| str[strl - 4] > '7')
- {
- as_warn (_("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"));
- }
- } /* scaled index */
- {
- if (recursive_level > 0)
- {
- as_warn (_("Scaled-indexed addressing mode combined with scaled-index"));
- return (0);
- }
- addr_modeP->am_size += 1; /* scaled index byte */
- j = str[strl - 4] - '0'; /* store temporary */
- str[strl - 6] = '\000'; /* nullterminate for recursive call */
- i = addr_mode (str, addr_modeP, 1);
- if (!i || addr_modeP->mode == 20)
- {
- as_warn (_("Invalid or illegal addressing mode combined with scaled-index"));
- return (0);
- }
- addr_modeP->scaled_mode = addr_modeP->mode; /* store the inferior
- mode */
- addr_modeP->mode = mode;
- addr_modeP->scaled_reg = j + 1;
- return (-1);
- }
+ as_warn (_("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"));
+ } /* Scaled index. */
+
+ if (recursive_level > 0)
+ {
+ as_warn (_("Scaled-indexed addressing mode combined with scaled-index"));
+ return 0;
+ }
+
+ addr_modeP->am_size += 1; /* scaled index byte */
+ j = str[strl - 4] - '0'; /* store temporary */
+ str[strl - 6] = '\000'; /* nullterminate for recursive call */
+ i = addr_mode (str, addr_modeP, 1);
+
+ if (!i || addr_modeP->mode == 20)
+ {
+ as_warn (_("Invalid or illegal addressing mode combined with scaled-index"));
+ return 0;
+ }
+
+ addr_modeP->scaled_mode = addr_modeP->mode; /* Store the inferior mode. */
+ addr_modeP->mode = mode;
+ addr_modeP->scaled_reg = j + 1;
+
+ return -1;
}
}
- addr_modeP->mode = DEFAULT; /* default to whatever */
+
+ addr_modeP->mode = DEFAULT; /* Default to whatever. */
addr_modeP->disp[0] = str;
- return (-1);
+
+ return -1;
}
/* ptr points at string addr_modeP points at struct with result This
@@ -642,160 +659,171 @@ addr_mode (operand, addr_modeP, recursive_level)
operand. When this is ready it parses the displacements for size
specifying suffixes and determines size of immediate mode via
ns32k-opcode. Also builds index bytes if needed. */
+
int
get_addr_mode (ptr, addr_modeP)
char *ptr;
addr_modeS *addr_modeP;
{
int tmp;
+
addr_mode (ptr, addr_modeP, 0);
+
if (addr_modeP->mode == DEFAULT || addr_modeP->scaled_mode == -1)
{
- /* resolve ambigious operands, this shouldn't be necessary if
+ /* Resolve ambigious operands, this shouldn't be necessary if
one uses standard NSC operand syntax. But the sequent
compiler doesn't!!! This finds a proper addressinging mode
- if it is implicitly stated. See ns32k-opcode.h */
- (void) evaluate_expr (&exprP, ptr); /* this call takes time Sigh! */
+ if it is implicitly stated. See ns32k-opcode.h. */
+ (void) evaluate_expr (&exprP, ptr); /* This call takes time Sigh! */
+
if (addr_modeP->mode == DEFAULT)
{
if (exprP.X_add_symbol || exprP.X_op_symbol)
- {
- addr_modeP->mode = desc->default_model; /* we have a label */
- }
+ addr_modeP->mode = desc->default_model; /* We have a label. */
else
- {
- addr_modeP->mode = desc->default_modec; /* we have a constant */
- }
+ addr_modeP->mode = desc->default_modec; /* We have a constant. */
}
else
{
if (exprP.X_add_symbol || exprP.X_op_symbol)
- {
- addr_modeP->scaled_mode = desc->default_model;
- }
+ addr_modeP->scaled_mode = desc->default_model;
else
- {
- addr_modeP->scaled_mode = desc->default_modec;
- }
+ addr_modeP->scaled_mode = desc->default_modec;
}
- /* must put this mess down in addr_mode to handle the scaled
- case better */
+
+ /* Must put this mess down in addr_mode to handle the scaled
+ case better. */
}
+
/* It appears as the sequent compiler wants an absolute when we have
a label without @. Constants becomes immediates besides the addr
case. Think it does so with local labels too, not optimum, pcrel
is better. When I have time I will make gas check this and
select pcrel when possible Actually that is trivial. */
if (tmp = addr_modeP->scaled_reg)
- { /* build indexbyte */
- tmp--; /* remember regnumber comes incremented for
- flagpurpose */
+ { /* Build indexbyte. */
+ tmp--; /* Remember regnumber comes incremented for
+ flagpurpose. */
tmp |= addr_modeP->scaled_mode << 3;
addr_modeP->index_byte = (char) tmp;
addr_modeP->am_size += 1;
}
+
if (disp_test[addr_modeP->mode])
- { /* there was a displacement, probe for length
- specifying suffix */
- {
- register char c;
- register char suffix;
- register char suffix_sub;
- register int i;
- register char *toP;
- register char *fromP;
-
- addr_modeP->pcrel = 0;
- if (disp_test[addr_modeP->mode])
- { /* there is a displacement */
- if (addr_modeP->mode == 27 || addr_modeP->scaled_mode == 27)
- { /* do we have pcrel. mode */
- addr_modeP->pcrel = 1;
- }
- addr_modeP->im_disp = 1;
- for (i = 0; i < 2; i++)
- {
- suffix_sub = suffix = 0;
- if (toP = addr_modeP->disp[i])
- { /* suffix of expression, the largest size
- rules */
- fromP = toP;
- while (c = *fromP++)
- {
- *toP++ = c;
- if (c == ':')
- {
- switch (*fromP)
- {
- case '\0':
- as_warn (_("Premature end of suffix -- Defaulting to d"));
- suffix = 4;
- continue;
- case 'b':
- suffix_sub = 1;
- break;
- case 'w':
- suffix_sub = 2;
- break;
- case 'd':
- suffix_sub = 4;
- break;
- default:
- as_warn (_("Bad suffix after ':' use {b|w|d} Defaulting to d"));
- suffix = 4;
- }
- fromP++;
- toP--; /* So we write over the ':' */
- if (suffix < suffix_sub)
- suffix = suffix_sub;
- }
- }
- *toP = '\0';/* terminate properly */
- addr_modeP->disp_suffix[i] = suffix;
- addr_modeP->am_size += suffix ? suffix : 4;
- }
- }
- }
- }
+ {
+ register char c;
+ register char suffix;
+ register char suffix_sub;
+ register int i;
+ register char *toP;
+ register char *fromP;
+
+ /* There was a displacement, probe for length specifying suffix. */
+ addr_modeP->pcrel = 0;
+
+ if (disp_test[addr_modeP->mode])
+ {
+ /* There is a displacement. */
+ if (addr_modeP->mode == 27 || addr_modeP->scaled_mode == 27)
+ /* Do we have pcrel. mode. */
+ addr_modeP->pcrel = 1;
+
+ addr_modeP->im_disp = 1;
+
+ for (i = 0; i < 2; i++)
+ {
+ suffix_sub = suffix = 0;
+
+ if (toP = addr_modeP->disp[i])
+ {
+ /* Suffix of expression, the largest size rules. */
+ fromP = toP;
+
+ while (c = *fromP++)
+ {
+ *toP++ = c;
+ if (c == ':')
+ {
+ switch (*fromP)
+ {
+ case '\0':
+ as_warn (_("Premature end of suffix -- Defaulting to d"));
+ suffix = 4;
+ continue;
+ case 'b':
+ suffix_sub = 1;
+ break;
+ case 'w':
+ suffix_sub = 2;
+ break;
+ case 'd':
+ suffix_sub = 4;
+ break;
+ default:
+ as_warn (_("Bad suffix after ':' use {b|w|d} Defaulting to d"));
+ suffix = 4;
+ }
+
+ fromP ++;
+ toP --; /* So we write over the ':' */
+
+ if (suffix < suffix_sub)
+ suffix = suffix_sub;
+ }
+ }
+
+ *toP = '\0'; /* Terminate properly. */
+ addr_modeP->disp_suffix[i] = suffix;
+ addr_modeP->am_size += suffix ? suffix : 4;
+ }
+ }
+ }
}
else
{
if (addr_modeP->mode == 20)
- { /* look in ns32k_opcode for size */
+ {
+ /* Look in ns32k_opcode for size. */
addr_modeP->disp_suffix[0] = addr_modeP->am_size = desc->im_size;
addr_modeP->im_disp = 0;
}
}
+
return addr_modeP->mode;
}
+/* Read an optionlist. */
-/* read an optionlist */
void
optlist (str, optionP, default_map)
- char *str; /* the string to extract options from */
- struct ns32k_option *optionP; /* how to search the string */
- unsigned long *default_map; /* default pattern and output */
+ char *str; /* The string to extract options from. */
+ struct ns32k_option *optionP; /* How to search the string. */
+ unsigned long *default_map; /* Default pattern and output. */
{
register int i, j, k, strlen1, strlen2;
register char *patternP, *strP;
+
strlen1 = strlen (str);
+
if (strlen1 < 1)
- {
- as_fatal (_("Very short instr to option, ie you can't do it on a NULLstr"));
- }
+ as_fatal (_("Very short instr to option, ie you can't do it on a NULLstr"));
+
for (i = 0; optionP[i].pattern != 0; i++)
{
strlen2 = strlen (optionP[i].pattern);
+
for (j = 0; j < strlen1; j++)
{
patternP = optionP[i].pattern;
strP = &str[j];
+
for (k = 0; k < strlen2; k++)
{
if (*(strP++) != *(patternP++))
break;
}
+
if (k == strlen2)
{ /* match */
*default_map |= optionP[i].or;
@@ -805,27 +833,31 @@ optlist (str, optionP, default_map)
}
}
-/* search struct for symbols
+/* Search struct for symbols.
This function is used to get the short integer form of reg names in
the instructions lmr, smr, lpr, spr return true if str is found in
- list */
+ list. */
int
list_search (str, optionP, default_map)
- char *str; /* the string to match */
- struct ns32k_option *optionP; /* list to search */
- unsigned long *default_map; /* default pattern and output */
+ char *str; /* The string to match. */
+ struct ns32k_option *optionP; /* List to search. */
+ unsigned long *default_map; /* Default pattern and output. */
{
register int i;
+
for (i = 0; optionP[i].pattern != 0; i++)
{
if (!strncmp (optionP[i].pattern, str, 20))
- { /* use strncmp to be safe */
+ {
+ /* Use strncmp to be safe. */
*default_map |= optionP[i].or;
*default_map &= optionP[i].and;
+
return -1;
}
}
+
as_warn (_("No such entry in list. (cpu/mmu register)"));
return 0;
}
@@ -847,8 +879,7 @@ evaluate_expr (resultP, ptr)
Operands are parsed in such an order that the opcode is updated from
its most significant bit, that is when the operand need to alter the
opcode.
- Be carefull not to put to objects in the same iif-slot.
- */
+ Be carefull not to put to objects in the same iif-slot. */
void
encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
@@ -862,15 +893,18 @@ encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
register int i, j;
char d;
int pcrel, tmp, b, loop, pcrel_adjust;
+
for (loop = 0; loop < argc; loop++)
{
- i = operandsP[loop << 1] - '1'; /* what operand are we supposed
- to work on */
+ /* What operand are we supposed to work on. */
+ i = operandsP[loop << 1] - '1';
if (i > 3)
as_fatal (_("Internal consistency error. check ns32k-opcode.h"));
+
pcrel = 0;
pcrel_adjust = 0;
tmp = 0;
+
switch ((d = operandsP[(loop << 1) + 1]))
{
case 'f': /* operand of sfsr turns out to be a nasty
@@ -886,16 +920,17 @@ encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
case 'A': /* double-word gen-address-form ie no regs
allowed */
get_addr_mode (argv[i], &addr_modeP);
- if((addr_modeP.mode == 20) &&
- (d == 'I' || d == 'Z' || d == 'A')) {
- as_fatal(d == 'A'? _("Address of immediate operand"):
- _("Invalid immediate write operand."));
- }
+
+ if ((addr_modeP.mode == 20) &&
+ (d == 'I' || d == 'Z' || d == 'A'))
+ as_fatal (d == 'A'? _("Address of immediate operand"):
+ _("Invalid immediate write operand."));
if (opcode_bit_ptr == desc->opcode_size)
b = 4;
else
b = 6;
+
for (j = b; j < (b + 2); j++)
{
if (addr_modeP.disp[j - b])
@@ -915,8 +950,10 @@ encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
0);
}
}
+
opcode_bit_ptr -= 5;
iif.iifP[1].object |= ((long) addr_modeP.mode) << opcode_bit_ptr;
+
if (addr_modeP.scaled_reg)
{
j = b / 2;
@@ -924,6 +961,7 @@ encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
0, 0, 0, 0, 0, NULL, -1, 0);
}
break;
+
case 'b': /* multiple instruction disp */
freeptr++; /* OVE:this is an useful hack */
sprintf (freeptr, "((%s-1)*%d)\000", argv[i], desc->im_size);
@@ -1025,9 +1063,9 @@ encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
out: internal structure of instruction
that has been prepared for direct conversion to fragment(s) and
fixes in a systematical fashion
- Return-value = recursive_level
- */
-/* build iif of one assembly text line */
+ Return-value = recursive_level. */
+/* Build iif of one assembly text line. */
+
int
parse (line, recursive_level)
char *line;
@@ -1037,53 +1075,64 @@ parse (line, recursive_level)
register int i;
int argc, arg_type;
char sqr, sep;
- char suffix[MAX_ARGS], *argv[MAX_ARGS]; /* no more than 4 operands */
+ char suffix[MAX_ARGS], *argv[MAX_ARGS]; /* No more than 4 operands. */
+
if (recursive_level <= 0)
- { /* called from md_assemble */
- for (lineptr = line; (*lineptr) != '\0' && (*lineptr) != ' '; lineptr++);
+ {
+ /* Called from md_assemble. */
+ for (lineptr = line; (*lineptr) != '\0' && (*lineptr) != ' '; lineptr++)
+ continue;
+
c = *lineptr;
*lineptr = '\0';
+
if (!(desc = (struct ns32k_opcode *) hash_find (inst_hash_handle, line)))
- {
- as_fatal (_("No such opcode"));
- }
+ as_fatal (_("No such opcode"));
+
*lineptr = c;
}
else
{
lineptr = line;
}
+
argc = 0;
+
if (*desc->operands)
{
if (*lineptr++ != '\0')
{
sqr = '[';
sep = ',';
+
while (*lineptr != '\0')
{
if (desc->operands[argc << 1])
{
suffix[argc] = 0;
arg_type = desc->operands[(argc << 1) + 1];
+
switch (arg_type)
{
case 'd':
case 'b':
case 'p':
- case 'H': /* the operand is supposed to be a
- displacement */
+ case 'H':
+ /* The operand is supposed to be a displacement. */
/* Hackwarning: do not forget to update the 4
- cases above when editing ns32k-opcode.h */
+ cases above when editing ns32k-opcode.h. */
suffix_separator = ':';
break;
default:
- suffix_separator = '\255'; /* if this char occurs we
- loose */
+ /* If this char occurs we loose. */
+ suffix_separator = '\255';
+ break;
}
+
suffix[argc] = 0; /* 0 when no ':' is encountered */
argv[argc] = freeptr;
*freeptr = '\0';
+
while ((c = *lineptr) != '\0' && c != sep)
{
if (c == sqr)
@@ -1099,8 +1148,10 @@ parse (line, recursive_level)
sep = ',';
}
}
+
if (c == suffix_separator)
- { /* ':' - label/suffix separator */
+ {
+ /* ':' - label/suffix separator. */
switch (lineptr[1])
{
case 'b':
@@ -1120,17 +1171,23 @@ parse (line, recursive_level)
lineptr += 1;
continue;
}
+ break;
}
+
lineptr += 2;
continue;
}
+
*freeptr++ = c;
lineptr++;
}
+
*freeptr++ = '\0';
argc += 1;
+
if (*lineptr == '\0')
continue;
+
lineptr += 1;
}
else
@@ -1140,31 +1197,31 @@ parse (line, recursive_level)
}
}
}
+
if (argc != strlen (desc->operands) / 2)
{
if (strlen (desc->default_args))
- { /* we can apply default, dont goof */
+ {
+ /* We can apply default, don't goof. */
if (parse (desc->default_args, 1) != 1)
- { /* check error in default */
- as_fatal (_("Wrong numbers of operands in default, check ns32k-opcodes.h"));
- }
+ /* Check error in default. */
+ as_fatal (_("Wrong numbers of operands in default, check ns32k-opcodes.h"));
}
else
{
as_fatal (_("Wrong number of operands"));
}
-
}
+
for (i = 0; i < IIF_ENTRIES; i++)
- {
- iif.iifP[i].type = 0; /* mark all entries as void*/
- }
+ /* Mark all entries as void. */
+ iif.iifP[i].type = 0;
- /* build opcode iif-entry */
+ /* Build opcode iif-entry. */
iif.instr_size = desc->opcode_size / 8;
IIF (1, 1, iif.instr_size, desc->opcode_seed, 0, 0, 0, 0, 0, 0, -1, 0);
- /* this call encodes operands to iif format */
+ /* This call encodes operands to iif format. */
if (argc)
{
encode_operand (argc,
@@ -1177,31 +1234,29 @@ parse (line, recursive_level)
return recursive_level;
}
-
/* Convert iif to fragments. From this point we start to dribble with
- * functions in other files than this one.(Except hash.c) So, if it's
- * possible to make an iif for an other CPU, you don't need to know
- * what frags, relax, obstacks, etc is in order to port this
- * assembler. You only need to know if it's possible to reduce your
- * cpu-instruction to iif-format (takes some work) and adopt the other
- * md_? parts according to given instructions Note that iif was
- * invented for the clean ns32k`s architecure.
- */
+ functions in other files than this one.(Except hash.c) So, if it's
+ possible to make an iif for an other CPU, you don't need to know
+ what frags, relax, obstacks, etc is in order to port this
+ assembler. You only need to know if it's possible to reduce your
+ cpu-instruction to iif-format (takes some work) and adopt the other
+ md_? parts according to given instructions Note that iif was
+ invented for the clean ns32k`s architecure. */
/* GAS for the ns32k has a problem. PC relative displacements are
- * relative to the address of the opcode, not the address of the
- * operand. We used to keep track of the offset between the operand
- * and the opcode in pcrel_adjust for each frag and each fix. However,
- * we get into trouble where there are two or more pc-relative
- * operands and the size of the first one can't be determined. Then in
- * the relax phase, the size of the first operand will change and
- * pcrel_adjust will no longer be correct. The current solution is
- * keep a pointer to the frag with the opcode in it and the offset in
- * that frag for each frag and each fix. Then, when needed, we can
- * always figure out how far it is between the opcode and the pcrel
- * object. See also md_pcrel_adjust and md_fix_pcrel_adjust. For
- * objects not part of an instruction, the pointer to the opcode frag
- * is always zero. */
+ relative to the address of the opcode, not the address of the
+ operand. We used to keep track of the offset between the operand
+ and the opcode in pcrel_adjust for each frag and each fix. However,
+ we get into trouble where there are two or more pc-relative
+ operands and the size of the first one can't be determined. Then in
+ the relax phase, the size of the first operand will change and
+ pcrel_adjust will no longer be correct. The current solution is
+ keep a pointer to the frag with the opcode in it and the offset in
+ that frag for each frag and each fix. Then, when needed, we can
+ always figure out how far it is between the opcode and the pcrel
+ object. See also md_pcrel_adjust and md_fix_pcrel_adjust. For
+ objects not part of an instruction, the pointer to the opcode frag
+ is always zero. */
void
convert_iif ()
@@ -1226,26 +1281,30 @@ convert_iif ()
for (i = 0; i < IIF_ENTRIES; i++)
{
if (type = iif.iifP[i].type)
- { /* the object exist, so handle it */
+ {
+ /* The object exist, so handle it. */
switch (size = iif.iifP[i].size)
{
case 42:
- size = 0; /* it's a bitfix that operates on an existing
- object*/
+ size = 0;
+ /* It's a bitfix that operates on an existing object. */
if (iif.iifP[i].bit_fixP->fx_bit_base)
- { /* expand fx_bit_base to point at opcode */
- iif.iifP[i].bit_fixP->fx_bit_base = (long) inst_opcode;
- }
+ /* Expand fx_bit_base to point at opcode. */
+ iif.iifP[i].bit_fixP->fx_bit_base = (long) inst_opcode;
+ /* Fall through. */
+
case 8: /* bignum or doublefloat */
case 1:
case 2:
case 3:
- case 4: /* the final size in objectmemory is known */
+ case 4:
+ /* The final size in objectmemory is known. */
memP = frag_more(size);
j = iif.iifP[i].bit_fixP;
+
switch (type)
{
- case 1: /* the object is pure binary */
+ case 1: /* The object is pure binary. */
if (j || iif.iifP[i].pcrel)
{
fix_new_ns32k (frag_now,
@@ -1260,7 +1319,8 @@ convert_iif ()
inst_frag, inst_offset);
}
else
- { /* good, just put them bytes out */
+ {
+ /* Good, just put them bytes out. */
switch (iif.iifP[i].im_disp)
{
case 0:
@@ -1274,21 +1334,24 @@ convert_iif ()
}
}
break;
+
case 2:
- /* the object is a pointer at an expression, so
+ /* The object is a pointer at an expression, so
unpack it, note that bignums may result from the
- expression */
+ expression. */
evaluate_expr (&exprP, (char *) iif.iifP[i].object);
if (exprP.X_op == O_big || size == 8)
{
if ((k = exprP.X_add_number) > 0)
{
- /* we have a bignum ie a quad. This can only
- happens in a long suffixed instruction */
+ /* We have a bignum ie a quad. This can only
+ happens in a long suffixed instruction. */
if (k * 2 > size)
as_warn (_("Bignum too big for long"));
+
if (k == 3)
memP += 2;
+
for (l = 0; k > 0; k--, l += 2)
{
md_number_to_chars (memP + l,
@@ -1297,7 +1360,8 @@ convert_iif ()
}
}
else
- { /* flonum */
+ {
+ /* flonum. */
LITTLENUM_TYPE words[4];
switch (size)
@@ -1337,7 +1401,7 @@ convert_iif ()
{
/* The expression was undefined due to an
undefined label. Create a fix so we can fix
- the object later. */
+ the object later. */
exprP.X_add_number += iif.iifP[i].object_adjust;
fix_new_ns32k_exp (frag_now,
(long) (memP - frag_now->fr_literal),
@@ -1351,7 +1415,7 @@ convert_iif ()
}
else
{
- /* good, just put them bytes out */
+ /* Good, just put them bytes out. */
switch (iif.iifP[i].im_disp)
{
case 0:
@@ -1369,19 +1433,21 @@ convert_iif ()
as_fatal (_("Internal logic error in iif.iifP[n].type"));
}
break;
+
case 0:
- /* To bad, the object may be undefined as far as its
+ /* Too bad, the object may be undefined as far as its
final nsize in object memory is concerned. The size
of the object in objectmemory is not explicitly
given. If the object is defined its length can be
- determined and a fix can replace the frag. */
+ determined and a fix can replace the frag. */
{
evaluate_expr (&exprP, (char *) iif.iifP[i].object);
+
if ((exprP.X_add_symbol || exprP.X_op_symbol) &&
!iif.iifP[i].pcrel)
{
/* Size is unknown until link time so have to
- allow 4 bytes. */
+ allow 4 bytes. */
size = 4;
memP = frag_more(size);
fix_new_ns32k_exp (frag_now,
@@ -1397,38 +1463,39 @@ convert_iif ()
}
if (exprP.X_add_symbol || exprP.X_op_symbol)
- { /* frag it */
+ {
+ /* Frag it. */
if (exprP.X_op_symbol)
- { /* We cant relax this case */
+ {
+ /* We cant relax this case. */
as_fatal (_("Can't relax difference"));
}
else
{
-
- /* Size is not important. This gets fixed by relax,
- * but we assume 0 in what follows
- */
- memP = frag_more(4); /* Max size */
+ /* Size is not important. This gets fixed by
+ relax, but we assume 0 in what follows. */
+ memP = frag_more(4); /* Max size. */
size = 0;
{
fragS *old_frag = frag_now;
frag_variant (rs_machine_dependent,
- 4, /* Max size */
- 0, /* size */
- IND (BRANCH, UNDEF), /* expecting the worst */
+ 4, /* Max size. */
+ 0, /* Size. */
+ IND (BRANCH, UNDEF), /* Expecting
+ the worst. */
exprP.X_add_symbol,
exprP.X_add_number,
inst_opcode);
- frag_opcode_frag(old_frag) = inst_frag;
- frag_opcode_offset(old_frag) = inst_offset;
- frag_bsr(old_frag) = iif.iifP[i].bsr;
+ frag_opcode_frag (old_frag) = inst_frag;
+ frag_opcode_offset (old_frag) = inst_offset;
+ frag_bsr (old_frag) = iif.iifP[i].bsr;
}
}
}
else
{
- /* This duplicates code in md_number_to_disp */
+ /* This duplicates code in md_number_to_disp. */
if (-64 <= exprP.X_add_number && exprP.X_add_number <= 63)
{
size = 1;
@@ -1442,8 +1509,8 @@ convert_iif ()
}
else
{
- if (-0x20000000<=exprP.X_add_number &&
- exprP.X_add_number<=0x1fffffff)
+ if (-0x20000000 <= exprP.X_add_number
+ && exprP.X_add_number<=0x1fffffff)
{
size = 4;
}
@@ -1454,11 +1521,13 @@ convert_iif ()
}
}
}
- memP = frag_more(size);
+
+ memP = frag_more (size);
md_number_to_disp (memP, exprP.X_add_number, size);
}
}
break;
+
default:
as_fatal (_("Internal logic error in iif.iifP[].type"));
}
@@ -1467,12 +1536,13 @@ convert_iif ()
}
#ifdef BFD_ASSEMBLER
-/* This functionality should really be in the bfd library */
+/* This functionality should really be in the bfd library. */
static bfd_reloc_code_real_type
reloc (int size, int pcrel, int type)
{
int length, index;
- bfd_reloc_code_real_type relocs[] = {
+ bfd_reloc_code_real_type relocs[] =
+ {
BFD_RELOC_NS32K_IMM_8,
BFD_RELOC_NS32K_IMM_16,
BFD_RELOC_NS32K_IMM_32,
@@ -1480,7 +1550,7 @@ reloc (int size, int pcrel, int type)
BFD_RELOC_NS32K_IMM_16_PCREL,
BFD_RELOC_NS32K_IMM_32_PCREL,
- /* ns32k displacements */
+ /* ns32k displacements. */
BFD_RELOC_NS32K_DISP_8,
BFD_RELOC_NS32K_DISP_16,
BFD_RELOC_NS32K_DISP_32,
@@ -1488,14 +1558,15 @@ reloc (int size, int pcrel, int type)
BFD_RELOC_NS32K_DISP_16_PCREL,
BFD_RELOC_NS32K_DISP_32_PCREL,
- /* Normal 2's complement */
+ /* Normal 2's complement. */
BFD_RELOC_8,
BFD_RELOC_16,
BFD_RELOC_32,
BFD_RELOC_8_PCREL,
BFD_RELOC_16_PCREL,
BFD_RELOC_32_PCREL
- };
+ };
+
switch (size)
{
case 1:
@@ -1511,19 +1582,22 @@ reloc (int size, int pcrel, int type)
length = -1;
break;
}
+
index = length + 3 * pcrel + 6 * type;
- if (index >= 0 && index < sizeof(relocs)/sizeof(relocs[0]))
+
+ if (index >= 0 && index < sizeof (relocs) / sizeof (relocs[0]))
return relocs[index];
+
if (pcrel)
as_bad (_("Can not do %d byte pc-relative relocation for storage type %d"),
size, type);
else
as_bad (_("Can not do %d byte relocation for storage type %d"),
size, type);
+
return BFD_RELOC_NONE;
}
-
#endif
void
@@ -1531,33 +1605,33 @@ md_assemble (line)
char *line;
{
freeptr = freeptr_static;
- parse (line, 0); /* explode line to more fix form in iif */
- convert_iif (); /* convert iif to frags, fix's etc */
+ parse (line, 0); /* Explode line to more fix form in iif. */
+ convert_iif (); /* Convert iif to frags, fix's etc. */
#ifdef SHOW_NUM
printf (" \t\t\t%s\n", line);
#endif
}
-
void
md_begin ()
{
- /* build a hashtable of the instructions */
+ /* Build a hashtable of the instructions. */
const struct ns32k_opcode *ptr;
const char *stat;
inst_hash_handle = hash_new ();
+
for (ptr = ns32k_opcodes; ptr < endop; ptr++)
{
if ((stat = hash_insert (inst_hash_handle, ptr->name, (char *) ptr)))
- {
- as_fatal (_("Can't hash %s: %s"), ptr->name, stat); /*fatal*/
- }
+ /* Fatal. */
+ as_fatal (_("Can't hash %s: %s"), ptr->name, stat);
}
- freeptr_static = (char *) malloc (PRIVATE_SIZE); /* some private space
- please! */
+
+ /* Some private space please! */
+ freeptr_static = (char *) malloc (PRIVATE_SIZE);
}
-/* Must be equal to MAX_PRECISON in atof-ieee.c */
+/* Must be equal to MAX_PRECISON in atof-ieee.c. */
#define MAX_LITTLENUMS 6
/* Turn the string pointed to by litP into a floating point constant
@@ -1589,20 +1663,23 @@ md_atof (type, litP, sizeP)
*sizeP = 0;
return _("Bad call to MD_ATOF()");
}
+
t = atof_ieee (input_line_pointer, type, words);
if (t)
input_line_pointer = t;
*sizeP = prec * sizeof (LITTLENUM_TYPE);
+
for (wordP = words + prec; prec--;)
{
md_number_to_chars (litP, (long) (*--wordP), sizeof (LITTLENUM_TYPE));
litP += sizeof (LITTLENUM_TYPE);
}
+
return 0;
}
-/* Convert number to chars in correct order */
+/* Convert number to chars in correct order. */
void
md_number_to_chars (buf, value, nbytes)
@@ -1613,7 +1690,6 @@ md_number_to_chars (buf, value, nbytes)
number_to_chars_littleendian (buf, value, nbytes);
}
-
/* This is a variant of md_numbers_to_chars. The reason for its'
existence is the fact that ns32k uses Huffman coded
displacements. This implies that the bit order is reversed in
@@ -1625,6 +1701,7 @@ md_number_to_chars (buf, value, nbytes)
11xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx double word
This must be taken care of and we do it here! */
+
static void
md_number_to_disp (buf, val, n)
char *buf;
@@ -1731,9 +1808,8 @@ md_number_to_imm (buf, val, n)
}
}
-
-/* fast bitfiddling support */
-/* mask used to zero bitfield before oring in the true field */
+/* Fast bitfiddling support. */
+/* Mask used to zero bitfield before oring in the true field. */
static unsigned long l_mask[] =
{
@@ -1762,8 +1838,7 @@ static unsigned long r_mask[] =
This routine is written for modification of the first 4 bytes pointed
to by buf, to yield speed.
The ifdef stuff is for selection between a ns32k-dependent routine
- and a general version. (My advice: use the general version!)
- */
+ and a general version. (My advice: use the general version!). */
static void
md_number_to_field (buf, val, field_ptr)
@@ -1783,31 +1858,26 @@ md_number_to_field (buf, val, field_ptr)
{
#ifdef ENDIAN
if (field_ptr->fx_bit_base)
- { /* override buf */
- mem_ptr = (unsigned long *) field_ptr->fx_bit_base;
- }
+ /* Override buf. */
+ mem_ptr = (unsigned long *) field_ptr->fx_bit_base;
else
- {
- mem_ptr = (unsigned long *) buf;
- }
+ mem_ptr = (unsigned long *) buf;
+
mem_ptr = ((unsigned long *)
((char *) mem_ptr + field_ptr->fx_bit_base_adj));
#else
if (field_ptr->fx_bit_base)
- { /* override buf */
- mem_ptr = (char *) field_ptr->fx_bit_base;
- }
+ mem_ptr = (char *) field_ptr->fx_bit_base;
else
- {
- mem_ptr = buf;
- }
+ mem_ptr = buf;
+
mem_ptr += field_ptr->fx_bit_base_adj;
#endif
-#ifdef ENDIAN /* we have a nice ns32k machine with lowbyte
- at low-physical mem */
+#ifdef ENDIAN
+ /* We have a nice ns32k machine with lowbyte at low-physical mem. */
object = *mem_ptr; /* get some bytes */
#else /* OVE Goof! the machine is a m68k or dito */
- /* That takes more byte fiddling */
+ /* That takes more byte fiddling. */
object = 0;
object |= mem_ptr[3] & 0xff;
object <<= 8;
@@ -1841,30 +1911,40 @@ md_number_to_field (buf, val, field_ptr)
}
}
-int md_pcrel_adjust (fragS *fragP)
+int
+md_pcrel_adjust (fragP)
+ fragS *fragP;
{
fragS *opcode_frag;
addressT opcode_address;
unsigned int offset;
- opcode_frag = frag_opcode_frag(fragP);
+
+ opcode_frag = frag_opcode_frag (fragP);
if (opcode_frag == 0)
return 0;
- offset = frag_opcode_offset(fragP);
+
+ offset = frag_opcode_offset (fragP);
opcode_address = offset + opcode_frag->fr_address;
+
return fragP->fr_address + fragP->fr_fix - opcode_address;
}
-int md_fix_pcrel_adjust (fixS *fixP)
+int
+md_fix_pcrel_adjust (fixP)
+ fixS *fixP;
{
fragS *fragP = fixP->fx_frag;
fragS *opcode_frag;
addressT opcode_address;
unsigned int offset;
- opcode_frag = fix_opcode_frag(fixP);
+
+ opcode_frag = fix_opcode_frag (fixP);
if (opcode_frag == 0)
return 0;
- offset = fix_opcode_offset(fixP);
+
+ offset = fix_opcode_offset (fixP);
opcode_address = offset + opcode_frag->fr_address;
+
return fixP->fx_where + fixP->fx_frag->fr_address - opcode_address;
}
@@ -1894,28 +1974,27 @@ md_apply_fix (fixP, val)
char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
- if (fix_bit_fixP(fixP))
- { /* Bitfields to fix, sigh */
- md_number_to_field (buf, val, fix_bit_fixP(fixP));
+ if (fix_bit_fixP (fixP))
+ { /* Bitfields to fix, sigh. */
+ md_number_to_field (buf, val, fix_bit_fixP (fixP));
}
else
- switch (fix_im_disp(fixP))
+ switch (fix_im_disp (fixP))
{
-
- case 0: /* Immediate field */
+ case 0: /* Immediate field. */
md_number_to_imm (buf, val, fixP->fx_size);
break;
- case 1: /* Displacement field */
+ case 1: /* Displacement field. */
/* Calculate offset */
{
- md_number_to_disp (buf,
- (fixP->fx_pcrel ? val + md_fix_pcrel_adjust(fixP)
- : val), fixP->fx_size);
+ md_number_to_disp (buf,
+ (fixP->fx_pcrel ? val + md_fix_pcrel_adjust (fixP)
+ : val), fixP->fx_size);
}
break;
- case 2: /* Pointer in a data object */
+ case 2: /* Pointer in a data object. */
md_number_to_chars (buf, val, fixP->fx_size);
break;
}
@@ -1963,18 +2042,19 @@ md_convert_frag (abfd, sec, fragP)
break;
}
- if(ext == 0)
+ if (ext == 0)
return;
know (fragP->fr_symbol);
object_address = fragP->fr_fix + fragP->fr_address;
+
/* The displacement of the address, from current location. */
disp = (S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset) - object_address;
#ifdef BFD_ASSEMBLER
disp += symbol_get_frag (fragP->fr_symbol)->fr_address;
#endif
- disp += md_pcrel_adjust(fragP);
+ disp += md_pcrel_adjust (fragP);
md_number_to_disp (buffer_address, (long) disp, (int) ext);
fragP->fr_fix += ext;
@@ -1982,7 +2062,7 @@ md_convert_frag (abfd, sec, fragP)
/* This function returns the estimated size a variable object will occupy,
one can say that we tries to guess the size of the objects before we
- actually know it */
+ actually know it. */
int
md_estimate_size_before_relax (fragP, segment)
@@ -1990,19 +2070,21 @@ md_estimate_size_before_relax (fragP, segment)
segT segment;
{
int old_fix;
+
old_fix = fragP->fr_fix;
+
switch (fragP->fr_subtype)
{
case IND (BRANCH, UNDEF):
if (S_GET_SEGMENT (fragP->fr_symbol) == segment)
{
- /* the symbol has been assigned a value */
+ /* The symbol has been assigned a value. */
fragP->fr_subtype = IND (BRANCH, BYTE);
}
else
{
- /* we don't relax symbols defined in an other segment the
- thing to do is to assume the object will occupy 4 bytes */
+ /* We don't relax symbols defined in an other segment the
+ thing to do is to assume the object will occupy 4 bytes. */
fix_new_ns32k (fragP,
(int) (fragP->fr_fix),
4,
@@ -2012,10 +2094,12 @@ md_estimate_size_before_relax (fragP, segment)
1,
0,
frag_bsr(fragP), /*sequent hack */
- frag_opcode_frag(fragP),
- frag_opcode_offset(fragP));
+ frag_opcode_frag (fragP),
+ frag_opcode_offset (fragP));
fragP->fr_fix += 4;
- /* fragP->fr_opcode[1]=0xff; */
+#if 0
+ fragP->fr_opcode[1] = 0xff;
+#endif
frag_wane (fragP);
break;
}
@@ -2025,12 +2109,13 @@ md_estimate_size_before_relax (fragP, segment)
default:
break;
}
+
return fragP->fr_var + fragP->fr_fix - old_fix;
}
int md_short_jump_size = 3;
int md_long_jump_size = 5;
-const int md_reloc_size = 8; /* Size of relocation record */
+const int md_reloc_size = 8; /* Size of relocation record. */
void
md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
@@ -2061,10 +2146,13 @@ md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
}
CONST char *md_shortopts = "m:";
-struct option md_longopts[] = {
+
+struct option md_longopts[] =
+{
{NULL, no_argument, NULL, 0}
};
-size_t md_longopts_size = sizeof(md_longopts);
+
+size_t md_longopts_size = sizeof (md_longopts);
int
md_parse_option (c, arg)
@@ -2102,19 +2190,16 @@ void
md_show_usage (stream)
FILE *stream;
{
- fprintf(stream, _("\
+ fprintf (stream, _("\
NS32K options:\n\
-m32032 | -m32532 select variant of NS32K architecture\n"));
}
-
-/*
- * bit_fix_new()
- *
- * Create a bit_fixS in obstack 'notes'.
- * This struct is used to profile the normal fix. If the bit_fixP is a
- * valid pointer (not NULL) the bit_fix data will be used to format the fix.
- */
+/* Create a bit_fixS in obstack 'notes'.
+ This struct is used to profile the normal fix. If the bit_fixP is a
+ valid pointer (not NULL) the bit_fix data will be used to format
+ the fix. */
+
bit_fixS *
bit_fix_new (size, offset, min, max, add, base_type, base_adj)
char size; /* Length of bitfield */
@@ -2157,23 +2242,22 @@ fix_new_ns32k (frag, where, size, add_symbol, offset, pcrel,
a bsr */
fragS *opcode_frag;
unsigned int opcode_offset;
-
{
fixS *fixP = fix_new (frag, where, size, add_symbol,
offset, pcrel,
#ifdef BFD_ASSEMBLER
- bit_fixP? NO_RELOC: reloc(size, pcrel, im_disp)
+ bit_fixP ? NO_RELOC : reloc (size, pcrel, im_disp)
#else
NO_RELOC
#endif
);
- fix_opcode_frag(fixP) = opcode_frag;
- fix_opcode_offset(fixP) = opcode_offset;
- fix_im_disp(fixP) = im_disp;
- fix_bsr(fixP) = bsr;
- fix_bit_fixP(fixP) = bit_fixP;
-} /* fix_new_ns32k() */
+ fix_opcode_frag (fixP) = opcode_frag;
+ fix_opcode_offset (fixP) = opcode_offset;
+ fix_im_disp (fixP) = im_disp;
+ fix_bsr (fixP) = bsr;
+ fix_bit_fixP (fixP) = bit_fixP;
+}
void
fix_new_ns32k_exp (frag, where, size, exp, pcrel,
@@ -2194,18 +2278,18 @@ fix_new_ns32k_exp (frag, where, size, exp, pcrel,
{
fixS *fixP = fix_new_exp (frag, where, size, exp, pcrel,
#ifdef BFD_ASSEMBLER
- bit_fixP? NO_RELOC: reloc(size, pcrel, im_disp)
+ bit_fixP ? NO_RELOC : reloc (size, pcrel, im_disp)
#else
NO_RELOC
#endif
);
- fix_opcode_frag(fixP) = opcode_frag;
- fix_opcode_offset(fixP) = opcode_offset;
- fix_im_disp(fixP) = im_disp;
- fix_bsr(fixP) = bsr;
- fix_bit_fixP(fixP) = bit_fixP;
-} /* fix_new_ns32k() */
+ fix_opcode_frag (fixP) = opcode_frag;
+ fix_opcode_offset (fixP) = opcode_offset;
+ fix_im_disp (fixP) = im_disp;
+ fix_bsr (fixP) = bsr;
+ fix_bit_fixP (fixP) = bit_fixP;
+}
/* This is TC_CONS_FIX_NEW, called by emit_expr in read.c. */
@@ -2230,16 +2314,18 @@ md_undefined_symbol (name)
}
/* Round up a section size to the appropriate boundary. */
+
valueT
md_section_align (segment, size)
segT segment;
valueT size;
{
- return size; /* Byte alignment is fine */
+ return size; /* Byte alignment is fine. */
}
/* Exactly what point is a PC-relative offset relative TO? On the
- ns32k, they're relative to the start of the instruction. */
+ ns32k, they're relative to the start of the instruction. */
+
long
md_pcrel_from (fixP)
fixS *fixP;
@@ -2247,8 +2333,8 @@ md_pcrel_from (fixP)
long res;
res = fixP->fx_where + fixP->fx_frag->fr_address;
#ifdef SEQUENT_COMPATABILITY
- if (frag_bsr(fixP->fx_frag))
- res += 0x12 /* FOO Kludge alert! */
+ if (frag_bsr (fixP->fx_frag))
+ res += 0x12 /* FOO Kludge alert! */
#endif
return res;
}
@@ -2263,7 +2349,7 @@ tc_gen_reloc (section, fixp)
arelent *rel;
bfd_reloc_code_real_type code;
- code = reloc(fixp->fx_size, fixp->fx_pcrel, fix_im_disp(fixp));
+ code = reloc (fixp->fx_size, fixp->fx_pcrel, fix_im_disp (fixp));
rel = (arelent *) xmalloc (sizeof (arelent));
rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
@@ -2297,12 +2383,10 @@ cons_fix_new_ns32k (where, fixP, segment_address_in_file)
struct fix *fixP;
relax_addressT segment_address_in_file;
{
- /*
- * In: length of relocation (or of address) in chars: 1, 2 or 4.
- * Out: GNU LD relocation length code: 0, 1, or 2.
- */
+ /* In: Length of relocation (or of address) in chars: 1, 2 or 4.
+ Out: GNU LD relocation length code: 0, 1, or 2. */
- static unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
+ static unsigned char nbytes_r_length[] = { 42, 0, 1, 42, 2 };
long r_symbolnum;
know (fixP->fx_addsy != NULL);
@@ -2320,12 +2404,10 @@ cons_fix_new_ns32k (where, fixP, segment_address_in_file)
| (long) (fixP->fx_pcrel << 24)
| (long) (nbytes_r_length[fixP->fx_size] << 25)
| (long) ((!S_IS_DEFINED (fixP->fx_addsy)) << 27)
- | (long) (fix_bsr(fixP) << 28)
- | (long) (fix_im_disp(fixP) << 29)),
+ | (long) (fix_bsr (fixP) << 28)
+ | (long) (fix_im_disp (fixP) << 29)),
4);
}
#endif /* OBJ_AOUT */
#endif /* BFD_ASSMEBLER */
-
-/* end of tc-ns32k.c */