1 /* tc-m68hc11.c -- Assembler code for the Motorola 68HC11 & 68HC12.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
3 Free Software Foundation, Inc.
4 Written by Stephane Carrez (stcarrez@nerim.fr)
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 3, 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, 51 Franklin Street - Fifth Floor,
21 Boston, MA 02110-1301, USA. */
24 #include "safe-ctype.h"
26 #include "opcode/m68hc11.h"
27 #include "dwarf2dbg.h"
28 #include "elf/m68hc11.h"
30 const char comment_chars
[] = ";!";
31 const char line_comment_chars
[] = "#*";
32 const char line_separator_chars
[] = "";
34 const char EXP_CHARS
[] = "eE";
35 const char FLT_CHARS
[] = "dD";
37 #define STATE_CONDITIONAL_BRANCH (1)
38 #define STATE_PC_RELATIVE (2)
39 #define STATE_INDEXED_OFFSET (3)
40 #define STATE_INDEXED_PCREL (4)
41 #define STATE_XBCC_BRANCH (5)
42 #define STATE_CONDITIONAL_BRANCH_6812 (6)
44 #define STATE_BYTE (0)
45 #define STATE_BITS5 (0)
46 #define STATE_WORD (1)
47 #define STATE_BITS9 (1)
48 #define STATE_LONG (2)
49 #define STATE_BITS16 (2)
50 #define STATE_UNDF (3) /* Symbol undefined in pass1 */
52 /* This macro has no side-effects. */
53 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
54 #define RELAX_STATE(s) ((s) >> 2)
55 #define RELAX_LENGTH(s) ((s) & 3)
57 #define IS_OPCODE(C1,C2) (((C1) & 0x0FF) == ((C2) & 0x0FF))
59 /* This table describes how you change sizes for the various types of variable
60 size expressions. This version only supports two kinds. */
63 How far Forward this mode will reach.
64 How far Backward this mode will reach.
65 How many bytes this mode will add to the size of the frag.
66 Which mode to go to if the offset won't fit in this one. */
68 relax_typeS md_relax_table
[] = {
69 {1, 1, 0, 0}, /* First entries aren't used. */
70 {1, 1, 0, 0}, /* For no good reason except. */
71 {1, 1, 0, 0}, /* that the VAX doesn't either. */
75 These insns are translated into b!cc +3 jmp L. */
76 {(127), (-128), 0, ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
)},
81 /* Relax for bsr <L> and bra <L>.
82 These insns are translated into jsr and jmp. */
83 {(127), (-128), 0, ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_WORD
)},
88 /* Relax for indexed offset: 5-bits, 9-bits, 16-bits. */
89 {(15), (-16), 0, ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_BITS9
)},
90 {(255), (-256), 1, ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_BITS16
)},
94 /* Relax for PC relative offset: 5-bits, 9-bits, 16-bits.
95 For the 9-bit case, there will be a -1 correction to take into
96 account the new byte that's why the range is -255..256. */
97 {(15), (-16), 0, ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_BITS9
)},
98 {(256), (-255), 1, ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_BITS16
)},
102 /* Relax for dbeq/ibeq/tbeq r,<L>:
103 These insns are translated into db!cc +3 jmp L. */
104 {(255), (-256), 0, ENCODE_RELAX (STATE_XBCC_BRANCH
, STATE_WORD
)},
109 /* Relax for bcc <L> on 68HC12.
110 These insns are translated into lbcc <L>. */
111 {(127), (-128), 0, ENCODE_RELAX (STATE_CONDITIONAL_BRANCH_6812
, STATE_WORD
)},
118 /* 68HC11 and 68HC12 registers. They are numbered according to the 68HC12. */
119 typedef enum register_id
{
131 typedef struct operand
{
138 struct m68hc11_opcode_def
{
144 struct m68hc11_opcode
*opcode
;
147 static struct m68hc11_opcode_def
*m68hc11_opcode_defs
= 0;
148 static int m68hc11_nb_opcode_defs
= 0;
150 typedef struct alias
{
155 static alias alias_opcodes
[] = {
162 /* Local functions. */
163 static register_id
reg_name_search (char *);
164 static register_id
register_name (void);
165 static int cmp_opcode (struct m68hc11_opcode
*, struct m68hc11_opcode
*);
166 static char *print_opcode_format (struct m68hc11_opcode
*, int);
167 static char *skip_whites (char *);
168 static int check_range (long, int);
169 static void print_opcode_list (void);
170 static void get_default_target (void);
171 static void print_insn_format (char *);
172 static int get_operand (operand
*, int, long);
173 static void fixup8 (expressionS
*, int, int);
174 static void fixup16 (expressionS
*, int, int);
175 static void fixup24 (expressionS
*, int, int);
176 static unsigned char convert_branch (unsigned char);
177 static char *m68hc11_new_insn (int);
178 static void build_dbranch_insn (struct m68hc11_opcode
*,
179 operand
*, int, int);
180 static int build_indexed_byte (operand
*, int, int);
181 static int build_reg_mode (operand
*, int);
183 static struct m68hc11_opcode
*find (struct m68hc11_opcode_def
*,
185 static struct m68hc11_opcode
*find_opcode (struct m68hc11_opcode_def
*,
187 static void build_jump_insn (struct m68hc11_opcode
*, operand
*, int, int);
188 static void build_insn (struct m68hc11_opcode
*, operand
*, int);
189 static int relaxable_symbol (symbolS
*);
191 /* Pseudo op to indicate a relax group. */
192 static void s_m68hc11_relax (int);
194 /* Pseudo op to control the ELF flags. */
195 static void s_m68hc11_mode (int);
197 /* Mark the symbols with STO_M68HC12_FAR to indicate the functions
198 are using 'rtc' for returning. It is necessary to use 'call'
199 to invoke them. This is also used by the debugger to correctly
200 find the stack frame. */
201 static void s_m68hc11_mark_symbol (int);
203 /* Controls whether relative branches can be turned into long branches.
204 When the relative offset is too large, the insn are changed:
212 Setting the flag forbidds this. */
213 static short flag_fixed_branches
= 0;
215 /* Force to use long jumps (absolute) instead of relative branches. */
216 static short flag_force_long_jumps
= 0;
218 /* Change the direct addressing mode into an absolute addressing mode
219 when the insn does not support direct addressing.
220 For example, "clr *ZD0" is normally not possible and is changed
222 static short flag_strict_direct_addressing
= 1;
224 /* When an opcode has invalid operand, print out the syntax of the opcode
226 static short flag_print_insn_syntax
= 0;
228 /* Dumps the list of instructions with syntax and then exit:
229 1 -> Only dumps the list (sorted by name)
230 2 -> Generate an example (or test) that can be compiled. */
231 static short flag_print_opcodes
= 0;
233 /* Opcode hash table. */
234 static struct hash_control
*m68hc11_hash
;
236 /* Current cpu (either cpu6811 or cpu6812). This is determined automagically
237 by 'get_default_target' by looking at default BFD vector. This is overridden
238 with the -m<cpu> option. */
239 static int current_architecture
= 0;
241 /* Default cpu determined by 'get_default_target'. */
242 static const char *default_cpu
;
244 /* Number of opcodes in the sorted table (filtered by current cpu). */
245 static int num_opcodes
;
247 /* The opcodes sorted by name and filtered by current cpu. */
248 static struct m68hc11_opcode
*m68hc11_sorted_opcodes
;
250 /* ELF flags to set in the output file header. */
251 static int elf_flags
= E_M68HC11_F64
;
253 /* These are the machine dependent pseudo-ops. These are included so
254 the assembler can work on the output from the SUN C compiler, which
257 /* This table describes all the machine specific pseudo-ops the assembler
258 has to support. The fields are:
259 pseudo-op name without dot
260 function to call to execute this pseudo-op
261 Integer arg to pass to the function. */
262 const pseudo_typeS md_pseudo_table
[] = {
263 /* The following pseudo-ops are supported for MRI compatibility. */
266 {"fcc", stringer
, 8 + 1},
270 {"xrefb", s_ignore
, 0}, /* Same as xref */
272 /* Gcc driven relaxation. */
273 {"relax", s_m68hc11_relax
, 0},
275 /* .mode instruction (ala SH). */
276 {"mode", s_m68hc11_mode
, 0},
278 /* .far instruction. */
279 {"far", s_m68hc11_mark_symbol
, STO_M68HC12_FAR
},
281 /* .interrupt instruction. */
282 {"interrupt", s_m68hc11_mark_symbol
, STO_M68HC12_INTERRUPT
},
287 /* Options and initialization. */
289 const char *md_shortopts
= "Sm:";
291 struct option md_longopts
[] = {
292 #define OPTION_FORCE_LONG_BRANCH (OPTION_MD_BASE)
293 {"force-long-branches", no_argument
, NULL
, OPTION_FORCE_LONG_BRANCH
},
294 {"force-long-branchs", no_argument
, NULL
, OPTION_FORCE_LONG_BRANCH
}, /* Misspelt version kept for backwards compatibility. */
296 #define OPTION_SHORT_BRANCHES (OPTION_MD_BASE + 1)
297 {"short-branches", no_argument
, NULL
, OPTION_SHORT_BRANCHES
},
298 {"short-branchs", no_argument
, NULL
, OPTION_SHORT_BRANCHES
}, /* Misspelt version kept for backwards compatibility. */
300 #define OPTION_STRICT_DIRECT_MODE (OPTION_MD_BASE + 2)
301 {"strict-direct-mode", no_argument
, NULL
, OPTION_STRICT_DIRECT_MODE
},
303 #define OPTION_PRINT_INSN_SYNTAX (OPTION_MD_BASE + 3)
304 {"print-insn-syntax", no_argument
, NULL
, OPTION_PRINT_INSN_SYNTAX
},
306 #define OPTION_PRINT_OPCODES (OPTION_MD_BASE + 4)
307 {"print-opcodes", no_argument
, NULL
, OPTION_PRINT_OPCODES
},
309 #define OPTION_GENERATE_EXAMPLE (OPTION_MD_BASE + 5)
310 {"generate-example", no_argument
, NULL
, OPTION_GENERATE_EXAMPLE
},
312 #define OPTION_MSHORT (OPTION_MD_BASE + 6)
313 {"mshort", no_argument
, NULL
, OPTION_MSHORT
},
315 #define OPTION_MLONG (OPTION_MD_BASE + 7)
316 {"mlong", no_argument
, NULL
, OPTION_MLONG
},
318 #define OPTION_MSHORT_DOUBLE (OPTION_MD_BASE + 8)
319 {"mshort-double", no_argument
, NULL
, OPTION_MSHORT_DOUBLE
},
321 #define OPTION_MLONG_DOUBLE (OPTION_MD_BASE + 9)
322 {"mlong-double", no_argument
, NULL
, OPTION_MLONG_DOUBLE
},
324 {NULL
, no_argument
, NULL
, 0}
326 size_t md_longopts_size
= sizeof (md_longopts
);
328 /* Get the target cpu for the assembler. This is based on the configure
329 options and on the -m68hc11/-m68hc12 option. If no option is specified,
330 we must get the default. */
332 m68hc11_arch_format (void)
334 get_default_target ();
335 if (current_architecture
& cpu6811
)
336 return "elf32-m68hc11";
338 return "elf32-m68hc12";
341 enum bfd_architecture
344 get_default_target ();
345 if (current_architecture
& cpu6811
)
346 return bfd_arch_m68hc11
;
348 return bfd_arch_m68hc12
;
357 /* Listing header selected according to cpu. */
359 m68hc11_listing_header (void)
361 if (current_architecture
& cpu6811
)
362 return "M68HC11 GAS ";
364 return "M68HC12 GAS ";
368 md_show_usage (FILE *stream
)
370 get_default_target ();
371 fprintf (stream
, _("\
372 Motorola 68HC11/68HC12/68HCS12 options:\n\
373 -m68hc11 | -m68hc12 |\n\
374 -m68hcs12 specify the processor [default %s]\n\
375 -mshort use 16-bit int ABI (default)\n\
376 -mlong use 32-bit int ABI\n\
377 -mshort-double use 32-bit double ABI\n\
378 -mlong-double use 64-bit double ABI (default)\n\
379 --force-long-branches always turn relative branches into absolute ones\n\
380 -S,--short-branches do not turn relative branches into absolute ones\n\
381 when the offset is out of range\n\
382 --strict-direct-mode do not turn the direct mode into extended mode\n\
383 when the instruction does not support direct mode\n\
384 --print-insn-syntax print the syntax of instruction in case of error\n\
385 --print-opcodes print the list of instructions with syntax\n\
386 --generate-example generate an example of each instruction\n\
387 (used for testing)\n"), default_cpu
);
391 /* Try to identify the default target based on the BFD library. */
393 get_default_target (void)
395 const bfd_target
*target
;
398 if (current_architecture
!= 0)
401 default_cpu
= "unknown";
402 target
= bfd_find_target (0, &abfd
);
403 if (target
&& target
->name
)
405 if (strcmp (target
->name
, "elf32-m68hc12") == 0)
407 current_architecture
= cpu6812
;
408 default_cpu
= "m68hc12";
410 else if (strcmp (target
->name
, "elf32-m68hc11") == 0)
412 current_architecture
= cpu6811
;
413 default_cpu
= "m68hc11";
417 as_bad (_("Default target `%s' is not supported."), target
->name
);
423 m68hc11_print_statistics (FILE *file
)
426 struct m68hc11_opcode_def
*opc
;
428 hash_print_statistics (file
, "opcode table", m68hc11_hash
);
430 opc
= m68hc11_opcode_defs
;
431 if (opc
== 0 || m68hc11_nb_opcode_defs
== 0)
434 /* Dump the opcode statistics table. */
435 fprintf (file
, _("Name # Modes Min ops Max ops Modes mask # Used\n"));
436 for (i
= 0; i
< m68hc11_nb_opcode_defs
; i
++, opc
++)
438 fprintf (file
, "%-7.7s %5d %7d %7d 0x%08lx %7d\n",
441 opc
->min_operands
, opc
->max_operands
, opc
->format
, opc
->used
);
446 md_parse_option (int c
, char *arg
)
448 get_default_target ();
451 /* -S means keep external to 2 bit offset rather than 16 bit one. */
452 case OPTION_SHORT_BRANCHES
:
454 flag_fixed_branches
= 1;
457 case OPTION_FORCE_LONG_BRANCH
:
458 flag_force_long_jumps
= 1;
461 case OPTION_PRINT_INSN_SYNTAX
:
462 flag_print_insn_syntax
= 1;
465 case OPTION_PRINT_OPCODES
:
466 flag_print_opcodes
= 1;
469 case OPTION_STRICT_DIRECT_MODE
:
470 flag_strict_direct_addressing
= 0;
473 case OPTION_GENERATE_EXAMPLE
:
474 flag_print_opcodes
= 2;
478 elf_flags
&= ~E_M68HC11_I32
;
482 elf_flags
|= E_M68HC11_I32
;
485 case OPTION_MSHORT_DOUBLE
:
486 elf_flags
&= ~E_M68HC11_F64
;
489 case OPTION_MLONG_DOUBLE
:
490 elf_flags
|= E_M68HC11_F64
;
494 if (strcasecmp (arg
, "68hc11") == 0)
495 current_architecture
= cpu6811
;
496 else if (strcasecmp (arg
, "68hc12") == 0)
497 current_architecture
= cpu6812
;
498 else if (strcasecmp (arg
, "68hcs12") == 0)
499 current_architecture
= cpu6812
| cpu6812s
;
501 as_bad (_("Option `%s' is not recognized."), arg
);
512 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
518 md_atof (int type
, char *litP
, int *sizeP
)
520 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
524 md_section_align (asection
*seg
, valueT addr
)
526 int align
= bfd_get_section_alignment (stdoutput
, seg
);
527 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
531 cmp_opcode (struct m68hc11_opcode
*op1
, struct m68hc11_opcode
*op2
)
533 return strcmp (op1
->name
, op2
->name
);
536 #define IS_CALL_SYMBOL(MODE) \
537 (((MODE) & (M6812_OP_PAGE|M6811_OP_IND16)) \
538 == ((M6812_OP_PAGE|M6811_OP_IND16)))
540 /* Initialize the assembler. Create the opcode hash table
541 (sorted on the names) with the M6811 opcode table
542 (from opcode library). */
546 char *prev_name
= "";
547 struct m68hc11_opcode
*opcodes
;
548 struct m68hc11_opcode_def
*opc
= 0;
551 get_default_target ();
553 m68hc11_hash
= hash_new ();
555 /* Get a writable copy of the opcode table and sort it on the names. */
556 opcodes
= (struct m68hc11_opcode
*) xmalloc (m68hc11_num_opcodes
*
559 m68hc11_sorted_opcodes
= opcodes
;
561 for (i
= 0; i
< m68hc11_num_opcodes
; i
++)
563 if (m68hc11_opcodes
[i
].arch
& current_architecture
)
565 opcodes
[num_opcodes
] = m68hc11_opcodes
[i
];
566 if (opcodes
[num_opcodes
].name
[0] == 'b'
567 && opcodes
[num_opcodes
].format
& M6811_OP_JUMP_REL
568 && !(opcodes
[num_opcodes
].format
& M6811_OP_BITMASK
))
571 opcodes
[num_opcodes
] = m68hc11_opcodes
[i
];
574 for (j
= 0; alias_opcodes
[j
].name
!= 0; j
++)
575 if (strcmp (m68hc11_opcodes
[i
].name
, alias_opcodes
[j
].name
) == 0)
577 opcodes
[num_opcodes
] = m68hc11_opcodes
[i
];
578 opcodes
[num_opcodes
].name
= alias_opcodes
[j
].alias
;
584 qsort (opcodes
, num_opcodes
, sizeof (struct m68hc11_opcode
),
585 (int (*) (const void*, const void*)) cmp_opcode
);
587 opc
= (struct m68hc11_opcode_def
*)
588 xmalloc (num_opcodes
* sizeof (struct m68hc11_opcode_def
));
589 m68hc11_opcode_defs
= opc
--;
591 /* Insert unique names into hash table. The M6811 instruction set
592 has several identical opcode names that have different opcodes based
593 on the operands. This hash table then provides a quick index to
594 the first opcode with a particular name in the opcode table. */
595 for (i
= 0; i
< num_opcodes
; i
++, opcodes
++)
599 if (strcmp (prev_name
, opcodes
->name
))
601 prev_name
= (char *) opcodes
->name
;
605 opc
->min_operands
= 100;
606 opc
->max_operands
= 0;
608 opc
->opcode
= opcodes
;
610 hash_insert (m68hc11_hash
, opcodes
->name
, opc
);
613 opc
->format
|= opcodes
->format
;
615 /* See how many operands this opcode needs. */
617 if (opcodes
->format
& M6811_OP_MASK
)
619 if (opcodes
->format
& M6811_OP_BITMASK
)
621 if (opcodes
->format
& (M6811_OP_JUMP_REL
| M6812_OP_JUMP_REL16
))
623 if (opcodes
->format
& (M6812_OP_IND16_P2
| M6812_OP_IDX_P2
))
625 /* Special case for call instruction. */
626 if ((opcodes
->format
& M6812_OP_PAGE
)
627 && !(opcodes
->format
& M6811_OP_IND16
))
630 if (expect
< opc
->min_operands
)
631 opc
->min_operands
= expect
;
632 if (IS_CALL_SYMBOL (opcodes
->format
))
634 if (expect
> opc
->max_operands
)
635 opc
->max_operands
= expect
;
638 m68hc11_nb_opcode_defs
= opc
- m68hc11_opcode_defs
;
640 if (flag_print_opcodes
)
642 print_opcode_list ();
648 m68hc11_init_after_args (void)
654 /* Return a string that represents the operand format for the instruction.
655 When example is true, this generates an example of operand. This is used
656 to give an example and also to generate a test. */
658 print_opcode_format (struct m68hc11_opcode
*opcode
, int example
)
660 static char buf
[128];
661 int format
= opcode
->format
;
666 if (format
& M6811_OP_IMM8
)
669 sprintf (p
, "#%d", rand () & 0x0FF);
671 strcpy (p
, _("#<imm8>"));
675 if (format
& M6811_OP_IMM16
)
678 sprintf (p
, "#%d", rand () & 0x0FFFF);
680 strcpy (p
, _("#<imm16>"));
684 if (format
& M6811_OP_IX
)
687 sprintf (p
, "%d,X", rand () & 0x0FF);
689 strcpy (p
, _("<imm8>,X"));
693 if (format
& M6811_OP_IY
)
696 sprintf (p
, "%d,X", rand () & 0x0FF);
698 strcpy (p
, _("<imm8>,X"));
702 if (format
& M6812_OP_IDX
)
705 sprintf (p
, "%d,X", rand () & 0x0FF);
711 if (format
& M6812_OP_PAGE
)
714 sprintf (p
, ", %d", rand () & 0x0FF);
716 strcpy (p
, ", <page>");
720 if (format
& M6811_OP_DIRECT
)
723 sprintf (p
, "*Z%d", rand () & 0x0FF);
725 strcpy (p
, _("*<abs8>"));
729 if (format
& M6811_OP_BITMASK
)
735 sprintf (p
, "#$%02x", rand () & 0x0FF);
737 strcpy (p
, _("#<mask>"));
740 if (format
& M6811_OP_JUMP_REL
)
744 if (format
& M6811_OP_IND16
)
747 sprintf (p
, _("symbol%d"), rand () & 0x0FF);
749 strcpy (p
, _("<abs>"));
754 if (format
& (M6811_OP_JUMP_REL
| M6812_OP_JUMP_REL16
))
758 if (format
& M6811_OP_BITMASK
)
760 sprintf (p
, ".+%d", rand () & 0x7F);
764 sprintf (p
, "L%d", rand () & 0x0FF);
768 strcpy (p
, _("<label>"));
774 /* Prints the list of instructions with the possible operands. */
776 print_opcode_list (void)
779 char *prev_name
= "";
780 struct m68hc11_opcode
*opcodes
;
781 int example
= flag_print_opcodes
== 2;
784 printf (_("# Example of `%s' instructions\n\t.sect .text\n_start:\n"),
787 opcodes
= m68hc11_sorted_opcodes
;
789 /* Walk the list sorted on names (by md_begin). We only report
790 one instruction per line, and we collect the different operand
792 for (i
= 0; i
< num_opcodes
; i
++, opcodes
++)
794 char *fmt
= print_opcode_format (opcodes
, example
);
798 printf ("L%d:\t", i
);
799 printf ("%s %s\n", opcodes
->name
, fmt
);
803 if (strcmp (prev_name
, opcodes
->name
))
808 printf ("%-5.5s ", opcodes
->name
);
809 prev_name
= (char *) opcodes
->name
;
812 printf (" [%s]", fmt
);
818 /* Print the instruction format. This operation is called when some
819 instruction is not correct. Instruction format is printed as an
822 print_insn_format (char *name
)
824 struct m68hc11_opcode_def
*opc
;
825 struct m68hc11_opcode
*opcode
;
828 opc
= (struct m68hc11_opcode_def
*) hash_find (m68hc11_hash
, name
);
831 as_bad (_("Instruction `%s' is not recognized."), name
);
834 opcode
= opc
->opcode
;
836 as_bad (_("Instruction formats for `%s':"), name
);
841 fmt
= print_opcode_format (opcode
, 0);
842 sprintf (buf
, "\t%-5.5s %s", opcode
->name
, fmt
);
847 while (strcmp (opcode
->name
, name
) == 0);
850 /* Analysis of 68HC11 and 68HC12 operands. */
852 /* reg_name_search() finds the register number given its name.
853 Returns the register number or REG_NONE on failure. */
855 reg_name_search (char *name
)
857 if (strcasecmp (name
, "x") == 0 || strcasecmp (name
, "ix") == 0)
859 if (strcasecmp (name
, "y") == 0 || strcasecmp (name
, "iy") == 0)
861 if (strcasecmp (name
, "a") == 0)
863 if (strcasecmp (name
, "b") == 0)
865 if (strcasecmp (name
, "d") == 0)
867 if (strcasecmp (name
, "sp") == 0)
869 if (strcasecmp (name
, "pc") == 0)
871 if (strcasecmp (name
, "ccr") == 0)
878 skip_whites (char *p
)
880 while (*p
== ' ' || *p
== '\t')
886 /* Check the string at input_line_pointer
887 to see if it is a valid register name. */
891 register_id reg_number
;
892 char c
, *p
= input_line_pointer
;
894 if (!is_name_beginner (*p
++))
897 while (is_part_of_name (*p
++))
904 /* Look to see if it's in the register table. */
905 reg_number
= reg_name_search (input_line_pointer
);
906 if (reg_number
!= REG_NONE
)
911 input_line_pointer
= p
;
919 #define M6811_OP_CALL_ADDR 0x00800000
920 #define M6811_OP_PAGE_ADDR 0x04000000
922 /* Parse a string of operands and return an array of expressions.
924 Operand mode[0] mode[1] exp[0] exp[1]
925 #n M6811_OP_IMM16 - O_*
926 *<exp> M6811_OP_DIRECT - O_*
927 .{+-}<exp> M6811_OP_JUMP_REL - O_*
928 <exp> M6811_OP_IND16 - O_*
929 ,r N,r M6812_OP_IDX M6812_OP_REG O_constant O_register
930 n,-r M6812_PRE_DEC M6812_OP_REG O_constant O_register
931 n,+r M6812_PRE_INC " "
932 n,r- M6812_POST_DEC " "
933 n,r+ M6812_POST_INC " "
934 A,r B,r D,r M6811_OP_REG M6812_OP_REG O_register O_register
935 [D,r] M6811_OP_D_IDX M6812_OP_REG O_register O_register
936 [n,r] M6811_OP_D_IDX_2 M6812_OP_REG O_constant O_register */
938 get_operand (operand
*oper
, int which
, long opmode
)
940 char *p
= input_line_pointer
;
944 oper
->exp
.X_op
= O_absent
;
945 oper
->reg1
= REG_NONE
;
946 oper
->reg2
= REG_NONE
;
947 mode
= M6811_OP_NONE
;
951 if (*p
== 0 || *p
== '\n' || *p
== '\r')
953 input_line_pointer
= p
;
957 if (*p
== '*' && (opmode
& (M6811_OP_DIRECT
| M6811_OP_IND16
)))
959 mode
= M6811_OP_DIRECT
;
964 if (!(opmode
& (M6811_OP_IMM8
| M6811_OP_IMM16
| M6811_OP_BITMASK
)))
966 as_bad (_("Immediate operand is not allowed for operand %d."),
971 mode
= M6811_OP_IMM16
;
973 if (strncmp (p
, "%hi", 3) == 0)
976 mode
|= M6811_OP_HIGH_ADDR
;
978 else if (strncmp (p
, "%lo", 3) == 0)
981 mode
|= M6811_OP_LOW_ADDR
;
983 /* %page modifier is used to obtain only the page number
984 of the address of a function. */
985 else if (strncmp (p
, "%page", 5) == 0)
988 mode
|= M6811_OP_PAGE_ADDR
;
991 /* %addr modifier is used to obtain the physical address part
992 of the function (16-bit). For 68HC12 the function will be
993 mapped in the 16K window at 0x8000 and the value will be
994 within that window (although the function address may not fit
995 in 16-bit). See bfd/elf32-m68hc12.c for the translation. */
996 else if (strncmp (p
, "%addr", 5) == 0)
999 mode
|= M6811_OP_CALL_ADDR
;
1002 else if (*p
== '.' && (p
[1] == '+' || p
[1] == '-'))
1005 mode
= M6811_OP_JUMP_REL
;
1009 if (current_architecture
& cpu6811
)
1010 as_bad (_("Indirect indexed addressing is not valid for 68HC11."));
1013 mode
= M6812_OP_D_IDX
;
1014 p
= skip_whites (p
);
1016 else if (*p
== ',') /* Special handling of ,x and ,y. */
1019 input_line_pointer
= p
;
1021 reg
= register_name ();
1022 if (reg
!= REG_NONE
)
1025 oper
->exp
.X_op
= O_constant
;
1026 oper
->exp
.X_add_number
= 0;
1027 oper
->mode
= M6812_OP_IDX
;
1030 as_bad (_("Spurious `,' or bad indirect register addressing mode."));
1033 /* Handle 68HC12 page specification in 'call foo,%page(bar)'. */
1034 else if ((opmode
& M6812_OP_PAGE
) && strncmp (p
, "%page", 5) == 0)
1037 mode
= M6811_OP_PAGE_ADDR
| M6812_OP_PAGE
| M6811_OP_IND16
;
1039 input_line_pointer
= p
;
1041 if (mode
== M6811_OP_NONE
|| mode
== M6812_OP_D_IDX
)
1042 reg
= register_name ();
1046 if (reg
!= REG_NONE
)
1048 p
= skip_whites (input_line_pointer
);
1049 if (*p
== ']' && mode
== M6812_OP_D_IDX
)
1052 (_("Missing second register or offset for indexed-indirect mode."));
1057 oper
->mode
= mode
| M6812_OP_REG
;
1060 if (mode
== M6812_OP_D_IDX
)
1062 as_bad (_("Missing second register for indexed-indirect mode."));
1069 input_line_pointer
= p
;
1070 reg
= register_name ();
1071 if (reg
!= REG_NONE
)
1073 p
= skip_whites (input_line_pointer
);
1074 if (mode
== M6812_OP_D_IDX
)
1078 as_bad (_("Missing `]' to close indexed-indirect mode."));
1082 oper
->mode
= M6812_OP_D_IDX
;
1084 input_line_pointer
= p
;
1092 /* In MRI mode, isolate the operand because we can't distinguish
1093 operands from comments. */
1098 p
= skip_whites (p
);
1099 while (*p
&& *p
!= ' ' && *p
!= '\t')
1108 /* Parse as an expression. */
1109 expression (&oper
->exp
);
1118 expression (&oper
->exp
);
1121 if (oper
->exp
.X_op
== O_illegal
)
1123 as_bad (_("Illegal operand."));
1126 else if (oper
->exp
.X_op
== O_absent
)
1128 as_bad (_("Missing operand."));
1132 p
= input_line_pointer
;
1134 if (mode
== M6811_OP_NONE
|| mode
== M6811_OP_DIRECT
1135 || mode
== M6812_OP_D_IDX
)
1137 p
= skip_whites (input_line_pointer
);
1141 int possible_mode
= M6811_OP_NONE
;
1142 char *old_input_line
;
1147 /* 68HC12 pre increment or decrement. */
1148 if (mode
== M6811_OP_NONE
)
1152 possible_mode
= M6812_PRE_DEC
;
1157 possible_mode
= M6812_PRE_INC
;
1160 p
= skip_whites (p
);
1162 input_line_pointer
= p
;
1163 reg
= register_name ();
1165 /* Backtrack if we have a valid constant expression and
1166 it does not correspond to the offset of the 68HC12 indexed
1167 addressing mode (as in N,x). */
1168 if (reg
== REG_NONE
&& mode
== M6811_OP_NONE
1169 && possible_mode
!= M6811_OP_NONE
)
1171 oper
->mode
= M6811_OP_IND16
| M6811_OP_JUMP_REL
;
1172 input_line_pointer
= skip_whites (old_input_line
);
1176 if (possible_mode
!= M6811_OP_NONE
)
1177 mode
= possible_mode
;
1179 if ((current_architecture
& cpu6811
)
1180 && possible_mode
!= M6811_OP_NONE
)
1181 as_bad (_("Pre-increment mode is not valid for 68HC11"));
1183 if (which
== 0 && opmode
& M6812_OP_IDX_P2
1184 && reg
!= REG_X
&& reg
!= REG_Y
1185 && reg
!= REG_PC
&& reg
!= REG_SP
)
1188 input_line_pointer
= p
;
1191 if (reg
== REG_NONE
&& mode
!= M6811_OP_DIRECT
1192 && !(mode
== M6811_OP_NONE
&& opmode
& M6811_OP_IND16
))
1194 as_bad (_("Wrong register in register indirect mode."));
1197 if (mode
== M6812_OP_D_IDX
)
1199 p
= skip_whites (input_line_pointer
);
1202 as_bad (_("Missing `]' to close register indirect operand."));
1205 input_line_pointer
= p
;
1207 oper
->mode
= M6812_OP_D_IDX_2
;
1210 if (reg
!= REG_NONE
)
1213 if (mode
== M6811_OP_NONE
)
1215 p
= input_line_pointer
;
1218 mode
= M6812_POST_DEC
;
1220 if (current_architecture
& cpu6811
)
1222 (_("Post-decrement mode is not valid for 68HC11."));
1226 mode
= M6812_POST_INC
;
1228 if (current_architecture
& cpu6811
)
1230 (_("Post-increment mode is not valid for 68HC11."));
1233 mode
= M6812_OP_IDX
;
1235 input_line_pointer
= p
;
1238 mode
|= M6812_OP_IDX
;
1243 input_line_pointer
= old_input_line
;
1246 if (mode
== M6812_OP_D_IDX_2
)
1248 as_bad (_("Invalid indexed indirect mode."));
1253 /* If the mode is not known until now, this is either a label
1254 or an indirect address. */
1255 if (mode
== M6811_OP_NONE
)
1256 mode
= M6811_OP_IND16
| M6811_OP_JUMP_REL
;
1258 p
= input_line_pointer
;
1259 while (*p
== ' ' || *p
== '\t')
1261 input_line_pointer
= p
;
1267 #define M6812_AUTO_INC_DEC (M6812_PRE_INC | M6812_PRE_DEC \
1268 | M6812_POST_INC | M6812_POST_DEC)
1270 /* Checks that the number 'num' fits for a given mode. */
1272 check_range (long num
, int mode
)
1274 /* Auto increment and decrement are ok for [-8..8] without 0. */
1275 if (mode
& M6812_AUTO_INC_DEC
)
1276 return (num
!= 0 && num
<= 8 && num
>= -8);
1278 /* The 68HC12 supports 5, 9 and 16-bit offsets. */
1279 if (mode
& (M6812_INDEXED_IND
| M6812_INDEXED
| M6812_OP_IDX
))
1280 mode
= M6811_OP_IND16
;
1282 if (mode
& M6812_OP_JUMP_REL16
)
1283 mode
= M6811_OP_IND16
;
1285 mode
&= ~M6811_OP_BRANCH
;
1290 case M6811_OP_DIRECT
:
1291 return (num
>= 0 && num
<= 255) ? 1 : 0;
1293 case M6811_OP_BITMASK
:
1296 return (((num
& 0xFFFFFF00) == 0) || ((num
& 0xFFFFFF00) == 0xFFFFFF00))
1299 case M6811_OP_JUMP_REL
:
1300 return (num
>= -128 && num
<= 127) ? 1 : 0;
1302 case M6811_OP_IND16
:
1303 case M6811_OP_IND16
| M6812_OP_PAGE
:
1304 case M6811_OP_IMM16
:
1305 return (((num
& 0xFFFF0000) == 0) || ((num
& 0xFFFF0000) == 0xFFFF0000))
1308 case M6812_OP_IBCC_MARKER
:
1309 case M6812_OP_TBCC_MARKER
:
1310 case M6812_OP_DBCC_MARKER
:
1311 return (num
>= -256 && num
<= 255) ? 1 : 0;
1313 case M6812_OP_TRAP_ID
:
1314 return ((num
>= 0x30 && num
<= 0x39)
1315 || (num
>= 0x40 && num
<= 0x0ff)) ? 1 : 0;
1322 /* Gas fixup generation. */
1324 /* Put a 1 byte expression described by 'oper'. If this expression contains
1325 unresolved symbols, generate an 8-bit fixup. */
1327 fixup8 (expressionS
*oper
, int mode
, int opmode
)
1333 if (oper
->X_op
== O_constant
)
1335 if (mode
& M6812_OP_TRAP_ID
1336 && !check_range (oper
->X_add_number
, M6812_OP_TRAP_ID
))
1338 static char trap_id_warn_once
= 0;
1340 as_bad (_("Trap id `%ld' is out of range."), oper
->X_add_number
);
1341 if (trap_id_warn_once
== 0)
1343 trap_id_warn_once
= 1;
1344 as_bad (_("Trap id must be within [0x30..0x39] or [0x40..0xff]."));
1348 if (!(mode
& M6812_OP_TRAP_ID
)
1349 && !check_range (oper
->X_add_number
, mode
))
1351 as_bad (_("Operand out of 8-bit range: `%ld'."), oper
->X_add_number
);
1353 number_to_chars_bigendian (f
, oper
->X_add_number
& 0x0FF, 1);
1355 else if (oper
->X_op
!= O_register
)
1357 if (mode
& M6812_OP_TRAP_ID
)
1358 as_bad (_("The trap id must be a constant."));
1360 if (mode
== M6811_OP_JUMP_REL
)
1364 fixp
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 1,
1365 oper
, TRUE
, BFD_RELOC_8_PCREL
);
1366 fixp
->fx_pcrel_adjust
= 1;
1373 /* Now create an 8-bit fixup. If there was some %hi, %lo
1374 or %page modifier, generate the reloc accordingly. */
1375 if (opmode
& M6811_OP_HIGH_ADDR
)
1376 reloc
= BFD_RELOC_M68HC11_HI8
;
1377 else if (opmode
& M6811_OP_LOW_ADDR
)
1378 reloc
= BFD_RELOC_M68HC11_LO8
;
1379 else if (opmode
& M6811_OP_PAGE_ADDR
)
1380 reloc
= BFD_RELOC_M68HC11_PAGE
;
1382 reloc
= BFD_RELOC_8
;
1384 fixp
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 1,
1385 oper
, FALSE
, reloc
);
1386 if (reloc
!= BFD_RELOC_8
)
1387 fixp
->fx_no_overflow
= 1;
1389 number_to_chars_bigendian (f
, 0, 1);
1393 as_fatal (_("Operand `%x' not recognized in fixup8."), oper
->X_op
);
1397 /* Put a 2 byte expression described by 'oper'. If this expression contains
1398 unresolved symbols, generate a 16-bit fixup. */
1400 fixup16 (expressionS
*oper
, int mode
, int opmode ATTRIBUTE_UNUSED
)
1406 if (oper
->X_op
== O_constant
)
1408 if (!check_range (oper
->X_add_number
, mode
))
1410 as_bad (_("Operand out of 16-bit range: `%ld'."),
1411 oper
->X_add_number
);
1413 number_to_chars_bigendian (f
, oper
->X_add_number
& 0x0FFFF, 2);
1415 else if (oper
->X_op
!= O_register
)
1420 if ((opmode
& M6811_OP_CALL_ADDR
) && (mode
& M6811_OP_IMM16
))
1421 reloc
= BFD_RELOC_M68HC11_LO16
;
1422 else if (mode
& M6812_OP_JUMP_REL16
)
1423 reloc
= BFD_RELOC_16_PCREL
;
1424 else if (mode
& M6812_OP_PAGE
)
1425 reloc
= BFD_RELOC_M68HC11_LO16
;
1427 reloc
= BFD_RELOC_16
;
1429 /* Now create a 16-bit fixup. */
1430 fixp
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 2,
1432 reloc
== BFD_RELOC_16_PCREL
,
1434 number_to_chars_bigendian (f
, 0, 2);
1435 if (reloc
== BFD_RELOC_16_PCREL
)
1436 fixp
->fx_pcrel_adjust
= 2;
1437 if (reloc
== BFD_RELOC_M68HC11_LO16
)
1438 fixp
->fx_no_overflow
= 1;
1442 as_fatal (_("Operand `%x' not recognized in fixup16."), oper
->X_op
);
1446 /* Put a 3 byte expression described by 'oper'. If this expression contains
1447 unresolved symbols, generate a 24-bit fixup. */
1449 fixup24 (expressionS
*oper
, int mode
, int opmode ATTRIBUTE_UNUSED
)
1455 if (oper
->X_op
== O_constant
)
1457 if (!check_range (oper
->X_add_number
, mode
))
1459 as_bad (_("Operand out of 16-bit range: `%ld'."),
1460 oper
->X_add_number
);
1462 number_to_chars_bigendian (f
, oper
->X_add_number
& 0x0FFFFFF, 3);
1464 else if (oper
->X_op
!= O_register
)
1468 /* Now create a 24-bit fixup. */
1469 fixp
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 3,
1470 oper
, FALSE
, BFD_RELOC_M68HC11_24
);
1471 number_to_chars_bigendian (f
, 0, 3);
1475 as_fatal (_("Operand `%x' not recognized in fixup16."), oper
->X_op
);
1479 /* 68HC11 and 68HC12 code generation. */
1481 /* Translate the short branch/bsr instruction into a long branch. */
1482 static unsigned char
1483 convert_branch (unsigned char code
)
1485 if (IS_OPCODE (code
, M6812_BSR
))
1487 else if (IS_OPCODE (code
, M6811_BSR
))
1489 else if (IS_OPCODE (code
, M6811_BRA
))
1490 return (current_architecture
& cpu6812
) ? M6812_JMP
: M6811_JMP
;
1492 as_fatal (_("Unexpected branch conversion with `%x'"), code
);
1494 /* Keep gcc happy. */
1498 /* Start a new insn that contains at least 'size' bytes. Record the
1499 line information of that insn in the dwarf2 debug sections. */
1501 m68hc11_new_insn (int size
)
1505 f
= frag_more (size
);
1507 dwarf2_emit_insn (size
);
1512 /* Builds a jump instruction (bra, bcc, bsr). */
1514 build_jump_insn (struct m68hc11_opcode
*opcode
, operand operands
[],
1515 int nb_operands
, int jmp_mode
)
1523 /* The relative branch conversion is not supported for
1525 gas_assert ((opcode
->format
& M6811_OP_BITMASK
) == 0);
1526 gas_assert (nb_operands
== 1);
1527 gas_assert (operands
[0].reg1
== REG_NONE
&& operands
[0].reg2
== REG_NONE
);
1529 code
= opcode
->opcode
;
1531 n
= operands
[0].exp
.X_add_number
;
1533 /* Turn into a long branch:
1534 - when force long branch option (and not for jbcc pseudos),
1535 - when jbcc and the constant is out of -128..127 range,
1536 - when branch optimization is allowed and branch out of range. */
1537 if ((jmp_mode
== 0 && flag_force_long_jumps
)
1538 || (operands
[0].exp
.X_op
== O_constant
1539 && (!check_range (n
, opcode
->format
) &&
1540 (jmp_mode
== 1 || flag_fixed_branches
== 0))))
1543 where
= frag_now_fix ();
1545 fix_new (frag_now
, frag_now_fix (), 0,
1546 &abs_symbol
, 0, 1, BFD_RELOC_M68HC11_RL_JUMP
);
1548 if (code
== M6811_BSR
|| code
== M6811_BRA
|| code
== M6812_BSR
)
1550 code
= convert_branch (code
);
1552 f
= m68hc11_new_insn (1);
1553 number_to_chars_bigendian (f
, code
, 1);
1555 else if (current_architecture
& cpu6812
)
1557 /* 68HC12: translate the bcc into a lbcc. */
1558 f
= m68hc11_new_insn (2);
1559 number_to_chars_bigendian (f
, M6811_OPCODE_PAGE2
, 1);
1560 number_to_chars_bigendian (f
+ 1, code
, 1);
1561 fixup16 (&operands
[0].exp
, M6812_OP_JUMP_REL16
,
1562 M6812_OP_JUMP_REL16
);
1567 /* 68HC11: translate the bcc into b!cc +3; jmp <L>. */
1568 f
= m68hc11_new_insn (3);
1570 number_to_chars_bigendian (f
, code
, 1);
1571 number_to_chars_bigendian (f
+ 1, 3, 1);
1572 number_to_chars_bigendian (f
+ 2, M6811_JMP
, 1);
1574 fixup16 (&operands
[0].exp
, M6811_OP_IND16
, M6811_OP_IND16
);
1578 /* Branch with a constant that must fit in 8-bits. */
1579 if (operands
[0].exp
.X_op
== O_constant
)
1581 if (!check_range (n
, opcode
->format
))
1583 as_bad (_("Operand out of range for a relative branch: `%ld'"),
1586 else if (opcode
->format
& M6812_OP_JUMP_REL16
)
1588 f
= m68hc11_new_insn (4);
1589 number_to_chars_bigendian (f
, M6811_OPCODE_PAGE2
, 1);
1590 number_to_chars_bigendian (f
+ 1, code
, 1);
1591 number_to_chars_bigendian (f
+ 2, n
& 0x0ffff, 2);
1595 f
= m68hc11_new_insn (2);
1596 number_to_chars_bigendian (f
, code
, 1);
1597 number_to_chars_bigendian (f
+ 1, n
& 0x0FF, 1);
1600 else if (opcode
->format
& M6812_OP_JUMP_REL16
)
1603 where
= frag_now_fix ();
1605 fix_new (frag_now
, frag_now_fix (), 0,
1606 &abs_symbol
, 0, 1, BFD_RELOC_M68HC11_RL_JUMP
);
1608 f
= m68hc11_new_insn (2);
1609 number_to_chars_bigendian (f
, M6811_OPCODE_PAGE2
, 1);
1610 number_to_chars_bigendian (f
+ 1, code
, 1);
1611 fixup16 (&operands
[0].exp
, M6812_OP_JUMP_REL16
, M6812_OP_JUMP_REL16
);
1618 where
= frag_now_fix ();
1620 fix_new (frag_now
, frag_now_fix (), 0,
1621 &abs_symbol
, 0, 1, BFD_RELOC_M68HC11_RL_JUMP
);
1623 /* Branch offset must fit in 8-bits, don't do some relax. */
1624 if (jmp_mode
== 0 && flag_fixed_branches
)
1626 op
= m68hc11_new_insn (1);
1627 number_to_chars_bigendian (op
, code
, 1);
1628 fixup8 (&operands
[0].exp
, M6811_OP_JUMP_REL
, M6811_OP_JUMP_REL
);
1631 /* bra/bsr made be changed into jmp/jsr. */
1632 else if (code
== M6811_BSR
|| code
== M6811_BRA
|| code
== M6812_BSR
)
1634 /* Allocate worst case storage. */
1635 op
= m68hc11_new_insn (3);
1636 number_to_chars_bigendian (op
, code
, 1);
1637 number_to_chars_bigendian (op
+ 1, 0, 1);
1638 frag_variant (rs_machine_dependent
, 1, 1,
1639 ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_UNDF
),
1640 operands
[0].exp
.X_add_symbol
, (offsetT
) n
,
1643 else if (current_architecture
& cpu6812
)
1645 op
= m68hc11_new_insn (2);
1646 number_to_chars_bigendian (op
, code
, 1);
1647 number_to_chars_bigendian (op
+ 1, 0, 1);
1648 frag_var (rs_machine_dependent
, 2, 2,
1649 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH_6812
, STATE_UNDF
),
1650 operands
[0].exp
.X_add_symbol
, (offsetT
) n
, op
);
1654 op
= m68hc11_new_insn (2);
1655 number_to_chars_bigendian (op
, code
, 1);
1656 number_to_chars_bigendian (op
+ 1, 0, 1);
1657 frag_var (rs_machine_dependent
, 3, 3,
1658 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_UNDF
),
1659 operands
[0].exp
.X_add_symbol
, (offsetT
) n
, op
);
1664 /* Builds a dbne/dbeq/tbne/tbeq instruction. */
1666 build_dbranch_insn (struct m68hc11_opcode
*opcode
, operand operands
[],
1667 int nb_operands
, int jmp_mode
)
1673 /* The relative branch conversion is not supported for
1675 gas_assert ((opcode
->format
& M6811_OP_BITMASK
) == 0);
1676 gas_assert (nb_operands
== 2);
1677 gas_assert (operands
[0].reg1
!= REG_NONE
);
1679 code
= opcode
->opcode
& 0x0FF;
1681 f
= m68hc11_new_insn (1);
1682 number_to_chars_bigendian (f
, code
, 1);
1684 n
= operands
[1].exp
.X_add_number
;
1685 code
= operands
[0].reg1
;
1687 if (operands
[0].reg1
== REG_NONE
|| operands
[0].reg1
== REG_CCR
1688 || operands
[0].reg1
== REG_PC
)
1689 as_bad (_("Invalid register for dbcc/tbcc instruction."));
1691 if (opcode
->format
& M6812_OP_IBCC_MARKER
)
1693 else if (opcode
->format
& M6812_OP_TBCC_MARKER
)
1696 if (!(opcode
->format
& M6812_OP_EQ_MARKER
))
1699 /* Turn into a long branch:
1700 - when force long branch option (and not for jbcc pseudos),
1701 - when jdbcc and the constant is out of -256..255 range,
1702 - when branch optimization is allowed and branch out of range. */
1703 if ((jmp_mode
== 0 && flag_force_long_jumps
)
1704 || (operands
[1].exp
.X_op
== O_constant
1705 && (!check_range (n
, M6812_OP_IBCC_MARKER
) &&
1706 (jmp_mode
== 1 || flag_fixed_branches
== 0))))
1710 number_to_chars_bigendian (f
, code
, 1);
1711 number_to_chars_bigendian (f
+ 1, M6812_JMP
, 1);
1712 fixup16 (&operands
[0].exp
, M6811_OP_IND16
, M6811_OP_IND16
);
1716 /* Branch with a constant that must fit in 9-bits. */
1717 if (operands
[1].exp
.X_op
== O_constant
)
1719 if (!check_range (n
, M6812_OP_IBCC_MARKER
))
1721 as_bad (_("Operand out of range for a relative branch: `%ld'"),
1730 number_to_chars_bigendian (f
, code
, 1);
1731 number_to_chars_bigendian (f
+ 1, n
& 0x0FF, 1);
1736 /* Branch offset must fit in 8-bits, don't do some relax. */
1737 if (jmp_mode
== 0 && flag_fixed_branches
)
1739 fixup8 (&operands
[0].exp
, M6811_OP_JUMP_REL
, M6811_OP_JUMP_REL
);
1745 number_to_chars_bigendian (f
, code
, 1);
1746 number_to_chars_bigendian (f
+ 1, 0, 1);
1747 frag_var (rs_machine_dependent
, 3, 3,
1748 ENCODE_RELAX (STATE_XBCC_BRANCH
, STATE_UNDF
),
1749 operands
[1].exp
.X_add_symbol
, (offsetT
) n
, f
);
1754 #define OP_EXTENDED (M6811_OP_PAGE2 | M6811_OP_PAGE3 | M6811_OP_PAGE4)
1756 /* Assemble the post index byte for 68HC12 extended addressing modes. */
1758 build_indexed_byte (operand
*op
, int format ATTRIBUTE_UNUSED
, int move_insn
)
1760 unsigned char byte
= 0;
1765 val
= op
->exp
.X_add_number
;
1767 if (mode
& M6812_AUTO_INC_DEC
)
1770 if (mode
& (M6812_POST_INC
| M6812_POST_DEC
))
1773 if (op
->exp
.X_op
== O_constant
)
1775 if (!check_range (val
, mode
))
1777 as_bad (_("Increment/decrement value is out of range: `%ld'."),
1780 if (mode
& (M6812_POST_INC
| M6812_PRE_INC
))
1781 byte
|= (val
- 1) & 0x07;
1783 byte
|= (8 - ((val
) & 7)) | 0x8;
1788 as_fatal (_("Expecting a register."));
1803 as_bad (_("Invalid register for post/pre increment."));
1808 number_to_chars_bigendian (f
, byte
, 1);
1812 if (mode
& (M6812_OP_IDX
| M6812_OP_D_IDX_2
))
1833 as_bad (_("Invalid register."));
1836 if (op
->exp
.X_op
== O_constant
)
1838 if (!check_range (val
, M6812_OP_IDX
))
1840 as_bad (_("Offset out of 16-bit range: %ld."), val
);
1843 if (move_insn
&& !(val
>= -16 && val
<= 15))
1845 as_bad (_("Offset out of 5-bit range for movw/movb insn: %ld."),
1850 if (val
>= -16 && val
<= 15 && !(mode
& M6812_OP_D_IDX_2
))
1855 number_to_chars_bigendian (f
, byte
, 1);
1858 else if (val
>= -256 && val
<= 255 && !(mode
& M6812_OP_D_IDX_2
))
1865 number_to_chars_bigendian (f
, byte
, 1);
1866 number_to_chars_bigendian (f
+ 1, val
& 0x0FF, 1);
1872 if (mode
& M6812_OP_D_IDX_2
)
1878 number_to_chars_bigendian (f
, byte
, 1);
1879 number_to_chars_bigendian (f
+ 1, val
& 0x0FFFF, 2);
1883 if (mode
& M6812_OP_D_IDX_2
)
1885 byte
= (byte
<< 3) | 0xe3;
1887 number_to_chars_bigendian (f
, byte
, 1);
1889 fixup16 (&op
->exp
, 0, 0);
1891 else if (op
->reg1
!= REG_PC
)
1897 number_to_chars_bigendian (f
, byte
, 1);
1898 sym
= op
->exp
.X_add_symbol
;
1899 off
= op
->exp
.X_add_number
;
1900 if (op
->exp
.X_op
!= O_symbol
)
1902 sym
= make_expr_symbol (&op
->exp
);
1905 /* movb/movw cannot be relaxed. */
1909 number_to_chars_bigendian (f
, byte
, 1);
1910 fix_new (frag_now
, f
- frag_now
->fr_literal
, 1,
1911 sym
, off
, 0, BFD_RELOC_M68HC12_5B
);
1916 number_to_chars_bigendian (f
, byte
, 1);
1917 frag_var (rs_machine_dependent
, 2, 2,
1918 ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_UNDF
),
1925 /* movb/movw cannot be relaxed. */
1929 number_to_chars_bigendian (f
, byte
, 1);
1930 fix_new (frag_now
, f
- frag_now
->fr_literal
, 1,
1931 op
->exp
.X_add_symbol
, op
->exp
.X_add_number
, 0, BFD_RELOC_M68HC12_5B
);
1936 number_to_chars_bigendian (f
, byte
, 1);
1937 frag_var (rs_machine_dependent
, 2, 2,
1938 ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_UNDF
),
1939 op
->exp
.X_add_symbol
,
1940 op
->exp
.X_add_number
, f
);
1946 if (mode
& (M6812_OP_REG
| M6812_OP_D_IDX
))
1948 if (mode
& M6812_OP_D_IDX
)
1950 if (op
->reg1
!= REG_D
)
1951 as_bad (_("Expecting register D for indexed indirect mode."));
1953 as_bad (_("Indexed indirect mode is not allowed for movb/movw."));
1970 as_bad (_("Invalid accumulator register."));
1995 as_bad (_("Invalid indexed register."));
1999 number_to_chars_bigendian (f
, byte
, 1);
2003 as_fatal (_("Addressing mode not implemented yet."));
2007 /* Assemble the 68HC12 register mode byte. */
2009 build_reg_mode (operand
*op
, int format
)
2014 if (format
& M6812_OP_SEX_MARKER
2015 && op
->reg1
!= REG_A
&& op
->reg1
!= REG_B
&& op
->reg1
!= REG_CCR
)
2016 as_bad (_("Invalid source register for this instruction, use 'tfr'."));
2017 else if (op
->reg1
== REG_NONE
|| op
->reg1
== REG_PC
)
2018 as_bad (_("Invalid source register."));
2020 if (format
& M6812_OP_SEX_MARKER
2021 && op
->reg2
!= REG_D
2022 && op
->reg2
!= REG_X
&& op
->reg2
!= REG_Y
&& op
->reg2
!= REG_SP
)
2023 as_bad (_("Invalid destination register for this instruction, use 'tfr'."));
2024 else if (op
->reg2
== REG_NONE
|| op
->reg2
== REG_PC
)
2025 as_bad (_("Invalid destination register."));
2027 byte
= (op
->reg1
<< 4) | (op
->reg2
);
2028 if (format
& M6812_OP_EXG_MARKER
)
2032 number_to_chars_bigendian (f
, byte
, 1);
2036 /* build_insn takes a pointer to the opcode entry in the opcode table,
2037 the array of operand expressions and builds the corresponding instruction.
2038 This operation only deals with non relative jumps insn (need special
2041 build_insn (struct m68hc11_opcode
*opcode
, operand operands
[],
2042 int nb_operands ATTRIBUTE_UNUSED
)
2049 /* Put the page code instruction if there is one. */
2050 format
= opcode
->format
;
2052 if (format
& M6811_OP_BRANCH
)
2053 fix_new (frag_now
, frag_now_fix (), 0,
2054 &abs_symbol
, 0, 1, BFD_RELOC_M68HC11_RL_JUMP
);
2056 if (format
& OP_EXTENDED
)
2060 f
= m68hc11_new_insn (2);
2061 if (format
& M6811_OP_PAGE2
)
2062 page_code
= M6811_OPCODE_PAGE2
;
2063 else if (format
& M6811_OP_PAGE3
)
2064 page_code
= M6811_OPCODE_PAGE3
;
2066 page_code
= M6811_OPCODE_PAGE4
;
2068 number_to_chars_bigendian (f
, page_code
, 1);
2072 f
= m68hc11_new_insn (1);
2074 number_to_chars_bigendian (f
, opcode
->opcode
, 1);
2078 /* The 68HC12 movb and movw instructions are special. We have to handle
2079 them in a special way. */
2080 if (format
& (M6812_OP_IND16_P2
| M6812_OP_IDX_P2
))
2083 if (format
& M6812_OP_IDX
)
2085 build_indexed_byte (&operands
[0], format
, 1);
2087 format
&= ~M6812_OP_IDX
;
2089 if (format
& M6812_OP_IDX_P2
)
2091 build_indexed_byte (&operands
[1], format
, 1);
2093 format
&= ~M6812_OP_IDX_P2
;
2097 if (format
& (M6811_OP_DIRECT
| M6811_OP_IMM8
))
2099 fixup8 (&operands
[i
].exp
,
2100 format
& (M6811_OP_DIRECT
| M6811_OP_IMM8
| M6812_OP_TRAP_ID
),
2104 else if (IS_CALL_SYMBOL (format
) && nb_operands
== 1)
2106 format
&= ~M6812_OP_PAGE
;
2107 fixup24 (&operands
[i
].exp
, format
& M6811_OP_IND16
,
2111 else if (format
& (M6811_OP_IMM16
| M6811_OP_IND16
))
2113 fixup16 (&operands
[i
].exp
,
2114 format
& (M6811_OP_IMM16
| M6811_OP_IND16
| M6812_OP_PAGE
),
2118 else if (format
& (M6811_OP_IX
| M6811_OP_IY
))
2120 if ((format
& M6811_OP_IX
) && (operands
[0].reg1
!= REG_X
))
2121 as_bad (_("Invalid indexed register, expecting register X."));
2122 if ((format
& M6811_OP_IY
) && (operands
[0].reg1
!= REG_Y
))
2123 as_bad (_("Invalid indexed register, expecting register Y."));
2125 fixup8 (&operands
[0].exp
, M6811_OP_IX
, operands
[0].mode
);
2129 (M6812_OP_IDX
| M6812_OP_IDX_2
| M6812_OP_IDX_1
2130 | M6812_OP_D_IDX
| M6812_OP_D_IDX_2
))
2132 build_indexed_byte (&operands
[i
], format
, move_insn
);
2135 else if (format
& M6812_OP_REG
&& current_architecture
& cpu6812
)
2137 build_reg_mode (&operands
[i
], format
);
2140 if (format
& M6811_OP_BITMASK
)
2142 fixup8 (&operands
[i
].exp
, M6811_OP_BITMASK
, operands
[i
].mode
);
2145 if (format
& M6811_OP_JUMP_REL
)
2147 fixup8 (&operands
[i
].exp
, M6811_OP_JUMP_REL
, operands
[i
].mode
);
2149 else if (format
& M6812_OP_IND16_P2
)
2151 fixup16 (&operands
[1].exp
, M6811_OP_IND16
, operands
[1].mode
);
2153 if (format
& M6812_OP_PAGE
)
2155 fixup8 (&operands
[i
].exp
, M6812_OP_PAGE
, operands
[i
].mode
);
2159 /* Opcode identification and operand analysis. */
2161 /* find() gets a pointer to an entry in the opcode table. It must look at all
2162 opcodes with the same name and use the operands to choose the correct
2163 opcode. Returns the opcode pointer if there was a match and 0 if none. */
2164 static struct m68hc11_opcode
*
2165 find (struct m68hc11_opcode_def
*opc
, operand operands
[], int nb_operands
)
2168 struct m68hc11_opcode
*opcode
;
2169 struct m68hc11_opcode
*op_indirect
;
2172 opcode
= opc
->opcode
;
2174 /* Now search the opcode table table for one with operands
2175 that matches what we've got. We're only done if the operands matched so
2176 far AND there are no more to check. */
2177 for (pos
= match
= 0; match
== 0 && pos
< opc
->nb_modes
; pos
++, opcode
++)
2179 int poss_indirect
= 0;
2180 long format
= opcode
->format
;
2184 if (opcode
->format
& M6811_OP_MASK
)
2186 if (opcode
->format
& M6811_OP_BITMASK
)
2188 if (opcode
->format
& (M6811_OP_JUMP_REL
| M6812_OP_JUMP_REL16
))
2190 if (opcode
->format
& (M6812_OP_IND16_P2
| M6812_OP_IDX_P2
))
2192 if ((opcode
->format
& M6812_OP_PAGE
)
2193 && (!IS_CALL_SYMBOL (opcode
->format
) || nb_operands
== 2))
2196 for (i
= 0; expect
== nb_operands
&& i
< nb_operands
; i
++)
2198 int mode
= operands
[i
].mode
;
2200 if (mode
& M6811_OP_IMM16
)
2203 (M6811_OP_IMM8
| M6811_OP_IMM16
| M6811_OP_BITMASK
))
2207 if (mode
== M6811_OP_DIRECT
)
2209 if (format
& M6811_OP_DIRECT
)
2212 /* If the operand is a page 0 operand, remember a
2213 possible <abs-16> addressing mode. We mark
2214 this and continue to check other operands. */
2215 if (format
& M6811_OP_IND16
2216 && flag_strict_direct_addressing
&& op_indirect
== 0)
2223 if (mode
& M6811_OP_IND16
)
2225 if (i
== 0 && (format
& M6811_OP_IND16
) != 0)
2227 if (i
!= 0 && (format
& M6812_OP_PAGE
) != 0)
2229 if (i
!= 0 && (format
& M6812_OP_IND16_P2
) != 0)
2231 if (i
== 0 && (format
& M6811_OP_BITMASK
))
2234 if (mode
& (M6811_OP_JUMP_REL
| M6812_OP_JUMP_REL16
))
2236 if (format
& (M6811_OP_JUMP_REL
| M6812_OP_JUMP_REL16
))
2239 if (mode
& M6812_OP_REG
)
2242 && (format
& M6812_OP_REG
)
2243 && (operands
[i
].reg2
== REG_NONE
))
2246 && (format
& M6812_OP_REG
)
2247 && (format
& M6812_OP_REG_2
)
2248 && (operands
[i
].reg2
!= REG_NONE
))
2251 && (format
& M6812_OP_IDX
)
2252 && (operands
[i
].reg2
!= REG_NONE
))
2255 && (format
& M6812_OP_IDX
)
2256 && (format
& (M6812_OP_IND16_P2
| M6812_OP_IDX_P2
)))
2259 && (format
& M6812_OP_IDX_P2
))
2263 if (mode
& M6812_OP_IDX
)
2265 if (format
& M6811_OP_IX
&& operands
[i
].reg1
== REG_X
)
2267 if (format
& M6811_OP_IY
&& operands
[i
].reg1
== REG_Y
)
2270 && format
& (M6812_OP_IDX
| M6812_OP_IDX_1
| M6812_OP_IDX_2
)
2271 && (operands
[i
].reg1
== REG_X
2272 || operands
[i
].reg1
== REG_Y
2273 || operands
[i
].reg1
== REG_SP
2274 || operands
[i
].reg1
== REG_PC
))
2276 if (i
== 1 && format
& M6812_OP_IDX_P2
)
2279 if (mode
& format
& (M6812_OP_D_IDX
| M6812_OP_D_IDX_2
))
2284 if (mode
& M6812_AUTO_INC_DEC
)
2287 && format
& (M6812_OP_IDX
| M6812_OP_IDX_1
|
2290 if (i
== 1 && format
& M6812_OP_IDX_P2
)
2295 match
= i
== nb_operands
;
2297 /* Operands are ok but an operand uses page 0 addressing mode
2298 while the insn supports abs-16 mode. Keep a reference to this
2299 insns in case there is no insn supporting page 0 addressing. */
2300 if (match
&& poss_indirect
)
2302 op_indirect
= opcode
;
2309 /* Page 0 addressing is used but not supported by any insn.
2310 If absolute addresses are supported, we use that insn. */
2311 if (match
== 0 && op_indirect
)
2313 opcode
= op_indirect
;
2325 /* Find the real opcode and its associated operands. We use a progressive
2326 approach here. On entry, 'opc' points to the first opcode in the
2327 table that matches the opcode name in the source line. We try to
2328 isolate an operand, find a possible match in the opcode table.
2329 We isolate another operand if no match were found. The table 'operands'
2330 is filled while operands are recognized.
2332 Returns the opcode pointer that matches the opcode name in the
2333 source line and the associated operands. */
2334 static struct m68hc11_opcode
*
2335 find_opcode (struct m68hc11_opcode_def
*opc
, operand operands
[],
2338 struct m68hc11_opcode
*opcode
;
2341 if (opc
->max_operands
== 0)
2347 for (i
= 0; i
< opc
->max_operands
;)
2351 result
= get_operand (&operands
[i
], i
, opc
->format
);
2355 /* Special case where the bitmask of the bclr/brclr
2356 instructions is not introduced by #.
2357 Example: bclr 3,x $80. */
2358 if (i
== 1 && (opc
->format
& M6811_OP_BITMASK
)
2359 && (operands
[i
].mode
& M6811_OP_IND16
))
2361 operands
[i
].mode
= M6811_OP_IMM16
;
2366 if (i
>= opc
->min_operands
)
2368 opcode
= find (opc
, operands
, i
);
2370 /* Another special case for 'call foo,page' instructions.
2371 Since we support 'call foo' and 'call foo,page' we must look
2372 if the optional page specification is present otherwise we will
2373 assemble immediately and treat the page spec as garbage. */
2374 if (opcode
&& !(opcode
->format
& M6812_OP_PAGE
))
2377 if (opcode
&& *input_line_pointer
!= ',')
2381 if (*input_line_pointer
== ',')
2382 input_line_pointer
++;
2388 #define M6812_XBCC_MARKER (M6812_OP_TBCC_MARKER \
2389 | M6812_OP_DBCC_MARKER \
2390 | M6812_OP_IBCC_MARKER)
2392 /* Gas line assembler entry point. */
2394 /* This is the main entry point for the machine-dependent assembler. str
2395 points to a machine-dependent instruction. This function is supposed to
2396 emit the frags/bytes it assembles to. */
2398 md_assemble (char *str
)
2400 struct m68hc11_opcode_def
*opc
;
2401 struct m68hc11_opcode
*opcode
;
2403 unsigned char *op_start
, *op_end
;
2407 operand operands
[M6811_MAX_OPERANDS
];
2408 int nb_operands
= 0;
2409 int branch_optimize
= 0;
2412 /* Drop leading whitespace. */
2416 /* Find the opcode end and get the opcode in 'name'. The opcode is forced
2417 lower case (the opcode table only has lower case op-codes). */
2418 for (op_start
= op_end
= (unsigned char *) str
;
2419 *op_end
&& nlen
< 20 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
2422 name
[nlen
] = TOLOWER (op_start
[nlen
]);
2429 as_bad (_("No instruction or missing opcode."));
2433 /* Find the opcode definition given its name. */
2434 opc
= (struct m68hc11_opcode_def
*) hash_find (m68hc11_hash
, name
);
2436 /* If it's not recognized, look for 'jbsr' and 'jbxx'. These are
2437 pseudo insns for relative branch. For these branches, we always
2438 optimize them (turned into absolute branches) even if --short-branches
2440 if (opc
== NULL
&& name
[0] == 'j' && name
[1] == 'b')
2442 opc
= (struct m68hc11_opcode_def
*) hash_find (m68hc11_hash
, &name
[1]);
2444 && (!(opc
->format
& M6811_OP_JUMP_REL
)
2445 || (opc
->format
& M6811_OP_BITMASK
)))
2448 branch_optimize
= 1;
2451 /* The following test should probably be removed. This is not conform
2452 to Motorola assembler specs. */
2453 if (opc
== NULL
&& flag_mri
)
2455 if (*op_end
== ' ' || *op_end
== '\t')
2457 while (*op_end
== ' ' || *op_end
== '\t')
2462 (is_end_of_line
[op_end
[1]]
2463 || op_end
[1] == ' ' || op_end
[1] == '\t'
2464 || !ISALNUM (op_end
[1])))
2465 && (*op_end
== 'a' || *op_end
== 'b'
2466 || *op_end
== 'A' || *op_end
== 'B'
2467 || *op_end
== 'd' || *op_end
== 'D'
2468 || *op_end
== 'x' || *op_end
== 'X'
2469 || *op_end
== 'y' || *op_end
== 'Y'))
2471 name
[nlen
++] = TOLOWER (*op_end
++);
2473 opc
= (struct m68hc11_opcode_def
*) hash_find (m68hc11_hash
,
2479 /* Identify a possible instruction alias. There are some on the
2480 68HC12 to emulate a few 68HC11 instructions. */
2481 if (opc
== NULL
&& (current_architecture
& cpu6812
))
2485 for (i
= 0; i
< m68hc12_num_alias
; i
++)
2486 if (strcmp (m68hc12_alias
[i
].name
, name
) == 0)
2492 if (opc
== NULL
&& alias_id
< 0)
2494 as_bad (_("Opcode `%s' is not recognized."), name
);
2497 save
= input_line_pointer
;
2498 input_line_pointer
= (char *) op_end
;
2503 opcode
= find_opcode (opc
, operands
, &nb_operands
);
2508 if ((opcode
|| alias_id
>= 0) && !flag_mri
)
2510 char *p
= input_line_pointer
;
2512 while (*p
== ' ' || *p
== '\t' || *p
== '\n' || *p
== '\r')
2515 if (*p
!= '\n' && *p
)
2516 as_bad (_("Garbage at end of instruction: `%s'."), p
);
2519 input_line_pointer
= save
;
2523 char *f
= m68hc11_new_insn (m68hc12_alias
[alias_id
].size
);
2525 number_to_chars_bigendian (f
, m68hc12_alias
[alias_id
].code1
, 1);
2526 if (m68hc12_alias
[alias_id
].size
> 1)
2527 number_to_chars_bigendian (f
+ 1, m68hc12_alias
[alias_id
].code2
, 1);
2532 /* Opcode is known but does not have valid operands. Print out the
2533 syntax for this opcode. */
2536 if (flag_print_insn_syntax
)
2537 print_insn_format (name
);
2539 as_bad (_("Invalid operand for `%s'"), name
);
2543 /* Treat dbeq/ibeq/tbeq instructions in a special way. The branch is
2544 relative and must be in the range -256..255 (9-bits). */
2545 if ((opcode
->format
& M6812_XBCC_MARKER
)
2546 && (opcode
->format
& M6811_OP_JUMP_REL
))
2547 build_dbranch_insn (opcode
, operands
, nb_operands
, branch_optimize
);
2549 /* Relative jumps instructions are taken care of separately. We have to make
2550 sure that the relative branch is within the range -128..127. If it's out
2551 of range, the instructions are changed into absolute instructions.
2552 This is not supported for the brset and brclr instructions. */
2553 else if ((opcode
->format
& (M6811_OP_JUMP_REL
| M6812_OP_JUMP_REL16
))
2554 && !(opcode
->format
& M6811_OP_BITMASK
))
2555 build_jump_insn (opcode
, operands
, nb_operands
, branch_optimize
);
2557 build_insn (opcode
, operands
, nb_operands
);
2561 /* Pseudo op to control the ELF flags. */
2563 s_m68hc11_mode (int x ATTRIBUTE_UNUSED
)
2565 char *name
= input_line_pointer
, ch
;
2567 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2568 input_line_pointer
++;
2569 ch
= *input_line_pointer
;
2570 *input_line_pointer
= '\0';
2572 if (strcmp (name
, "mshort") == 0)
2574 elf_flags
&= ~E_M68HC11_I32
;
2576 else if (strcmp (name
, "mlong") == 0)
2578 elf_flags
|= E_M68HC11_I32
;
2580 else if (strcmp (name
, "mshort-double") == 0)
2582 elf_flags
&= ~E_M68HC11_F64
;
2584 else if (strcmp (name
, "mlong-double") == 0)
2586 elf_flags
|= E_M68HC11_F64
;
2590 as_warn (_("Invalid mode: %s\n"), name
);
2592 *input_line_pointer
= ch
;
2593 demand_empty_rest_of_line ();
2596 /* Mark the symbols with STO_M68HC12_FAR to indicate the functions
2597 are using 'rtc' for returning. It is necessary to use 'call'
2598 to invoke them. This is also used by the debugger to correctly
2599 find the stack frame. */
2601 s_m68hc11_mark_symbol (int mark
)
2607 elf_symbol_type
*elfsym
;
2611 name
= input_line_pointer
;
2612 c
= get_symbol_end ();
2613 symbolP
= symbol_find_or_make (name
);
2614 *input_line_pointer
= c
;
2618 bfdsym
= symbol_get_bfdsym (symbolP
);
2619 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
2621 gas_assert (elfsym
);
2623 /* Mark the symbol far (using rtc for function return). */
2624 elfsym
->internal_elf_sym
.st_other
|= mark
;
2628 input_line_pointer
++;
2632 if (*input_line_pointer
== '\n')
2638 demand_empty_rest_of_line ();
2642 s_m68hc11_relax (int ignore ATTRIBUTE_UNUSED
)
2648 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
2650 as_bad (_("bad .relax format"));
2651 ignore_rest_of_line ();
2655 fix_new_exp (frag_now
, frag_now_fix (), 0, &ex
, 1,
2656 BFD_RELOC_M68HC11_RL_GROUP
);
2658 demand_empty_rest_of_line ();
2662 /* Relocation, relaxation and frag conversions. */
2664 /* PC-relative offsets are relative to the start of the
2665 next instruction. That is, the address of the offset, plus its
2666 size, since the offset is always the last part of the insn. */
2668 md_pcrel_from (fixS
*fixP
)
2670 if (fixP
->fx_r_type
== BFD_RELOC_M68HC11_RL_JUMP
)
2673 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2676 /* If while processing a fixup, a reloc really needs to be created
2677 then it is done here. */
2679 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
2683 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2684 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2685 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2686 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2687 if (fixp
->fx_r_type
== 0)
2688 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_16
);
2690 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2691 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2693 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2694 _("Relocation %d is not supported by object file format."),
2695 (int) fixp
->fx_r_type
);
2699 /* Since we use Rel instead of Rela, encode the vtable entry to be
2700 used in the relocation's section offset. */
2701 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2702 reloc
->address
= fixp
->fx_offset
;
2708 /* We need a port-specific relaxation function to cope with sym2 - sym1
2709 relative expressions with both symbols in the same segment (but not
2710 necessarily in the same frag as this insn), for example:
2711 ldab sym2-(sym1-2),pc
2713 The offset can be 5, 9 or 16 bits long. */
2716 m68hc11_relax_frag (segT seg ATTRIBUTE_UNUSED
, fragS
*fragP
,
2717 long stretch ATTRIBUTE_UNUSED
)
2722 const relax_typeS
*this_type
;
2723 const relax_typeS
*start_type
;
2724 relax_substateT next_state
;
2725 relax_substateT this_state
;
2726 const relax_typeS
*table
= TC_GENERIC_RELAX_TABLE
;
2728 /* We only have to cope with frags as prepared by
2729 md_estimate_size_before_relax. The STATE_BITS16 case may geet here
2730 because of the different reasons that it's not relaxable. */
2731 switch (fragP
->fr_subtype
)
2733 case ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_BITS16
):
2734 case ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_BITS16
):
2735 /* When we get to this state, the frag won't grow any more. */
2738 case ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_BITS5
):
2739 case ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_BITS5
):
2740 case ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_BITS9
):
2741 case ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_BITS9
):
2742 if (fragP
->fr_symbol
== NULL
2743 || S_GET_SEGMENT (fragP
->fr_symbol
) != absolute_section
)
2744 as_fatal (_("internal inconsistency problem in %s: fr_symbol %lx"),
2745 __FUNCTION__
, (long) fragP
->fr_symbol
);
2746 symbolP
= fragP
->fr_symbol
;
2747 if (symbol_resolved_p (symbolP
))
2748 as_fatal (_("internal inconsistency problem in %s: resolved symbol"),
2750 aim
= S_GET_VALUE (symbolP
);
2754 as_fatal (_("internal inconsistency problem in %s: fr_subtype %d"),
2755 __FUNCTION__
, fragP
->fr_subtype
);
2758 /* The rest is stolen from relax_frag. There's no obvious way to
2759 share the code, but fortunately no requirement to keep in sync as
2760 long as fragP->fr_symbol does not have its segment changed. */
2762 this_state
= fragP
->fr_subtype
;
2763 start_type
= this_type
= table
+ this_state
;
2767 /* Look backwards. */
2768 for (next_state
= this_type
->rlx_more
; next_state
;)
2769 if (aim
>= this_type
->rlx_backward
)
2773 /* Grow to next state. */
2774 this_state
= next_state
;
2775 this_type
= table
+ this_state
;
2776 next_state
= this_type
->rlx_more
;
2781 /* Look forwards. */
2782 for (next_state
= this_type
->rlx_more
; next_state
;)
2783 if (aim
<= this_type
->rlx_forward
)
2787 /* Grow to next state. */
2788 this_state
= next_state
;
2789 this_type
= table
+ this_state
;
2790 next_state
= this_type
->rlx_more
;
2794 growth
= this_type
->rlx_length
- start_type
->rlx_length
;
2796 fragP
->fr_subtype
= this_state
;
2801 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec ATTRIBUTE_UNUSED
,
2807 char *buffer_address
= fragP
->fr_literal
;
2809 /* Address in object code of the displacement. */
2810 register int object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
2812 buffer_address
+= fragP
->fr_fix
;
2814 /* The displacement of the address, from current location. */
2815 value
= S_GET_VALUE (fragP
->fr_symbol
);
2816 disp
= (value
+ fragP
->fr_offset
) - object_address
;
2818 switch (fragP
->fr_subtype
)
2820 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
):
2821 fragP
->fr_opcode
[1] = disp
;
2824 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_WORD
):
2825 /* This relax is only for bsr and bra. */
2826 gas_assert (IS_OPCODE (fragP
->fr_opcode
[0], M6811_BSR
)
2827 || IS_OPCODE (fragP
->fr_opcode
[0], M6811_BRA
)
2828 || IS_OPCODE (fragP
->fr_opcode
[0], M6812_BSR
));
2830 fragP
->fr_opcode
[0] = convert_branch (fragP
->fr_opcode
[0]);
2832 fix_new (fragP
, fragP
->fr_fix
- 1, 2,
2833 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_16
);
2837 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
2838 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH_6812
, STATE_BYTE
):
2839 fragP
->fr_opcode
[1] = disp
;
2842 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
2843 /* Invert branch. */
2844 fragP
->fr_opcode
[0] ^= 1;
2845 fragP
->fr_opcode
[1] = 3; /* Branch offset. */
2846 buffer_address
[0] = M6811_JMP
;
2847 fix_new (fragP
, fragP
->fr_fix
+ 1, 2,
2848 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_16
);
2852 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH_6812
, STATE_WORD
):
2853 /* Translate branch into a long branch. */
2854 fragP
->fr_opcode
[1] = fragP
->fr_opcode
[0];
2855 fragP
->fr_opcode
[0] = M6811_OPCODE_PAGE2
;
2857 fixp
= fix_new (fragP
, fragP
->fr_fix
, 2,
2858 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2859 BFD_RELOC_16_PCREL
);
2860 fixp
->fx_pcrel_adjust
= 2;
2864 case ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_BITS5
):
2865 if (fragP
->fr_symbol
!= 0
2866 && S_GET_SEGMENT (fragP
->fr_symbol
) != absolute_section
)
2870 case ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_BITS5
):
2871 fragP
->fr_opcode
[0] = fragP
->fr_opcode
[0] << 6;
2872 fragP
->fr_opcode
[0] |= value
& 0x1f;
2875 case ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_BITS9
):
2876 /* For a PC-relative offset, use the displacement with a -1 correction
2877 to take into account the additional byte of the insn. */
2878 if (fragP
->fr_symbol
!= 0
2879 && S_GET_SEGMENT (fragP
->fr_symbol
) != absolute_section
)
2883 case ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_BITS9
):
2884 fragP
->fr_opcode
[0] = (fragP
->fr_opcode
[0] << 3);
2885 fragP
->fr_opcode
[0] |= 0xE0;
2886 fragP
->fr_opcode
[0] |= (value
>> 8) & 1;
2887 fragP
->fr_opcode
[1] = value
;
2891 case ENCODE_RELAX (STATE_INDEXED_PCREL
, STATE_BITS16
):
2892 case ENCODE_RELAX (STATE_INDEXED_OFFSET
, STATE_BITS16
):
2893 fragP
->fr_opcode
[0] = (fragP
->fr_opcode
[0] << 3);
2894 fragP
->fr_opcode
[0] |= 0xe2;
2895 if ((fragP
->fr_opcode
[0] & 0x0ff) == 0x0fa
2896 && fragP
->fr_symbol
!= 0
2897 && S_GET_SEGMENT (fragP
->fr_symbol
) != absolute_section
)
2899 fixp
= fix_new (fragP
, fragP
->fr_fix
, 2,
2900 fragP
->fr_symbol
, fragP
->fr_offset
,
2901 1, BFD_RELOC_16_PCREL
);
2905 fix_new (fragP
, fragP
->fr_fix
, 2,
2906 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_16
);
2911 case ENCODE_RELAX (STATE_XBCC_BRANCH
, STATE_BYTE
):
2913 fragP
->fr_opcode
[0] |= 0x10;
2915 fragP
->fr_opcode
[1] = disp
& 0x0FF;
2918 case ENCODE_RELAX (STATE_XBCC_BRANCH
, STATE_WORD
):
2919 /* Invert branch. */
2920 fragP
->fr_opcode
[0] ^= 0x20;
2921 fragP
->fr_opcode
[1] = 3; /* Branch offset. */
2922 buffer_address
[0] = M6812_JMP
;
2923 fix_new (fragP
, fragP
->fr_fix
+ 1, 2,
2924 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_16
);
2933 /* On an ELF system, we can't relax a weak symbol. The weak symbol
2934 can be overridden at final link time by a non weak symbol. We can
2935 relax externally visible symbol because there is no shared library
2936 and such symbol can't be overridden (unless they are weak). */
2938 relaxable_symbol (symbolS
*symbol
)
2940 return ! S_IS_WEAK (symbol
);
2943 /* Force truly undefined symbols to their maximum size, and generally set up
2944 the frag list to be relaxed. */
2946 md_estimate_size_before_relax (fragS
*fragP
, asection
*segment
)
2948 if (RELAX_LENGTH (fragP
->fr_subtype
) == STATE_UNDF
)
2950 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
2951 || !relaxable_symbol (fragP
->fr_symbol
)
2952 || (segment
!= absolute_section
2953 && RELAX_STATE (fragP
->fr_subtype
) == STATE_INDEXED_OFFSET
))
2955 /* Non-relaxable cases. */
2957 char *buffer_address
;
2959 old_fr_fix
= fragP
->fr_fix
;
2960 buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
2962 switch (RELAX_STATE (fragP
->fr_subtype
))
2964 case STATE_PC_RELATIVE
:
2966 /* This relax is only for bsr and bra. */
2967 gas_assert (IS_OPCODE (fragP
->fr_opcode
[0], M6811_BSR
)
2968 || IS_OPCODE (fragP
->fr_opcode
[0], M6811_BRA
)
2969 || IS_OPCODE (fragP
->fr_opcode
[0], M6812_BSR
));
2971 if (flag_fixed_branches
)
2972 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2973 _("bra or bsr with undefined symbol."));
2975 /* The symbol is undefined or in a separate section.
2976 Turn bra into a jmp and bsr into a jsr. The insn
2977 becomes 3 bytes long (instead of 2). A fixup is
2978 necessary for the unresolved symbol address. */
2979 fragP
->fr_opcode
[0] = convert_branch (fragP
->fr_opcode
[0]);
2981 fix_new (fragP
, fragP
->fr_fix
- 1, 2, fragP
->fr_symbol
,
2982 fragP
->fr_offset
, 0, BFD_RELOC_16
);
2986 case STATE_CONDITIONAL_BRANCH
:
2987 gas_assert (current_architecture
& cpu6811
);
2989 fragP
->fr_opcode
[0] ^= 1; /* Reverse sense of branch. */
2990 fragP
->fr_opcode
[1] = 3; /* Skip next jmp insn (3 bytes). */
2992 /* Don't use fr_opcode[2] because this may be
2993 in a different frag. */
2994 buffer_address
[0] = M6811_JMP
;
2997 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
2998 fragP
->fr_offset
, 0, BFD_RELOC_16
);
3002 case STATE_INDEXED_OFFSET
:
3003 gas_assert (current_architecture
& cpu6812
);
3005 if (fragP
->fr_symbol
3006 && S_GET_SEGMENT (fragP
->fr_symbol
) == absolute_section
)
3008 fragP
->fr_subtype
= ENCODE_RELAX (STATE_INDEXED_OFFSET
,
3010 /* Return the size of the variable part of the frag. */
3011 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
3015 /* Switch the indexed operation to 16-bit mode. */
3016 fragP
->fr_opcode
[0] = fragP
->fr_opcode
[0] << 3;
3017 fragP
->fr_opcode
[0] |= 0xe2;
3018 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3019 fragP
->fr_offset
, 0, BFD_RELOC_16
);
3024 case STATE_INDEXED_PCREL
:
3025 gas_assert (current_architecture
& cpu6812
);
3027 if (fragP
->fr_symbol
3028 && S_GET_SEGMENT (fragP
->fr_symbol
) == absolute_section
)
3030 fragP
->fr_subtype
= ENCODE_RELAX (STATE_INDEXED_PCREL
,
3032 /* Return the size of the variable part of the frag. */
3033 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
3039 fragP
->fr_opcode
[0] = fragP
->fr_opcode
[0] << 3;
3040 fragP
->fr_opcode
[0] |= 0xe2;
3041 fixp
= fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3042 fragP
->fr_offset
, 1, BFD_RELOC_16_PCREL
);
3047 case STATE_XBCC_BRANCH
:
3048 gas_assert (current_architecture
& cpu6812
);
3050 fragP
->fr_opcode
[0] ^= 0x20; /* Reverse sense of branch. */
3051 fragP
->fr_opcode
[1] = 3; /* Skip next jmp insn (3 bytes). */
3053 /* Don't use fr_opcode[2] because this may be
3054 in a different frag. */
3055 buffer_address
[0] = M6812_JMP
;
3058 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3059 fragP
->fr_offset
, 0, BFD_RELOC_16
);
3063 case STATE_CONDITIONAL_BRANCH_6812
:
3064 gas_assert (current_architecture
& cpu6812
);
3066 /* Translate into a lbcc branch. */
3067 fragP
->fr_opcode
[1] = fragP
->fr_opcode
[0];
3068 fragP
->fr_opcode
[0] = M6811_OPCODE_PAGE2
;
3070 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
3071 fragP
->fr_offset
, 1, BFD_RELOC_16_PCREL
);
3076 as_fatal (_("Subtype %d is not recognized."), fragP
->fr_subtype
);
3080 /* Return the growth in the fixed part of the frag. */
3081 return fragP
->fr_fix
- old_fr_fix
;
3084 /* Relaxable cases. */
3085 switch (RELAX_STATE (fragP
->fr_subtype
))
3087 case STATE_PC_RELATIVE
:
3088 /* This relax is only for bsr and bra. */
3089 gas_assert (IS_OPCODE (fragP
->fr_opcode
[0], M6811_BSR
)
3090 || IS_OPCODE (fragP
->fr_opcode
[0], M6811_BRA
)
3091 || IS_OPCODE (fragP
->fr_opcode
[0], M6812_BSR
));
3093 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
);
3096 case STATE_CONDITIONAL_BRANCH
:
3097 gas_assert (current_architecture
& cpu6811
);
3099 fragP
->fr_subtype
= ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
,
3103 case STATE_INDEXED_OFFSET
:
3104 gas_assert (current_architecture
& cpu6812
);
3106 fragP
->fr_subtype
= ENCODE_RELAX (STATE_INDEXED_OFFSET
,
3110 case STATE_INDEXED_PCREL
:
3111 gas_assert (current_architecture
& cpu6812
);
3113 fragP
->fr_subtype
= ENCODE_RELAX (STATE_INDEXED_PCREL
,
3117 case STATE_XBCC_BRANCH
:
3118 gas_assert (current_architecture
& cpu6812
);
3120 fragP
->fr_subtype
= ENCODE_RELAX (STATE_XBCC_BRANCH
, STATE_BYTE
);
3123 case STATE_CONDITIONAL_BRANCH_6812
:
3124 gas_assert (current_architecture
& cpu6812
);
3126 fragP
->fr_subtype
= ENCODE_RELAX (STATE_CONDITIONAL_BRANCH_6812
,
3132 if (fragP
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
3133 as_fatal (_("Subtype %d is not recognized."), fragP
->fr_subtype
);
3135 /* Return the size of the variable part of the frag. */
3136 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
3139 /* See whether we need to force a relocation into the output file. */
3141 tc_m68hc11_force_relocation (fixS
*fixP
)
3143 if (fixP
->fx_r_type
== BFD_RELOC_M68HC11_RL_GROUP
)
3146 return generic_force_reloc (fixP
);
3149 /* Here we decide which fixups can be adjusted to make them relative
3150 to the beginning of the section instead of the symbol. Basically
3151 we need to make sure that the linker relaxation is done
3152 correctly, so in some cases we force the original symbol to be
3155 tc_m68hc11_fix_adjustable (fixS
*fixP
)
3157 switch (fixP
->fx_r_type
)
3159 /* For the linker relaxation to work correctly, these relocs
3160 need to be on the symbol itself. */
3162 case BFD_RELOC_M68HC11_RL_JUMP
:
3163 case BFD_RELOC_M68HC11_RL_GROUP
:
3164 case BFD_RELOC_VTABLE_INHERIT
:
3165 case BFD_RELOC_VTABLE_ENTRY
:
3168 /* The memory bank addressing translation also needs the original
3170 case BFD_RELOC_M68HC11_LO16
:
3171 case BFD_RELOC_M68HC11_PAGE
:
3172 case BFD_RELOC_M68HC11_24
:
3181 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3184 long value
= * valP
;
3187 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
3190 /* We don't actually support subtracting a symbol. */
3191 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
3192 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("Expression too complex."));
3194 op_type
= fixP
->fx_r_type
;
3196 /* Patch the instruction with the resolved operand. Elf relocation
3197 info will also be generated to take care of linker/loader fixups.
3198 The 68HC11 addresses only 64Kb, we are only concerned by 8 and 16-bit
3199 relocs. BFD_RELOC_8 is basically used for .page0 access (the linker
3200 will warn for overflows). BFD_RELOC_8_PCREL should not be generated
3201 because it's either resolved or turned out into non-relative insns (see
3202 relax table, bcc, bra, bsr transformations)
3204 The BFD_RELOC_32 is necessary for the support of --gstabs. */
3205 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
3207 switch (fixP
->fx_r_type
)
3210 bfd_putb32 ((bfd_vma
) value
, (unsigned char *) where
);
3214 case BFD_RELOC_M68HC11_24
:
3215 bfd_putb16 ((bfd_vma
) (value
& 0x0ffff), (unsigned char *) where
);
3216 ((bfd_byte
*) where
)[2] = ((value
>> 16) & 0x0ff);
3220 case BFD_RELOC_16_PCREL
:
3221 case BFD_RELOC_M68HC11_LO16
:
3222 bfd_putb16 ((bfd_vma
) value
, (unsigned char *) where
);
3223 if (value
< -65537 || value
> 65535)
3224 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3225 _("Value out of 16-bit range."));
3228 case BFD_RELOC_M68HC11_HI8
:
3232 case BFD_RELOC_M68HC11_LO8
:
3234 case BFD_RELOC_M68HC11_PAGE
:
3235 ((bfd_byte
*) where
)[0] = (bfd_byte
) value
;
3238 case BFD_RELOC_8_PCREL
:
3239 ((bfd_byte
*) where
)[0] = (bfd_byte
) value
;
3241 if (value
< -128 || value
> 127)
3242 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3243 _("Value %ld too large for 8-bit PC-relative branch."),
3247 case BFD_RELOC_M68HC11_3B
:
3248 if (value
<= 0 || value
> 8)
3249 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3250 _("Auto increment/decrement offset '%ld' is out of range."),
3257 where
[0] = where
[0] | (value
& 0x07);
3260 case BFD_RELOC_M68HC12_5B
:
3261 if (value
< -16 || value
> 15)
3262 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3263 _("Offset out of 5-bit range for movw/movb insn: %ld"),
3268 where
[0] |= (0x10 | (16 + value
));
3271 case BFD_RELOC_M68HC11_RL_JUMP
:
3272 case BFD_RELOC_M68HC11_RL_GROUP
:
3273 case BFD_RELOC_VTABLE_INHERIT
:
3274 case BFD_RELOC_VTABLE_ENTRY
:
3279 as_fatal (_("Line %d: unknown relocation type: 0x%x."),
3280 fixP
->fx_line
, fixP
->fx_r_type
);
3284 /* Set the ELF specific flags. */
3286 m68hc11_elf_final_processing (void)
3288 if (current_architecture
& cpu6812s
)
3289 elf_flags
|= EF_M68HCS12_MACH
;
3290 elf_elfheader (stdoutput
)->e_flags
&= ~EF_M68HC11_ABI
;
3291 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;