* elf64-alpha.c (elf64_alpha_relocate_section): Soft fail
[binutils.git] / gas / config / tc-w65.c
blob24247ae9ad0193be9dec8f7edfa30a228d71db86
1 /* tc-w65.c -- Assemble code for the W65816
2 Copyright 1995, 1998, 2000, 2001 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 2, or (at your option)
9 any later version.
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, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
21 /* Written By Steve Chamberlain <sac@cygnus.com>. */
23 #include <stdio.h>
24 #include "as.h"
25 #include "bfd.h"
26 #include "subsegs.h"
27 #define DEFINE_TABLE
28 #include "../opcodes/w65-opc.h"
29 #include <ctype.h>
31 const char comment_chars[] = "!";
32 CONST char line_separator_chars[] = ";";
33 const char line_comment_chars[] = "!#";
35 /* This table describes all the machine specific pseudo-ops the assembler
36 has to support. The fields are:
38 pseudo-op name without dot
39 function to call to execute this pseudo-op
40 Integer arg to pass to the function */
42 #define OP_BCC 0x90
43 #define OP_BCS 0xB0
44 #define OP_BEQ 0xF0
45 #define OP_BMI 0x30
46 #define OP_BNE 0xD0
47 #define OP_BPL 0x10
48 #define OP_BRA 0x80
49 #define OP_BRL 0x82
50 #define OP_BVC 0x50
51 #define OP_BVS 0x70
53 void s_longa ();
55 const pseudo_typeS md_pseudo_table[] = {
56 {"int", cons, 2},
57 {"word", cons, 2},
58 {"longa", s_longa, 0},
59 {"longi", s_longa, 1},
60 {0, 0, 0}
63 void cons ();
64 void s_align_bytes ();
66 #if 0
67 int md_reloc_size;
68 #endif
70 static int relax; /* set if -relax seen */
72 const char EXP_CHARS[] = "eE";
74 /* Chars that mean this number is a floating point constant. */
75 /* As in 0f12.456 */
76 /* or 0d1.2345e12 */
77 const char FLT_CHARS[] = "rRsSfFdDxXpP";
79 /* Opcode mnemonics */
80 static struct hash_control *opcode_hash_control;
82 int M; /* M flag */
83 int X; /* X flag */
85 #define C(a,b) ENCODE_RELAX(a,b)
86 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
88 #define GET_WHAT(x) ((x>>2))
90 #define BYTE_DISP 1
91 #define WORD_DISP 2
92 #define UNDEF_BYTE_DISP 0
93 #define UNDEF_WORD_DISP 3
95 #define COND_BRANCH 1
96 #define UNCOND_BRANCH 2
97 #define END 3
99 #define BYTE_F 127 /* How far we can branch forwards */
100 #define BYTE_B -126 /* How far we can branch backwards */
101 #define WORD_F 32767
102 #define WORD_B 32768
104 relax_typeS md_relax_table[C (END, 0)] = {
105 { 0, 0, 0, 0 },
106 { 0, 0, 0, 0 },
107 { 0, 0, 0, 0 },
108 { 0, 0, 0, 0 },
110 /* COND_BRANCH */
111 { 0, 0, 0, 0 }, /* UNDEF_BYTE_DISP */
112 { BYTE_F, BYTE_B, 2, C (COND_BRANCH, WORD_DISP) }, /* BYTE_DISP */
113 { WORD_F, WORD_B, 5, 0 }, /* WORD_DISP */
114 { 0, 0, 5, 0 }, /* UNDEF_WORD_DISP */
116 /* UNCOND_BRANCH */
117 { 0, 0, 0, 0 }, /* UNDEF_BYTE_DISP */
118 { BYTE_F, BYTE_B, 2, C (UNCOND_BRANCH, WORD_DISP) }, /* BYTE_DISP */
119 { WORD_F, WORD_B, 3, 0 }, /* WORD_DISP */
120 { 0, 0, 3, 0 } /* UNDEF_WORD_DISP */
124 /* This function is called once, at assembler startup time. This
125 should set up all the tables, etc that the MD part of the assembler
126 needs. */
128 void
129 s_longa (xmode)
131 int *p = xmode ? &X : &M;
132 while (*input_line_pointer == ' ')
133 input_line_pointer++;
134 if (strncmp (input_line_pointer, "on", 2) == 0)
136 input_line_pointer += 2;
137 *p = 0;
139 else if (strncmp (input_line_pointer, "off", 3) == 0)
141 *p = 1;
142 input_line_pointer += 3;
144 else
145 as_bad (_("need on or off."));
146 demand_empty_rest_of_line ();
149 void
150 md_begin ()
152 struct opinfo *opcode;
153 char *prev_name = "";
155 opcode_hash_control = hash_new ();
157 /* Insert unique names into hash table. */
158 for (opcode = optable; opcode->name; opcode++)
160 if (strcmp (prev_name, opcode->name))
162 prev_name = opcode->name;
163 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
165 else
167 /* Make all the opcodes with the same name point to the same
168 string. */
169 opcode->name = prev_name;
173 flag_signed_overflow_ok = 1;
176 static expressionS immediate; /* absolute expression */
177 static expressionS immediate1; /* absolute expression */
179 static symbolS *
180 dot ()
182 const char *fake;
184 /* JF: '.' is pseudo symbol with value of current location
185 in current segment. */
186 fake = FAKE_LABEL_NAME;
187 return symbol_new (fake,
188 now_seg,
189 (valueT) frag_now_fix (),
190 frag_now);
194 int expr_size;
195 int expr_shift;
196 int tc_cons_reloc;
198 void
199 w65_expression (dest, bytes)
200 expressionS *dest;
201 unsigned int bytes;
203 expr_size = 0;
204 expr_shift = 0;
205 tc_cons_reloc = 0;
206 while (*input_line_pointer == ' ')
207 input_line_pointer++;
209 if (*input_line_pointer == '<')
211 expr_size = 1;
212 input_line_pointer++;
214 else if (*input_line_pointer == '>')
216 expr_shift = 1;
217 input_line_pointer++;
219 else if (*input_line_pointer == '^')
221 expr_shift = 2;
222 input_line_pointer++;
225 expr (0, dest);
228 int amode;
230 static char *
231 parse_exp (s, bytes)
232 char *s;
233 int bytes;
235 char *save;
236 char *new;
238 save = input_line_pointer;
239 input_line_pointer = s;
240 w65_expression (&immediate, bytes);
241 if (immediate.X_op == O_absent)
242 as_bad (_("missing operand"));
243 new = input_line_pointer;
244 input_line_pointer = save;
245 return new;
248 static char *
249 get_operands (info, ptr)
250 struct opinfo *info;
251 char *ptr;
253 register int override_len = 0;
254 register int bytes = 0;
256 while (*ptr == ' ')
257 ptr++;
259 if (ptr[0] == '#')
261 ptr++;
262 switch (info->amode)
264 case ADDR_IMMTOI:
265 bytes = X ? 1 : 2;
266 amode = ADDR_IMMTOI;
267 break;
268 case ADDR_IMMTOA:
269 bytes = M ? 1 : 2;
270 amode = ADDR_IMMTOA;
271 break;
272 case ADDR_IMMCOP:
273 bytes = 1;
274 amode = ADDR_IMMCOP;
275 break;
276 case ADDR_DIR:
277 bytes = 2;
278 amode = ADDR_ABS;
279 break;
280 default:
281 abort ();
282 break;
284 ptr = parse_exp (ptr);
286 else if (ptr[0] == '!')
288 ptr = parse_exp (ptr + 1);
289 if (ptr[0] == ',')
291 if (ptr[1] == 'y')
293 amode = ADDR_ABS_IDX_Y;
294 bytes = 2;
295 ptr += 2;
297 else if (ptr[1] == 'x')
299 amode = ADDR_ABS_IDX_X;
300 bytes = 2;
301 ptr += 2;
303 else
305 as_bad (_("syntax error after <exp"));
308 else
310 amode = ADDR_ABS;
311 bytes = 2;
314 else if (ptr[0] == '>')
316 ptr = parse_exp (ptr + 1);
317 if (ptr[0] == ',' && ptr[1] == 'x')
319 amode = ADDR_ABS_LONG_IDX_X;
320 bytes = 3;
321 ptr += 2;
323 else
325 amode = ADDR_ABS_LONG;
326 bytes = 3;
329 else if (ptr[0] == '<')
331 ptr = parse_exp (ptr + 1);
332 if (ptr[0] == ',')
334 if (ptr[1] == 'y')
336 amode = ADDR_DIR_IDX_Y;
337 ptr += 2;
338 bytes = 2;
340 else if (ptr[1] == 'x')
342 amode = ADDR_DIR_IDX_X;
343 ptr += 2;
344 bytes = 2;
346 else
348 as_bad (_("syntax error after <exp"));
351 else
353 amode = ADDR_DIR;
354 bytes = 1;
357 else if (ptr[0] == 'a')
359 amode = ADDR_ACC;
361 else if (ptr[0] == '(')
363 /* Look for (exp),y
364 (<exp),y
365 (exp,x)
366 (<exp,x)
367 (exp)
368 (!exp)
369 (exp)
370 (<exp)
371 (exp,x)
372 (!exp,x)
373 (exp,s)
374 (exp,s),y */
376 ptr++;
377 if (ptr[0] == '<')
379 override_len = 1;
380 ptr++;
382 else if (ptr[0] == '!')
384 override_len = 2;
385 ptr++;
387 else if (ptr[0] == '>')
389 override_len = 3;
390 ptr++;
392 else
394 override_len = 0;
396 ptr = parse_exp (ptr);
398 if (ptr[0] == ',')
400 ptr++;
401 if (ptr[0] == 'x' && ptr[1] == ')')
403 ptr += 2;
405 if (override_len == 1)
407 amode = ADDR_DIR_IDX_IND_X;
408 bytes = 2;
410 else
412 amode = ADDR_ABS_IND_IDX;
413 bytes = 2;
416 else if (ptr[0] == 's' && ptr[1] == ')'
417 && ptr[2] == ',' && ptr[3] == 'y')
419 amode = ADDR_STACK_REL_INDX_IDX;
420 bytes = 1;
421 ptr += 4;
424 else if (ptr[0] == ')')
426 if (ptr[1] == ',' && ptr[2] == 'y')
428 amode = ADDR_DIR_IND_IDX_Y;
429 ptr += 3;
430 bytes = 2;
432 else
434 if (override_len == 1)
436 amode = ADDR_DIR_IND;
437 bytes = 1;
439 else
441 amode = ADDR_ABS_IND;
442 bytes = 2;
444 ptr++;
449 else if (ptr[0] == '[')
451 ptr = parse_exp (ptr + 1);
452 if (ptr[0] == ']')
454 ptr++;
455 if (ptr[0] == ',' && ptr[1] == 'y')
457 bytes = 1;
458 amode = ADDR_DIR_IND_IDX_Y_LONG;
459 ptr += 2;
461 else
463 if (info->code == O_jmp)
465 bytes = 2;
466 amode = ADDR_ABS_IND_LONG;
468 else
470 bytes = 1;
471 amode = ADDR_DIR_IND_LONG;
476 else
478 ptr = parse_exp (ptr, 2);
479 if (ptr[0] == ',')
481 if (ptr[1] == 'y')
483 if (override_len == 1)
485 bytes = 1;
486 amode = ADDR_DIR_IDX_Y;
488 else
490 amode = ADDR_ABS_IDX_Y;
491 bytes = 2;
493 ptr += 2;
495 else if (ptr[1] == 'x')
497 if (override_len == 1)
499 amode = ADDR_DIR_IDX_X;
500 bytes = 1;
502 else
504 amode = ADDR_ABS_IDX_X;
505 bytes = 2;
507 ptr += 2;
509 else if (ptr[1] == 's')
511 bytes = 1;
512 amode = ADDR_STACK_REL;
513 ptr += 2;
515 else
517 bytes = 1;
518 immediate1 = immediate;
519 ptr = parse_exp (ptr + 1);
520 amode = ADDR_BLOCK_MOVE;
523 else
525 switch (info->amode)
527 case ADDR_PC_REL:
528 amode = ADDR_PC_REL;
529 bytes = 1;
530 break;
531 case ADDR_PC_REL_LONG:
532 amode = ADDR_PC_REL_LONG;
533 bytes = 2;
534 break;
535 default:
536 if (override_len == 1)
538 amode = ADDR_DIR;
539 bytes = 1;
541 else if (override_len == 3)
543 bytes = 3;
544 amode = ADDR_ABS_LONG;
546 else
548 amode = ADDR_ABS;
549 bytes = 2;
555 switch (bytes)
557 case 1:
558 switch (expr_shift)
560 case 0:
561 if (amode == ADDR_DIR)
562 tc_cons_reloc = R_W65_DP;
563 else
564 tc_cons_reloc = R_W65_ABS8;
565 break;
566 case 1:
567 tc_cons_reloc = R_W65_ABS8S8;
568 break;
569 case 2:
570 tc_cons_reloc = R_W65_ABS8S16;
571 break;
573 break;
574 case 2:
575 switch (expr_shift)
577 case 0:
578 tc_cons_reloc = R_W65_ABS16;
579 break;
580 case 1:
581 tc_cons_reloc = R_W65_ABS16S8;
582 break;
583 case 2:
584 tc_cons_reloc = R_W65_ABS16S16;
585 break;
588 return ptr;
591 /* Passed a pointer to a list of opcodes which use different
592 addressing modes, return the opcode which matches the opcodes
593 provided. */
595 static struct opinfo *
596 get_specific (opcode)
597 struct opinfo *opcode;
599 int ocode = opcode->code;
601 for (; opcode->code == ocode; opcode++)
603 if (opcode->amode == amode)
604 return opcode;
606 return 0;
610 check (operand, low, high)
611 expressionS *operand;
612 int low;
613 int high;
615 if (operand->X_op != O_constant
616 || operand->X_add_number < low
617 || operand->X_add_number > high)
619 as_bad ("operand must be absolute in range %d..%d", low, high);
621 return operand->X_add_number;
624 static int log2[] = { 0, 0, 1, 0, 2 };
626 /* Now we know what sort of opcodes it is, let's build the bytes. */
628 static void
629 build_Mytes (opcode)
630 struct opinfo *opcode;
632 int size;
633 int type;
634 int pcrel;
635 char *output;
637 if (opcode->amode == ADDR_IMPLIED)
639 output = frag_more (1);
641 else if (opcode->amode == ADDR_PC_REL)
643 int type;
645 /* This is a relaxable insn, so we do some special handling. */
646 type = opcode->val == OP_BRA ? UNCOND_BRANCH : COND_BRANCH;
647 output = frag_var (rs_machine_dependent,
648 md_relax_table[C (type, WORD_DISP)].rlx_length,
649 md_relax_table[C (type, BYTE_DISP)].rlx_length,
650 C (type, UNDEF_BYTE_DISP),
651 immediate.X_add_symbol,
652 immediate.X_add_number,
655 else
657 switch (opcode->amode)
659 GETINFO (size, type, pcrel);
662 /* If something special was done in the expression modify the
663 reloc type. */
664 if (tc_cons_reloc)
665 type = tc_cons_reloc;
667 /* 1 byte for the opcode + the bytes for the addrmode. */
668 output = frag_more (size + 1);
670 if (opcode->amode == ADDR_BLOCK_MOVE)
672 /* Two relocs for this one. */
673 fix_new_exp (frag_now,
674 output + 1 - frag_now->fr_literal,
676 &immediate,
678 R_W65_ABS8S16);
680 fix_new_exp (frag_now,
681 output + 2 - frag_now->fr_literal,
683 &immediate1,
685 R_W65_ABS8S16);
687 else if (type >= 0
688 && opcode->amode != ADDR_IMPLIED
689 && opcode->amode != ADDR_ACC
690 && opcode->amode != ADDR_STACK)
692 fix_new_exp (frag_now,
693 output + 1 - frag_now->fr_literal,
694 size,
695 &immediate,
696 pcrel,
697 type);
700 output[0] = opcode->val;
703 /* This is the guts of the machine-dependent assembler. STR points to
704 a machine dependent instruction. This function is supposed to emit
705 the frags/bytes it assembles to. */
707 void
708 md_assemble (str)
709 char *str;
711 unsigned char *op_start;
712 unsigned char *op_end;
713 struct opinfo *opcode;
714 char name[20];
715 int nlen = 0;
716 char *p;
718 /* Drop leading whitespace */
719 while (*str == ' ')
720 str++;
722 /* all opcodes are three letters */
723 name[0] = str[0];
724 name[1] = str[1];
725 name[2] = str[2];
726 name[3] = 0;
728 tc_cons_reloc = 0;
729 str += 3;
730 opcode = (struct opinfo *) hash_find (opcode_hash_control, name);
732 if (opcode == NULL)
734 as_bad (_("unknown opcode"));
735 return;
738 if (opcode->amode != ADDR_IMPLIED
739 && opcode->amode != ADDR_STACK)
741 get_operands (opcode, str);
742 opcode = get_specific (opcode);
745 if (opcode == 0)
747 /* Couldn't find an opcode which matched the operands. */
749 char *where = frag_more (1);
751 where[0] = 0x0;
752 where[1] = 0x0;
753 as_bad (_("invalid operands for opcode"));
754 return;
757 build_Mytes (opcode);
760 void
761 tc_crawl_symbol_chain (headers)
762 object_headers *headers;
764 printf (_("call to tc_crawl_symbol_chain \n"));
767 symbolS *
768 md_undefined_symbol (name)
769 char *name;
771 return 0;
774 void
775 tc_headers_hook (headers)
776 object_headers *headers;
778 printf (_("call to tc_headers_hook \n"));
781 /* Various routines to kill one day. */
782 /* Equal to MAX_PRECISION in atof-ieee.c. */
783 #define MAX_LITTLENUMS 6
785 /* Turn a string in input_line_pointer into a floating point constant
786 of type TYPE, and store the appropriate bytes in *LITP. The number
787 of LITTLENUMS emitted is stored in *SIZEP. An error message is
788 returned, or NULL on OK. */
790 char *
791 md_atof (type, litP, sizeP)
792 char type;
793 char *litP;
794 int *sizeP;
796 int prec;
797 LITTLENUM_TYPE words[MAX_LITTLENUMS];
798 LITTLENUM_TYPE *wordP;
799 char *t;
800 char *atof_ieee ();
802 switch (type)
804 case 'f':
805 case 'F':
806 case 's':
807 case 'S':
808 prec = 2;
809 break;
811 case 'd':
812 case 'D':
813 case 'r':
814 case 'R':
815 prec = 4;
816 break;
818 case 'x':
819 case 'X':
820 prec = 6;
821 break;
823 case 'p':
824 case 'P':
825 prec = 6;
826 break;
828 default:
829 *sizeP = 0;
830 return _("Bad call to MD_NTOF()");
832 t = atof_ieee (input_line_pointer, type, words);
833 if (t)
834 input_line_pointer = t;
836 *sizeP = prec * sizeof (LITTLENUM_TYPE);
837 for (wordP = words + prec - 1; prec--;)
839 md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE));
840 litP += sizeof (LITTLENUM_TYPE);
842 return 0;
846 md_parse_option (c, a)
847 int c;
848 char *a;
850 return 1;
853 void
854 tc_Nout_fix_to_chars ()
856 printf (_("call to tc_Nout_fix_to_chars \n"));
857 abort ();
860 /* Called after relaxing, change the frags so they know how big they
861 are. */
863 void
864 md_convert_frag (headers, seg, fragP)
865 object_headers *headers;
866 segT seg;
867 fragS *fragP;
869 int disp_size = 0;
870 int inst_size = 0;
871 unsigned char *buffer =
872 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
874 switch (fragP->fr_subtype)
876 case C (COND_BRANCH, BYTE_DISP):
877 case C (UNCOND_BRANCH, BYTE_DISP):
878 disp_size = 1;
879 inst_size = 1;
880 break;
882 /* Conditional branches to a known 16 bit displacement. */
883 case C (COND_BRANCH, WORD_DISP):
884 switch (buffer[0])
886 case OP_BCC:
887 case OP_BCS:
888 case OP_BEQ:
889 case OP_BMI:
890 case OP_BNE:
891 case OP_BPL:
892 case OP_BVS:
893 case OP_BVC:
894 /* Invert the sense of the test */
895 buffer[0] ^= 0x20;
896 buffer[1] = 3; /* Jump over following brl */
897 buffer[2] = OP_BRL;
898 buffer[3] = 0;
899 buffer[4] = 0;
900 disp_size = 2;
901 inst_size = 3;
902 break;
903 default:
904 abort ();
906 break;
907 case C (UNCOND_BRANCH, WORD_DISP):
908 /* Unconditional branches to a known 16 bit displacement. */
910 switch (buffer[0])
912 case OP_BRA:
913 buffer[0] = OP_BRL;
914 disp_size = 2;
915 inst_size = 1;
916 break;
917 default:
918 abort ();
920 break;
921 /* Got to create a branch over a reloc here. */
922 case C (COND_BRANCH, UNDEF_WORD_DISP):
923 buffer[0] ^= 0x20; /* invert test */
924 buffer[1] = 3;
925 buffer[2] = OP_BRL;
926 buffer[3] = 0;
927 buffer[4] = 0;
928 fix_new (fragP,
929 fragP->fr_fix + 3,
931 fragP->fr_symbol,
932 fragP->fr_offset,
934 R_W65_PCR16);
936 fragP->fr_fix += disp_size + inst_size;
937 fragP->fr_var = 0;
938 break;
939 case C (UNCOND_BRANCH, UNDEF_WORD_DISP):
940 buffer[0] = OP_BRL;
941 buffer[1] = 0;
942 buffer[2] = 0;
943 fix_new (fragP,
944 fragP->fr_fix + 1,
946 fragP->fr_symbol,
947 fragP->fr_offset,
949 R_W65_PCR16);
951 fragP->fr_fix += disp_size + inst_size;
952 fragP->fr_var = 0;
953 break;
954 default:
955 abort ();
957 if (inst_size)
959 /* Get the address of the end of the instruction. */
960 int next_inst = (fragP->fr_fix + fragP->fr_address
961 + disp_size + inst_size);
962 int targ_addr = (S_GET_VALUE (fragP->fr_symbol) +
963 fragP->fr_offset);
964 int disp = targ_addr - next_inst;
966 md_number_to_chars (buffer + inst_size, disp, disp_size);
967 fragP->fr_fix += disp_size + inst_size;
968 fragP->fr_var = 0;
972 valueT
973 md_section_align (seg, size)
974 segT seg;
975 valueT size;
977 return ((size + (1 << section_alignment[(int) seg]) - 1)
978 & (-1 << section_alignment[(int) seg]));
981 void
982 md_apply_fix (fixP, val)
983 fixS *fixP;
984 long val;
986 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
987 int addr = fixP->fx_frag->fr_address + fixP->fx_where;
989 if (fixP->fx_r_type == 0)
991 if (fixP->fx_size == 1)
992 fixP->fx_r_type = R_W65_ABS8;
993 else
994 fixP->fx_r_type = R_W65_ABS16;
997 switch (fixP->fx_r_type)
999 case R_W65_ABS8S16:
1000 val >>= 8;
1001 case R_W65_ABS8S8:
1002 val >>= 8;
1003 case R_W65_ABS8:
1004 *buf++ = val;
1005 break;
1006 case R_W65_ABS16S16:
1007 val >>= 8;
1008 case R_W65_ABS16S8:
1009 val >>= 8;
1010 case R_W65_ABS16:
1011 *buf++ = val >> 0;
1012 *buf++ = val >> 8;
1013 break;
1014 case R_W65_ABS24:
1015 *buf++ = val >> 0;
1016 *buf++ = val >> 8;
1017 *buf++ = val >> 16;
1018 break;
1019 case R_W65_PCR8:
1020 *buf++ = val - addr - 1;
1021 break;
1022 case R_W65_PCR16:
1023 val = val - addr - 1;
1024 *buf++ = val;
1025 *buf++ = val >> 8;
1026 break;
1027 case R_W65_DP:
1028 *buf++ = val;
1029 break;
1031 default:
1032 abort ();
1036 /* Put number into target byte order */
1038 void
1039 md_number_to_chars (ptr, use, nbytes)
1040 char *ptr;
1041 valueT use;
1042 int nbytes;
1044 number_to_chars_littleendian (ptr, use, nbytes);
1047 long
1048 md_pcrel_from (fixP)
1049 fixS *fixP;
1051 int gap = fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address - 1;
1052 return gap;
1055 void
1056 tc_coff_symbol_emit_hook (x)
1057 symbolS *x;
1061 short
1062 tc_coff_fix2rtype (fix_ptr)
1063 fixS *fix_ptr;
1065 return fix_ptr->fx_r_type;
1068 void
1069 tc_reloc_mangle (fix_ptr, intr, base)
1070 fixS *fix_ptr;
1071 struct internal_reloc *intr;
1072 bfd_vma base;
1075 symbolS *symbol_ptr;
1077 symbol_ptr = fix_ptr->fx_addsy;
1079 /* If this relocation is attached to a symbol then it's ok
1080 to output it */
1081 if (fix_ptr->fx_r_type == RELOC_32)
1083 /* cons likes to create reloc32's whatever the size of the reloc..
1085 switch (fix_ptr->fx_size)
1087 case 2:
1088 intr->r_type = R_IMM16;
1089 break;
1090 case 1:
1091 intr->r_type = R_IMM8;
1092 break;
1093 default:
1094 abort ();
1097 else
1099 if (fix_ptr->fx_size == 4)
1100 intr->r_type = R_W65_ABS24;
1101 else
1102 intr->r_type = fix_ptr->fx_r_type;
1105 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1106 intr->r_offset = fix_ptr->fx_offset;
1108 /* Turn the segment of the symbol into an offset. */
1109 if (symbol_ptr)
1111 symbolS *dot;
1113 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
1114 if (dot)
1116 intr->r_offset += S_GET_VALUE (symbol_ptr);
1117 intr->r_symndx = dot->sy_number;
1119 else
1121 intr->r_symndx = symbol_ptr->sy_number;
1124 else
1126 intr->r_symndx = -1;
1131 tc_coff_sizemachdep (frag)
1132 fragS *frag;
1134 return md_relax_table[frag->fr_subtype].rlx_length;
1137 /* Called just before address relaxation, return the length by which a
1138 fragment must grow to reach it's destination. */
1141 md_estimate_size_before_relax (fragP, segment_type)
1142 register fragS *fragP;
1143 register segT segment_type;
1145 int what;
1147 switch (fragP->fr_subtype)
1149 default:
1150 abort ();
1152 case C (COND_BRANCH, UNDEF_BYTE_DISP):
1153 case C (UNCOND_BRANCH, UNDEF_BYTE_DISP):
1154 what = GET_WHAT (fragP->fr_subtype);
1155 /* Used to be a branch to somewhere which was unknown. */
1156 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
1158 /* Got a symbol and it's defined in this segment, become byte
1159 sized - maybe it will fix up. */
1160 fragP->fr_subtype = C (what, BYTE_DISP);
1162 else
1164 /* Its got a segment, but its not ours, so it will always be
1165 long. */
1166 fragP->fr_subtype = C (what, UNDEF_WORD_DISP);
1168 break;
1170 case C (COND_BRANCH, BYTE_DISP):
1171 case C (COND_BRANCH, WORD_DISP):
1172 case C (COND_BRANCH, UNDEF_WORD_DISP):
1173 case C (UNCOND_BRANCH, BYTE_DISP):
1174 case C (UNCOND_BRANCH, WORD_DISP):
1175 case C (UNCOND_BRANCH, UNDEF_WORD_DISP):
1176 /* When relaxing a section for the second time, we don't need to
1177 do anything besides return the current size. */
1178 break;
1181 fragP->fr_var = md_relax_table[fragP->fr_subtype].rlx_length;
1182 return fragP->fr_var;
1185 CONST char *md_shortopts = "";
1186 struct option md_longopts[] = {
1187 #define OPTION_RELAX (OPTION_MD_BASE)
1188 {NULL, no_argument, NULL, 0}
1191 void
1192 md_show_usage (stream)
1193 FILE *stream;
1197 size_t md_longopts_size = sizeof (md_longopts);