2002-12-30 20:25:13 +01:00
|
|
|
/* tc-msp430.c -- Assembler code for the Texas Instruments MSP430
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
Copyright (C) 2002-2013 Free Software Foundation, Inc.
|
2002-12-30 20:25:13 +01:00
|
|
|
Contributed by Dmitry Diky <diwil@mail.ru>
|
|
|
|
|
|
|
|
This file is part of GAS, the GNU Assembler.
|
|
|
|
|
|
|
|
GAS is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-03 13:01:12 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
2002-12-30 20:25:13 +01:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
GAS is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GAS; see the file COPYING. If not, write to
|
2005-05-05 11:13:19 +02:00
|
|
|
the Free Software Foundation, 51 Franklin Street - Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2012-05-17 17:13:28 +02:00
|
|
|
#include "as.h"
|
2002-12-30 20:25:13 +01:00
|
|
|
#include <limits.h>
|
|
|
|
#define PUSH_1X_WORKAROUND
|
|
|
|
#include "subsegs.h"
|
|
|
|
#include "opcode/msp430.h"
|
|
|
|
#include "safe-ctype.h"
|
2005-09-01 14:41:25 +02:00
|
|
|
#include "dwarf2dbg.h"
|
2013-05-02 23:06:15 +02:00
|
|
|
#include "elf/msp430.h"
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2007-10-11 15:48:39 +02:00
|
|
|
/* We will disable polymorphs by default because it is dangerous.
|
* config/obj-coff.c, config/tc-arm.c, config/tc-bfin.c,
config/tc-cris.c, config/tc-crx.c, config/tc-i386.c,
config/tc-ia64.c, config/tc-maxq.c, config/tc-maxq.h,
config/tc-mips.c, config/tc-msp430.c, config/tc-sh.c,
config/tc-tic4x.c, config/tc-xtensa.c: Fix comment typos.
2006-04-24 00:12:43 +02:00
|
|
|
The potential problem here is the following: assume we got the
|
2005-08-12 13:54:23 +02:00
|
|
|
following code:
|
|
|
|
|
|
|
|
jump .l1
|
|
|
|
nop
|
|
|
|
jump subroutine ; external symbol
|
|
|
|
.l1:
|
|
|
|
nop
|
|
|
|
ret
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2005-08-12 13:54:23 +02:00
|
|
|
In case of assembly time relaxation we'll get:
|
|
|
|
0: jmp .l1 <.text +0x08> (reloc deleted)
|
|
|
|
2: nop
|
|
|
|
4: br subroutine
|
|
|
|
.l1:
|
|
|
|
8: nop
|
|
|
|
10: ret
|
|
|
|
|
2007-10-11 15:48:39 +02:00
|
|
|
If the 'subroutine' is within +-1024 bytes range then linker
|
|
|
|
will produce:
|
2005-08-12 13:54:23 +02:00
|
|
|
0: jmp .text +0x08
|
|
|
|
2: nop
|
|
|
|
4: jmp subroutine
|
|
|
|
.l1:
|
|
|
|
6: nop
|
|
|
|
8: ret ; 'jmp .text +0x08' will land here. WRONG!!!
|
|
|
|
|
|
|
|
The workaround is the following:
|
2007-10-11 15:48:39 +02:00
|
|
|
1. Declare global var enable_polymorphs which set to 1 via option -mp.
|
2005-08-12 13:54:23 +02:00
|
|
|
2. Declare global var enable_relax which set to 1 via option -mQ.
|
|
|
|
|
|
|
|
If polymorphs are enabled, and relax isn't, treat all jumps as long jumps,
|
|
|
|
do not delete any relocs and leave them for linker.
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2007-10-11 15:48:39 +02:00
|
|
|
If relax is enabled, relax at assembly time and kill relocs as necessary. */
|
2005-08-12 13:54:23 +02:00
|
|
|
|
|
|
|
int msp430_enable_relax;
|
|
|
|
int msp430_enable_polys;
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Set linkrelax here to avoid fixups in most sections. */
|
|
|
|
int linkrelax = 1;
|
|
|
|
|
2004-11-19 13:28:03 +01:00
|
|
|
/* GCC uses the some condition codes which we'll
|
|
|
|
implement as new polymorph instructions.
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2004-11-19 13:28:03 +01:00
|
|
|
COND EXPL SHORT JUMP LONG JUMP
|
|
|
|
===============================================
|
|
|
|
eq == jeq jne +4; br lab
|
|
|
|
ne != jne jeq +4; br lab
|
|
|
|
|
|
|
|
ltn honours no-overflow flag
|
|
|
|
ltn < jn jn +2; jmp +4; br lab
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
lt < jl jge +4; br lab
|
2004-11-19 13:28:03 +01:00
|
|
|
ltu < jlo lhs +4; br lab
|
|
|
|
le <= see below
|
|
|
|
leu <= see below
|
|
|
|
|
|
|
|
gt > see below
|
|
|
|
gtu > see below
|
|
|
|
ge >= jge jl +4; br lab
|
|
|
|
geu >= jhs jlo +4; br lab
|
|
|
|
===============================================
|
|
|
|
|
|
|
|
Therefore, new opcodes are (BranchEQ -> beq; and so on...)
|
|
|
|
beq,bne,blt,bltn,bltu,bge,bgeu
|
2013-05-02 23:06:15 +02:00
|
|
|
'u' means unsigned compares
|
|
|
|
|
2004-11-19 13:28:03 +01:00
|
|
|
Also, we add 'jump' instruction:
|
|
|
|
jump UNCOND -> jmp br lab
|
|
|
|
|
|
|
|
They will have fmt == 4, and insn_opnumb == number of instruction. */
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
struct rcodes_s
|
2004-11-19 13:28:03 +01:00
|
|
|
{
|
|
|
|
char * name;
|
|
|
|
int index; /* Corresponding insn_opnumb. */
|
|
|
|
int sop; /* Opcode if jump length is short. */
|
|
|
|
long lpos; /* Label position. */
|
|
|
|
long lop0; /* Opcode 1 _word_ (16 bits). */
|
|
|
|
long lop1; /* Opcode second word. */
|
|
|
|
long lop2; /* Opcode third word. */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MSP430_RLC(n,i,sop,o1) \
|
|
|
|
{#n, i, sop, 2, (o1 + 2), 0x4010, 0}
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
static struct rcodes_s msp430_rcodes[] =
|
2004-11-19 13:28:03 +01:00
|
|
|
{
|
|
|
|
MSP430_RLC (beq, 0, 0x2400, 0x2000),
|
|
|
|
MSP430_RLC (bne, 1, 0x2000, 0x2400),
|
|
|
|
MSP430_RLC (blt, 2, 0x3800, 0x3400),
|
|
|
|
MSP430_RLC (bltu, 3, 0x2800, 0x2c00),
|
|
|
|
MSP430_RLC (bge, 4, 0x3400, 0x3800),
|
|
|
|
MSP430_RLC (bgeu, 5, 0x2c00, 0x2800),
|
|
|
|
{"bltn", 6, 0x3000, 3, 0x3000 + 1, 0x3c00 + 2,0x4010},
|
|
|
|
{"jump", 7, 0x3c00, 1, 0x4010, 0, 0},
|
|
|
|
{0,0,0,0,0,0,0}
|
|
|
|
};
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
#undef MSP430_RLC
|
|
|
|
#define MSP430_RLC(n,i,sop,o1) \
|
|
|
|
{#n, i, sop, 2, (o1 + 2), 0x0030, 0}
|
|
|
|
|
|
|
|
static struct rcodes_s msp430x_rcodes[] =
|
|
|
|
{
|
|
|
|
MSP430_RLC (beq, 0, 0x2400, 0x2000),
|
|
|
|
MSP430_RLC (bne, 1, 0x2000, 0x2400),
|
|
|
|
MSP430_RLC (blt, 2, 0x3800, 0x3400),
|
|
|
|
MSP430_RLC (bltu, 3, 0x2800, 0x2c00),
|
|
|
|
MSP430_RLC (bge, 4, 0x3400, 0x3800),
|
|
|
|
MSP430_RLC (bgeu, 5, 0x2c00, 0x2800),
|
|
|
|
{"bltn", 6, 0x3000, 3, 0x0030 + 1, 0x3c00 + 2, 0x3000},
|
|
|
|
{"jump", 7, 0x3c00, 1, 0x0030, 0, 0},
|
|
|
|
{0,0,0,0,0,0,0}
|
|
|
|
};
|
|
|
|
#undef MSP430_RLC
|
2004-11-19 13:28:03 +01:00
|
|
|
|
|
|
|
/* More difficult than above and they have format 5.
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2004-11-19 13:28:03 +01:00
|
|
|
COND EXPL SHORT LONG
|
|
|
|
=================================================================
|
|
|
|
gt > jeq +2; jge label jeq +6; jl +4; br label
|
|
|
|
gtu > jeq +2; jhs label jeq +6; jlo +4; br label
|
|
|
|
leu <= jeq label; jlo label jeq +2; jhs +4; br label
|
|
|
|
le <= jeq label; jl label jeq +2; jge +4; br label
|
|
|
|
================================================================= */
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
struct hcodes_s
|
2004-11-19 13:28:03 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
char * name;
|
2004-11-19 13:28:03 +01:00
|
|
|
int index; /* Corresponding insn_opnumb. */
|
|
|
|
int tlab; /* Number of labels in short mode. */
|
|
|
|
int op0; /* Opcode for first word of short jump. */
|
|
|
|
int op1; /* Opcode for second word of short jump. */
|
|
|
|
int lop0; /* Opcodes for long jump mode. */
|
|
|
|
int lop1;
|
|
|
|
int lop2;
|
|
|
|
};
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
static struct hcodes_s msp430_hcodes[] =
|
2004-11-19 13:28:03 +01:00
|
|
|
{
|
|
|
|
{"bgt", 0, 1, 0x2401, 0x3400, 0x2403, 0x3802, 0x4010 },
|
|
|
|
{"bgtu", 1, 1, 0x2401, 0x2c00, 0x2403, 0x2802, 0x4010 },
|
|
|
|
{"bleu", 2, 2, 0x2400, 0x2800, 0x2401, 0x2c02, 0x4010 },
|
|
|
|
{"ble", 3, 2, 0x2400, 0x3800, 0x2401, 0x3402, 0x4010 },
|
|
|
|
{0,0,0,0,0,0,0,0}
|
|
|
|
};
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
static struct hcodes_s msp430x_hcodes[] =
|
|
|
|
{
|
|
|
|
{"bgt", 0, 1, 0x2401, 0x3400, 0x2403, 0x3802, 0x0030 },
|
|
|
|
{"bgtu", 1, 1, 0x2401, 0x2c00, 0x2403, 0x2802, 0x0030 },
|
|
|
|
{"bleu", 2, 2, 0x2400, 0x2800, 0x2401, 0x2c02, 0x0030 },
|
|
|
|
{"ble", 3, 2, 0x2400, 0x3800, 0x2401, 0x3402, 0x0030 },
|
|
|
|
{0,0,0,0,0,0,0,0}
|
|
|
|
};
|
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
const char comment_chars[] = ";";
|
|
|
|
const char line_comment_chars[] = "#";
|
2007-02-28 11:02:37 +01:00
|
|
|
const char line_separator_chars[] = "{";
|
2002-12-30 20:25:13 +01:00
|
|
|
const char EXP_CHARS[] = "eE";
|
|
|
|
const char FLT_CHARS[] = "dD";
|
|
|
|
|
|
|
|
/* Handle long expressions. */
|
|
|
|
extern LITTLENUM_TYPE generic_bignum[];
|
|
|
|
|
|
|
|
static struct hash_control *msp430_hash;
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Relaxations. */
|
|
|
|
#define STATE_UNCOND_BRANCH 1 /* jump */
|
|
|
|
#define STATE_NOOV_BRANCH 3 /* bltn */
|
|
|
|
#define STATE_SIMPLE_BRANCH 2 /* bne, beq, etc... */
|
|
|
|
#define STATE_EMUL_BRANCH 4
|
|
|
|
|
|
|
|
#define CNRL 2
|
|
|
|
#define CUBL 4
|
|
|
|
#define CNOL 8
|
|
|
|
#define CSBL 6
|
|
|
|
#define CEBL 4
|
|
|
|
|
|
|
|
/* Length. */
|
|
|
|
#define STATE_BITS10 1 /* wild guess. short jump */
|
|
|
|
#define STATE_WORD 2 /* 2 bytes pc rel. addr. more */
|
|
|
|
#define STATE_UNDEF 3 /* cannot handle this yet. convert to word mode */
|
|
|
|
|
|
|
|
#define ENCODE_RELAX(what,length) (((what) << 2) + (length))
|
|
|
|
#define RELAX_STATE(s) ((s) & 3)
|
|
|
|
#define RELAX_LEN(s) ((s) >> 2)
|
|
|
|
#define RELAX_NEXT(a,b) ENCODE_RELAX (a, b + 1)
|
|
|
|
|
|
|
|
relax_typeS md_relax_table[] =
|
|
|
|
{
|
|
|
|
/* Unused. */
|
|
|
|
{1, 1, 0, 0},
|
|
|
|
{1, 1, 0, 0},
|
|
|
|
{1, 1, 0, 0},
|
|
|
|
{1, 1, 0, 0},
|
|
|
|
|
|
|
|
/* Unconditional jump. */
|
|
|
|
{1, 1, 8, 5},
|
|
|
|
{1024, -1024, CNRL, RELAX_NEXT (STATE_UNCOND_BRANCH, STATE_BITS10)}, /* state 10 bits displ */
|
|
|
|
{0, 0, CUBL, RELAX_NEXT (STATE_UNCOND_BRANCH, STATE_WORD)}, /* state word */
|
|
|
|
{1, 1, CUBL, 0}, /* state undef */
|
|
|
|
|
|
|
|
/* Simple branches. */
|
|
|
|
{0, 0, 8, 9},
|
|
|
|
{1024, -1024, CNRL, RELAX_NEXT (STATE_SIMPLE_BRANCH, STATE_BITS10)}, /* state 10 bits displ */
|
|
|
|
{0, 0, CSBL, RELAX_NEXT (STATE_SIMPLE_BRANCH, STATE_WORD)}, /* state word */
|
|
|
|
{1, 1, CSBL, 0},
|
|
|
|
|
|
|
|
/* blt no overflow branch. */
|
|
|
|
{1, 1, 8, 13},
|
|
|
|
{1024, -1024, CNRL, RELAX_NEXT (STATE_NOOV_BRANCH, STATE_BITS10)}, /* state 10 bits displ */
|
|
|
|
{0, 0, CNOL, RELAX_NEXT (STATE_NOOV_BRANCH, STATE_WORD)}, /* state word */
|
|
|
|
{1, 1, CNOL, 0},
|
|
|
|
|
|
|
|
/* Emulated branches. */
|
|
|
|
{1, 1, 8, 17},
|
|
|
|
{1020, -1020, CEBL, RELAX_NEXT (STATE_EMUL_BRANCH, STATE_BITS10)}, /* state 10 bits displ */
|
|
|
|
{0, 0, CNOL, RELAX_NEXT (STATE_EMUL_BRANCH, STATE_WORD)}, /* state word */
|
|
|
|
{1, 1, CNOL, 0}
|
|
|
|
};
|
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2003-09-17 13:27:39 +02:00
|
|
|
#define MAX_OP_LEN 256
|
2002-12-30 20:25:13 +01:00
|
|
|
|
|
|
|
struct mcu_type_s
|
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
char * name;
|
2002-12-30 20:25:13 +01:00
|
|
|
int isa;
|
|
|
|
int mach;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MSP430_ISA_11 11
|
2003-08-08 12:14:52 +02:00
|
|
|
#define MSP430_ISA_110 110
|
2002-12-30 20:25:13 +01:00
|
|
|
#define MSP430_ISA_12 12
|
|
|
|
#define MSP430_ISA_13 13
|
|
|
|
#define MSP430_ISA_14 14
|
2003-08-08 12:14:52 +02:00
|
|
|
#define MSP430_ISA_15 15
|
|
|
|
#define MSP430_ISA_16 16
|
2013-05-02 23:06:15 +02:00
|
|
|
#define MSP430_ISA_20 20
|
2005-08-08 19:08:04 +02:00
|
|
|
#define MSP430_ISA_21 21
|
2013-05-02 23:06:15 +02:00
|
|
|
#define MSP430_ISA_22 22
|
|
|
|
#define MSP430_ISA_23 23
|
|
|
|
#define MSP430_ISA_24 24
|
|
|
|
#define MSP430_ISA_26 26
|
2002-12-30 20:25:13 +01:00
|
|
|
#define MSP430_ISA_31 31
|
|
|
|
#define MSP430_ISA_32 32
|
|
|
|
#define MSP430_ISA_33 33
|
2003-08-08 12:14:52 +02:00
|
|
|
#define MSP430_ISA_41 41
|
|
|
|
#define MSP430_ISA_42 42
|
2002-12-30 20:25:13 +01:00
|
|
|
#define MSP430_ISA_43 43
|
|
|
|
#define MSP430_ISA_44 44
|
2013-05-02 23:06:15 +02:00
|
|
|
#define MSP430X_ISA 45
|
|
|
|
#define MSP430_ISA_46 46
|
|
|
|
#define MSP430_ISA_47 47
|
|
|
|
#define MSP430_ISA_54 54
|
|
|
|
|
|
|
|
/* Generate a 16-bit relocation.
|
|
|
|
For the 430X we generate a relocation without linkwer range checking
|
|
|
|
if the value is being used in an extended (ie 20-bit) instruction.
|
|
|
|
For the 430 we generate a relocation without assembler range checking
|
|
|
|
if we are handling an immediate value or a byte-width instruction. */
|
|
|
|
#undef CHECK_RELOC_MSP430
|
|
|
|
#define CHECK_RELOC_MSP430 \
|
|
|
|
(msp430_mcu->isa == MSP430X_ISA \
|
|
|
|
? (extended_op ? BFD_RELOC_16 : BFD_RELOC_MSP430X_ABS16) \
|
|
|
|
: ((imm_op || byte_op) \
|
|
|
|
? BFD_RELOC_MSP430_16_BYTE : BFD_RELOC_MSP430_16))
|
|
|
|
|
|
|
|
/* Generate a 16-bit pc-relative relocation.
|
|
|
|
For the 430X we generate a relocation without linkwer range checking.
|
|
|
|
For the 430 we generate a relocation without assembler range checking
|
|
|
|
if we are handling an immediate value or a byte-width instruction. */
|
|
|
|
#undef CHECK_RELOC_MSP430_PCREL
|
|
|
|
#define CHECK_RELOC_MSP430_PCREL \
|
|
|
|
(msp430_mcu->isa == MSP430X_ISA \
|
|
|
|
? BFD_RELOC_MSP430X_PCR16 \
|
|
|
|
: (imm_op || byte_op) \
|
|
|
|
? BFD_RELOC_MSP430_16_PCREL_BYTE : BFD_RELOC_MSP430_16_PCREL)
|
2002-12-30 20:25:13 +01:00
|
|
|
|
|
|
|
static struct mcu_type_s mcu_types[] =
|
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
{"msp1", MSP430_ISA_11, bfd_mach_msp11},
|
|
|
|
{"msp2", MSP430_ISA_14, bfd_mach_msp14},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp3", MSP430_ISA_20, bfd_mach_msp20},
|
|
|
|
{"msp4", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp5", MSP430_ISA_31, bfd_mach_msp31},
|
|
|
|
{"msp6", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
{"msp430x110", MSP430_ISA_11, bfd_mach_msp11},
|
|
|
|
{"msp430x112", MSP430_ISA_11, bfd_mach_msp11},
|
|
|
|
{"msp430x1101", MSP430_ISA_110, bfd_mach_msp110},
|
|
|
|
{"msp430x1111", MSP430_ISA_110, bfd_mach_msp110},
|
|
|
|
{"msp430x1121", MSP430_ISA_110, bfd_mach_msp110},
|
|
|
|
{"msp430x1122", MSP430_ISA_11, bfd_mach_msp110},
|
|
|
|
{"msp430x1132", MSP430_ISA_11, bfd_mach_msp110},
|
|
|
|
|
|
|
|
{"msp430x122", MSP430_ISA_12, bfd_mach_msp12},
|
|
|
|
{"msp430x123", MSP430_ISA_12, bfd_mach_msp12},
|
|
|
|
{"msp430x1222", MSP430_ISA_12, bfd_mach_msp12},
|
|
|
|
{"msp430x1232", MSP430_ISA_12, bfd_mach_msp12},
|
|
|
|
|
|
|
|
{"msp430x133", MSP430_ISA_13, bfd_mach_msp13},
|
|
|
|
{"msp430x135", MSP430_ISA_13, bfd_mach_msp13},
|
|
|
|
{"msp430x1331", MSP430_ISA_13, bfd_mach_msp13},
|
|
|
|
{"msp430x1351", MSP430_ISA_13, bfd_mach_msp13},
|
|
|
|
{"msp430x147", MSP430_ISA_14, bfd_mach_msp14},
|
|
|
|
{"msp430x148", MSP430_ISA_14, bfd_mach_msp14},
|
|
|
|
{"msp430x149", MSP430_ISA_14, bfd_mach_msp14},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430x1471", MSP430_ISA_14, bfd_mach_msp14},
|
|
|
|
{"msp430x1481", MSP430_ISA_14, bfd_mach_msp14},
|
|
|
|
{"msp430x1491", MSP430_ISA_14, bfd_mach_msp14},
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
{"msp430x155", MSP430_ISA_15, bfd_mach_msp15},
|
|
|
|
{"msp430x156", MSP430_ISA_15, bfd_mach_msp15},
|
|
|
|
{"msp430x157", MSP430_ISA_15, bfd_mach_msp15},
|
|
|
|
{"msp430x167", MSP430_ISA_16, bfd_mach_msp16},
|
|
|
|
{"msp430x168", MSP430_ISA_16, bfd_mach_msp16},
|
|
|
|
{"msp430x169", MSP430_ISA_16, bfd_mach_msp16},
|
2004-07-26 14:29:02 +02:00
|
|
|
{"msp430x1610", MSP430_ISA_16, bfd_mach_msp16},
|
|
|
|
{"msp430x1611", MSP430_ISA_16, bfd_mach_msp16},
|
|
|
|
{"msp430x1612", MSP430_ISA_16, bfd_mach_msp16},
|
2003-08-08 12:14:52 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430x2001", MSP430_ISA_20, bfd_mach_msp20},
|
|
|
|
{"msp430x2011", MSP430_ISA_20, bfd_mach_msp20},
|
|
|
|
{"msp430x2002", MSP430_ISA_20, bfd_mach_msp20},
|
|
|
|
{"msp430x2012", MSP430_ISA_20, bfd_mach_msp20},
|
|
|
|
{"msp430x2003", MSP430_ISA_20, bfd_mach_msp20},
|
|
|
|
{"msp430x2013", MSP430_ISA_20, bfd_mach_msp20 },
|
|
|
|
|
2005-08-08 19:08:04 +02:00
|
|
|
{"msp430x2101", MSP430_ISA_21, bfd_mach_msp21},
|
|
|
|
{"msp430x2111", MSP430_ISA_21, bfd_mach_msp21},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430x2112", MSP430_ISA_21, bfd_mach_msp21},
|
2005-08-08 19:08:04 +02:00
|
|
|
{"msp430x2121", MSP430_ISA_21, bfd_mach_msp21},
|
|
|
|
{"msp430x2131", MSP430_ISA_21, bfd_mach_msp21},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430x2132", MSP430_ISA_21, bfd_mach_msp21},
|
|
|
|
|
|
|
|
{"msp430x2232", MSP430_ISA_22, bfd_mach_msp22},
|
|
|
|
{"msp430x2234", MSP430_ISA_22, bfd_mach_msp22},
|
|
|
|
{"msp430x2252", MSP430_ISA_22, bfd_mach_msp22},
|
|
|
|
{"msp430x2254", MSP430_ISA_22, bfd_mach_msp22},
|
|
|
|
{"msp430x2272", MSP430_ISA_22, bfd_mach_msp22},
|
|
|
|
{"msp430x2274", MSP430_ISA_22, bfd_mach_msp22},
|
|
|
|
|
|
|
|
{"msp430x233", MSP430_ISA_23, bfd_mach_msp23},
|
|
|
|
{"msp430x235", MSP430_ISA_23, bfd_mach_msp23},
|
|
|
|
{"msp430x2330", MSP430_ISA_23, bfd_mach_msp23},
|
|
|
|
{"msp430x2350", MSP430_ISA_23, bfd_mach_msp23},
|
|
|
|
{"msp430x2370", MSP430_ISA_23, bfd_mach_msp23},
|
|
|
|
|
|
|
|
{"msp430x247", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x2471", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x248", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x2481", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x249", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x2491", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x2410", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x2416", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x2417", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x2418", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
{"msp430x2419", MSP430_ISA_24, bfd_mach_msp24},
|
|
|
|
|
|
|
|
{"msp430x2616", MSP430_ISA_26, bfd_mach_msp26},
|
|
|
|
{"msp430x2617", MSP430_ISA_26, bfd_mach_msp26},
|
|
|
|
{"msp430x2618", MSP430_ISA_26, bfd_mach_msp26},
|
|
|
|
{"msp430x2619", MSP430_ISA_26, bfd_mach_msp26},
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
{"msp430x311", MSP430_ISA_31, bfd_mach_msp31},
|
|
|
|
{"msp430x312", MSP430_ISA_31, bfd_mach_msp31},
|
|
|
|
{"msp430x313", MSP430_ISA_31, bfd_mach_msp31},
|
|
|
|
{"msp430x314", MSP430_ISA_31, bfd_mach_msp31},
|
|
|
|
{"msp430x315", MSP430_ISA_31, bfd_mach_msp31},
|
|
|
|
{"msp430x323", MSP430_ISA_32, bfd_mach_msp32},
|
|
|
|
{"msp430x325", MSP430_ISA_32, bfd_mach_msp32},
|
|
|
|
{"msp430x336", MSP430_ISA_33, bfd_mach_msp33},
|
|
|
|
{"msp430x337", MSP430_ISA_33, bfd_mach_msp33},
|
|
|
|
|
|
|
|
{"msp430x412", MSP430_ISA_41, bfd_mach_msp41},
|
|
|
|
{"msp430x413", MSP430_ISA_41, bfd_mach_msp41},
|
|
|
|
{"msp430x415", MSP430_ISA_41, bfd_mach_msp41},
|
|
|
|
{"msp430x417", MSP430_ISA_41, bfd_mach_msp41},
|
2003-08-08 12:14:52 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430x423", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430x425", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430x427", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430x4250", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430x4260", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430x4270", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430xG4250",MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430xG4260",MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430xG4270",MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
|
2003-08-08 12:14:52 +02:00
|
|
|
{"msp430xE423", MSP430_ISA_42, bfd_mach_msp42},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430xE4232",MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430xE4242",MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430xE4252",MSP430_ISA_42, bfd_mach_msp42},
|
2003-08-08 12:14:52 +02:00
|
|
|
{"msp430xE425", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430xE427", MSP430_ISA_42, bfd_mach_msp42},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430xE4272",MSP430_ISA_42, bfd_mach_msp42},
|
2004-07-26 14:29:02 +02:00
|
|
|
|
2003-08-08 12:14:52 +02:00
|
|
|
{"msp430xW423", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430xW425", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
{"msp430xW427", MSP430_ISA_42, bfd_mach_msp42},
|
|
|
|
|
2004-07-26 14:29:02 +02:00
|
|
|
{"msp430xG437", MSP430_ISA_43, bfd_mach_msp43},
|
|
|
|
{"msp430xG438", MSP430_ISA_43, bfd_mach_msp43},
|
|
|
|
{"msp430xG439", MSP430_ISA_43, bfd_mach_msp43},
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
{"msp430x435", MSP430_ISA_43, bfd_mach_msp43},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430x4351", MSP430_ISA_43, bfd_mach_msp43},
|
2004-08-25 14:54:15 +02:00
|
|
|
{"msp430x436", MSP430_ISA_43, bfd_mach_msp43},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430x4361", MSP430_ISA_43, bfd_mach_msp43},
|
2004-08-25 14:54:15 +02:00
|
|
|
{"msp430x437", MSP430_ISA_43, bfd_mach_msp43},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430x4371", MSP430_ISA_43, bfd_mach_msp43},
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
{"msp430x447", MSP430_ISA_44, bfd_mach_msp44},
|
|
|
|
{"msp430x448", MSP430_ISA_44, bfd_mach_msp44},
|
|
|
|
{"msp430x449", MSP430_ISA_44, bfd_mach_msp44},
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
{"msp430xG4616",MSP430_ISA_46, bfd_mach_msp46},
|
|
|
|
{"msp430xG4617",MSP430_ISA_46, bfd_mach_msp46},
|
|
|
|
{"msp430xG4618",MSP430_ISA_46, bfd_mach_msp46},
|
|
|
|
{"msp430xG4619",MSP430_ISA_46, bfd_mach_msp46},
|
|
|
|
|
|
|
|
{"msp430x4783", MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x4784", MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x4793", MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x4794", MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x47166",MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x47176",MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x47186",MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x47196",MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x47167",MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x47177",MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x47187",MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
{"msp430x47197",MSP430_ISA_47, bfd_mach_msp47},
|
|
|
|
|
|
|
|
{"msp430x5418", MSP430_ISA_54, bfd_mach_msp54},
|
|
|
|
{"msp430x5419", MSP430_ISA_54, bfd_mach_msp54},
|
|
|
|
{"msp430x5435", MSP430_ISA_54, bfd_mach_msp54},
|
|
|
|
{"msp430x5436", MSP430_ISA_54, bfd_mach_msp54},
|
|
|
|
{"msp430x5437", MSP430_ISA_54, bfd_mach_msp54},
|
|
|
|
{"msp430x5438", MSP430_ISA_54, bfd_mach_msp54},
|
|
|
|
|
|
|
|
{"msp430X", MSP430X_ISA, bfd_mach_msp430x},
|
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
{NULL, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct mcu_type_s default_mcu =
|
|
|
|
{ "msp430x11", MSP430_ISA_11, bfd_mach_msp11 };
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
static struct mcu_type_s * msp430_mcu = & default_mcu;
|
|
|
|
|
|
|
|
/* Profiling capability:
|
|
|
|
It is a performance hit to use gcc's profiling approach for this tiny target.
|
|
|
|
Even more -- jtag hardware facility does not perform any profiling functions.
|
|
|
|
However we've got gdb's built-in simulator where we can do anything.
|
|
|
|
Therefore my suggestion is:
|
|
|
|
|
|
|
|
We define new section ".profiler" which holds all profiling information.
|
|
|
|
We define new pseudo operation .profiler which will instruct assembler to
|
|
|
|
add new profile entry to the object file. Profile should take place at the
|
|
|
|
present address.
|
|
|
|
|
|
|
|
Pseudo-op format:
|
|
|
|
|
|
|
|
.profiler flags,function_to_profile [, cycle_corrector, extra]
|
|
|
|
|
|
|
|
where 'flags' is a combination of the following chars:
|
|
|
|
s - function Start
|
|
|
|
x - function eXit
|
|
|
|
i - function is in Init section
|
|
|
|
f - function is in Fini section
|
|
|
|
l - Library call
|
|
|
|
c - libC standard call
|
|
|
|
d - stack value Demand (saved at run-time in simulator)
|
|
|
|
I - Interrupt service routine
|
|
|
|
P - Prologue start
|
|
|
|
p - Prologue end
|
|
|
|
E - Epilogue start
|
|
|
|
e - Epilogue end
|
|
|
|
j - long Jump/ sjlj unwind
|
|
|
|
a - an Arbitrary code fragment
|
|
|
|
t - exTra parameter saved (constant value like frame size)
|
|
|
|
'""' optional: "sil" == sil
|
|
|
|
|
|
|
|
function_to_profile - function's address
|
|
|
|
cycle_corrector - a value which should be added to the cycle
|
|
|
|
counter, zero if omitted
|
|
|
|
extra - some extra parameter, zero if omitted.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
------------------------------
|
|
|
|
.global fxx
|
|
|
|
.type fxx,@function
|
|
|
|
fxx:
|
|
|
|
.LFrameOffset_fxx=0x08
|
|
|
|
.profiler "scdP", fxx ; function entry.
|
|
|
|
; we also demand stack value to be displayed
|
|
|
|
push r11
|
|
|
|
push r10
|
|
|
|
push r9
|
|
|
|
push r8
|
|
|
|
.profiler "cdp",fxx,0, .LFrameOffset_fxx ; check stack value at this point
|
|
|
|
; (this is a prologue end)
|
2007-10-11 15:48:39 +02:00
|
|
|
; note, that spare var filled with the frame size
|
2004-08-25 14:54:15 +02:00
|
|
|
mov r15,r8
|
|
|
|
....
|
|
|
|
.profiler cdE,fxx ; check stack
|
|
|
|
pop r8
|
|
|
|
pop r9
|
|
|
|
pop r10
|
|
|
|
pop r11
|
|
|
|
.profiler xcde,fxx,3 ; exit adds 3 to the cycle counter
|
|
|
|
ret ; cause 'ret' insn takes 3 cycles
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
This profiling approach does not produce any overhead and
|
|
|
|
absolutely harmless.
|
|
|
|
So, even profiled code can be uploaded to the MCU. */
|
|
|
|
#define MSP430_PROFILER_FLAG_ENTRY 1 /* s */
|
|
|
|
#define MSP430_PROFILER_FLAG_EXIT 2 /* x */
|
|
|
|
#define MSP430_PROFILER_FLAG_INITSECT 4 /* i */
|
|
|
|
#define MSP430_PROFILER_FLAG_FINISECT 8 /* f */
|
|
|
|
#define MSP430_PROFILER_FLAG_LIBCALL 0x10 /* l */
|
|
|
|
#define MSP430_PROFILER_FLAG_STDCALL 0x20 /* c */
|
|
|
|
#define MSP430_PROFILER_FLAG_STACKDMD 0x40 /* d */
|
|
|
|
#define MSP430_PROFILER_FLAG_ISR 0x80 /* I */
|
|
|
|
#define MSP430_PROFILER_FLAG_PROLSTART 0x100 /* P */
|
|
|
|
#define MSP430_PROFILER_FLAG_PROLEND 0x200 /* p */
|
|
|
|
#define MSP430_PROFILER_FLAG_EPISTART 0x400 /* E */
|
|
|
|
#define MSP430_PROFILER_FLAG_EPIEND 0x800 /* e */
|
|
|
|
#define MSP430_PROFILER_FLAG_JUMP 0x1000 /* j */
|
|
|
|
#define MSP430_PROFILER_FLAG_FRAGMENT 0x2000 /* a */
|
|
|
|
#define MSP430_PROFILER_FLAG_EXTRA 0x4000 /* t */
|
|
|
|
#define MSP430_PROFILER_FLAG_notyet 0x8000 /* ? */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
static int
|
|
|
|
pow2value (int y)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
int n = 0;
|
|
|
|
unsigned int x;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
x = y;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (!x)
|
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
for (; x; x = x >> 1)
|
|
|
|
if (x & 1)
|
|
|
|
n++;
|
|
|
|
|
|
|
|
return n == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse ordinary expression. */
|
|
|
|
|
|
|
|
static char *
|
|
|
|
parse_exp (char * s, expressionS * op)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
input_line_pointer = s;
|
|
|
|
expression (op);
|
|
|
|
if (op->X_op == O_absent)
|
|
|
|
as_bad (_("missing operand"));
|
|
|
|
return input_line_pointer;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
/* Delete spaces from s: X ( r 1 2) => X(r12). */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
|
|
|
static void
|
2004-08-25 14:54:15 +02:00
|
|
|
del_spaces (char * s)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
if (ISSPACE (*s))
|
|
|
|
{
|
|
|
|
char *m = s + 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
while (ISSPACE (*m) && *m)
|
|
|
|
m++;
|
|
|
|
memmove (s, m, strlen (m) + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
static inline char *
|
|
|
|
skip_space (char * s)
|
|
|
|
{
|
|
|
|
while (ISSPACE (*s))
|
|
|
|
++s;
|
|
|
|
return s;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
* config/obj-coff.c, config/tc-arm.c, config/tc-bfin.c,
config/tc-cris.c, config/tc-crx.c, config/tc-i386.c,
config/tc-ia64.c, config/tc-maxq.c, config/tc-maxq.h,
config/tc-mips.c, config/tc-msp430.c, config/tc-sh.c,
config/tc-tic4x.c, config/tc-xtensa.c: Fix comment typos.
2006-04-24 00:12:43 +02:00
|
|
|
/* Extract one word from FROM and copy it to TO. Delimiters are ",;\n" */
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
static char *
|
|
|
|
extract_operand (char * from, char * to, int limit)
|
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
/* Drop leading whitespace. */
|
|
|
|
from = skip_space (from);
|
|
|
|
|
|
|
|
while (size < limit && *from)
|
|
|
|
{
|
|
|
|
*(to + size) = *from;
|
|
|
|
if (*from == ',' || *from == ';' || *from == '\n')
|
|
|
|
break;
|
|
|
|
from++;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(to + size) = 0;
|
|
|
|
del_spaces (to);
|
|
|
|
|
|
|
|
from++;
|
|
|
|
|
|
|
|
return from;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
static void
|
|
|
|
msp430_profiler (int dummy ATTRIBUTE_UNUSED)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
char buffer[1024];
|
|
|
|
char f[32];
|
|
|
|
char * str = buffer;
|
|
|
|
char * flags = f;
|
|
|
|
int p_flags = 0;
|
|
|
|
char * halt;
|
|
|
|
int ops = 0;
|
|
|
|
int left;
|
|
|
|
char * s;
|
|
|
|
segT seg;
|
|
|
|
int subseg;
|
|
|
|
char * end = 0;
|
|
|
|
expressionS exp;
|
|
|
|
expressionS exp1;
|
|
|
|
|
|
|
|
s = input_line_pointer;
|
|
|
|
end = input_line_pointer;
|
|
|
|
|
|
|
|
while (*end && *end != '\n')
|
|
|
|
end++;
|
|
|
|
|
|
|
|
while (*s && *s != '\n')
|
|
|
|
{
|
|
|
|
if (*s == ',')
|
|
|
|
ops++;
|
|
|
|
s++;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
left = 3 - ops;
|
|
|
|
|
|
|
|
if (ops < 1)
|
|
|
|
{
|
|
|
|
as_bad (_(".profiler pseudo requires at least two operands."));
|
|
|
|
input_line_pointer = end;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_line_pointer = extract_operand (input_line_pointer, flags, 32);
|
|
|
|
|
|
|
|
while (*flags)
|
|
|
|
{
|
|
|
|
switch (*flags)
|
|
|
|
{
|
|
|
|
case '"':
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_FRAGMENT;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_JUMP;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_PROLSTART;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_PROLEND;
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_EPISTART;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_EPIEND;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_ENTRY;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_EXIT;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_INITSECT;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_FINISECT;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_LIBCALL;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_STDCALL;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_STACKDMD;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_ISR;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
p_flags |= MSP430_PROFILER_FLAG_EXTRA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
as_warn (_("unknown profiling flag - ignored."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
flags++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_flags
|
|
|
|
&& ( ! pow2value (p_flags & ( MSP430_PROFILER_FLAG_ENTRY
|
|
|
|
| MSP430_PROFILER_FLAG_EXIT))
|
|
|
|
|| ! pow2value (p_flags & ( MSP430_PROFILER_FLAG_PROLSTART
|
|
|
|
| MSP430_PROFILER_FLAG_PROLEND
|
|
|
|
| MSP430_PROFILER_FLAG_EPISTART
|
|
|
|
| MSP430_PROFILER_FLAG_EPIEND))
|
|
|
|
|| ! pow2value (p_flags & ( MSP430_PROFILER_FLAG_INITSECT
|
|
|
|
| MSP430_PROFILER_FLAG_FINISECT))))
|
|
|
|
{
|
2007-10-11 15:48:39 +02:00
|
|
|
as_bad (_("ambiguous flags combination - '.profiler' directive ignored."));
|
2004-08-25 14:54:15 +02:00
|
|
|
input_line_pointer = end;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate temp symbol which denotes current location. */
|
2007-10-11 15:48:39 +02:00
|
|
|
if (now_seg == absolute_section) /* Paranoia ? */
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
|
|
|
exp1.X_op = O_constant;
|
|
|
|
exp1.X_add_number = abs_section_offset;
|
2007-10-11 15:48:39 +02:00
|
|
|
as_warn (_("profiling in absolute section?"));
|
2004-08-25 14:54:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exp1.X_op = O_symbol;
|
|
|
|
exp1.X_add_symbol = symbol_temp_new_now ();
|
|
|
|
exp1.X_add_number = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate a symbol which holds flags value. */
|
|
|
|
exp.X_op = O_constant;
|
|
|
|
exp.X_add_number = p_flags;
|
|
|
|
|
|
|
|
/* Save current section. */
|
|
|
|
seg = now_seg;
|
|
|
|
subseg = now_subseg;
|
|
|
|
|
|
|
|
/* Now go to .profiler section. */
|
|
|
|
obj_elf_change_section (".profiler", SHT_PROGBITS, 0, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
/* Save flags. */
|
|
|
|
emit_expr (& exp, 2);
|
|
|
|
|
|
|
|
/* Save label value. */
|
|
|
|
emit_expr (& exp1, 2);
|
|
|
|
|
|
|
|
while (ops--)
|
|
|
|
{
|
|
|
|
/* Now get profiling info. */
|
|
|
|
halt = extract_operand (input_line_pointer, str, 1024);
|
|
|
|
/* Process like ".word xxx" directive. */
|
|
|
|
parse_exp (str, & exp);
|
|
|
|
emit_expr (& exp, 2);
|
|
|
|
input_line_pointer = halt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill the rest with zeros. */
|
|
|
|
exp.X_op = O_constant;
|
|
|
|
exp.X_add_number = 0;
|
|
|
|
while (left--)
|
|
|
|
emit_expr (& exp, 2);
|
|
|
|
|
|
|
|
/* Return to current section. */
|
|
|
|
subseg_set (seg, subseg);
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2004-08-25 14:54:15 +02:00
|
|
|
extract_word (char * from, char * to, int limit)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
|
|
|
char *op_end;
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
/* Drop leading whitespace. */
|
|
|
|
from = skip_space (from);
|
|
|
|
*to = 0;
|
|
|
|
|
|
|
|
/* Find the op code end. */
|
* config/obj-evax.h (S_SET_OTHER, S_SET_TYPE, S_SET_DESC): Don't define.
* config/tc-crx.c (gettrap): Constify arg.
(handle_LoadStor, get_cinv_parameters): Likewise.
(getreg_image): Fix enum warning
(md_assemble): Restore input line char.
* config/tc-hppa.c (tc_gen_reloc): Fix enum warning.
* config/tc-i960.c (mem_fmt): Rename var to fix shadow warning.
* config/tc-sh.c (sh_fdpic): Only define when OBJ_ELF.
(build_Mytes): Fix build failure for non-elf targets.
* config/tc-tic4x.c (tic4x_eval): Restore terminator char.
* config/tc-xtensa.c (xtensa_end_directive): Fix switch enum warning.
* cgen.c (gas_cgen_md_apply_fix): Avoid set but unused warning.
* ecoff.c (add_ecoff_symbol): Likewise.
* itbl-ops.c (append_insns_as_macros): Likewise.
* listing.c (debugging_pseudo): Likewise.
* read.c (s_mri_common, stringer): Likewise.
* config/obj-coff.c (coff_frob_section): Likewise.
* config/tc-alpha.c (emit_ldgp, s_alpha_proc): Likewise.
* config/tc-arm.c (my_get_expression): Likewise.
* config/tc-hppa.c (process_exit, pa_type_args): Likewise.
* config/tc-m32c.c (md_assemble): Likewise.
* config/tc-microblaze.c (md_convert_frag): Likewise.
* config/tc-mips.c (s_change_section): Likewise.
* config/tc-mt.c (mt_fix_adjustable): Likewise.
* config/tc-xtensa.c (xtensa_literal_pseudo): Likewise.
* config/obj-aout.c (obj_aout_frob_symbol): Delete set but otherwise
unused vars.
* config/tc-alpha.c (load_expression): Likewise.
(s_alpha_rdata, s_alpha_section, s_alpha_prologue): Likewise.
* config/tc-arm.c (parse_neon_el_struct_list): Likewise.
* config/tc-avr.c (extract_word): Likewise.
* config/tc-cris.c (cris_get_expression): Likewise.
* config/tc-d30v.c (build_insn, find_format): Likewise.
* config/tc-dlx.c (machine_ip): Likewise.
* config/tc-hppa.c (pa_get_absolute_expression): Likewise.
* config/tc-i370.c (md_assemble): Likewise.
* config/tc-i960.c (brtab_emit): Likewise.
* config/tc-iq2000.c (s_iq2000_ent): Likewise.
* config/tc-m32c.c (md_convert_frag): Likewise.
* config/tc-m68hc11.c (fixup24, build_jump_insn): Likewise.
(md_estimate_size_before_relax, md_apply_fix): Likewise.
* config/tc-m68k.c (md_show_usage): Likewise.
* config/tc-microblaze.c (microblaze_s_lcomm): Likewise.
* config/tc-mips.c (s_mips_end): Likewise.
* config/tc-mmix.c (mmix_byte, mmix_cons): Likewise.
* config/tc-mn10300.c (md_assemble): Likewise.
* config/tc-msp430.c (extract_word): Likewise.
* config/tc-mt.c (md_assemble): Likewise.
* config/tc-or32.c (machine_ip): Likewise.
* config/tc-pj.c (md_apply_fix): Likewise.
* config/tc-s390.c (md_gather_operands): Likewise.
* config/tc-sh.c (sh_cons_align): Likewise.
* config/tc-sparc.c (sparc_cons_align): Likewise.
* config/tc-tic4x.c (tic4x_sect): Likewise.
* config/tc-tic54x.c (tic54x_stringer): Likewise.
* config/tc-vax.c (vip_op): Likewise.
* config/tc-xstormy16.c (xstormy16_cons_fix_new): Likewise.
* config/tc-xtensa.c (md_assemble): Likewise.
(xtensa_fix_short_loop_frags, convert_frag_immed): Likewise.
(xtensa_move_literals): Likewise.
2010-06-28 16:06:57 +02:00
|
|
|
for (op_end = from; *op_end != 0 && is_part_of_name (*op_end);)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
|
|
|
to[size++] = *op_end++;
|
|
|
|
if (size + 1 >= limit)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
to[size] = 0;
|
|
|
|
return op_end;
|
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
#define OPTION_MMCU 'm'
|
2005-08-12 13:54:23 +02:00
|
|
|
#define OPTION_RELAX 'Q'
|
|
|
|
#define OPTION_POLYMORPHS 'P'
|
2013-05-02 23:06:15 +02:00
|
|
|
#define OPTION_LARGE 'l'
|
|
|
|
static bfd_boolean large_model = FALSE;
|
|
|
|
#define OPTION_NO_INTR_NOPS 'N'
|
|
|
|
static bfd_boolean gen_interrupt_nops = TRUE;
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
static void
|
2004-08-25 14:54:15 +02:00
|
|
|
msp430_set_arch (int dummy ATTRIBUTE_UNUSED)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
|
|
|
char *str = (char *) alloca (32); /* 32 for good measure. */
|
|
|
|
|
|
|
|
input_line_pointer = extract_word (input_line_pointer, str, 32);
|
|
|
|
|
|
|
|
md_parse_option (OPTION_MMCU, str);
|
|
|
|
bfd_set_arch_mach (stdoutput, TARGET_ARCH, msp430_mcu->mach);
|
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
static void
|
|
|
|
show_mcu_list (FILE * stream)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fprintf (stream, _("Known MCU names:\n"));
|
|
|
|
|
|
|
|
for (i = 0; mcu_types[i].name; i++)
|
2013-05-02 23:06:15 +02:00
|
|
|
{
|
|
|
|
fprintf (stream, "%13.13s", mcu_types[i].name);
|
|
|
|
if ((i % 6) == 5)
|
|
|
|
fprintf (stream, "\n");
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
fprintf (stream, "\n");
|
|
|
|
}
|
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
int
|
2004-08-25 14:54:15 +02:00
|
|
|
md_parse_option (int c, char * arg)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case OPTION_MMCU:
|
|
|
|
for (i = 0; mcu_types[i].name; ++i)
|
|
|
|
if (strcmp (mcu_types[i].name, arg) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!mcu_types[i].name)
|
|
|
|
{
|
|
|
|
show_mcu_list (stderr);
|
|
|
|
as_fatal (_("unknown MCU: %s\n"), arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msp430_mcu == &default_mcu || msp430_mcu->mach == mcu_types[i].mach)
|
|
|
|
msp430_mcu = &mcu_types[i];
|
2013-05-02 23:06:15 +02:00
|
|
|
else if (msp430_mcu->mach == bfd_mach_msp430x)
|
|
|
|
/* Allow switching to a lesser architecture. */
|
|
|
|
msp430_mcu = mcu_types + i;
|
2002-12-30 20:25:13 +01:00
|
|
|
else
|
|
|
|
as_fatal (_("redefinition of mcu type %s' to %s'"),
|
|
|
|
msp430_mcu->name, mcu_types[i].name);
|
|
|
|
return 1;
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2005-08-12 13:54:23 +02:00
|
|
|
case OPTION_RELAX:
|
2013-05-02 23:06:15 +02:00
|
|
|
msp430_enable_relax = 1;
|
2005-08-12 13:54:23 +02:00
|
|
|
return 1;
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2005-08-12 13:54:23 +02:00
|
|
|
case OPTION_POLYMORPHS:
|
|
|
|
msp430_enable_polys = 1;
|
|
|
|
return 1;
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
case OPTION_LARGE:
|
|
|
|
large_model = TRUE;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case OPTION_NO_INTR_NOPS:
|
|
|
|
gen_interrupt_nops = FALSE;
|
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
const pseudo_typeS md_pseudo_table[] =
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
{"arch", msp430_set_arch, 0},
|
|
|
|
{"profiler", msp430_profiler, 0},
|
|
|
|
{NULL, NULL, 0}
|
|
|
|
};
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
const char *md_shortopts = "m:";
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
struct option md_longopts[] =
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
{"mmcu", required_argument, NULL, OPTION_MMCU},
|
2005-08-12 13:54:23 +02:00
|
|
|
{"mP", no_argument, NULL, OPTION_POLYMORPHS},
|
|
|
|
{"mQ", no_argument, NULL, OPTION_RELAX},
|
2013-05-02 23:06:15 +02:00
|
|
|
{"ml", no_argument, NULL, OPTION_LARGE},
|
|
|
|
{"mN", no_argument, NULL, OPTION_NO_INTR_NOPS},
|
2004-08-25 14:54:15 +02:00
|
|
|
{NULL, no_argument, NULL, 0}
|
|
|
|
};
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
size_t md_longopts_size = sizeof (md_longopts);
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
void
|
|
|
|
md_show_usage (FILE * stream)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
fprintf (stream,
|
|
|
|
_("MSP430 options:\n"
|
2013-05-02 23:06:15 +02:00
|
|
|
" -mmcu=<msp430-name> select microcontroller type\n"));
|
2005-08-12 13:54:23 +02:00
|
|
|
fprintf (stream,
|
|
|
|
_(" -mQ - enable relaxation at assembly time. DANGEROUS!\n"
|
|
|
|
" -mP - enable polymorph instructions\n"));
|
2013-05-02 23:06:15 +02:00
|
|
|
fprintf (stream,
|
|
|
|
_(" -ml - enable large code model\n"));
|
|
|
|
fprintf (stream,
|
|
|
|
_(" -mN - disable generation of NOP after changing interrupts\n"));
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
show_mcu_list (stream);
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
symbolS *
|
|
|
|
md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
return NULL;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2004-08-25 14:54:15 +02:00
|
|
|
extract_cmd (char * from, char * to, int limit)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
while (*from && ! ISSPACE (*from) && *from != '.' && limit > size)
|
|
|
|
{
|
|
|
|
*(to + size) = *from;
|
|
|
|
from++;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(to + size) = 0;
|
|
|
|
|
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2004-08-25 14:54:15 +02:00
|
|
|
md_atof (int type, char * litP, int * sizeP)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2007-10-17 18:45:56 +02:00
|
|
|
return ieee_md_atof (type, litP, sizeP, FALSE);
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-25 14:54:15 +02:00
|
|
|
md_begin (void)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
struct msp430_opcode_s * opcode;
|
2002-12-30 20:25:13 +01:00
|
|
|
msp430_hash = hash_new ();
|
|
|
|
|
|
|
|
for (opcode = msp430_opcodes; opcode->name; opcode++)
|
|
|
|
hash_insert (msp430_hash, opcode->name, (char *) opcode);
|
|
|
|
|
|
|
|
bfd_set_arch_mach (stdoutput, TARGET_ARCH, msp430_mcu->mach);
|
|
|
|
}
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Returns the register number equivalent to the string T.
|
|
|
|
Returns -1 if there is no such register.
|
|
|
|
Skips a leading 'r' or 'R' character if there is one.
|
|
|
|
Handles the register aliases PC and SP. */
|
|
|
|
|
|
|
|
static signed int
|
2004-08-25 14:54:15 +02:00
|
|
|
check_reg (char * t)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
signed int val;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (t == NULL)
|
|
|
|
return -1;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (*t == 'r' || *t == 'R')
|
|
|
|
++t;
|
|
|
|
|
|
|
|
if (strncasecmp (t, "pc", 2) == 0)
|
|
|
|
return 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (strncasecmp (t, "sp", 2) == 0)
|
2004-08-25 14:54:15 +02:00
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (strncasecmp (t, "sr", 2) == 0)
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
if (*t == '0')
|
|
|
|
return 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
val = atoi (t);
|
|
|
|
|
|
|
|
if (val < 1 || val > 15)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
static int
|
|
|
|
msp430_srcoperand (struct msp430_operand_s * op,
|
2013-05-02 23:06:15 +02:00
|
|
|
char * l,
|
|
|
|
int bin,
|
|
|
|
int * imm_op,
|
|
|
|
bfd_boolean allow_20bit_values,
|
|
|
|
bfd_boolean constants_allowed)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
char *__tl = l;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Check if an immediate #VALUE. The hash sign should be only at the beginning! */
|
|
|
|
if (*l == '#')
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
char *h = l;
|
|
|
|
int vshift = -1;
|
|
|
|
int rval = 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Check if there is:
|
|
|
|
llo(x) - least significant 16 bits, x &= 0xffff
|
|
|
|
lhi(x) - x = (x >> 16) & 0xffff,
|
|
|
|
hlo(x) - x = (x >> 32) & 0xffff,
|
|
|
|
hhi(x) - x = (x >> 48) & 0xffff
|
|
|
|
The value _MUST_ be constant expression: #hlo(1231231231). */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
*imm_op = 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (strncasecmp (h, "#llo(", 5) == 0)
|
|
|
|
{
|
|
|
|
vshift = 0;
|
|
|
|
rval = 3;
|
|
|
|
}
|
|
|
|
else if (strncasecmp (h, "#lhi(", 5) == 0)
|
|
|
|
{
|
|
|
|
vshift = 1;
|
|
|
|
rval = 3;
|
|
|
|
}
|
|
|
|
else if (strncasecmp (h, "#hlo(", 5) == 0)
|
|
|
|
{
|
|
|
|
vshift = 2;
|
|
|
|
rval = 3;
|
|
|
|
}
|
|
|
|
else if (strncasecmp (h, "#hhi(", 5) == 0)
|
|
|
|
{
|
|
|
|
vshift = 3;
|
|
|
|
rval = 3;
|
|
|
|
}
|
|
|
|
else if (strncasecmp (h, "#lo(", 4) == 0)
|
|
|
|
{
|
|
|
|
vshift = 0;
|
|
|
|
rval = 2;
|
|
|
|
}
|
|
|
|
else if (strncasecmp (h, "#hi(", 4) == 0)
|
|
|
|
{
|
|
|
|
vshift = 1;
|
|
|
|
rval = 2;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
op->reg = 0; /* Reg PC. */
|
|
|
|
op->am = 3;
|
|
|
|
op->ol = 1; /* Immediate will follow an instruction. */
|
|
|
|
__tl = h + 1 + rval;
|
|
|
|
op->mode = OP_EXP;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
parse_exp (__tl, &(op->exp));
|
|
|
|
if (op->exp.X_op == O_constant)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
int x = op->exp.X_add_number;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (vshift == 0)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
x = x & 0xffff;
|
|
|
|
op->exp.X_add_number = x;
|
|
|
|
}
|
|
|
|
else if (vshift == 1)
|
|
|
|
{
|
|
|
|
x = (x >> 16) & 0xffff;
|
|
|
|
op->exp.X_add_number = x;
|
|
|
|
}
|
|
|
|
else if (vshift > 1)
|
|
|
|
{
|
|
|
|
if (x < 0)
|
|
|
|
op->exp.X_add_number = -1;
|
2002-12-30 20:25:13 +01:00
|
|
|
else
|
2004-08-25 14:54:15 +02:00
|
|
|
op->exp.X_add_number = 0; /* Nothing left. */
|
|
|
|
x = op->exp.X_add_number;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (allow_20bit_values)
|
|
|
|
{
|
|
|
|
if (op->exp.X_add_number > 0xfffff || op->exp.X_add_number < - (0x7ffff))
|
|
|
|
{
|
|
|
|
as_bad (_("value 0x%x out of extended range."), x);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (op->exp.X_add_number > 65535 || op->exp.X_add_number < -32768)
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
|
|
|
as_bad (_("value %d out of range. Use #lo() or #hi()"), x);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Now check constants. */
|
|
|
|
/* Substitute register mode with a constant generator if applicable. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (!allow_20bit_values)
|
|
|
|
x = (short) x; /* Extend sign. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (! constants_allowed)
|
|
|
|
;
|
|
|
|
else if (x == 0)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
op->reg = 3;
|
|
|
|
op->am = 0;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == 1)
|
|
|
|
{
|
|
|
|
op->reg = 3;
|
|
|
|
op->am = 1;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == 2)
|
|
|
|
{
|
|
|
|
op->reg = 3;
|
|
|
|
op->am = 2;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == -1)
|
|
|
|
{
|
|
|
|
op->reg = 3;
|
|
|
|
op->am = 3;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == 4)
|
|
|
|
{
|
|
|
|
#ifdef PUSH_1X_WORKAROUND
|
|
|
|
if (bin == 0x1200)
|
|
|
|
{
|
|
|
|
/* Remove warning as confusing.
|
2009-07-24 13:45:01 +02:00
|
|
|
as_warn (_("Hardware push bug workaround")); */
|
2004-08-25 14:54:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
op->reg = 2;
|
|
|
|
op->am = 2;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (x == 8)
|
|
|
|
{
|
|
|
|
#ifdef PUSH_1X_WORKAROUND
|
|
|
|
if (bin == 0x1200)
|
|
|
|
{
|
|
|
|
/* Remove warning as confusing.
|
2009-07-24 13:45:01 +02:00
|
|
|
as_warn (_("Hardware push bug workaround")); */
|
2004-08-25 14:54:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
op->reg = 2;
|
|
|
|
op->am = 3;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else if (op->exp.X_op == O_symbol)
|
|
|
|
{
|
|
|
|
op->mode = OP_EXP;
|
|
|
|
}
|
|
|
|
else if (op->exp.X_op == O_big)
|
|
|
|
{
|
|
|
|
short x;
|
|
|
|
if (vshift != -1)
|
|
|
|
{
|
|
|
|
op->exp.X_op = O_constant;
|
|
|
|
op->exp.X_add_number = 0xffff & generic_bignum[vshift];
|
|
|
|
x = op->exp.X_add_number;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
as_bad (_
|
|
|
|
("unknown expression in operand %s. use #llo() #lhi() #hlo() #hhi() "),
|
|
|
|
l);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (x == 0)
|
|
|
|
{
|
|
|
|
op->reg = 3;
|
|
|
|
op->am = 0;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == 1)
|
|
|
|
{
|
|
|
|
op->reg = 3;
|
|
|
|
op->am = 1;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == 2)
|
|
|
|
{
|
|
|
|
op->reg = 3;
|
|
|
|
op->am = 2;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == -1)
|
|
|
|
{
|
|
|
|
op->reg = 3;
|
|
|
|
op->am = 3;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == 4)
|
|
|
|
{
|
|
|
|
op->reg = 2;
|
|
|
|
op->am = 2;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
else if (x == 8)
|
|
|
|
{
|
|
|
|
op->reg = 2;
|
|
|
|
op->am = 3;
|
|
|
|
op->ol = 0;
|
|
|
|
op->mode = OP_REG;
|
|
|
|
}
|
|
|
|
}
|
2007-10-11 15:48:39 +02:00
|
|
|
/* Redundant (yet) check. */
|
2004-08-25 14:54:15 +02:00
|
|
|
else if (op->exp.X_op == O_register)
|
|
|
|
as_bad
|
|
|
|
(_("Registers cannot be used within immediate expression [%s]"), l);
|
|
|
|
else
|
|
|
|
as_bad (_("unknown operand %s"), l);
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Check if absolute &VALUE (assume that we can construct something like ((a&b)<<7 + 25). */
|
|
|
|
if (*l == '&')
|
|
|
|
{
|
|
|
|
char *h = l;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
op->reg = 2; /* reg 2 in absolute addr mode. */
|
|
|
|
op->am = 1; /* mode As == 01 bin. */
|
|
|
|
op->ol = 1; /* Immediate value followed by instruction. */
|
|
|
|
__tl = h + 1;
|
|
|
|
parse_exp (__tl, &(op->exp));
|
|
|
|
op->mode = OP_EXP;
|
|
|
|
if (op->exp.X_op == O_constant)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
int x = op->exp.X_add_number;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (allow_20bit_values)
|
|
|
|
{
|
|
|
|
if (x > 0xfffff || x < -(0x7ffff))
|
|
|
|
{
|
|
|
|
as_bad (_("value 0x%x out of extended range."), x);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (x > 65535 || x < -32768)
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
as_bad (_("value out of range: 0x%x"), x);
|
2004-08-25 14:54:15 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else if (op->exp.X_op == O_symbol)
|
|
|
|
;
|
|
|
|
else
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2007-10-11 15:48:39 +02:00
|
|
|
/* Redundant (yet) check. */
|
2004-08-25 14:54:15 +02:00
|
|
|
if (op->exp.X_op == O_register)
|
|
|
|
as_bad
|
|
|
|
(_("Registers cannot be used within absolute expression [%s]"), l);
|
2002-12-30 20:25:13 +01:00
|
|
|
else
|
2004-08-25 14:54:15 +02:00
|
|
|
as_bad (_("unknown expression in operand %s"), l);
|
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Check if indirect register mode @Rn / postincrement @Rn+. */
|
|
|
|
if (*l == '@')
|
|
|
|
{
|
|
|
|
char *t = l;
|
|
|
|
char *m = strchr (l, '+');
|
|
|
|
|
|
|
|
if (t != l)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
as_bad (_("unknown addressing mode %s"), l);
|
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
t++;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if ((op->reg = check_reg (t)) == -1)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
as_bad (_("Bad register name %s"), t);
|
2004-08-25 14:54:15 +02:00
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
op->mode = OP_REG;
|
|
|
|
op->am = m ? 3 : 2;
|
|
|
|
op->ol = 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Check if register indexed X(Rn). */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
char *h = strrchr (l, '(');
|
|
|
|
char *m = strrchr (l, ')');
|
|
|
|
char *t;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
*imm_op = 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (!h)
|
|
|
|
break;
|
|
|
|
if (!m)
|
|
|
|
{
|
|
|
|
as_bad (_("')' required"));
|
|
|
|
return 1;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
t = h;
|
|
|
|
op->am = 1;
|
|
|
|
op->ol = 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Extract a register. */
|
|
|
|
if ((op->reg = check_reg (t + 1)) == -1)
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
|
|
|
as_bad (_
|
|
|
|
("unknown operator %s. Did you mean X(Rn) or #[hl][hl][oi](CONST) ?"),
|
|
|
|
l);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (op->reg == 2)
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
as_bad (_("r2 should not be used in indexed addressing mode"));
|
2004-08-25 14:54:15 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract constant. */
|
|
|
|
__tl = l;
|
|
|
|
*h = 0;
|
|
|
|
op->mode = OP_EXP;
|
|
|
|
parse_exp (__tl, &(op->exp));
|
|
|
|
if (op->exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
int x = op->exp.X_add_number;
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (allow_20bit_values)
|
|
|
|
{
|
|
|
|
if (x > 0xfffff || x < - (0x7ffff))
|
|
|
|
{
|
|
|
|
as_bad (_("value 0x%x out of extended range."), x);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (x > 65535 || x < -32768)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
as_bad (_("value out of range: 0x%x"), x);
|
2004-08-25 14:54:15 +02:00
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
if (x == 0)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
op->mode = OP_REG;
|
|
|
|
op->am = 2;
|
|
|
|
op->ol = 0;
|
|
|
|
return 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else if (op->exp.X_op == O_symbol)
|
|
|
|
;
|
2002-12-30 20:25:13 +01:00
|
|
|
else
|
|
|
|
{
|
2007-10-11 15:48:39 +02:00
|
|
|
/* Redundant (yet) check. */
|
2004-08-25 14:54:15 +02:00
|
|
|
if (op->exp.X_op == O_register)
|
|
|
|
as_bad
|
|
|
|
(_("Registers cannot be used as a prefix of indexed expression [%s]"), l);
|
|
|
|
else
|
|
|
|
as_bad (_("unknown expression in operand %s"), l);
|
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
return 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
while (0);
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Possibly register mode 'mov r1,r2'. */
|
|
|
|
if ((op->reg = check_reg (l)) != -1)
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
op->mode = OP_REG;
|
|
|
|
op->am = 0;
|
|
|
|
op->ol = 0;
|
|
|
|
return 0;
|
2004-08-25 14:54:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Symbolic mode 'mov a, b' == 'mov x(pc), y(pc)'. */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
op->mode = OP_EXP;
|
|
|
|
op->reg = 0; /* PC relative... be careful. */
|
2013-05-02 23:06:15 +02:00
|
|
|
/* An expression starting with a minus sign is a constant, not an address. */
|
|
|
|
op->am = (*l == '-' ? 3 : 1);
|
2004-08-25 14:54:15 +02:00
|
|
|
op->ol = 1;
|
|
|
|
__tl = l;
|
|
|
|
parse_exp (__tl, &(op->exp));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
while (0);
|
|
|
|
|
|
|
|
/* Unreachable. */
|
|
|
|
as_bad (_("unknown addressing mode for operand %s"), l);
|
|
|
|
return 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
static int
|
2013-05-02 23:06:15 +02:00
|
|
|
msp430_dstoperand (struct msp430_operand_s * op,
|
|
|
|
char * l,
|
|
|
|
int bin,
|
|
|
|
bfd_boolean allow_20bit_values,
|
|
|
|
bfd_boolean constants_allowed)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
|
|
|
int dummy;
|
2013-05-02 23:06:15 +02:00
|
|
|
int ret = msp430_srcoperand (op, l, bin, & dummy,
|
|
|
|
allow_20bit_values,
|
|
|
|
constants_allowed);
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (op->am == 2)
|
|
|
|
{
|
|
|
|
char *__tl = "0";
|
|
|
|
|
|
|
|
op->mode = OP_EXP;
|
|
|
|
op->am = 1;
|
|
|
|
op->ol = 1;
|
|
|
|
parse_exp (__tl, &(op->exp));
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
if (op->exp.X_op != O_constant || op->exp.X_add_number != 0)
|
|
|
|
{
|
|
|
|
as_bad (_("Internal bug. Try to use 0(r%d) instead of @r%d"),
|
|
|
|
op->reg, op->reg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op->am > 1)
|
|
|
|
{
|
|
|
|
as_bad (_
|
|
|
|
("this addressing mode is not applicable for destination operand"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Attempt to encode a MOVA instruction with the given operands.
|
|
|
|
Returns the length of the encoded instruction if successful
|
|
|
|
or 0 upon failure. If the encoding fails, an error message
|
|
|
|
will be returned if a pointer is provided. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
try_encode_mova (bfd_boolean imm_op,
|
|
|
|
int bin,
|
|
|
|
struct msp430_operand_s * op1,
|
|
|
|
struct msp430_operand_s * op2,
|
|
|
|
const char ** error_message_return)
|
|
|
|
{
|
|
|
|
short ZEROS = 0;
|
|
|
|
char *frag;
|
|
|
|
int where;
|
|
|
|
|
|
|
|
/* Only a restricted subset of the normal MSP430 addressing modes
|
|
|
|
are supported here, so check for the ones that are allowed. */
|
|
|
|
if (imm_op)
|
|
|
|
{
|
|
|
|
if (op1->mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op2->mode != OP_REG)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("expected register as second argument of %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op1->am == 3)
|
|
|
|
{
|
|
|
|
/* MOVA #imm20, Rdst. */
|
|
|
|
bin |= 0x80 | op2->reg;
|
|
|
|
frag = frag_more (4);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
if (op1->exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bin |= ((op1->exp.X_add_number >> 16) & 0xf) << 8;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
bfd_putl16 (op1->exp.X_add_number & 0xffff, frag + 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
fix_new_exp (frag_now, where, 4, &(op1->exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_ADR_SRC);
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else if (op1->am == 1)
|
|
|
|
{
|
|
|
|
/* MOVA z16(Rsrc), Rdst. */
|
|
|
|
bin |= 0x30 | (op1->reg << 8) | op2->reg;
|
|
|
|
frag = frag_more (4);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
if (op1->exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
if (op1->exp.X_add_number > 0xffff
|
|
|
|
|| op1->exp.X_add_number < -(0x7fff))
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("index value too big for %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bfd_putl16 (op1->exp.X_add_number & 0xffff, frag + 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag + 2);
|
|
|
|
fix_new_exp (frag_now, where + 2, 2, &(op1->exp), FALSE,
|
|
|
|
op1->reg == 0 ?
|
|
|
|
BFD_RELOC_MSP430X_PCR16 :
|
|
|
|
BFD_RELOC_MSP430X_ABS16);
|
|
|
|
}
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("unexpected addressing mode for %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (op1->am == 0)
|
|
|
|
{
|
|
|
|
/* MOVA Rsrc, ... */
|
|
|
|
if (op2->mode == OP_REG)
|
|
|
|
{
|
|
|
|
bin |= 0xc0 | (op1->reg << 8) | op2->reg;
|
|
|
|
frag = frag_more (2);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (op2->am == 1)
|
|
|
|
{
|
|
|
|
if (op2->reg == 2)
|
|
|
|
{
|
|
|
|
/* MOVA Rsrc, &abs20. */
|
|
|
|
bin |= 0x60 | (op1->reg << 8);
|
|
|
|
frag = frag_more (4);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
if (op2->exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bin |= (op2->exp.X_add_number >> 16) & 0xf;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
bfd_putl16 (op2->exp.X_add_number & 0xffff, frag + 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag + 2);
|
|
|
|
fix_new_exp (frag_now, where, 4, &(op2->exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_ADR_DST);
|
|
|
|
}
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MOVA Rsrc, z16(Rdst). */
|
|
|
|
bin |= 0x70 | (op1->reg << 8) | op2->reg;
|
|
|
|
frag = frag_more (4);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
if (op2->exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
if (op2->exp.X_add_number > 0xffff
|
|
|
|
|| op2->exp.X_add_number < -(0x7fff))
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("index value too big for %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bfd_putl16 (op2->exp.X_add_number & 0xffff, frag + 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag + 2);
|
|
|
|
fix_new_exp (frag_now, where + 2, 2, &(op2->exp), FALSE,
|
|
|
|
op2->reg == 0 ?
|
|
|
|
BFD_RELOC_MSP430X_PCR16 :
|
|
|
|
BFD_RELOC_MSP430X_ABS16);
|
|
|
|
}
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("unexpected addressing mode for %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* imm_op == FALSE. */
|
|
|
|
|
|
|
|
if (op1->reg == 2 && op1->am == 1 && op1->mode == OP_EXP)
|
|
|
|
{
|
|
|
|
/* MOVA &abs20, Rdst. */
|
|
|
|
if (op2->mode != OP_REG)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("expected register as second argument of %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op2->reg == 2 || op2->reg == 3)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("constant generator destination register found in %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= 0x20 | op2->reg;
|
|
|
|
frag = frag_more (4);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
if (op1->exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bin |= ((op1->exp.X_add_number >> 16) & 0xf) << 8;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
bfd_putl16 (op1->exp.X_add_number & 0xffff, frag + 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag + 2);
|
|
|
|
fix_new_exp (frag_now, where, 4, &(op1->exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_ADR_SRC);
|
|
|
|
}
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else if (op1->mode == OP_REG)
|
|
|
|
{
|
|
|
|
if (op1->am == 3)
|
|
|
|
{
|
|
|
|
/* MOVA @Rsrc+, Rdst. */
|
|
|
|
if (op2->mode != OP_REG)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("expected register as second argument of %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op2->reg == 2 || op2->reg == 3)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("constant generator destination register found in %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op1->reg == 2 || op1->reg == 3)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("constant generator source register found in %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= 0x10 | (op1->reg << 8) | op2->reg;
|
|
|
|
frag = frag_more (2);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (op1->am == 2)
|
|
|
|
{
|
|
|
|
/* MOVA @Rsrc,Rdst */
|
|
|
|
if (op2->mode != OP_REG)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("expected register as second argument of %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op2->reg == 2 || op2->reg == 3)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("constant generator destination register found in %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op1->reg == 2 || op1->reg == 3)
|
|
|
|
{
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("constant generator source register found in %s");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= (op1->reg << 8) | op2->reg;
|
|
|
|
frag = frag_more (2);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error_message_return != NULL)
|
|
|
|
* error_message_return = _("unexpected addressing mode for %s");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Parse instruction operands.
|
|
|
|
Return binary opcode. */
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
msp430_operands (struct msp430_opcode_s * opcode, char * line)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
int bin = opcode->bin_opcode; /* Opcode mask. */
|
2013-05-02 23:06:15 +02:00
|
|
|
int insn_length = 0;
|
2004-08-25 14:54:15 +02:00
|
|
|
char l1[MAX_OP_LEN], l2[MAX_OP_LEN];
|
|
|
|
char *frag;
|
|
|
|
int where;
|
|
|
|
struct msp430_operand_s op1, op2;
|
|
|
|
int res = 0;
|
|
|
|
static short ZEROS = 0;
|
|
|
|
int byte_op, imm_op;
|
2013-05-02 23:06:15 +02:00
|
|
|
int op_length = 0;
|
|
|
|
int fmt;
|
|
|
|
int extended = 0x1800;
|
|
|
|
bfd_boolean extended_op = FALSE;
|
|
|
|
bfd_boolean addr_op;
|
|
|
|
const char * error_message;
|
|
|
|
static signed int repeat_count = 0;
|
|
|
|
bfd_boolean fix_emitted;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Opcode is the one from opcodes table
|
|
|
|
line contains something like
|
|
|
|
[.w] @r2+, 5(R1)
|
|
|
|
or
|
|
|
|
.b @r2+, 5(R1). */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Check if byte or word operation. */
|
|
|
|
if (*line == '.' && TOLOWER (*(line + 1)) == 'b')
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
bin |= BYTE_OPERATION;
|
|
|
|
byte_op = 1;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else
|
|
|
|
byte_op = 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
/* "Address" ops work on 20-bit values. */
|
|
|
|
if (*line == '.' && TOLOWER (*(line + 1)) == 'a')
|
|
|
|
{
|
|
|
|
addr_op = TRUE;
|
|
|
|
bin |= BYTE_OPERATION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
addr_op = FALSE;
|
|
|
|
|
|
|
|
/* skip .[aAbwBW]. */
|
2004-08-25 14:54:15 +02:00
|
|
|
while (! ISSPACE (*line) && *line)
|
|
|
|
line++;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (opcode->fmt != -1
|
|
|
|
&& opcode->insn_opnumb
|
|
|
|
&& (!*line || *line == '\n'))
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
as_bad (_("instruction %s requires %d operand(s)"),
|
|
|
|
opcode->name, opcode->insn_opnumb);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
memset (l1, 0, sizeof (l1));
|
|
|
|
memset (l2, 0, sizeof (l2));
|
|
|
|
memset (&op1, 0, sizeof (op1));
|
|
|
|
memset (&op2, 0, sizeof (op2));
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
imm_op = 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if ((fmt = opcode->fmt) < 0)
|
|
|
|
{
|
|
|
|
if (msp430_mcu->isa != MSP430X_ISA)
|
|
|
|
{
|
|
|
|
as_bad (_("instruction %s requires MSP430X mcu"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt = (-fmt) - 1;
|
|
|
|
extended_op = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (repeat_count)
|
|
|
|
{
|
|
|
|
/* If requested set the extended instruction repeat count. */
|
|
|
|
if (extended_op)
|
|
|
|
{
|
|
|
|
if (repeat_count > 0)
|
|
|
|
extended |= (repeat_count - 1);
|
|
|
|
else
|
|
|
|
extended |= (1 << 7) | (- repeat_count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
as_bad (_("unable to repeat %s insn"), opcode->name);
|
|
|
|
|
|
|
|
repeat_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fmt)
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
|
|
|
case 0: /* Emulated. */
|
|
|
|
switch (opcode->insn_opnumb)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
case 0:
|
|
|
|
/* Set/clear bits instructions. */
|
2013-05-02 23:06:15 +02:00
|
|
|
if (extended_op)
|
|
|
|
{
|
|
|
|
if (!addr_op)
|
|
|
|
extended |= BYTE_OPERATION;
|
|
|
|
|
|
|
|
/* Emit the extension word. */
|
|
|
|
insn_length += 2;
|
|
|
|
frag = frag_more (insn_length);
|
|
|
|
bfd_putl16 (extended, frag);
|
|
|
|
}
|
|
|
|
insn_length += 2;
|
|
|
|
frag = frag_more (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
if (gen_interrupt_nops
|
|
|
|
&& msp430_mcu->isa == MSP430_ISA_54
|
|
|
|
&& (strcmp (opcode->name, "eint") == 0
|
|
|
|
|| strcmp (opcode->name, "dint") == 0))
|
|
|
|
{
|
|
|
|
/* Emit a NOP following interrupt enable/disable.
|
|
|
|
See 1.3.4.1 of the MSP430x5xx User Guide. */
|
|
|
|
insn_length += 2;
|
|
|
|
frag = frag_more (2);
|
|
|
|
bfd_putl16 ((bfd_vma) 0x4303 /* NOP */, frag);
|
|
|
|
}
|
|
|
|
|
|
|
|
dwarf2_emit_insn (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
break;
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
case 1:
|
|
|
|
/* Something which works with destination operand. */
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
2013-05-02 23:06:15 +02:00
|
|
|
res = msp430_dstoperand (&op1, l1, opcode->bin_opcode, extended_op, TRUE);
|
2004-08-25 14:54:15 +02:00
|
|
|
if (res)
|
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Compute the entire instruction length, in bytes. */
|
|
|
|
insn_length = (extended_op ? 2 : 0) + 2 + (op1.ol * 2);
|
|
|
|
frag = frag_more (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
where = frag - frag_now->fr_literal;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (extended_op)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
if (!addr_op)
|
|
|
|
extended |= BYTE_OPERATION;
|
|
|
|
|
|
|
|
if (op1.ol != 0 && ((extended & 0xf) != 0))
|
|
|
|
{
|
|
|
|
as_bad (_("repeat instruction used with non-register mode instruction"));
|
|
|
|
extended &= ~ 0xf;
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (op1.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
extended |= ((op1.exp.X_add_number >> 16) & 0xf) << 7;
|
|
|
|
|
|
|
|
else if (op1.reg || (op1.reg == 0 && op1.am == 3)) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_EXT_SRC);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_PCR20_EXT_SRC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit the extension word. */
|
|
|
|
bfd_putl16 (extended, frag);
|
|
|
|
frag += 2;
|
|
|
|
where += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= (op1.reg | (op1.am << 7));
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
frag += 2;
|
|
|
|
where += 2;
|
|
|
|
|
|
|
|
if (op1.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bfd_putl16 (op1.exp.X_add_number & 0xffff, frag);
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
else
|
2013-05-02 23:06:15 +02:00
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag);
|
|
|
|
|
|
|
|
if (!extended_op)
|
|
|
|
{
|
|
|
|
if (op1.reg)
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), FALSE, CHECK_RELOC_MSP430);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), TRUE, CHECK_RELOC_MSP430_PCREL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gen_interrupt_nops
|
|
|
|
&& msp430_mcu->isa == MSP430_ISA_54
|
|
|
|
&& strcmp (opcode->name, "clr") == 0
|
|
|
|
&& bin == 0x4302 /* CLR R2*/)
|
|
|
|
{
|
|
|
|
/* Emit a NOP following interrupt enable/disable.
|
|
|
|
See 1.3.4.1 of the MSP430x5xx User Guide. */
|
|
|
|
insn_length += 2;
|
|
|
|
frag = frag_more (2);
|
|
|
|
bfd_putl16 ((bfd_vma) 0x4303 /* NOP */, frag);
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
dwarf2_emit_insn (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
case 2:
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Shift instruction. */
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
strncpy (l2, l1, sizeof (l2));
|
|
|
|
l2[sizeof (l2) - 1] = '\0';
|
|
|
|
res = msp430_srcoperand (&op1, l1, opcode->bin_opcode, &imm_op, extended_op, TRUE);
|
|
|
|
res += msp430_dstoperand (&op2, l2, opcode->bin_opcode, extended_op, TRUE);
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
break; /* An error occurred. All warnings were done before. */
|
|
|
|
|
|
|
|
insn_length = (extended_op ? 2 : 0) + 2 + (op1.ol * 2) + (op2.ol * 2);
|
|
|
|
frag = frag_more (insn_length);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
|
|
|
|
if (extended_op)
|
|
|
|
{
|
|
|
|
if (!addr_op)
|
|
|
|
extended |= BYTE_OPERATION;
|
|
|
|
|
|
|
|
if ((op1.ol != 0 || op2.ol != 0) && ((extended & 0xf) != 0))
|
|
|
|
{
|
|
|
|
as_bad (_("repeat instruction used with non-register mode instruction"));
|
|
|
|
extended &= ~ 0xf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op1.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
extended |= ((op1.exp.X_add_number >> 16) & 0xf) << 7;
|
|
|
|
|
|
|
|
else if (op1.reg || (op1.reg == 0 && op1.am == 3)) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_EXT_SRC);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_PCR20_EXT_SRC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op2.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op2.exp.X_op == O_constant)
|
|
|
|
extended |= (op2.exp.X_add_number >> 16) & 0xf;
|
|
|
|
|
|
|
|
else if (op1.mode == OP_EXP)
|
|
|
|
fix_new_exp (frag_now, where, 8, &(op2.exp), FALSE,
|
|
|
|
op2.reg ? BFD_RELOC_MSP430X_ABS20_EXT_ODST
|
|
|
|
: BFD_RELOC_MSP430X_PCR20_EXT_ODST);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op2.exp), FALSE,
|
|
|
|
op2.reg ? BFD_RELOC_MSP430X_ABS20_EXT_DST
|
|
|
|
: BFD_RELOC_MSP430X_PCR20_EXT_DST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit the extension word. */
|
|
|
|
bfd_putl16 (extended, frag);
|
|
|
|
frag += 2;
|
|
|
|
where += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= (op2.reg | (op1.reg << 8) | (op1.am << 4) | (op2.am << 7));
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
frag += 2;
|
|
|
|
where += 2;
|
|
|
|
|
|
|
|
if (op1.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bfd_putl16 (op1.exp.X_add_number & 0xffff, frag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag);
|
|
|
|
|
|
|
|
if (!extended_op)
|
|
|
|
{
|
|
|
|
if (op1.reg || (op1.reg == 0 && op1.am == 3)) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), FALSE, CHECK_RELOC_MSP430);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), TRUE, CHECK_RELOC_MSP430_PCREL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frag += 2;
|
|
|
|
where += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op2.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op2.exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bfd_putl16 (op2.exp.X_add_number & 0xffff, frag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag);
|
|
|
|
|
|
|
|
if (!extended_op)
|
|
|
|
{
|
|
|
|
if (op2.reg) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op2.exp), FALSE, CHECK_RELOC_MSP430);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op2.exp), TRUE, CHECK_RELOC_MSP430_PCREL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dwarf2_emit_insn (insn_length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
/* Branch instruction => mov dst, r0. */
|
|
|
|
if (extended_op)
|
|
|
|
{
|
|
|
|
as_bad ("Internal error: state 0/3 not coded for extended instructions");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
res = msp430_srcoperand (&op1, l1, opcode->bin_opcode, &imm_op, extended_op, FALSE);
|
|
|
|
if (res)
|
|
|
|
break;
|
|
|
|
|
|
|
|
byte_op = 0;
|
|
|
|
imm_op = 0;
|
|
|
|
bin |= ((op1.reg << 8) | (op1.am << 4));
|
|
|
|
op_length = 2 + 2 * op1.ol;
|
|
|
|
frag = frag_more (op_length);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
|
|
|
|
if (op1.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bfd_putl16 (op1.exp.X_add_number & 0xffff, frag + 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
where += 2;
|
|
|
|
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag + 2);
|
|
|
|
|
|
|
|
if (op1.reg || (op1.reg == 0 && op1.am == 3))
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), FALSE, CHECK_RELOC_MSP430);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), TRUE, CHECK_RELOC_MSP430_PCREL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dwarf2_emit_insn (insn_length + op_length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
/* CALLA instructions. */
|
|
|
|
fix_emitted = FALSE;
|
|
|
|
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
imm_op = 0;
|
|
|
|
|
|
|
|
res = msp430_srcoperand (&op1, l1, opcode->bin_opcode, &imm_op,
|
|
|
|
extended_op, FALSE);
|
|
|
|
if (res)
|
|
|
|
break;
|
|
|
|
|
|
|
|
byte_op = 0;
|
|
|
|
|
|
|
|
op_length = 2 + 2 * op1.ol;
|
|
|
|
frag = frag_more (op_length);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
|
|
|
|
if (imm_op)
|
|
|
|
{
|
|
|
|
if (op1.am == 3)
|
|
|
|
{
|
|
|
|
bin |= 0xb0;
|
|
|
|
|
|
|
|
fix_new_exp (frag_now, where, 4, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_ADR_DST);
|
|
|
|
fix_emitted = TRUE;
|
|
|
|
}
|
|
|
|
else if (op1.am == 1)
|
|
|
|
{
|
|
|
|
if (op1.reg == 0)
|
|
|
|
{
|
|
|
|
bin |= 0x90;
|
|
|
|
|
|
|
|
fix_new_exp (frag_now, where, 4, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_PCR20_CALL);
|
|
|
|
fix_emitted = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bin |= 0x50 | op1.reg;
|
|
|
|
}
|
|
|
|
else if (op1.am == 0)
|
|
|
|
bin |= 0x40 | op1.reg;
|
|
|
|
}
|
|
|
|
else if (op1.am == 1)
|
|
|
|
{
|
|
|
|
bin |= 0x80;
|
|
|
|
|
|
|
|
fix_new_exp (frag_now, where, 4, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_ADR_DST);
|
|
|
|
fix_emitted = TRUE;
|
|
|
|
}
|
|
|
|
else if (op1.am == 2)
|
|
|
|
bin |= 0x60 | op1.reg;
|
|
|
|
else if (op1.am == 3)
|
|
|
|
bin |= 0x70 | op1.reg;
|
|
|
|
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
|
|
|
|
if (op1.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op1.ol != 1)
|
|
|
|
{
|
|
|
|
as_bad ("Internal error: unexpected CALLA instruction length: %d\n", op1.ol);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag + 2);
|
|
|
|
|
|
|
|
if (! fix_emitted)
|
|
|
|
fix_new_exp (frag_now, where + 2, 2,
|
|
|
|
&(op1.exp), FALSE, BFD_RELOC_16);
|
|
|
|
}
|
|
|
|
|
|
|
|
dwarf2_emit_insn (insn_length + op_length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
int n;
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
/* [POP|PUSH]M[.A] #N, Rd */
|
2004-08-25 14:54:15 +02:00
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
2013-05-02 23:06:15 +02:00
|
|
|
line = extract_operand (line, l2, sizeof (l2));
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (*l1 != '#')
|
|
|
|
{
|
|
|
|
as_bad (_("expected #n as first argument of POPM"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
parse_exp (l1 + 1, &(op1.exp));
|
|
|
|
if (op1.exp.X_op != O_constant)
|
|
|
|
{
|
|
|
|
as_bad (_("expected constant expression for first argument of %s"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if ((reg = check_reg (l2)) == -1)
|
|
|
|
{
|
|
|
|
as_bad (_("expected register as second argument of %s"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
op_length = 2;
|
|
|
|
frag = frag_more (op_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
where = frag - frag_now->fr_literal;
|
2013-05-02 23:06:15 +02:00
|
|
|
bin = opcode->bin_opcode;
|
|
|
|
if (! addr_op)
|
|
|
|
bin |= 0x100;
|
|
|
|
n = op1.exp.X_add_number;
|
|
|
|
bin |= (n - 1) << 4;
|
|
|
|
if (strcmp (opcode->name, "pushm") == 0)
|
|
|
|
bin |= reg;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (reg - n + 1 < 0)
|
|
|
|
{
|
|
|
|
as_bad (_("Too many registers popped"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bin |= (reg - n + 1);
|
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
2013-05-02 23:06:15 +02:00
|
|
|
dwarf2_emit_insn (op_length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
/* Bit rotation instructions. RRCM, RRAM, RRUM, RLAM. */
|
|
|
|
if (extended & 0xff)
|
|
|
|
{
|
|
|
|
as_bad (_("repeat count cannot be used with %s"), opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
line = extract_operand (line, l2, sizeof (l2));
|
|
|
|
|
|
|
|
if (*l1 != '#')
|
|
|
|
{
|
|
|
|
as_bad (_("expected #n as first argument of %s"), opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
parse_exp (l1 + 1, &(op1.exp));
|
|
|
|
if (op1.exp.X_op != O_constant)
|
|
|
|
{
|
|
|
|
as_bad (_("expected constant expression for first argument of %s"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
n = op1.exp.X_add_number;
|
|
|
|
if (n > 4 || n < 1)
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
as_bad (_("expected first argument of %s to be in the range 1-4"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if ((reg = check_reg (l2)) == -1)
|
|
|
|
{
|
|
|
|
as_bad (_("expected register as second argument of %s"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
2004-08-25 14:54:15 +02:00
|
|
|
}
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
op_length = 2;
|
|
|
|
frag = frag_more (op_length);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
|
|
|
|
bin = opcode->bin_opcode;
|
|
|
|
if (! addr_op)
|
|
|
|
bin |= 0x10;
|
|
|
|
bin |= (n - 1) << 10;
|
|
|
|
bin |= reg;
|
|
|
|
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
dwarf2_emit_insn (op_length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
/* RRUX: Synthetic unsigned right shift of a register by one bit. */
|
|
|
|
if (extended & 0xff)
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
as_bad (_("repeat count cannot be used with %s"), opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
if ((reg = check_reg (l1)) == -1)
|
|
|
|
{
|
|
|
|
as_bad (_("expected register as argument of %s"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (byte_op)
|
|
|
|
{
|
|
|
|
/* Tricky - there is no single instruction that will do this.
|
|
|
|
Encode as: RRA.B rN { BIC.B #0x80, rN */
|
|
|
|
op_length = 6;
|
|
|
|
frag = frag_more (op_length);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bin = 0x1140 | reg;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
dwarf2_emit_insn (2);
|
|
|
|
bin = 0xc070 | reg;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag + 2);
|
|
|
|
bin = 0x0080;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag + 4);
|
|
|
|
dwarf2_emit_insn (4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Encode as RRUM[.A] rN. */
|
|
|
|
bin = opcode->bin_opcode;
|
|
|
|
if (! addr_op)
|
|
|
|
bin |= 0x10;
|
|
|
|
bin |= reg;
|
|
|
|
op_length = 2;
|
|
|
|
frag = frag_more (op_length);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
dwarf2_emit_insn (op_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
bfd_boolean need_reloc = FALSE;
|
|
|
|
int n;
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
/* ADDA, CMPA and SUBA address instructions. */
|
|
|
|
if (extended & 0xff)
|
|
|
|
{
|
|
|
|
as_bad (_("repeat count cannot be used with %s"), opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
line = extract_operand (line, l2, sizeof (l2));
|
|
|
|
|
|
|
|
bin = opcode->bin_opcode;
|
|
|
|
|
|
|
|
if (*l1 == '#')
|
|
|
|
{
|
|
|
|
parse_exp (l1 + 1, &(op1.exp));
|
|
|
|
|
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
n = op1.exp.X_add_number;
|
|
|
|
if (n > 0xfffff || n < - (0x7ffff))
|
|
|
|
{
|
|
|
|
as_bad (_("expected value of first argument of %s to fit into 20-bits"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= ((n >> 16) & 0xf) << 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = 0;
|
|
|
|
need_reloc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
op_length = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((n = check_reg (l1)) == -1)
|
|
|
|
{
|
|
|
|
as_bad (_("expected register name or constant as first argument of %s"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= (n << 8) | (1 << 6);
|
|
|
|
op_length = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((reg = check_reg (l2)) == -1)
|
|
|
|
{
|
|
|
|
as_bad (_("expected register as second argument of %s"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
frag = frag_more (op_length);
|
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
bin |= reg;
|
|
|
|
if (need_reloc)
|
|
|
|
fix_new_exp (frag_now, where, 4, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_ADR_SRC);
|
|
|
|
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
if (op_length == 4)
|
|
|
|
bfd_putl16 ((bfd_vma) (n & 0xffff), frag + 2);
|
|
|
|
dwarf2_emit_insn (op_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
break;
|
2013-05-02 23:06:15 +02:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
case 9: /* MOVA, BRA, RETA. */
|
2004-08-25 14:54:15 +02:00
|
|
|
imm_op = 0;
|
2013-05-02 23:06:15 +02:00
|
|
|
bin = opcode->bin_opcode;
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (strcmp (opcode->name, "reta") == 0)
|
|
|
|
{
|
|
|
|
/* The RETA instruction does not take any arguments.
|
|
|
|
The implicit first argument is @SP+.
|
|
|
|
The implicit second argument is PC. */
|
|
|
|
op1.mode = OP_REG;
|
|
|
|
op1.am = 3;
|
|
|
|
op1.reg = 1;
|
|
|
|
|
|
|
|
op2.mode = OP_REG;
|
|
|
|
op2.reg = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
res = msp430_srcoperand (&op1, l1, opcode->bin_opcode,
|
|
|
|
&imm_op, extended_op, FALSE);
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (strcmp (opcode->name, "bra") == 0)
|
|
|
|
{
|
|
|
|
/* This is the BRA synthetic instruction.
|
|
|
|
The second argument is always PC. */
|
|
|
|
op2.mode = OP_REG;
|
|
|
|
op2.reg = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line = extract_operand (line, l2, sizeof (l2));
|
|
|
|
res += msp430_dstoperand (&op2, l2, opcode->bin_opcode,
|
|
|
|
extended_op, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
break; /* Error occurred. All warnings were done before. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only a restricted subset of the normal MSP430 addressing modes
|
|
|
|
are supported here, so check for the ones that are allowed. */
|
|
|
|
if ((op_length = try_encode_mova (imm_op, bin, & op1, & op2,
|
|
|
|
& error_message)) == 0)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
as_bad (error_message, opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dwarf2_emit_insn (op_length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10: /* RPT */
|
|
|
|
line = extract_operand (line, l1, sizeof l1);
|
|
|
|
/* The RPT instruction only accepted immediates and registers. */
|
|
|
|
if (*l1 == '#')
|
|
|
|
{
|
|
|
|
parse_exp (l1 + 1, &(op1.exp));
|
|
|
|
if (op1.exp.X_op != O_constant)
|
|
|
|
{
|
|
|
|
as_bad (_("expected constant value as argument to RPT"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (op1.exp.X_add_number < 1
|
|
|
|
|| op1.exp.X_add_number > (1 << 4))
|
|
|
|
{
|
|
|
|
as_bad (_("expected constant in the range 2..16"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We silently accept and ignore a repeat count of 1. */
|
|
|
|
if (op1.exp.X_add_number > 1)
|
|
|
|
repeat_count = op1.exp.X_add_number;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int reg;
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if ((reg = check_reg (l1)) != -1)
|
|
|
|
{
|
|
|
|
if (reg == 0)
|
|
|
|
as_warn (_("PC used as an argument to RPT"));
|
|
|
|
else
|
|
|
|
repeat_count = - reg;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
else
|
2013-05-02 23:06:15 +02:00
|
|
|
{
|
|
|
|
as_bad (_("expected constant or register name as argument to RPT insn"));
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
break;
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
as_bad (_("Illegal emulated instruction "));
|
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
case 1: /* Format 1, double operand. */
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
line = extract_operand (line, l2, sizeof (l2));
|
2013-05-02 23:06:15 +02:00
|
|
|
res = msp430_srcoperand (&op1, l1, opcode->bin_opcode, &imm_op, extended_op, TRUE);
|
|
|
|
res += msp430_dstoperand (&op2, l2, opcode->bin_opcode, extended_op, TRUE);
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (res)
|
|
|
|
break; /* Error occurred. All warnings were done before. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (extended_op
|
|
|
|
&& strcmp (opcode->name, "movx") == 0
|
|
|
|
&& addr_op
|
|
|
|
&& msp430_enable_relax)
|
|
|
|
{
|
|
|
|
/* This is the MOVX.A instruction. See if we can convert
|
|
|
|
it into the MOVA instruction instead. This saves 2 bytes. */
|
|
|
|
if ((op_length = try_encode_mova (imm_op, 0x0000, & op1, & op2,
|
|
|
|
NULL)) != 0)
|
|
|
|
{
|
|
|
|
dwarf2_emit_insn (op_length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the entire length of the instruction in bytes. */
|
|
|
|
insn_length =
|
|
|
|
(extended_op ? 2 : 0) /* The extension word. */
|
|
|
|
+ 2 /* The opcode */
|
|
|
|
+ (2 * op1.ol) /* The first operand. */
|
|
|
|
+ (2 * op2.ol); /* The second operand. */
|
2004-08-25 14:54:15 +02:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
frag = frag_more (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
where = frag - frag_now->fr_literal;
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
if (extended_op)
|
|
|
|
{
|
|
|
|
if (!addr_op)
|
|
|
|
extended |= BYTE_OPERATION;
|
|
|
|
|
|
|
|
if ((op1.ol != 0 || op2.ol != 0) && ((extended & 0xf) != 0))
|
|
|
|
{
|
|
|
|
as_bad (_("repeat instruction used with non-register mode instruction"));
|
|
|
|
extended &= ~ 0xf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If necessary, emit a reloc to update the extension word. */
|
|
|
|
if (op1.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
extended |= ((op1.exp.X_add_number >> 16) & 0xf) << 7;
|
|
|
|
|
|
|
|
else if (op1.reg || (op1.reg == 0 && op1.am == 3)) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_EXT_SRC);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_PCR20_EXT_SRC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op2.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op2.exp.X_op == O_constant)
|
|
|
|
extended |= (op2.exp.X_add_number >> 16) & 0xf;
|
|
|
|
|
|
|
|
else if (op1.mode == OP_EXP)
|
|
|
|
fix_new_exp (frag_now, where, 8, &(op2.exp), FALSE,
|
|
|
|
op2.reg ? BFD_RELOC_MSP430X_ABS20_EXT_ODST
|
|
|
|
: BFD_RELOC_MSP430X_PCR20_EXT_ODST);
|
|
|
|
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op2.exp), FALSE,
|
|
|
|
op2.reg ? BFD_RELOC_MSP430X_ABS20_EXT_DST
|
|
|
|
: BFD_RELOC_MSP430X_PCR20_EXT_DST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit the extension word. */
|
|
|
|
bfd_putl16 (extended, frag);
|
|
|
|
where += 2;
|
|
|
|
frag += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= (op2.reg | (op1.reg << 8) | (op1.am << 4) | (op2.am << 7));
|
2004-08-25 14:54:15 +02:00
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
2013-05-02 23:06:15 +02:00
|
|
|
where += 2;
|
|
|
|
frag += 2;
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
if (op1.mode == OP_EXP)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bfd_putl16 (op1.exp.X_add_number & 0xffff, frag);
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else
|
2013-05-02 23:06:15 +02:00
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag);
|
|
|
|
|
|
|
|
if (!extended_op)
|
|
|
|
{
|
|
|
|
if (op1.reg || (op1.reg == 0 && op1.am == 3)) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), FALSE, CHECK_RELOC_MSP430);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), TRUE, CHECK_RELOC_MSP430_PCREL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
where += 2;
|
|
|
|
frag += 2;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
if (op2.mode == OP_EXP)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
if (op2.exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bfd_putl16 (op2.exp.X_add_number & 0xffff, frag);
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else
|
2013-05-02 23:06:15 +02:00
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag);
|
|
|
|
|
|
|
|
if (!extended_op)
|
|
|
|
{
|
|
|
|
if (op2.reg) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op2.exp), FALSE, CHECK_RELOC_MSP430);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op2.exp), TRUE, CHECK_RELOC_MSP430_PCREL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gen_interrupt_nops
|
|
|
|
&& msp430_mcu->isa == MSP430_ISA_54
|
|
|
|
&& ( (strcmp (opcode->name, "bic") == 0 && bin == 0xc232)
|
|
|
|
|| (strcmp (opcode->name, "bis") == 0 && bin == 0xd232)
|
|
|
|
|| (strcmp (opcode->name, "mov") == 0 && op2.mode == OP_REG && op2.reg == 2)))
|
|
|
|
{
|
|
|
|
/* Emit a NOP following interrupt enable/disable.
|
|
|
|
See 1.3.4.1 of the MSP430x5xx User Guide. */
|
|
|
|
insn_length += 2;
|
|
|
|
frag = frag_more (2);
|
|
|
|
bfd_putl16 ((bfd_vma) 0x4303 /* NOP */, frag);
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
dwarf2_emit_insn (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* Single-operand mostly instr. */
|
|
|
|
if (opcode->insn_opnumb == 0)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
/* reti instruction. */
|
2013-05-02 23:06:15 +02:00
|
|
|
insn_length += 2;
|
2004-08-25 14:54:15 +02:00
|
|
|
frag = frag_more (2);
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
2013-05-02 23:06:15 +02:00
|
|
|
dwarf2_emit_insn (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
2013-05-02 23:06:15 +02:00
|
|
|
res = msp430_srcoperand (&op1, l1, opcode->bin_opcode,
|
|
|
|
&imm_op, extended_op, TRUE);
|
2004-08-25 14:54:15 +02:00
|
|
|
if (res)
|
|
|
|
break; /* Error in operand. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
insn_length = (extended_op ? 2 : 0) + 2 + (op1.ol * 2);
|
|
|
|
frag = frag_more (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
where = frag - frag_now->fr_literal;
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
if (extended_op)
|
|
|
|
{
|
|
|
|
if (strcmp (opcode->name, "swpbx") == 0
|
|
|
|
|| strcmp (opcode->name, "sxtx") == 0)
|
|
|
|
{
|
|
|
|
/* These two instructions use a special
|
|
|
|
encoding of the A/L and B/W bits. */
|
|
|
|
bin &= ~ BYTE_OPERATION;
|
|
|
|
|
|
|
|
if (byte_op)
|
|
|
|
{
|
|
|
|
as_bad (_("%s instruction does not accept a .b suffix"),
|
|
|
|
opcode->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (! addr_op)
|
|
|
|
extended |= BYTE_OPERATION;
|
|
|
|
}
|
|
|
|
else if (! addr_op)
|
|
|
|
extended |= BYTE_OPERATION;
|
|
|
|
|
|
|
|
if (op1.ol != 0 && ((extended & 0xf) != 0))
|
|
|
|
{
|
|
|
|
as_bad (_("repeat instruction used with non-register mode instruction"));
|
|
|
|
extended &= ~ 0xf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op1.mode == OP_EXP)
|
|
|
|
{
|
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
extended |= ((op1.exp.X_add_number >> 16) & 0xf) << 7;
|
|
|
|
|
|
|
|
else if (op1.reg || (op1.reg == 0 && op1.am == 3)) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_ABS20_EXT_SRC);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 6, &(op1.exp), FALSE,
|
|
|
|
BFD_RELOC_MSP430X_PCR20_EXT_SRC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit the extension word. */
|
|
|
|
bfd_putl16 (extended, frag);
|
|
|
|
frag += 2;
|
|
|
|
where += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bin |= op1.reg | (op1.am << 4);
|
2004-08-25 14:54:15 +02:00
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
2013-05-02 23:06:15 +02:00
|
|
|
frag += 2;
|
|
|
|
where += 2;
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
if (op1.mode == OP_EXP)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
if (op1.exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
bfd_putl16 (op1.exp.X_add_number & 0xffff, frag);
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else
|
2013-05-02 23:06:15 +02:00
|
|
|
{
|
|
|
|
bfd_putl16 ((bfd_vma) ZEROS, frag);
|
|
|
|
|
|
|
|
if (!extended_op)
|
|
|
|
{
|
|
|
|
if (op1.reg || (op1.reg == 0 && op1.am == 3)) /* Not PC relative. */
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), FALSE, CHECK_RELOC_MSP430);
|
|
|
|
else
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&(op1.exp), TRUE, CHECK_RELOC_MSP430_PCREL);
|
|
|
|
}
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
dwarf2_emit_insn (insn_length);
|
2004-08-25 14:54:15 +02:00
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
case 3: /* Conditional jumps instructions. */
|
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
/* l1 is a label. */
|
|
|
|
if (l1[0])
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
char *m = l1;
|
|
|
|
expressionS exp;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (*m == '$')
|
|
|
|
m++;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
parse_exp (m, &exp);
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* In order to handle something like:
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
and #0x8000, r5
|
|
|
|
tst r5
|
|
|
|
jz 4 ; skip next 4 bytes
|
|
|
|
inv r5
|
|
|
|
inc r5
|
|
|
|
nop ; will jump here if r5 positive or zero
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
jCOND -n ;assumes jump n bytes backward:
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
mov r5,r6
|
|
|
|
jmp -2
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
is equal to:
|
|
|
|
lab:
|
|
|
|
mov r5,r6
|
|
|
|
jmp lab
|
|
|
|
|
|
|
|
jCOND $n ; jump from PC in either direction. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (exp.X_op == O_constant)
|
|
|
|
{
|
|
|
|
int x = exp.X_add_number;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (x & 1)
|
|
|
|
{
|
|
|
|
as_warn (_("Even number required. Rounded to %d"), x + 1);
|
|
|
|
x++;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if ((*l1 == '$' && x > 0) || x < 0)
|
|
|
|
x -= 2;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
x >>= 1;
|
|
|
|
|
|
|
|
if (x > 512 || x < -511)
|
|
|
|
{
|
|
|
|
as_bad (_("Wrong displacement %d"), x << 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
insn_length += 2;
|
|
|
|
frag = frag_more (2); /* Instr size is 1 word. */
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
bin |= x & 0x3ff;
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
|
|
|
}
|
|
|
|
else if (exp.X_op == O_symbol && *l1 != '$')
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
insn_length += 2;
|
|
|
|
frag = frag_more (2); /* Instr size is 1 word. */
|
2004-08-25 14:54:15 +02:00
|
|
|
where = frag - frag_now->fr_literal;
|
|
|
|
fix_new_exp (frag_now, where, 2,
|
|
|
|
&exp, TRUE, BFD_RELOC_MSP430_10_PCREL);
|
|
|
|
|
|
|
|
bfd_putl16 ((bfd_vma) bin, frag);
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else if (*l1 == '$')
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
as_bad (_("instruction requires label sans '$'"));
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else
|
2013-05-02 23:06:15 +02:00
|
|
|
as_bad (_
|
|
|
|
("instruction requires label or value in range -511:512"));
|
|
|
|
dwarf2_emit_insn (insn_length);
|
2005-09-01 14:41:25 +02:00
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
as_bad (_("instruction requires label"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
case 4: /* Extended jumps. */
|
2005-08-12 13:54:23 +02:00
|
|
|
if (!msp430_enable_polys)
|
|
|
|
{
|
2009-07-24 13:45:01 +02:00
|
|
|
as_bad (_("polymorphs are not enabled. Use -mP option to enable."));
|
2005-08-12 13:54:23 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
if (l1[0])
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
char *m = l1;
|
|
|
|
expressionS exp;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Ignore absolute addressing. make it PC relative anyway. */
|
|
|
|
if (*m == '#' || *m == '$')
|
|
|
|
m++;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
parse_exp (m, & exp);
|
|
|
|
if (exp.X_op == O_symbol)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Relaxation required. */
|
|
|
|
struct rcodes_s rc = msp430_rcodes[opcode->insn_opnumb];
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (msp430_mcu->isa == MSP430X_ISA)
|
|
|
|
rc = msp430x_rcodes[opcode->insn_opnumb];
|
|
|
|
|
|
|
|
/* The parameter to dwarf2_emit_insn is actually the offset to
|
|
|
|
the start of the insn from the fix piece of instruction that
|
|
|
|
was emitted. Since next fragments may have variable size we
|
|
|
|
tie debug info to the beginning of the instruction. */
|
|
|
|
insn_length += 8;
|
2005-09-09 10:46:19 +02:00
|
|
|
frag = frag_more (8);
|
2005-09-01 14:41:25 +02:00
|
|
|
dwarf2_emit_insn (0);
|
2005-09-09 10:46:19 +02:00
|
|
|
bfd_putl16 ((bfd_vma) rc.sop, frag);
|
|
|
|
frag = frag_variant (rs_machine_dependent, 8, 2,
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Wild guess. */
|
|
|
|
ENCODE_RELAX (rc.lpos, STATE_BITS10),
|
2004-08-25 14:54:15 +02:00
|
|
|
exp.X_add_symbol,
|
|
|
|
0, /* Offset is zero if jump dist less than 1K. */
|
|
|
|
(char *) frag);
|
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
|
|
|
|
as_bad (_("instruction requires label"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5: /* Emulated extended branches. */
|
2005-08-12 13:54:23 +02:00
|
|
|
if (!msp430_enable_polys)
|
|
|
|
{
|
2009-07-24 13:45:01 +02:00
|
|
|
as_bad (_("polymorphs are not enabled. Use -mP option to enable."));
|
2005-08-12 13:54:23 +02:00
|
|
|
break;
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
line = extract_operand (line, l1, sizeof (l1));
|
|
|
|
if (l1[0])
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
char * m = l1;
|
|
|
|
expressionS exp;
|
|
|
|
|
|
|
|
/* Ignore absolute addressing. make it PC relative anyway. */
|
|
|
|
if (*m == '#' || *m == '$')
|
|
|
|
m++;
|
|
|
|
|
|
|
|
parse_exp (m, & exp);
|
|
|
|
if (exp.X_op == O_symbol)
|
|
|
|
{
|
|
|
|
/* Relaxation required. */
|
|
|
|
struct hcodes_s hc = msp430_hcodes[opcode->insn_opnumb];
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (msp430_mcu->isa == MSP430X_ISA)
|
|
|
|
hc = msp430x_hcodes[opcode->insn_opnumb];
|
|
|
|
|
|
|
|
insn_length += 8;
|
2005-09-09 10:46:19 +02:00
|
|
|
frag = frag_more (8);
|
2005-09-01 14:41:25 +02:00
|
|
|
dwarf2_emit_insn (0);
|
2005-09-09 10:46:19 +02:00
|
|
|
bfd_putl16 ((bfd_vma) hc.op0, frag);
|
|
|
|
bfd_putl16 ((bfd_vma) hc.op1, frag+2);
|
|
|
|
|
|
|
|
frag = frag_variant (rs_machine_dependent, 8, 2,
|
2004-08-25 14:54:15 +02:00
|
|
|
ENCODE_RELAX (STATE_EMUL_BRANCH, STATE_BITS10), /* Wild guess. */
|
|
|
|
exp.X_add_symbol,
|
|
|
|
0, /* Offset is zero if jump dist less than 1K. */
|
|
|
|
(char *) frag);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
as_bad (_("instruction requires label"));
|
|
|
|
break;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
default:
|
2007-10-11 15:48:39 +02:00
|
|
|
as_bad (_("Illegal instruction or not implemented opcode."));
|
2004-08-25 14:54:15 +02:00
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
input_line_pointer = line;
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
void
|
|
|
|
md_assemble (char * str)
|
|
|
|
{
|
|
|
|
struct msp430_opcode_s * opcode;
|
|
|
|
char cmd[32];
|
|
|
|
unsigned int i = 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
str = skip_space (str); /* Skip leading spaces. */
|
|
|
|
str = extract_cmd (str, cmd, sizeof (cmd));
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
while (cmd[i] && i < sizeof (cmd))
|
|
|
|
{
|
|
|
|
char a = TOLOWER (cmd[i]);
|
|
|
|
cmd[i] = a;
|
|
|
|
i++;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (!cmd[0])
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
as_bad (_("can't find opcode "));
|
|
|
|
return;
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
opcode = (struct msp430_opcode_s *) hash_find (msp430_hash, cmd);
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (opcode == NULL)
|
|
|
|
{
|
|
|
|
as_bad (_("unknown opcode `%s'"), cmd);
|
|
|
|
return;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
{
|
|
|
|
char *__t = input_line_pointer;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
msp430_operands (opcode, str);
|
|
|
|
input_line_pointer = __t;
|
|
|
|
}
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
|
|
|
/* 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
|
2004-08-25 14:54:15 +02:00
|
|
|
md_section_align (asection * seg, valueT addr)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
|
|
|
int align = bfd_get_section_alignment (stdoutput, seg);
|
|
|
|
|
|
|
|
return ((addr + (1 << align) - 1) & (-1 << align));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If you define this macro, it should return the offset between the
|
|
|
|
address of a PC relative fixup and the position from which the PC
|
|
|
|
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
|
2004-08-25 14:54:15 +02:00
|
|
|
md_pcrel_from_section (fixS * fixp, segT sec)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-08-12 13:54:23 +02:00
|
|
|
/* Replaces standard TC_FORCE_RELOCATION_LOCAL.
|
|
|
|
Now it handles the situation when relocations
|
2013-05-02 23:06:15 +02:00
|
|
|
have to be passed to linker. */
|
2005-08-12 13:54:23 +02:00
|
|
|
int
|
2013-05-02 23:06:15 +02:00
|
|
|
msp430_force_relocation_local (fixS *fixp)
|
2005-08-12 13:54:23 +02:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
if (fixp->fx_r_type == BFD_RELOC_MSP430_10_PCREL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (fixp->fx_pcrel)
|
|
|
|
return 1;
|
|
|
|
|
2005-08-12 13:54:23 +02:00
|
|
|
if (msp430_enable_polys
|
|
|
|
&& !msp430_enable_relax)
|
|
|
|
return 1;
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
return (!fixp->fx_pcrel
|
|
|
|
|| generic_force_reloc (fixp));
|
2005-08-12 13:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
/* GAS will call this for each fixup. It should store the correct
|
|
|
|
value in the object file. */
|
|
|
|
void
|
gas:
* cgen.c, cgen.h, tc.h, write.c, config/obj-coff.c
* config/tc-a29k.c, config/tc-alpha.c, config/tc-alpha.h
* config/tc-arc.c, config/tc-arc.h, config/tc-arm.c
* config/tc-arm.h, config/tc-avr.c, config/tc-avr.h
* config/tc-cris.c, config/tc-crx.c, config/tc-d10v.c
* config/tc-d10v.h, config/tc-d30v.c, config/tc-d30v.h
* config/tc-dlx.c, config/tc-dlx.h, config/tc-fr30.h
* config/tc-frv.c, config/tc-frv.h, config/tc-h8300.c
* config/tc-h8500.c, config/tc-hppa.c, config/tc-hppa.h
* config/tc-i370.c, config/tc-i370.h, config/tc-i386.c
* config/tc-i386.h, config/tc-i860.c, config/tc-i860.h
* config/tc-i960.c, config/tc-i960.h, config/tc-ia64.c
* config/tc-ip2k.c, config/tc-ip2k.h, config/tc-iq2000.c
* config/tc-iq2000.h, config/tc-m32r.c, config/tc-m32r.h
* config/tc-m68hc11.c, config/tc-m68hc11.h, config/tc-m68k.c
* config/tc-m68k.h, config/tc-m88k.c, config/tc-maxq.c
* config/tc-mcore.c, config/tc-mcore.h, config/tc-mips.c
* config/tc-mips.h, config/tc-mmix.c, config/tc-mn10200.c
* config/tc-mn10300.c, config/tc-msp430.c, config/tc-ns32k.c
* config/tc-openrisc.h, config/tc-or32.c, config/tc-or32.h
* config/tc-pdp11.c, config/tc-pj.c, config/tc-pj.h
* config/tc-ppc.c, config/tc-ppc.h, config/tc-s390.c
* config/tc-s390.h, config/tc-sh64.c, config/tc-sh.c
* config/tc-sh.h, config/tc-sparc.c, config/tc-sparc.h
* config/tc-tahoe.c, config/tc-tic30.c, config/tc-tic4x.c
* config/tc-tic54x.c, config/tc-tic80.c, config/tc-v850.c
* config/tc-v850.h, config/tc-vax.c, config/tc-vax.h
* config/tc-w65.c, config/tc-xstormy16.c, config/tc-xstormy16.h
* config/tc-xtensa.c, config/tc-z8k.c:
Replace all instances of the string "_apply_fix3" with
"_apply_fix".
* po/POTFILES.in, po/gas.pot: Regenerate.
bfd:
* coff-i386.c: Change md_apply_fix3 to md_apply_fix in comment.
cgen:
* doc/porting.texi: Change all mention of md_apply_fix3 and
gas_cgen_md_apply_fix3 to md_apply_fix and gas_cgen_md_apply_fix
respectively.
2005-06-07 19:54:22 +02:00
|
|
|
md_apply_fix (fixS * fixp, valueT * valuep, segT seg)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
unsigned char * where;
|
2002-12-30 20:25:13 +01:00
|
|
|
unsigned long insn;
|
|
|
|
long value;
|
|
|
|
|
|
|
|
if (fixp->fx_addsy == (symbolS *) NULL)
|
|
|
|
{
|
|
|
|
value = *valuep;
|
|
|
|
fixp->fx_done = 1;
|
|
|
|
}
|
|
|
|
else if (fixp->fx_pcrel)
|
|
|
|
{
|
|
|
|
segT s = S_GET_SEGMENT (fixp->fx_addsy);
|
|
|
|
|
|
|
|
if (fixp->fx_addsy && (s == seg || s == absolute_section))
|
|
|
|
{
|
2005-01-04 11:20:36 +01:00
|
|
|
/* FIXME: We can appear here only in case if we perform a pc
|
|
|
|
relative jump to the label which is i) global, ii) locally
|
|
|
|
defined or this is a jump to an absolute symbol.
|
|
|
|
If this is an absolute symbol -- everything is OK.
|
|
|
|
If this is a global label, we've got a symbol value defined
|
|
|
|
twice:
|
|
|
|
1. S_GET_VALUE (fixp->fx_addsy) will contain a symbol offset
|
|
|
|
from this section start
|
|
|
|
2. *valuep will contain the real offset from jump insn to the
|
|
|
|
label
|
|
|
|
So, the result of S_GET_VALUE (fixp->fx_addsy) + (* valuep);
|
|
|
|
will be incorrect. Therefore remove s_get_value. */
|
|
|
|
value = /* S_GET_VALUE (fixp->fx_addsy) + */ * valuep;
|
2002-12-30 20:25:13 +01:00
|
|
|
fixp->fx_done = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value = *valuep;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = fixp->fx_offset;
|
|
|
|
|
|
|
|
if (fixp->fx_subsy != (symbolS *) NULL)
|
|
|
|
{
|
|
|
|
if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
|
|
|
|
{
|
|
|
|
value -= S_GET_VALUE (fixp->fx_subsy);
|
|
|
|
fixp->fx_done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-12 13:54:23 +02:00
|
|
|
fixp->fx_no_overflow = 1;
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
/* If polymorphs are enabled and relax disabled.
|
|
|
|
do not kill any relocs and pass them to linker. */
|
|
|
|
if (msp430_enable_polys
|
2005-08-12 13:54:23 +02:00
|
|
|
&& !msp430_enable_relax)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
if (!fixp->fx_addsy || (fixp->fx_addsy
|
2005-08-12 13:54:23 +02:00
|
|
|
&& S_GET_SEGMENT (fixp->fx_addsy) == absolute_section))
|
2007-10-11 15:48:39 +02:00
|
|
|
fixp->fx_done = 1; /* It is ok to kill 'abs' reloc. */
|
2005-08-12 13:54:23 +02:00
|
|
|
else
|
|
|
|
fixp->fx_done = 0;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fixp->fx_done)
|
|
|
|
{
|
|
|
|
/* Fetch the instruction, insert the fully resolved operand
|
2003-09-17 13:27:39 +02:00
|
|
|
value, and stuff the instruction back again. */
|
2005-02-23 13:28:06 +01:00
|
|
|
where = (unsigned char *) fixp->fx_frag->fr_literal + fixp->fx_where;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
|
|
|
insn = bfd_getl16 (where);
|
|
|
|
|
|
|
|
switch (fixp->fx_r_type)
|
|
|
|
{
|
|
|
|
case BFD_RELOC_MSP430_10_PCREL:
|
|
|
|
if (value & 1)
|
|
|
|
as_bad_where (fixp->fx_file, fixp->fx_line,
|
|
|
|
_("odd address operand: %ld"), value);
|
|
|
|
|
|
|
|
/* Jumps are in words. */
|
|
|
|
value >>= 1;
|
|
|
|
--value; /* Correct PC. */
|
|
|
|
|
|
|
|
if (value < -512 || value > 511)
|
|
|
|
as_bad_where (fixp->fx_file, fixp->fx_line,
|
|
|
|
_("operand out of range: %ld"), value);
|
|
|
|
|
|
|
|
value &= 0x3ff; /* get rid of extended sign */
|
|
|
|
bfd_putl16 ((bfd_vma) (value | insn), where);
|
|
|
|
break;
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
case BFD_RELOC_MSP430X_PCR16:
|
2004-08-25 14:54:15 +02:00
|
|
|
case BFD_RELOC_MSP430_RL_PCREL:
|
2002-12-30 20:25:13 +01:00
|
|
|
case BFD_RELOC_MSP430_16_PCREL:
|
|
|
|
if (value & 1)
|
|
|
|
as_bad_where (fixp->fx_file, fixp->fx_line,
|
|
|
|
_("odd address operand: %ld"), value);
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Fall through. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
|
|
|
case BFD_RELOC_MSP430_16_PCREL_BYTE:
|
|
|
|
/* Nothing to be corrected here. */
|
|
|
|
if (value < -32768 || value > 65536)
|
|
|
|
as_bad_where (fixp->fx_file, fixp->fx_line,
|
|
|
|
_("operand out of range: %ld"), value);
|
2013-05-02 23:06:15 +02:00
|
|
|
/* Fall through. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
case BFD_RELOC_MSP430X_ABS16:
|
|
|
|
case BFD_RELOC_MSP430_16:
|
|
|
|
case BFD_RELOC_16:
|
|
|
|
case BFD_RELOC_MSP430_16_BYTE:
|
2002-12-30 20:25:13 +01:00
|
|
|
value &= 0xffff; /* Get rid of extended sign. */
|
|
|
|
bfd_putl16 ((bfd_vma) value, where);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_32:
|
|
|
|
bfd_putl16 ((bfd_vma) value, where);
|
|
|
|
break;
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
case BFD_RELOC_MSP430_ABS8:
|
|
|
|
case BFD_RELOC_8:
|
|
|
|
bfd_put_8 (NULL, (bfd_vma) value, where);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_MSP430X_ABS20_EXT_SRC:
|
|
|
|
case BFD_RELOC_MSP430X_PCR20_EXT_SRC:
|
|
|
|
bfd_putl16 ((bfd_vma) (value & 0xffff), where + 4);
|
|
|
|
value >>= 16;
|
|
|
|
bfd_putl16 ((bfd_vma) (((value & 0xf) << 7) | insn), where);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_MSP430X_ABS20_ADR_SRC:
|
|
|
|
bfd_putl16 ((bfd_vma) (value & 0xffff), where + 2);
|
|
|
|
value >>= 16;
|
|
|
|
bfd_putl16 ((bfd_vma) (((value & 0xf) << 8) | insn), where);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_MSP430X_ABS20_EXT_ODST:
|
|
|
|
bfd_putl16 ((bfd_vma) (value & 0xffff), where + 6);
|
|
|
|
value >>= 16;
|
|
|
|
bfd_putl16 ((bfd_vma) ((value & 0xf) | insn), where);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_MSP430X_PCR20_CALL:
|
|
|
|
bfd_putl16 ((bfd_vma) (value & 0xffff), where + 2);
|
|
|
|
value >>= 16;
|
|
|
|
bfd_putl16 ((bfd_vma) ((value & 0xf) | insn), where);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_MSP430X_ABS20_EXT_DST:
|
|
|
|
case BFD_RELOC_MSP430X_PCR20_EXT_DST:
|
|
|
|
bfd_putl16 ((bfd_vma) (value & 0xffff), where + 4);
|
|
|
|
value >>= 16;
|
|
|
|
bfd_putl16 ((bfd_vma) ((value & 0xf) | insn), where);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_MSP430X_PCR20_EXT_ODST:
|
|
|
|
bfd_putl16 ((bfd_vma) (value & 0xffff), where + 6);
|
|
|
|
value >>= 16;
|
|
|
|
bfd_putl16 ((bfd_vma) ((value & 0xf) | insn), where);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_MSP430X_ABS20_ADR_DST:
|
|
|
|
bfd_putl16 ((bfd_vma) (value & 0xffff), where + 2);
|
|
|
|
value >>= 16;
|
|
|
|
bfd_putl16 ((bfd_vma) ((value & 0xf) | insn), where);
|
2002-12-30 20:25:13 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
as_fatal (_("line %d: unknown relocation type: 0x%x"),
|
|
|
|
fixp->fx_line, fixp->fx_r_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fixp->fx_addnumber = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
static bfd_boolean
|
|
|
|
S_IS_GAS_LOCAL (symbolS * s)
|
|
|
|
{
|
|
|
|
const char * name;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
return FALSE;
|
|
|
|
name = S_GET_NAME (s);
|
|
|
|
len = strlen (name) - 1;
|
|
|
|
|
|
|
|
return name[len] == 1 || name[len] == 2;
|
|
|
|
}
|
|
|
|
|
* README-vms: Delete.
* config-gas.com: Delete.
* makefile.vms: Delete.
* vmsconf.sh: Delete.
* config/atof-tahoe.c: Delete.
* config/m88k-opcode.h: Delete.
* config/obj-bout.c: Delete.
* config/obj-bout.h: Delete.
* config/obj-hp300.c: Delete.
* config/obj-hp300.h: Delete.
* config/tc-a29k.c: Delete.
* config/tc-a29k.h: Delete.
* config/tc-h8500.c: Delete.
* config/tc-h8500.h: Delete.
* config/tc-m88k.c: Delete.
* config/tc-m88k.h: Delete.
* config/tc-tahoe.c: Delete.
* config/tc-tahoe.h: Delete.
* config/tc-tic80.c: Delete.
* config/tc-tic80.h: Delete.
* config/tc-w65.c: Delete.
* config/tc-w65.h: Delete.
* config/te-aux.h: Delete.
* config/te-delt88.h: Delete.
* config/te-delta.h: Delete.
* config/te-dpx2.h: Delete.
* config/te-hp300.h: Delete.
* config/te-ic960.h: Delete.
* config/vms-a-conf.h: Delete.
* doc/c-a29k.texi: Delete.
* doc/c-h8500.texi: Delete.
* doc/c-m88k.texi: Delete.
* README: Remove obsolete examples, and list of supported targets.
* Makefile.am: Remove a29k, h8500, m88k, tahoe, tic80, w65,
bout and hp300 support.
(DEP_FLAGS): Don't define BFD_ASSEMBLER.
* configure.in: Remove --enable-bfd-assembler, need_bfd,
primary_bfd_gas.
* configure.tgt: Remove a29k, h8300-coff, h8500-*, i960 non-elf,
m68k non bfd, m88k, or32-coff, tic80-*, vax non-bfd, w65k-*, *-nindy.
* as.c: Remove all non-BFD_ASSEMBLER code, support for above targets.
* as.h: Likewise.
* dw2gencfi.c: Likewise.
* dwarf2dbg.c: Likewise.
* ehopt.c: Likewise.
* input-file.c: Likewise.
* listing.c: Likewise.
* literal.c: Likewise.
* messages.c: Likewise.
* obj.h: Likewise.
* output-file.c: Likewise.
* read.c: Likewise.
* stabs.c: Likewise.
* struc-symbol.h: Likewise.
* subsegs.c: Likewise.
* subsegs.h: Likewise.
* symbols.c: Likewise.
* symbols.h: Likewise.
* tc.h: Likewise.
* write.c: Likewise.
* write.h: Likewise.
* config/aout_gnu.h: Likewise.
* config/obj-aout.c: Likewise.
* config/obj-aout.h: Likewise.
* config/obj-coff.c: Likewise.
* config/obj-coff.h: Likewise.
* config/obj-evax.h: Likewise.
* config/obj-ieee.h: Likewise.
* config/tc-arm.c: Likewise.
* config/tc-arm.h: Likewise.
* config/tc-avr.c: Likewise.
* config/tc-avr.h: Likewise.
* config/tc-crx.h: Likewise.
* config/tc-d10v.h: Likewise.
* config/tc-d30v.h: Likewise.
* config/tc-dlx.h: Likewise.
* config/tc-fr30.h: Likewise.
* config/tc-frv.h: Likewise.
* config/tc-h8300.c: Likewise.
* config/tc-h8300.h: Likewise.
* config/tc-hppa.h: Likewise.
* config/tc-i370.h: Likewise.
* config/tc-i386.c: Likewise.
* config/tc-i386.h: Likewise.
* config/tc-i860.h: Likewise.
* config/tc-i960.c: Likewise.
* config/tc-i960.h: Likewise.
* config/tc-ip2k.h: Likewise.
* config/tc-iq2000.h: Likewise.
* config/tc-m32c.h: Likewise.
* config/tc-m32r.h: Likewise.
* config/tc-m68hc11.h: Likewise.
* config/tc-m68k.c: Likewise.
* config/tc-m68k.h: Likewise.
* config/tc-maxq.c: Likewise.
* config/tc-maxq.h: Likewise.
* config/tc-mcore.c: Likewise.
* config/tc-mcore.h: Likewise.
* config/tc-mn10200.h: Likewise.
* config/tc-mn10300.c: Likewise.
* config/tc-mn10300.h: Likewise.
* config/tc-ms1.h: Likewise.
* config/tc-msp430.c: Likewise.
* config/tc-msp430.h: Likewise.
* config/tc-ns32k.c: Likewise.
* config/tc-ns32k.h: Likewise.
* config/tc-openrisc.h: Likewise.
* config/tc-or32.c: Likewise.
* config/tc-or32.h: Likewise.
* config/tc-ppc.c: Likewise.
* config/tc-ppc.h: Likewise.
* config/tc-s390.h: Likewise.
* config/tc-sh.c: Likewise.
* config/tc-sh.h: Likewise.
* config/tc-sparc.c: Likewise.
* config/tc-tic30.c: Likewise.
* config/tc-tic30.h: Likewise.
* config/tc-tic4x.c: Likewise.
* config/tc-tic4x.h: Likewise.
* config/tc-tic54x.c: Likewise.
* config/tc-tic54x.h: Likewise.
* config/tc-v850.h: Likewise.
* config/tc-vax.c: Likewise.
* config/tc-vax.h: Likewise.
* config/tc-xstormy16.h: Likewise.
* config/tc-xtensa.h: Likewise.
* config/tc-z8k.c: Likewise.
* config/tc-z8k.h: Likewise.
* config/vms-a-conf.h
* doc/Makefile.am: Likewise.
* doc/all.texi: Likewise.
* doc/as.texinfo: Likewise.
* doc/Makefile.in: Regenerate.
* Makefile.in: Regenerate.
* configure: Regenerate.
* config.in: Regenerate.
* po/POTFILES.in: Regenerate.
2005-08-11 03:25:29 +02:00
|
|
|
/* GAS will call this to generate a reloc, passing 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'. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
|
|
|
/* If while processing a fixup, a reloc really needs to be created
|
|
|
|
then it is done here. */
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
arelent **
|
2004-08-25 14:54:15 +02:00
|
|
|
tc_gen_reloc (asection * seg ATTRIBUTE_UNUSED, fixS * fixp)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2013-05-02 23:06:15 +02:00
|
|
|
static arelent * no_relocs = NULL;
|
|
|
|
static arelent * relocs[MAX_RELOC_EXPANSION + 1];
|
|
|
|
arelent *reloc;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
reloc = xmalloc (sizeof (arelent));
|
2002-12-30 20:25:13 +01:00
|
|
|
reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
|
|
|
|
reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2002-12-30 20:25:13 +01:00
|
|
|
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);
|
2013-05-02 23:06:15 +02:00
|
|
|
free (reloc);
|
|
|
|
return & no_relocs;
|
|
|
|
}
|
|
|
|
|
|
|
|
relocs[0] = reloc;
|
|
|
|
relocs[1] = NULL;
|
|
|
|
|
|
|
|
if (fixp->fx_subsy
|
|
|
|
&& S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
|
|
|
|
{
|
|
|
|
fixp->fx_offset -= S_GET_VALUE (fixp->fx_subsy);
|
|
|
|
fixp->fx_subsy = NULL;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
if (fixp->fx_addsy && fixp->fx_subsy)
|
|
|
|
{
|
|
|
|
asection *asec, *ssec;
|
|
|
|
|
|
|
|
asec = S_GET_SEGMENT (fixp->fx_addsy);
|
|
|
|
ssec = S_GET_SEGMENT (fixp->fx_subsy);
|
|
|
|
|
|
|
|
/* If we have a difference between two different, non-absolute symbols
|
|
|
|
we must generate two relocs (one for each symbol) and allow the
|
|
|
|
linker to resolve them - relaxation may change the distances between
|
|
|
|
symbols, even local symbols defined in the same section.
|
|
|
|
|
|
|
|
Unfortunately we cannot do this with assembler generated local labels
|
|
|
|
because there can be multiple incarnations of the same label, with
|
|
|
|
exactly the same name, in any given section and the linker will have
|
|
|
|
no way to identify the correct one. Instead we just have to hope
|
|
|
|
that no relaxtion will occur between the local label and the other
|
|
|
|
symbol in the expression.
|
|
|
|
|
|
|
|
Similarly we have to compute differences between symbols in the .eh_frame
|
|
|
|
section as the linker is not smart enough to apply relocations there
|
|
|
|
before attempting to process it. */
|
|
|
|
if ((ssec != absolute_section || asec != absolute_section)
|
|
|
|
&& (fixp->fx_addsy != fixp->fx_subsy)
|
|
|
|
&& strcmp (ssec->name, ".eh_frame") != 0
|
|
|
|
&& ! S_IS_GAS_LOCAL (fixp->fx_addsy)
|
|
|
|
&& ! S_IS_GAS_LOCAL (fixp->fx_subsy))
|
|
|
|
{
|
|
|
|
arelent * reloc2 = xmalloc (sizeof * reloc);
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
relocs[0] = reloc2;
|
|
|
|
relocs[1] = reloc;
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2013-05-02 23:06:15 +02:00
|
|
|
reloc2->address = reloc->address;
|
|
|
|
reloc2->howto = bfd_reloc_type_lookup (stdoutput,
|
|
|
|
BFD_RELOC_MSP430_SYM_DIFF);
|
|
|
|
reloc2->addend = - S_GET_VALUE (fixp->fx_subsy);
|
|
|
|
|
|
|
|
if (ssec == absolute_section)
|
|
|
|
reloc2->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reloc2->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
|
|
|
|
*reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
|
|
|
|
}
|
|
|
|
|
|
|
|
reloc->addend = fixp->fx_offset;
|
|
|
|
if (asec == absolute_section)
|
|
|
|
{
|
|
|
|
reloc->addend += S_GET_VALUE (fixp->fx_addsy);
|
|
|
|
reloc->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
|
|
|
|
*reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
|
|
|
|
}
|
|
|
|
|
|
|
|
fixp->fx_pcrel = 0;
|
|
|
|
fixp->fx_done = 1;
|
|
|
|
return relocs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *fixpos = fixp->fx_where + fixp->fx_frag->fr_literal;
|
|
|
|
|
|
|
|
reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
|
|
|
|
- S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
|
|
|
|
|
|
|
|
switch (fixp->fx_r_type)
|
|
|
|
{
|
|
|
|
case BFD_RELOC_8:
|
|
|
|
md_number_to_chars (fixpos, reloc->addend, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_16:
|
|
|
|
md_number_to_chars (fixpos, reloc->addend, 2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_24:
|
|
|
|
md_number_to_chars (fixpos, reloc->addend, 3);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BFD_RELOC_32:
|
|
|
|
md_number_to_chars (fixpos, reloc->addend, 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
reloc->sym_ptr_ptr
|
|
|
|
= (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
|
|
|
|
return relocs;
|
|
|
|
}
|
|
|
|
|
|
|
|
free (reloc);
|
|
|
|
return & no_relocs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
if (fixp->fx_r_type == BFD_RELOC_MSP430X_ABS16
|
|
|
|
&& S_GET_SEGMENT (fixp->fx_addsy) == absolute_section)
|
|
|
|
{
|
|
|
|
bfd_vma amount = S_GET_VALUE (fixp->fx_addsy);
|
|
|
|
char *fixpos = fixp->fx_where + fixp->fx_frag->fr_literal;
|
|
|
|
|
|
|
|
md_number_to_chars (fixpos, amount, 2);
|
|
|
|
free (reloc);
|
|
|
|
return & no_relocs;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
|
|
|
|
*reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
|
|
|
|
reloc->addend = fixp->fx_offset;
|
|
|
|
|
|
|
|
if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
|
|
|
|
|| fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
|
|
|
|
reloc->address = fixp->fx_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return relocs;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
int
|
|
|
|
md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
|
|
|
|
asection * segment_type ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
if (fragP->fr_symbol && S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
|
|
|
|
{
|
|
|
|
/* This is a jump -> pcrel mode. Nothing to do much here.
|
|
|
|
Return value == 2. */
|
|
|
|
fragP->fr_subtype =
|
|
|
|
ENCODE_RELAX (RELAX_LEN (fragP->fr_subtype), STATE_BITS10);
|
|
|
|
}
|
|
|
|
else if (fragP->fr_symbol)
|
|
|
|
{
|
|
|
|
/* Its got a segment, but its not ours. Even if fr_symbol is in
|
2007-10-11 15:48:39 +02:00
|
|
|
an absolute segment, we don't know a displacement until we link
|
2004-08-25 14:54:15 +02:00
|
|
|
object files. So it will always be long. This also applies to
|
|
|
|
labels in a subsegment of current. Liker may relax it to short
|
|
|
|
jump later. Return value == 8. */
|
|
|
|
fragP->fr_subtype =
|
|
|
|
ENCODE_RELAX (RELAX_LEN (fragP->fr_subtype), STATE_WORD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We know the abs value. may be it is a jump to fixed address.
|
2007-10-11 15:48:39 +02:00
|
|
|
Impossible in our case, cause all constants already handled. */
|
2004-08-25 14:54:15 +02:00
|
|
|
fragP->fr_subtype =
|
|
|
|
ENCODE_RELAX (RELAX_LEN (fragP->fr_subtype), STATE_UNDEF);
|
|
|
|
}
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
return md_relax_table[fragP->fr_subtype].rlx_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED,
|
|
|
|
asection * sec ATTRIBUTE_UNUSED,
|
|
|
|
fragS * fragP)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
char * where = 0;
|
|
|
|
int rela = -1;
|
|
|
|
int i;
|
|
|
|
struct rcodes_s * cc = NULL;
|
|
|
|
struct hcodes_s * hc = NULL;
|
|
|
|
|
|
|
|
switch (fragP->fr_subtype)
|
|
|
|
{
|
|
|
|
case ENCODE_RELAX (STATE_UNCOND_BRANCH, STATE_BITS10):
|
|
|
|
case ENCODE_RELAX (STATE_SIMPLE_BRANCH, STATE_BITS10):
|
|
|
|
case ENCODE_RELAX (STATE_NOOV_BRANCH, STATE_BITS10):
|
|
|
|
/* We do not have to convert anything here.
|
|
|
|
Just apply a fix. */
|
|
|
|
rela = BFD_RELOC_MSP430_10_PCREL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENCODE_RELAX (STATE_UNCOND_BRANCH, STATE_WORD):
|
|
|
|
case ENCODE_RELAX (STATE_UNCOND_BRANCH, STATE_UNDEF):
|
|
|
|
/* Convert uncond branch jmp lab -> br lab. */
|
|
|
|
cc = & msp430_rcodes[7];
|
2013-05-02 23:06:15 +02:00
|
|
|
if (msp430_mcu->isa == MSP430X_ISA)
|
|
|
|
cc = msp430x_rcodes + 7;
|
2004-08-25 14:54:15 +02:00
|
|
|
where = fragP->fr_literal + fragP->fr_fix;
|
|
|
|
bfd_putl16 (cc->lop0, where);
|
|
|
|
rela = BFD_RELOC_MSP430_RL_PCREL;
|
|
|
|
fragP->fr_fix += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENCODE_RELAX (STATE_SIMPLE_BRANCH, STATE_WORD):
|
|
|
|
case ENCODE_RELAX (STATE_SIMPLE_BRANCH, STATE_UNDEF):
|
|
|
|
{
|
|
|
|
/* Other simple branches. */
|
|
|
|
int insn = bfd_getl16 (fragP->fr_opcode);
|
|
|
|
|
|
|
|
insn &= 0xffff;
|
|
|
|
/* Find actual instruction. */
|
2013-05-02 23:06:15 +02:00
|
|
|
if (msp430_mcu->isa == MSP430X_ISA)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 7 && !cc; i++)
|
|
|
|
if (msp430x_rcodes[i].sop == insn)
|
|
|
|
cc = msp430x_rcodes + i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < 7 && !cc; i++)
|
|
|
|
if (msp430_rcodes[i].sop == insn)
|
|
|
|
cc = & msp430_rcodes[i];
|
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (!cc || !cc->name)
|
|
|
|
as_fatal (_("internal inconsistency problem in %s: insn %04lx"),
|
|
|
|
__FUNCTION__, (long) insn);
|
|
|
|
where = fragP->fr_literal + fragP->fr_fix;
|
|
|
|
bfd_putl16 (cc->lop0, where);
|
|
|
|
bfd_putl16 (cc->lop1, where + 2);
|
|
|
|
rela = BFD_RELOC_MSP430_RL_PCREL;
|
|
|
|
fragP->fr_fix += 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENCODE_RELAX (STATE_NOOV_BRANCH, STATE_WORD):
|
|
|
|
case ENCODE_RELAX (STATE_NOOV_BRANCH, STATE_UNDEF):
|
|
|
|
cc = & msp430_rcodes[6];
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
if (msp430_mcu->isa == MSP430X_ISA)
|
|
|
|
cc = msp430x_rcodes + 6;
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
where = fragP->fr_literal + fragP->fr_fix;
|
|
|
|
bfd_putl16 (cc->lop0, where);
|
|
|
|
bfd_putl16 (cc->lop1, where + 2);
|
|
|
|
bfd_putl16 (cc->lop2, where + 4);
|
|
|
|
rela = BFD_RELOC_MSP430_RL_PCREL;
|
|
|
|
fragP->fr_fix += 6;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENCODE_RELAX (STATE_EMUL_BRANCH, STATE_BITS10):
|
|
|
|
{
|
|
|
|
int insn = bfd_getl16 (fragP->fr_opcode + 2);
|
|
|
|
|
|
|
|
insn &= 0xffff;
|
2013-05-02 23:06:15 +02:00
|
|
|
if (msp430_mcu->isa == MSP430X_ISA)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4 && !hc; i++)
|
|
|
|
if (msp430x_hcodes[i].op1 == insn)
|
|
|
|
hc = msp430x_hcodes + i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4 && !hc; i++)
|
|
|
|
if (msp430_hcodes[i].op1 == insn)
|
|
|
|
hc = &msp430_hcodes[i];
|
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
if (!hc || !hc->name)
|
|
|
|
as_fatal (_("internal inconsistency problem in %s: ext. insn %04lx"),
|
|
|
|
__FUNCTION__, (long) insn);
|
|
|
|
rela = BFD_RELOC_MSP430_10_PCREL;
|
|
|
|
/* Apply a fix for a first label if necessary.
|
|
|
|
another fix will be applied to the next word of insn anyway. */
|
|
|
|
if (hc->tlab == 2)
|
|
|
|
fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
|
2013-05-02 23:06:15 +02:00
|
|
|
fragP->fr_offset, TRUE, rela);
|
2004-08-25 14:54:15 +02:00
|
|
|
fragP->fr_fix += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENCODE_RELAX (STATE_EMUL_BRANCH, STATE_WORD):
|
|
|
|
case ENCODE_RELAX (STATE_EMUL_BRANCH, STATE_UNDEF):
|
|
|
|
{
|
|
|
|
int insn = bfd_getl16 (fragP->fr_opcode + 2);
|
|
|
|
|
|
|
|
insn &= 0xffff;
|
2013-05-02 23:06:15 +02:00
|
|
|
if (msp430_mcu->isa == MSP430X_ISA)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4 && !hc; i++)
|
|
|
|
if (msp430x_hcodes[i].op1 == insn)
|
|
|
|
hc = msp430x_hcodes + i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4 && !hc; i++)
|
|
|
|
if (msp430_hcodes[i].op1 == insn)
|
|
|
|
hc = & msp430_hcodes[i];
|
|
|
|
}
|
2004-08-25 14:54:15 +02:00
|
|
|
if (!hc || !hc->name)
|
|
|
|
as_fatal (_("internal inconsistency problem in %s: ext. insn %04lx"),
|
|
|
|
__FUNCTION__, (long) insn);
|
|
|
|
rela = BFD_RELOC_MSP430_RL_PCREL;
|
|
|
|
where = fragP->fr_literal + fragP->fr_fix;
|
|
|
|
bfd_putl16 (hc->lop0, where);
|
|
|
|
bfd_putl16 (hc->lop1, where + 2);
|
|
|
|
bfd_putl16 (hc->lop2, where + 4);
|
|
|
|
fragP->fr_fix += 6;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
as_fatal (_("internal inconsistency problem in %s: %lx"),
|
|
|
|
__FUNCTION__, (long) fragP->fr_subtype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now apply fix. */
|
|
|
|
fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
|
|
|
|
fragP->fr_offset, TRUE, rela);
|
|
|
|
/* Just fixed 2 bytes. */
|
|
|
|
fragP->fr_fix += 2;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
/* Relax fragment. Mostly stolen from hc11 and mcore
|
|
|
|
which arches I think I know. */
|
2002-12-30 20:25:13 +01:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
long
|
|
|
|
msp430_relax_frag (segT seg ATTRIBUTE_UNUSED, fragS * fragP,
|
|
|
|
long stretch ATTRIBUTE_UNUSED)
|
2002-12-30 20:25:13 +01:00
|
|
|
{
|
2004-08-25 14:54:15 +02:00
|
|
|
long growth;
|
|
|
|
offsetT aim = 0;
|
|
|
|
symbolS *symbolP;
|
|
|
|
const relax_typeS *this_type;
|
|
|
|
const relax_typeS *start_type;
|
|
|
|
relax_substateT next_state;
|
|
|
|
relax_substateT this_state;
|
|
|
|
const relax_typeS *table = md_relax_table;
|
|
|
|
|
|
|
|
/* Nothing to be done if the frag has already max size. */
|
|
|
|
if (RELAX_STATE (fragP->fr_subtype) == STATE_UNDEF
|
|
|
|
|| RELAX_STATE (fragP->fr_subtype) == STATE_WORD)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (RELAX_STATE (fragP->fr_subtype) == STATE_BITS10)
|
|
|
|
{
|
|
|
|
symbolP = fragP->fr_symbol;
|
|
|
|
if (symbol_resolved_p (symbolP))
|
|
|
|
as_fatal (_("internal inconsistency problem in %s: resolved symbol"),
|
|
|
|
__FUNCTION__);
|
|
|
|
/* We know the offset. calculate a distance. */
|
|
|
|
aim = S_GET_VALUE (symbolP) - fragP->fr_address - fragP->fr_fix;
|
|
|
|
}
|
|
|
|
|
2005-08-12 13:54:23 +02:00
|
|
|
if (!msp430_enable_relax)
|
|
|
|
{
|
|
|
|
/* Relaxation is not enabled. So, make all jump as long ones
|
2013-05-02 23:06:15 +02:00
|
|
|
by setting 'aim' to quite high value. */
|
2005-08-12 13:54:23 +02:00
|
|
|
aim = 0x7fff;
|
|
|
|
}
|
2013-05-02 23:06:15 +02:00
|
|
|
|
2004-08-25 14:54:15 +02:00
|
|
|
this_state = fragP->fr_subtype;
|
|
|
|
start_type = this_type = table + this_state;
|
|
|
|
|
|
|
|
if (aim < 0)
|
|
|
|
{
|
|
|
|
/* Look backwards. */
|
|
|
|
for (next_state = this_type->rlx_more; next_state;)
|
2005-09-09 10:46:19 +02:00
|
|
|
if (aim >= this_type->rlx_backward || !this_type->rlx_backward)
|
2004-08-25 14:54:15 +02:00
|
|
|
next_state = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Grow to next state. */
|
|
|
|
this_state = next_state;
|
|
|
|
this_type = table + this_state;
|
|
|
|
next_state = this_type->rlx_more;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Look forwards. */
|
|
|
|
for (next_state = this_type->rlx_more; next_state;)
|
2005-09-09 10:46:19 +02:00
|
|
|
if (aim <= this_type->rlx_forward || !this_type->rlx_forward)
|
2004-08-25 14:54:15 +02:00
|
|
|
next_state = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Grow to next state. */
|
|
|
|
this_state = next_state;
|
|
|
|
this_type = table + this_state;
|
|
|
|
next_state = this_type->rlx_more;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
growth = this_type->rlx_length - start_type->rlx_length;
|
|
|
|
if (growth != 0)
|
|
|
|
fragP->fr_subtype = this_state;
|
|
|
|
return growth;
|
2002-12-30 20:25:13 +01:00
|
|
|
}
|
2013-05-02 23:06:15 +02:00
|
|
|
|
|
|
|
/* Return FALSE if the fixup in fixp should be left alone and not
|
|
|
|
adjusted. We return FALSE here so that linker relaxation will
|
|
|
|
work. */
|
|
|
|
|
|
|
|
bfd_boolean
|
|
|
|
msp430_fix_adjustable (struct fix *fixp ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* If the symbol is in a non-code section then it should be OK. */
|
|
|
|
if (fixp->fx_addsy
|
|
|
|
&& ((S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_CODE) == 0))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the contents of the .MSP430.attributes section. */
|
|
|
|
|
|
|
|
void
|
|
|
|
msp430_md_end (void)
|
|
|
|
{
|
|
|
|
bfd_elf_add_proc_attr_int (stdoutput, OFBA_MSPABI_Tag_ISA,
|
|
|
|
msp430_mcu->isa == MSP430X_ISA ? 2 : 1);
|
|
|
|
|
|
|
|
bfd_elf_add_proc_attr_int (stdoutput, OFBA_MSPABI_Tag_Code_Model,
|
|
|
|
large_model ? 2 : 1);
|
|
|
|
|
|
|
|
bfd_elf_add_proc_attr_int (stdoutput, OFBA_MSPABI_Tag_Data_Model,
|
|
|
|
large_model ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns FALSE if there is a msp430 specific reason why the
|
|
|
|
subtraction of two same-section symbols cannot be computed by
|
|
|
|
the assembler. */
|
|
|
|
|
|
|
|
bfd_boolean
|
|
|
|
msp430_allow_local_subtract (expressionS * left,
|
|
|
|
expressionS * right,
|
|
|
|
segT section)
|
|
|
|
{
|
|
|
|
/* If the symbols are not in a code section then they are OK. */
|
|
|
|
if ((section->flags & SEC_CODE) == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (S_IS_GAS_LOCAL (left->X_add_symbol) || S_IS_GAS_LOCAL (right->X_add_symbol))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (left->X_add_symbol == right->X_add_symbol)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* We have to assume that there may be instructions between the
|
|
|
|
two symbols and that relaxation may increase the distance between
|
|
|
|
them. */
|
|
|
|
return FALSE;
|
|
|
|
}
|