the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/*
- Written By Steve Chamberlain
- sac@cygnus.com
- */
+ Written By Steve Chamberlain
+ sac@cygnus.com
+ */
#include <stdio.h>
#include "as.h"
pseudo-op name without dot
function to call to execute this pseudo-op
Integer arg to pass to the function
- */
+ */
void cons ();
void s_align_bytes ();
{0, 0, 0}
};
-/*int md_reloc_size;*/
+/*int md_reloc_size; */
static int relax; /* set if -relax seen */
static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
/*
- This function is called once, at assembler startup time. This should
- set up all the tables, etc that the MD part of the assembler needs
- */
+ This function is called once, at assembler startup time. This should
+ set up all the tables, etc that the MD part of the assembler needs
+ */
void
md_begin ()
else
{
/* Make all the opcodes with the same name point to the same
- string */
+ string */
opcode->name = prev_name;
}
}
static expressionS immediate; /* absolute expression */
typedef struct
-{
- sh_arg_type type;
- int reg;
-}
+ {
+ sh_arg_type type;
+ int reg;
+ }
sh_operand_info;
return 0;
}
+static symbolS *dot()
+{
+ const char *fake;
+
+ /* JF: '.' is pseudo symbol with value of current location
+ in current segment. */
+ fake = FAKE_LABEL_NAME;
+ return symbol_new (fake,
+ now_seg,
+ (valueT) frag_now_fix (),
+ frag_now);
+
+}
+
+
static
char *
parse_exp (s)
{
char *save;
char *new;
- segT seg;
save = input_line_pointer;
-
-
input_line_pointer = s;
-
- seg = expr (0, &immediate);
+ expression (&immediate);
+ if (immediate.X_op == O_absent)
+ as_bad ("missing operand");
new = input_line_pointer;
input_line_pointer = save;
- if (SEG_NORMAL (seg))
- return new;
- switch (seg)
- {
- case SEG_ABSOLUTE:
- case SEG_UNKNOWN:
- case SEG_DIFFERENCE:
- case SEG_BIG:
- case SEG_REGISTER:
- return new;
- case SEG_ABSENT:
- as_bad ("Missing operand");
- return new;
- default:
- as_bad ("Don't understand operand of type %s", segment_name (seg));
- return new;
- }
+ return new;
}
/* The many forms of operand:
- Rn Register direct
- @Rn Register indirect
- @Rn+ Autoincrement
- @-Rn Autodecrement
+ Rn Register direct
+ @Rn Register indirect
+ @Rn+ Autoincrement
+ @-Rn Autodecrement
@(disp:4,Rn)
@(disp:8,GBR)
@(disp:8,PC)
else if (src[0] == '(')
{
/* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
- @(r0, rn) */
+ @(r0, rn) */
src++;
len = parse_reg (src, &mode, &(op->reg));
if (len && mode == A_REG_N)
}
else if (mode == A_DISP_PC)
{
+ /* Turn a plain @(4,pc) into @(.+4,pc) */
+ if (immediate.X_op == O_constant) {
+ immediate.X_add_symbol = dot();
+ immediate.X_op = O_symbol;
+ }
op->type = A_DISP_PC;
}
else
/* Passed a pointer to a list of opcodes which use different
addressing modes, return the opcode which matches the opcodes
provided
- */
+ */
static
sh_opcode_info *
return 0;
}
/* look at both operands needed by the opcodes and provided by
- the user - since an arg test will often fail on the same arg
- again and again, we'll try and test the last failing arg the
- first on each opcode try */
+ the user - since an arg test will often fail on the same arg
+ again and again, we'll try and test the last failing arg the
+ first on each opcode try */
for (n = 0; this_try->arg[n]; n++)
{
int low;
int high;
{
- if (operand->X_seg != SEG_ABSOLUTE
+ if (operand->X_op != O_constant
|| operand->X_add_number < low
|| operand->X_add_number > high)
{
int how;
int pcrel;
{
- fix_new (frag_now,
- where - frag_now->fr_literal,
- 4,
- immediate.X_add_symbol,
- immediate.X_subtract_symbol,
- immediate.X_add_number,
- pcrel,
- how);
+ fix_new_exp (frag_now,
+ where - frag_now->fr_literal,
+ 4,
+ &immediate,
+ pcrel,
+ how);
}
insert (output + 1, R_SH_IMM8, 0);
break;
case PCRELIMM_8BY4:
- insert (output + 1, R_SH_PCRELIMM8BY4, 0);
+ insert (output + 1, R_SH_PCRELIMM8BY4, 1);
break;
case PCRELIMM_8BY2:
- insert (output + 1, R_SH_PCRELIMM8BY2, 0);
+ insert (output + 1, R_SH_PCRELIMM8BY2, 1);
break;
default:
printf ("failed for %d\n", i);
/* This is the guts of the machine-dependent assembler. STR points to a
machine dependent instruction. This function is supposed to emit
the frags/bytes it assembles to.
- */
+ */
void
md_assemble (str)
unsigned char *op_end;
sh_operand_info operand[2];
sh_opcode_info *opcode;
- unsigned char *name;
-
+ char name[20];
int nlen = 0;
-
+ char *p;
/* Drop leading whitespace */
while (*str == ' ')
str++;
/* find the op code end */
- for (name = op_start = op_end = (unsigned char *) (str);
- *op_end &&
- !is_end_of_line[*op_end] && *op_end != ' ';
+ for (op_start = op_end = (unsigned char *) (str);
+ *op_end
+ && nlen < 20
+ && !is_end_of_line[*op_end] && *op_end != ' ';
op_end++)
{
+ name[nlen] = op_start[nlen];
nlen++;
}
name[nlen] = 0;
- if (op_end == op_start)
+ if (nlen == 0)
{
as_bad ("can't find opcode ");
}
if (opcode->arg[0] == A_BDISP12
|| opcode->arg[0] == A_BDISP8)
{
- input_line_pointer = parse_exp (op_end + 1);
+ parse_exp (op_end + 1);
build_relax (opcode);
}
else
{
- input_line_pointer = get_operands (opcode, op_end, operand);
-
+ if (opcode->arg[0] != A_END)
+ {
+ get_operands (opcode, op_end, operand);
+ }
opcode = get_specific (opcode, operand);
if (opcode == 0)
printf ("call to tc_headers_hook \n");
}
-void
-DEFUN_VOID (md_end)
-{
-}
-
/* Various routines to kill one day */
/* Equal to MAX_PRECISION in atof-ieee.c */
#define MAX_LITTLENUMS 6
/* 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)
char type;
md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
litP += sizeof (LITTLENUM_TYPE);
}
- return ""; /* Someone should teach Dean about null pointers */
+ return 0;
}
+\f
+CONST char *md_shortopts = "";
+struct option md_longopts[] = {
+#define OPTION_RELAX (OPTION_MD_BASE)
+ {"relax", no_argument, NULL, OPTION_RELAX},
+ {NULL, no_argument, NULL, 0}
+};
+size_t md_longopts_size = sizeof(md_longopts);
int
-md_parse_option (argP, cntP, vecP)
- char **argP;
- int *cntP;
- char ***vecP;
-
+md_parse_option (c, arg)
+ int c;
+ char *arg;
{
- if (!strcmp (*argP, "relax"))
+ switch (c)
{
+ case OPTION_RELAX:
relax = 1;
- **argP = 0;
+ break;
+
+ default:
+ return 0;
}
+
return 1;
}
+void
+md_show_usage (stream)
+ FILE *stream;
+{
+ fprintf(stream, "\
+SH options:\n\
+-relax alter jump instructions for long displacements\n");
+}
+\f
int md_short_jump_size;
void
}
/*
-called after relaxing, change the frags so they know how big they are
-*/
+ called after relaxing, change the frags so they know how big they are
+ */
void
md_convert_frag (headers, fragP)
object_headers *headers;
int disp = targ_addr - next_inst - 2;
disp /= 2;
- md_number_to_chars (buffer + 1, disp, 1);
+
+ md_number_to_chars (buffer + 1, disp & 0xff, 1);
fragP->fr_fix += 2;
fragP->fr_var = 0;
}
disp /= 2;
t = buffer[0] & 0xf0;
- md_number_to_chars (buffer, disp, 2);
+ md_number_to_chars (buffer, disp & 0xfff, 2);
buffer[0] = (buffer[0] & 0xf) | t;
fragP->fr_fix += 2;
fragP->fr_var = 0;
mov.w @(0, PC), r14
.long disp
foo: bra @r14
- */
+ */
int next_inst =
fragP->fr_fix + fragP->fr_address + UNCOND32_LENGTH;
buffer[0] = 0xa0; /* branch over move and disp */
buffer[1] = 3;
- buffer[2] = 0xd0 | JREG;/* Build mov insn */
+ buffer[2] = 0xd0 | JREG; /* Build mov insn */
buffer[3] = 0x00;
buffer[4] = 0; /* space for 32 bit jump disp */
fragP->fr_fix + 4,
4,
fragP->fr_symbol,
- 0,
fragP->fr_offset,
0,
R_SH_IMM32);
int disp = targ_addr - next_inst;
disp /= 2;
- md_number_to_chars (buffer + 2, disp, 2);
+ md_number_to_chars (buffer + 2, disp & 0xfff, 2);
buffer[0] ^= 0x2; /* Toggle T/F bit */
buffer[1] = 1; /* branch over jump and nop */
buffer[2] = (buffer[2] & 0xf) | 0xa0; /* Build jump insn */
displacement either, the code sequence looks like:
b!cond foop
mov.w @(n, PC), r14
- jmp @r14
+ jmp @r14
nop
.long where
foop:
- */
+ */
int next_inst =
fragP->fr_fix + fragP->fr_address + COND32_LENGTH;
buffer[0] ^= 0x2; /* Toggle T/F bit */
#define JREG 14
buffer[1] = 5; /* branch over mov, jump, nop and ptr */
- buffer[2] = 0xd0 | JREG;/* Build mov insn */
+ buffer[2] = 0xd0 | JREG; /* Build mov insn */
buffer[3] = 0x2;
- buffer[4] = 0x40 | JREG;/* Build jmp @JREG */
+ buffer[4] = 0x40 | JREG; /* Build jmp @JREG */
buffer[5] = 0x0b;
buffer[6] = 0x20; /* build nop */
buffer[7] = 0x0b;
fragP->fr_fix + 8,
4,
fragP->fr_symbol,
- 0,
fragP->fr_offset,
0,
R_SH_IMM32);
if (donerelax && !relax)
{
- as_bad ("Offset doesn't fit at 0x%x, trying to get to 0x%x",
- fragP->fr_address,
- targ_addr);
+ as_warn ("Offset doesn't fit at 0x%x, trying to get to %s+0x%x",
+ fragP->fr_address,
+ fragP->fr_symbol ? S_GET_NAME(fragP->fr_symbol): "",
+ targ_addr);
}
}
int addr = fixP->fx_frag->fr_address + fixP->fx_where;
if (fixP->fx_r_type == 0)
{
- fixP->fx_r_type = R_SH_IMM32;
+ if (fixP->fx_size == 2)
+ fixP->fx_r_type = R_SH_IMM16;
+ else
+ fixP->fx_r_type = R_SH_IMM32;
}
switch (fixP->fx_r_type)
case R_SH_PCRELIMM8BY4:
addr &= ~1;
-
+#if 0
if (val & 0x3)
as_warn ("non aligned displacement at %x\n", addr);
- val -= (addr + 4);
+#endif
+ /* val -= (addr + 4); */
val += 3;
val /= 4;
if (val & ~0xff)
addr &= ~1;
if (val & 0x1)
as_bad ("odd displacement at %x\n", addr);
- val -= (addr + 4);
+ /* val -= (addr + 4); */
val++;
val /= 2;
if (val & ~0xff)
*buf++ = val >> 0;
break;
+ case R_SH_IMM16:
+ *buf++ = val >> 8;
+ *buf++ = val >> 0;
+ break;
+
default:
abort ();
}
int md_long_jump_size;
/*
-called just before address relaxation, return the length
-by which a fragment must grow to reach it's destination
-*/
+ called just before address relaxation, return the length
+ by which a fragment must grow to reach it's destination
+ */
int
md_estimate_size_before_relax (fragP, segment_type)
register fragS *fragP;
&& S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
{
/* Got a symbol and it's defined in this segment, become byte
- sized - maybe it will fix up */
+ sized - maybe it will fix up */
fragP->fr_subtype = C (COND_JUMP, COND8);
fragP->fr_var = md_relax_table[C (COND_JUMP, COND8)].rlx_length;
}
valueT use;
int nbytes;
{
- switch (nbytes)
- {
- case 4:
- *ptr++ = (use >> 24) & 0xff;
- case 3:
- *ptr++ = (use >> 16) & 0xff;
- case 2:
- *ptr++ = (use >> 8) & 0xff;
- case 1:
- *ptr++ = (use >> 0) & 0xff;
- break;
- default:
- abort ();
- }
+ number_to_chars_bigendian (ptr, use, nbytes);
}
+
long
md_pcrel_from (fixP)
fixS *fixP;
-
{
- int gap = fixP->fx_size + fixP->fx_where +
- fixP->fx_frag->fr_address;
+ int gap = fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address - 1 ;
return gap;
}
-void
-tc_coff_symbol_emit_hook ()
-{
-}
-
short
tc_coff_fix2rtype (fix_ptr)
fixS *fix_ptr;
{
return md_relax_table[frag->fr_subtype].rlx_length;
}
-
-
-/* end of tc-sh.c */