1 /* ns32k.c -- Assemble on the National Semiconductor 32k series
2 Copyright 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /*#define SHOW_NUM 1*//* Uncomment for debugging. */
28 #include "opcode/ns32k.h"
33 #define IIF_ENTRIES 13 /* Number of entries in iif. */
34 #define PRIVATE_SIZE 256 /* Size of my garbage memory. */
36 #define DEFAULT -1 /* addr_mode returns this value when
37 plain constant or label is
40 #define IIF(ptr,a1,c1,e1,g1,i1,k1,m1,o1,q1,s1,u1) \
41 iif.iifP[ptr].type= a1; \
42 iif.iifP[ptr].size= c1; \
43 iif.iifP[ptr].object= e1; \
44 iif.iifP[ptr].object_adjust= g1; \
45 iif.iifP[ptr].pcrel= i1; \
46 iif.iifP[ptr].pcrel_adjust= k1; \
47 iif.iifP[ptr].im_disp= m1; \
48 iif.iifP[ptr].relax_substate= o1; \
49 iif.iifP[ptr].bit_fixP= q1; \
50 iif.iifP[ptr].addr_mode= s1; \
51 iif.iifP[ptr].bsr= u1;
53 #ifdef SEQUENT_COMPATABILITY
54 #define LINE_COMMENT_CHARS "|"
55 #define ABSOLUTE_PREFIX '@'
56 #define IMMEDIATE_PREFIX '#'
59 #ifndef LINE_COMMENT_CHARS
60 #define LINE_COMMENT_CHARS "#"
63 const char comment_chars
[] = "#";
64 const char line_comment_chars
[] = LINE_COMMENT_CHARS
;
65 const char line_separator_chars
[] = ";";
66 static int default_disp_size
= 4; /* Displacement size for external refs. */
68 #if !defined(ABSOLUTE_PREFIX) && !defined(IMMEDIATE_PREFIX)
69 #define ABSOLUTE_PREFIX '@' /* One or the other MUST be defined. */
74 signed char mode
; /* Addressing mode of operand (0-31). */
75 signed char scaled_mode
; /* Mode combined with scaled mode. */
76 char scaled_reg
; /* Register used in scaled+1 (1-8). */
77 char float_flag
; /* Set if R0..R7 was F0..F7 ie a
78 floating-point-register. */
79 char am_size
; /* Estimated max size of general addr-mode
81 char im_disp
; /* If im_disp==1 we have a displacement. */
82 char pcrel
; /* 1 if pcrel, this is really redundant info. */
83 char disp_suffix
[2]; /* Length of displacement(s), 0=undefined. */
84 char *disp
[2]; /* Pointer(s) at displacement(s)
85 or immediates(s) (ascii). */
86 char index_byte
; /* Index byte. */
88 typedef struct addr_mode addr_modeS
;
90 char *freeptr
, *freeptr_static
; /* Points at some number of free bytes. */
91 struct hash_control
*inst_hash_handle
;
93 struct ns32k_opcode
*desc
; /* Pointer at description of instruction. */
94 addr_modeS addr_modeP
;
95 const char EXP_CHARS
[] = "eE";
96 const char FLT_CHARS
[] = "fd"; /* We don't want to support lowercase,
99 /* UPPERCASE denotes live names when an instruction is built, IIF is
100 used as an intermediate form to store the actual parts of the
101 instruction. A ns32k machine instruction can be divided into a
102 couple of sub PARTs. When an instruction is assembled the
103 appropriate PART get an assignment. When an IIF has been completed
104 it is converted to a FRAGment as specified in AS.H. */
106 /* Internal structs. */
116 int type
; /* How to interpret object. */
117 int size
; /* Estimated max size of object. */
118 unsigned long object
; /* Binary data. */
119 int object_adjust
; /* Number added to object. */
120 int pcrel
; /* True if object is pcrel. */
121 int pcrel_adjust
; /* Length in bytes from the instruction
122 start to the displacement. */
123 int im_disp
; /* True if the object is a displacement. */
124 relax_substateT relax_substate
; /* Initial relaxsubstate. */
125 bit_fixS
*bit_fixP
; /* Pointer at bit_fix struct. */
126 int addr_mode
; /* What addrmode do we associate with this
128 char bsr
; /* Sequent hack. */
129 } iif_entryT
; /* Internal Instruction Format. */
133 int instr_size
; /* Max size of instruction in bytes. */
134 iif_entryT iifP
[IIF_ENTRIES
+ 1];
137 struct int_ins_form iif
;
139 char *input_line_pointer
;
141 /* Description of the PARTs in IIF
143 0 total length in bytes of entries in iif
156 For every entry there is a datalength in bytes. This is stored in size[n].
157 0, the objectlength is not explicitly given by the instruction
158 and the operand is undefined. This is a case for relaxation.
159 Reserve 4 bytes for the final object.
161 1, the entry contains one byte
162 2, the entry contains two bytes
163 3, the entry contains three bytes
164 4, the entry contains four bytes
167 Furthermore, every entry has a data type identifier in type[n].
169 0, the entry is void, ignore it.
170 1, the entry is a binary number.
171 2, the entry is a pointer at an expression.
172 Where expression may be as simple as a single '1',
173 and as complicated as foo-bar+12,
174 foo and bar may be undefined but suffixed by :{b|w|d} to
175 control the length of the object.
177 3, the entry is a pointer at a bignum struct
179 The low-order-byte coresponds to low physical memory.
180 Obviously a FRAGment must be created for each valid disp in PART whose
181 datalength is undefined (to bad) .
182 The case where just the expression is undefined is less severe and is
183 handled by fix. Here the number of bytes in the objectfile is known.
184 With this representation we simplify the assembly and separates the
185 machine dependent/independent parts in a more clean way (said OE). */
187 struct ns32k_option opt1
[] = /* restore, exit. */
199 struct ns32k_option opt2
[] = /* save, enter. */
211 struct ns32k_option opt3
[] = /* setcfg. */
219 struct ns32k_option opt4
[] = /* cinv. */
226 struct ns32k_option opt5
[] = /* String inst. */
233 struct ns32k_option opt6
[] = /* Plain reg ext,cvtp etc. */
246 #if !defined(NS32032) && !defined(NS32532)
250 struct ns32k_option cpureg_532
[] = /* lpr spr. */
263 {"intbase", 0xe, 0xff},
267 struct ns32k_option mmureg_532
[] = /* lmr smr. */
274 {"ivar0", 0xe, 0xff},
275 {"ivar1", 0xf, 0xff},
279 struct ns32k_option cpureg_032
[] = /* lpr spr. */
286 {"intbase", 0xe, 0xff},
290 struct ns32k_option mmureg_032
[] = /* lmr smr. */
306 struct ns32k_option
*cpureg
= cpureg_532
;
307 struct ns32k_option
*mmureg
= mmureg_532
;
309 struct ns32k_option
*cpureg
= cpureg_032
;
310 struct ns32k_option
*mmureg
= mmureg_032
;
314 const pseudo_typeS md_pseudo_table
[] =
315 { /* So far empty. */
319 #define IND(x,y) (((x)<<2)+(y))
321 /* Those are index's to relax groups in md_relax_table ie it must be
322 multiplied by 4 to point at a group start. Viz IND(x,y) Se function
323 relax_segment in write.c for more info. */
328 /* Those are index's to entries in a relax group. */
334 /* Those limits are calculated from the displacement start in memory.
335 The ns32k uses the begining of the instruction as displacement
336 base. This type of displacements could be handled here by moving
337 the limit window up or down. I choose to use an internal
338 displacement base-adjust as there are other routines that must
339 consider this. Also, as we have two various offset-adjusts in the
340 ns32k (acb versus br/brs/jsr/bcond), two set of limits would have
341 had to be used. Now we dont have to think about that. */
343 const relax_typeS md_relax_table
[] =
350 {(63), (-64), 1, IND (BRANCH
, WORD
)},
351 {(8192), (-8192), 2, IND (BRANCH
, DOUBLE
)},
356 /* Array used to test if mode contains displacements.
357 Value is true if mode contains displacement. */
360 {0, 0, 0, 0, 0, 0, 0, 0,
361 1, 1, 1, 1, 1, 1, 1, 1,
362 1, 1, 1, 0, 0, 1, 1, 0,
363 1, 1, 1, 1, 1, 1, 1, 1};
365 /* Array used to calculate max size of displacements. */
370 static void evaluate_expr
PARAMS ((expressionS
* resultP
, char *));
371 static void md_number_to_disp
PARAMS ((char *, long, int));
372 static void md_number_to_imm
PARAMS ((char *, long, int));
373 static void md_number_to_field
PARAMS ((char *, long, bit_fixS
*));
375 /* Parse a general operand into an addressingmode struct
377 In: pointer at operand in ascii form
378 pointer at addr_mode struct for result
379 the level of recursion. (always 0 or 1)
381 Out: data in addr_mode struct. */
383 static int addr_mode
PARAMS ((char *, addr_modeS
*, int));
386 addr_mode (operand
, addr_modeP
, recursive_level
)
388 addr_modeS
*addr_modeP
;
397 mode
= DEFAULT
; /* Default. */
398 addr_modeP
->scaled_mode
= 0; /* Why not. */
399 addr_modeP
->scaled_reg
= 0; /* If 0, not scaled index. */
400 addr_modeP
->float_flag
= 0;
401 addr_modeP
->am_size
= 0;
402 addr_modeP
->im_disp
= 0;
403 addr_modeP
->pcrel
= 0; /* Not set in this function. */
404 addr_modeP
->disp_suffix
[0] = 0;
405 addr_modeP
->disp_suffix
[1] = 0;
406 addr_modeP
->disp
[0] = NULL
;
407 addr_modeP
->disp
[1] = NULL
;
417 /* The following three case statements controls the mode-chars
418 this is the place to ed if you want to change them. */
419 #ifdef ABSOLUTE_PREFIX
420 case ABSOLUTE_PREFIX
:
421 if (str
[strl
- 1] == ']')
423 addr_modeP
->mode
= 21; /* absolute */
424 addr_modeP
->disp
[0] = str
+ 1;
427 #ifdef IMMEDIATE_PREFIX
428 case IMMEDIATE_PREFIX
:
429 if (str
[strl
- 1] == ']')
431 addr_modeP
->mode
= 20; /* immediate */
432 addr_modeP
->disp
[0] = str
+ 1;
436 if (str
[strl
- 1] != ']')
442 if (str
[2] != '\000')
444 addr_modeP
->mode
= 27; /* pc-relativ */
445 addr_modeP
->disp
[0] = str
+ 2;
449 as_bad (_("Invalid syntax in PC-relative addressing mode"));
455 if (str
[strl
- 1] != ']')
457 if ((!strncmp (str
, "ext(", 4)) && strl
> 7)
459 addr_modeP
->disp
[0] = str
+ 4;
463 { /* disp[0]'s termination point. */
470 while (j
< strl
&& i
!= 0);
471 if (i
!= 0 || !(str
[j
+ 1] == '-' || str
[j
+ 1] == '+'))
473 as_bad (_("Invalid syntax in External addressing mode"));
476 str
[j
] = '\000'; /* null terminate disp[0] */
477 addr_modeP
->disp
[1] = str
+ j
+ 2;
478 addr_modeP
->mode
= 22;
496 addr_modeP
->float_flag
= 1;
499 if (str
[1] >= '0' && str
[1] < '8')
501 addr_modeP
->mode
= str
[1] - '0';
511 if (!strncmp (str
, "tos", 3))
513 addr_modeP
->mode
= 23; /* TopOfStack */
524 if (str
[strl
- 1] == ')')
526 if (str
[strl
- 2] == ')')
528 if (!strncmp (&str
[strl
- 5], "(fp", 3))
529 mode
= 16; /* Memory Relative. */
530 else if (!strncmp (&str
[strl
- 5], "(sp", 3))
532 else if (!strncmp (&str
[strl
- 5], "(sb", 3))
537 /* Memory relative. */
538 addr_modeP
->mode
= mode
;
539 j
= strl
- 5; /* Temp for end of disp[0]. */
545 if (str
[strl
] == ')')
547 if (str
[strl
] == '(')
550 while (strl
> -1 && i
!= 0);
554 as_bad (_("Invalid syntax in Memory Relative addressing mode"));
558 addr_modeP
->disp
[1] = str
;
559 addr_modeP
->disp
[0] = str
+ strl
+ 1;
560 str
[j
] = '\000'; /* Null terminate disp[0] . */
561 str
[strl
] = '\000'; /* Null terminate disp[1]. */
567 switch (str
[strl
- 3])
571 if (str
[strl
- 2] >= '0'
572 && str
[strl
- 2] < '8'
573 && str
[strl
- 4] == '(')
575 addr_modeP
->mode
= str
[strl
- 2] - '0' + 8;
576 addr_modeP
->disp
[0] = str
;
578 return -1; /* reg rel */
583 if (!strncmp (&str
[strl
- 4], "(fp", 3))
585 else if (!strncmp (&str
[strl
- 4], "(sp", 3))
587 else if (!strncmp (&str
[strl
- 4], "(sb", 3))
589 else if (!strncmp (&str
[strl
- 4], "(pc", 3))
594 addr_modeP
->mode
= mode
;
595 addr_modeP
->disp
[0] = str
;
596 str
[strl
- 4] = '\0';
598 return -1; /* Memory space. */
603 /* No trailing ')' do we have a ']' ? */
604 if (str
[strl
- 1] == ']')
606 switch (str
[strl
- 2])
621 as_bad (_("Invalid scaled-indexed mode, use (b,w,d,q)"));
623 if (str
[strl
- 3] != ':' || str
[strl
- 6] != '['
624 || str
[strl
- 5] == 'r' || str
[strl
- 4] < '0'
625 || str
[strl
- 4] > '7')
626 as_bad (_("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"));
627 } /* Scaled index. */
629 if (recursive_level
> 0)
631 as_bad (_("Scaled-indexed addressing mode combined with scaled-index"));
635 addr_modeP
->am_size
+= 1; /* scaled index byte. */
636 j
= str
[strl
- 4] - '0'; /* store temporary. */
637 str
[strl
- 6] = '\000'; /* nullterminate for recursive call. */
638 i
= addr_mode (str
, addr_modeP
, 1);
640 if (!i
|| addr_modeP
->mode
== 20)
642 as_bad (_("Invalid or illegal addressing mode combined with scaled-index"));
646 addr_modeP
->scaled_mode
= addr_modeP
->mode
; /* Store the inferior mode. */
647 addr_modeP
->mode
= mode
;
648 addr_modeP
->scaled_reg
= j
+ 1;
654 addr_modeP
->mode
= DEFAULT
; /* Default to whatever. */
655 addr_modeP
->disp
[0] = str
;
660 /* ptr points at string addr_modeP points at struct with result This
661 routine calls addr_mode to determine the general addr.mode of the
662 operand. When this is ready it parses the displacements for size
663 specifying suffixes and determines size of immediate mode via
664 ns32k-opcode. Also builds index bytes if needed. */
666 static int get_addr_mode
PARAMS ((char *, addr_modeS
*));
668 get_addr_mode (ptr
, addr_modeP
)
670 addr_modeS
*addr_modeP
;
674 addr_mode (ptr
, addr_modeP
, 0);
676 if (addr_modeP
->mode
== DEFAULT
|| addr_modeP
->scaled_mode
== -1)
678 /* Resolve ambigious operands, this shouldn't be necessary if
679 one uses standard NSC operand syntax. But the sequent
680 compiler doesn't!!! This finds a proper addressinging mode
681 if it is implicitly stated. See ns32k-opcode.h. */
682 (void) evaluate_expr (&exprP
, ptr
); /* This call takes time Sigh! */
684 if (addr_modeP
->mode
== DEFAULT
)
686 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
687 addr_modeP
->mode
= desc
->default_model
; /* We have a label. */
689 addr_modeP
->mode
= desc
->default_modec
; /* We have a constant. */
693 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
694 addr_modeP
->scaled_mode
= desc
->default_model
;
696 addr_modeP
->scaled_mode
= desc
->default_modec
;
699 /* Must put this mess down in addr_mode to handle the scaled
703 /* It appears as the sequent compiler wants an absolute when we have
704 a label without @. Constants becomes immediates besides the addr
705 case. Think it does so with local labels too, not optimum, pcrel
706 is better. When I have time I will make gas check this and
707 select pcrel when possible Actually that is trivial. */
708 if ((tmp
= addr_modeP
->scaled_reg
))
709 { /* Build indexbyte. */
710 tmp
--; /* Remember regnumber comes incremented for
712 tmp
|= addr_modeP
->scaled_mode
<< 3;
713 addr_modeP
->index_byte
= (char) tmp
;
714 addr_modeP
->am_size
+= 1;
717 assert (addr_modeP
->mode
>= 0);
718 if (disp_test
[(unsigned int) addr_modeP
->mode
])
727 /* There was a displacement, probe for length specifying suffix. */
728 addr_modeP
->pcrel
= 0;
730 assert(addr_modeP
->mode
>= 0);
731 if (disp_test
[(unsigned int) addr_modeP
->mode
])
733 /* There is a displacement. */
734 if (addr_modeP
->mode
== 27 || addr_modeP
->scaled_mode
== 27)
735 /* Do we have pcrel. mode. */
736 addr_modeP
->pcrel
= 1;
738 addr_modeP
->im_disp
= 1;
740 for (i
= 0; i
< 2; i
++)
742 suffix_sub
= suffix
= 0;
744 if ((toP
= addr_modeP
->disp
[i
]))
746 /* Suffix of expression, the largest size rules. */
749 while ((c
= *fromP
++))
757 as_warn (_("Premature end of suffix -- Defaulting to d"));
770 as_warn (_("Bad suffix after ':' use {b|w|d} Defaulting to d"));
775 toP
--; /* So we write over the ':' */
777 if (suffix
< suffix_sub
)
782 *toP
= '\0'; /* Terminate properly. */
783 addr_modeP
->disp_suffix
[i
] = suffix
;
784 addr_modeP
->am_size
+= suffix
? suffix
: 4;
791 if (addr_modeP
->mode
== 20)
793 /* Look in ns32k_opcode for size. */
794 addr_modeP
->disp_suffix
[0] = addr_modeP
->am_size
= desc
->im_size
;
795 addr_modeP
->im_disp
= 0;
799 return addr_modeP
->mode
;
802 /* Read an optionlist. */
804 static void optlist
PARAMS ((char *, struct ns32k_option
*, unsigned long *));
806 optlist (str
, optionP
, default_map
)
807 char *str
; /* The string to extract options from. */
808 struct ns32k_option
*optionP
; /* How to search the string. */
809 unsigned long *default_map
; /* Default pattern and output. */
811 int i
, j
, k
, strlen1
, strlen2
;
812 char *patternP
, *strP
;
814 strlen1
= strlen (str
);
817 as_fatal (_("Very short instr to option, ie you can't do it on a NULLstr"));
819 for (i
= 0; optionP
[i
].pattern
!= 0; i
++)
821 strlen2
= strlen (optionP
[i
].pattern
);
823 for (j
= 0; j
< strlen1
; j
++)
825 patternP
= optionP
[i
].pattern
;
828 for (k
= 0; k
< strlen2
; k
++)
830 if (*(strP
++) != *(patternP
++))
836 *default_map
|= optionP
[i
].or;
837 *default_map
&= optionP
[i
].and;
843 /* Search struct for symbols.
844 This function is used to get the short integer form of reg names in
845 the instructions lmr, smr, lpr, spr return true if str is found in
848 static int list_search
PARAMS ((char *, struct ns32k_option
*, unsigned long *));
851 list_search (str
, optionP
, default_map
)
852 char *str
; /* The string to match. */
853 struct ns32k_option
*optionP
; /* List to search. */
854 unsigned long *default_map
; /* Default pattern and output. */
858 for (i
= 0; optionP
[i
].pattern
!= 0; i
++)
860 if (!strncmp (optionP
[i
].pattern
, str
, 20))
862 /* Use strncmp to be safe. */
863 *default_map
|= optionP
[i
].or;
864 *default_map
&= optionP
[i
].and;
870 as_bad (_("No such entry in list. (cpu/mmu register)"));
875 evaluate_expr (resultP
, ptr
)
876 expressionS
*resultP
;
881 tmp_line
= input_line_pointer
;
882 input_line_pointer
= ptr
;
883 expression (resultP
);
884 input_line_pointer
= tmp_line
;
887 /* Convert operands to iif-format and adds bitfields to the opcode.
888 Operands are parsed in such an order that the opcode is updated from
889 its most significant bit, that is when the operand need to alter the
891 Be carefull not to put to objects in the same iif-slot. */
893 static void encode_operand
894 PARAMS ((int, char **, const char *, const char *, char, char));
897 encode_operand (argc
, argv
, operandsP
, suffixP
, im_size
, opcode_bit_ptr
)
900 const char *operandsP
;
902 char im_size ATTRIBUTE_UNUSED
;
907 int pcrel
, b
, loop
, pcrel_adjust
;
910 for (loop
= 0; loop
< argc
; loop
++)
912 /* What operand are we supposed to work on. */
913 i
= operandsP
[loop
<< 1] - '1';
915 as_fatal (_("Internal consistency error. check ns32k-opcode.h"));
921 switch ((d
= operandsP
[(loop
<< 1) + 1]))
923 case 'f': /* Operand of sfsr turns out to be a nasty
926 case 'Z': /* Float not immediate. */
927 case 'F': /* 32 bit float general form. */
928 case 'L': /* 64 bit float. */
929 case 'I': /* Integer not immediate. */
932 case 'D': /* Double-word. */
933 case 'A': /* Double-word gen-address-form ie no regs
935 get_addr_mode (argv
[i
], &addr_modeP
);
937 if ((addr_modeP
.mode
== 20) &&
938 (d
== 'I' || d
== 'Z' || d
== 'A'))
939 as_fatal (d
== 'A'? _("Address of immediate operand"):
940 _("Invalid immediate write operand."));
942 if (opcode_bit_ptr
== desc
->opcode_size
)
947 for (j
= b
; j
< (b
+ 2); j
++)
949 if (addr_modeP
.disp
[j
- b
])
953 addr_modeP
.disp_suffix
[j
- b
],
954 (unsigned long) addr_modeP
.disp
[j
- b
],
961 (addr_modeP
.scaled_reg
? addr_modeP
.scaled_mode
968 iif
.iifP
[1].object
|= ((long) addr_modeP
.mode
) << opcode_bit_ptr
;
970 if (addr_modeP
.scaled_reg
)
973 IIF (j
, 1, 1, (unsigned long) addr_modeP
.index_byte
,
974 0, 0, 0, 0, 0, NULL
, -1, 0);
978 case 'b': /* Multiple instruction disp. */
979 freeptr
++; /* OVE:this is an useful hack. */
980 sprintf (freeptr
, "((%s-1)*%d)", argv
[i
], desc
->im_size
);
982 pcrel
-= 1; /* Make pcrel 0 inspite of what case 'p':
985 case 'p': /* Displacement - pc relative addressing. */
988 case 'd': /* Displacement. */
989 iif
.instr_size
+= suffixP
[i
] ? suffixP
[i
] : 4;
990 IIF (12, 2, suffixP
[i
], (unsigned long) argv
[i
], 0,
991 pcrel
, pcrel_adjust
, 1, IND (BRANCH
, BYTE
), NULL
, -1, 0);
993 case 'H': /* Sequent-hack: the linker wants a bit set
996 iif
.instr_size
+= suffixP
[i
] ? suffixP
[i
] : 4;
997 IIF (12, 2, suffixP
[i
], (unsigned long) argv
[i
], 0,
998 pcrel
, pcrel_adjust
, 1, IND (BRANCH
, BYTE
), NULL
, -1, 1);
1000 case 'q': /* quick */
1001 opcode_bit_ptr
-= 4;
1002 IIF (11, 2, 42, (unsigned long) argv
[i
], 0, 0, 0, 0, 0,
1003 bit_fix_new (4, opcode_bit_ptr
, -8, 7, 0, 1, 0), -1, 0);
1005 case 'r': /* Register number (3 bits). */
1006 list_search (argv
[i
], opt6
, &tmp
);
1007 opcode_bit_ptr
-= 3;
1008 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
1010 case 'O': /* Setcfg instruction optionslist. */
1011 optlist (argv
[i
], opt3
, &tmp
);
1012 opcode_bit_ptr
-= 4;
1013 iif
.iifP
[1].object
|= tmp
<< 15;
1015 case 'C': /* Cinv instruction optionslist. */
1016 optlist (argv
[i
], opt4
, &tmp
);
1017 opcode_bit_ptr
-= 4;
1018 iif
.iifP
[1].object
|= tmp
<< 15; /* Insert the regtype in opcode. */
1020 case 'S': /* String instruction options list. */
1021 optlist (argv
[i
], opt5
, &tmp
);
1022 opcode_bit_ptr
-= 4;
1023 iif
.iifP
[1].object
|= tmp
<< 15;
1026 case 'U': /* Register list. */
1027 IIF (10, 1, 1, 0, 0, 0, 0, 0, 0, NULL
, -1, 0);
1028 switch (operandsP
[(i
<< 1) + 1])
1030 case 'u': /* Restore, exit. */
1031 optlist (argv
[i
], opt1
, &iif
.iifP
[10].object
);
1033 case 'U': /* Save, enter. */
1034 optlist (argv
[i
], opt2
, &iif
.iifP
[10].object
);
1037 iif
.instr_size
+= 1;
1039 case 'M': /* MMU register. */
1040 list_search (argv
[i
], mmureg
, &tmp
);
1041 opcode_bit_ptr
-= 4;
1042 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
1044 case 'P': /* CPU register. */
1045 list_search (argv
[i
], cpureg
, &tmp
);
1046 opcode_bit_ptr
-= 4;
1047 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
1049 case 'g': /* Inss exts. */
1050 iif
.instr_size
+= 1; /* 1 byte is allocated after the opcode. */
1052 (unsigned long) argv
[i
], /* i always 2 here. */
1054 bit_fix_new (3, 5, 0, 7, 0, 0, 0), /* A bit_fix is targeted to
1060 (unsigned long) argv
[i
], /* i always 3 here. */
1062 bit_fix_new (5, 0, 1, 32, -1, 0, -1), -1, 0);
1065 iif
.instr_size
+= 1;
1066 b
= 2 + i
; /* Put the extension byte after opcode. */
1067 IIF (b
, 2, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0);
1070 as_fatal (_("Bad opcode-table-option, check in file ns32k-opcode.h"));
1075 /* in: instruction line
1076 out: internal structure of instruction
1077 that has been prepared for direct conversion to fragment(s) and
1078 fixes in a systematical fashion
1079 Return-value = recursive_level. */
1080 /* Build iif of one assembly text line. */
1082 static int parse
PARAMS ((const char *, int));
1085 parse (line
, recursive_level
)
1087 int recursive_level
;
1089 const char *lineptr
;
1090 char c
, suffix_separator
;
1095 char suffix
[MAX_ARGS
], *argv
[MAX_ARGS
]; /* No more than 4 operands. */
1097 if (recursive_level
<= 0)
1099 /* Called from md_assemble. */
1100 for (lineptr
= line
; (*lineptr
) != '\0' && (*lineptr
) != ' '; lineptr
++)
1104 *(char *) lineptr
= '\0';
1106 if (!(desc
= (struct ns32k_opcode
*) hash_find (inst_hash_handle
, line
)))
1107 as_fatal (_("No such opcode"));
1109 *(char *) lineptr
= c
;
1118 if (*desc
->operands
)
1120 if (*lineptr
++ != '\0')
1125 while (*lineptr
!= '\0')
1127 if (desc
->operands
[argc
<< 1])
1130 arg_type
= desc
->operands
[(argc
<< 1) + 1];
1138 /* The operand is supposed to be a displacement. */
1139 /* Hackwarning: do not forget to update the 4
1140 cases above when editing ns32k-opcode.h. */
1141 suffix_separator
= ':';
1144 /* If this char occurs we loose. */
1145 suffix_separator
= '\255';
1149 suffix
[argc
] = 0; /* 0 when no ':' is encountered. */
1150 argv
[argc
] = freeptr
;
1153 while ((c
= *lineptr
) != '\0' && c
!= sep
)
1169 if (c
== suffix_separator
)
1171 /* ':' - label/suffix separator. */
1184 as_warn (_("Bad suffix, defaulting to d"));
1186 if (lineptr
[1] == '\0' || lineptr
[1] == sep
)
1205 if (*lineptr
== '\0')
1212 as_fatal (_("Too many operands passed to instruction"));
1218 if (argc
!= strlen (desc
->operands
) / 2)
1220 if (strlen (desc
->default_args
))
1222 /* We can apply default, don't goof. */
1223 if (parse (desc
->default_args
, 1) != 1)
1224 /* Check error in default. */
1225 as_fatal (_("Wrong numbers of operands in default, check ns32k-opcodes.h"));
1229 as_fatal (_("Wrong number of operands"));
1233 for (i
= 0; i
< IIF_ENTRIES
; i
++)
1234 /* Mark all entries as void. */
1235 iif
.iifP
[i
].type
= 0;
1237 /* Build opcode iif-entry. */
1238 iif
.instr_size
= desc
->opcode_size
/ 8;
1239 IIF (1, 1, iif
.instr_size
, desc
->opcode_seed
, 0, 0, 0, 0, 0, 0, -1, 0);
1241 /* This call encodes operands to iif format. */
1244 encode_operand (argc
,
1251 return recursive_level
;
1254 /* Convert iif to fragments. From this point we start to dribble with
1255 functions in other files than this one.(Except hash.c) So, if it's
1256 possible to make an iif for an other CPU, you don't need to know
1257 what frags, relax, obstacks, etc is in order to port this
1258 assembler. You only need to know if it's possible to reduce your
1259 cpu-instruction to iif-format (takes some work) and adopt the other
1260 md_? parts according to given instructions Note that iif was
1261 invented for the clean ns32k`s architecure. */
1263 /* GAS for the ns32k has a problem. PC relative displacements are
1264 relative to the address of the opcode, not the address of the
1265 operand. We used to keep track of the offset between the operand
1266 and the opcode in pcrel_adjust for each frag and each fix. However,
1267 we get into trouble where there are two or more pc-relative
1268 operands and the size of the first one can't be determined. Then in
1269 the relax phase, the size of the first operand will change and
1270 pcrel_adjust will no longer be correct. The current solution is
1271 keep a pointer to the frag with the opcode in it and the offset in
1272 that frag for each frag and each fix. Then, when needed, we can
1273 always figure out how far it is between the opcode and the pcrel
1274 object. See also md_pcrel_adjust and md_fix_pcrel_adjust. For
1275 objects not part of an instruction, the pointer to the opcode frag
1278 static void convert_iif
PARAMS ((void));
1285 unsigned int inst_offset
;
1293 frag_grow (iif
.instr_size
); /* This is important. */
1294 memP
= frag_more (0);
1296 inst_offset
= (memP
- frag_now
->fr_literal
);
1297 inst_frag
= frag_now
;
1299 for (i
= 0; i
< IIF_ENTRIES
; i
++)
1301 if ((type
= iif
.iifP
[i
].type
))
1303 /* The object exist, so handle it. */
1304 switch (size
= iif
.iifP
[i
].size
)
1308 /* It's a bitfix that operates on an existing object. */
1309 if (iif
.iifP
[i
].bit_fixP
->fx_bit_base
)
1310 /* Expand fx_bit_base to point at opcode. */
1311 iif
.iifP
[i
].bit_fixP
->fx_bit_base
= (long) inst_opcode
;
1314 case 8: /* bignum or doublefloat. */
1319 /* The final size in objectmemory is known. */
1320 memP
= frag_more (size
);
1321 j
= iif
.iifP
[i
].bit_fixP
;
1325 case 1: /* The object is pure binary. */
1328 md_number_to_field(memP
, exprP
.X_add_number
, j
);
1330 else if (iif
.iifP
[i
].pcrel
)
1332 fix_new_ns32k (frag_now
,
1333 (long) (memP
- frag_now
->fr_literal
),
1338 iif
.iifP
[i
].im_disp
,
1340 iif
.iifP
[i
].bsr
, /* Sequent hack. */
1341 inst_frag
, inst_offset
);
1345 /* Good, just put them bytes out. */
1346 switch (iif
.iifP
[i
].im_disp
)
1349 md_number_to_chars (memP
, iif
.iifP
[i
].object
, size
);
1352 md_number_to_disp (memP
, iif
.iifP
[i
].object
, size
);
1355 as_fatal (_("iif convert internal pcrel/binary"));
1361 /* The object is a pointer at an expression, so
1362 unpack it, note that bignums may result from the
1364 evaluate_expr (&exprP
, (char *) iif
.iifP
[i
].object
);
1365 if (exprP
.X_op
== O_big
|| size
== 8)
1367 if ((k
= exprP
.X_add_number
) > 0)
1369 /* We have a bignum ie a quad. This can only
1370 happens in a long suffixed instruction. */
1372 as_bad (_("Bignum too big for long"));
1377 for (l
= 0; k
> 0; k
--, l
+= 2)
1378 md_number_to_chars (memP
+ l
,
1379 generic_bignum
[l
>> 1],
1380 sizeof (LITTLENUM_TYPE
));
1385 LITTLENUM_TYPE words
[4];
1390 gen_to_words (words
, 2, 8);
1391 md_number_to_imm (memP
, (long) words
[0],
1392 sizeof (LITTLENUM_TYPE
));
1393 md_number_to_imm (memP
+ sizeof (LITTLENUM_TYPE
),
1395 sizeof (LITTLENUM_TYPE
));
1398 gen_to_words (words
, 4, 11);
1399 md_number_to_imm (memP
, (long) words
[0],
1400 sizeof (LITTLENUM_TYPE
));
1401 md_number_to_imm (memP
+ sizeof (LITTLENUM_TYPE
),
1403 sizeof (LITTLENUM_TYPE
));
1404 md_number_to_imm ((memP
+ 2
1405 * sizeof (LITTLENUM_TYPE
)),
1407 sizeof (LITTLENUM_TYPE
));
1408 md_number_to_imm ((memP
+ 3
1409 * sizeof (LITTLENUM_TYPE
)),
1411 sizeof (LITTLENUM_TYPE
));
1417 if (exprP
.X_add_symbol
||
1418 exprP
.X_op_symbol
||
1421 /* The expression was undefined due to an
1422 undefined label. Create a fix so we can fix
1423 the object later. */
1424 exprP
.X_add_number
+= iif
.iifP
[i
].object_adjust
;
1425 fix_new_ns32k_exp (frag_now
,
1426 (long) (memP
- frag_now
->fr_literal
),
1430 iif
.iifP
[i
].im_disp
,
1433 inst_frag
, inst_offset
);
1437 md_number_to_field(memP
, exprP
.X_add_number
, j
);
1441 /* Good, just put them bytes out. */
1442 switch (iif
.iifP
[i
].im_disp
)
1445 md_number_to_imm (memP
, exprP
.X_add_number
, size
);
1448 md_number_to_disp (memP
, exprP
.X_add_number
, size
);
1451 as_fatal (_("iif convert internal pcrel/pointer"));
1456 as_fatal (_("Internal logic error in iif.iifP[n].type"));
1461 /* Too bad, the object may be undefined as far as its
1462 final nsize in object memory is concerned. The size
1463 of the object in objectmemory is not explicitly
1464 given. If the object is defined its length can be
1465 determined and a fix can replace the frag. */
1467 evaluate_expr (&exprP
, (char *) iif
.iifP
[i
].object
);
1469 if ((exprP
.X_add_symbol
|| exprP
.X_op_symbol
) &&
1472 /* Size is unknown until link time so have to default. */
1473 size
= default_disp_size
; /* Normally 4 bytes. */
1474 memP
= frag_more (size
);
1475 fix_new_ns32k_exp (frag_now
,
1476 (long) (memP
- frag_now
->fr_literal
),
1479 0, /* never iif.iifP[i].pcrel, */
1480 1, /* always iif.iifP[i].im_disp */
1484 break; /* Exit this absolute hack. */
1487 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
1490 if (exprP
.X_op_symbol
)
1492 /* We cant relax this case. */
1493 as_fatal (_("Can't relax difference"));
1497 /* Size is not important. This gets fixed by
1498 relax, but we assume 0 in what follows. */
1499 memP
= frag_more (4); /* Max size. */
1503 fragS
*old_frag
= frag_now
;
1504 frag_variant (rs_machine_dependent
,
1507 IND (BRANCH
, UNDEF
), /* Expecting
1512 frag_opcode_frag (old_frag
) = inst_frag
;
1513 frag_opcode_offset (old_frag
) = inst_offset
;
1514 frag_bsr (old_frag
) = iif
.iifP
[i
].bsr
;
1520 /* This duplicates code in md_number_to_disp. */
1521 if (-64 <= exprP
.X_add_number
&& exprP
.X_add_number
<= 63)
1527 if (-8192 <= exprP
.X_add_number
1528 && exprP
.X_add_number
<= 8191)
1534 if (-0x20000000 <= exprP
.X_add_number
1535 && exprP
.X_add_number
<=0x1fffffff)
1541 as_bad (_("Displacement to large for :d"));
1547 memP
= frag_more (size
);
1548 md_number_to_disp (memP
, exprP
.X_add_number
, size
);
1554 as_fatal (_("Internal logic error in iif.iifP[].type"));
1560 #ifdef BFD_ASSEMBLER
1561 /* This functionality should really be in the bfd library. */
1562 static bfd_reloc_code_real_type
1563 reloc (int size
, int pcrel
, int type
)
1566 bfd_reloc_code_real_type relocs
[] =
1568 BFD_RELOC_NS32K_IMM_8
,
1569 BFD_RELOC_NS32K_IMM_16
,
1570 BFD_RELOC_NS32K_IMM_32
,
1571 BFD_RELOC_NS32K_IMM_8_PCREL
,
1572 BFD_RELOC_NS32K_IMM_16_PCREL
,
1573 BFD_RELOC_NS32K_IMM_32_PCREL
,
1575 /* ns32k displacements. */
1576 BFD_RELOC_NS32K_DISP_8
,
1577 BFD_RELOC_NS32K_DISP_16
,
1578 BFD_RELOC_NS32K_DISP_32
,
1579 BFD_RELOC_NS32K_DISP_8_PCREL
,
1580 BFD_RELOC_NS32K_DISP_16_PCREL
,
1581 BFD_RELOC_NS32K_DISP_32_PCREL
,
1583 /* Normal 2's complement. */
1608 index
= length
+ 3 * pcrel
+ 6 * type
;
1610 if (index
>= 0 && (unsigned int) index
< sizeof (relocs
) / sizeof (relocs
[0]))
1611 return relocs
[index
];
1614 as_bad (_("Can not do %d byte pc-relative relocation for storage type %d"),
1617 as_bad (_("Can not do %d byte relocation for storage type %d"),
1620 return BFD_RELOC_NONE
;
1629 freeptr
= freeptr_static
;
1630 parse (line
, 0); /* Explode line to more fix form in iif. */
1631 convert_iif (); /* Convert iif to frags, fix's etc. */
1633 printf (" \t\t\t%s\n", line
);
1640 /* Build a hashtable of the instructions. */
1641 const struct ns32k_opcode
*ptr
;
1643 const struct ns32k_opcode
*endop
;
1645 inst_hash_handle
= hash_new ();
1647 endop
= ns32k_opcodes
+ sizeof (ns32k_opcodes
) / sizeof (ns32k_opcodes
[0]);
1648 for (ptr
= ns32k_opcodes
; ptr
< endop
; ptr
++)
1650 if ((stat
= hash_insert (inst_hash_handle
, ptr
->name
, (char *) ptr
)))
1652 as_fatal (_("Can't hash %s: %s"), ptr
->name
, stat
);
1655 /* Some private space please! */
1656 freeptr_static
= (char *) malloc (PRIVATE_SIZE
);
1659 /* Must be equal to MAX_PRECISON in atof-ieee.c. */
1660 #define MAX_LITTLENUMS 6
1662 /* Turn the string pointed to by litP into a floating point constant
1663 of type TYPE, and emit the appropriate bytes. The number of
1664 LITTLENUMS emitted is stored in *SIZEP. An error message is
1665 returned, or NULL on OK. */
1668 md_atof (type
, litP
, sizeP
)
1674 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1675 LITTLENUM_TYPE
*wordP
;
1689 return _("Bad call to MD_ATOF()");
1692 t
= atof_ieee (input_line_pointer
, type
, words
);
1694 input_line_pointer
= t
;
1696 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1698 for (wordP
= words
+ prec
; prec
--;)
1700 md_number_to_chars (litP
, (long) (*--wordP
), sizeof (LITTLENUM_TYPE
));
1701 litP
+= sizeof (LITTLENUM_TYPE
);
1707 /* Convert number to chars in correct order. */
1710 md_number_to_chars (buf
, value
, nbytes
)
1715 number_to_chars_littleendian (buf
, value
, nbytes
);
1718 /* This is a variant of md_numbers_to_chars. The reason for its'
1719 existence is the fact that ns32k uses Huffman coded
1720 displacements. This implies that the bit order is reversed in
1721 displacements and that they are prefixed with a size-tag.
1725 10xxxxxx xxxxxxxx word
1726 11xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx double word
1728 This must be taken care of and we do it here! */
1731 md_number_to_disp (buf
, val
, n
)
1739 if (val
< -64 || val
> 63)
1740 as_bad (_("value of %ld out of byte displacement range."), val
);
1743 printf ("%x ", val
& 0xff);
1748 if (val
< -8192 || val
> 8191)
1749 as_bad (_("value of %ld out of word displacement range."), val
);
1753 printf ("%x ", val
>> 8 & 0xff);
1755 *buf
++ = (val
>> 8);
1757 printf ("%x ", val
& 0xff);
1762 if (val
< -0x20000000 || val
>= 0x20000000)
1763 as_bad (_("value of %ld out of double word displacement range."), val
);
1766 printf ("%x ", val
>> 24 & 0xff);
1768 *buf
++ = (val
>> 24);
1770 printf ("%x ", val
>> 16 & 0xff);
1772 *buf
++ = (val
>> 16);
1774 printf ("%x ", val
>> 8 & 0xff);
1776 *buf
++ = (val
>> 8);
1778 printf ("%x ", val
& 0xff);
1783 as_fatal (_("Internal logic error. line %d, file \"%s\""),
1784 __LINE__
, __FILE__
);
1789 md_number_to_imm (buf
, val
, n
)
1798 printf ("%x ", val
& 0xff);
1804 printf ("%x ", val
>> 8 & 0xff);
1806 *buf
++ = (val
>> 8);
1808 printf ("%x ", val
& 0xff);
1814 printf ("%x ", val
>> 24 & 0xff);
1816 *buf
++ = (val
>> 24);
1818 printf ("%x ", val
>> 16 & 0xff);
1820 *buf
++ = (val
>> 16);
1822 printf ("%x ", val
>> 8 & 0xff);
1824 *buf
++ = (val
>> 8);
1826 printf ("%x ", val
& 0xff);
1831 as_fatal (_("Internal logic error. line %d, file \"%s\""),
1832 __LINE__
, __FILE__
);
1836 /* Fast bitfiddling support. */
1837 /* Mask used to zero bitfield before oring in the true field. */
1839 static unsigned long l_mask
[] =
1841 0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
1842 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
1843 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
1844 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
1845 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
1846 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
1847 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
1848 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
1850 static unsigned long r_mask
[] =
1852 0x00000000, 0x00000001, 0x00000003, 0x00000007,
1853 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
1854 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
1855 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
1856 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
1857 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
1858 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
1859 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
1861 #define MASK_BITS 31
1862 /* Insert bitfield described by field_ptr and val at buf
1863 This routine is written for modification of the first 4 bytes pointed
1864 to by buf, to yield speed.
1865 The ifdef stuff is for selection between a ns32k-dependent routine
1866 and a general version. (My advice: use the general version!). */
1869 md_number_to_field (buf
, val
, field_ptr
)
1872 bit_fixS
*field_ptr
;
1874 unsigned long object
;
1876 /* Define ENDIAN on a ns32k machine. */
1878 unsigned long *mem_ptr
;
1883 if (field_ptr
->fx_bit_min
<= val
&& val
<= field_ptr
->fx_bit_max
)
1886 if (field_ptr
->fx_bit_base
)
1888 mem_ptr
= (unsigned long *) field_ptr
->fx_bit_base
;
1890 mem_ptr
= (unsigned long *) buf
;
1892 mem_ptr
= ((unsigned long *)
1893 ((char *) mem_ptr
+ field_ptr
->fx_bit_base_adj
));
1895 if (field_ptr
->fx_bit_base
)
1896 mem_ptr
= (char *) field_ptr
->fx_bit_base
;
1900 mem_ptr
+= field_ptr
->fx_bit_base_adj
;
1903 /* We have a nice ns32k machine with lowbyte at low-physical mem. */
1904 object
= *mem_ptr
; /* get some bytes */
1905 #else /* OVE Goof! the machine is a m68k or dito. */
1906 /* That takes more byte fiddling. */
1908 object
|= mem_ptr
[3] & 0xff;
1910 object
|= mem_ptr
[2] & 0xff;
1912 object
|= mem_ptr
[1] & 0xff;
1914 object
|= mem_ptr
[0] & 0xff;
1917 mask
|= (r_mask
[field_ptr
->fx_bit_offset
]);
1918 mask
|= (l_mask
[field_ptr
->fx_bit_offset
+ field_ptr
->fx_bit_size
]);
1920 val
+= field_ptr
->fx_bit_add
;
1921 object
|= ((val
<< field_ptr
->fx_bit_offset
) & (mask
^ 0xffffffff));
1925 mem_ptr
[0] = (char) object
;
1927 mem_ptr
[1] = (char) object
;
1929 mem_ptr
[2] = (char) object
;
1931 mem_ptr
[3] = (char) object
;
1936 as_bad (_("Bit field out of range"));
1941 md_pcrel_adjust (fragP
)
1945 addressT opcode_address
;
1946 unsigned int offset
;
1948 opcode_frag
= frag_opcode_frag (fragP
);
1949 if (opcode_frag
== 0)
1952 offset
= frag_opcode_offset (fragP
);
1953 opcode_address
= offset
+ opcode_frag
->fr_address
;
1955 return fragP
->fr_address
+ fragP
->fr_fix
- opcode_address
;
1958 static int md_fix_pcrel_adjust
PARAMS ((fixS
*fixP
));
1960 md_fix_pcrel_adjust (fixP
)
1964 addressT opcode_address
;
1965 unsigned int offset
;
1967 opcode_frag
= fix_opcode_frag (fixP
);
1968 if (opcode_frag
== 0)
1971 offset
= fix_opcode_offset (fixP
);
1972 opcode_address
= offset
+ opcode_frag
->fr_address
;
1974 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- opcode_address
;
1977 /* Apply a fixS (fixup of an instruction or data that we didn't have
1978 enough info to complete immediately) to the data in a frag.
1980 On the ns32k, everything is in a different format, so we have broken
1981 out separate functions for each kind of thing we could be fixing.
1982 They all get called from here. */
1985 md_apply_fix3 (fixP
, valP
, seg
)
1988 segT seg ATTRIBUTE_UNUSED
;
1990 long val
= * (long *) valP
;
1991 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1993 if (fix_bit_fixP (fixP
))
1995 /* Bitfields to fix, sigh. */
1996 md_number_to_field (buf
, val
, fix_bit_fixP (fixP
));
1998 else switch (fix_im_disp (fixP
))
2001 /* Immediate field. */
2002 md_number_to_imm (buf
, val
, fixP
->fx_size
);
2006 /* Displacement field. */
2007 /* Calculate offset. */
2008 md_number_to_disp (buf
,
2009 (fixP
->fx_pcrel
? val
+ md_fix_pcrel_adjust (fixP
)
2010 : val
), fixP
->fx_size
);
2014 /* Pointer in a data object. */
2015 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2019 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
2023 /* Convert a relaxed displacement to ditto in final output. */
2025 #ifndef BFD_ASSEMBLER
2027 md_convert_frag (headers
, sec
, fragP
)
2028 object_headers
*headers
;
2033 md_convert_frag (abfd
, sec
, fragP
)
2034 bfd
*abfd ATTRIBUTE_UNUSED
;
2035 segT sec ATTRIBUTE_UNUSED
;
2041 /* Address in gas core of the place to store the displacement. */
2042 char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
2043 /* Address in object code of the displacement. */
2046 switch (fragP
->fr_subtype
)
2048 case IND (BRANCH
, BYTE
):
2051 case IND (BRANCH
, WORD
):
2054 case IND (BRANCH
, DOUBLE
):
2062 know (fragP
->fr_symbol
);
2064 object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
2066 /* The displacement of the address, from current location. */
2067 disp
= (S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
) - object_address
;
2068 disp
+= md_pcrel_adjust (fragP
);
2070 md_number_to_disp (buffer_address
, (long) disp
, (int) ext
);
2071 fragP
->fr_fix
+= ext
;
2074 /* This function returns the estimated size a variable object will occupy,
2075 one can say that we tries to guess the size of the objects before we
2076 actually know it. */
2079 md_estimate_size_before_relax (fragP
, segment
)
2083 if (fragP
->fr_subtype
== IND (BRANCH
, UNDEF
))
2085 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
)
2087 /* We don't relax symbols defined in another segment. The
2088 thing to do is to assume the object will occupy 4 bytes. */
2089 fix_new_ns32k (fragP
,
2090 (int) (fragP
->fr_fix
),
2097 frag_bsr(fragP
), /* Sequent hack. */
2098 frag_opcode_frag (fragP
),
2099 frag_opcode_offset (fragP
));
2102 fragP
->fr_opcode
[1] = 0xff;
2108 /* Relaxable case. Set up the initial guess for the variable
2109 part of the frag. */
2110 fragP
->fr_subtype
= IND (BRANCH
, BYTE
);
2113 if (fragP
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
2116 /* Return the size of the variable part of the frag. */
2117 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2120 int md_short_jump_size
= 3;
2121 int md_long_jump_size
= 5;
2122 const int md_reloc_size
= 8; /* Size of relocation record. */
2125 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2127 addressT from_addr
, to_addr
;
2128 fragS
*frag ATTRIBUTE_UNUSED
;
2129 symbolS
*to_symbol ATTRIBUTE_UNUSED
;
2133 offset
= to_addr
- from_addr
;
2134 md_number_to_chars (ptr
, (valueT
) 0xEA, 1);
2135 md_number_to_disp (ptr
+ 1, (valueT
) offset
, 2);
2139 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2141 addressT from_addr
, to_addr
;
2142 fragS
*frag ATTRIBUTE_UNUSED
;
2143 symbolS
*to_symbol ATTRIBUTE_UNUSED
;
2147 offset
= to_addr
- from_addr
;
2148 md_number_to_chars (ptr
, (valueT
) 0xEA, 1);
2149 md_number_to_disp (ptr
+ 1, (valueT
) offset
, 4);
2152 const char *md_shortopts
= "m:";
2154 struct option md_longopts
[] =
2156 #define OPTION_DISP_SIZE (OPTION_MD_BASE)
2157 {"disp-size-default", required_argument
, NULL
, OPTION_DISP_SIZE
},
2158 {NULL
, no_argument
, NULL
, 0}
2161 size_t md_longopts_size
= sizeof (md_longopts
);
2164 md_parse_option (c
, arg
)
2171 if (!strcmp (arg
, "32032"))
2173 cpureg
= cpureg_032
;
2174 mmureg
= mmureg_032
;
2176 else if (!strcmp (arg
, "32532"))
2178 cpureg
= cpureg_532
;
2179 mmureg
= mmureg_532
;
2183 as_warn (_("invalid architecture option -m%s, ignored"), arg
);
2187 case OPTION_DISP_SIZE
:
2189 int size
= atoi(arg
);
2192 case 1: case 2: case 4:
2193 default_disp_size
= size
;
2196 as_warn (_("invalid default displacement size \"%s\". Defaulting to %d."),
2197 arg
, default_disp_size
);
2210 md_show_usage (stream
)
2213 fprintf (stream
, _("\
2215 -m32032 | -m32532 select variant of NS32K architecture\n\
2216 --disp-size-default=<1|2|4>\n"));
2219 /* Create a bit_fixS in obstack 'notes'.
2220 This struct is used to profile the normal fix. If the bit_fixP is a
2221 valid pointer (not NULL) the bit_fix data will be used to format
2225 bit_fix_new (size
, offset
, min
, max
, add
, base_type
, base_adj
)
2226 char size
; /* Length of bitfield. */
2227 char offset
; /* Bit offset to bitfield. */
2228 long min
; /* Signextended min for bitfield. */
2229 long max
; /* Signextended max for bitfield. */
2230 long add
; /* Add mask, used for huffman prefix. */
2231 long base_type
; /* 0 or 1, if 1 it's exploded to opcode ptr. */
2236 bit_fixP
= (bit_fixS
*) obstack_alloc (¬es
, sizeof (bit_fixS
));
2238 bit_fixP
->fx_bit_size
= size
;
2239 bit_fixP
->fx_bit_offset
= offset
;
2240 bit_fixP
->fx_bit_base
= base_type
;
2241 bit_fixP
->fx_bit_base_adj
= base_adj
;
2242 bit_fixP
->fx_bit_max
= max
;
2243 bit_fixP
->fx_bit_min
= min
;
2244 bit_fixP
->fx_bit_add
= add
;
2250 fix_new_ns32k (frag
, where
, size
, add_symbol
, offset
, pcrel
,
2251 im_disp
, bit_fixP
, bsr
, opcode_frag
, opcode_offset
)
2252 fragS
*frag
; /* Which frag? */
2253 int where
; /* Where in that frag? */
2254 int size
; /* 1, 2 or 4 usually. */
2255 symbolS
*add_symbol
; /* X_add_symbol. */
2256 long offset
; /* X_add_number. */
2257 int pcrel
; /* True if PC-relative relocation. */
2258 char im_disp
; /* True if the value to write is a
2260 bit_fixS
*bit_fixP
; /* Pointer at struct of bit_fix's, ignored if
2262 char bsr
; /* Sequent-linker-hack: 1 when relocobject is
2265 unsigned int opcode_offset
;
2267 fixS
*fixP
= fix_new (frag
, where
, size
, add_symbol
,
2269 #ifdef BFD_ASSEMBLER
2270 bit_fixP
? NO_RELOC
: reloc (size
, pcrel
, im_disp
)
2276 fix_opcode_frag (fixP
) = opcode_frag
;
2277 fix_opcode_offset (fixP
) = opcode_offset
;
2278 fix_im_disp (fixP
) = im_disp
;
2279 fix_bsr (fixP
) = bsr
;
2280 fix_bit_fixP (fixP
) = bit_fixP
;
2281 /* We have a MD overflow check for displacements. */
2282 fixP
->fx_no_overflow
= (im_disp
!= 0);
2286 fix_new_ns32k_exp (frag
, where
, size
, exp
, pcrel
,
2287 im_disp
, bit_fixP
, bsr
, opcode_frag
, opcode_offset
)
2288 fragS
*frag
; /* Which frag? */
2289 int where
; /* Where in that frag? */
2290 int size
; /* 1, 2 or 4 usually. */
2291 expressionS
*exp
; /* Expression. */
2292 int pcrel
; /* True if PC-relative relocation. */
2293 char im_disp
; /* True if the value to write is a
2295 bit_fixS
*bit_fixP
; /* Pointer at struct of bit_fix's, ignored if
2297 char bsr
; /* Sequent-linker-hack: 1 when relocobject is
2300 unsigned int opcode_offset
;
2302 fixS
*fixP
= fix_new_exp (frag
, where
, size
, exp
, pcrel
,
2303 #ifdef BFD_ASSEMBLER
2304 bit_fixP
? NO_RELOC
: reloc (size
, pcrel
, im_disp
)
2310 fix_opcode_frag (fixP
) = opcode_frag
;
2311 fix_opcode_offset (fixP
) = opcode_offset
;
2312 fix_im_disp (fixP
) = im_disp
;
2313 fix_bsr (fixP
) = bsr
;
2314 fix_bit_fixP (fixP
) = bit_fixP
;
2315 /* We have a MD overflow check for displacements. */
2316 fixP
->fx_no_overflow
= (im_disp
!= 0);
2319 /* This is TC_CONS_FIX_NEW, called by emit_expr in read.c. */
2322 cons_fix_new_ns32k (frag
, where
, size
, exp
)
2323 fragS
*frag
; /* Which frag? */
2324 int where
; /* Where in that frag? */
2325 int size
; /* 1, 2 or 4 usually. */
2326 expressionS
*exp
; /* Expression. */
2328 fix_new_ns32k_exp (frag
, where
, size
, exp
,
2332 /* We have no need to default values of symbols. */
2335 md_undefined_symbol (name
)
2336 char *name ATTRIBUTE_UNUSED
;
2341 /* Round up a section size to the appropriate boundary. */
2344 md_section_align (segment
, size
)
2345 segT segment ATTRIBUTE_UNUSED
;
2348 return size
; /* Byte alignment is fine. */
2351 /* Exactly what point is a PC-relative offset relative TO? On the
2352 ns32k, they're relative to the start of the instruction. */
2355 md_pcrel_from (fixP
)
2360 res
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2361 #ifdef SEQUENT_COMPATABILITY
2362 if (frag_bsr (fixP
->fx_frag
))
2363 res
+= 0x12 /* FOO Kludge alert! */
2368 #ifdef BFD_ASSEMBLER
2371 tc_gen_reloc (section
, fixp
)
2372 asection
*section ATTRIBUTE_UNUSED
;
2376 bfd_reloc_code_real_type code
;
2378 code
= reloc (fixp
->fx_size
, fixp
->fx_pcrel
, fix_im_disp (fixp
));
2380 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2381 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2382 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2383 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2385 rel
->addend
= fixp
->fx_addnumber
;
2389 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2394 name
= S_GET_NAME (fixp
->fx_addsy
);
2396 name
= _("<unknown>");
2397 as_fatal (_("Cannot find relocation type for symbol %s, code %d"),
2403 #else /* BFD_ASSEMBLER */
2407 cons_fix_new_ns32k (where
, fixP
, segment_address_in_file
)
2410 relax_addressT segment_address_in_file
;
2412 /* In: Length of relocation (or of address) in chars: 1, 2 or 4.
2413 Out: GNU LD relocation length code: 0, 1, or 2. */
2415 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
2418 know (fixP
->fx_addsy
!= NULL
);
2420 md_number_to_chars (where
,
2421 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2424 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
2425 ? S_GET_TYPE (fixP
->fx_addsy
)
2426 : fixP
->fx_addsy
->sy_number
);
2428 md_number_to_chars (where
+ 4,
2429 ((long) (r_symbolnum
)
2430 | (long) (fixP
->fx_pcrel
<< 24)
2431 | (long) (nbytes_r_length
[fixP
->fx_size
] << 25)
2432 | (long) ((!S_IS_DEFINED (fixP
->fx_addsy
)) << 27)
2433 | (long) (fix_bsr (fixP
) << 28)
2434 | (long) (fix_im_disp (fixP
) << 29)),
2438 #endif /* OBJ_AOUT */
2439 #endif /* BFD_ASSMEBLER */