Fix formatting
[deliverable/binutils-gdb.git] / gas / config / tc-w65.c
1 /* tc-w65.c -- Assemble code for the W65816
2 Copyright (C) 1995, 1998, 2000 Free Software Foundation.
3
4 This file is part of GAS, the GNU Assembler.
5
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.
10
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.
15
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. */
20
21 /* Written By Steve Chamberlain <sac@cygnus.com>. */
22
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>
30
31 const char comment_chars[] = "!";
32 CONST char line_separator_chars[] = ";";
33 const char line_comment_chars[] = "!#";
34
35 /* This table describes all the machine specific pseudo-ops the assembler
36 has to support. The fields are:
37
38 pseudo-op name without dot
39 function to call to execute this pseudo-op
40 Integer arg to pass to the function */
41
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
52
53 void s_longa ();
54 const pseudo_typeS md_pseudo_table[] =
55 {
56 {"int", cons, 2},
57 {"word", cons, 2},
58 {"longa", s_longa, 0},
59 {"longi", s_longa, 1},
60 {0, 0, 0}
61 };
62
63 void cons ();
64 void s_align_bytes ();
65
66 #if 0
67 int md_reloc_size;
68 #endif
69
70 static int relax; /* set if -relax seen */
71
72 const char EXP_CHARS[] = "eE";
73
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";
78
79 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
80
81 int M; /* M flag */
82 int X; /* X flag */
83
84 #define C(a,b) ENCODE_RELAX(a,b)
85 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
86
87 #define GET_WHAT(x) ((x>>2))
88
89 #define BYTE_DISP 1
90 #define WORD_DISP 2
91 #define UNDEF_BYTE_DISP 0
92 #define UNDEF_WORD_DISP 3
93
94 #define COND_BRANCH 1
95 #define UNCOND_BRANCH 2
96 #define END 3
97
98 #define BYTE_F 127 /* How far we can branch forwards */
99 #define BYTE_B -126 /* How far we can branch backwards */
100 #define WORD_F 32767
101 #define WORD_B 32768
102
103 relax_typeS md_relax_table[C (END, 0)];
104
105 /* This function is called once, at assembler startup time. This
106 should set up all the tables, etc that the MD part of the assembler
107 needs. */
108
109 void
110 s_longa (xmode)
111 {
112 int *p = xmode ? &X : &M;
113 while (*input_line_pointer == ' ')
114 input_line_pointer++;
115 if (strncmp (input_line_pointer, "on", 2) == 0)
116 {
117 input_line_pointer += 2;
118 *p = 0;
119 }
120 else if (strncmp (input_line_pointer, "off", 3) == 0)
121 {
122 *p = 1;
123 input_line_pointer += 3;
124 }
125 else
126 as_bad (_("need on or off."));
127 demand_empty_rest_of_line ();
128 }
129
130 void
131 md_begin ()
132 {
133 relax_typeS *table;
134 struct opinfo *opcode;
135 char *prev_name = "";
136
137 opcode_hash_control = hash_new ();
138
139 /* Insert unique names into hash table. */
140 for (opcode = optable; opcode->name; opcode++)
141 {
142 if (strcmp (prev_name, opcode->name))
143 {
144 prev_name = opcode->name;
145 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
146 }
147 else
148 {
149 /* Make all the opcodes with the same name point to the same
150 string. */
151 opcode->name = prev_name;
152 }
153 }
154
155 /* Initialize the relax table. We use a local variable to avoid
156 warnings about modifying a supposedly const data structure. */
157 table = (relax_typeS *) md_relax_table;
158 table[C (COND_BRANCH, BYTE_DISP)].rlx_forward = BYTE_F;
159 table[C (COND_BRANCH, BYTE_DISP)].rlx_backward = BYTE_B;
160 table[C (COND_BRANCH, BYTE_DISP)].rlx_length = 2;
161 table[C (COND_BRANCH, BYTE_DISP)].rlx_more = C (COND_BRANCH, WORD_DISP);
162
163 table[C (COND_BRANCH, WORD_DISP)].rlx_forward = WORD_F;
164 table[C (COND_BRANCH, WORD_DISP)].rlx_backward = WORD_B;
165 table[C (COND_BRANCH, WORD_DISP)].rlx_length = 5;
166 table[C (COND_BRANCH, WORD_DISP)].rlx_more = 0;
167
168 table[C (UNCOND_BRANCH, BYTE_DISP)].rlx_forward = BYTE_F;
169 table[C (UNCOND_BRANCH, BYTE_DISP)].rlx_backward = BYTE_B;
170 table[C (UNCOND_BRANCH, BYTE_DISP)].rlx_length = 2;
171 table[C (UNCOND_BRANCH, BYTE_DISP)].rlx_more = C (UNCOND_BRANCH, WORD_DISP);
172
173 table[C (UNCOND_BRANCH, WORD_DISP)].rlx_forward = WORD_F;
174 table[C (UNCOND_BRANCH, WORD_DISP)].rlx_backward = WORD_B;
175 table[C (UNCOND_BRANCH, WORD_DISP)].rlx_length = 3;
176 table[C (UNCOND_BRANCH, WORD_DISP)].rlx_more = 0;
177
178 flag_signed_overflow_ok = 1;
179 }
180
181 static expressionS immediate; /* absolute expression */
182 static expressionS immediate1; /* absolute expression */
183
184 static symbolS *
185 dot ()
186 {
187 const char *fake;
188
189 /* JF: '.' is pseudo symbol with value of current location
190 in current segment. */
191 fake = FAKE_LABEL_NAME;
192 return symbol_new (fake,
193 now_seg,
194 (valueT) frag_now_fix (),
195 frag_now);
196
197 }
198
199 int expr_size;
200 int expr_shift;
201 int tc_cons_reloc;
202
203 void
204 w65_expression (dest, bytes)
205 expressionS *dest;
206 unsigned int bytes;
207 {
208 expr_size = 0;
209 expr_shift = 0;
210 tc_cons_reloc = 0;
211 while (*input_line_pointer == ' ')
212 input_line_pointer++;
213
214 if (*input_line_pointer == '<')
215 {
216 expr_size = 1;
217 input_line_pointer++;
218 }
219 else if (*input_line_pointer == '>')
220 {
221 expr_shift = 1;
222 input_line_pointer++;
223 }
224 else if (*input_line_pointer == '^')
225 {
226 expr_shift = 2;
227 input_line_pointer++;
228 }
229
230 expr (0, dest);
231 }
232
233 int amode;
234
235 static char *
236 parse_exp (s, bytes)
237 char *s;
238 int bytes;
239 {
240 char *save;
241 char *new;
242
243 save = input_line_pointer;
244 input_line_pointer = s;
245 w65_expression (&immediate, bytes);
246 if (immediate.X_op == O_absent)
247 as_bad (_("missing operand"));
248 new = input_line_pointer;
249 input_line_pointer = save;
250 return new;
251 }
252
253 static char *
254 get_operands (info, ptr)
255 struct opinfo *info;
256 char *ptr;
257 {
258 register int override_len = 0;
259 register int bytes = 0;
260
261 while (*ptr == ' ')
262 ptr++;
263
264 if (ptr[0] == '#')
265 {
266 ptr++;
267 switch (info->amode)
268 {
269 case ADDR_IMMTOI:
270 bytes = X ? 1 : 2;
271 amode = ADDR_IMMTOI;
272 break;
273 case ADDR_IMMTOA:
274 bytes = M ? 1 : 2;
275 amode = ADDR_IMMTOA;
276 break;
277 case ADDR_IMMCOP:
278 bytes = 1;
279 amode = ADDR_IMMCOP;
280 break;
281 case ADDR_DIR:
282 bytes = 2;
283 amode = ADDR_ABS;
284 break;
285 default:
286 abort ();
287 break;
288 }
289 ptr = parse_exp (ptr);
290 }
291 else if (ptr[0] == '!')
292 {
293 ptr = parse_exp (ptr + 1);
294 if (ptr[0] == ',')
295 {
296 if (ptr[1] == 'y')
297 {
298 amode = ADDR_ABS_IDX_Y;
299 bytes = 2;
300 ptr += 2;
301 }
302 else if (ptr[1] == 'x')
303 {
304 amode = ADDR_ABS_IDX_X;
305 bytes = 2;
306 ptr += 2;
307 }
308 else
309 {
310 as_bad (_("syntax error after <exp"));
311 }
312 }
313 else
314 {
315 amode = ADDR_ABS;
316 bytes = 2;
317 }
318 }
319 else if (ptr[0] == '>')
320 {
321 ptr = parse_exp (ptr + 1);
322 if (ptr[0] == ',' && ptr[1] == 'x')
323 {
324 amode = ADDR_ABS_LONG_IDX_X;
325 bytes = 3;
326 ptr += 2;
327 }
328 else
329 {
330 amode = ADDR_ABS_LONG;
331 bytes = 3;
332 }
333 }
334 else if (ptr[0] == '<')
335 {
336 ptr = parse_exp (ptr + 1);
337 if (ptr[0] == ',')
338 {
339 if (ptr[1] == 'y')
340 {
341 amode = ADDR_DIR_IDX_Y;
342 ptr += 2;
343 bytes = 2;
344 }
345 else if (ptr[1] == 'x')
346 {
347 amode = ADDR_DIR_IDX_X;
348 ptr += 2;
349 bytes = 2;
350 }
351 else
352 {
353 as_bad (_("syntax error after <exp"));
354 }
355 }
356 else
357 {
358 amode = ADDR_DIR;
359 bytes = 1;
360 }
361 }
362 else if (ptr[0] == 'a')
363 {
364 amode = ADDR_ACC;
365 }
366 else if (ptr[0] == '(')
367 {
368 /* Look for (exp),y
369 (<exp),y
370 (exp,x)
371 (<exp,x)
372 (exp)
373 (!exp)
374 (exp)
375 (<exp)
376 (exp,x)
377 (!exp,x)
378 (exp,s)
379 (exp,s),y */
380
381 ptr++;
382 if (ptr[0] == '<')
383 {
384 override_len = 1;
385 ptr++;
386 }
387 else if (ptr[0] == '!')
388 {
389 override_len = 2;
390 ptr++;
391 }
392 else if (ptr[0] == '>')
393 {
394 override_len = 3;
395 ptr++;
396 }
397 else
398 {
399 override_len = 0;
400 }
401 ptr = parse_exp (ptr);
402
403 if (ptr[0] == ',')
404 {
405 ptr++;
406 if (ptr[0] == 'x' && ptr[1] == ')')
407 {
408 ptr += 2;
409
410 if (override_len == 1)
411 {
412 amode = ADDR_DIR_IDX_IND_X;
413 bytes = 2;
414 }
415 else
416 {
417 amode = ADDR_ABS_IND_IDX;
418 bytes = 2;
419 }
420 }
421 else if (ptr[0] == 's' && ptr[1] == ')'
422 && ptr[2] == ',' && ptr[3] == 'y')
423 {
424 amode = ADDR_STACK_REL_INDX_IDX;
425 bytes = 1;
426 ptr += 4;
427 }
428 }
429 else if (ptr[0] == ')')
430 {
431 if (ptr[1] == ',' && ptr[2] == 'y')
432 {
433 amode = ADDR_DIR_IND_IDX_Y;
434 ptr += 3;
435 bytes = 2;
436 }
437 else
438 {
439 if (override_len == 1)
440 {
441 amode = ADDR_DIR_IND;
442 bytes = 1;
443 }
444 else
445 {
446 amode = ADDR_ABS_IND;
447 bytes = 2;
448 }
449 ptr++;
450
451 }
452 }
453 }
454 else if (ptr[0] == '[')
455 {
456 ptr = parse_exp (ptr + 1);
457 if (ptr[0] == ']')
458 {
459 ptr++;
460 if (ptr[0] == ',' && ptr[1] == 'y')
461 {
462 bytes = 1;
463 amode = ADDR_DIR_IND_IDX_Y_LONG;
464 ptr += 2;
465 }
466 else
467 {
468 if (info->code == O_jmp)
469 {
470 bytes = 2;
471 amode = ADDR_ABS_IND_LONG;
472 }
473 else
474 {
475 bytes = 1;
476 amode = ADDR_DIR_IND_LONG;
477 }
478 }
479 }
480 }
481 else
482 {
483 ptr = parse_exp (ptr, 2);
484 if (ptr[0] == ',')
485 {
486 if (ptr[1] == 'y')
487 {
488 if (override_len == 1)
489 {
490 bytes = 1;
491 amode = ADDR_DIR_IDX_Y;
492 }
493 else
494 {
495 amode = ADDR_ABS_IDX_Y;
496 bytes = 2;
497 }
498 ptr += 2;
499 }
500 else if (ptr[1] == 'x')
501 {
502 if (override_len == 1)
503 {
504 amode = ADDR_DIR_IDX_X;
505 bytes = 1;
506 }
507 else
508 {
509 amode = ADDR_ABS_IDX_X;
510 bytes = 2;
511 }
512 ptr += 2;
513 }
514 else if (ptr[1] == 's')
515 {
516 bytes = 1;
517 amode = ADDR_STACK_REL;
518 ptr += 2;
519 }
520 else
521 {
522 bytes = 1;
523 immediate1 = immediate;
524 ptr = parse_exp (ptr + 1);
525 amode = ADDR_BLOCK_MOVE;
526 }
527 }
528 else
529 {
530 switch (info->amode)
531 {
532 case ADDR_PC_REL:
533 amode = ADDR_PC_REL;
534 bytes = 1;
535 break;
536 case ADDR_PC_REL_LONG:
537 amode = ADDR_PC_REL_LONG;
538 bytes = 2;
539 break;
540 default:
541 if (override_len == 1)
542 {
543 amode = ADDR_DIR;
544 bytes = 1;
545 }
546 else if (override_len == 3)
547 {
548 bytes = 3;
549 amode = ADDR_ABS_LONG;
550 }
551 else
552 {
553 amode = ADDR_ABS;
554 bytes = 2;
555 }
556 }
557 }
558 }
559
560 switch (bytes)
561 {
562 case 1:
563 switch (expr_shift)
564 {
565 case 0:
566 if (amode == ADDR_DIR)
567 tc_cons_reloc = R_W65_DP;
568 else
569 tc_cons_reloc = R_W65_ABS8;
570 break;
571 case 1:
572 tc_cons_reloc = R_W65_ABS8S8;
573 break;
574 case 2:
575 tc_cons_reloc = R_W65_ABS8S16;
576 break;
577 }
578 break;
579 case 2:
580 switch (expr_shift)
581 {
582 case 0:
583 tc_cons_reloc = R_W65_ABS16;
584 break;
585 case 1:
586 tc_cons_reloc = R_W65_ABS16S8;
587 break;
588 case 2:
589 tc_cons_reloc = R_W65_ABS16S16;
590 break;
591 }
592 }
593 return ptr;
594 }
595
596 /* Passed a pointer to a list of opcodes which use different
597 addressing modes, return the opcode which matches the opcodes
598 provided. */
599
600 static struct opinfo *
601 get_specific (opcode)
602 struct opinfo *opcode;
603 {
604 int ocode = opcode->code;
605
606 for (; opcode->code == ocode; opcode++)
607 {
608 if (opcode->amode == amode)
609 return opcode;
610 }
611 return 0;
612 }
613
614 int
615 check (operand, low, high)
616 expressionS *operand;
617 int low;
618 int high;
619 {
620 if (operand->X_op != O_constant
621 || operand->X_add_number < low
622 || operand->X_add_number > high)
623 {
624 as_bad ("operand must be absolute in range %d..%d", low, high);
625 }
626 return operand->X_add_number;
627 }
628
629 static int log2[] = { 0, 0, 1, 0, 2 };
630
631 /* Now we know what sort of opcodes it is, let's build the bytes. */
632
633 static void
634 build_Mytes (opcode)
635 struct opinfo *opcode;
636 {
637 int size;
638 int type;
639 int pcrel;
640 char *output;
641
642 if (opcode->amode == ADDR_IMPLIED)
643 {
644 output = frag_more (1);
645 }
646 else if (opcode->amode == ADDR_PC_REL)
647 {
648 int type;
649
650 /* This is a relaxable insn, so we do some special handling. */
651 type = opcode->val == OP_BRA ? UNCOND_BRANCH : COND_BRANCH;
652 output = frag_var (rs_machine_dependent,
653 md_relax_table[C (type, WORD_DISP)].rlx_length,
654 md_relax_table[C (type, BYTE_DISP)].rlx_length,
655 C (type, UNDEF_BYTE_DISP),
656 immediate.X_add_symbol,
657 immediate.X_add_number,
658 0);
659 }
660 else
661 {
662 switch (opcode->amode)
663 {
664 GETINFO (size, type, pcrel);
665 }
666
667 /* If something special was done in the expression modify the
668 reloc type. */
669 if (tc_cons_reloc)
670 type = tc_cons_reloc;
671
672 /* 1 byte for the opcode + the bytes for the addrmode. */
673 output = frag_more (size + 1);
674
675 if (opcode->amode == ADDR_BLOCK_MOVE)
676 {
677 /* Two relocs for this one. */
678 fix_new_exp (frag_now,
679 output + 1 - frag_now->fr_literal,
680 1,
681 &immediate,
682 0,
683 R_W65_ABS8S16);
684
685 fix_new_exp (frag_now,
686 output + 2 - frag_now->fr_literal,
687 1,
688 &immediate1,
689 0,
690 R_W65_ABS8S16);
691 }
692 else if (type >= 0
693 && opcode->amode != ADDR_IMPLIED
694 && opcode->amode != ADDR_ACC
695 && opcode->amode != ADDR_STACK)
696 {
697 fix_new_exp (frag_now,
698 output + 1 - frag_now->fr_literal,
699 size,
700 &immediate,
701 pcrel,
702 type);
703 }
704 }
705 output[0] = opcode->val;
706 }
707
708 /* This is the guts of the machine-dependent assembler. STR points to
709 a machine dependent instruction. This function is supposed to emit
710 the frags/bytes it assembles to. */
711
712 void
713 md_assemble (str)
714 char *str;
715 {
716 unsigned char *op_start;
717 unsigned char *op_end;
718 struct opinfo *opcode;
719 char name[20];
720 int nlen = 0;
721 char *p;
722
723 /* Drop leading whitespace */
724 while (*str == ' ')
725 str++;
726
727 /* all opcodes are three letters */
728 name[0] = str[0];
729 name[1] = str[1];
730 name[2] = str[2];
731 name[3] = 0;
732
733 tc_cons_reloc = 0;
734 str += 3;
735 opcode = (struct opinfo *) hash_find (opcode_hash_control, name);
736
737 if (opcode == NULL)
738 {
739 as_bad (_("unknown opcode"));
740 return;
741 }
742
743 if (opcode->amode != ADDR_IMPLIED
744 && opcode->amode != ADDR_STACK)
745 {
746 get_operands (opcode, str);
747 opcode = get_specific (opcode);
748 }
749
750 if (opcode == 0)
751 {
752 /* Couldn't find an opcode which matched the operands. */
753
754 char *where = frag_more (1);
755
756 where[0] = 0x0;
757 where[1] = 0x0;
758 as_bad (_("invalid operands for opcode"));
759 return;
760 }
761
762 build_Mytes (opcode);
763 }
764
765 void
766 tc_crawl_symbol_chain (headers)
767 object_headers *headers;
768 {
769 printf (_("call to tc_crawl_symbol_chain \n"));
770 }
771
772 symbolS *
773 md_undefined_symbol (name)
774 char *name;
775 {
776 return 0;
777 }
778
779 void
780 tc_headers_hook (headers)
781 object_headers *headers;
782 {
783 printf (_("call to tc_headers_hook \n"));
784 }
785
786 /* Various routines to kill one day. */
787 /* Equal to MAX_PRECISION in atof-ieee.c. */
788 #define MAX_LITTLENUMS 6
789
790 /* Turn a string in input_line_pointer into a floating point constant
791 of type TYPE, and store the appropriate bytes in *LITP. The number
792 of LITTLENUMS emitted is stored in *SIZEP. An error message is
793 returned, or NULL on OK. */
794
795 char *
796 md_atof (type, litP, sizeP)
797 char type;
798 char *litP;
799 int *sizeP;
800 {
801 int prec;
802 LITTLENUM_TYPE words[MAX_LITTLENUMS];
803 LITTLENUM_TYPE *wordP;
804 char *t;
805 char *atof_ieee ();
806
807 switch (type)
808 {
809 case 'f':
810 case 'F':
811 case 's':
812 case 'S':
813 prec = 2;
814 break;
815
816 case 'd':
817 case 'D':
818 case 'r':
819 case 'R':
820 prec = 4;
821 break;
822
823 case 'x':
824 case 'X':
825 prec = 6;
826 break;
827
828 case 'p':
829 case 'P':
830 prec = 6;
831 break;
832
833 default:
834 *sizeP = 0;
835 return _("Bad call to MD_NTOF()");
836 }
837 t = atof_ieee (input_line_pointer, type, words);
838 if (t)
839 input_line_pointer = t;
840
841 *sizeP = prec * sizeof (LITTLENUM_TYPE);
842 for (wordP = words + prec - 1; prec--;)
843 {
844 md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE));
845 litP += sizeof (LITTLENUM_TYPE);
846 }
847 return 0;
848 }
849
850 int
851 md_parse_option (c, a)
852 int c;
853 char *a;
854 {
855 return 1;
856 }
857
858 void
859 tc_Nout_fix_to_chars ()
860 {
861 printf (_("call to tc_Nout_fix_to_chars \n"));
862 abort ();
863 }
864
865 /* Called after relaxing, change the frags so they know how big they
866 are. */
867
868 void
869 md_convert_frag (headers, seg, fragP)
870 object_headers *headers;
871 segT seg;
872 fragS *fragP;
873 {
874 int disp_size = 0;
875 int inst_size = 0;
876 unsigned char *buffer =
877 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
878
879 switch (fragP->fr_subtype)
880 {
881 case C (COND_BRANCH, BYTE_DISP):
882 case C (UNCOND_BRANCH, BYTE_DISP):
883 disp_size = 1;
884 inst_size = 1;
885 break;
886
887 /* Conditional branches to a known 16 bit displacement. */
888 case C (COND_BRANCH, WORD_DISP):
889 switch (buffer[0])
890 {
891 case OP_BCC:
892 case OP_BCS:
893 case OP_BEQ:
894 case OP_BMI:
895 case OP_BNE:
896 case OP_BPL:
897 case OP_BVS:
898 case OP_BVC:
899 /* Invert the sense of the test */
900 buffer[0] ^= 0x20;
901 buffer[1] = 3; /* Jump over following brl */
902 buffer[2] = OP_BRL;
903 buffer[3] = 0;
904 buffer[4] = 0;
905 disp_size = 2;
906 inst_size = 3;
907 break;
908 default:
909 abort ();
910 }
911 break;
912 case C (UNCOND_BRANCH, WORD_DISP):
913 /* Unconditional branches to a known 16 bit displacement. */
914
915 switch (buffer[0])
916 {
917 case OP_BRA:
918 buffer[0] = OP_BRL;
919 disp_size = 2;
920 inst_size = 1;
921 break;
922 default:
923 abort ();
924 }
925 break;
926 /* Got to create a branch over a reloc here. */
927 case C (COND_BRANCH, UNDEF_WORD_DISP):
928 buffer[0] ^= 0x20; /* invert test */
929 buffer[1] = 3;
930 buffer[2] = OP_BRL;
931 buffer[3] = 0;
932 buffer[4] = 0;
933 fix_new (fragP,
934 fragP->fr_fix + 3,
935 4,
936 fragP->fr_symbol,
937 fragP->fr_offset,
938 0,
939 R_W65_PCR16);
940
941 fragP->fr_fix += disp_size + inst_size;
942 fragP->fr_var = 0;
943 break;
944 case C (UNCOND_BRANCH, UNDEF_WORD_DISP):
945 buffer[0] = OP_BRL;
946 buffer[1] = 0;
947 buffer[2] = 0;
948 fix_new (fragP,
949 fragP->fr_fix + 1,
950 4,
951 fragP->fr_symbol,
952 fragP->fr_offset,
953 0,
954 R_W65_PCR16);
955
956 fragP->fr_fix += disp_size + inst_size;
957 fragP->fr_var = 0;
958 break;
959 default:
960 abort ();
961 }
962 if (inst_size)
963 {
964 /* Get the address of the end of the instruction. */
965 int next_inst = (fragP->fr_fix + fragP->fr_address
966 + disp_size + inst_size);
967 int targ_addr = (S_GET_VALUE (fragP->fr_symbol) +
968 fragP->fr_offset);
969 int disp = targ_addr - next_inst;
970
971 md_number_to_chars (buffer + inst_size, disp, disp_size);
972 fragP->fr_fix += disp_size + inst_size;
973 fragP->fr_var = 0;
974 }
975 }
976
977 valueT
978 md_section_align (seg, size)
979 segT seg;
980 valueT size;
981 {
982 return ((size + (1 << section_alignment[(int) seg]) - 1)
983 & (-1 << section_alignment[(int) seg]));
984 }
985
986 void
987 md_apply_fix (fixP, val)
988 fixS *fixP;
989 long val;
990 {
991 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
992 int addr = fixP->fx_frag->fr_address + fixP->fx_where;
993
994 if (fixP->fx_r_type == 0)
995 {
996 if (fixP->fx_size == 1)
997 fixP->fx_r_type = R_W65_ABS8;
998 else
999 fixP->fx_r_type = R_W65_ABS16;
1000 }
1001
1002 switch (fixP->fx_r_type)
1003 {
1004 case R_W65_ABS8S16:
1005 val >>= 8;
1006 case R_W65_ABS8S8:
1007 val >>= 8;
1008 case R_W65_ABS8:
1009 *buf++ = val;
1010 break;
1011 case R_W65_ABS16S16:
1012 val >>= 8;
1013 case R_W65_ABS16S8:
1014 val >>= 8;
1015 case R_W65_ABS16:
1016 *buf++ = val >> 0;
1017 *buf++ = val >> 8;
1018 break;
1019 case R_W65_ABS24:
1020 *buf++ = val >> 0;
1021 *buf++ = val >> 8;
1022 *buf++ = val >> 16;
1023 break;
1024 case R_W65_PCR8:
1025 *buf++ = val - addr - 1;
1026 break;
1027 case R_W65_PCR16:
1028 val = val - addr - 1;
1029 *buf++ = val;
1030 *buf++ = val >> 8;
1031 break;
1032 case R_W65_DP:
1033 *buf++ = val;
1034 break;
1035
1036 default:
1037 abort ();
1038 }
1039 }
1040
1041 /* Put number into target byte order */
1042
1043 void
1044 md_number_to_chars (ptr, use, nbytes)
1045 char *ptr;
1046 valueT use;
1047 int nbytes;
1048 {
1049 number_to_chars_littleendian (ptr, use, nbytes);
1050 }
1051
1052 long
1053 md_pcrel_from (fixP)
1054 fixS *fixP;
1055 {
1056 int gap = fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address - 1;
1057 return gap;
1058 }
1059
1060 void
1061 tc_coff_symbol_emit_hook (x)
1062 symbolS *x;
1063 {
1064 }
1065
1066 short
1067 tc_coff_fix2rtype (fix_ptr)
1068 fixS *fix_ptr;
1069 {
1070 return fix_ptr->fx_r_type;
1071 }
1072
1073 void
1074 tc_reloc_mangle (fix_ptr, intr, base)
1075 fixS *fix_ptr;
1076 struct internal_reloc *intr;
1077 bfd_vma base;
1078
1079 {
1080 symbolS *symbol_ptr;
1081
1082 symbol_ptr = fix_ptr->fx_addsy;
1083
1084 /* If this relocation is attached to a symbol then it's ok
1085 to output it */
1086 if (fix_ptr->fx_r_type == RELOC_32)
1087 {
1088 /* cons likes to create reloc32's whatever the size of the reloc..
1089 */
1090 switch (fix_ptr->fx_size)
1091 {
1092 case 2:
1093 intr->r_type = R_IMM16;
1094 break;
1095 case 1:
1096 intr->r_type = R_IMM8;
1097 break;
1098 default:
1099 abort ();
1100 }
1101 }
1102 else
1103 {
1104 if (fix_ptr->fx_size == 4)
1105 intr->r_type = R_W65_ABS24;
1106 else
1107 intr->r_type = fix_ptr->fx_r_type;
1108 }
1109
1110 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1111 intr->r_offset = fix_ptr->fx_offset;
1112
1113 /* Turn the segment of the symbol into an offset. */
1114 if (symbol_ptr)
1115 {
1116 symbolS *dot;
1117
1118 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
1119 if (dot)
1120 {
1121 intr->r_offset += S_GET_VALUE (symbol_ptr);
1122 intr->r_symndx = dot->sy_number;
1123 }
1124 else
1125 {
1126 intr->r_symndx = symbol_ptr->sy_number;
1127 }
1128 }
1129 else
1130 {
1131 intr->r_symndx = -1;
1132 }
1133 }
1134
1135 int
1136 tc_coff_sizemachdep (frag)
1137 fragS *frag;
1138 {
1139 return md_relax_table[frag->fr_subtype].rlx_length;
1140 }
1141
1142 /* Called just before address relaxation, return the length by which a
1143 fragment must grow to reach it's destination. */
1144
1145 int
1146 md_estimate_size_before_relax (fragP, segment_type)
1147 register fragS *fragP;
1148 register segT segment_type;
1149 {
1150 int what = GET_WHAT (fragP->fr_subtype);
1151
1152 switch (fragP->fr_subtype)
1153 {
1154 default:
1155 abort ();
1156 case C (COND_BRANCH, UNDEF_BYTE_DISP):
1157 case C (UNCOND_BRANCH, UNDEF_BYTE_DISP):
1158 /* Used to be a branch to somewhere which was unknown. */
1159 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
1160 {
1161 /* Got a symbol and it's defined in this segment, become byte
1162 sized - maybe it will fix up. */
1163 fragP->fr_subtype = C (what, BYTE_DISP);
1164 fragP->fr_var = md_relax_table[C (what, BYTE_DISP)].rlx_length;
1165 }
1166 else
1167 {
1168 /* Its got a segment, but its not ours, so it will always be
1169 long. */
1170 fragP->fr_subtype = C (what, UNDEF_WORD_DISP);
1171 fragP->fr_var = md_relax_table[C (what, WORD_DISP)].rlx_length;
1172 return md_relax_table[C (what, WORD_DISP)].rlx_length;
1173 }
1174 }
1175 return fragP->fr_var;
1176 }
1177
1178 CONST char *md_shortopts = "";
1179 struct option md_longopts[] = {
1180 #define OPTION_RELAX (OPTION_MD_BASE)
1181 {NULL, no_argument, NULL, 0}
1182 };
1183
1184 void
1185 md_show_usage (stream)
1186 FILE *stream;
1187 {
1188 }
1189
1190 size_t md_longopts_size = sizeof (md_longopts);
This page took 0.058134 seconds and 5 git commands to generate.