1 /* tc-msp430.c -- Assembler code for the Texas Instruments MSP430
3 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4 Contributed by Dmitry Diky <diwil@mail.ru>
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #define PUSH_1X_WORKAROUND
31 #include "opcode/msp430.h"
32 #include "safe-ctype.h"
34 const char comment_chars
[] = ";";
35 const char line_comment_chars
[] = "#";
36 const char line_separator_chars
[] = "";
37 const char EXP_CHARS
[] = "eE";
38 const char FLT_CHARS
[] = "dD";
40 /* Handle long expressions. */
41 extern LITTLENUM_TYPE generic_bignum
[];
43 static struct hash_control
*msp430_hash
;
45 static unsigned int msp430_operands
46 PARAMS ((struct msp430_opcode_s
*, char *));
47 static int msp430_srcoperand
48 PARAMS ((struct msp430_operand_s
*, char *, int, int *));
49 static int msp430_dstoperand
50 PARAMS ((struct msp430_operand_s
*, char *, int));
51 static char *parse_exp
52 PARAMS ((char *, expressionS
*));
53 static inline char *skip_space
57 static void msp430_set_arch
59 static void show_mcu_list
61 static void del_spaces
73 #define MSP430_ISA_11 11
74 #define MSP430_ISA_110 110
75 #define MSP430_ISA_12 12
76 #define MSP430_ISA_13 13
77 #define MSP430_ISA_14 14
78 #define MSP430_ISA_15 15
79 #define MSP430_ISA_16 16
80 #define MSP430_ISA_31 31
81 #define MSP430_ISA_32 32
82 #define MSP430_ISA_33 33
83 #define MSP430_ISA_41 41
84 #define MSP430_ISA_42 42
85 #define MSP430_ISA_43 43
86 #define MSP430_ISA_44 44
88 #define CHECK_RELOC_MSP430 ((imm_op || byte_op)?BFD_RELOC_MSP430_16_BYTE:BFD_RELOC_MSP430_16)
89 #define CHECK_RELOC_MSP430_PCREL ((imm_op || byte_op)?BFD_RELOC_MSP430_16_PCREL_BYTE:BFD_RELOC_MSP430_16_PCREL)
91 static struct mcu_type_s mcu_types
[] =
93 {"msp1", MSP430_ISA_11
, bfd_mach_msp11
},
94 {"msp2", MSP430_ISA_14
, bfd_mach_msp14
},
95 {"msp430x110", MSP430_ISA_11
, bfd_mach_msp11
},
96 {"msp430x112", MSP430_ISA_11
, bfd_mach_msp11
},
97 {"msp430x1101",MSP430_ISA_110
, bfd_mach_msp110
},
98 {"msp430x1111",MSP430_ISA_110
, bfd_mach_msp110
},
99 {"msp430x1121",MSP430_ISA_110
, bfd_mach_msp110
},
100 {"msp430x1122",MSP430_ISA_11
, bfd_mach_msp110
},
101 {"msp430x1132",MSP430_ISA_11
, bfd_mach_msp110
},
103 {"msp430x122", MSP430_ISA_12
, bfd_mach_msp12
},
104 {"msp430x123", MSP430_ISA_12
, bfd_mach_msp12
},
105 {"msp430x1222",MSP430_ISA_12
, bfd_mach_msp12
},
106 {"msp430x1232",MSP430_ISA_12
, bfd_mach_msp12
},
108 {"msp430x133", MSP430_ISA_13
, bfd_mach_msp13
},
109 {"msp430x135", MSP430_ISA_13
, bfd_mach_msp13
},
110 {"msp430x1331",MSP430_ISA_13
, bfd_mach_msp13
},
111 {"msp430x1351",MSP430_ISA_13
, bfd_mach_msp13
},
112 {"msp430x147", MSP430_ISA_14
, bfd_mach_msp14
},
113 {"msp430x148", MSP430_ISA_14
, bfd_mach_msp14
},
114 {"msp430x149", MSP430_ISA_14
, bfd_mach_msp14
},
116 {"msp430x155", MSP430_ISA_15
, bfd_mach_msp15
},
117 {"msp430x156", MSP430_ISA_15
, bfd_mach_msp15
},
118 {"msp430x157", MSP430_ISA_15
, bfd_mach_msp15
},
119 {"msp430x167", MSP430_ISA_16
, bfd_mach_msp16
},
120 {"msp430x168", MSP430_ISA_16
, bfd_mach_msp16
},
121 {"msp430x169", MSP430_ISA_16
, bfd_mach_msp16
},
123 {"msp430x311", MSP430_ISA_31
, bfd_mach_msp31
},
124 {"msp430x312", MSP430_ISA_31
, bfd_mach_msp31
},
125 {"msp430x313", MSP430_ISA_31
, bfd_mach_msp31
},
126 {"msp430x314", MSP430_ISA_31
, bfd_mach_msp31
},
127 {"msp430x315", MSP430_ISA_31
, bfd_mach_msp31
},
128 {"msp430x323", MSP430_ISA_32
, bfd_mach_msp32
},
129 {"msp430x325", MSP430_ISA_32
, bfd_mach_msp32
},
130 {"msp430x336", MSP430_ISA_33
, bfd_mach_msp33
},
131 {"msp430x337", MSP430_ISA_33
, bfd_mach_msp33
},
133 {"msp430x412", MSP430_ISA_41
, bfd_mach_msp41
},
134 {"msp430x413", MSP430_ISA_41
, bfd_mach_msp41
},
136 {"msp430xE423", MSP430_ISA_42
, bfd_mach_msp42
},
137 {"msp430xE425", MSP430_ISA_42
, bfd_mach_msp42
},
138 {"msp430xE427", MSP430_ISA_42
, bfd_mach_msp42
},
139 {"msp430xW423", MSP430_ISA_42
, bfd_mach_msp42
},
140 {"msp430xW425", MSP430_ISA_42
, bfd_mach_msp42
},
141 {"msp430xW427", MSP430_ISA_42
, bfd_mach_msp42
},
143 {"msp430x435", MSP430_ISA_43
, bfd_mach_msp43
},
144 {"msp430x436", MSP430_ISA_43
, bfd_mach_msp43
},
145 {"msp430x437", MSP430_ISA_43
, bfd_mach_msp43
},
146 {"msp430x447", MSP430_ISA_44
, bfd_mach_msp44
},
147 {"msp430x448", MSP430_ISA_44
, bfd_mach_msp44
},
148 {"msp430x449", MSP430_ISA_44
, bfd_mach_msp44
},
154 static struct mcu_type_s default_mcu
=
155 { "msp430x11", MSP430_ISA_11
, bfd_mach_msp11
};
157 static struct mcu_type_s
*msp430_mcu
= &default_mcu
;
159 const pseudo_typeS md_pseudo_table
[] =
161 {"arch", msp430_set_arch
, 0},
165 #define OPTION_MMCU 'm'
167 const char *md_shortopts
= "m:";
169 struct option md_longopts
[] =
171 {"mmcu", required_argument
, NULL
, OPTION_MMCU
},
172 {NULL
, no_argument
, NULL
, 0}
175 size_t md_longopts_size
= sizeof (md_longopts
);
178 show_mcu_list (stream
)
183 fprintf (stream
, _("Known MCU names:\n"));
185 for (i
= 0; mcu_types
[i
].name
; i
++)
186 fprintf (stream
, _("\t %s\n"), mcu_types
[i
].name
);
188 fprintf (stream
, "\n");
192 md_show_usage (stream
)
196 _("MSP430 options:\n"
197 " -mmcu=[msp430-name] select microcontroller type\n"
198 " msp430x110 msp430x112\n"
199 " msp430x1101 msp430x1111\n"
200 " msp430x1121 msp430x1122 msp430x1132\n"
201 " msp430x122 msp430x123\n"
202 " msp430x1222 msp430x1232\n"
203 " msp430x133 msp430x135\n"
204 " msp430x1331 msp430x1351\n"
205 " msp430x147 msp430x148 msp430x149\n"
206 " msp430x155 msp430x156 msp430x157\n"
207 " msp430x167 msp430x168 msp430x169\n"
208 " msp430x311 msp430x312 msp430x313 msp430x314 msp430x315\n"
209 " msp430x323 msp430x325\n"
210 " msp430x336 msp430x337\n"
211 " msp430x412 msp430x413\n"
212 " msp430xE423 msp430xE425 msp430E427\n"
213 " msp430xW423 msp430xW425 msp430W427\n"
214 " msp430x435 msp430x436 msp430x437\n"
215 " msp430x447 msp430x448 msp430x449\n"));
217 show_mcu_list (stream
);
221 extract_word (char *from
, char *to
, int limit
)
227 /* Drop leading whitespace. */
228 from
= skip_space (from
);
231 /* Find the op code end. */
232 for (op_start
= op_end
= from
; *op_end
!= 0 && is_part_of_name (*op_end
);)
234 to
[size
++] = *op_end
++;
235 if (size
+ 1 >= limit
)
244 msp430_set_arch (dummy
)
245 int dummy ATTRIBUTE_UNUSED
;
247 char *str
= (char *) alloca (32); /* 32 for good measure. */
249 input_line_pointer
= extract_word (input_line_pointer
, str
, 32);
251 md_parse_option (OPTION_MMCU
, str
);
252 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, msp430_mcu
->mach
);
256 md_parse_option (c
, arg
)
265 for (i
= 0; mcu_types
[i
].name
; ++i
)
266 if (strcmp (mcu_types
[i
].name
, arg
) == 0)
269 if (!mcu_types
[i
].name
)
271 show_mcu_list (stderr
);
272 as_fatal (_("unknown MCU: %s\n"), arg
);
275 if (msp430_mcu
== &default_mcu
|| msp430_mcu
->mach
== mcu_types
[i
].mach
)
276 msp430_mcu
= &mcu_types
[i
];
278 as_fatal (_("redefinition of mcu type %s' to %s'"),
279 msp430_mcu
->name
, mcu_types
[i
].name
);
287 md_undefined_symbol (name
)
288 char *name ATTRIBUTE_UNUSED
;
302 /* Delete spaces from s: X ( r 1 2) => X(r12). */
314 while (ISSPACE (*m
) && *m
)
316 memmove (s
, m
, strlen (m
) + 1);
323 /* Extract one word from FROM and copy it to TO. Delimeters are ",;\n" */
326 extract_operand (char *from
, char *to
, int limit
)
330 /* Drop leading whitespace. */
331 from
= skip_space (from
);
333 while (size
< limit
&& *from
)
335 *(to
+ size
) = *from
;
336 if (*from
== ',' || *from
== ';' || *from
== '\n')
351 extract_cmd (char *from
, char *to
, int limit
)
355 while (*from
&& ! ISSPACE (*from
) && *from
!= '.' && limit
> size
)
357 *(to
+ size
) = *from
;
367 /* Turn a string in input_line_pointer into a floating point constant
368 of type TYPE, and store the appropriate bytes in *LITP. The number
369 of LITTLENUMS emitted is stored in *SIZEP. An error message is
370 returned, or NULL on OK. */
373 md_atof (type
, litP
, sizeP
)
379 LITTLENUM_TYPE words
[4];
380 LITTLENUM_TYPE
*wordP
;
393 return _("bad call to md_atof");
396 t
= atof_ieee (input_line_pointer
, type
, words
);
398 input_line_pointer
= t
;
400 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
402 /* This loop outputs the LITTLENUMs in REVERSE order. */
403 for (wordP
= words
+ prec
- 1; prec
--;)
405 md_number_to_chars (litP
, (valueT
) (*wordP
--), sizeof (LITTLENUM_TYPE
));
406 litP
+= sizeof (LITTLENUM_TYPE
);
413 md_convert_frag (abfd
, sec
, fragP
)
414 bfd
*abfd ATTRIBUTE_UNUSED
;
415 asection
*sec ATTRIBUTE_UNUSED
;
416 fragS
*fragP ATTRIBUTE_UNUSED
;
424 struct msp430_opcode_s
*opcode
;
425 msp430_hash
= hash_new ();
427 for (opcode
= msp430_opcodes
; opcode
->name
; opcode
++)
428 hash_insert (msp430_hash
, opcode
->name
, (char *) opcode
);
430 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, msp430_mcu
->mach
);
437 struct msp430_opcode_s
*opcode
;
441 str
= skip_space (str
); /* Skip leading spaces. */
442 str
= extract_cmd (str
, cmd
, sizeof (cmd
));
444 while (cmd
[i
] && i
< sizeof (cmd
))
446 char a
= TOLOWER (cmd
[i
]);
453 as_bad (_("can't find opcode "));
457 opcode
= (struct msp430_opcode_s
*) hash_find (msp430_hash
, cmd
);
461 as_bad (_("unknown opcode `%s'"), cmd
);
466 char *__t
= input_line_pointer
;
467 msp430_operands (opcode
, str
);
468 input_line_pointer
= __t
;
472 /* Parse instruction operands.
473 Return binary opcode. */
476 msp430_operands (opcode
, line
)
477 struct msp430_opcode_s
*opcode
;
480 int bin
= opcode
->bin_opcode
; /* opcode mask. */
482 char l1
[MAX_OP_LEN
], l2
[MAX_OP_LEN
];
485 struct msp430_operand_s op1
, op2
;
487 static short ZEROS
= 0;
490 /* opcode is the one from opcodes table
491 line contains something like
496 /* Check if byte or word operation. */
497 if (*line
== '.' && TOLOWER (*(line
+ 1)) == 'b')
499 bin
|= BYTE_OPERATION
;
506 while (! ISSPACE (*line
) && *line
)
509 if (opcode
->insn_opnumb
&& (!*line
|| *line
== '\n'))
511 as_bad (_("instruction %s requires %d operand(s)"),
512 opcode
->name
, opcode
->insn_opnumb
);
516 memset (l1
, 0, sizeof (l1
));
517 memset (l2
, 0, sizeof (l2
));
518 memset (&op1
, 0, sizeof (op1
));
519 memset (&op2
, 0, sizeof (op2
));
525 case 0: /* Emulated. */
526 switch (opcode
->insn_opnumb
)
529 /* Set/clear bits instructions. */
531 frag
= frag_more (__is
);
532 bfd_putl16 ((bfd_vma
) bin
, frag
);
535 /* Something which works with destination operand. */
536 line
= extract_operand (line
, l1
, sizeof (l1
));
537 res
= msp430_dstoperand (&op1
, l1
, opcode
->bin_opcode
);
541 bin
|= (op1
.reg
| (op1
.am
<< 7));
543 frag
= frag_more (2 * __is
);
544 where
= frag
- frag_now
->fr_literal
;
545 bfd_putl16 ((bfd_vma
) bin
, frag
);
547 if (op1
.mode
== OP_EXP
)
550 bfd_putl16 ((bfd_vma
) ZEROS
, frag
+ 2);
553 fix_new_exp (frag_now
, where
, 2,
554 &(op1
.exp
), FALSE
, CHECK_RELOC_MSP430
);
556 fix_new_exp (frag_now
, where
, 2,
557 &(op1
.exp
), TRUE
, CHECK_RELOC_MSP430_PCREL
);
565 /* Shift instruction. */
566 line
= extract_operand (line
, l1
, sizeof (l1
));
567 strncpy (l2
, l1
, 16);
568 res
= msp430_srcoperand (&op1
, l1
, opcode
->bin_opcode
, &imm_op
);
569 res
+= msp430_dstoperand (&op2
, l2
, opcode
->bin_opcode
);
572 break; /* An error occured. All warnings were done before. */
574 bin
|= (op2
.reg
| (op1
.reg
<< 8) | (op1
.am
<< 4) | (op2
.am
<< 7));
576 __is
= 1 + op1
.ol
+ op2
.ol
; /* insn size in words. */
577 frag
= frag_more (2 * __is
);
578 where
= frag
- frag_now
->fr_literal
;
579 bfd_putl16 ((bfd_vma
) bin
, frag
);
581 if (op1
.mode
== OP_EXP
)
583 where
+= 2; /* Advance 'where' as we do not know _where_. */
584 bfd_putl16 ((bfd_vma
) ZEROS
, frag
+ 2);
586 if (op1
.reg
|| (op1
.reg
== 0 && op1
.am
== 3)) /* Not PC relative. */
587 fix_new_exp (frag_now
, where
, 2,
588 &(op1
.exp
), FALSE
, CHECK_RELOC_MSP430
);
590 fix_new_exp (frag_now
, where
, 2,
591 &(op1
.exp
), TRUE
, CHECK_RELOC_MSP430_PCREL
);
594 if (op2
.mode
== OP_EXP
)
597 bfd_putl16 ((bfd_vma
) ZEROS
, frag
+ 2 + ((__is
== 3) ? 2 : 0));
599 if (op2
.reg
) /* Not PC relative. */
600 fix_new_exp (frag_now
, where
+ 2, 2,
601 &(op2
.exp
), FALSE
, CHECK_RELOC_MSP430
);
603 fix_new_exp (frag_now
, where
+ 2, 2,
604 &(op2
.exp
), TRUE
, CHECK_RELOC_MSP430_PCREL
);
609 /* Branch instruction => mov dst, r0. */
610 line
= extract_operand (line
, l1
, sizeof (l1
));
612 res
= msp430_srcoperand (&op1
, l1
, opcode
->bin_opcode
, &imm_op
);
619 bin
|= ((op1
.reg
<< 8) | (op1
.am
<< 4));
621 frag
= frag_more (2 * __is
);
622 where
= frag
- frag_now
->fr_literal
;
623 bfd_putl16 ((bfd_vma
) bin
, frag
);
625 if (op1
.mode
== OP_EXP
)
628 bfd_putl16 ((bfd_vma
) ZEROS
, frag
+ 2);
630 if (op1
.reg
|| (op1
.reg
== 0 && op1
.am
== 3))
631 fix_new_exp (frag_now
, where
, 2,
632 &(op1
.exp
), FALSE
, CHECK_RELOC_MSP430
);
634 fix_new_exp (frag_now
, where
, 2,
635 &(op1
.exp
), TRUE
, CHECK_RELOC_MSP430_PCREL
);
641 case 1: /* Format 1, double operand. */
642 line
= extract_operand (line
, l1
, sizeof (l1
));
643 line
= extract_operand (line
, l2
, sizeof (l2
));
644 res
= msp430_srcoperand (&op1
, l1
, opcode
->bin_opcode
, &imm_op
);
645 res
+= msp430_dstoperand (&op2
, l2
, opcode
->bin_opcode
);
648 break; /* Error occured. All warnings were done before. */
650 bin
|= (op2
.reg
| (op1
.reg
<< 8) | (op1
.am
<< 4) | (op2
.am
<< 7));
652 __is
= 1 + op1
.ol
+ op2
.ol
; /* insn size in words. */
653 frag
= frag_more (2 * __is
);
654 where
= frag
- frag_now
->fr_literal
;
655 bfd_putl16 ((bfd_vma
) bin
, frag
);
657 if (op1
.mode
== OP_EXP
)
659 where
+= 2; /* Advance where as we do not know _where_. */
660 bfd_putl16 ((bfd_vma
) ZEROS
, frag
+ 2);
662 if (op1
.reg
|| (op1
.reg
== 0 && op1
.am
== 3)) /* Not PC relative. */
663 fix_new_exp (frag_now
, where
, 2,
664 &(op1
.exp
), FALSE
, CHECK_RELOC_MSP430
);
666 fix_new_exp (frag_now
, where
, 2,
667 &(op1
.exp
), TRUE
, CHECK_RELOC_MSP430_PCREL
);
670 if (op2
.mode
== OP_EXP
)
673 bfd_putl16 ((bfd_vma
) ZEROS
, frag
+ 2 + ((__is
== 3) ? 2 : 0));
675 if (op2
.reg
) /* Not PC relative. */
676 fix_new_exp (frag_now
, where
+ 2, 2,
677 &(op2
.exp
), FALSE
, CHECK_RELOC_MSP430
);
679 fix_new_exp (frag_now
, where
+ 2, 2,
680 &(op2
.exp
), TRUE
, CHECK_RELOC_MSP430_PCREL
);
684 case 2: /* Single-operand mostly instr. */
685 if (opcode
->insn_opnumb
== 0)
687 /* reti instruction. */
688 frag
= frag_more (2);
689 bfd_putl16 ((bfd_vma
) bin
, frag
);
693 line
= extract_operand (line
, l1
, sizeof (l1
));
694 res
= msp430_srcoperand (&op1
, l1
, opcode
->bin_opcode
, &imm_op
);
696 break; /* Error in operand. */
698 bin
|= op1
.reg
| (op1
.am
<< 4);
700 frag
= frag_more (2 * __is
);
701 where
= frag
- frag_now
->fr_literal
;
702 bfd_putl16 ((bfd_vma
) bin
, frag
);
704 if (op1
.mode
== OP_EXP
)
706 bfd_putl16 ((bfd_vma
) ZEROS
, frag
+ 2);
708 if (op1
.reg
|| (op1
.reg
== 0 && op1
.am
== 3)) /* Not PC relative. */
709 fix_new_exp (frag_now
, where
+ 2, 2,
710 &(op1
.exp
), FALSE
, CHECK_RELOC_MSP430
);
712 fix_new_exp (frag_now
, where
+ 2, 2,
713 &(op1
.exp
), TRUE
, CHECK_RELOC_MSP430_PCREL
);
717 case 3: /* Conditional jumps instructions. */
718 line
= extract_operand (line
, l1
, sizeof (l1
));
729 frag
= frag_more (2); /* Instr size is 1 word. */
731 /* In order to handle something like:
735 jz 4 ; skip next 4 bytes
738 nop ; will jump here if r5 positive or zero
740 jCOND -n ;assumes jump n bytes backward:
750 jCOND $n ; jump from PC in either direction. */
752 if (exp
.X_op
== O_constant
)
754 int x
= exp
.X_add_number
;
758 as_warn (_("Even number required. Rounded to %d"), x
+ 1);
762 if ((*l1
== '$' && x
> 0) || x
< 0)
767 if (x
> 512 || x
< -511)
769 as_bad (_("Wrong displacement %d"), x
<< 1);
774 bfd_putl16 ((bfd_vma
) bin
, frag
);
776 else if (exp
.X_op
== O_symbol
&& *l1
!= '$')
778 where
= frag
- frag_now
->fr_literal
;
779 fix_new_exp (frag_now
, where
, 2,
780 &exp
, TRUE
, BFD_RELOC_MSP430_10_PCREL
);
782 bfd_putl16 ((bfd_vma
) bin
, frag
);
786 as_bad (_("instruction requires label sans '$'"));
792 ("instruction requires label or value in range -511:512"));
798 as_bad (_("instruction requires label"));
804 as_bad (_("Ilegal instruction or not implmented opcode."));
807 input_line_pointer
= line
;
812 msp430_dstoperand (op
, l
, bin
)
813 struct msp430_operand_s
*op
;
818 int ret
= msp430_srcoperand (op
, l
, bin
, &dummy
);
829 parse_exp (__tl
, &(op
->exp
));
830 if (op
->exp
.X_op
!= O_constant
|| op
->exp
.X_add_number
!= 0)
832 as_bad (_("Internal bug. Try to use 0(r%d) instead of @r%d"),
842 ("this addressing mode is not applicable for destination operand"));
853 /* If this is a reg numb, str 't' must be a number from 0 - 15. */
855 if (strlen (t
) > 2 && *(t
+ 2) != '+')
860 if ((*t
< '0' || *t
> '9') && *t
!= '+')
873 msp430_srcoperand (op
, l
, bin
, imm_op
)
874 struct msp430_operand_s
*op
;
881 /* Check if an immediate #VALUE. The hash sign should be only at the beginning! */
888 /* Check if there is:
889 llo(x) - least significant 16 bits, x &= 0xffff
890 lhi(x) - x = (x >> 16) & 0xffff,
891 hlo(x) - x = (x >> 32) & 0xffff,
892 hhi(x) - x = (x >> 48) & 0xffff
893 The value _MUST_ be constant expression: #hlo(1231231231). */
897 if (strncasecmp (h
, "#llo(", 5) == 0)
902 else if (strncasecmp (h
, "#lhi(", 5) == 0)
907 else if (strncasecmp (h
, "#hlo(", 5) == 0)
912 else if (strncasecmp (h
, "#hhi(", 5) == 0)
917 else if (strncasecmp (h
, "#lo(", 4) == 0)
922 else if (strncasecmp (h
, "#hi(", 4) == 0)
928 op
->reg
= 0; /* Reg PC. */
930 op
->ol
= 1; /* Immediate will follow an instruction. */
933 parse_exp (__tl
, &(op
->exp
));
934 if (op
->exp
.X_op
== O_constant
)
936 int x
= op
->exp
.X_add_number
;
941 op
->exp
.X_add_number
= x
;
943 else if (vshift
== 1)
945 x
= (x
>> 16) & 0xffff;
946 op
->exp
.X_add_number
= x
;
951 op
->exp
.X_add_number
= -1;
953 op
->exp
.X_add_number
= 0; /* Nothing left. */
954 x
= op
->exp
.X_add_number
;
957 if (op
->exp
.X_add_number
> 65535 || op
->exp
.X_add_number
< -32768)
959 as_bad (_("value %ld out of range. Use #lo() or #hi()"), x
);
963 /* Now check constants. */
964 /* Substitude register mode with a constant generator if applicable. */
966 x
= (short) x
; /* Extend sign. */
998 #ifdef PUSH_1X_WORKAROUND
1001 /* Remove warning as confusing.
1002 as_warn(_("Hardware push bug workaround")); */
1015 #ifdef PUSH_1X_WORKAROUND
1018 /* Remove warning as confusing.
1019 as_warn(_("Hardware push bug workaround")); */
1031 else if (op
->exp
.X_op
== O_symbol
)
1035 else if (op
->exp
.X_op
== O_big
)
1040 op
->exp
.X_op
= O_constant
;
1041 op
->exp
.X_add_number
= 0xffff & generic_bignum
[vshift
];
1042 x
= op
->exp
.X_add_number
;
1047 ("unknown expression in operand %s. use #llo() #lhi() #hlo() #hhi() "),
1097 as_bad (_("unknown operand %s"), l
);
1102 /* Check if absolute &VALUE (assume that we can construct something like ((a&b)<<7 + 25). */
1107 op
->reg
= 2; /* reg 2 in absolute addr mode. */
1108 op
->am
= 1; /* mode As == 01 bin. */
1109 op
->ol
= 1; /* Immediate value followed by instruction. */
1111 parse_exp (__tl
, &(op
->exp
));
1113 if (op
->exp
.X_op
== O_constant
)
1115 int x
= op
->exp
.X_add_number
;
1116 if (x
> 65535 || x
< -32768)
1118 as_bad (_("value out of range: %d"), x
);
1122 else if (op
->exp
.X_op
== O_symbol
)
1127 as_bad (_("unknown expression in operand %s"), l
);
1133 /* Check if inderect register mode @Rn / postincrement @Rn+. */
1137 char *m
= strchr (l
, '+');
1141 as_bad (_("unknown addressing mode %s"), l
);
1146 if (*t
!= 'r' && *t
!= 'R')
1148 as_bad (_("unknown addressing mode %s"), l
);
1152 t
++; /* Points to the reg value. */
1156 as_bad (_("Bad register name r%s"), t
);
1164 *m
= 0; /* strip '+' */
1166 if (op
->reg
< 0 || op
->reg
> 15)
1168 as_bad (_("MSP430 does not have %d registers"), op
->reg
);
1175 /* Check if register indexed X(Rn). */
1178 char *h
= strrchr (l
, '(');
1179 char *m
= strrchr (l
, ')');
1188 as_bad (_("')' required"));
1195 /* Extract a register. */
1196 t
++; /* Advance pointer. */
1198 if (*t
!= 'r' && *t
!= 'R')
1201 ("unknown operator %s. Did you mean X(Rn) or #[hl][hl][oi](CONST) ?"),
1208 if (op
->reg
> 9 || op
->reg
< 0)
1210 as_bad (_("unknown operator (r%s substituded as a register name"),
1217 op
->reg
= op
->reg
* 10;
1218 op
->reg
+= *t
- '0';
1222 as_bad (_("unknown operator %s"), l
);
1227 as_bad (_("r2 should not be used in indexed addressing mode"));
1231 if (*(t
+ 1) != ')')
1233 as_bad (_("unknown operator %s"), l
);
1238 /* Extract constant. */
1242 parse_exp (__tl
, &(op
->exp
));
1243 if (op
->exp
.X_op
== O_constant
)
1245 int x
= op
->exp
.X_add_number
;
1247 if (x
> 65535 || x
< -32768)
1249 as_bad (_("value out of range: %d"), x
);
1261 else if (op
->exp
.X_op
== O_symbol
)
1266 as_bad (_("unknown expression in operand %s"), l
);
1274 /* Register mode 'mov r1,r2'. */
1279 /* Operand should be a register. */
1280 if (*t
== 'r' || *t
== 'R')
1282 int x
= atoi (t
+ 1);
1284 if (check_reg (t
+ 1))
1287 if (x
< 0 || x
> 15)
1288 break; /* Symbolic mode. */
1299 /* Symbolic mode 'mov a, b' == 'mov x(pc), y(pc)'. */
1308 /* alpha/number underline dot for labels. */
1309 if (! ISALNUM (*t
) && *t
!= '_' && *t
!= '.')
1311 as_bad (_("unknown operand %s"), l
);
1318 op
->reg
= 0; /* PC relative... be careful. */
1322 parse_exp (__tl
, &(op
->exp
));
1328 as_bad (_("unknown addressing mode for operand %s"), l
);
1333 /* GAS will call this function for each section at the end of the assembly,
1334 to permit the CPU backend to adjust the alignment of a section. */
1337 md_section_align (seg
, addr
)
1341 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1343 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1346 /* If you define this macro, it should return the offset between the
1347 address of a PC relative fixup and the position from which the PC
1348 relative adjustment should be made. On many processors, the base
1349 of a PC relative instruction is the next instruction, so this
1350 macro would return the length of an instruction. */
1353 md_pcrel_from_section (fixp
, sec
)
1357 if (fixp
->fx_addsy
!= (symbolS
*) NULL
1358 && (!S_IS_DEFINED (fixp
->fx_addsy
)
1359 || (S_GET_SEGMENT (fixp
->fx_addsy
) != sec
)))
1362 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1365 /* GAS will call this for each fixup. It should store the correct
1366 value in the object file. */
1369 md_apply_fix3 (fixp
, valuep
, seg
)
1374 unsigned char *where
;
1378 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
1383 else if (fixp
->fx_pcrel
)
1385 segT s
= S_GET_SEGMENT (fixp
->fx_addsy
);
1387 if (fixp
->fx_addsy
&& (s
== seg
|| s
== absolute_section
))
1389 value
= S_GET_VALUE (fixp
->fx_addsy
) + *valuep
;
1397 value
= fixp
->fx_offset
;
1399 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
1401 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
1403 value
-= S_GET_VALUE (fixp
->fx_subsy
);
1408 /* We don't actually support subtracting a symbol. */
1409 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1410 _("expression too complex"));
1415 switch (fixp
->fx_r_type
)
1418 fixp
->fx_no_overflow
= 1;
1420 case BFD_RELOC_MSP430_10_PCREL
:
1426 /* Fetch the instruction, insert the fully resolved operand
1427 value, and stuff the instruction back again. */
1429 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1431 insn
= bfd_getl16 (where
);
1433 switch (fixp
->fx_r_type
)
1435 case BFD_RELOC_MSP430_10_PCREL
:
1437 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1438 _("odd address operand: %ld"), value
);
1440 /* Jumps are in words. */
1442 --value
; /* Correct PC. */
1444 if (value
< -512 || value
> 511)
1445 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1446 _("operand out of range: %ld"), value
);
1448 value
&= 0x3ff; /* get rid of extended sign */
1449 bfd_putl16 ((bfd_vma
) (value
| insn
), where
);
1452 case BFD_RELOC_MSP430_16_PCREL
:
1454 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1455 _("odd address operand: %ld"), value
);
1457 /* Nothing to be corrected here. */
1458 if (value
< -32768 || value
> 65536)
1459 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1460 _("operand out of range: %ld"), value
);
1462 value
&= 0xffff; /* Get rid of extended sign. */
1463 bfd_putl16 ((bfd_vma
) value
, where
);
1466 case BFD_RELOC_MSP430_16_PCREL_BYTE
:
1467 /* Nothing to be corrected here. */
1468 if (value
< -32768 || value
> 65536)
1469 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1470 _("operand out of range: %ld"), value
);
1472 value
&= 0xffff; /* Get rid of extended sign. */
1473 bfd_putl16 ((bfd_vma
) value
, where
);
1477 bfd_putl16 ((bfd_vma
) value
, where
);
1480 case BFD_RELOC_MSP430_16
:
1482 case BFD_RELOC_MSP430_16_BYTE
:
1484 bfd_putl16 ((bfd_vma
) value
, where
);
1488 as_fatal (_("line %d: unknown relocation type: 0x%x"),
1489 fixp
->fx_line
, fixp
->fx_r_type
);
1495 fixp
->fx_addnumber
= value
;
1500 /* A `BFD_ASSEMBLER' GAS will call this to generate a reloc. GAS
1501 will pass the resulting reloc to `bfd_install_relocation'. This
1502 currently works poorly, as `bfd_install_relocation' often does the
1503 wrong thing, and instances of `tc_gen_reloc' have been written to
1504 work around the problems, which in turns makes it difficult to fix
1505 `bfd_install_relocation'. */
1507 /* If while processing a fixup, a reloc really needs to be created
1508 then it is done here. */
1511 tc_gen_reloc (seg
, fixp
)
1512 asection
*seg ATTRIBUTE_UNUSED
;
1517 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1519 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1520 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1522 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1523 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1524 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1526 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1527 _("reloc %d not supported by object file format"),
1528 (int) fixp
->fx_r_type
);
1532 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1533 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1534 reloc
->address
= fixp
->fx_offset
;
1536 reloc
->addend
= fixp
->fx_offset
;
1541 /* Parse ordinary expression. */
1548 input_line_pointer
= s
;
1550 if (op
->X_op
== O_absent
)
1551 as_bad (_("missing operand"));
1552 return input_line_pointer
;
1557 md_estimate_size_before_relax (fragp
, seg
)
1558 fragS
*fragp ATTRIBUTE_UNUSED
;
1559 asection
*seg ATTRIBUTE_UNUSED
;