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
29 #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;
39 const int md_reloc_size;
41 /* This is non-zero if target was set from the command line. */
42 static int z8k_target_from_cmdline;
50 machine = bfd_mach_z8001;
56 machine = bfd_mach_z8002;
62 even (int ignore ATTRIBUTE_UNUSED)
65 record_alignment (now_seg, 1);
79 sval (int ignore ATTRIBUTE_UNUSED)
82 if (*input_line_pointer == '\'')
86 c = *input_line_pointer++;
91 c = (tohex (input_line_pointer[0]) << 4)
92 | tohex (input_line_pointer[1]);
93 input_line_pointer += 2;
95 FRAG_APPEND_1_CHAR (c);
96 c = *input_line_pointer++;
98 demand_empty_rest_of_line ();
102 /* This table describes all the machine specific pseudo-ops the assembler
103 has to support. The fields are:
104 pseudo-op name without dot
105 function to call to execute this pseudo-op
106 Integer arg to pass to the function
109 const pseudo_typeS md_pseudo_table[] = {
111 {"data.b" , cons , 1},
112 {"data.w" , cons , 2},
113 {"data.l" , cons , 4},
114 {"form" , listing_psize , 0},
115 {"heading", listing_title , 0},
116 {"import" , s_ignore , 0},
117 {"page" , listing_eject , 0},
118 {"program", s_ignore , 0},
119 {"z8001" , s_segm , 1},
120 {"z8002" , s_segm , 0},
122 {"segm" , s_segm , 1},
123 {"unsegm" , s_segm , 0},
124 {"unseg" , s_segm , 0},
125 {"name" , s_app_file , 0},
126 {"global" , s_globl , 0},
131 {"rsect" , obj_coff_section, 0},
132 {"sect" , obj_coff_section, 0},
133 {"block" , s_space , 0},
138 const char EXP_CHARS[] = "eE";
140 /* Chars that mean this number is a floating point constant.
143 const char FLT_CHARS[] = "rRsSfFdDxXpP";
145 /* Opcode mnemonics. */
146 static struct hash_control *opcode_hash_control;
151 const opcode_entry_type *opcode;
154 opcode_hash_control = hash_new ();
156 for (opcode = z8k_table; opcode->name; opcode++)
158 /* Only enter unique codes into the table. */
159 if (idx != opcode->idx)
160 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
164 /* Default to z8002. */
165 if (! z8k_target_from_cmdline)
168 /* Insert the pseudo ops, too. */
169 for (idx = 0; md_pseudo_table[idx].poc_name; idx++)
171 opcode_entry_type *fake_opcode;
172 fake_opcode = (opcode_entry_type *) malloc (sizeof (opcode_entry_type));
173 fake_opcode->name = md_pseudo_table[idx].poc_name;
174 fake_opcode->func = (void *) (md_pseudo_table + idx);
175 fake_opcode->opcode = 250;
176 hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode);
180 typedef struct z8k_op {
189 /* Any other register associated with the mode. */
192 /* Any expression. */
196 static expressionS *da_operand;
197 static expressionS *imm_operand;
202 static int the_flags;
203 static int the_interrupt;
206 whatreg (unsigned int *reg, char *src)
208 if (ISDIGIT (src[1]))
210 *reg = (src[0] - '0') * 10 + src[1] - '0';
215 *reg = (src[0] - '0');
226 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
234 /* Try to parse a reg name. Return a pointer to the first character
235 in SRC after the reg name. */
238 parse_reg (char *src, int *mode, unsigned int *reg)
243 /* Check for stack pointer "sp" alias. */
244 if ((src[0] == 's' || src[0] == 'S')
245 && (src[1] == 'p' || src[1] == 'P')
246 && (src[2] == 0 || src[2] == ','))
250 *mode = CLASS_REG_LONG;
255 *mode = CLASS_REG_WORD;
261 if (src[0] == 'r' || src[0] == 'R')
263 if (src[1] == 'r' || src[1] == 'R')
265 if (src[2] < '0' || src[2] > '9')
266 return res; /* Assume no register name but a label starting with 'rr'. */
267 *mode = CLASS_REG_LONG;
268 res = whatreg (reg, src + 2);
271 as_bad (_("register rr%d out of range"), regno);
273 as_bad (_("register rr%d does not exist"), regno);
275 else if (src[1] == 'h' || src[1] == 'H')
277 if (src[2] < '0' || src[2] > '9')
278 return res; /* Assume no register name but a label starting with 'rh'. */
279 *mode = CLASS_REG_BYTE;
280 res = whatreg (reg, src + 2);
283 as_bad (_("register rh%d out of range"), regno);
285 else if (src[1] == 'l' || src[1] == 'L')
287 if (src[2] < '0' || src[2] > '9')
288 return res; /* Assume no register name but a label starting with 'rl'. */
289 *mode = CLASS_REG_BYTE;
290 res = whatreg (reg, src + 2);
293 as_bad (_("register rl%d out of range"), regno);
296 else if (src[1] == 'q' || src[1] == 'Q')
298 if (src[2] < '0' || src[2] > '9')
299 return res; /* Assume no register name but a label starting with 'rq'. */
300 *mode = CLASS_REG_QUAD;
301 res = whatreg (reg, src + 2);
304 as_bad (_("register rq%d out of range"), regno);
306 as_bad (_("register rq%d does not exist"), regno);
310 if (src[1] < '0' || src[1] > '9')
311 return res; /* Assume no register name but a label starting with 'r'. */
312 *mode = CLASS_REG_WORD;
313 res = whatreg (reg, src + 1);
316 as_bad (_("register r%d out of range"), regno);
323 parse_exp (char *s, expressionS *op)
325 char *save = input_line_pointer;
328 input_line_pointer = s;
330 if (op->X_op == O_absent)
331 as_bad (_("missing operand"));
332 new = input_line_pointer;
333 input_line_pointer = save;
337 /* The many forms of operand:
352 checkfor (char *ptr, char what)
357 as_bad (_("expected %c"), what);
362 /* Make sure the mode supplied is the size of a word. */
365 regword (int mode, char *string)
372 as_bad (_("register is wrong size for a word %s"), string);
376 /* Make sure the mode supplied is the size of an address. */
379 regaddr (int mode, char *string)
383 ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
386 as_bad (_("register is wrong size for address %s"), string);
395 static struct ctrl_names ctrl_table[] = {
396 { 0x1, "flags" }, /* ldctlb only. */
397 { 0x2, "fcw" }, /* ldctl only. Applies to all remaining control registers. */
409 get_ctrl_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
417 mode->mode = CLASS_CTRL;
418 for (i = 0; ctrl_table[i].name; i++)
420 l = strlen (ctrl_table[i].name);
421 if (! strncasecmp (ctrl_table[i].name, src, l))
423 the_ctrl = ctrl_table[i].value;
424 if (*(src + l) && *(src + l) != ',')
426 *ptr = src + l; /* Valid control name found: "consume" it. */
438 static struct flag_names flag_table[] = {
450 get_flags_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
460 mode->mode = CLASS_FLAGS;
462 for (j = 0; j <= 9; j++)
467 for (i = 0; flag_table[i].name; i++)
469 if (flag_table[i].name[0] == c)
471 the_flags = the_flags | flag_table[i].value;
483 struct interrupt_names {
488 static struct interrupt_names intr_table[] = {
497 get_interrupt_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
505 mode->mode = CLASS_IMM;
510 for (i = 0; intr_table[i].name; i++)
512 l = strlen (intr_table[i].name);
513 if (! strncasecmp (intr_table[i].name, src, l))
515 the_interrupt |= intr_table[i].value;
516 if (*(src + l) && *(src + l) != ',')
520 as_bad (_("unknown interrupt %s"), src);
521 while (**ptr && ! is_end_of_line[(unsigned char) **ptr])
522 (*ptr)++; /* Consume rest of line. */
542 /* No interrupt type specified, opcode won't do anything. */
543 as_warn (_("opcode has no effect"));
552 static struct cc_names table[] = {
587 get_cc_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
595 mode->mode = CLASS_CC;
596 for (i = 0; table[i].name; i++)
598 l = strlen (table[i].name);
599 if (! strncasecmp (table[i].name, src, l))
601 the_cc = table[i].value;
602 if (*(src + l) && *(src + l) != ',')
604 *ptr = src + l; /* Valid cc found: "consume" it. */
608 the_cc = 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
612 get_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
623 mode->mode = CLASS_IMM;
624 imm_operand = &(mode->exp);
625 src = parse_exp (src + 1, &(mode->exp));
627 else if (*src == '@')
629 mode->mode = CLASS_IR;
630 src = parse_reg (src + 1, &mode->regsize, &mode->reg);
636 end = parse_reg (src, &mode->mode, ®n);
647 end = parse_reg (src, &nw, &nr);
654 as_bad (_("Missing ) in ra(rb)"));
658 regaddr (mode->mode, "ra(rb) ra");
659 mode->mode = CLASS_BX;
669 src = parse_exp (src, &(mode->exp));
670 src = checkfor (src, ')');
671 mode->mode = CLASS_BA;
674 imm_operand = &(mode->exp);
685 /* No initial reg. */
686 src = parse_exp (src, &(mode->exp));
690 end = parse_reg (src, &(mode->mode), ®n);
691 regword (mode->mode, "addr(Ra) ra");
692 mode->mode = CLASS_X;
695 da_operand = &(mode->exp);
696 src = checkfor (end, ')');
700 /* Just an address. */
701 mode->mode = CLASS_DA;
704 da_operand = &(mode->exp);
712 get_operands (const opcode_entry_type *opcode, char *op_end, op_type *operand)
717 switch (opcode->noperands)
727 if (opcode->arg_info[0] == CLASS_CC)
729 get_cc_operand (&ptr, operand + 0, 0);
732 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
734 as_bad (_("invalid condition code '%s'"), ptr);
735 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
736 ptr++; /* Consume rest of line. */
739 else if (opcode->arg_info[0] == CLASS_FLAGS)
741 get_flags_operand (&ptr, operand + 0, 0);
744 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
746 as_bad (_("invalid flag '%s'"), ptr);
747 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
748 ptr++; /* Consume rest of line. */
751 else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2)))
752 get_interrupt_operand (&ptr, operand + 0, 0);
754 get_operand (&ptr, operand + 0, 0);
761 if (opcode->arg_info[0] == CLASS_CC)
763 get_cc_operand (&ptr, operand + 0, 0);
766 if (*ptr != ',' && strchr (ptr + 1, ','))
773 as_bad (_("invalid condition code '%s'"), savptr);
776 else if (opcode->arg_info[0] == CLASS_CTRL)
778 get_ctrl_operand (&ptr, operand + 0, 0);
783 get_operand (&ptr, operand + 0, 0);
789 get_ctrl_operand (&ptr, operand + 1, 1);
796 get_operand (&ptr, operand + 0, 0);
802 get_operand (&ptr, operand + 1, 1);
806 get_operand (&ptr, operand + 0, 0);
809 get_operand (&ptr, operand + 1, 1);
812 get_operand (&ptr, operand + 2, 2);
816 get_operand (&ptr, operand + 0, 0);
819 get_operand (&ptr, operand + 1, 1);
822 get_operand (&ptr, operand + 2, 2);
825 get_cc_operand (&ptr, operand + 3, 3);
835 /* Passed a pointer to a list of opcodes which use different
836 addressing modes. Return the opcode which matches the opcodes
839 static opcode_entry_type *
840 get_specific (opcode_entry_type *opcode, op_type *operands)
842 opcode_entry_type *this_try = opcode;
844 unsigned int noperands = opcode->noperands;
846 int this_index = opcode->idx;
848 while (this_index == opcode->idx && !found)
853 for (i = 0; i < noperands; i++)
855 unsigned int mode = operands[i].mode;
857 if (((mode & CLASS_MASK) == CLASS_IR) && ((this_try->arg_info[i] & CLASS_MASK) == CLASS_IRO))
859 mode = operands[i].mode = (operands[i].mode & ~CLASS_MASK) | CLASS_IRO;
862 if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK))
864 /* It could be a pc rel operand, if this is a da mode
865 and we like disps, then insert it. */
867 if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP)
869 /* This is the case. */
870 operands[i].mode = CLASS_DISP;
872 else if (mode == CLASS_BA && this_try->arg_info[i])
874 /* Can't think of a way to turn what we've been
875 given into something that's OK. */
878 else if (this_try->arg_info[i] & CLASS_PR)
880 if (mode == CLASS_REG_LONG && segmented_mode)
884 else if (mode == CLASS_REG_WORD && !segmented_mode)
894 switch (mode & CLASS_MASK)
899 if (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;
904 if ((segmented_mode && operands[i].regsize != CLASS_REG_LONG)
905 || (!segmented_mode && operands[i].regsize != CLASS_REG_WORD))
906 as_bad (_("invalid indirect register size"));
907 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
919 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
922 if (this_try->opcode == OPC_ldctlb && the_ctrl != 1)
923 as_bad (_("invalid control register name"));
938 static char buffer[20];
941 newfix (int ptr, int type, int size, expressionS *operand)
945 /* size is in nibbles. */
947 if (operand->X_add_symbol
948 || operand->X_op_symbol
949 || operand->X_add_number)
958 fix_new_exp (frag_now,
968 apply_fix (char *ptr, int type, expressionS *operand, int size)
970 long n = operand->X_add_number;
972 /* size is in nibbles. */
974 newfix ((ptr - buffer) / 2, type, size + 1, operand);
977 case 8: /* 8 nibbles == 32 bits. */
982 case 4: /* 4 nibbles == 16 bits. */
994 /* Now we know what sort of opcodes it is. Let's build the bytes. */
997 build_bytes (opcode_entry_type *this_try, struct z8k_op *operand ATTRIBUTE_UNUSED)
999 char *output_ptr = buffer;
1002 unsigned int *class_ptr;
1004 frag_wane (frag_now);
1007 memset (buffer, 0, sizeof (buffer));
1008 class_ptr = this_try->byte_info;
1010 for (nibble = 0; (c = *class_ptr++); nibble++)
1013 switch (c & CLASS_MASK)
1019 /* Direct address, we don't cope with the SS mode right now. */
1022 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
1023 output_ptr = apply_fix (output_ptr, R_IMM32, da_operand, 8);
1027 output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
1033 output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
1040 output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
1047 output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
1048 output_ptr[-2] = 0x8;
1052 case CLASS_BIT_1OR2:
1053 *output_ptr = c & 0xf;
1056 if (imm_operand->X_add_number == 2)
1058 else if (imm_operand->X_add_number != 1)
1059 as_bad (_("immediate must be 1 or 2"));
1062 as_bad (_("immediate 1 or 2 expected"));
1066 *output_ptr++ = the_cc;
1069 if (the_ctrl < 2 || the_ctrl > 7)
1070 as_bad (_("invalid control register name"));
1071 *output_ptr++ = the_ctrl;
1074 if (the_ctrl < 2 || the_ctrl > 7)
1075 as_bad (_("invalid control register name"));
1076 *output_ptr++ = the_ctrl | 0x8;
1079 *output_ptr++ = (~the_interrupt & 0x3);
1082 *output_ptr++ = (~the_interrupt & 0x3) | 0x4;
1085 *output_ptr++ = the_flags;
1089 *output_ptr++ = c & 0xf;
1092 if (reg[c & 0xf] == 0)
1093 as_bad (_("can't use R0 here"));
1096 case CLASS_REG_BYTE:
1097 case CLASS_REG_WORD:
1098 case CLASS_REG_LONG:
1099 case CLASS_REG_QUAD:
1100 /* Insert bit mattern of right reg. */
1101 *output_ptr++ = reg[c & 0xf];
1104 switch (c & ARG_MASK)
1107 output_ptr = apply_fix (output_ptr, R_CALLR, da_operand, 4);
1110 output_ptr = apply_fix (output_ptr, R_REL16, da_operand, 4);
1113 output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
1120 switch (c & ARG_MASK)
1123 if (imm_operand->X_add_number > 15)
1125 as_bad (_("immediate value out of range"));
1127 imm_operand->X_add_number = -imm_operand->X_add_number;
1128 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
1130 /*case ARG_IMMNMINUS1: not used. */
1132 imm_operand->X_add_number--;
1135 if (imm_operand->X_add_number > 15)
1137 as_bad (_("immediate value out of range"));
1139 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
1142 imm_operand->X_add_number = -imm_operand->X_add_number;
1145 output_ptr = apply_fix (output_ptr, R_IMM8, imm_operand, 2);
1148 output_ptr = apply_fix (output_ptr, R_IMM16, imm_operand, 4);
1151 output_ptr = apply_fix (output_ptr, R_IMM32, imm_operand, 8);
1160 /* Copy from the nibble buffer into the frag. */
1162 int length = (output_ptr - buffer) / 2;
1164 char *fragp = frag_more (length);
1166 while (src < output_ptr)
1168 *fragp = (src[0] << 4) | src[1];
1175 /* This is the guts of the machine-dependent assembler. STR points to a
1176 machine dependent instruction. This function is supposed to emit
1177 the frags/bytes it assembles to. */
1180 md_assemble (char *str)
1185 struct z8k_op operand[4];
1186 opcode_entry_type *opcode;
1188 /* Drop leading whitespace. */
1192 /* Find the op code end. */
1193 for (op_start = op_end = str;
1194 *op_end != 0 && *op_end != ' ' && ! is_end_of_line[(unsigned char) *op_end];
1198 if (op_end == op_start)
1200 as_bad (_("can't find opcode "));
1204 *op_end = 0; /* Zero-terminate op code string for hash_find() call. */
1206 opcode = (opcode_entry_type *) hash_find (opcode_hash_control, op_start);
1210 as_bad (_("unknown opcode"));
1214 *op_end = c; /* Restore original string. */
1216 if (opcode->opcode == 250)
1220 char *old = input_line_pointer;
1222 /* Was really a pseudo op. */
1224 input_line_pointer = op_end;
1228 while (*input_line_pointer == ' ')
1229 input_line_pointer++;
1230 p = (pseudo_typeS *) (opcode->func);
1232 (p->poc_handler) (p->poc_val);
1233 input_line_pointer = old;
1238 char *new_input_line_pointer;
1240 new_input_line_pointer = get_operands (opcode, op_end, operand);
1241 if (new_input_line_pointer)
1243 input_line_pointer = new_input_line_pointer;
1244 opcode = get_specific (opcode, operand);
1247 if (new_input_line_pointer == NULL || opcode == NULL)
1249 /* Couldn't find an opcode which matched the operands. */
1250 char *where = frag_more (2);
1255 as_bad (_("Can't find opcode to match operands"));
1259 build_bytes (opcode, operand);
1264 tc_crawl_symbol_chain (object_headers *headers ATTRIBUTE_UNUSED)
1266 printf (_("call to tc_crawl_symbol_chain \n"));
1269 /* We have no need to default values of symbols. */
1272 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1278 tc_headers_hook (object_headers *headers ATTRIBUTE_UNUSED)
1280 printf (_("call to tc_headers_hook \n"));
1283 /* Various routines to kill one day. */
1284 /* Equal to MAX_PRECISION in atof-ieee.c. */
1285 #define MAX_LITTLENUMS 6
1287 /* Turn a string in input_line_pointer into a floating point constant
1288 of type TYPE, and store the appropriate bytes in *LITP. The number
1289 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1290 returned, or NULL on OK. */
1293 md_atof (int type, char *litP, int *sizeP)
1296 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1297 LITTLENUM_TYPE *wordP;
1328 return _("Bad call to MD_ATOF()");
1330 t = atof_ieee (input_line_pointer, type, words);
1332 input_line_pointer = t;
1334 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1335 for (wordP = words; prec--;)
1337 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1338 litP += sizeof (LITTLENUM_TYPE);
1343 const char *md_shortopts = "z:";
1345 struct option md_longopts[] =
1347 #define OPTION_RELAX (OPTION_MD_BASE)
1348 {"linkrelax", no_argument, NULL, OPTION_RELAX},
1349 {NULL, no_argument, NULL, 0}
1352 size_t md_longopts_size = sizeof (md_longopts);
1355 md_parse_option (int c, char *arg)
1360 if (!strcmp (arg, "8001"))
1362 else if (!strcmp (arg, "8002"))
1366 as_bad (_("invalid architecture -z%s"), arg);
1369 z8k_target_from_cmdline = 1;
1384 md_show_usage (FILE *stream)
1386 fprintf (stream, _("\
1388 -z8001 generate segmented code\n\
1389 -z8002 generate unsegmented code\n\
1390 -linkrelax create linker relaxable code\n"));
1394 md_convert_frag (object_headers *headers ATTRIBUTE_UNUSED,
1395 segT seg ATTRIBUTE_UNUSED,
1396 fragS *fragP ATTRIBUTE_UNUSED)
1398 printf (_("call to md_convert_frag\n"));
1403 md_section_align (segT seg, valueT size)
1405 return ((size + (1 << section_alignment[(int) seg]) - 1)
1406 & (-1 << section_alignment[(int) seg]));
1409 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1410 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1411 we will have to generate a reloc entry. */
1413 md_apply_fix (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
1415 long val = * (long *) valP;
1416 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1418 switch (fixP->fx_r_type)
1421 buf[0] = (buf[0] & 0xf0) | (val & 0xf);
1427 fixP->fx_no_overflow = 1;
1433 as_bad_where (fixP->fx_file, fixP->fx_line,
1434 _("cannot branch to odd address"));
1436 if (val > 127 || val < -128)
1437 as_bad_where (fixP->fx_file, fixP->fx_line,
1438 _("relative jump out of range"));
1440 fixP->fx_no_overflow = 1;
1448 fixP->fx_no_overflow = 1;
1454 as_bad_where (fixP->fx_file, fixP->fx_line,
1455 _("cannot branch to odd address"));
1457 if (val > 0 || val < -127)
1458 as_bad_where (fixP->fx_file, fixP->fx_line,
1459 _("relative jump out of range"));
1460 *buf = (*buf & 0x80) | (-val & 0x7f);
1461 fixP->fx_no_overflow = 1;
1469 fixP->fx_no_overflow = 1;
1475 as_bad_where (fixP->fx_file, fixP->fx_line,
1476 _("cannot branch to odd address"));
1477 if (val > 4096 || val < -4095)
1478 as_bad_where (fixP->fx_file, fixP->fx_line,
1479 _("relative call out of range"));
1481 *buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1483 *buf++ = val & 0xff;
1484 fixP->fx_no_overflow = 1;
1494 *buf++ = (val >> 8);
1499 *buf++ = (val >> 24);
1500 *buf++ = (val >> 16);
1501 *buf++ = (val >> 8);
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;
1516 md_number_to_chars (buf, val, fixP->fx_size);
1520 printf(_("md_apply_fix: unknown r_type 0x%x\n"), fixP->fx_r_type);
1524 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1529 md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
1530 segT segment_type ATTRIBUTE_UNUSED)
1532 printf (_("call to md_estimate_size_before_relax\n"));
1536 /* Put number into target byte order. */
1539 md_number_to_chars (char *ptr, valueT use, int nbytes)
1541 number_to_chars_bigendian (ptr, use, nbytes);
1544 /* On the Z8000, a PC-relative offset is relative to the address of the
1545 instruction plus its size. */
1547 md_pcrel_from (fixS *fixP)
1549 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1553 tc_coff_symbol_emit_hook (symbolS *s ATTRIBUTE_UNUSED)
1558 tc_reloc_mangle (fixS *fix_ptr, struct internal_reloc *intr, bfd_vma base)
1560 symbolS *symbol_ptr;
1562 if (fix_ptr->fx_addsy
1563 && fix_ptr->fx_subsy)
1565 symbolS *add = fix_ptr->fx_addsy;
1566 symbolS *sub = fix_ptr->fx_subsy;
1568 if (S_GET_SEGMENT (add) != S_GET_SEGMENT (sub))
1569 as_bad (_("Can't subtract symbols in different sections %s %s"),
1570 S_GET_NAME (add), S_GET_NAME (sub));
1573 int diff = S_GET_VALUE (add) - S_GET_VALUE (sub);
1575 fix_ptr->fx_addsy = 0;
1576 fix_ptr->fx_subsy = 0;
1577 fix_ptr->fx_offset += diff;
1580 symbol_ptr = fix_ptr->fx_addsy;
1582 /* If this relocation is attached to a symbol then it's ok
1584 if (fix_ptr->fx_r_type == 0)
1586 /* cons likes to create reloc32's whatever the size of the reloc. */
1587 switch (fix_ptr->fx_size)
1590 intr->r_type = R_IMM16;
1593 intr->r_type = R_IMM8;
1596 intr->r_type = R_IMM32;
1603 intr->r_type = fix_ptr->fx_r_type;
1605 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1606 intr->r_offset = fix_ptr->fx_offset;
1609 intr->r_symndx = symbol_ptr->sy_number;
1611 intr->r_symndx = -1;