1 /* tc-z8k.c -- Assemble code for the Zilog Z800n
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, 2002, 2003,
3 2005 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>. */
28 #include "safe-ctype.h"
30 #include "opcodes/z8k-opc.h"
32 const char comment_chars
[] = "!";
33 const char line_comment_chars
[] = "#";
34 const char line_separator_chars
[] = ";";
37 extern int coff_flags
;
40 /* This is non-zero if target was set from the command line. */
41 static int z8k_target_from_cmdline
;
49 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, bfd_mach_z8001
);
54 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, bfd_mach_z8002
);
59 even (int ignore ATTRIBUTE_UNUSED
)
62 record_alignment (now_seg
, 1);
76 sval (int ignore ATTRIBUTE_UNUSED
)
79 if (*input_line_pointer
== '\'')
83 c
= *input_line_pointer
++;
88 c
= (tohex (input_line_pointer
[0]) << 4)
89 | tohex (input_line_pointer
[1]);
90 input_line_pointer
+= 2;
92 FRAG_APPEND_1_CHAR (c
);
93 c
= *input_line_pointer
++;
95 demand_empty_rest_of_line ();
99 /* This table describes all the machine specific pseudo-ops the assembler
100 has to support. The fields are:
101 pseudo-op name without dot
102 function to call to execute this pseudo-op
103 Integer arg to pass to the function
106 const pseudo_typeS md_pseudo_table
[] = {
108 {"data.b" , cons
, 1},
109 {"data.w" , cons
, 2},
110 {"data.l" , cons
, 4},
111 {"form" , listing_psize
, 0},
112 {"heading", listing_title
, 0},
113 {"import" , s_ignore
, 0},
114 {"page" , listing_eject
, 0},
115 {"program", s_ignore
, 0},
116 {"z8001" , s_segm
, 1},
117 {"z8002" , s_segm
, 0},
119 {"segm" , s_segm
, 1},
120 {"unsegm" , s_segm
, 0},
121 {"unseg" , s_segm
, 0},
122 {"name" , s_app_file
, 0},
123 {"global" , s_globl
, 0},
128 {"rsect" , obj_coff_section
, 0},
129 {"sect" , obj_coff_section
, 0},
130 {"block" , s_space
, 0},
135 const char EXP_CHARS
[] = "eE";
137 /* Chars that mean this number is a floating point constant.
140 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
142 /* Opcode mnemonics. */
143 static struct hash_control
*opcode_hash_control
;
148 const opcode_entry_type
*opcode
;
151 opcode_hash_control
= hash_new ();
153 for (opcode
= z8k_table
; opcode
->name
; opcode
++)
155 /* Only enter unique codes into the table. */
156 if (idx
!= opcode
->idx
)
157 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
161 /* Default to z8002. */
162 if (! z8k_target_from_cmdline
)
165 /* Insert the pseudo ops, too. */
166 for (idx
= 0; md_pseudo_table
[idx
].poc_name
; idx
++)
168 opcode_entry_type
*fake_opcode
;
169 fake_opcode
= (opcode_entry_type
*) malloc (sizeof (opcode_entry_type
));
170 fake_opcode
->name
= md_pseudo_table
[idx
].poc_name
;
171 fake_opcode
->func
= (void *) (md_pseudo_table
+ idx
);
172 fake_opcode
->opcode
= 250;
173 hash_insert (opcode_hash_control
, fake_opcode
->name
, fake_opcode
);
177 typedef struct z8k_op
{
186 /* Any other register associated with the mode. */
189 /* Any expression. */
193 static expressionS
*da_operand
;
194 static expressionS
*imm_operand
;
199 static int the_flags
;
200 static int the_interrupt
;
203 whatreg (unsigned int *reg
, char *src
)
205 if (ISDIGIT (src
[1]))
207 *reg
= (src
[0] - '0') * 10 + src
[1] - '0';
212 *reg
= (src
[0] - '0');
223 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
231 /* Try to parse a reg name. Return a pointer to the first character
232 in SRC after the reg name. */
235 parse_reg (char *src
, int *mode
, unsigned int *reg
)
240 /* Check for stack pointer "sp" alias. */
241 if ((src
[0] == 's' || src
[0] == 'S')
242 && (src
[1] == 'p' || src
[1] == 'P')
243 && (src
[2] == 0 || src
[2] == ','))
247 *mode
= CLASS_REG_LONG
;
252 *mode
= CLASS_REG_WORD
;
258 if (src
[0] == 'r' || src
[0] == 'R')
260 if (src
[1] == 'r' || src
[1] == 'R')
262 if (src
[2] < '0' || src
[2] > '9')
263 return res
; /* Assume no register name but a label starting with 'rr'. */
264 *mode
= CLASS_REG_LONG
;
265 res
= whatreg (reg
, src
+ 2);
268 as_bad (_("register rr%d out of range"), regno
);
270 as_bad (_("register rr%d does not exist"), regno
);
272 else if (src
[1] == 'h' || src
[1] == 'H')
274 if (src
[2] < '0' || src
[2] > '9')
275 return res
; /* Assume no register name but a label starting with 'rh'. */
276 *mode
= CLASS_REG_BYTE
;
277 res
= whatreg (reg
, src
+ 2);
280 as_bad (_("register rh%d out of range"), regno
);
282 else if (src
[1] == 'l' || src
[1] == 'L')
284 if (src
[2] < '0' || src
[2] > '9')
285 return res
; /* Assume no register name but a label starting with 'rl'. */
286 *mode
= CLASS_REG_BYTE
;
287 res
= whatreg (reg
, src
+ 2);
290 as_bad (_("register rl%d out of range"), regno
);
293 else if (src
[1] == 'q' || src
[1] == 'Q')
295 if (src
[2] < '0' || src
[2] > '9')
296 return res
; /* Assume no register name but a label starting with 'rq'. */
297 *mode
= CLASS_REG_QUAD
;
298 res
= whatreg (reg
, src
+ 2);
301 as_bad (_("register rq%d out of range"), regno
);
303 as_bad (_("register rq%d does not exist"), regno
);
307 if (src
[1] < '0' || src
[1] > '9')
308 return res
; /* Assume no register name but a label starting with 'r'. */
309 *mode
= CLASS_REG_WORD
;
310 res
= whatreg (reg
, src
+ 1);
313 as_bad (_("register r%d out of range"), regno
);
320 parse_exp (char *s
, expressionS
*op
)
322 char *save
= input_line_pointer
;
325 input_line_pointer
= s
;
327 if (op
->X_op
== O_absent
)
328 as_bad (_("missing operand"));
329 new = input_line_pointer
;
330 input_line_pointer
= save
;
334 /* The many forms of operand:
349 checkfor (char *ptr
, char what
)
354 as_bad (_("expected %c"), what
);
359 /* Make sure the mode supplied is the size of a word. */
362 regword (int mode
, char *string
)
369 as_bad (_("register is wrong size for a word %s"), string
);
373 /* Make sure the mode supplied is the size of an address. */
376 regaddr (int mode
, char *string
)
380 ok
= segmented_mode
? CLASS_REG_LONG
: CLASS_REG_WORD
;
383 as_bad (_("register is wrong size for address %s"), string
);
392 static struct ctrl_names ctrl_table
[] = {
393 { 0x1, "flags" }, /* ldctlb only. */
394 { 0x2, "fcw" }, /* ldctl only. Applies to all remaining control registers. */
406 get_ctrl_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
414 mode
->mode
= CLASS_CTRL
;
415 for (i
= 0; ctrl_table
[i
].name
; i
++)
417 l
= strlen (ctrl_table
[i
].name
);
418 if (! strncasecmp (ctrl_table
[i
].name
, src
, l
))
420 the_ctrl
= ctrl_table
[i
].value
;
421 if (*(src
+ l
) && *(src
+ l
) != ',')
423 *ptr
= src
+ l
; /* Valid control name found: "consume" it. */
435 static struct flag_names flag_table
[] = {
447 get_flags_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
457 mode
->mode
= CLASS_FLAGS
;
459 for (j
= 0; j
<= 9; j
++)
464 for (i
= 0; flag_table
[i
].name
; i
++)
466 if (flag_table
[i
].name
[0] == c
)
468 the_flags
= the_flags
| flag_table
[i
].value
;
480 struct interrupt_names
{
485 static struct interrupt_names intr_table
[] = {
494 get_interrupt_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
502 mode
->mode
= CLASS_IMM
;
507 for (i
= 0; intr_table
[i
].name
; i
++)
509 l
= strlen (intr_table
[i
].name
);
510 if (! strncasecmp (intr_table
[i
].name
, src
, l
))
512 the_interrupt
|= intr_table
[i
].value
;
513 if (*(src
+ l
) && *(src
+ l
) != ',')
517 as_bad (_("unknown interrupt %s"), src
);
518 while (**ptr
&& ! is_end_of_line
[(unsigned char) **ptr
])
519 (*ptr
)++; /* Consume rest of line. */
539 /* No interrupt type specified, opcode won't do anything. */
540 as_warn (_("opcode has no effect"));
549 static struct cc_names table
[] = {
584 get_cc_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
592 mode
->mode
= CLASS_CC
;
593 for (i
= 0; table
[i
].name
; i
++)
595 l
= strlen (table
[i
].name
);
596 if (! strncasecmp (table
[i
].name
, src
, l
))
598 the_cc
= table
[i
].value
;
599 if (*(src
+ l
) && *(src
+ l
) != ',')
601 *ptr
= src
+ l
; /* Valid cc found: "consume" it. */
605 the_cc
= 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
609 get_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
620 mode
->mode
= CLASS_IMM
;
621 imm_operand
= &(mode
->exp
);
622 src
= parse_exp (src
+ 1, &(mode
->exp
));
624 else if (*src
== '@')
626 mode
->mode
= CLASS_IR
;
627 src
= parse_reg (src
+ 1, &mode
->regsize
, &mode
->reg
);
633 end
= parse_reg (src
, &mode
->mode
, ®n
);
644 end
= parse_reg (src
, &nw
, &nr
);
651 as_bad (_("Missing ) in ra(rb)"));
655 regaddr (mode
->mode
, "ra(rb) ra");
656 mode
->mode
= CLASS_BX
;
666 src
= parse_exp (src
, &(mode
->exp
));
667 src
= checkfor (src
, ')');
668 mode
->mode
= CLASS_BA
;
671 imm_operand
= &(mode
->exp
);
682 /* No initial reg. */
683 src
= parse_exp (src
, &(mode
->exp
));
687 end
= parse_reg (src
, &(mode
->mode
), ®n
);
688 regword (mode
->mode
, "addr(Ra) ra");
689 mode
->mode
= CLASS_X
;
692 da_operand
= &(mode
->exp
);
693 src
= checkfor (end
, ')');
697 /* Just an address. */
698 mode
->mode
= CLASS_DA
;
701 da_operand
= &(mode
->exp
);
709 get_operands (const opcode_entry_type
*opcode
, char *op_end
, op_type
*operand
)
714 switch (opcode
->noperands
)
724 if (opcode
->arg_info
[0] == CLASS_CC
)
726 get_cc_operand (&ptr
, operand
+ 0, 0);
729 if (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
731 as_bad (_("invalid condition code '%s'"), ptr
);
732 while (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
733 ptr
++; /* Consume rest of line. */
736 else if (opcode
->arg_info
[0] == CLASS_FLAGS
)
738 get_flags_operand (&ptr
, operand
+ 0, 0);
741 if (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
743 as_bad (_("invalid flag '%s'"), ptr
);
744 while (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
745 ptr
++; /* Consume rest of line. */
748 else if (opcode
->arg_info
[0] == (CLASS_IMM
+ (ARG_IMM2
)))
749 get_interrupt_operand (&ptr
, operand
+ 0, 0);
751 get_operand (&ptr
, operand
+ 0, 0);
758 if (opcode
->arg_info
[0] == CLASS_CC
)
760 get_cc_operand (&ptr
, operand
+ 0, 0);
763 if (*ptr
!= ',' && strchr (ptr
+ 1, ','))
770 as_bad (_("invalid condition code '%s'"), savptr
);
773 else if (opcode
->arg_info
[0] == CLASS_CTRL
)
775 get_ctrl_operand (&ptr
, operand
+ 0, 0);
780 get_operand (&ptr
, operand
+ 0, 0);
786 get_ctrl_operand (&ptr
, operand
+ 1, 1);
793 get_operand (&ptr
, operand
+ 0, 0);
799 get_operand (&ptr
, operand
+ 1, 1);
803 get_operand (&ptr
, operand
+ 0, 0);
806 get_operand (&ptr
, operand
+ 1, 1);
809 get_operand (&ptr
, operand
+ 2, 2);
813 get_operand (&ptr
, operand
+ 0, 0);
816 get_operand (&ptr
, operand
+ 1, 1);
819 get_operand (&ptr
, operand
+ 2, 2);
822 get_cc_operand (&ptr
, operand
+ 3, 3);
832 /* Passed a pointer to a list of opcodes which use different
833 addressing modes. Return the opcode which matches the opcodes
836 static opcode_entry_type
*
837 get_specific (opcode_entry_type
*opcode
, op_type
*operands
)
839 opcode_entry_type
*this_try
= opcode
;
841 unsigned int noperands
= opcode
->noperands
;
843 int this_index
= opcode
->idx
;
845 while (this_index
== opcode
->idx
&& !found
)
850 for (i
= 0; i
< noperands
; i
++)
852 unsigned int mode
= operands
[i
].mode
;
854 if (((mode
& CLASS_MASK
) == CLASS_IR
) && ((this_try
->arg_info
[i
] & CLASS_MASK
) == CLASS_IRO
))
856 mode
= operands
[i
].mode
= (operands
[i
].mode
& ~CLASS_MASK
) | CLASS_IRO
;
859 if ((mode
& CLASS_MASK
) != (this_try
->arg_info
[i
] & CLASS_MASK
))
861 /* It could be a pc rel operand, if this is a da mode
862 and we like disps, then insert it. */
864 if (mode
== CLASS_DA
&& this_try
->arg_info
[i
] == CLASS_DISP
)
866 /* This is the case. */
867 operands
[i
].mode
= CLASS_DISP
;
869 else if (mode
== CLASS_BA
&& this_try
->arg_info
[i
])
871 /* Can't think of a way to turn what we've been
872 given into something that's OK. */
875 else if (this_try
->arg_info
[i
] & CLASS_PR
)
877 if (mode
== CLASS_REG_LONG
&& segmented_mode
)
881 else if (mode
== CLASS_REG_WORD
&& !segmented_mode
)
891 switch (mode
& CLASS_MASK
)
896 if (operands
[i
].regsize
!= CLASS_REG_WORD
)
897 as_bad (_("invalid indirect register size"));
898 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
901 if ((segmented_mode
&& operands
[i
].regsize
!= CLASS_REG_LONG
)
902 || (!segmented_mode
&& operands
[i
].regsize
!= CLASS_REG_WORD
))
903 as_bad (_("invalid indirect register size"));
904 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
916 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
919 if (this_try
->opcode
== OPC_ldctlb
&& the_ctrl
!= 1)
920 as_bad (_("invalid control register name"));
935 static char buffer
[20];
938 newfix (int ptr
, int type
, int size
, expressionS
*operand
)
943 /* Size is in nibbles. */
944 if (operand
->X_add_symbol
945 || operand
->X_op_symbol
946 || operand
->X_add_number
)
950 case BFD_RELOC_8_PCREL
:
951 case BFD_RELOC_Z8K_CALLR
:
952 case BFD_RELOC_Z8K_DISP7
:
955 fixP
= fix_new_exp (frag_now
, ptr
, size
/ 2,
956 operand
, is_pcrel
, type
);
958 fixP
->fx_no_overflow
= 1;
963 apply_fix (char *ptr
, int type
, expressionS
*operand
, int size
)
965 long n
= operand
->X_add_number
;
967 /* size is in nibbles. */
969 newfix ((ptr
- buffer
) / 2, type
, size
+ 1, operand
);
972 case 8: /* 8 nibbles == 32 bits. */
977 case 4: /* 4 nibbles == 16 bits. */
989 /* Now we know what sort of opcodes it is. Let's build the bytes. */
992 build_bytes (opcode_entry_type
*this_try
, struct z8k_op
*operand ATTRIBUTE_UNUSED
)
994 char *output_ptr
= buffer
;
997 unsigned int *class_ptr
;
999 frag_wane (frag_now
);
1002 if (frag_room () < 8)
1003 frag_grow (8); /* Make room for maximum instruction size. */
1005 memset (buffer
, 0, sizeof (buffer
));
1006 class_ptr
= this_try
->byte_info
;
1008 for (nibble
= 0; (c
= *class_ptr
++); nibble
++)
1011 switch (c
& CLASS_MASK
)
1017 /* Direct address, we don't cope with the SS mode right now. */
1020 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
1021 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_32
, da_operand
, 8);
1025 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_16
, da_operand
, 4);
1031 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_8_PCREL
, da_operand
, 2);
1038 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_DISP7
, da_operand
, 2);
1045 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_DISP7
, da_operand
, 2);
1046 output_ptr
[-2] = 0x8;
1050 case CLASS_BIT_1OR2
:
1051 *output_ptr
= c
& 0xf;
1054 if (imm_operand
->X_add_number
== 2)
1056 else if (imm_operand
->X_add_number
!= 1)
1057 as_bad (_("immediate must be 1 or 2"));
1060 as_bad (_("immediate 1 or 2 expected"));
1064 *output_ptr
++ = the_cc
;
1067 if (the_ctrl
< 2 || the_ctrl
> 7)
1068 as_bad (_("invalid control register name"));
1069 *output_ptr
++ = the_ctrl
;
1072 if (the_ctrl
< 2 || the_ctrl
> 7)
1073 as_bad (_("invalid control register name"));
1074 *output_ptr
++ = the_ctrl
| 0x8;
1077 *output_ptr
++ = (~the_interrupt
& 0x3);
1080 *output_ptr
++ = (~the_interrupt
& 0x3) | 0x4;
1083 *output_ptr
++ = the_flags
;
1087 *output_ptr
++ = c
& 0xf;
1090 if (reg
[c
& 0xf] == 0)
1091 as_bad (_("can't use R0 here"));
1094 case CLASS_REG_BYTE
:
1095 case CLASS_REG_WORD
:
1096 case CLASS_REG_LONG
:
1097 case CLASS_REG_QUAD
:
1098 /* Insert bit mattern of right reg. */
1099 *output_ptr
++ = reg
[c
& 0xf];
1102 switch (c
& ARG_MASK
)
1105 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_CALLR
, da_operand
, 4);
1108 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_16_PCREL
, da_operand
, 4);
1111 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_16
, da_operand
, 4);
1118 switch (c
& ARG_MASK
)
1121 if (imm_operand
->X_add_number
> 15)
1122 as_bad (_("immediate value out of range"));
1123 imm_operand
->X_add_number
= -imm_operand
->X_add_number
;
1124 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_IMM4L
, imm_operand
, 1);
1126 /*case ARG_IMMNMINUS1: not used. */
1128 imm_operand
->X_add_number
--;
1131 if (imm_operand
->X_add_number
> 15)
1132 as_bad (_("immediate value out of range"));
1133 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_Z8K_IMM4L
, imm_operand
, 1);
1136 imm_operand
->X_add_number
= -imm_operand
->X_add_number
;
1139 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_8
, imm_operand
, 2);
1142 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_16
, imm_operand
, 4);
1145 output_ptr
= apply_fix (output_ptr
, BFD_RELOC_32
, imm_operand
, 8);
1154 /* Copy from the nibble buffer into the frag. */
1156 int length
= (output_ptr
- buffer
) / 2;
1158 char *fragp
= frag_more (length
);
1160 while (src
< output_ptr
)
1162 *fragp
= (src
[0] << 4) | src
[1];
1169 /* This is the guts of the machine-dependent assembler. STR points to a
1170 machine dependent instruction. This function is supposed to emit
1171 the frags/bytes it assembles to. */
1174 md_assemble (char *str
)
1179 struct z8k_op operand
[4];
1180 opcode_entry_type
*opcode
;
1182 /* Drop leading whitespace. */
1186 /* Find the op code end. */
1187 for (op_start
= op_end
= str
;
1188 *op_end
!= 0 && *op_end
!= ' ' && ! is_end_of_line
[(unsigned char) *op_end
];
1192 if (op_end
== op_start
)
1194 as_bad (_("can't find opcode "));
1198 *op_end
= 0; /* Zero-terminate op code string for hash_find() call. */
1200 opcode
= (opcode_entry_type
*) hash_find (opcode_hash_control
, op_start
);
1204 as_bad (_("unknown opcode"));
1208 *op_end
= c
; /* Restore original string. */
1210 if (opcode
->opcode
== 250)
1214 char *old
= input_line_pointer
;
1216 /* Was really a pseudo op. */
1218 input_line_pointer
= op_end
;
1222 while (*input_line_pointer
== ' ')
1223 input_line_pointer
++;
1224 p
= (pseudo_typeS
*) (opcode
->func
);
1226 (p
->poc_handler
) (p
->poc_val
);
1227 input_line_pointer
= old
;
1232 char *new_input_line_pointer
;
1234 new_input_line_pointer
= get_operands (opcode
, op_end
, operand
);
1235 if (new_input_line_pointer
)
1237 input_line_pointer
= new_input_line_pointer
;
1238 opcode
= get_specific (opcode
, operand
);
1241 if (new_input_line_pointer
== NULL
|| opcode
== NULL
)
1243 /* Couldn't find an opcode which matched the operands. */
1244 char *where
= frag_more (2);
1249 as_bad (_("Can't find opcode to match operands"));
1253 build_bytes (opcode
, operand
);
1257 /* We have no need to default values of symbols. */
1260 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1265 /* Various routines to kill one day. */
1266 /* Equal to MAX_PRECISION in atof-ieee.c. */
1267 #define MAX_LITTLENUMS 6
1269 /* Turn a string in input_line_pointer into a floating point constant
1270 of type TYPE, and store the appropriate bytes in *LITP. The number
1271 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1272 returned, or NULL on OK. */
1275 md_atof (int type
, char *litP
, int *sizeP
)
1278 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1279 LITTLENUM_TYPE
*wordP
;
1310 return _("Bad call to MD_ATOF()");
1312 t
= atof_ieee (input_line_pointer
, type
, words
);
1314 input_line_pointer
= t
;
1316 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1317 for (wordP
= words
; prec
--;)
1319 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1320 litP
+= sizeof (LITTLENUM_TYPE
);
1325 const char *md_shortopts
= "z:";
1327 struct option md_longopts
[] =
1329 #define OPTION_RELAX (OPTION_MD_BASE)
1330 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
1331 {NULL
, no_argument
, NULL
, 0}
1334 size_t md_longopts_size
= sizeof (md_longopts
);
1337 md_parse_option (int c
, char *arg
)
1342 if (!strcmp (arg
, "8001"))
1344 else if (!strcmp (arg
, "8002"))
1348 as_bad (_("invalid architecture -z%s"), arg
);
1351 z8k_target_from_cmdline
= 1;
1366 md_show_usage (FILE *stream
)
1368 fprintf (stream
, _("\
1370 -z8001 generate segmented code\n\
1371 -z8002 generate unsegmented code\n\
1372 -linkrelax create linker relaxable code\n"));
1376 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
1377 segT sec ATTRIBUTE_UNUSED
,
1378 fragS
*fragP ATTRIBUTE_UNUSED
)
1380 printf (_("call to md_convert_frag\n"));
1384 /* Generate a machine dependent reloc from a fixup. */
1387 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
,
1388 fixS
*fixp ATTRIBUTE_UNUSED
)
1392 reloc
= xmalloc (sizeof (*reloc
));
1393 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
1394 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1395 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1396 reloc
->addend
= fixp
->fx_offset
;
1397 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1401 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1402 "Cannot represent %s relocation in object file",
1403 bfd_get_reloc_code_name (fixp
->fx_r_type
));
1410 md_section_align (segT seg
, valueT size
)
1412 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1413 valueT mask
= ((valueT
) 1 << align
) - 1;
1415 return (size
+ mask
) & ~mask
;
1418 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1419 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1420 we will have to generate a reloc entry. */
1422 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT segment ATTRIBUTE_UNUSED
)
1424 long val
= * (long *) valP
;
1425 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1427 switch (fixP
->fx_r_type
)
1429 case BFD_RELOC_Z8K_IMM4L
:
1432 fixP
->fx_no_overflow
= 1;
1436 buf
[0] = (buf
[0] & 0xf0) | (val
& 0xf);
1442 fixP
->fx_no_overflow
= 1;
1452 fixP
->fx_no_overflow
= 1;
1457 *buf
++ = (val
>> 8);
1465 fixP
->fx_no_overflow
= 1;
1470 *buf
++ = (val
>> 24);
1471 *buf
++ = (val
>> 16);
1472 *buf
++ = (val
>> 8);
1477 case BFD_RELOC_8_PCREL
:
1480 fixP
->fx_no_overflow
= 1;
1486 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1487 _("cannot branch to odd address"));
1489 if (val
> 127 || val
< -128)
1490 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1491 _("relative jump out of range"));
1493 fixP
->fx_no_overflow
= 1;
1498 case BFD_RELOC_16_PCREL
:
1501 fixP
->fx_no_overflow
= 1;
1506 val
= val
- fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- fixP
->fx_size
;
1507 if (val
> 32767 || val
< -32768)
1508 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1509 _("relative address out of range"));
1510 *buf
++ = (val
>> 8);
1512 fixP
->fx_no_overflow
= 1;
1517 case BFD_RELOC_Z8K_CALLR
:
1520 fixP
->fx_no_overflow
= 1;
1526 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1527 _("cannot branch to odd address"));
1528 if (val
> 4096 || val
< -4095)
1529 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1530 _("relative call out of range"));
1532 *buf
= (*buf
& 0xf0) | ((val
>> 8) & 0xf);
1534 *buf
++ = val
& 0xff;
1535 fixP
->fx_no_overflow
= 1;
1540 case BFD_RELOC_Z8K_DISP7
:
1543 fixP
->fx_no_overflow
= 1;
1549 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1550 _("cannot branch to odd address"));
1552 if (val
> 0 || val
< -127)
1553 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1554 _("relative jump out of range"));
1555 *buf
= (*buf
& 0x80) | (-val
& 0x7f);
1556 fixP
->fx_no_overflow
= 1;
1562 printf(_("md_apply_fix: unknown r_type 0x%x\n"), fixP
->fx_r_type
);
1566 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1571 md_estimate_size_before_relax (fragS
*fragP ATTRIBUTE_UNUSED
,
1572 segT segment_type ATTRIBUTE_UNUSED
)
1574 printf (_("call to md_estimate_size_before_relax\n"));
1578 /* Put number into target byte order. */
1581 md_number_to_chars (char *ptr
, valueT use
, int nbytes
)
1583 number_to_chars_bigendian (ptr
, use
, nbytes
);
1586 /* On the Z8000, a PC-relative offset is relative to the address of the
1587 instruction plus its size. */
1589 md_pcrel_from (fixS
*fixP
)
1591 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1595 tc_coff_symbol_emit_hook (symbolS
*s ATTRIBUTE_UNUSED
)