1 /* tc-z8k.c -- Assemble code for the Zilog Z800n
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, 2002, 2003
3 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, 59 Temple Place - Suite 330, Boston, MA
22 /* Written By Steve Chamberlain <sac@cygnus.com>. */
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;
44 static void s_segm PARAMS ((int));
45 static void even PARAMS ((int));
46 static int tohex PARAMS ((int));
47 static void sval PARAMS ((int));
56 machine = bfd_mach_z8001;
62 machine = bfd_mach_z8002;
69 int ignore ATTRIBUTE_UNUSED;
72 record_alignment (now_seg, 1);
88 int ignore ATTRIBUTE_UNUSED;
91 if (*input_line_pointer == '\'')
95 c = *input_line_pointer++;
100 c = (tohex (input_line_pointer[0]) << 4)
101 | tohex (input_line_pointer[1]);
102 input_line_pointer += 2;
104 FRAG_APPEND_1_CHAR (c);
105 c = *input_line_pointer++;
107 demand_empty_rest_of_line ();
111 /* This table describes all the machine specific pseudo-ops the assembler
112 has to support. The fields are:
113 pseudo-op name without dot
114 function to call to execute this pseudo-op
115 Integer arg to pass to the function
118 const pseudo_typeS md_pseudo_table[] = {
120 {"data.b" , cons , 1},
121 {"data.w" , cons , 2},
122 {"data.l" , cons , 4},
123 {"form" , listing_psize , 0},
124 {"heading", listing_title , 0},
125 {"import" , s_ignore , 0},
126 {"page" , listing_eject , 0},
127 {"program", s_ignore , 0},
128 {"z8001" , s_segm , 1},
129 {"z8002" , s_segm , 0},
131 {"segm" , s_segm , 1},
132 {"unsegm" , s_segm , 0},
133 {"unseg" , s_segm , 0},
134 {"name" , s_app_file , 0},
135 {"global" , s_globl , 0},
140 {"rsect" , obj_coff_section, 0},
141 {"sect" , obj_coff_section, 0},
142 {"block" , s_space , 0},
147 const char EXP_CHARS[] = "eE";
149 /* Chars that mean this number is a floating point constant.
152 const char FLT_CHARS[] = "rRsSfFdDxXpP";
154 /* Opcode mnemonics. */
155 static struct hash_control *opcode_hash_control;
160 const opcode_entry_type *opcode;
163 opcode_hash_control = hash_new ();
165 for (opcode = z8k_table; opcode->name; opcode++)
167 /* Only enter unique codes into the table. */
168 if (idx != opcode->idx)
169 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
173 /* Default to z8002. */
174 if (! z8k_target_from_cmdline)
177 /* Insert the pseudo ops, too. */
178 for (idx = 0; md_pseudo_table[idx].poc_name; idx++)
180 opcode_entry_type *fake_opcode;
181 fake_opcode = (opcode_entry_type *) malloc (sizeof (opcode_entry_type));
182 fake_opcode->name = md_pseudo_table[idx].poc_name;
183 fake_opcode->func = (void *) (md_pseudo_table + idx);
184 fake_opcode->opcode = 250;
185 hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode);
195 typedef struct z8k_op {
204 /* Any other register associated with the mode. */
207 /* Any expression. */
211 static expressionS *da_operand;
212 static expressionS *imm_operand;
220 static char *whatreg PARAMS ((int *, char *));
221 static char *parse_reg PARAMS ((char *, int *, unsigned int *));
222 static char *parse_exp PARAMS ((char *, expressionS *));
223 static char *checkfor PARAMS ((char *, char));
224 static void regword PARAMS ((int, char *));
225 static void regaddr PARAMS ((int, char *));
226 static void get_ctrl_operand
227 PARAMS ((char **, struct z8k_op *, unsigned int));
228 static void get_flags_operand
229 PARAMS ((char **, struct z8k_op *, unsigned int));
230 static void get_interrupt_operand
231 PARAMS ((char **, struct z8k_op *, unsigned int));
232 static void get_cc_operand
233 PARAMS ((char **, struct z8k_op *, unsigned int));
234 static void get_operand
235 PARAMS ((char **, struct z8k_op *, unsigned int));
236 static char *get_operands
237 PARAMS ((const opcode_entry_type *, char *, op_type *));
238 static opcode_entry_type *get_specific
239 PARAMS ((opcode_entry_type *, op_type *));
241 PARAMS ((int, int, int, expressionS *));
242 static char *apply_fix
243 PARAMS ((char *, int, expressionS *, int));
244 static void build_bytes
245 PARAMS ((opcode_entry_type *, struct z8k_op *));
252 if (ISDIGIT (src[1]))
254 *reg = (src[0] - '0') * 10 + src[1] - '0';
259 *reg = (src[0] - '0');
270 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
278 /* Try to parse a reg name. Return a pointer to the first character
279 in SRC after the reg name. */
282 parse_reg (src, mode, reg)
290 if (src[0] == 's' && src[1] == 'p' && (src[2] == 0 || src[2] == ','))
294 *mode = CLASS_REG_LONG;
299 *mode = CLASS_REG_WORD;
308 if (src[2] < '0' || src[2] > '9')
309 return res; /* Assume no register name but a label starting with 'rr'. */
310 *mode = CLASS_REG_LONG;
311 res = whatreg (reg, src + 2);
314 as_bad (_("register rr%d out of range"), regno);
316 as_bad (_("register rr%d does not exist"), regno);
318 else if (src[1] == 'h')
320 if (src[2] < '0' || src[2] > '9')
321 return res; /* Assume no register name but a label starting with 'rh'. */
322 *mode = CLASS_REG_BYTE;
323 res = whatreg (reg, src + 2);
326 as_bad (_("register rh%d out of range"), regno);
328 else if (src[1] == 'l')
330 if (src[2] < '0' || src[2] > '9')
331 return res; /* Assume no register name but a label starting with 'rl'. */
332 *mode = CLASS_REG_BYTE;
333 res = whatreg (reg, src + 2);
336 as_bad (_("register rl%d out of range"), regno);
339 else if (src[1] == 'q')
341 if (src[2] < '0' || src[2] > '9')
342 return res; /* Assume no register name but a label starting with 'rq'. */
343 *mode = CLASS_REG_QUAD;
344 res = whatreg (reg, src + 2);
347 as_bad (_("register rq%d out of range"), regno);
349 as_bad (_("register rq%d does not exist"), regno);
353 if (src[1] < '0' || src[1] > '9')
354 return res; /* Assume no register name but a label starting with 'r'. */
355 *mode = CLASS_REG_WORD;
356 res = whatreg (reg, src + 1);
359 as_bad (_("register r%d out of range"), regno);
370 char *save = input_line_pointer;
373 input_line_pointer = s;
375 if (op->X_op == O_absent)
376 as_bad (_("missing operand"));
377 new = input_line_pointer;
378 input_line_pointer = save;
382 /* The many forms of operand:
404 as_bad (_("expected %c"), what);
409 /* Make sure the mode supplied is the size of a word. */
412 regword (mode, string)
421 as_bad (_("register is wrong size for a word %s"), string);
425 /* Make sure the mode supplied is the size of an address. */
428 regaddr (mode, string)
434 ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
437 as_bad (_("register is wrong size for address %s"), string);
446 struct ctrl_names ctrl_table[] = {
459 get_ctrl_operand (ptr, mode, dst)
462 unsigned int dst ATTRIBUTE_UNUSED;
470 mode->mode = CLASS_CTRL;
471 for (i = 0; ctrl_table[i].name; i++)
475 for (j = 0; ctrl_table[i].name[j]; j++)
477 if (ctrl_table[i].name[j] != src[j])
480 the_ctrl = ctrl_table[i].value;
496 struct flag_names flag_table[] = {
507 get_flags_operand (ptr, mode, dst)
510 unsigned int dst ATTRIBUTE_UNUSED;
519 mode->mode = CLASS_FLAGS;
521 for (j = 0; j <= 9; j++)
525 for (i = 0; flag_table[i].name; i++)
527 if (flag_table[i].name[0] == src[j])
529 the_flags = the_flags | flag_table[i].value;
542 struct interrupt_names {
548 struct interrupt_names intr_table[] = {
557 get_interrupt_operand (ptr, mode, dst)
560 unsigned int dst ATTRIBUTE_UNUSED;
568 mode->mode = CLASS_IMM;
569 for (i = 0; intr_table[i].name; i++)
573 for (j = 0; intr_table[i].name[j]; j++)
575 if (intr_table[i].name[j] != src[j])
578 the_interrupt = intr_table[i].value;
584 /* No interrupt type specified, opcode won't do anything. */
585 as_warn (_("opcode has no effect"));
595 struct cc_names table[] = {
622 get_cc_operand (ptr, mode, dst)
625 unsigned int dst ATTRIBUTE_UNUSED;
633 mode->mode = CLASS_CC;
634 for (i = 0; table[i].name; i++)
638 for (j = 0; table[i].name[j]; j++)
640 if (table[i].name[j] != src[j])
643 the_cc = table[i].value;
653 get_operand (ptr, mode, dst)
656 unsigned int dst ATTRIBUTE_UNUSED;
667 mode->mode = CLASS_IMM;
668 imm_operand = &(mode->exp);
669 src = parse_exp (src + 1, &(mode->exp));
671 else if (*src == '@')
673 mode->mode = CLASS_IR;
674 src = parse_reg (src + 1, &mode->regsize, &mode->reg);
680 end = parse_reg (src, &mode->mode, ®n);
690 end = parse_reg (src, &nw, &nr);
697 as_bad (_("Missing ) in ra(rb)"));
701 regaddr (mode->mode, "ra(rb) ra");
703 regword (mode->mode, "ra(rb) rb");
705 mode->mode = CLASS_BX;
715 src = parse_exp (src, &(mode->exp));
716 src = checkfor (src, ')');
717 mode->mode = CLASS_BA;
720 imm_operand = &(mode->exp);
731 /* No initial reg. */
732 src = parse_exp (src, &(mode->exp));
736 end = parse_reg (src, &(mode->mode), ®n);
737 regword (mode->mode, "addr(Ra) ra");
738 mode->mode = CLASS_X;
741 da_operand = &(mode->exp);
742 src = checkfor (end, ')');
746 /* Just an address. */
747 mode->mode = CLASS_DA;
750 da_operand = &(mode->exp);
758 get_operands (opcode, op_end, operand)
759 const opcode_entry_type *opcode;
767 switch (opcode->noperands)
775 if (opcode->arg_info[0] == CLASS_CC)
776 get_cc_operand (&ptr, operand + 0, 0);
778 else if (opcode->arg_info[0] == CLASS_FLAGS)
779 get_flags_operand (&ptr, operand + 0, 0);
781 else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2)))
782 get_interrupt_operand (&ptr, operand + 0, 0);
785 get_operand (&ptr, operand + 0, 0);
792 if (opcode->arg_info[0] == CLASS_CC)
793 get_cc_operand (&ptr, operand + 0, 0);
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);
813 get_operand (&ptr, operand + 0, 0);
819 get_operand (&ptr, operand + 1, 1);
823 get_operand (&ptr, operand + 0, 0);
826 get_operand (&ptr, operand + 1, 1);
829 get_operand (&ptr, operand + 2, 2);
833 get_operand (&ptr, operand + 0, 0);
836 get_operand (&ptr, operand + 1, 1);
839 get_operand (&ptr, operand + 2, 2);
842 get_cc_operand (&ptr, operand + 3, 3);
852 /* Passed a pointer to a list of opcodes which use different
853 addressing modes. Return the opcode which matches the opcodes
856 static opcode_entry_type *
857 get_specific (opcode, operands)
858 opcode_entry_type *opcode;
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;
953 #if 0 /* Not used. */
955 check_operand (operand, width, string)
956 struct z8k_op *operand;
960 if (operand->exp.X_add_symbol == 0
961 && operand->exp.X_op_symbol == 0)
964 /* No symbol involved, let's look at offset, it's dangerous if
965 any of the high bits are not 0 or ff's, find out by oring or
966 anding with the width and seeing if the answer is 0 or all
968 if ((operand->exp.X_add_number & ~width) != 0 &&
969 (operand->exp.X_add_number | width) != (~0))
971 as_warn (_("operand %s0x%x out of range"),
972 string, operand->exp.X_add_number);
979 static char buffer[20];
982 newfix (ptr, type, size, operand)
985 int size; /* nibbles. */
986 expressionS *operand;
990 if (operand->X_add_symbol
991 || operand->X_op_symbol
992 || operand->X_add_number)
1001 fix_new_exp (frag_now,
1011 apply_fix (ptr, type, operand, size)
1014 expressionS *operand;
1015 int size; /* nibbles. */
1017 long n = operand->X_add_number;
1019 newfix ((ptr - buffer) / 2, type, size + 1, operand);
1022 case 8: /* 8 nibbles == 32 bits. */
1027 case 4: /* 4 nibbles == 16 bits. */
1039 /* Now we know what sort of opcodes it is. Let's build the bytes. */
1041 #define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
1044 build_bytes (this_try, operand)
1045 opcode_entry_type *this_try;
1046 struct z8k_op *operand ATTRIBUTE_UNUSED;
1048 char *output_ptr = buffer;
1051 unsigned int *class_ptr;
1053 frag_wane (frag_now);
1056 memset (buffer, 0, sizeof (buffer));
1057 class_ptr = this_try->byte_info;
1059 for (nibble = 0; (c = *class_ptr++); nibble++)
1062 switch (c & CLASS_MASK)
1068 /* Direct address, we don't cope with the SS mode right now. */
1071 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
1072 output_ptr = apply_fix (output_ptr, R_IMM32, da_operand, 8);
1076 output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
1082 output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
1089 output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
1096 output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
1097 output_ptr[-2] = 0x8;
1101 case CLASS_BIT_1OR2:
1102 *output_ptr = c & 0xf;
1105 if (imm_operand->X_add_number == 2)
1107 else if (imm_operand->X_add_number != 1)
1108 as_bad (_("immediate must be 1 or 2"));
1111 as_bad (_("immediate 1 or 2 expected"));
1115 *output_ptr++ = the_cc;
1118 *output_ptr++ = the_ctrl;
1121 *output_ptr++ = the_ctrl | 0x8;
1124 *output_ptr++ = (~the_interrupt & 0x3);
1127 *output_ptr++ = (~the_interrupt & 0x3) | 0x4;
1130 *output_ptr++ = the_flags;
1134 *output_ptr++ = c & 0xf;
1137 if (reg[c & 0xf] == 0)
1138 as_bad (_("can't use R0 here"));
1141 case CLASS_REG_BYTE:
1142 case CLASS_REG_WORD:
1143 case CLASS_REG_LONG:
1144 case CLASS_REG_QUAD:
1145 /* Insert bit mattern of right reg. */
1146 *output_ptr++ = reg[c & 0xf];
1149 switch (c & ARG_MASK)
1152 output_ptr = apply_fix (output_ptr, R_CALLR, da_operand, 4);
1155 output_ptr = apply_fix (output_ptr, R_REL16, da_operand, 4);
1158 output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
1165 switch (c & ARG_MASK)
1168 if (imm_operand->X_add_number > 15)
1170 as_bad (_("immediate value out of range"));
1172 imm_operand->X_add_number = -imm_operand->X_add_number;
1173 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
1175 /*case ARG_IMMNMINUS1: not used. */
1177 imm_operand->X_add_number--;
1180 if (imm_operand->X_add_number > 15)
1182 as_bad (_("immediate value out of range"));
1184 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
1187 imm_operand->X_add_number = -imm_operand->X_add_number;
1190 output_ptr = apply_fix (output_ptr, R_IMM8, imm_operand, 2);
1193 output_ptr = apply_fix (output_ptr, R_IMM16, imm_operand, 4);
1196 output_ptr = apply_fix (output_ptr, R_IMM32, imm_operand, 8);
1205 /* Copy from the nibble buffer into the frag. */
1207 int length = (output_ptr - buffer) / 2;
1209 char *fragp = frag_more (length);
1211 while (src < output_ptr)
1213 *fragp = (src[0] << 4) | src[1];
1220 /* This is the guts of the machine-dependent assembler. STR points to a
1221 machine dependent instruction. This function is supposed to emit
1222 the frags/bytes it assembles to. */
1231 struct z8k_op operand[3];
1232 opcode_entry_type *opcode;
1233 opcode_entry_type *prev_opcode;
1235 /* Drop leading whitespace. */
1239 /* Find the op code end. */
1240 for (op_start = op_end = str;
1241 *op_end != 0 && *op_end != ' ';
1245 if (op_end == op_start)
1247 as_bad (_("can't find opcode "));
1253 opcode = (opcode_entry_type *) hash_find (opcode_hash_control, op_start);
1257 as_bad (_("unknown opcode"));
1261 if (opcode->opcode == 250)
1265 char *old = input_line_pointer;
1268 /* Was really a pseudo op. */
1270 input_line_pointer = op_end;
1274 while (*input_line_pointer == ' ')
1275 input_line_pointer++;
1276 p = (pseudo_typeS *) (opcode->func);
1278 (p->poc_handler) (p->poc_val);
1279 input_line_pointer = old;
1284 char *new_input_line_pointer;
1286 new_input_line_pointer = get_operands (opcode, op_end, operand);
1287 if (new_input_line_pointer)
1288 input_line_pointer = new_input_line_pointer;
1289 prev_opcode = opcode; /* XXX is this used ?? */
1291 opcode = get_specific (opcode, operand);
1295 /* Couldn't find an opcode which matched the operands. */
1296 char *where = frag_more (2);
1301 as_bad (_("Can't find opcode to match operands"));
1305 build_bytes (opcode, operand);
1310 tc_crawl_symbol_chain (headers)
1311 object_headers *headers ATTRIBUTE_UNUSED;
1313 printf (_("call to tc_crawl_symbol_chain \n"));
1316 /* We have no need to default values of symbols. */
1319 md_undefined_symbol (name)
1320 char *name ATTRIBUTE_UNUSED;
1326 tc_headers_hook (headers)
1327 object_headers *headers ATTRIBUTE_UNUSED;
1329 printf (_("call to tc_headers_hook \n"));
1332 /* Various routines to kill one day. */
1333 /* Equal to MAX_PRECISION in atof-ieee.c. */
1334 #define MAX_LITTLENUMS 6
1336 /* Turn a string in input_line_pointer into a floating point constant
1337 of type TYPE, and store the appropriate bytes in *LITP. The number
1338 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1339 returned, or NULL on OK. */
1342 md_atof (type, litP, sizeP)
1348 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1349 LITTLENUM_TYPE *wordP;
1380 return _("Bad call to MD_ATOF()");
1382 t = atof_ieee (input_line_pointer, type, words);
1384 input_line_pointer = t;
1386 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1387 for (wordP = words; prec--;)
1389 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1390 litP += sizeof (LITTLENUM_TYPE);
1395 const char *md_shortopts = "z:";
1397 struct option md_longopts[] =
1399 #define OPTION_RELAX (OPTION_MD_BASE)
1400 {"linkrelax", no_argument, NULL, OPTION_RELAX},
1401 {NULL, no_argument, NULL, 0}
1404 size_t md_longopts_size = sizeof (md_longopts);
1407 md_parse_option (c, arg)
1414 if (!strcmp (arg, "8001"))
1416 else if (!strcmp (arg, "8002"))
1420 as_bad (_("invalid architecture -z%s"), arg);
1423 z8k_target_from_cmdline = 1;
1438 md_show_usage (stream)
1441 fprintf (stream, _("\
1443 -z8001 generate segmented code\n\
1444 -z8002 generate unsegmented code\n\
1445 -linkrelax create linker relaxable code\n"));
1449 md_convert_frag (headers, seg, fragP)
1450 object_headers *headers ATTRIBUTE_UNUSED;
1451 segT seg ATTRIBUTE_UNUSED;
1452 fragS *fragP ATTRIBUTE_UNUSED;
1454 printf (_("call to md_convert_frag\n"));
1459 md_section_align (seg, size)
1463 return ((size + (1 << section_alignment[(int) seg]) - 1)
1464 & (-1 << section_alignment[(int) seg]));
1467 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1468 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1469 we will have to generate a reloc entry. */
1471 md_apply_fix3 (fixP, valP, segment)
1474 segT segment ATTRIBUTE_UNUSED;
1476 long val = * (long *) valP;
1477 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1479 switch (fixP->fx_r_type)
1482 buf[0] = (buf[0] & 0xf0) | (val & 0xf);
1488 fixP->fx_no_overflow = 1;
1494 as_bad (_("cannot branch to odd address"));
1496 if (val > 127 || val < -128)
1497 as_warn (_("relative jump out of range"));
1499 fixP->fx_no_overflow = 1;
1507 fixP->fx_no_overflow = 1;
1513 as_bad (_("cannot branch to odd address"));
1515 if (val > 0 || val < -127)
1516 as_bad (_("relative jump out of range"));
1517 *buf = (*buf & 0x80) | (-val & 0x7f);
1518 fixP->fx_no_overflow = 1;
1526 fixP->fx_no_overflow = 1;
1532 as_bad (_("cannot branch to odd address"));
1533 if (val > 4096 || val < -4095)
1534 as_bad (_("relative call out of range"));
1536 *buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1538 *buf++ = val & 0xff;
1539 fixP->fx_no_overflow = 1;
1549 *buf++ = (val >> 8);
1554 *buf++ = (val >> 24);
1555 *buf++ = (val >> 16);
1556 *buf++ = (val >> 8);
1561 val = val - fixP->fx_frag->fr_address + fixP->fx_where - fixP->fx_size;
1562 if (val > 32767 || val < -32768)
1563 as_bad (_("relative address out of range"));
1564 *buf++ = (val >> 8);
1566 fixP->fx_no_overflow = 1;
1571 *buf++ = (val >> 16);
1573 *buf++ = (val >> 8);
1579 md_number_to_chars (buf, val, fixP->fx_size);
1583 printf(_("md_apply_fix3: unknown r_type 0x%x\n"), fixP->fx_r_type);
1587 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1592 md_estimate_size_before_relax (fragP, segment_type)
1593 register fragS *fragP ATTRIBUTE_UNUSED;
1594 register 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 (ptr, use, nbytes)
1608 number_to_chars_bigendian (ptr, use, nbytes);
1611 /* On the Z8000, a PC-relative offset is relative to the address of the
1612 instruction plus its size. */
1614 md_pcrel_from (fixP)
1617 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1621 tc_coff_symbol_emit_hook (s)
1622 symbolS *s ATTRIBUTE_UNUSED;
1627 tc_reloc_mangle (fix_ptr, intr, base)
1629 struct internal_reloc *intr;
1633 symbolS *symbol_ptr;
1635 if (fix_ptr->fx_addsy
1636 && fix_ptr->fx_subsy)
1638 symbolS *add = fix_ptr->fx_addsy;
1639 symbolS *sub = fix_ptr->fx_subsy;
1641 if (S_GET_SEGMENT (add) != S_GET_SEGMENT (sub))
1642 as_bad (_("Can't subtract symbols in different sections %s %s"),
1643 S_GET_NAME (add), S_GET_NAME (sub));
1646 int diff = S_GET_VALUE (add) - S_GET_VALUE (sub);
1648 fix_ptr->fx_addsy = 0;
1649 fix_ptr->fx_subsy = 0;
1650 fix_ptr->fx_offset += diff;
1653 symbol_ptr = fix_ptr->fx_addsy;
1655 /* If this relocation is attached to a symbol then it's ok
1657 if (fix_ptr->fx_r_type == 0)
1659 /* cons likes to create reloc32's whatever the size of the reloc. */
1660 switch (fix_ptr->fx_size)
1663 intr->r_type = R_IMM16;
1666 intr->r_type = R_IMM8;
1669 intr->r_type = R_IMM32;
1676 intr->r_type = fix_ptr->fx_r_type;
1678 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1679 intr->r_offset = fix_ptr->fx_offset;
1682 intr->r_symndx = symbol_ptr->sy_number;
1684 intr->r_symndx = -1;