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
;
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
);
186 typedef struct z8k_op
{
195 /* Any other register associated with the mode. */
198 /* Any expression. */
202 static expressionS
*da_operand
;
203 static expressionS
*imm_operand
;
208 static int the_flags
;
209 static int the_interrupt
;
212 whatreg (int *reg
, char *src
)
214 if (ISDIGIT (src
[1]))
216 *reg
= (src
[0] - '0') * 10 + src
[1] - '0';
221 *reg
= (src
[0] - '0');
232 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
240 /* Try to parse a reg name. Return a pointer to the first character
241 in SRC after the reg name. */
244 parse_reg (char *src
, int *mode
, unsigned int *reg
)
249 if (src
[0] == 's' && src
[1] == 'p' && (src
[2] == 0 || src
[2] == ','))
253 *mode
= CLASS_REG_LONG
;
258 *mode
= CLASS_REG_WORD
;
267 if (src
[2] < '0' || src
[2] > '9')
268 return res
; /* Assume no register name but a label starting with 'rr'. */
269 *mode
= CLASS_REG_LONG
;
270 res
= whatreg (reg
, src
+ 2);
273 as_bad (_("register rr%d out of range"), regno
);
275 as_bad (_("register rr%d does not exist"), regno
);
277 else if (src
[1] == 'h')
279 if (src
[2] < '0' || src
[2] > '9')
280 return res
; /* Assume no register name but a label starting with 'rh'. */
281 *mode
= CLASS_REG_BYTE
;
282 res
= whatreg (reg
, src
+ 2);
285 as_bad (_("register rh%d out of range"), regno
);
287 else if (src
[1] == 'l')
289 if (src
[2] < '0' || src
[2] > '9')
290 return res
; /* Assume no register name but a label starting with 'rl'. */
291 *mode
= CLASS_REG_BYTE
;
292 res
= whatreg (reg
, src
+ 2);
295 as_bad (_("register rl%d out of range"), regno
);
298 else if (src
[1] == 'q')
300 if (src
[2] < '0' || src
[2] > '9')
301 return res
; /* Assume no register name but a label starting with 'rq'. */
302 *mode
= CLASS_REG_QUAD
;
303 res
= whatreg (reg
, src
+ 2);
306 as_bad (_("register rq%d out of range"), regno
);
308 as_bad (_("register rq%d does not exist"), regno
);
312 if (src
[1] < '0' || src
[1] > '9')
313 return res
; /* Assume no register name but a label starting with 'r'. */
314 *mode
= CLASS_REG_WORD
;
315 res
= whatreg (reg
, src
+ 1);
318 as_bad (_("register r%d out of range"), regno
);
325 parse_exp (char *s
, expressionS
*op
)
327 char *save
= input_line_pointer
;
330 input_line_pointer
= s
;
332 if (op
->X_op
== O_absent
)
333 as_bad (_("missing operand"));
334 new = input_line_pointer
;
335 input_line_pointer
= save
;
339 /* The many forms of operand:
354 checkfor (char *ptr
, char what
)
359 as_bad (_("expected %c"), what
);
364 /* Make sure the mode supplied is the size of a word. */
367 regword (int mode
, char *string
)
374 as_bad (_("register is wrong size for a word %s"), string
);
378 /* Make sure the mode supplied is the size of an address. */
381 regaddr (int mode
, char *string
)
385 ok
= segmented_mode
? CLASS_REG_LONG
: CLASS_REG_WORD
;
388 as_bad (_("register is wrong size for address %s"), string
);
397 static struct ctrl_names ctrl_table
[] = {
410 get_ctrl_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
418 mode
->mode
= CLASS_CTRL
;
419 for (i
= 0; ctrl_table
[i
].name
; i
++)
423 for (j
= 0; ctrl_table
[i
].name
[j
]; j
++)
425 if (ctrl_table
[i
].name
[j
] != src
[j
])
428 the_ctrl
= ctrl_table
[i
].value
;
443 static struct flag_names flag_table
[] = {
454 get_flags_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
463 mode
->mode
= CLASS_FLAGS
;
465 for (j
= 0; j
<= 9; j
++)
469 for (i
= 0; flag_table
[i
].name
; i
++)
471 if (flag_table
[i
].name
[0] == src
[j
])
473 the_flags
= the_flags
| flag_table
[i
].value
;
486 struct interrupt_names
{
491 static struct interrupt_names intr_table
[] = {
500 get_interrupt_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
508 mode
->mode
= CLASS_IMM
;
509 for (i
= 0; intr_table
[i
].name
; i
++)
513 for (j
= 0; intr_table
[i
].name
[j
]; j
++)
515 if (intr_table
[i
].name
[j
] != src
[j
])
518 the_interrupt
= intr_table
[i
].value
;
524 /* No interrupt type specified, opcode won't do anything. */
525 as_warn (_("opcode has no effect"));
535 static struct cc_names table
[] = {
570 get_cc_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
578 mode
->mode
= CLASS_CC
;
579 for (i
= 0; table
[i
].name
; i
++)
581 l
= strlen (table
[i
].name
);
582 if (! strncasecmp (table
[i
].name
, src
, l
))
584 the_cc
= table
[i
].value
;
585 if (*(src
+ l
) && *(src
+ l
) != ',')
587 *ptr
= src
+ l
; /* Valid cc found: "consume" it. */
591 the_cc
= 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
595 get_operand (char **ptr
, struct z8k_op
*mode
, unsigned int dst ATTRIBUTE_UNUSED
)
606 mode
->mode
= CLASS_IMM
;
607 imm_operand
= &(mode
->exp
);
608 src
= parse_exp (src
+ 1, &(mode
->exp
));
610 else if (*src
== '@')
612 mode
->mode
= CLASS_IR
;
613 src
= parse_reg (src
+ 1, &mode
->regsize
, &mode
->reg
);
619 end
= parse_reg (src
, &mode
->mode
, ®n
);
629 end
= parse_reg (src
, &nw
, &nr
);
636 as_bad (_("Missing ) in ra(rb)"));
640 regaddr (mode
->mode
, "ra(rb) ra");
642 regword (mode
->mode
, "ra(rb) rb");
644 mode
->mode
= CLASS_BX
;
654 src
= parse_exp (src
, &(mode
->exp
));
655 src
= checkfor (src
, ')');
656 mode
->mode
= CLASS_BA
;
659 imm_operand
= &(mode
->exp
);
670 /* No initial reg. */
671 src
= parse_exp (src
, &(mode
->exp
));
675 end
= parse_reg (src
, &(mode
->mode
), ®n
);
676 regword (mode
->mode
, "addr(Ra) ra");
677 mode
->mode
= CLASS_X
;
680 da_operand
= &(mode
->exp
);
681 src
= checkfor (end
, ')');
685 /* Just an address. */
686 mode
->mode
= CLASS_DA
;
689 da_operand
= &(mode
->exp
);
697 get_operands (const opcode_entry_type
*opcode
, char *op_end
, op_type
*operand
)
702 switch (opcode
->noperands
)
712 if (opcode
->arg_info
[0] == CLASS_CC
)
714 get_cc_operand (&ptr
, operand
+ 0, 0);
717 if (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
719 as_bad (_("invalid condition code '%s'"), ptr
);
720 while (*ptr
&& ! is_end_of_line
[(unsigned char) *ptr
])
721 ptr
++; /* Consume rest of line. */
725 else if (opcode
->arg_info
[0] == CLASS_FLAGS
)
726 get_flags_operand (&ptr
, operand
+ 0, 0);
728 else if (opcode
->arg_info
[0] == (CLASS_IMM
+ (ARG_IMM2
)))
729 get_interrupt_operand (&ptr
, operand
+ 0, 0);
732 get_operand (&ptr
, operand
+ 0, 0);
739 if (opcode
->arg_info
[0] == CLASS_CC
)
741 get_cc_operand (&ptr
, operand
+ 0, 0);
744 if (*ptr
!= ',' && strchr (ptr
+ 1, ','))
751 as_bad (_("invalid condition code '%s'"), savptr
);
755 else if (opcode
->arg_info
[0] == CLASS_CTRL
)
757 get_ctrl_operand (&ptr
, operand
+ 0, 0);
762 get_operand (&ptr
, operand
+ 0, 0);
768 get_ctrl_operand (&ptr
, operand
+ 1, 1);
773 get_operand (&ptr
, operand
+ 0, 0);
779 get_operand (&ptr
, operand
+ 1, 1);
783 get_operand (&ptr
, operand
+ 0, 0);
786 get_operand (&ptr
, operand
+ 1, 1);
789 get_operand (&ptr
, operand
+ 2, 2);
793 get_operand (&ptr
, operand
+ 0, 0);
796 get_operand (&ptr
, operand
+ 1, 1);
799 get_operand (&ptr
, operand
+ 2, 2);
802 get_cc_operand (&ptr
, operand
+ 3, 3);
812 /* Passed a pointer to a list of opcodes which use different
813 addressing modes. Return the opcode which matches the opcodes
816 static opcode_entry_type
*
817 get_specific (opcode_entry_type
*opcode
, op_type
*operands
)
819 opcode_entry_type
*this_try
= opcode
;
821 unsigned int noperands
= opcode
->noperands
;
823 int this_index
= opcode
->idx
;
825 while (this_index
== opcode
->idx
&& !found
)
830 for (i
= 0; i
< noperands
; i
++)
832 unsigned int mode
= operands
[i
].mode
;
834 if (((mode
& CLASS_MASK
) == CLASS_IR
) && ((this_try
->arg_info
[i
] & CLASS_MASK
) == CLASS_IRO
))
836 mode
= operands
[i
].mode
= (operands
[i
].mode
& ~CLASS_MASK
) | CLASS_IRO
;
839 if ((mode
& CLASS_MASK
) != (this_try
->arg_info
[i
] & CLASS_MASK
))
841 /* It could be a pc rel operand, if this is a da mode
842 and we like disps, then insert it. */
844 if (mode
== CLASS_DA
&& this_try
->arg_info
[i
] == CLASS_DISP
)
846 /* This is the case. */
847 operands
[i
].mode
= CLASS_DISP
;
849 else if (mode
== CLASS_BA
&& this_try
->arg_info
[i
])
851 /* Can't think of a way to turn what we've been
852 given into something that's OK. */
855 else if (this_try
->arg_info
[i
] & CLASS_PR
)
857 if (mode
== CLASS_REG_LONG
&& segmented_mode
)
861 else if (mode
== CLASS_REG_WORD
&& !segmented_mode
)
871 switch (mode
& CLASS_MASK
)
876 if (operands
[i
].regsize
!= CLASS_REG_WORD
)
877 as_bad (_("invalid indirect register size"));
878 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
881 if ((segmented_mode
&& operands
[i
].regsize
!= CLASS_REG_LONG
)
882 || (!segmented_mode
&& operands
[i
].regsize
!= CLASS_REG_WORD
))
883 as_bad (_("invalid indirect register size"));
884 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
896 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
911 static char buffer
[20];
914 newfix (int ptr
, int type
, int size
, expressionS
*operand
)
918 /* size is in nibbles. */
920 if (operand
->X_add_symbol
921 || operand
->X_op_symbol
922 || operand
->X_add_number
)
931 fix_new_exp (frag_now
,
941 apply_fix (char *ptr
, int type
, expressionS
*operand
, int size
)
943 long n
= operand
->X_add_number
;
945 /* size is in nibbles. */
947 newfix ((ptr
- buffer
) / 2, type
, size
+ 1, operand
);
950 case 8: /* 8 nibbles == 32 bits. */
955 case 4: /* 4 nibbles == 16 bits. */
967 /* Now we know what sort of opcodes it is. Let's build the bytes. */
969 #define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
972 build_bytes (opcode_entry_type
*this_try
, struct z8k_op
*operand ATTRIBUTE_UNUSED
)
974 char *output_ptr
= buffer
;
977 unsigned int *class_ptr
;
979 frag_wane (frag_now
);
982 memset (buffer
, 0, sizeof (buffer
));
983 class_ptr
= this_try
->byte_info
;
985 for (nibble
= 0; (c
= *class_ptr
++); nibble
++)
988 switch (c
& CLASS_MASK
)
994 /* Direct address, we don't cope with the SS mode right now. */
997 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
998 output_ptr
= apply_fix (output_ptr
, R_IMM32
, da_operand
, 8);
1002 output_ptr
= apply_fix (output_ptr
, R_IMM16
, da_operand
, 4);
1008 output_ptr
= apply_fix (output_ptr
, R_JR
, da_operand
, 2);
1015 output_ptr
= apply_fix (output_ptr
, R_DISP7
, da_operand
, 2);
1022 output_ptr
= apply_fix (output_ptr
, R_DISP7
, da_operand
, 2);
1023 output_ptr
[-2] = 0x8;
1027 case CLASS_BIT_1OR2
:
1028 *output_ptr
= c
& 0xf;
1031 if (imm_operand
->X_add_number
== 2)
1033 else if (imm_operand
->X_add_number
!= 1)
1034 as_bad (_("immediate must be 1 or 2"));
1037 as_bad (_("immediate 1 or 2 expected"));
1041 *output_ptr
++ = the_cc
;
1044 *output_ptr
++ = the_ctrl
;
1047 *output_ptr
++ = the_ctrl
| 0x8;
1050 *output_ptr
++ = (~the_interrupt
& 0x3);
1053 *output_ptr
++ = (~the_interrupt
& 0x3) | 0x4;
1056 *output_ptr
++ = the_flags
;
1060 *output_ptr
++ = c
& 0xf;
1063 if (reg
[c
& 0xf] == 0)
1064 as_bad (_("can't use R0 here"));
1067 case CLASS_REG_BYTE
:
1068 case CLASS_REG_WORD
:
1069 case CLASS_REG_LONG
:
1070 case CLASS_REG_QUAD
:
1071 /* Insert bit mattern of right reg. */
1072 *output_ptr
++ = reg
[c
& 0xf];
1075 switch (c
& ARG_MASK
)
1078 output_ptr
= apply_fix (output_ptr
, R_CALLR
, da_operand
, 4);
1081 output_ptr
= apply_fix (output_ptr
, R_REL16
, da_operand
, 4);
1084 output_ptr
= apply_fix (output_ptr
, R_IMM16
, da_operand
, 4);
1091 switch (c
& ARG_MASK
)
1094 if (imm_operand
->X_add_number
> 15)
1096 as_bad (_("immediate value out of range"));
1098 imm_operand
->X_add_number
= -imm_operand
->X_add_number
;
1099 output_ptr
= apply_fix (output_ptr
, R_IMM4L
, imm_operand
, 1);
1101 /*case ARG_IMMNMINUS1: not used. */
1103 imm_operand
->X_add_number
--;
1106 if (imm_operand
->X_add_number
> 15)
1108 as_bad (_("immediate value out of range"));
1110 output_ptr
= apply_fix (output_ptr
, R_IMM4L
, imm_operand
, 1);
1113 imm_operand
->X_add_number
= -imm_operand
->X_add_number
;
1116 output_ptr
= apply_fix (output_ptr
, R_IMM8
, imm_operand
, 2);
1119 output_ptr
= apply_fix (output_ptr
, R_IMM16
, imm_operand
, 4);
1122 output_ptr
= apply_fix (output_ptr
, R_IMM32
, imm_operand
, 8);
1131 /* Copy from the nibble buffer into the frag. */
1133 int length
= (output_ptr
- buffer
) / 2;
1135 char *fragp
= frag_more (length
);
1137 while (src
< output_ptr
)
1139 *fragp
= (src
[0] << 4) | src
[1];
1146 /* This is the guts of the machine-dependent assembler. STR points to a
1147 machine dependent instruction. This function is supposed to emit
1148 the frags/bytes it assembles to. */
1151 md_assemble (char *str
)
1156 struct z8k_op operand
[3];
1157 opcode_entry_type
*opcode
;
1159 /* Drop leading whitespace. */
1163 /* Find the op code end. */
1164 for (op_start
= op_end
= str
;
1165 *op_end
!= 0 && *op_end
!= ' ' && ! is_end_of_line
[(unsigned char) *op_end
];
1169 if (op_end
== op_start
)
1171 as_bad (_("can't find opcode "));
1175 *op_end
= 0; /* Zero-terminate op code string for hash_find() call. */
1177 opcode
= (opcode_entry_type
*) hash_find (opcode_hash_control
, op_start
);
1181 as_bad (_("unknown opcode"));
1185 *op_end
= c
; /* Restore original string. */
1187 if (opcode
->opcode
== 250)
1191 char *old
= input_line_pointer
;
1193 /* Was really a pseudo op. */
1195 input_line_pointer
= op_end
;
1199 while (*input_line_pointer
== ' ')
1200 input_line_pointer
++;
1201 p
= (pseudo_typeS
*) (opcode
->func
);
1203 (p
->poc_handler
) (p
->poc_val
);
1204 input_line_pointer
= old
;
1209 char *new_input_line_pointer
;
1211 new_input_line_pointer
= get_operands (opcode
, op_end
, operand
);
1212 if (new_input_line_pointer
)
1213 input_line_pointer
= new_input_line_pointer
;
1215 opcode
= get_specific (opcode
, operand
);
1219 /* Couldn't find an opcode which matched the operands. */
1220 char *where
= frag_more (2);
1225 as_bad (_("Can't find opcode to match operands"));
1229 build_bytes (opcode
, operand
);
1234 tc_crawl_symbol_chain (object_headers
*headers ATTRIBUTE_UNUSED
)
1236 printf (_("call to tc_crawl_symbol_chain \n"));
1239 /* We have no need to default values of symbols. */
1242 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1248 tc_headers_hook (object_headers
*headers ATTRIBUTE_UNUSED
)
1250 printf (_("call to tc_headers_hook \n"));
1253 /* Various routines to kill one day. */
1254 /* Equal to MAX_PRECISION in atof-ieee.c. */
1255 #define MAX_LITTLENUMS 6
1257 /* Turn a string in input_line_pointer into a floating point constant
1258 of type TYPE, and store the appropriate bytes in *LITP. The number
1259 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1260 returned, or NULL on OK. */
1263 md_atof (int type
, char *litP
, int *sizeP
)
1266 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1267 LITTLENUM_TYPE
*wordP
;
1298 return _("Bad call to MD_ATOF()");
1300 t
= atof_ieee (input_line_pointer
, type
, words
);
1302 input_line_pointer
= t
;
1304 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1305 for (wordP
= words
; prec
--;)
1307 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1308 litP
+= sizeof (LITTLENUM_TYPE
);
1313 const char *md_shortopts
= "z:";
1315 struct option md_longopts
[] =
1317 #define OPTION_RELAX (OPTION_MD_BASE)
1318 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
1319 {NULL
, no_argument
, NULL
, 0}
1322 size_t md_longopts_size
= sizeof (md_longopts
);
1325 md_parse_option (int c
, char *arg
)
1330 if (!strcmp (arg
, "8001"))
1332 else if (!strcmp (arg
, "8002"))
1336 as_bad (_("invalid architecture -z%s"), arg
);
1339 z8k_target_from_cmdline
= 1;
1354 md_show_usage (FILE *stream
)
1356 fprintf (stream
, _("\
1358 -z8001 generate segmented code\n\
1359 -z8002 generate unsegmented code\n\
1360 -linkrelax create linker relaxable code\n"));
1364 md_convert_frag (object_headers
*headers ATTRIBUTE_UNUSED
,
1365 segT seg ATTRIBUTE_UNUSED
,
1366 fragS
*fragP ATTRIBUTE_UNUSED
)
1368 printf (_("call to md_convert_frag\n"));
1373 md_section_align (segT seg
, valueT size
)
1375 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
1376 & (-1 << section_alignment
[(int) seg
]));
1379 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1380 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1381 we will have to generate a reloc entry. */
1383 md_apply_fix3 (fixS
*fixP
, valueT
*valP
, segT segment ATTRIBUTE_UNUSED
)
1385 long val
= * (long *) valP
;
1386 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1388 switch (fixP
->fx_r_type
)
1391 buf
[0] = (buf
[0] & 0xf0) | (val
& 0xf);
1397 fixP
->fx_no_overflow
= 1;
1403 as_bad (_("cannot branch to odd address"));
1405 if (val
> 127 || val
< -128)
1406 as_warn (_("relative jump out of range"));
1408 fixP
->fx_no_overflow
= 1;
1416 fixP
->fx_no_overflow
= 1;
1422 as_bad (_("cannot branch to odd address"));
1424 if (val
> 0 || val
< -127)
1425 as_bad (_("relative jump out of range"));
1426 *buf
= (*buf
& 0x80) | (-val
& 0x7f);
1427 fixP
->fx_no_overflow
= 1;
1435 fixP
->fx_no_overflow
= 1;
1441 as_bad (_("cannot branch to odd address"));
1442 if (val
> 4096 || val
< -4095)
1443 as_bad (_("relative call out of range"));
1445 *buf
= (*buf
& 0xf0) | ((val
>> 8) & 0xf);
1447 *buf
++ = val
& 0xff;
1448 fixP
->fx_no_overflow
= 1;
1458 *buf
++ = (val
>> 8);
1463 *buf
++ = (val
>> 24);
1464 *buf
++ = (val
>> 16);
1465 *buf
++ = (val
>> 8);
1470 val
= val
- fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- fixP
->fx_size
;
1471 if (val
> 32767 || val
< -32768)
1472 as_bad (_("relative address out of range"));
1473 *buf
++ = (val
>> 8);
1475 fixP
->fx_no_overflow
= 1;
1480 *buf
++ = (val
>> 16);
1482 *buf
++ = (val
>> 8);
1488 md_number_to_chars (buf
, val
, fixP
->fx_size
);
1492 printf(_("md_apply_fix3: unknown r_type 0x%x\n"), fixP
->fx_r_type
);
1496 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1501 md_estimate_size_before_relax (fragS
*fragP ATTRIBUTE_UNUSED
,
1502 segT segment_type ATTRIBUTE_UNUSED
)
1504 printf (_("call to md_estimate_size_before_relax\n"));
1508 /* Put number into target byte order. */
1511 md_number_to_chars (char *ptr
, valueT use
, int nbytes
)
1513 number_to_chars_bigendian (ptr
, use
, nbytes
);
1516 /* On the Z8000, a PC-relative offset is relative to the address of the
1517 instruction plus its size. */
1519 md_pcrel_from (fixS
*fixP
)
1521 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1525 tc_coff_symbol_emit_hook (symbolS
*s ATTRIBUTE_UNUSED
)
1530 tc_reloc_mangle (fixS
*fix_ptr
, struct internal_reloc
*intr
, bfd_vma base
)
1532 symbolS
*symbol_ptr
;
1534 if (fix_ptr
->fx_addsy
1535 && fix_ptr
->fx_subsy
)
1537 symbolS
*add
= fix_ptr
->fx_addsy
;
1538 symbolS
*sub
= fix_ptr
->fx_subsy
;
1540 if (S_GET_SEGMENT (add
) != S_GET_SEGMENT (sub
))
1541 as_bad (_("Can't subtract symbols in different sections %s %s"),
1542 S_GET_NAME (add
), S_GET_NAME (sub
));
1545 int diff
= S_GET_VALUE (add
) - S_GET_VALUE (sub
);
1547 fix_ptr
->fx_addsy
= 0;
1548 fix_ptr
->fx_subsy
= 0;
1549 fix_ptr
->fx_offset
+= diff
;
1552 symbol_ptr
= fix_ptr
->fx_addsy
;
1554 /* If this relocation is attached to a symbol then it's ok
1556 if (fix_ptr
->fx_r_type
== 0)
1558 /* cons likes to create reloc32's whatever the size of the reloc. */
1559 switch (fix_ptr
->fx_size
)
1562 intr
->r_type
= R_IMM16
;
1565 intr
->r_type
= R_IMM8
;
1568 intr
->r_type
= R_IMM32
;
1575 intr
->r_type
= fix_ptr
->fx_r_type
;
1577 intr
->r_vaddr
= fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
+ base
;
1578 intr
->r_offset
= fix_ptr
->fx_offset
;
1581 intr
->r_symndx
= symbol_ptr
->sy_number
;
1583 intr
->r_symndx
= -1;