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
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;
200 whatreg (unsigned int *reg, char *src)
202 if (ISDIGIT (src[1]))
204 *reg = (src[0] - '0') * 10 + src[1] - '0';
209 *reg = (src[0] - '0');
220 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
228 /* Try to parse a reg name. Return a pointer to the first character
229 in SRC after the reg name. */
232 parse_reg (char *src, int *mode, unsigned int *reg)
237 /* Check for stack pointer "sp" alias. */
238 if ((src[0] == 's' || src[0] == 'S')
239 && (src[1] == 'p' || src[1] == 'P')
240 && (src[2] == 0 || src[2] == ','))
244 *mode = CLASS_REG_LONG;
249 *mode = CLASS_REG_WORD;
255 if (src[0] == 'r' || src[0] == 'R')
257 if (src[1] == 'r' || src[1] == 'R')
259 if (src[2] < '0' || src[2] > '9')
260 return res; /* Assume no register name but a label starting with 'rr'. */
261 *mode = CLASS_REG_LONG;
262 res = whatreg (reg, src + 2);
265 as_bad (_("register rr%d out of range"), regno);
267 as_bad (_("register rr%d does not exist"), regno);
269 else if (src[1] == 'h' || src[1] == 'H')
271 if (src[2] < '0' || src[2] > '9')
272 return res; /* Assume no register name but a label starting with 'rh'. */
273 *mode = CLASS_REG_BYTE;
274 res = whatreg (reg, src + 2);
277 as_bad (_("register rh%d out of range"), regno);
279 else if (src[1] == 'l' || src[1] == 'L')
281 if (src[2] < '0' || src[2] > '9')
282 return res; /* Assume no register name but a label starting with 'rl'. */
283 *mode = CLASS_REG_BYTE;
284 res = whatreg (reg, src + 2);
287 as_bad (_("register rl%d out of range"), regno);
290 else if (src[1] == 'q' || src[1] == 'Q')
292 if (src[2] < '0' || src[2] > '9')
293 return res; /* Assume no register name but a label starting with 'rq'. */
294 *mode = CLASS_REG_QUAD;
295 res = whatreg (reg, src + 2);
298 as_bad (_("register rq%d out of range"), regno);
300 as_bad (_("register rq%d does not exist"), regno);
304 if (src[1] < '0' || src[1] > '9')
305 return res; /* Assume no register name but a label starting with 'r'. */
306 *mode = CLASS_REG_WORD;
307 res = whatreg (reg, src + 1);
310 as_bad (_("register r%d out of range"), regno);
317 parse_exp (char *s, expressionS *op)
319 char *save = input_line_pointer;
322 input_line_pointer = s;
324 if (op->X_op == O_absent)
325 as_bad (_("missing operand"));
326 new = input_line_pointer;
327 input_line_pointer = save;
331 /* The many forms of operand:
346 checkfor (char *ptr, char what)
351 as_bad (_("expected %c"), what);
356 /* Make sure the mode supplied is the size of a word. */
359 regword (int mode, char *string)
366 as_bad (_("register is wrong size for a word %s"), string);
370 /* Make sure the mode supplied is the size of an address. */
373 regaddr (int mode, char *string)
377 ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
380 as_bad (_("register is wrong size for address %s"), string);
389 static struct ctrl_names ctrl_table[] = {
390 { 0x1, "flags" }, /* ldctlb only. */
391 { 0x2, "fcw" }, /* ldctl only. Applies to all remaining control registers. */
403 get_ctrl_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
411 mode->mode = CLASS_CTRL;
412 for (i = 0; ctrl_table[i].name; i++)
414 l = strlen (ctrl_table[i].name);
415 if (! strncasecmp (ctrl_table[i].name, src, l))
417 the_ctrl = ctrl_table[i].value;
418 if (*(src + l) && *(src + l) != ',')
420 *ptr = src + l; /* Valid control name found: "consume" it. */
432 static struct flag_names flag_table[] = {
444 get_flags_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
454 mode->mode = CLASS_FLAGS;
456 for (j = 0; j <= 9; j++)
461 for (i = 0; flag_table[i].name; i++)
463 if (flag_table[i].name[0] == c)
465 the_flags = the_flags | flag_table[i].value;
477 struct interrupt_names {
482 static struct interrupt_names intr_table[] = {
491 get_interrupt_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
499 mode->mode = CLASS_IMM;
504 for (i = 0; intr_table[i].name; i++)
506 l = strlen (intr_table[i].name);
507 if (! strncasecmp (intr_table[i].name, src, l))
509 the_interrupt |= intr_table[i].value;
510 if (*(src + l) && *(src + l) != ',')
514 as_bad (_("unknown interrupt %s"), src);
515 while (**ptr && ! is_end_of_line[(unsigned char) **ptr])
516 (*ptr)++; /* Consume rest of line. */
536 /* No interrupt type specified, opcode won't do anything. */
537 as_warn (_("opcode has no effect"));
546 static struct cc_names table[] = {
581 get_cc_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
589 mode->mode = CLASS_CC;
590 for (i = 0; table[i].name; i++)
592 l = strlen (table[i].name);
593 if (! strncasecmp (table[i].name, src, l))
595 the_cc = table[i].value;
596 if (*(src + l) && *(src + l) != ',')
598 *ptr = src + l; /* Valid cc found: "consume" it. */
602 the_cc = 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
606 get_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
617 mode->mode = CLASS_IMM;
618 imm_operand = &(mode->exp);
619 src = parse_exp (src + 1, &(mode->exp));
621 else if (*src == '@')
623 mode->mode = CLASS_IR;
624 src = parse_reg (src + 1, &mode->regsize, &mode->reg);
630 end = parse_reg (src, &mode->mode, ®n);
641 end = parse_reg (src, &nw, &nr);
648 as_bad (_("Missing ) in ra(rb)"));
652 regaddr (mode->mode, "ra(rb) ra");
653 mode->mode = CLASS_BX;
663 src = parse_exp (src, &(mode->exp));
664 src = checkfor (src, ')');
665 mode->mode = CLASS_BA;
668 imm_operand = &(mode->exp);
679 /* No initial reg. */
680 src = parse_exp (src, &(mode->exp));
684 end = parse_reg (src, &(mode->mode), ®n);
685 regword (mode->mode, "addr(Ra) ra");
686 mode->mode = CLASS_X;
689 da_operand = &(mode->exp);
690 src = checkfor (end, ')');
694 /* Just an address. */
695 mode->mode = CLASS_DA;
698 da_operand = &(mode->exp);
706 get_operands (const opcode_entry_type *opcode, char *op_end, op_type *operand)
711 switch (opcode->noperands)
721 if (opcode->arg_info[0] == CLASS_CC)
723 get_cc_operand (&ptr, operand + 0, 0);
726 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
728 as_bad (_("invalid condition code '%s'"), ptr);
729 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
730 ptr++; /* Consume rest of line. */
733 else if (opcode->arg_info[0] == CLASS_FLAGS)
735 get_flags_operand (&ptr, operand + 0, 0);
738 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
740 as_bad (_("invalid flag '%s'"), ptr);
741 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
742 ptr++; /* Consume rest of line. */
745 else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2)))
746 get_interrupt_operand (&ptr, operand + 0, 0);
748 get_operand (&ptr, operand + 0, 0);
755 if (opcode->arg_info[0] == CLASS_CC)
757 get_cc_operand (&ptr, operand + 0, 0);
760 if (*ptr != ',' && strchr (ptr + 1, ','))
767 as_bad (_("invalid condition code '%s'"), savptr);
770 else if (opcode->arg_info[0] == CLASS_CTRL)
772 get_ctrl_operand (&ptr, operand + 0, 0);
777 get_operand (&ptr, operand + 0, 0);
783 get_ctrl_operand (&ptr, operand + 1, 1);
790 get_operand (&ptr, operand + 0, 0);
796 get_operand (&ptr, operand + 1, 1);
800 get_operand (&ptr, operand + 0, 0);
803 get_operand (&ptr, operand + 1, 1);
806 get_operand (&ptr, operand + 2, 2);
810 get_operand (&ptr, operand + 0, 0);
813 get_operand (&ptr, operand + 1, 1);
816 get_operand (&ptr, operand + 2, 2);
819 get_cc_operand (&ptr, operand + 3, 3);
829 /* Passed a pointer to a list of opcodes which use different
830 addressing modes. Return the opcode which matches the opcodes
833 static opcode_entry_type *
834 get_specific (opcode_entry_type *opcode, op_type *operands)
836 opcode_entry_type *this_try = opcode;
838 unsigned int noperands = opcode->noperands;
840 int this_index = opcode->idx;
842 while (this_index == opcode->idx && !found)
847 for (i = 0; i < noperands; i++)
849 unsigned int mode = operands[i].mode;
851 if (((mode & CLASS_MASK) == CLASS_IR) && ((this_try->arg_info[i] & CLASS_MASK) == CLASS_IRO))
853 mode = operands[i].mode = (operands[i].mode & ~CLASS_MASK) | CLASS_IRO;
856 if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK))
858 /* It could be a pc rel operand, if this is a da mode
859 and we like disps, then insert it. */
861 if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP)
863 /* This is the case. */
864 operands[i].mode = CLASS_DISP;
866 else if (mode == CLASS_BA && this_try->arg_info[i])
868 /* Can't think of a way to turn what we've been
869 given into something that's OK. */
872 else if (this_try->arg_info[i] & CLASS_PR)
874 if (mode == CLASS_REG_LONG && segmented_mode)
878 else if (mode == CLASS_REG_WORD && !segmented_mode)
888 switch (mode & CLASS_MASK)
893 if (operands[i].regsize != CLASS_REG_WORD)
894 as_bad (_("invalid indirect register size"));
895 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
898 if ((segmented_mode && operands[i].regsize != CLASS_REG_LONG)
899 || (!segmented_mode && operands[i].regsize != CLASS_REG_WORD))
900 as_bad (_("invalid indirect register size"));
901 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
913 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
916 if (this_try->opcode == OPC_ldctlb && the_ctrl != 1)
917 as_bad (_("invalid control register name"));
932 static char buffer[20];
935 newfix (int ptr, int type, int size, expressionS *operand)
940 /* Size is in nibbles. */
941 if (operand->X_add_symbol
942 || operand->X_op_symbol
943 || operand->X_add_number)
947 case BFD_RELOC_8_PCREL:
948 case BFD_RELOC_Z8K_CALLR:
949 case BFD_RELOC_Z8K_DISP7:
952 fixP = fix_new_exp (frag_now, ptr, size / 2,
953 operand, is_pcrel, type);
955 fixP->fx_no_overflow = 1;
960 apply_fix (char *ptr, int type, expressionS *operand, int size)
962 long n = operand->X_add_number;
964 /* size is in nibbles. */
966 newfix ((ptr - buffer) / 2, type, size + 1, operand);
969 case 8: /* 8 nibbles == 32 bits. */
974 case 4: /* 4 nibbles == 16 bits. */
986 /* Now we know what sort of opcodes it is. Let's build the bytes. */
989 build_bytes (opcode_entry_type *this_try, struct z8k_op *operand ATTRIBUTE_UNUSED)
991 char *output_ptr = buffer;
994 unsigned int *class_ptr;
996 frag_wane (frag_now);
999 if (frag_room () < 8)
1000 frag_grow (8); /* Make room for maximum instruction size. */
1002 memset (buffer, 0, sizeof (buffer));
1003 class_ptr = this_try->byte_info;
1005 for (nibble = 0; (c = *class_ptr++); nibble++)
1008 switch (c & CLASS_MASK)
1014 /* Direct address, we don't cope with the SS mode right now. */
1017 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
1018 output_ptr = apply_fix (output_ptr, BFD_RELOC_32, da_operand, 8);
1022 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, da_operand, 4);
1028 output_ptr = apply_fix (output_ptr, BFD_RELOC_8_PCREL, da_operand, 2);
1035 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_DISP7, da_operand, 2);
1042 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_DISP7, da_operand, 2);
1043 output_ptr[-2] = 0x8;
1047 case CLASS_BIT_1OR2:
1048 *output_ptr = c & 0xf;
1051 if (imm_operand->X_add_number == 2)
1053 else if (imm_operand->X_add_number != 1)
1054 as_bad (_("immediate must be 1 or 2"));
1057 as_bad (_("immediate 1 or 2 expected"));
1061 *output_ptr++ = the_cc;
1064 if (the_ctrl < 2 || the_ctrl > 7)
1065 as_bad (_("invalid control register name"));
1066 *output_ptr++ = the_ctrl;
1069 if (the_ctrl < 2 || the_ctrl > 7)
1070 as_bad (_("invalid control register name"));
1071 *output_ptr++ = the_ctrl | 0x8;
1074 *output_ptr++ = (~the_interrupt & 0x3);
1077 *output_ptr++ = (~the_interrupt & 0x3) | 0x4;
1080 *output_ptr++ = the_flags;
1084 *output_ptr++ = c & 0xf;
1087 if (reg[c & 0xf] == 0)
1088 as_bad (_("can't use R0 here"));
1091 case CLASS_REG_BYTE:
1092 case CLASS_REG_WORD:
1093 case CLASS_REG_LONG:
1094 case CLASS_REG_QUAD:
1095 /* Insert bit mattern of right reg. */
1096 *output_ptr++ = reg[c & 0xf];
1099 switch (c & ARG_MASK)
1102 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_CALLR, da_operand, 4);
1105 output_ptr = apply_fix (output_ptr, BFD_RELOC_16_PCREL, da_operand, 4);
1108 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, da_operand, 4);
1115 switch (c & ARG_MASK)
1118 if (imm_operand->X_add_number > 15)
1119 as_bad (_("immediate value out of range"));
1120 imm_operand->X_add_number = -imm_operand->X_add_number;
1121 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_IMM4L, imm_operand, 1);
1123 /*case ARG_IMMNMINUS1: not used. */
1125 imm_operand->X_add_number--;
1128 if (imm_operand->X_add_number > 15)
1129 as_bad (_("immediate value out of range"));
1130 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_IMM4L, imm_operand, 1);
1133 imm_operand->X_add_number = -imm_operand->X_add_number;
1136 output_ptr = apply_fix (output_ptr, BFD_RELOC_8, imm_operand, 2);
1139 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, imm_operand, 4);
1142 output_ptr = apply_fix (output_ptr, BFD_RELOC_32, imm_operand, 8);
1151 /* Copy from the nibble buffer into the frag. */
1153 int length = (output_ptr - buffer) / 2;
1155 char *fragp = frag_more (length);
1157 while (src < output_ptr)
1159 *fragp = (src[0] << 4) | src[1];
1166 /* This is the guts of the machine-dependent assembler. STR points to a
1167 machine dependent instruction. This function is supposed to emit
1168 the frags/bytes it assembles to. */
1171 md_assemble (char *str)
1176 struct z8k_op operand[4];
1177 opcode_entry_type *opcode;
1179 /* Drop leading whitespace. */
1183 /* Find the op code end. */
1184 for (op_start = op_end = str;
1185 *op_end != 0 && *op_end != ' ' && ! is_end_of_line[(unsigned char) *op_end];
1189 if (op_end == op_start)
1191 as_bad (_("can't find opcode "));
1195 *op_end = 0; /* Zero-terminate op code string for hash_find() call. */
1197 opcode = (opcode_entry_type *) hash_find (opcode_hash_control, op_start);
1201 as_bad (_("unknown opcode"));
1205 *op_end = c; /* Restore original string. */
1207 if (opcode->opcode == 250)
1211 char *old = input_line_pointer;
1213 /* Was really a pseudo op. */
1215 input_line_pointer = op_end;
1219 while (*input_line_pointer == ' ')
1220 input_line_pointer++;
1221 p = (pseudo_typeS *) (opcode->func);
1223 (p->poc_handler) (p->poc_val);
1224 input_line_pointer = old;
1229 char *new_input_line_pointer;
1231 new_input_line_pointer = get_operands (opcode, op_end, operand);
1232 if (new_input_line_pointer)
1234 input_line_pointer = new_input_line_pointer;
1235 opcode = get_specific (opcode, operand);
1238 if (new_input_line_pointer == NULL || opcode == NULL)
1240 /* Couldn't find an opcode which matched the operands. */
1241 char *where = frag_more (2);
1246 as_bad (_("Can't find opcode to match operands"));
1250 build_bytes (opcode, operand);
1254 /* We have no need to default values of symbols. */
1257 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1262 /* Various routines to kill one day. */
1263 /* Equal to MAX_PRECISION in atof-ieee.c. */
1264 #define MAX_LITTLENUMS 6
1266 /* Turn a string in input_line_pointer into a floating point constant
1267 of type TYPE, and store the appropriate bytes in *LITP. The number
1268 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1269 returned, or NULL on OK. */
1272 md_atof (int type, char *litP, int *sizeP)
1275 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1276 LITTLENUM_TYPE *wordP;
1307 return _("Bad call to MD_ATOF()");
1309 t = atof_ieee (input_line_pointer, type, words);
1311 input_line_pointer = t;
1313 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1314 for (wordP = words; prec--;)
1316 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1317 litP += sizeof (LITTLENUM_TYPE);
1322 const char *md_shortopts = "z:";
1324 struct option md_longopts[] =
1326 #define OPTION_RELAX (OPTION_MD_BASE)
1327 {"linkrelax", no_argument, NULL, OPTION_RELAX},
1328 {NULL, no_argument, NULL, 0}
1331 size_t md_longopts_size = sizeof (md_longopts);
1334 md_parse_option (int c, char *arg)
1339 if (!strcmp (arg, "8001"))
1341 else if (!strcmp (arg, "8002"))
1345 as_bad (_("invalid architecture -z%s"), arg);
1348 z8k_target_from_cmdline = 1;
1363 md_show_usage (FILE *stream)
1365 fprintf (stream, _("\
1367 -z8001 generate segmented code\n\
1368 -z8002 generate unsegmented code\n\
1369 -linkrelax create linker relaxable code\n"));
1373 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
1374 segT sec ATTRIBUTE_UNUSED,
1375 fragS *fragP ATTRIBUTE_UNUSED)
1377 printf (_("call to md_convert_frag\n"));
1381 /* Generate a machine dependent reloc from a fixup. */
1384 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED,
1385 fixS *fixp ATTRIBUTE_UNUSED)
1389 reloc = xmalloc (sizeof (*reloc));
1390 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
1391 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1392 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1393 reloc->addend = fixp->fx_offset;
1394 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1398 as_bad_where (fixp->fx_file, fixp->fx_line,
1399 "Cannot represent %s relocation in object file",
1400 bfd_get_reloc_code_name (fixp->fx_r_type));
1407 md_section_align (segT seg, valueT size)
1409 int align = bfd_get_section_alignment (stdoutput, seg);
1410 valueT mask = ((valueT) 1 << align) - 1;
1412 return (size + mask) & ~mask;
1415 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1416 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1417 we will have to generate a reloc entry. */
1419 md_apply_fix (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
1421 long val = * (long *) valP;
1422 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1424 switch (fixP->fx_r_type)
1426 case BFD_RELOC_Z8K_IMM4L:
1429 fixP->fx_no_overflow = 1;
1433 buf[0] = (buf[0] & 0xf0) | (val & 0xf);
1439 fixP->fx_no_overflow = 1;
1449 fixP->fx_no_overflow = 1;
1454 *buf++ = (val >> 8);
1462 fixP->fx_no_overflow = 1;
1467 *buf++ = (val >> 24);
1468 *buf++ = (val >> 16);
1469 *buf++ = (val >> 8);
1474 case BFD_RELOC_8_PCREL:
1477 fixP->fx_no_overflow = 1;
1483 as_bad_where (fixP->fx_file, fixP->fx_line,
1484 _("cannot branch to odd address"));
1486 if (val > 127 || val < -128)
1487 as_bad_where (fixP->fx_file, fixP->fx_line,
1488 _("relative jump out of range"));
1490 fixP->fx_no_overflow = 1;
1495 case BFD_RELOC_16_PCREL:
1498 fixP->fx_no_overflow = 1;
1503 val = val - fixP->fx_frag->fr_address + fixP->fx_where - fixP->fx_size;
1504 if (val > 32767 || val < -32768)
1505 as_bad_where (fixP->fx_file, fixP->fx_line,
1506 _("relative address out of range"));
1507 *buf++ = (val >> 8);
1509 fixP->fx_no_overflow = 1;
1514 case BFD_RELOC_Z8K_CALLR:
1517 fixP->fx_no_overflow = 1;
1523 as_bad_where (fixP->fx_file, fixP->fx_line,
1524 _("cannot branch to odd address"));
1525 if (val > 4096 || val < -4095)
1526 as_bad_where (fixP->fx_file, fixP->fx_line,
1527 _("relative call out of range"));
1529 *buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1531 *buf++ = val & 0xff;
1532 fixP->fx_no_overflow = 1;
1537 case BFD_RELOC_Z8K_DISP7:
1540 fixP->fx_no_overflow = 1;
1546 as_bad_where (fixP->fx_file, fixP->fx_line,
1547 _("cannot branch to odd address"));
1549 if (val > 0 || val < -127)
1550 as_bad_where (fixP->fx_file, fixP->fx_line,
1551 _("relative jump out of range"));
1552 *buf = (*buf & 0x80) | (-val & 0x7f);
1553 fixP->fx_no_overflow = 1;
1559 printf(_("md_apply_fix: unknown r_type 0x%x\n"), fixP->fx_r_type);
1563 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1568 md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
1569 segT segment_type ATTRIBUTE_UNUSED)
1571 printf (_("call to md_estimate_size_before_relax\n"));
1575 /* Put number into target byte order. */
1578 md_number_to_chars (char *ptr, valueT use, int nbytes)
1580 number_to_chars_bigendian (ptr, use, nbytes);
1583 /* On the Z8000, a PC-relative offset is relative to the address of the
1584 instruction plus its size. */
1586 md_pcrel_from (fixS *fixP)
1588 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1592 tc_coff_symbol_emit_hook (symbolS *s ATTRIBUTE_UNUSED)