1 /* tc-z8k.c -- Assemble code for the Zilog Z800n
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, 2002, 2003,
3 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 /* Written By Steve Chamberlain <sac@cygnus.com>. */
25 #include "safe-ctype.h"
27 #include "opcodes/z8k-opc.h"
29 const char comment_chars
[] = "!";
30 const char line_comment_chars
[] = "#";
31 const char line_separator_chars
[] = ";";
34 extern int coff_flags
;
37 /* This is non-zero if target was set from the command line. */
38 static int z8k_target_from_cmdline
;
46 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, bfd_mach_z8001
);
51 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, bfd_mach_z8002
);
56 even (int ignore ATTRIBUTE_UNUSED
)
59 record_alignment (now_seg
, 1);
73 sval (int ignore ATTRIBUTE_UNUSED
)
76 if (*input_line_pointer
== '\'')
80 c
= *input_line_pointer
++;
85 c
= (tohex (input_line_pointer
[0]) << 4)
86 | tohex (input_line_pointer
[1]);
87 input_line_pointer
+= 2;
89 FRAG_APPEND_1_CHAR (c
);
90 c
= *input_line_pointer
++;
92 demand_empty_rest_of_line ();
96 /* This table describes all the machine specific pseudo-ops the assembler
97 has to support. The fields are:
98 pseudo-op name without dot
99 function to call to execute this pseudo-op
100 Integer arg to pass to the function
103 const pseudo_typeS md_pseudo_table
[] = {
105 {"data.b" , cons
, 1},
106 {"data.w" , cons
, 2},
107 {"data.l" , cons
, 4},
108 {"form" , listing_psize
, 0},
109 {"heading", listing_title
, 0},
110 {"import" , s_ignore
, 0},
111 {"page" , listing_eject
, 0},
112 {"program", s_ignore
, 0},
113 {"z8001" , s_segm
, 1},
114 {"z8002" , s_segm
, 0},
116 {"segm" , s_segm
, 1},
117 {"unsegm" , s_segm
, 0},
118 {"unseg" , s_segm
, 0},
119 {"name" , s_app_file
, 0},
120 {"global" , s_globl
, 0},
125 {"rsect" , obj_coff_section
, 0},
126 {"sect" , obj_coff_section
, 0},
127 {"block" , s_space
, 0},
132 const char EXP_CHARS
[] = "eE";
134 /* Chars that mean this number is a floating point constant.
137 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
139 /* Opcode mnemonics. */
140 static struct hash_control
*opcode_hash_control
;
145 const opcode_entry_type
*opcode
;
148 opcode_hash_control
= hash_new ();
150 for (opcode
= z8k_table
; opcode
->name
; opcode
++)
152 /* Only enter unique codes into the table. */
153 if (idx
!= opcode
->idx
)
154 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
158 /* Default to z8002. */
159 if (! z8k_target_from_cmdline
)
162 /* Insert the pseudo ops, too. */
163 for (idx
= 0; md_pseudo_table
[idx
].poc_name
; idx
++)
165 opcode_entry_type
*fake_opcode
;
166 fake_opcode
= (opcode_entry_type
*) malloc (sizeof (opcode_entry_type
));
167 fake_opcode
->name
= md_pseudo_table
[idx
].poc_name
;
168 fake_opcode
->func
= (void *) (md_pseudo_table
+ idx
);
169 fake_opcode
->opcode
= 250;
170 hash_insert (opcode_hash_control
, fake_opcode
->name
, fake_opcode
);
174 typedef struct z8k_op
{
183 /* Any other register associated with the mode. */
186 /* Any expression. */
190 static expressionS
*da_operand
;
191 static expressionS
*imm_operand
;
196 static int the_flags
;
197 static int the_interrupt
;
199 /* Determine register number. src points to the ascii number
200 (after "rl", "rh", "r", "rr", or "rq"). If a character
201 outside the set of {0,',',')','('} follows the number,
202 return NULL to indicate that it's not a valid register
206 whatreg (unsigned int *reg
, char *src
)
208 unsigned int new_reg
;
210 /* src[0] is already known to be a digit. */
211 if (ISDIGIT (src
[1]))
213 new_reg
= (src
[0] - '0') * 10 + src
[1] - '0';
218 new_reg
= (src
[0] - '0');
222 if (src
[0] != 0 && src
[0] != ',' && src
[0] != '(' && src
[0] != ')')
235 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
243 /* Try to parse a reg name. Return a pointer to the first character
244 in SRC after the reg name. */
247 parse_reg (char *src
, int *mode
, unsigned int *reg
)
252 /* Check for stack pointer "sp" alias. */
253 if ((src
[0] == 's' || src
[0] == 'S')
254 && (src
[1] == 'p' || src
[1] == 'P')
255 && (src
[2] == 0 || src
[2] == ','))
259 *mode
= CLASS_REG_LONG
;
264 *mode
= CLASS_REG_WORD
;
270 if (src
[0] == 'r' || src
[0] == 'R')
272 if (src
[1] == 'r' || src
[1] == 'R')
274 if (src
[2] < '0' || src
[2] > '9')
275 return NULL
; /* Assume no register name but a label starting with 'rr'. */
276 *mode
= CLASS_REG_LONG
;
277 res
= whatreg (reg
, src
+ 2);
279 return NULL
; /* Not a valid register name. */
282 as_bad (_("register rr%d out of range"), regno
);
284 as_bad (_("register rr%d does not exist"), regno
);
286 else if (src
[1] == 'h' || src
[1] == 'H')
288 if (src
[2] < '0' || src
[2] > '9')
289 return NULL
; /* Assume no register name but a label starting with 'rh'. */
290 *mode
= CLASS_REG_BYTE
;
291 res
= whatreg (reg
, src
+ 2);
293 return NULL
; /* Not a valid register name. */
296 as_bad (_("register rh%d out of range"), regno
);
298 else if (src
[1] == 'l' || src
[1] == 'L')
300 if (src
[2] < '0' || src
[2] > '9')
301 return NULL
; /* Assume no register name but a label starting with 'rl'. */
302 *mode
= CLASS_REG_BYTE
;
303 res
= whatreg (reg
, src
+ 2);
305 return NULL
; /* Not a valid register name. */
308 as_bad (_("register rl%d out of range"), regno
);
311 else if (src
[1] == 'q' || src
[1] == 'Q')
313 if (src
[2] < '0' || src
[2] > '9')
314 return NULL
; /* Assume no register name but a label starting with 'rq'. */
315 *mode
= CLASS_REG_QUAD
;
316 res
= whatreg (reg
, src
+ 2);
318 return NULL
; /* Not a valid register name. */
321 as_bad (_("register rq%d out of range"), regno
);
323 as_bad (_("register rq%d does not exist"), regno
);
327 if (src
[1] < '0' || src
[1] > '9')
328 return NULL
; /* Assume no register name but a label starting with 'r'. */
329 *mode
= CLASS_REG_WORD
;
330 res
= whatreg (reg
, src
+ 1);
332 return NULL
; /* Not a valid register name. */
335 as_bad (_("register r%d out of range"), regno
);
342 parse_exp (char *s
, expressionS
*op
)
344 char *save
= input_line_pointer
;
347 input_line_pointer
= s
;
349 if (op
->X_op
== O_absent
)
350 as_bad (_("missing operand"));
351 new = input_line_pointer
;
352 input_line_pointer
= save
;
356 /* The many forms of operand:
371 checkfor (char *ptr
, char what
)
376 as_bad (_("expected %c"), what
);
381 /* Make sure the mode supplied is the size of a word. */
384 regword (int mode
, char *string
)
391 as_bad (_("register is wrong size for a word %s"), string
);
395 /* Make sure the mode supplied is the size of an address. */
398 regaddr (int mode
, char *string
)
402 ok
= segmented_mode
? CLASS_REG_LONG
: CLASS_REG_WORD
;
405 as_bad (_("register is wrong size for address %s"), string
);
414 static struct ctrl_names ctrl_table
[] = {
415 { 0x1, "flags" }, /* ldctlb only. */
416 { 0x2, "fcw" }, /* ldctl only. Applies to all remaining control registers. */
428 get_ctrl_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
436 mode
->mode
= CLASS_CTRL
;
437 for (i
= 0; ctrl_table
[i
].name
; i
++)
439 l
= strlen (ctrl_table
[i
].name
);
440 if (! strncasecmp (ctrl_table
[i
].name
, src
, l
))
442 the_ctrl
= ctrl_table
[i
].value
;
443 if (*(src
+ l
) && *(src
+ l
) != ',')
445 *ptr
= src
+ l
; /* Valid control name found: "consume" it. */
457 static struct flag_names flag_table
[] = {
469 get_flags_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
479 mode
->mode
= CLASS_FLAGS
;
481 for (j
= 0; j
<= 9; j
++)
486 for (i
= 0; flag_table
[i
].name
; i
++)
488 if (flag_table
[i
].name
[0] == c
)
490 the_flags
= the_flags
| flag_table
[i
].value
;
502 struct interrupt_names
{
507 static struct interrupt_names intr_table
[] = {
516 get_interrupt_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
524 mode
->mode
= CLASS_IMM
;
529 for (i
= 0; intr_table
[i
].name
; i
++)
531 l
= strlen (intr_table
[i
].name
);
532 if (! strncasecmp (intr_table
[i
].name
, src
, l
))
534 the_interrupt
|= intr_table
[i
].value
;
535 if (*(src
+ l
) && *(src
+ l
) != ',')
539 as_bad (_("unknown interrupt %s"), src
);
540 while (**ptr
&& ! is_end_of_line
[(unsigned char) **ptr
])
541 (*ptr
)++; /* Consume rest of line. */
561 /* No interrupt type specified, opcode won't do anything. */
562 as_warn (_("opcode has no effect"));
571 static struct cc_names table
[] = {
606 get_cc_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
614 mode
->mode
= CLASS_CC
;
615 for (i
= 0; table
[i
].name
; i
++)
617 l
= strlen (table
[i
].name
);
618 if (! strncasecmp (table
[i
].name
, src
, l
))
620 the_cc
= table
[i
].value
;
621 if (*(src
+ l
) && *(src
+ l
) != ',')
623 *ptr
= src
+ l
; /* Valid cc found: "consume" it. */
627 the_cc
= 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
631 get_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
642 mode
->mode
= CLASS_IMM
;
643 imm_operand
= &(mode
->exp
);
644 src
= parse_exp (src
+ 1, &(mode
->exp
));
646 else if (*src
== '@')
648 mode
->mode
= CLASS_IR
;
649 src
= parse_reg (src
+ 1, &mode
->regsize
, &mode
->reg
);
655 end
= parse_reg (src
, &mode
->mode
, ®n
);
666 end
= parse_reg (src
, &nw
, &nr
);
673 as_bad (_("Missing ) in ra(rb)"));
677 regaddr (mode
->mode
, "ra(rb) ra");
678 mode
->mode
= CLASS_BX
;
688 src
= parse_exp (src
, &(mode
->exp
));
689 src
= checkfor (src
, ')');
690 mode
->mode
= CLASS_BA
;
693 imm_operand
= &(mode
->exp
);
704 /* No initial reg. */
705 src
= parse_exp (src
, &(mode
->exp
));
709 end
= parse_reg (src
, &(mode
->mode
), ®n
);
710 regword (mode
->mode
, "addr(Ra) ra");
711 mode
->mode
= CLASS_X
;
714 da_operand
= &(mode
->exp
);
715 src
= checkfor (end
, ')');
719 /* Just an address. */
720 mode
->mode
= CLASS_DA
;
723 da_operand
= &(mode
->exp
);
731 get_operands (const opcode_entry_type
*opcode
, char *op_end
, op_type
*operand
)
736 switch (opcode
->noperands
)
746 if (opcode
->arg_info
[0] == CLASS_CC
)
748 get_cc_operand (&ptr
, operand
+ 0, 0);
751 if (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
753 as_bad (_("invalid condition code '%s'"), ptr
);
754 while (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
755 ptr
++; /* Consume rest of line. */
758 else if (opcode
->arg_info
[0] == CLASS_FLAGS
)
760 get_flags_operand (&ptr
, operand
+ 0, 0);
763 if (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
765 as_bad (_("invalid flag '%s'"), ptr
);
766 while (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
767 ptr
++; /* Consume rest of line. */
770 else if (opcode
->arg_info
[0] == (CLASS_IMM
+ (ARG_IMM2
)))
771 get_interrupt_operand (&ptr
, operand
+ 0, 0);
773 get_operand (&ptr
, operand
+ 0, 0);
780 if (opcode
->arg_info
[0] == CLASS_CC
)
782 get_cc_operand (&ptr
, operand
+ 0, 0);
785 if (*ptr
!= ',' && strchr (ptr
+ 1, ','))
792 as_bad (_("invalid condition code '%s'"), savptr
);
795 else if (opcode
->arg_info
[0] == CLASS_CTRL
)
797 get_ctrl_operand (&ptr
, operand
+ 0, 0);
802 get_operand (&ptr
, operand
+ 0, 0);
808 get_ctrl_operand (&ptr
, operand
+ 1, 1);
815 get_operand (&ptr
, operand
+ 0, 0);
821 get_operand (&ptr
, operand
+ 1, 1);
825 get_operand (&ptr
, operand
+ 0, 0);
828 get_operand (&ptr
, operand
+ 1, 1);
831 get_operand (&ptr
, operand
+ 2, 2);
835 get_operand (&ptr
, operand
+ 0, 0);
838 get_operand (&ptr
, operand
+ 1, 1);
841 get_operand (&ptr
, operand
+ 2, 2);
844 get_cc_operand (&ptr
, operand
+ 3, 3);
854 /* Passed a pointer to a list of opcodes which use different
855 addressing modes. Return the opcode which matches the opcodes
858 static opcode_entry_type
*
859 get_specific (opcode_entry_type
*opcode
, op_type
*operands
)
861 opcode_entry_type
*this_try
= opcode
;
863 unsigned int noperands
= opcode
->noperands
;
865 int this_index
= opcode
->idx
;
867 while (this_index
== opcode
->idx
&& !found
)
872 for (i
= 0; i
< noperands
; i
++)
874 unsigned int mode
= operands
[i
].mode
;
876 if (((mode
& CLASS_MASK
) == CLASS_IR
) && ((this_try
->arg_info
[i
] & CLASS_MASK
) == CLASS_IRO
))
878 mode
= operands
[i
].mode
= (operands
[i
].mode
& ~CLASS_MASK
) | CLASS_IRO
;
881 if ((mode
& CLASS_MASK
) != (this_try
->arg_info
[i
] & CLASS_MASK
))
883 /* It could be a pc rel operand, if this is a da mode
884 and we like disps, then insert it. */
886 if (mode
== CLASS_DA
&& this_try
->arg_info
[i
] == CLASS_DISP
)
888 /* This is the case. */
889 operands
[i
].mode
= CLASS_DISP
;
891 else if (mode
== CLASS_BA
&& this_try
->arg_info
[i
])
893 /* Can't think of a way to turn what we've been
894 given into something that's OK. */
897 else if (this_try
->arg_info
[i
] & CLASS_PR
)
899 if (mode
== CLASS_REG_LONG
&& segmented_mode
)
903 else if (mode
== CLASS_REG_WORD
&& !segmented_mode
)
913 switch (mode
& CLASS_MASK
)
918 if (operands
[i
].regsize
!= CLASS_REG_WORD
)
919 as_bad (_("invalid indirect register size"));
920 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
923 if ((segmented_mode
&& operands
[i
].regsize
!= CLASS_REG_LONG
)
924 || (!segmented_mode
&& operands
[i
].regsize
!= CLASS_REG_WORD
))
925 as_bad (_("invalid indirect register size"));
926 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
938 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
941 if (this_try
->opcode
== OPC_ldctlb
&& the_ctrl
!= 1)
942 as_bad (_("invalid control register name"));
957 static char buffer
[20];
960 newfix (int ptr
, int type
, int size
, expressionS
*operand
)
965 /* Size is in nibbles. */
966 if (operand
->X_add_symbol
967 || operand
->X_op_symbol
968 || operand
->X_add_number
)
972 case BFD_RELOC_8_PCREL
:
973 case BFD_RELOC_Z8K_CALLR
:
974 case BFD_RELOC_Z8K_DISP7
:
977 fixP
= fix_new_exp (frag_now
, ptr
, size
/ 2,
978 operand
, is_pcrel
, type
);
980 fixP
->fx_no_overflow
= 1;
985 apply_fix (char *ptr
, int type
, expressionS
*operand
, int size
)
987 long n
= operand
->X_add_number
;
989 /* size is in nibbles. */
991 newfix ((ptr
- buffer
) / 2, type
, size
+ 1, operand
);
994 case 8: /* 8 nibbles == 32 bits. */
999 case 4: /* 4 nibbles == 16 bits. */
1011 /* Now we know what sort of opcodes it is. Let's build the bytes. */
1014 build_bytes (opcode_entry_type
*this_try
, struct z8k_op
*operand ATTRIBUTE_UNUSED
)
1016 char *output_ptr
= buffer
;
1019 unsigned int *class_ptr
;
1021 frag_wane (frag_now
);
1024 if (frag_room () < 8)
1025 frag_grow (8); /* Make room for maximum instruction size. */
1027 memset (buffer
, 0, sizeof (buffer
));
1028 class_ptr
= this_try
->byte_info
;
1030 for (nibble
= 0; (c
= *class_ptr
++); nibble
++)
1033 switch (c
& CLASS_MASK
)
1039 /* Direct address, we don't cope with the SS mode right now. */
1042 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
1043 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_32
, da_operand
, 8);
1047 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_16
, da_operand
, 4);
1053 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_8_PCREL
, da_operand
, 2);
1060 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_DISP7
, da_operand
, 2);
1067 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_DISP7
, da_operand
, 2);
1068 output_ptr
[-2] = 0x8;
1072 case CLASS_BIT_1OR2
:
1073 *output_ptr
= c
& 0xf;
1076 if (imm_operand
->X_add_number
== 2)
1078 else if (imm_operand
->X_add_number
!= 1)
1079 as_bad (_("immediate must be 1 or 2"));
1082 as_bad (_("immediate 1 or 2 expected"));
1086 *output_ptr
++ = the_cc
;
1089 if (the_ctrl
< 2 || the_ctrl
> 7)
1090 as_bad (_("invalid control register name"));
1091 *output_ptr
++ = the_ctrl
;
1094 if (the_ctrl
< 2 || the_ctrl
> 7)
1095 as_bad (_("invalid control register name"));
1096 *output_ptr
++ = the_ctrl
| 0x8;
1099 *output_ptr
++ = (~the_interrupt
& 0x3);
1102 *output_ptr
++ = (~the_interrupt
& 0x3) | 0x4;
1105 *output_ptr
++ = the_flags
;
1109 *output_ptr
++ = c
& 0xf;
1112 if (reg
[c
& 0xf] == 0)
1113 as_bad (_("can't use R0 here"));
1116 case CLASS_REG_BYTE
:
1117 case CLASS_REG_WORD
:
1118 case CLASS_REG_LONG
:
1119 case CLASS_REG_QUAD
:
1120 /* Insert bit mattern of right reg. */
1121 *output_ptr
++ = reg
[c
& 0xf];
1124 switch (c
& ARG_MASK
)
1127 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_CALLR
, da_operand
, 4);
1130 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_16_PCREL
, da_operand
, 4);
1133 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_16
, da_operand
, 4);
1140 switch (c
& ARG_MASK
)
1143 if (imm_operand
->X_add_number
> 15)
1144 as_bad (_("immediate value out of range"));
1145 imm_operand
->X_add_number
= -imm_operand
->X_add_number
;
1146 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_IMM4L
, imm_operand
, 1);
1148 /*case ARG_IMMNMINUS1: not used. */
1150 imm_operand
->X_add_number
--;
1153 if (imm_operand
->X_add_number
> 15)
1154 as_bad (_("immediate value out of range"));
1155 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_IMM4L
, imm_operand
, 1);
1158 imm_operand
->X_add_number
= -imm_operand
->X_add_number
;
1161 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_8
, imm_operand
, 2);
1164 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_16
, imm_operand
, 4);
1167 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_32
, imm_operand
, 8);
1176 /* Copy from the nibble buffer into the frag. */
1178 int length
= (output_ptr
- buffer
) / 2;
1180 char *fragp
= frag_more (length
);
1182 while (src
< output_ptr
)
1184 *fragp
= (src
[0] << 4) | src
[1];
1191 /* This is the guts of the machine-dependent assembler. STR points to a
1192 machine dependent instruction. This function is supposed to emit
1193 the frags/bytes it assembles to. */
1196 md_assemble (char *str
)
1201 struct z8k_op operand
[4];
1202 opcode_entry_type
*opcode
;
1204 /* Drop leading whitespace. */
1208 /* Find the op code end. */
1209 for (op_start
= op_end
= str
;
1210 *op_end
!= 0 && *op_end
!= ' ' && ! is_end_of_line
[(unsigned char) *op_end
];
1214 if (op_end
== op_start
)
1216 as_bad (_("can't find opcode "));
1220 *op_end
= 0; /* Zero-terminate op code string for hash_find() call. */
1222 opcode
= (opcode_entry_type
*) hash_find (opcode_hash_control
, op_start
);
1226 as_bad (_("unknown opcode"));
1230 *op_end
= c
; /* Restore original string. */
1232 if (opcode
->opcode
== 250)
1236 char *old
= input_line_pointer
;
1238 /* Was really a pseudo op. */
1240 input_line_pointer
= op_end
;
1244 while (*input_line_pointer
== ' ')
1245 input_line_pointer
++;
1246 p
= (pseudo_typeS
*) (opcode
->func
);
1248 (p
->poc_handler
) (p
->poc_val
);
1249 input_line_pointer
= old
;
1254 char *new_input_line_pointer
;
1256 new_input_line_pointer
= get_operands (opcode
, op_end
, operand
);
1257 if (new_input_line_pointer
)
1259 input_line_pointer
= new_input_line_pointer
;
1260 opcode
= get_specific (opcode
, operand
);
1263 if (new_input_line_pointer
== NULL
|| opcode
== NULL
)
1265 /* Couldn't find an opcode which matched the operands. */
1266 char *where
= frag_more (2);
1271 as_bad (_("Can't find opcode to match operands"));
1275 build_bytes (opcode
, operand
);
1279 /* We have no need to default values of symbols. */
1282 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1287 /* Various routines to kill one day. */
1288 /* Equal to MAX_PRECISION in atof-ieee.c. */
1289 #define MAX_LITTLENUMS 6
1291 /* Turn a string in input_line_pointer into a floating point constant
1292 of type TYPE, and store the appropriate bytes in *LITP. The number
1293 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1294 returned, or NULL on OK. */
1297 md_atof (int type
, char *litP
, int *sizeP
)
1300 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1301 LITTLENUM_TYPE
*wordP
;
1332 return _("Bad call to MD_ATOF()");
1334 t
= atof_ieee (input_line_pointer
, type
, words
);
1336 input_line_pointer
= t
;
1338 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1339 for (wordP
= words
; prec
--;)
1341 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1342 litP
+= sizeof (LITTLENUM_TYPE
);
1347 const char *md_shortopts
= "z:";
1349 struct option md_longopts
[] =
1351 #define OPTION_RELAX (OPTION_MD_BASE)
1352 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
1353 {NULL
, no_argument
, NULL
, 0}
1356 size_t md_longopts_size
= sizeof (md_longopts
);
1359 md_parse_option (int c
, char *arg
)
1364 if (!strcmp (arg
, "8001"))
1366 else if (!strcmp (arg
, "8002"))
1370 as_bad (_("invalid architecture -z%s"), arg
);
1373 z8k_target_from_cmdline
= 1;
1388 md_show_usage (FILE *stream
)
1390 fprintf (stream
, _("\
1392 -z8001 generate segmented code\n\
1393 -z8002 generate unsegmented code\n\
1394 -linkrelax create linker relaxable code\n"));
1398 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
1399 segT sec ATTRIBUTE_UNUSED
,
1400 fragS
*fragP ATTRIBUTE_UNUSED
)
1402 printf (_("call to md_convert_frag\n"));
1406 /* Generate a machine dependent reloc from a fixup. */
1409 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
,
1410 fixS
*fixp ATTRIBUTE_UNUSED
)
1414 reloc
= xmalloc (sizeof (*reloc
));
1415 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
1416 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1417 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1418 reloc
->addend
= fixp
->fx_offset
;
1419 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1423 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1424 "Cannot represent %s relocation in object file",
1425 bfd_get_reloc_code_name (fixp
->fx_r_type
));
1432 md_section_align (segT seg
, valueT size
)
1434 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1435 valueT mask
= ((valueT
) 1 << align
) - 1;
1437 return (size
+ mask
) & ~mask
;
1440 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1441 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1442 we will have to generate a reloc entry. */
1444 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT segment ATTRIBUTE_UNUSED
)
1446 long val
= * (long *) valP
;
1447 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1449 switch (fixP
->fx_r_type
)
1451 case BFD_RELOC_Z8K_IMM4L
:
1454 fixP
->fx_no_overflow
= 1;
1458 buf
[0] = (buf
[0] & 0xf0) | (val
& 0xf);
1464 fixP
->fx_no_overflow
= 1;
1474 fixP
->fx_no_overflow
= 1;
1479 *buf
++ = (val
>> 8);
1487 fixP
->fx_no_overflow
= 1;
1492 *buf
++ = (val
>> 24);
1493 *buf
++ = (val
>> 16);
1494 *buf
++ = (val
>> 8);
1499 case BFD_RELOC_8_PCREL
:
1502 fixP
->fx_no_overflow
= 1;
1508 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1509 _("cannot branch to odd address"));
1511 if (val
> 127 || val
< -128)
1512 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1513 _("relative jump out of range"));
1515 fixP
->fx_no_overflow
= 1;
1520 case BFD_RELOC_16_PCREL
:
1523 fixP
->fx_no_overflow
= 1;
1528 val
= val
- fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- fixP
->fx_size
;
1529 if (val
> 32767 || val
< -32768)
1530 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1531 _("relative address out of range"));
1532 *buf
++ = (val
>> 8);
1534 fixP
->fx_no_overflow
= 1;
1539 case BFD_RELOC_Z8K_CALLR
:
1542 fixP
->fx_no_overflow
= 1;
1548 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1549 _("cannot branch to odd address"));
1550 if (val
> 4096 || val
< -4095)
1551 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1552 _("relative call out of range"));
1554 *buf
= (*buf
& 0xf0) | ((val
>> 8) & 0xf);
1556 *buf
++ = val
& 0xff;
1557 fixP
->fx_no_overflow
= 1;
1562 case BFD_RELOC_Z8K_DISP7
:
1565 fixP
->fx_no_overflow
= 1;
1571 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1572 _("cannot branch to odd address"));
1574 if (val
> 0 || val
< -127)
1575 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1576 _("relative jump out of range"));
1577 *buf
= (*buf
& 0x80) | (-val
& 0x7f);
1578 fixP
->fx_no_overflow
= 1;
1584 printf(_("md_apply_fix: unknown r_type 0x%x\n"), fixP
->fx_r_type
);
1588 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1593 md_estimate_size_before_relax (fragS
*fragP ATTRIBUTE_UNUSED
,
1594 segT segment_type ATTRIBUTE_UNUSED
)
1596 printf (_("call to md_estimate_size_before_relax\n"));
1600 /* Put number into target byte order. */
1603 md_number_to_chars (char *ptr
, valueT use
, int nbytes
)
1605 number_to_chars_bigendian (ptr
, use
, nbytes
);
1608 /* On the Z8000, a PC-relative offset is relative to the address of the
1609 instruction plus its size. */
1611 md_pcrel_from (fixS
*fixP
)
1613 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1617 tc_coff_symbol_emit_hook (symbolS
*s ATTRIBUTE_UNUSED
)