1 /* tc-z8k.c -- Assemble code for the Zilog Z800n
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, 2002
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 static void s_segm
PARAMS ((int));
42 static void s_unseg
PARAMS ((int));
43 static void even
PARAMS ((int));
44 static int tohex
PARAMS ((int));
45 static void sval
PARAMS ((int));
49 int ignore ATTRIBUTE_UNUSED
;
52 machine
= bfd_mach_z8001
;
58 int ignore ATTRIBUTE_UNUSED
;
61 machine
= bfd_mach_z8002
;
67 int ignore ATTRIBUTE_UNUSED
;
70 record_alignment (now_seg
, 1);
86 int ignore ATTRIBUTE_UNUSED
;
89 if (*input_line_pointer
== '\'')
93 c
= *input_line_pointer
++;
98 c
= (tohex (input_line_pointer
[0]) << 4)
99 | tohex (input_line_pointer
[1]);
100 input_line_pointer
+= 2;
102 FRAG_APPEND_1_CHAR (c
);
103 c
= *input_line_pointer
++;
105 demand_empty_rest_of_line ();
109 /* This table describes all the machine specific pseudo-ops the assembler
110 has to support. The fields are:
111 pseudo-op name without dot
112 function to call to execute this pseudo-op
113 Integer arg to pass to the function
116 const pseudo_typeS md_pseudo_table
[] = {
118 {"data.b" , cons
, 1},
119 {"data.w" , cons
, 2},
120 {"data.l" , cons
, 4},
121 {"form" , listing_psize
, 0},
122 {"heading", listing_title
, 0},
123 {"import" , s_ignore
, 0},
124 {"page" , listing_eject
, 0},
125 {"program", s_ignore
, 0},
126 {"z8001" , s_segm
, 0},
127 {"z8002" , s_unseg
, 0},
129 {"segm" , s_segm
, 0},
130 {"unsegm" , s_unseg
, 0},
131 {"unseg" , s_unseg
, 0},
132 {"name" , s_app_file
, 0},
133 {"global" , s_globl
, 0},
138 {"rsect" , obj_coff_section
, 0},
139 {"sect" , obj_coff_section
, 0},
140 {"block" , s_space
, 0},
145 const char EXP_CHARS
[] = "eE";
147 /* Chars that mean this number is a floating point constant.
150 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
152 /* Opcode mnemonics. */
153 static struct hash_control
*opcode_hash_control
;
158 const opcode_entry_type
*opcode
;
161 opcode_hash_control
= hash_new ();
163 for (opcode
= z8k_table
; opcode
->name
; opcode
++)
165 /* Only enter unique codes into the table. */
166 if (idx
!= opcode
->idx
)
167 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
171 /* Default to z8002. */
174 /* Insert the pseudo ops, too. */
175 for (idx
= 0; md_pseudo_table
[idx
].poc_name
; idx
++)
177 opcode_entry_type
*fake_opcode
;
178 fake_opcode
= (opcode_entry_type
*) malloc (sizeof (opcode_entry_type
));
179 fake_opcode
->name
= md_pseudo_table
[idx
].poc_name
;
180 fake_opcode
->func
= (void *) (md_pseudo_table
+ idx
);
181 fake_opcode
->opcode
= 250;
182 hash_insert (opcode_hash_control
, fake_opcode
->name
, fake_opcode
);
194 typedef struct z8k_op
{
195 /* 'b','w','r','q'. */
203 /* Any other register associated with the mode. */
206 /* Any expression. */
210 static expressionS
*da_operand
;
211 static expressionS
*imm_operand
;
219 static char *whatreg
PARAMS ((int *, char *));
220 static char *parse_reg
PARAMS ((char *, int *, unsigned int *));
221 static char *parse_exp
PARAMS ((char *, expressionS
*));
222 static char *checkfor
PARAMS ((char *, char));
223 static void regword
PARAMS ((int, char *));
224 static void regaddr
PARAMS ((int, char *));
225 static void get_ctrl_operand
226 PARAMS ((char **, struct z8k_op
*, unsigned int));
227 static void get_flags_operand
228 PARAMS ((char **, struct z8k_op
*, unsigned int));
229 static void get_interrupt_operand
230 PARAMS ((char **, struct z8k_op
*, unsigned int));
231 static void get_cc_operand
232 PARAMS ((char **, struct z8k_op
*, unsigned int));
233 static void get_operand
234 PARAMS ((char **, struct z8k_op
*, unsigned int));
235 static char *get_operands
236 PARAMS ((const opcode_entry_type
*, char *, op_type
*));
237 static opcode_entry_type
*get_specific
238 PARAMS ((opcode_entry_type
*, op_type
*));
240 PARAMS ((int, int, expressionS
*));
241 static char *apply_fix
242 PARAMS ((char *, int, expressionS
*, int));
243 static void build_bytes
244 PARAMS ((opcode_entry_type
*, struct z8k_op
*));
251 if (ISDIGIT (src
[1]))
253 *reg
= (src
[0] - '0') * 10 + src
[1] - '0';
258 *reg
= (src
[0] - '0');
269 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
277 /* Try to parse a reg name. Return a pointer to the first character
278 in SRC after the reg name. */
281 parse_reg (src
, mode
, reg
)
289 if (src
[0] == 's' && src
[1] == 'p' && (src
[2] == 0 || src
[2] == ','))
293 *mode
= CLASS_REG_LONG
;
298 *mode
= CLASS_REG_WORD
;
307 if (src
[2] < '0' || src
[2] > '9')
308 return res
; /* Assume no register name but a label starting with 'rr'. */
309 *mode
= CLASS_REG_LONG
;
310 res
= whatreg (reg
, src
+ 2);
313 as_warn (_("register rr%d, out of range."), regno
);
315 else if (src
[1] == 'h')
317 if (src
[2] < '0' || src
[2] > '9')
318 return res
; /* Assume no register name but a label starting with 'rh'. */
319 *mode
= CLASS_REG_BYTE
;
320 res
= whatreg (reg
, src
+ 2);
323 as_warn (_("register rh%d, out of range."), regno
);
325 else if (src
[1] == 'l')
327 if (src
[2] < '0' || src
[2] > '9')
328 return res
; /* Assume no register name but a label starting with 'rl'. */
329 *mode
= CLASS_REG_BYTE
;
330 res
= whatreg (reg
, src
+ 2);
333 as_warn (_("register rl%d, out of range."), regno
);
336 else if (src
[1] == 'q')
338 if (src
[2] < '0' || src
[2] > '9')
339 return res
; /* Assume no register name but a label starting with 'rq'. */
340 *mode
= CLASS_REG_QUAD
;
341 res
= whatreg (reg
, src
+ 2);
344 as_warn (_("register rq%d, out of range."), regno
);
348 if (src
[1] < '0' || src
[1] > '9')
349 return res
; /* Assume no register name but a label starting with 'r'. */
350 *mode
= CLASS_REG_WORD
;
351 res
= whatreg (reg
, src
+ 1);
354 as_warn (_("register r%d, out of range."), regno
);
365 char *save
= input_line_pointer
;
368 input_line_pointer
= s
;
370 if (op
->X_op
== O_absent
)
371 as_bad (_("missing operand"));
372 new = input_line_pointer
;
373 input_line_pointer
= save
;
377 /* The many forms of operand:
399 as_bad (_("expected %c"), what
);
404 /* Make sure the mode supplied is the size of a word. */
407 regword (mode
, string
)
416 as_bad (_("register is wrong size for a word %s"), string
);
420 /* Make sure the mode supplied is the size of an address. */
423 regaddr (mode
, string
)
429 ok
= segmented_mode
? CLASS_REG_LONG
: CLASS_REG_WORD
;
432 as_bad (_("register is wrong size for address %s"), string
);
441 struct ctrl_names ctrl_table
[] = {
454 get_ctrl_operand (ptr
, mode
, dst
)
457 unsigned int dst ATTRIBUTE_UNUSED
;
465 mode
->mode
= CLASS_CTRL
;
466 for (i
= 0; ctrl_table
[i
].name
; i
++)
470 for (j
= 0; ctrl_table
[i
].name
[j
]; j
++)
472 if (ctrl_table
[i
].name
[j
] != src
[j
])
475 the_ctrl
= ctrl_table
[i
].value
;
491 struct flag_names flag_table
[] = {
502 get_flags_operand (ptr
, mode
, dst
)
505 unsigned int dst ATTRIBUTE_UNUSED
;
514 mode
->mode
= CLASS_FLAGS
;
516 for (j
= 0; j
<= 9; j
++)
520 for (i
= 0; flag_table
[i
].name
; i
++)
522 if (flag_table
[i
].name
[0] == src
[j
])
524 the_flags
= the_flags
| flag_table
[i
].value
;
537 struct interrupt_names
{
543 struct interrupt_names intr_table
[] = {
552 get_interrupt_operand (ptr
, mode
, dst
)
555 unsigned int dst ATTRIBUTE_UNUSED
;
563 mode
->mode
= CLASS_IMM
;
564 for (i
= 0; intr_table
[i
].name
; i
++)
568 for (j
= 0; intr_table
[i
].name
[j
]; j
++)
570 if (intr_table
[i
].name
[j
] != src
[j
])
573 the_interrupt
= intr_table
[i
].value
;
589 struct cc_names table
[] = {
616 get_cc_operand (ptr
, mode
, dst
)
619 unsigned int dst ATTRIBUTE_UNUSED
;
627 mode
->mode
= CLASS_CC
;
628 for (i
= 0; table
[i
].name
; i
++)
632 for (j
= 0; table
[i
].name
[j
]; j
++)
634 if (table
[i
].name
[j
] != src
[j
])
637 the_cc
= table
[i
].value
;
647 get_operand (ptr
, mode
, dst
)
650 unsigned int dst ATTRIBUTE_UNUSED
;
661 mode
->mode
= CLASS_IMM
;
662 imm_operand
= &(mode
->exp
);
663 src
= parse_exp (src
+ 1, &(mode
->exp
));
665 else if (*src
== '@')
669 mode
->mode
= CLASS_IR
;
670 src
= parse_reg (src
+ 1, &d
, &mode
->reg
);
676 end
= parse_reg (src
, &mode
->mode
, ®n
);
686 end
= parse_reg (src
, &nw
, &nr
);
693 as_bad (_("Missing ) in ra(rb)"));
697 regaddr (mode
->mode
, "ra(rb) ra");
699 regword (mode
->mode
, "ra(rb) rb");
701 mode
->mode
= CLASS_BX
;
711 src
= parse_exp (src
, &(mode
->exp
));
712 src
= checkfor (src
, ')');
713 mode
->mode
= CLASS_BA
;
716 imm_operand
= &(mode
->exp
);
727 /* No initial reg. */
728 src
= parse_exp (src
, &(mode
->exp
));
732 end
= parse_reg (src
, &(mode
->mode
), ®n
);
733 regword (mode
->mode
, "addr(Ra) ra");
734 mode
->mode
= CLASS_X
;
737 da_operand
= &(mode
->exp
);
738 src
= checkfor (end
, ')');
742 /* Just an address. */
743 mode
->mode
= CLASS_DA
;
746 da_operand
= &(mode
->exp
);
754 get_operands (opcode
, op_end
, operand
)
755 const opcode_entry_type
*opcode
;
763 switch (opcode
->noperands
)
771 if (opcode
->arg_info
[0] == CLASS_CC
)
772 get_cc_operand (&ptr
, operand
+ 0, 0);
774 else if (opcode
->arg_info
[0] == CLASS_FLAGS
)
775 get_flags_operand (&ptr
, operand
+ 0, 0);
777 else if (opcode
->arg_info
[0] == (CLASS_IMM
+ (ARG_IMM2
)))
778 get_interrupt_operand (&ptr
, operand
+ 0, 0);
781 get_operand (&ptr
, operand
+ 0, 0);
788 if (opcode
->arg_info
[0] == CLASS_CC
)
789 get_cc_operand (&ptr
, operand
+ 0, 0);
791 else if (opcode
->arg_info
[0] == CLASS_CTRL
)
793 get_ctrl_operand (&ptr
, operand
+ 0, 0);
798 get_operand (&ptr
, operand
+ 0, 0);
804 get_ctrl_operand (&ptr
, operand
+ 1, 1);
809 get_operand (&ptr
, operand
+ 0, 0);
815 get_operand (&ptr
, operand
+ 1, 1);
819 get_operand (&ptr
, operand
+ 0, 0);
822 get_operand (&ptr
, operand
+ 1, 1);
825 get_operand (&ptr
, operand
+ 2, 2);
829 get_operand (&ptr
, operand
+ 0, 0);
832 get_operand (&ptr
, operand
+ 1, 1);
835 get_operand (&ptr
, operand
+ 2, 2);
838 get_cc_operand (&ptr
, operand
+ 3, 3);
848 /* Passed a pointer to a list of opcodes which use different
849 addressing modes. Return the opcode which matches the opcodes
852 static opcode_entry_type
*
853 get_specific (opcode
, operands
)
854 opcode_entry_type
*opcode
;
857 opcode_entry_type
*this_try
= opcode
;
859 unsigned int noperands
= opcode
->noperands
;
861 int this_index
= opcode
->idx
;
863 while (this_index
== opcode
->idx
&& !found
)
868 for (i
= 0; i
< noperands
; i
++)
870 unsigned int mode
= operands
[i
].mode
;
872 if ((mode
& CLASS_MASK
) != (this_try
->arg_info
[i
] & CLASS_MASK
))
874 /* It could be a pc rel operand, if this is a da mode
875 and we like disps, then insert it. */
877 if (mode
== CLASS_DA
&& this_try
->arg_info
[i
] == CLASS_DISP
)
879 /* This is the case. */
880 operands
[i
].mode
= CLASS_DISP
;
882 else if (mode
== CLASS_BA
&& this_try
->arg_info
[i
])
884 /* Can't think of a way to turn what we've been
885 given into something that's OK. */
888 else if (this_try
->arg_info
[i
] & CLASS_PR
)
890 if (mode
== CLASS_REG_LONG
&& segmented_mode
)
894 else if (mode
== CLASS_REG_WORD
&& !segmented_mode
)
904 switch (mode
& CLASS_MASK
)
919 reg
[this_try
->arg_info
[i
] & ARG_MASK
] = operands
[i
].reg
;
934 #if 0 /* Not used. */
936 check_operand (operand
, width
, string
)
937 struct z8k_op
*operand
;
941 if (operand
->exp
.X_add_symbol
== 0
942 && operand
->exp
.X_op_symbol
== 0)
945 /* No symbol involved, let's look at offset, it's dangerous if
946 any of the high bits are not 0 or ff's, find out by oring or
947 anding with the width and seeing if the answer is 0 or all
949 if ((operand
->exp
.X_add_number
& ~width
) != 0 &&
950 (operand
->exp
.X_add_number
| width
) != (~0))
952 as_warn (_("operand %s0x%x out of range."),
953 string
, operand
->exp
.X_add_number
);
960 static char buffer
[20];
963 newfix (ptr
, type
, operand
)
966 expressionS
*operand
;
968 if (operand
->X_add_symbol
969 || operand
->X_op_symbol
970 || operand
->X_add_number
)
972 fix_new_exp (frag_now
,
982 apply_fix (ptr
, type
, operand
, size
)
985 expressionS
*operand
;
988 int n
= operand
->X_add_number
;
990 newfix ((ptr
- buffer
) / 2, type
, 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. */
1012 #define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
1015 build_bytes (this_try
, operand
)
1016 opcode_entry_type
*this_try
;
1017 struct z8k_op
*operand ATTRIBUTE_UNUSED
;
1019 char *output_ptr
= buffer
;
1023 unsigned int *class_ptr
;
1025 frag_wane (frag_now
);
1028 memset (buffer
, 0, sizeof (buffer
));
1029 class_ptr
= this_try
->byte_info
;
1031 for (nibble
= 0; (c
= *class_ptr
++); nibble
++)
1034 switch (c
& CLASS_MASK
)
1040 /* Direct address, we don't cope with the SS mode right now. */
1043 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
1044 output_ptr
= apply_fix (output_ptr
, R_IMM32
, da_operand
, 8);
1048 output_ptr
= apply_fix (output_ptr
, R_IMM16
, da_operand
, 4);
1054 output_ptr
= apply_fix (output_ptr
, R_JR
, da_operand
, 2);
1061 output_ptr
= apply_fix (output_ptr
, R_DISP7
, da_operand
, 2);
1068 output_ptr
= apply_fix (output_ptr
, R_DISP7
, da_operand
, 2);
1069 output_ptr
[-2] = 0x8;
1073 case CLASS_BIT_1OR2
:
1074 *output_ptr
= c
& 0xf;
1077 if (imm_operand
->X_add_number
== 2)
1079 else if (imm_operand
->X_add_number
!= 1)
1080 as_bad (_("immediate must be 1 or 2"));
1083 as_bad (_("immediate 1 or 2 expected"));
1087 *output_ptr
++ = the_cc
;
1090 *output_ptr
++ = the_ctrl
;
1093 *output_ptr
++ = the_ctrl
| 0x8;
1096 *output_ptr
++ = (~the_interrupt
& 0x3);
1099 *output_ptr
++ = (~the_interrupt
& 0x3) | 0x4;
1102 *output_ptr
++ = the_flags
;
1106 *output_ptr
++ = c
& 0xf;
1109 if (reg
[c
& 0xf] == 0)
1110 as_bad (_("can't use R0 here"));
1113 case CLASS_REG_BYTE
:
1114 case CLASS_REG_WORD
:
1115 case CLASS_REG_LONG
:
1116 case CLASS_REG_QUAD
:
1117 /* Insert bit mattern of right reg. */
1118 *output_ptr
++ = reg
[c
& 0xf];
1121 switch (c
& ARG_MASK
)
1124 output_ptr
= apply_fix (output_ptr
, R_CALLR
, da_operand
, 4);
1127 output_ptr
= apply_fix (output_ptr
, R_REL16
, da_operand
, 4);
1130 output_ptr
= apply_fix (output_ptr
, R_IMM16
, da_operand
, 4);
1138 switch (c
& ARG_MASK
)
1141 imm_operand
->X_add_number
= -imm_operand
->X_add_number
;
1144 output_ptr
= apply_fix (output_ptr
, R_IMM4L
, imm_operand
, 1);
1147 imm_operand
->X_add_number
--;
1148 output_ptr
= apply_fix (output_ptr
, R_IMM4L
, imm_operand
, 1);
1150 case ARG_IMMNMINUS1
:
1151 imm_operand
->X_add_number
--;
1152 output_ptr
= apply_fix (output_ptr
, R_IMM4L
, imm_operand
, 1);
1155 imm_operand
->X_add_number
= -imm_operand
->X_add_number
;
1157 output_ptr
= apply_fix (output_ptr
, R_IMM8
, imm_operand
, 2);
1160 output_ptr
= apply_fix (output_ptr
, R_IMM16
, imm_operand
, 4);
1164 output_ptr
= apply_fix (output_ptr
, R_IMM32
, imm_operand
, 8);
1174 /* Copy from the nibble buffer into the frag. */
1176 int length
= (output_ptr
- buffer
) / 2;
1178 char *fragp
= frag_more (length
);
1180 while (src
< output_ptr
)
1182 *fragp
= (src
[0] << 4) | src
[1];
1189 /* This is the guts of the machine-dependent assembler. STR points to a
1190 machine dependent instruction. This function is supposed to emit
1191 the frags/bytes it assembles to. */
1200 struct z8k_op operand
[3];
1201 opcode_entry_type
*opcode
;
1202 opcode_entry_type
*prev_opcode
;
1204 /* Drop leading whitespace. */
1208 /* Find the op code end. */
1209 for (op_start
= op_end
= str
;
1210 *op_end
!= 0 && *op_end
!= ' ';
1214 if (op_end
== op_start
)
1216 as_bad (_("can't find opcode "));
1222 opcode
= (opcode_entry_type
*) hash_find (opcode_hash_control
, op_start
);
1226 as_bad (_("unknown opcode"));
1230 if (opcode
->opcode
== 250)
1234 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
)
1257 input_line_pointer
= new_input_line_pointer
;
1258 prev_opcode
= opcode
;
1260 opcode
= get_specific (opcode
, operand
);
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
);
1279 tc_crawl_symbol_chain (headers
)
1280 object_headers
*headers ATTRIBUTE_UNUSED
;
1282 printf (_("call to tc_crawl_symbol_chain \n"));
1286 md_undefined_symbol (name
)
1287 char *name ATTRIBUTE_UNUSED
;
1293 tc_headers_hook (headers
)
1294 object_headers
*headers ATTRIBUTE_UNUSED
;
1296 printf (_("call to tc_headers_hook \n"));
1299 /* Various routines to kill one day. */
1300 /* Equal to MAX_PRECISION in atof-ieee.c. */
1301 #define MAX_LITTLENUMS 6
1303 /* Turn a string in input_line_pointer into a floating point constant
1304 of type TYPE, and store the appropriate bytes in *LITP. The number
1305 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1306 returned, or NULL on OK. */
1309 md_atof (type
, litP
, sizeP
)
1315 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1316 LITTLENUM_TYPE
*wordP
;
1347 return _("Bad call to MD_ATOF()");
1349 t
= atof_ieee (input_line_pointer
, type
, words
);
1351 input_line_pointer
= t
;
1353 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1354 for (wordP
= words
; prec
--;)
1356 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1357 litP
+= sizeof (LITTLENUM_TYPE
);
1362 const char *md_shortopts
= "z:";
1364 struct option md_longopts
[] =
1366 {NULL
, no_argument
, NULL
, 0}
1369 size_t md_longopts_size
= sizeof (md_longopts
);
1372 md_parse_option (c
, arg
)
1379 if (!strcmp (arg
, "8001"))
1381 else if (!strcmp (arg
, "8002"))
1385 as_bad (_("invalid architecture -z%s"), arg
);
1398 md_show_usage (stream
)
1401 fprintf (stream
, _("\
1403 -z8001 generate segmented code\n\
1404 -z8002 generate unsegmented code\n"));
1408 md_convert_frag (headers
, seg
, fragP
)
1409 object_headers
*headers ATTRIBUTE_UNUSED
;
1410 segT seg ATTRIBUTE_UNUSED
;
1411 fragS
*fragP ATTRIBUTE_UNUSED
;
1413 printf (_("call to md_convert_frag \n"));
1418 md_section_align (seg
, size
)
1422 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
1423 & (-1 << section_alignment
[(int) seg
]));
1427 md_apply_fix3 (fixP
, valP
, segment
)
1430 segT segment ATTRIBUTE_UNUSED
;
1432 long val
= * (long *) valP
;
1433 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1435 switch (fixP
->fx_r_type
)
1438 buf
[0] = (buf
[0] & 0xf0) | ((buf
[0] + val
) & 0xf);
1463 *buf
++ = (val
>> 8);
1467 *buf
++ = (val
>> 24);
1468 *buf
++ = (val
>> 16);
1469 *buf
++ = (val
>> 8);
1474 *buf
++ = (val
>> 16);
1476 *buf
++ = (val
>> 8);
1482 md_number_to_chars (buf
, val
, fixP
->fx_size
);
1489 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1494 md_estimate_size_before_relax (fragP
, segment_type
)
1495 register fragS
*fragP ATTRIBUTE_UNUSED
;
1496 register segT segment_type ATTRIBUTE_UNUSED
;
1498 printf (_("call tomd_estimate_size_before_relax\n"));
1502 /* Put number into target byte order. */
1505 md_number_to_chars (ptr
, use
, nbytes
)
1510 number_to_chars_bigendian (ptr
, use
, nbytes
);
1514 md_pcrel_from (fixP
)
1515 fixS
*fixP ATTRIBUTE_UNUSED
;
1521 tc_coff_symbol_emit_hook (s
)
1522 symbolS
*s ATTRIBUTE_UNUSED
;
1527 tc_reloc_mangle (fix_ptr
, intr
, base
)
1529 struct internal_reloc
*intr
;
1533 symbolS
*symbol_ptr
;
1535 if (fix_ptr
->fx_addsy
1536 && fix_ptr
->fx_subsy
)
1538 symbolS
*add
= fix_ptr
->fx_addsy
;
1539 symbolS
*sub
= fix_ptr
->fx_subsy
;
1541 if (S_GET_SEGMENT (add
) != S_GET_SEGMENT (sub
))
1542 as_bad (_("Can't subtract symbols in different sections %s %s"),
1543 S_GET_NAME (add
), S_GET_NAME (sub
));
1546 int diff
= S_GET_VALUE (add
) - S_GET_VALUE (sub
);
1548 fix_ptr
->fx_addsy
= 0;
1549 fix_ptr
->fx_subsy
= 0;
1550 fix_ptr
->fx_offset
+= diff
;
1553 symbol_ptr
= fix_ptr
->fx_addsy
;
1555 /* If this relocation is attached to a symbol then it's ok
1557 if (fix_ptr
->fx_r_type
== 0)
1559 /* cons likes to create reloc32's whatever the size of the reloc. */
1560 switch (fix_ptr
->fx_size
)
1563 intr
->r_type
= R_IMM16
;
1566 intr
->r_type
= R_IMM8
;
1569 intr
->r_type
= R_IMM32
;
1576 intr
->r_type
= fix_ptr
->fx_r_type
;
1578 intr
->r_vaddr
= fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
+ base
;
1579 intr
->r_offset
= fix_ptr
->fx_offset
;
1582 intr
->r_symndx
= symbol_ptr
->sy_number
;
1584 intr
->r_symndx
= -1;