1 /* tc-z8k.c -- Assemble code for the Zilog Z800n
2 Copyright (C) 1992-2016 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* Written By Steve Chamberlain <sac@cygnus.com>. */
24 #include "safe-ctype.h"
26 #include "opcodes/z8k-opc.h"
28 const char comment_chars[] = "!";
29 const char line_comment_chars[] = "#";
30 const char line_separator_chars[] = ";";
33 extern int coff_flags;
36 /* This is non-zero if target was set from the command line.
37 If non-zero, 1 means Z8002 (non-segmented), 2 means Z8001 (segmented). */
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 s_segm (z8k_target_from_cmdline ? z8k_target_from_cmdline - 1 : 0);
161 /* Insert the pseudo ops, too. */
162 for (idx = 0; md_pseudo_table[idx].poc_name; idx++)
164 opcode_entry_type *fake_opcode;
165 fake_opcode = XNEW (opcode_entry_type);
166 fake_opcode->name = md_pseudo_table[idx].poc_name;
167 fake_opcode->func = (void *) (md_pseudo_table + idx);
168 fake_opcode->opcode = 250;
169 hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode);
173 typedef struct z8k_op {
182 /* Any other register associated with the mode. */
185 /* Any expression. */
189 static expressionS *da_operand;
190 static expressionS *imm_operand;
195 static int the_flags;
196 static int the_interrupt;
198 /* Determine register number. src points to the ascii number
199 (after "rl", "rh", "r", "rr", or "rq"). If a character
200 outside the set of {0,',',')','('} follows the number,
201 return NULL to indicate that it's not a valid register
205 whatreg (unsigned int *preg, char *src)
207 unsigned int new_reg;
209 /* src[0] is already known to be a digit. */
210 if (ISDIGIT (src[1]))
212 new_reg = (src[0] - '0') * 10 + src[1] - '0';
217 new_reg = (src[0] - '0');
221 if (src[0] != 0 && src[0] != ',' && src[0] != '(' && src[0] != ')')
234 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
242 /* Try to parse a reg name. Return a pointer to the first character
243 in SRC after the reg name. */
246 parse_reg (char *src, int *mode, unsigned int *preg)
251 /* Check for stack pointer "sp" alias. */
252 if ((src[0] == 's' || src[0] == 'S')
253 && (src[1] == 'p' || src[1] == 'P')
254 && (src[2] == 0 || src[2] == ','))
258 *mode = CLASS_REG_LONG;
263 *mode = CLASS_REG_WORD;
269 if (src[0] == 'r' || src[0] == 'R')
271 if (src[1] == 'r' || src[1] == 'R')
273 if (src[2] < '0' || src[2] > '9')
274 return NULL; /* Assume no register name but a label starting with 'rr'. */
275 *mode = CLASS_REG_LONG;
276 res = whatreg (preg, src + 2);
278 return NULL; /* Not a valid register name. */
281 as_bad (_("register rr%d out of range"), regno);
283 as_bad (_("register rr%d does not exist"), regno);
285 else if (src[1] == 'h' || src[1] == 'H')
287 if (src[2] < '0' || src[2] > '9')
288 return NULL; /* Assume no register name but a label starting with 'rh'. */
289 *mode = CLASS_REG_BYTE;
290 res = whatreg (preg, src + 2);
292 return NULL; /* Not a valid register name. */
295 as_bad (_("register rh%d out of range"), regno);
297 else if (src[1] == 'l' || src[1] == 'L')
299 if (src[2] < '0' || src[2] > '9')
300 return NULL; /* Assume no register name but a label starting with 'rl'. */
301 *mode = CLASS_REG_BYTE;
302 res = whatreg (preg, src + 2);
304 return NULL; /* Not a valid register name. */
307 as_bad (_("register rl%d out of range"), regno);
310 else if (src[1] == 'q' || src[1] == 'Q')
312 if (src[2] < '0' || src[2] > '9')
313 return NULL; /* Assume no register name but a label starting with 'rq'. */
314 *mode = CLASS_REG_QUAD;
315 res = whatreg (preg, src + 2);
317 return NULL; /* Not a valid register name. */
320 as_bad (_("register rq%d out of range"), regno);
322 as_bad (_("register rq%d does not exist"), regno);
326 if (src[1] < '0' || src[1] > '9')
327 return NULL; /* Assume no register name but a label starting with 'r'. */
328 *mode = CLASS_REG_WORD;
329 res = whatreg (preg, src + 1);
331 return NULL; /* Not a valid register name. */
334 as_bad (_("register r%d out of range"), regno);
341 parse_exp (char *s, expressionS *op)
343 char *save = input_line_pointer;
346 input_line_pointer = s;
348 if (op->X_op == O_absent)
349 as_bad (_("missing operand"));
350 new_pointer = input_line_pointer;
351 input_line_pointer = save;
355 /* The many forms of operand:
370 checkfor (char *ptr, char what)
375 as_bad (_("expected %c"), what);
380 /* Make sure the mode supplied is the size of a word. */
383 regword (int mode, const char *string)
390 as_bad (_("register is wrong size for a word %s"), string);
394 /* Make sure the mode supplied is the size of an address. */
397 regaddr (int mode, const char *string)
401 ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
404 as_bad (_("register is wrong size for address %s"), string);
413 static struct ctrl_names ctrl_table[] = {
414 { 0x1, "flags" }, /* ldctlb only. */
415 { 0x2, "fcw" }, /* ldctl only. Applies to all remaining control registers. */
427 get_ctrl_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
435 mode->mode = CLASS_CTRL;
436 for (i = 0; ctrl_table[i].name; i++)
438 l = strlen (ctrl_table[i].name);
439 if (! strncasecmp (ctrl_table[i].name, src, l))
441 the_ctrl = ctrl_table[i].value;
442 if (*(src + l) && *(src + l) != ',')
444 *ptr = src + l; /* Valid control name found: "consume" it. */
456 static struct flag_names flag_table[] = {
468 get_flags_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
478 mode->mode = CLASS_FLAGS;
480 for (j = 0; j <= 9; j++)
485 for (i = 0; flag_table[i].name; i++)
487 if (flag_table[i].name[0] == c)
489 the_flags = the_flags | flag_table[i].value;
501 struct interrupt_names {
506 static struct interrupt_names intr_table[] = {
515 get_interrupt_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
523 mode->mode = CLASS_IMM;
528 for (i = 0; intr_table[i].name; i++)
530 l = strlen (intr_table[i].name);
531 if (! strncasecmp (intr_table[i].name, src, l))
533 the_interrupt |= intr_table[i].value;
534 if (*(src + l) && *(src + l) != ',')
538 as_bad (_("unknown interrupt %s"), src);
539 while (**ptr && ! is_end_of_line[(unsigned char) **ptr])
540 (*ptr)++; /* Consume rest of line. */
560 /* No interrupt type specified, opcode won't do anything. */
561 as_warn (_("opcode has no effect"));
570 static struct cc_names table[] = {
605 get_cc_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
613 mode->mode = CLASS_CC;
614 for (i = 0; table[i].name; i++)
616 l = strlen (table[i].name);
617 if (! strncasecmp (table[i].name, src, l))
619 the_cc = table[i].value;
620 if (*(src + l) && *(src + l) != ',')
622 *ptr = src + l; /* Valid cc found: "consume" it. */
626 the_cc = 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
630 get_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
641 mode->mode = CLASS_IMM;
642 imm_operand = &(mode->exp);
643 src = parse_exp (src + 1, &(mode->exp));
645 else if (*src == '@')
647 mode->mode = CLASS_IR;
648 src = parse_reg (src + 1, &mode->regsize, &mode->reg);
654 end = parse_reg (src, &mode->mode, ®n);
665 end = parse_reg (src, &nw, &nr);
672 as_bad (_("Missing ) in ra(rb)"));
676 regaddr (mode->mode, "ra(rb) ra");
677 mode->mode = CLASS_BX;
687 src = parse_exp (src, &(mode->exp));
688 src = checkfor (src, ')');
689 mode->mode = CLASS_BA;
692 imm_operand = &(mode->exp);
703 /* No initial reg. */
704 src = parse_exp (src, &(mode->exp));
708 end = parse_reg (src, &(mode->mode), ®n);
709 regword (mode->mode, "addr(Ra) ra");
710 mode->mode = CLASS_X;
713 da_operand = &(mode->exp);
714 src = checkfor (end, ')');
718 /* Just an address. */
719 mode->mode = CLASS_DA;
722 da_operand = &(mode->exp);
730 get_operands (const opcode_entry_type *opcode, char *op_end, op_type *operand)
735 switch (opcode->noperands)
745 if (opcode->arg_info[0] == CLASS_CC)
747 get_cc_operand (&ptr, operand + 0, 0);
750 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
752 as_bad (_("invalid condition code '%s'"), ptr);
753 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
754 ptr++; /* Consume rest of line. */
757 else if (opcode->arg_info[0] == CLASS_FLAGS)
759 get_flags_operand (&ptr, operand + 0, 0);
762 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
764 as_bad (_("invalid flag '%s'"), ptr);
765 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
766 ptr++; /* Consume rest of line. */
769 else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2)))
770 get_interrupt_operand (&ptr, operand + 0, 0);
772 get_operand (&ptr, operand + 0, 0);
779 if (opcode->arg_info[0] == CLASS_CC)
781 get_cc_operand (&ptr, operand + 0, 0);
784 if (*ptr != ',' && strchr (ptr + 1, ','))
791 as_bad (_("invalid condition code '%s'"), savptr);
794 else if (opcode->arg_info[0] == CLASS_CTRL)
796 get_ctrl_operand (&ptr, operand + 0, 0);
801 get_operand (&ptr, operand + 0, 0);
807 get_ctrl_operand (&ptr, operand + 1, 1);
814 get_operand (&ptr, operand + 0, 0);
820 get_operand (&ptr, operand + 1, 1);
824 get_operand (&ptr, operand + 0, 0);
827 get_operand (&ptr, operand + 1, 1);
830 get_operand (&ptr, operand + 2, 2);
834 get_operand (&ptr, operand + 0, 0);
837 get_operand (&ptr, operand + 1, 1);
840 get_operand (&ptr, operand + 2, 2);
843 get_cc_operand (&ptr, operand + 3, 3);
853 /* Passed a pointer to a list of opcodes which use different
854 addressing modes. Return the opcode which matches the opcodes
857 static opcode_entry_type *
858 get_specific (opcode_entry_type *opcode, op_type *operands)
860 opcode_entry_type *this_try = opcode;
862 unsigned int noperands = opcode->noperands;
864 int this_index = opcode->idx;
866 while (this_index == opcode->idx && !found)
871 for (i = 0; i < noperands; i++)
873 unsigned int mode = operands[i].mode;
875 if (((mode & CLASS_MASK) == CLASS_IR) && ((this_try->arg_info[i] & CLASS_MASK) == CLASS_IRO))
877 mode = operands[i].mode = (operands[i].mode & ~CLASS_MASK) | CLASS_IRO;
880 if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK))
882 /* It could be a pc rel operand, if this is a da mode
883 and we like disps, then insert it. */
885 if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP)
887 /* This is the case. */
888 operands[i].mode = CLASS_DISP;
890 else if (mode == CLASS_BA && this_try->arg_info[i])
892 /* Can't think of a way to turn what we've been
893 given into something that's OK. */
896 else if (this_try->arg_info[i] & CLASS_PR)
898 if (mode == CLASS_REG_LONG && segmented_mode)
902 else if (mode == CLASS_REG_WORD && !segmented_mode)
912 switch (mode & CLASS_MASK)
917 if (operands[i].regsize != CLASS_REG_WORD)
918 as_bad (_("invalid indirect register size"));
919 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
922 if ((segmented_mode && operands[i].regsize != CLASS_REG_LONG)
923 || (!segmented_mode && operands[i].regsize != CLASS_REG_WORD))
924 as_bad (_("invalid indirect register size"));
925 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
937 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
940 if (this_try->opcode == OPC_ldctlb && the_ctrl != 1)
941 as_bad (_("invalid control register name"));
956 static char buffer[20];
959 newfix (int ptr, int type, int size, expressionS *operand)
964 /* Size is in nibbles. */
965 if (operand->X_add_symbol
966 || operand->X_op_symbol
967 || operand->X_add_number)
971 case BFD_RELOC_8_PCREL:
972 case BFD_RELOC_Z8K_CALLR:
973 case BFD_RELOC_Z8K_DISP7:
976 fixP = fix_new_exp (frag_now, ptr, size / 2,
977 operand, is_pcrel, type);
979 fixP->fx_no_overflow = 1;
984 apply_fix (char *ptr, int type, expressionS *operand, int size)
986 long n = operand->X_add_number;
988 /* size is in nibbles. */
990 newfix ((ptr - buffer) / 2, type, size + 1, operand);
993 case 8: /* 8 nibbles == 32 bits. */
998 case 4: /* 4 nibbles == 16 bits. */
1010 /* Now we know what sort of opcodes it is. Let's build the bytes. */
1013 build_bytes (opcode_entry_type *this_try, struct z8k_op *operand ATTRIBUTE_UNUSED)
1015 char *output_ptr = buffer;
1018 unsigned int *class_ptr;
1020 frag_wane (frag_now);
1023 if (frag_room () < 8)
1024 frag_grow (8); /* Make room for maximum instruction size. */
1026 memset (buffer, 0, sizeof (buffer));
1027 class_ptr = this_try->byte_info;
1029 for (nibble = 0; (c = *class_ptr++); nibble++)
1032 switch (c & CLASS_MASK)
1038 /* Direct address, we don't cope with the SS mode right now. */
1041 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
1042 output_ptr = apply_fix (output_ptr, BFD_RELOC_32, da_operand, 8);
1046 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, da_operand, 4);
1052 output_ptr = apply_fix (output_ptr, BFD_RELOC_8_PCREL, da_operand, 2);
1059 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_DISP7, da_operand, 2);
1066 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_DISP7, da_operand, 2);
1067 output_ptr[-2] = 0x8;
1071 case CLASS_BIT_1OR2:
1072 *output_ptr = c & 0xf;
1075 if (imm_operand->X_add_number == 2)
1077 else if (imm_operand->X_add_number != 1)
1078 as_bad (_("immediate must be 1 or 2"));
1081 as_bad (_("immediate 1 or 2 expected"));
1085 *output_ptr++ = the_cc;
1088 if (the_ctrl < 2 || the_ctrl > 7)
1089 as_bad (_("invalid control register name"));
1090 *output_ptr++ = the_ctrl;
1093 if (the_ctrl < 2 || the_ctrl > 7)
1094 as_bad (_("invalid control register name"));
1095 *output_ptr++ = the_ctrl | 0x8;
1098 *output_ptr++ = (~the_interrupt & 0x3);
1101 *output_ptr++ = (~the_interrupt & 0x3) | 0x4;
1104 *output_ptr++ = the_flags;
1108 *output_ptr++ = c & 0xf;
1111 if (reg[c & 0xf] == 0)
1112 as_bad (_("can't use R0 here"));
1115 case CLASS_REG_BYTE:
1116 case CLASS_REG_WORD:
1117 case CLASS_REG_LONG:
1118 case CLASS_REG_QUAD:
1119 /* Insert bit mattern of right reg. */
1120 *output_ptr++ = reg[c & 0xf];
1123 switch (c & ARG_MASK)
1126 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_CALLR, da_operand, 4);
1129 output_ptr = apply_fix (output_ptr, BFD_RELOC_16_PCREL, da_operand, 4);
1132 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, da_operand, 4);
1139 switch (c & ARG_MASK)
1142 if (imm_operand->X_add_number > 15)
1143 as_bad (_("immediate value out of range"));
1144 imm_operand->X_add_number = -imm_operand->X_add_number;
1145 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_IMM4L, imm_operand, 1);
1147 /*case ARG_IMMNMINUS1: not used. */
1149 imm_operand->X_add_number--;
1152 if (imm_operand->X_add_number > 15)
1153 as_bad (_("immediate value out of range"));
1154 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_IMM4L, imm_operand, 1);
1157 imm_operand->X_add_number = -imm_operand->X_add_number;
1160 output_ptr = apply_fix (output_ptr, BFD_RELOC_8, imm_operand, 2);
1163 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, imm_operand, 4);
1166 output_ptr = apply_fix (output_ptr, BFD_RELOC_32, imm_operand, 8);
1175 /* Copy from the nibble buffer into the frag. */
1177 int length = (output_ptr - buffer) / 2;
1179 char *fragp = frag_more (length);
1181 while (src < output_ptr)
1183 *fragp = (src[0] << 4) | src[1];
1190 /* This is the guts of the machine-dependent assembler. STR points to a
1191 machine dependent instruction. This function is supposed to emit
1192 the frags/bytes it assembles to. */
1195 md_assemble (char *str)
1200 struct z8k_op operand[4];
1201 opcode_entry_type *opcode;
1203 /* Drop leading whitespace. */
1207 /* Find the op code end. */
1208 for (op_start = op_end = str;
1209 *op_end != 0 && *op_end != ' ' && ! is_end_of_line[(unsigned char) *op_end];
1213 if (op_end == op_start)
1215 as_bad (_("can't find opcode "));
1219 *op_end = 0; /* Zero-terminate op code string for hash_find() call. */
1221 opcode = (opcode_entry_type *) hash_find (opcode_hash_control, op_start);
1225 as_bad (_("unknown opcode"));
1229 *op_end = c; /* Restore original string. */
1231 if (opcode->opcode == 250)
1235 char *old = input_line_pointer;
1237 /* Was really a pseudo op. */
1239 input_line_pointer = op_end;
1243 while (*input_line_pointer == ' ')
1244 input_line_pointer++;
1245 p = (pseudo_typeS *) (opcode->func);
1247 (p->poc_handler) (p->poc_val);
1248 input_line_pointer = old;
1253 char *new_input_line_pointer;
1255 new_input_line_pointer = get_operands (opcode, op_end, operand);
1256 if (new_input_line_pointer)
1258 input_line_pointer = new_input_line_pointer;
1259 opcode = get_specific (opcode, operand);
1262 if (new_input_line_pointer == NULL || opcode == NULL)
1264 /* Couldn't find an opcode which matched the operands. */
1265 char *where = frag_more (2);
1270 as_bad (_("Can't find opcode to match operands"));
1274 build_bytes (opcode, operand);
1278 /* We have no need to default values of symbols. */
1281 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1286 /* Various routines to kill one day. */
1289 md_atof (int type, char *litP, int *sizeP)
1291 return ieee_md_atof (type, litP, sizeP, TRUE);
1294 const char *md_shortopts = "z:";
1296 struct option md_longopts[] =
1298 #define OPTION_RELAX (OPTION_MD_BASE)
1299 {"linkrelax", no_argument, NULL, OPTION_RELAX},
1300 {NULL, no_argument, NULL, 0}
1303 size_t md_longopts_size = sizeof (md_longopts);
1306 md_parse_option (int c, const char *arg)
1311 if (!strcmp (arg, "8001"))
1312 z8k_target_from_cmdline = 2;
1313 else if (!strcmp (arg, "8002"))
1314 z8k_target_from_cmdline = 1;
1317 as_bad (_("invalid architecture -z%s"), arg);
1334 md_show_usage (FILE *stream)
1336 fprintf (stream, _("\
1338 -z8001 generate segmented code\n\
1339 -z8002 generate unsegmented code\n\
1340 -linkrelax create linker relaxable code\n"));
1344 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
1345 segT sec ATTRIBUTE_UNUSED,
1346 fragS *fragP ATTRIBUTE_UNUSED)
1348 printf (_("call to md_convert_frag\n"));
1352 /* Generate a machine dependent reloc from a fixup. */
1355 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED,
1356 fixS *fixp ATTRIBUTE_UNUSED)
1360 reloc = XNEW (arelent);
1361 reloc->sym_ptr_ptr = XNEW (asymbol *);
1362 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1363 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1364 reloc->addend = fixp->fx_offset;
1365 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1369 as_bad_where (fixp->fx_file, fixp->fx_line,
1370 _("Cannot represent %s relocation in object file"),
1371 bfd_get_reloc_code_name (fixp->fx_r_type));
1378 md_section_align (segT seg, valueT size)
1380 int align = bfd_get_section_alignment (stdoutput, seg);
1381 valueT mask = ((valueT) 1 << align) - 1;
1383 return (size + mask) & ~mask;
1386 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1387 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1388 we will have to generate a reloc entry. */
1390 md_apply_fix (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
1392 long val = * (long *) valP;
1393 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1395 switch (fixP->fx_r_type)
1397 case BFD_RELOC_Z8K_IMM4L:
1400 fixP->fx_no_overflow = 1;
1404 buf[0] = (buf[0] & 0xf0) | (val & 0xf);
1410 fixP->fx_no_overflow = 1;
1420 fixP->fx_no_overflow = 1;
1425 *buf++ = (val >> 8);
1433 fixP->fx_no_overflow = 1;
1438 *buf++ = (val >> 24);
1439 *buf++ = (val >> 16);
1440 *buf++ = (val >> 8);
1445 case BFD_RELOC_8_PCREL:
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 > 127 || val < -128)
1458 as_bad_where (fixP->fx_file, fixP->fx_line,
1459 _("relative jump out of range"));
1461 fixP->fx_no_overflow = 1;
1466 case BFD_RELOC_16_PCREL:
1469 fixP->fx_no_overflow = 1;
1474 val = val - fixP->fx_frag->fr_address + fixP->fx_where - fixP->fx_size;
1475 if (val > 32767 || val < -32768)
1476 as_bad_where (fixP->fx_file, fixP->fx_line,
1477 _("relative address out of range"));
1478 *buf++ = (val >> 8);
1480 fixP->fx_no_overflow = 1;
1485 case BFD_RELOC_Z8K_CALLR:
1488 fixP->fx_no_overflow = 1;
1494 as_bad_where (fixP->fx_file, fixP->fx_line,
1495 _("cannot branch to odd address"));
1496 if (val > 4096 || val < -4095)
1497 as_bad_where (fixP->fx_file, fixP->fx_line,
1498 _("relative call out of range"));
1500 *buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1502 *buf++ = val & 0xff;
1503 fixP->fx_no_overflow = 1;
1508 case BFD_RELOC_Z8K_DISP7:
1511 fixP->fx_no_overflow = 1;
1517 as_bad_where (fixP->fx_file, fixP->fx_line,
1518 _("cannot branch to odd address"));
1520 if (val > 0 || val < -127)
1521 as_bad_where (fixP->fx_file, fixP->fx_line,
1522 _("relative jump out of range"));
1523 *buf = (*buf & 0x80) | (-val & 0x7f);
1524 fixP->fx_no_overflow = 1;
1530 printf(_("md_apply_fix: unknown r_type 0x%x\n"), fixP->fx_r_type);
1534 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1539 md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
1540 segT segment_type ATTRIBUTE_UNUSED)
1542 printf (_("call to md_estimate_size_before_relax\n"));
1546 /* Put number into target byte order. */
1549 md_number_to_chars (char *ptr, valueT use, int nbytes)
1551 number_to_chars_bigendian (ptr, use, nbytes);
1554 /* On the Z8000, a PC-relative offset is relative to the address of the
1555 instruction plus its size. */
1557 md_pcrel_from (fixS *fixP)
1559 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1563 tc_coff_symbol_emit_hook (symbolS *s ATTRIBUTE_UNUSED)