36d28b34c858856f3805dbc5bbb25a41a98ff228
[deliverable/binutils-gdb.git] / gas / config / tc-z8k.c
1 /* tc-z8k.c -- Assemble code for the Zilog Z800N
2 Copyright (C) 1992 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
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21 /*
22 Written By Steve Chamberlain
23 sac@cygnus.com
24 */
25
26 #include <stdio.h>
27 #define DEFINE_TABLE
28 #include "../opcodes/z8k-opc.h"
29
30 #include "as.h"
31 #include "read.h"
32 #include "bfd.h"
33 #include <ctype.h>
34 #include "listing.h"
35
36 <<<<<<< tc-z8k.c
37 char comment_chars[]=
38 {'!', 0};
39 char line_separator_chars[]=
40 {';', 0};
41 =======
42 const char comment_chars[] = { '!',0 };
43 const char line_separator_chars[] = { ';' ,0};
44 const char line_comment_chars[] = "";
45 >>>>>>> 1.5
46
47 extern int machine ;
48 extern int coff_flags;
49 int segmented_mode;
50 int md_reloc_size;
51
52 /* This table describes all the machine specific pseudo-ops the assembler
53 has to support. The fields are:
54 pseudo-op name without dot
55 function to call to execute this pseudo-op
56 Integer arg to pass to the function
57 */
58
59 void cons ();
60
61
62 void
63 s_segm ()
64 {
65 segmented_mode = 1;
66 machine = bfd_mach_z8001;
67 coff_flags = F_Z8001;
68 }
69
70 void
71 s_unseg ()
72 {
73 segmented_mode = 0;
74 machine = bfd_mach_z8002;
75 coff_flags = F_Z8002;
76 }
77 const pseudo_typeS md_pseudo_table[]=
78 {
79 {"int", cons, 2},
80 {"data.b", cons, 1},
81 {"data.w", cons, 2},
82 {"data.l", cons, 4},
83 {"form", listing_psize, 0},
84 {"heading", listing_title, 0},
85 {"import", s_ignore, 0},
86 {"page", listing_eject, 0},
87 {"program", s_ignore, 0},
88 {"z8001", s_segm, 0},
89 {"z8002", s_unseg, 0},
90 {0, 0, 0}
91 };
92
93
94 const char EXP_CHARS[]= "eE";
95
96 /* Chars that mean this number is a floating point constant */
97 /* As in 0f12.456 */
98 /* or 0d1.2345e12 */
99 <<<<<<< tc-z8k.c
100 char FLT_CHARS[]= "rRsSfFdDxXpP";
101 =======
102 const char FLT_CHARS[] = "rRsSfFdDxXpP";
103 >>>>>>> 1.5
104
105
106 const relax_typeS md_relax_table[1];
107
108
109 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
110
111
112
113 void
114 md_begin ()
115 {
116 opcode_entry_type *opcode;
117 char *prev_name = "";
118 int idx = 0;
119
120 opcode_hash_control = hash_new ();
121
122
123 for (opcode = z8k_table; opcode->name; opcode++)
124 {
125 /* Only enter unique codes into the table */
126 char *src = opcode->name;
127
128 if (strcmp (opcode->name, prev_name))
129 {
130 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
131 idx++;
132 }
133 opcode->idx = idx;
134 prev_name = opcode->name;
135 }
136
137 /* default to z8002 */
138 s_unseg();
139 }
140
141
142 struct z8k_exp
143 {
144 char *e_beg;
145 char *e_end;
146 expressionS e_exp;
147 };
148 typedef struct z8k_op
149 {
150 char regsize; /* 'b','w','r','q' */
151 unsigned int reg; /* 0..15 */
152
153 int mode;
154
155 unsigned int x_reg; /* any other register associated with the mode */
156 expressionS exp; /* any expression */
157 } op_type;
158
159
160
161 static expressionS *da_operand;
162 static expressionS *imm_operand;
163
164
165 int reg[16];
166 int the_cc;
167
168 char *
169 DEFUN (whatreg, (reg, src),
170 int *reg AND
171 char *src)
172 {
173 if (isdigit (src[1]))
174 {
175 *reg = (src[0] - '0') * 10 + src[1] - '0';
176 return src + 2;
177 }
178 else
179 {
180 *reg = (src[0] - '0');
181 return src + 1;
182 }
183 }
184
185 /*
186 parse operands
187
188 rh0-rh7, rl0-rl7
189 r0-r15
190 rr0-rr14
191 rq0--rq12
192 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
193 r0l,r0h,..r7l,r7h
194 @WREG
195 @WREG+
196 @-WREG
197 #const
198
199 */
200
201
202 /* try and parse a reg name, returns number of chars consumed */
203 char *
204 DEFUN (parse_reg, (src, mode, reg),
205 char *src AND
206 int *mode AND
207 unsigned int *reg)
208 {
209 char *res = 0;
210
211 if (src[0] == 'r')
212 {
213 if (src[1] == 'r')
214 {
215 *mode = CLASS_REG_LONG;
216 res = whatreg (reg, src + 2);
217 }
218 else if (src[1] == 'h')
219 {
220 *mode = CLASS_REG_BYTE;
221 res = whatreg (reg, src + 2);
222 }
223 else if (src[1] == 'l')
224 {
225 *mode = CLASS_REG_BYTE;
226 res = whatreg (reg, src + 2) ;
227 *reg += 8;
228 }
229 else if (src[1] == 'q')
230 {
231 *mode = CLASS_REG_QUAD;
232 res = whatreg (reg, src + 2);
233 }
234 else
235 {
236 *mode = CLASS_REG_WORD;
237 res = whatreg (reg, src + 1);
238 }
239 }
240 return res;
241
242
243 }
244
245 char *
246 DEFUN (parse_exp, (s, op),
247 char *s AND
248 expressionS * op)
249 {
250 char *save = input_line_pointer;
251 char *new;
252 segT seg;
253
254 input_line_pointer = s;
255 seg = expr (0, op);
256 new = input_line_pointer;
257 input_line_pointer = save;
258 if (SEG_NORMAL (seg))
259 return new;
260 switch (seg)
261 {
262 case SEG_ABSOLUTE:
263 case SEG_UNKNOWN:
264 case SEG_DIFFERENCE:
265 case SEG_BIG:
266 case SEG_REGISTER:
267 return new;
268 case SEG_ABSENT:
269 as_bad ("Missing operand");
270 return new;
271 default:
272 as_bad ("Don't understand operand of type %s", segment_name (seg));
273 return new;
274 }
275 }
276
277 /* The many forms of operand:
278
279 <rb>
280 <r>
281 <rr>
282 <rq>
283 @r
284 #exp
285 exp
286 exp(r)
287 r(#exp)
288 r(r)
289
290
291
292 */
293
294 static
295 char *
296 DEFUN (checkfor, (ptr, what),
297 char *ptr AND
298 char what)
299 {
300 if (*ptr == what)
301 ptr++;
302 else
303 {
304 as_bad ("expected %c", what);
305 }
306 return ptr;
307 }
308
309 /* Make sure the mode supplied is the size of a word */
310 static void
311 DEFUN (regword, (mode, string),
312 int mode AND
313 char *string)
314 {
315 int ok;
316
317 ok = CLASS_REG_WORD;
318 if (ok != mode)
319 {
320 as_bad ("register is wrong size for a word %s", string);
321 }
322 }
323
324 /* Make sure the mode supplied is the size of an address */
325 static void
326 DEFUN (regaddr, (mode, string),
327 int mode AND
328 char *string)
329 {
330 int ok;
331
332 ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
333 if (ok != mode)
334 {
335 as_bad ("register is wrong size for address %s", string);
336 }
337 }
338
339 struct cc_names
340 {
341 int value;
342 char *name;
343
344
345 };
346
347 struct cc_names table[]=
348 {
349 0x0, "f",
350 0x1, "lt",
351 0x2, "le",
352 0x3, "ule",
353 0x4, "ov",
354 0x4, "pe",
355 0x5, "mi",
356 0x6, "eq",
357 0x6, "z",
358 0x7, "c",
359 0x7, "ult",
360 0x8, "t",
361 0x9, "ge",
362 0xa, "gt",
363 0xb, "ugt",
364 0xc, "nov",
365 0xc, "po",
366 0xd, "pl",
367 0xe, "ne",
368 0xe, "nz",
369 0xf, "nc",
370 0xf, "uge",
371 0, 0
372 };
373
374 static void
375 DEFUN (get_cc_operand, (ptr, mode, dst),
376 char **ptr AND
377 struct z8k_op *mode AND
378 unsigned int dst)
379 {
380 char *src = *ptr;
381 int r;
382 int i;
383
384 while (*src == ' ')
385 src++;
386
387 mode->mode = CLASS_CC;
388 for (i = 0; table[i].name; i++)
389 {
390 int j;
391
392 for (j = 0; table[i].name[j]; j++)
393 {
394 if (table[i].name[j] != src[j])
395 goto fail;
396 }
397 the_cc = table[i].value;
398 *ptr = src + j;
399 return;
400 fail:;
401 }
402 the_cc = 0x8;
403 return;
404 }
405
406 static void
407 DEFUN (get_operand, (ptr, mode, dst),
408 char **ptr AND
409 struct z8k_op *mode AND
410 unsigned int dst)
411 {
412 char *src = *ptr;
413 char *end;
414 unsigned int num;
415 unsigned int len;
416 unsigned int size;
417
418 mode->mode = 0;
419
420
421 while (*src == ' ')
422 src++;
423 if (*src == '#')
424 {
425 mode->mode = CLASS_IMM;
426 imm_operand = &(mode->exp);
427 src = parse_exp (src + 1, &(mode->exp));
428 }
429 else if (*src == '@')
430 {
431 int d;
432
433 mode->mode = CLASS_IR;
434 src = parse_reg (src + 1, &d, &mode->reg);
435 }
436 else
437 {
438 int regn;
439
440 end = parse_reg (src, &mode->mode, &regn);
441
442 if (end)
443 {
444 int nw, nr;
445
446 src = end;
447 if (*src == '(')
448 {
449 src++;
450 end = parse_reg (src, &nw, &nr);
451 if (end)
452 {
453 /* Got Ra(Rb) */
454 src = end;
455
456 if (*src != ')')
457 {
458 as_bad ("Missing ) in ra(rb)");
459 }
460 else
461 {
462 src++;
463 }
464
465 regaddr (mode->mode, "ra(rb) ra");
466 regword (mode->mode, "ra(rb) rb");
467 mode->mode = CLASS_BX;
468 mode->reg = regn;
469 mode->x_reg = nr;
470 reg[ARG_RX] = nr;
471 }
472 else
473 {
474 /* Got Ra(disp) */
475 if (*src == '#')
476 src++;
477 src = parse_exp (src, &(mode->exp));
478 src = checkfor (src, ')');
479 mode->mode = CLASS_BA;
480 mode->reg = regn;
481 mode->x_reg = 0;
482 imm_operand = &(mode->exp);
483 }
484 }
485 else
486 {
487 mode->reg = regn;
488 mode->x_reg = 0;
489 }
490 }
491 else
492 {
493 /* No initial reg */
494 src = parse_exp (src, &(mode->exp));
495 if (*src == '(')
496 {
497 src++;
498 end = parse_reg (src, &(mode->mode), &regn);
499 regword (mode->mode, "addr(Ra) ra");
500 mode->mode = CLASS_X;
501 mode->reg = regn;
502 mode->x_reg = 0;
503 da_operand = &(mode->exp);
504 src = checkfor (end, ')');
505 }
506 else
507 {
508 /* Just an address */
509 mode->mode = CLASS_DA;
510 mode->reg = 0;
511 mode->x_reg = 0;
512 da_operand = &(mode->exp);
513 }
514 }
515 }
516 *ptr = src;
517 }
518
519 static
520 char *
521 DEFUN (get_operands, (opcode, op_end, operand),
522 opcode_entry_type * opcode AND
523 char *op_end AND
524 op_type * operand)
525 {
526 char *ptr = op_end;
527
528 switch (opcode->noperands)
529 {
530 case 0:
531 operand[0].mode = 0;
532 operand[1].mode = 0;
533 break;
534
535 case 1:
536 ptr++;
537 if (opcode->arg_info[0] == CLASS_CC)
538 {
539 get_cc_operand (&ptr, operand + 0, 0);
540 }
541 else
542 {
543
544 get_operand (&ptr, operand + 0, 0);
545 }
546 operand[1].mode = 0;
547 break;
548
549 case 2:
550 ptr++;
551 if (opcode->arg_info[0] == CLASS_CC)
552 {
553 get_cc_operand (&ptr, operand + 0, 0);
554 }
555 else
556 {
557
558 get_operand (&ptr, operand + 0, 0);
559 }
560 if (*ptr == ',')
561 ptr++;
562 get_operand (&ptr, operand + 1, 1);
563 break;
564
565 case 3:
566 ptr++;
567 get_operand (&ptr, operand + 0, 0);
568 if (*ptr == ',')
569 ptr++;
570 get_operand (&ptr, operand + 1, 1);
571 if (*ptr == ',')
572 ptr++;
573 get_operand (&ptr, operand + 2, 2);
574 break;
575
576 case 4:
577 ptr++;
578 get_operand (&ptr, operand + 0, 0);
579 if (*ptr == ',')
580 ptr++;
581 get_operand (&ptr, operand + 1, 1);
582 if (*ptr == ',')
583 ptr++;
584 get_operand (&ptr, operand + 2, 2);
585 if (*ptr == ',')
586 ptr++;
587 get_cc_operand (&ptr, operand + 3, 3);
588 break;
589 default:
590 abort ();
591 }
592
593
594 return ptr;
595 }
596
597 /* Passed a pointer to a list of opcodes which use different
598 addressing modes, return the opcode which matches the opcodes
599 provided
600 */
601
602
603
604
605 static
606 opcode_entry_type *
607 DEFUN (get_specific, (opcode, operands),
608 opcode_entry_type * opcode AND
609 op_type * operands)
610
611 {
612 opcode_entry_type *this_try = opcode;
613 int found = 0;
614 unsigned int noperands = opcode->noperands;
615
616 unsigned int dispreg;
617 unsigned int this_index = opcode->idx;
618
619 while (this_index == opcode->idx && !found)
620 {
621 unsigned int i;
622
623 this_try = opcode++;
624 for (i = 0; i < noperands; i++)
625 {
626 int mode = operands[i].mode;
627
628 if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK))
629 {
630 /* it could be an pc rel operand, if this is a da mode and
631 we like disps, then insert it */
632
633 if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP)
634 {
635 /* This is the case */
636 operands[i].mode = CLASS_DISP;
637 }
638 else if (mode == CLASS_BA && this_try->arg_info[i])
639 {
640 /* Can't think of a way to turn what we've been given into
641 something that's ok */
642 goto fail;
643 }
644 else goto fail;
645 }
646 switch (mode & CLASS_MASK)
647 {
648 default:
649 break;
650 case CLASS_X:
651 case CLASS_IR:
652 case CLASS_BA:
653 case CLASS_BX:
654 case CLASS_DISP:
655 case CLASS_REG:
656 case CLASS_REG_WORD:
657 case CLASS_REG_BYTE:
658 case CLASS_REG_QUAD:
659 case CLASS_REG_LONG:
660 case CLASS_REGN0:
661 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
662 break;
663 }
664 }
665
666 found = 1;
667 fail:;
668 }
669 if (found)
670 return this_try;
671 else
672 return 0;
673 }
674
675 static void
676 DEFUN (check_operand, (operand, width, string),
677 struct z8k_op *operand AND
678 unsigned int width AND
679 char *string)
680 {
681 if (operand->exp.X_add_symbol == 0
682 && operand->exp.X_subtract_symbol == 0)
683 {
684
685 /* No symbol involved, let's look at offset, it's dangerous if any of
686 the high bits are not 0 or ff's, find out by oring or anding with
687 the width and seeing if the answer is 0 or all fs*/
688 if ((operand->exp.X_add_number & ~width) != 0 &&
689 (operand->exp.X_add_number | width) != (~0))
690 {
691 as_warn ("operand %s0x%x out of range.", string, operand->exp.X_add_number);
692 }
693 }
694
695 }
696
697 static char buffer[20];
698
699 static void
700 DEFUN (newfix, (ptr, type, operand),
701 int ptr AND
702 int type AND
703 expressionS * operand)
704 {
705 if (operand->X_add_symbol
706 || operand->X_subtract_symbol
707 || operand->X_add_number)
708 {
709 fix_new (frag_now,
710 ptr,
711 1,
712 operand->X_add_symbol,
713 operand->X_subtract_symbol,
714 operand->X_add_number,
715 0,
716 type);
717 }
718 }
719
720 static char *
721 DEFUN (apply_fix,(ptr, type, operand, size),
722 char* ptr AND
723 int type AND
724 expressionS *operand AND
725 int size)
726 {
727 int n = operand->X_add_number;
728 operand->X_add_number = n;
729 newfix((ptr - buffer)/2, type, operand);
730 #if 1
731 switch (size) {
732 case 8: /* 8 nibbles == 32 bits */
733 *ptr++ = n>> 28;
734 *ptr++ = n>> 24;
735 *ptr++ = n>> 20;
736 *ptr++ = n>> 16;
737 case 4: /* 4 niblles == 16 bits */
738 *ptr++ = n >> 12;
739 *ptr++ = n >> 8;
740 case 2:
741 *ptr++ = n >> 4;
742 case 1:
743 *ptr++ = n >> 0;
744 break;
745 }
746 #endif
747 return ptr;
748
749 }
750
751
752 /* Now we know what sort of opcodes it is, lets build the bytes -
753 */
754 #define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
755 static void
756 DEFUN (build_bytes, (this_try, operand),
757 opcode_entry_type * this_try AND
758 struct z8k_op *operand)
759 {
760 unsigned int i;
761
762 int length;
763 char *output;
764 char *output_ptr = buffer;
765 char part;
766 int c;
767 char high;
768 int nib;
769 int nibble;
770 unsigned short *class_ptr;
771 frag_wane (frag_now);
772 frag_new (0);
773
774 memset (buffer, 20, 0);
775 class_ptr = this_try->byte_info;
776 top:;
777
778 for (nibble = 0; c = *class_ptr++; nibble++)
779 {
780
781 switch (c & CLASS_MASK)
782 {
783 default:
784
785 abort ();
786 case CLASS_ADDRESS:
787 /* Direct address, we don't cope with the SS mode right now */
788 if (segmented_mode)
789 {
790 output_ptr = apply_fix (output_ptr , R_DA | R_SEG, da_operand, 8);
791 }
792 else
793 {
794 output_ptr = apply_fix(output_ptr, R_DA, da_operand, 4);
795 }
796 da_operand = 0;
797 break;
798 case CLASS_DISP8:
799 /* pc rel 8 bit */
800 output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
801 da_operand = 0;
802
803 break;
804
805 case CLASS_CC:
806 *output_ptr++ = the_cc;
807 break;
808 case CLASS_BIT:
809 *output_ptr++ = c & 0xf;
810 break;
811 case CLASS_REGN0:
812 if (reg[c & 0xf] == 0)
813 {
814 as_bad ("can't use R0 here");
815 }
816 case CLASS_REG:
817 case CLASS_REG_BYTE:
818 case CLASS_REG_WORD:
819 case CLASS_REG_LONG:
820 case CLASS_REG_QUAD:
821 /* Insert bit mattern of
822 right reg */
823 *output_ptr++ = reg[c & 0xf];
824 break;
825 case CLASS_DISP:
826 output_ptr = apply_fix (output_ptr, R_DA, da_operand, 4);
827 da_operand = 0;
828 break;
829 case CLASS_IMM:
830 {
831 nib = 0;
832 switch (c & ARG_MASK)
833 {
834 case ARG_IMM4:
835 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
836 break;
837 case ARG_IMM4M1:
838 imm_operand->X_add_number--;
839 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
840 break;
841 case ARG_IMMNMINUS1:
842 imm_operand->X_add_number--;
843 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand,1);
844 break;
845 case ARG_NIM8:
846 imm_operand->X_add_number = -imm_operand->X_add_number;
847 case ARG_IMM8:
848 output_ptr = apply_fix (output_ptr , R_IMM8, imm_operand, 2);
849 break;
850
851
852 case ARG_IMM16:
853 output_ptr= apply_fix(output_ptr, R_DA, imm_operand, 4);
854 break;
855
856 case ARG_IMM32:
857 output_ptr = apply_fix (output_ptr, R_IMM32, imm_operand, 8);
858 break;
859
860 default:
861 abort ();
862 }
863 }
864 }
865 }
866
867 /* Copy from the nibble buffer into the frag */
868
869 {
870 int length = (output_ptr - buffer) / 2;
871 char *src = buffer;
872 char *fragp = frag_more (length);
873
874 while (src < output_ptr)
875 {
876 *fragp = (src[0] << 4) | src[1];
877 src += 2;
878 fragp++;
879 }
880
881
882 }
883
884 }
885
886 /* This is the guts of the machine-dependent assembler. STR points to a
887 machine dependent instruction. This funciton is supposed to emit
888 the frags/bytes it assembles to.
889 */
890
891
892
893 void
894 DEFUN (md_assemble, (str),
895 char *str)
896 {
897 char *op_start;
898 char *op_end;
899 unsigned int i;
900 struct z8k_op operand[3];
901 opcode_entry_type *opcode;
902 opcode_entry_type *prev_opcode;
903
904 char *dot = 0;
905 char c;
906
907 /* Drop leading whitespace */
908 while (*str == ' ')
909 str++;
910
911 /* find the op code end */
912 for (op_start = op_end = str;
913 *op_end != 0 && *op_end != ' ';
914 op_end++)
915 {
916 }
917
918 ;
919
920 if (op_end == op_start)
921 {
922 as_bad ("can't find opcode ");
923 }
924 c = *op_end;
925
926 *op_end = 0;
927
928 opcode = (opcode_entry_type *) hash_find (opcode_hash_control,
929 op_start);
930
931 if (opcode == NULL)
932 {
933 as_bad ("unknown opcode");
934 return;
935 }
936
937
938 input_line_pointer = get_operands (opcode, op_end,
939 operand);
940 *op_end = c;
941 prev_opcode = opcode;
942
943 opcode = get_specific (opcode, operand);
944
945 if (opcode == 0)
946 {
947 /* Couldn't find an opcode which matched the operands */
948 char *where = frag_more (2);
949
950 where[0] = 0x0;
951 where[1] = 0x0;
952
953 as_bad ("Can't find opcode to match operands");
954 return;
955 }
956
957 build_bytes (opcode, operand);
958 }
959
960 void
961 DEFUN (tc_crawl_symbol_chain, (headers),
962 object_headers * headers)
963 {
964 printf ("call to tc_crawl_symbol_chain \n");
965 }
966
967 symbolS *
968 DEFUN (md_undefined_symbol, (name),
969 char *name)
970 {
971 return 0;
972 }
973
974 void
975 DEFUN (tc_headers_hook, (headers),
976 object_headers * headers)
977 {
978 printf ("call to tc_headers_hook \n");
979 }
980
981 void
982 DEFUN_VOID (md_end)
983 {
984 }
985
986 /* Various routines to kill one day */
987 /* Equal to MAX_PRECISION in atof-ieee.c */
988 #define MAX_LITTLENUMS 6
989
990 /* Turn a string in input_line_pointer into a floating point constant of type
991 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
992 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
993 */
994 char *
995 md_atof (type, litP, sizeP)
996 char type;
997 char *litP;
998 int *sizeP;
999 {
1000 int prec;
1001 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1002 LITTLENUM_TYPE *wordP;
1003 char *t;
1004 char *atof_ieee ();
1005
1006 switch (type)
1007 {
1008 case 'f':
1009 case 'F':
1010 case 's':
1011 case 'S':
1012 prec = 2;
1013 break;
1014
1015 case 'd':
1016 case 'D':
1017 case 'r':
1018 case 'R':
1019 prec = 4;
1020 break;
1021
1022 case 'x':
1023 case 'X':
1024 prec = 6;
1025 break;
1026
1027 case 'p':
1028 case 'P':
1029 prec = 6;
1030 break;
1031
1032 default:
1033 *sizeP = 0;
1034 return "Bad call to MD_ATOF()";
1035 }
1036 t = atof_ieee (input_line_pointer, type, words);
1037 if (t)
1038 input_line_pointer = t;
1039
1040 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1041 for (wordP = words; prec--;)
1042 {
1043 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1044 litP += sizeof (LITTLENUM_TYPE);
1045 }
1046 return ""; /* Someone should teach Dean about null pointers */
1047 }
1048
1049 int
1050 md_parse_option (argP, cntP, vecP)
1051 char **argP;
1052 int *cntP;
1053 char ***vecP;
1054
1055 {
1056 return 0;
1057
1058 }
1059
1060 int md_short_jump_size;
1061
1062 void
1063 tc_aout_fix_to_chars ()
1064 {
1065 printf ("call to tc_aout_fix_to_chars \n");
1066 abort ();
1067 }
1068
1069 void
1070 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1071 char *ptr;
1072 long from_addr;
1073 long to_addr;
1074 fragS *frag;
1075 symbolS *to_symbol;
1076 {
1077 as_fatal ("failed sanity check.");
1078 }
1079
1080 void
1081 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1082 char *ptr;
1083 long from_addr, to_addr;
1084 fragS *frag;
1085 symbolS *to_symbol;
1086 {
1087 as_fatal ("failed sanity check.");
1088 }
1089
1090 void
1091 md_convert_frag (headers, fragP)
1092 object_headers *headers;
1093 fragS *fragP;
1094
1095 {
1096 printf ("call to md_convert_frag \n");
1097 abort ();
1098 }
1099
1100 long
1101 DEFUN (md_section_align, (seg, size),
1102 segT seg AND
1103 long size)
1104 {
1105 return ((size + (1 << section_alignment[(int) seg]) - 1) & (-1 << section_alignment[(int) seg]));
1106
1107 }
1108
1109 void
1110 md_apply_fix (fixP, val)
1111 fixS *fixP;
1112 long val;
1113 {
1114 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1115
1116 switch (fixP->fx_r_type)
1117 {
1118 case R_IMM4L:
1119 buf[0] = (buf[0] & 0xf0) | ((buf[0] + val) & 0xf);
1120 break;
1121
1122 case R_JR:
1123
1124 *buf++ = val;
1125 /* if (val != 0) abort();*/
1126 break;
1127
1128
1129 case R_IMM8:
1130 buf[0] += val;
1131 break;
1132 break;
1133 case R_DA:
1134 *buf++ = (val >> 8);
1135 *buf++ = val;
1136 break;
1137 case R_IMM32:
1138 *buf++ = (val >> 24);
1139 *buf++ = (val >> 16);
1140 *buf++ = (val >> 8);
1141 *buf++ = val;
1142 break;
1143 case R_DA | R_SEG:
1144 *buf++ = (val >> 16);
1145 *buf++ = 0x00;
1146 *buf++ = (val >> 8);
1147 *buf++ = val;
1148 break;
1149 default:
1150 abort ();
1151
1152 }
1153 }
1154
1155 void
1156 DEFUN (md_operand, (expressionP), expressionS * expressionP)
1157 {
1158 }
1159
1160 int md_long_jump_size;
1161 int
1162 md_estimate_size_before_relax (fragP, segment_type)
1163 register fragS *fragP;
1164 register segT segment_type;
1165 {
1166 printf ("call tomd_estimate_size_before_relax \n");
1167 abort ();
1168 }
1169
1170 /* Put number into target byte order */
1171
1172 void
1173 DEFUN (md_number_to_chars, (ptr, use, nbytes),
1174 char *ptr AND
1175 long use AND
1176 int nbytes)
1177 {
1178 switch (nbytes)
1179 {
1180 case 4:*ptr++ = (use >> 24) & 0xff;
1181 case 3:
1182 *ptr++ = (use >> 16) & 0xff;
1183 case 2:
1184 *ptr++ = (use >> 8) & 0xff;
1185 case 1:
1186 *ptr++ = (use >> 0) & 0xff;
1187 break;
1188 default:
1189 abort ();
1190 }
1191 }
1192 long
1193 md_pcrel_from (fixP)
1194 fixS *fixP;
1195 {
1196 abort ();
1197 }
1198
1199 void
1200 tc_coff_symbol_emit_hook ()
1201 {
1202 }
1203
1204
1205 void
1206 tc_reloc_mangle (fix_ptr, intr, base)
1207 fixS *fix_ptr;
1208 struct internal_reloc *intr;
1209 bfd_vma base;
1210
1211 {
1212 symbolS *symbol_ptr;
1213
1214 symbol_ptr = fix_ptr->fx_addsy;
1215
1216 /* If this relocation is attached to a symbol then it's ok
1217 to output it */
1218 if (fix_ptr->fx_r_type == 0)
1219 {
1220 /* cons likes to create reloc32's whatever the size of the reloc..
1221 */
1222 switch (fix_ptr->fx_size)
1223 {
1224
1225 case 2:
1226 intr->r_type = R_DA;
1227 break;
1228 case 1:
1229 intr->r_type = R_IMM8;
1230 break;
1231 default:
1232 abort ();
1233
1234 }
1235
1236 }
1237 else
1238 {
1239 intr->r_type = fix_ptr->fx_r_type;
1240 }
1241
1242 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1243 intr->r_offset = fix_ptr->fx_offset;
1244
1245 if (symbol_ptr)
1246 intr->r_symndx = symbol_ptr->sy_number;
1247 else
1248 intr->r_symndx = -1;
1249
1250
1251 }
This page took 0.058208 seconds and 4 git commands to generate.