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. */
29 #include "opcode/ns32k.h"
34 #define IIF_ENTRIES 13 /* Number of entries in iif. */
35 #define PRIVATE_SIZE 256 /* Size of my garbage memory. */
37 #define DEFAULT -1 /* addr_mode returns this value when
38 plain constant or label is
41 #define IIF(ptr,a1,c1,e1,g1,i1,k1,m1,o1,q1,s1,u1) \
42 iif.iifP[ptr].type= a1; \
43 iif.iifP[ptr].size= c1; \
44 iif.iifP[ptr].object= e1; \
45 iif.iifP[ptr].object_adjust= g1; \
46 iif.iifP[ptr].pcrel= i1; \
47 iif.iifP[ptr].pcrel_adjust= k1; \
48 iif.iifP[ptr].im_disp= m1; \
49 iif.iifP[ptr].relax_substate= o1; \
50 iif.iifP[ptr].bit_fixP= q1; \
51 iif.iifP[ptr].addr_mode= s1; \
52 iif.iifP[ptr].bsr= u1;
54 #ifdef SEQUENT_COMPATABILITY
55 #define LINE_COMMENT_CHARS "|"
56 #define ABSOLUTE_PREFIX '@'
57 #define IMMEDIATE_PREFIX '#'
60 #ifndef LINE_COMMENT_CHARS
61 #define LINE_COMMENT_CHARS "#"
64 const char comment_chars
[] = "#";
65 const char line_comment_chars
[] = LINE_COMMENT_CHARS
;
66 const char line_separator_chars
[] = ";";
68 #if !defined(ABSOLUTE_PREFIX) && !defined(IMMEDIATE_PREFIX)
69 #define ABSOLUTE_PREFIX '@' /* One or the other MUST be defined */
74 char mode
; /* addressing mode of operand (0-31) */
75 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
122 instruction start to the
124 int im_disp
; /* True if the object is a displacement */
125 relax_substateT relax_substate
; /* Initial relaxsubstate */
126 bit_fixS
*bit_fixP
; /* Pointer at bit_fix struct */
127 int addr_mode
; /* What addrmode do we associate with this
129 char bsr
; /* Sequent hack */
130 } iif_entryT
; /* Internal Instruction Format */
134 int instr_size
; /* Max size of instruction in bytes. */
135 iif_entryT iifP
[IIF_ENTRIES
+ 1];
138 struct int_ins_form iif
;
140 char *input_line_pointer
;
142 /* Description of the PARTs in IIF
144 0 total length in bytes of entries in iif
157 For every entry there is a datalength in bytes. This is stored in size[n].
158 0, the objectlength is not explicitly given by the instruction
159 and the operand is undefined. This is a case for relaxation.
160 Reserve 4 bytes for the final object.
162 1, the entry contains one byte
163 2, the entry contains two bytes
164 3, the entry contains three bytes
165 4, the entry contains four bytes
168 Furthermore, every entry has a data type identifier in type[n].
170 0, the entry is void, ignore it.
171 1, the entry is a binary number.
172 2, the entry is a pointer at an expression.
173 Where expression may be as simple as a single '1',
174 and as complicated as foo-bar+12,
175 foo and bar may be undefined but suffixed by :{b|w|d} to
176 control the length of the object.
178 3, the entry is a pointer at a bignum struct
180 The low-order-byte coresponds to low physical memory.
181 Obviously a FRAGment must be created for each valid disp in PART whose
182 datalength is undefined (to bad) .
183 The case where just the expression is undefined is less severe and is
184 handled by fix. Here the number of bytes in the objectfile is known.
185 With this representation we simplify the assembly and separates the
186 machine dependent/independent parts in a more clean way (said OE). */
188 struct ns32k_option opt1
[] = /* restore, exit */
200 struct ns32k_option opt2
[] = /* save, enter */
212 struct ns32k_option opt3
[] = /* setcfg */
220 struct ns32k_option opt4
[] = /* cinv */
227 struct ns32k_option opt5
[] = /* string inst */
234 struct ns32k_option opt6
[] = /* plain reg ext,cvtp etc */
247 #if !defined(NS32032) && !defined(NS32532)
251 struct ns32k_option cpureg_532
[] = /* lpr spr */
264 {"intbase", 0xe, 0xff},
268 struct ns32k_option mmureg_532
[] = /* lmr smr */
275 {"ivar0", 0xe, 0xff},
276 {"ivar1", 0xf, 0xff},
280 struct ns32k_option cpureg_032
[] = /* lpr spr */
287 {"intbase", 0xe, 0xff},
291 struct ns32k_option mmureg_032
[] = /* lmr smr */
307 struct ns32k_option
*cpureg
= cpureg_532
;
308 struct ns32k_option
*mmureg
= mmureg_532
;
310 struct ns32k_option
*cpureg
= cpureg_032
;
311 struct ns32k_option
*mmureg
= mmureg_032
;
315 const pseudo_typeS md_pseudo_table
[] =
316 { /* So far empty. */
320 #define IND(x,y) (((x)<<2)+(y))
322 /* Those are index's to relax groups in md_relax_table ie it must be
323 multiplied by 4 to point at a group start. Viz IND(x,y) Se function
324 relax_segment in write.c for more info. */
329 /* Those are index's to entries in a relax group. */
335 /* Those limits are calculated from the displacement start in memory.
336 The ns32k uses the begining of the instruction as displacement
337 base. This type of displacements could be handled here by moving
338 the limit window up or down. I choose to use an internal
339 displacement base-adjust as there are other routines that must
340 consider this. Also, as we have two various offset-adjusts in the
341 ns32k (acb versus br/brs/jsr/bcond), two set of limits would have
342 had to be used. Now we dont have to think about that. */
344 const relax_typeS md_relax_table
[] =
351 {(63), (-64), 1, IND (BRANCH
, WORD
)},
352 {(8192), (-8192), 2, IND (BRANCH
, DOUBLE
)},
357 /* Array used to test if mode contains displacements.
358 Value is true if mode contains displacement. */
361 {0, 0, 0, 0, 0, 0, 0, 0,
362 1, 1, 1, 1, 1, 1, 1, 1,
363 1, 1, 1, 0, 0, 1, 1, 0,
364 1, 1, 1, 1, 1, 1, 1, 1};
366 /* Array used to calculate max size of displacements. */
371 static void evaluate_expr
PARAMS ((expressionS
* resultP
, char *ptr
));
372 static void md_number_to_disp
PARAMS ((char *buf
, long val
, int n
));
373 static void md_number_to_imm
PARAMS ((char *buf
, long val
, int n
));
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. */
384 addr_mode (operand
, addr_modeP
, recursive_level
)
386 register addr_modeS
*addr_modeP
;
395 mode
= DEFAULT
; /* default */
396 addr_modeP
->scaled_mode
= 0; /* why not */
397 addr_modeP
->scaled_reg
= 0; /* if 0, not scaled index */
398 addr_modeP
->float_flag
= 0;
399 addr_modeP
->am_size
= 0;
400 addr_modeP
->im_disp
= 0;
401 addr_modeP
->pcrel
= 0; /* not set in this function */
402 addr_modeP
->disp_suffix
[0] = 0;
403 addr_modeP
->disp_suffix
[1] = 0;
404 addr_modeP
->disp
[0] = NULL
;
405 addr_modeP
->disp
[1] = NULL
;
415 /* The following three case statements controls the mode-chars
416 this is the place to ed if you want to change them. */
417 #ifdef ABSOLUTE_PREFIX
418 case ABSOLUTE_PREFIX
:
419 if (str
[strl
- 1] == ']')
421 addr_modeP
->mode
= 21; /* absolute */
422 addr_modeP
->disp
[0] = str
+ 1;
425 #ifdef IMMEDIATE_PREFIX
426 case IMMEDIATE_PREFIX
:
427 if (str
[strl
- 1] == ']')
429 addr_modeP
->mode
= 20; /* immediate */
430 addr_modeP
->disp
[0] = str
+ 1;
434 if (str
[strl
- 1] != ']')
440 if (str
[2] != '\000')
442 addr_modeP
->mode
= 27; /* pc-relativ */
443 addr_modeP
->disp
[0] = str
+ 2;
447 as_warn (_("Invalid syntax in PC-relative addressing mode"));
453 if (str
[strl
- 1] != ']')
455 if ((!strncmp (str
, "ext(", 4)) && strl
> 7)
457 addr_modeP
->disp
[0] = str
+ 4;
461 { /* disp[0]'s termination point */
468 while (j
< strl
&& i
!= 0);
469 if (i
!= 0 || !(str
[j
+ 1] == '-' || str
[j
+ 1] == '+'))
471 as_warn (_("Invalid syntax in External addressing mode"));
474 str
[j
] = '\000'; /* null terminate disp[0] */
475 addr_modeP
->disp
[1] = str
+ j
+ 2;
476 addr_modeP
->mode
= 22;
494 addr_modeP
->float_flag
= 1;
497 if (str
[1] >= '0' && str
[1] < '8')
499 addr_modeP
->mode
= str
[1] - '0';
509 if (!strncmp (str
, "tos", 3))
511 addr_modeP
->mode
= 23; /* TopOfStack */
522 if (str
[strl
- 1] == ')')
524 if (str
[strl
- 2] == ')')
526 if (!strncmp (&str
[strl
- 5], "(fp", 3))
527 mode
= 16; /* Memory Relative. */
528 else if (!strncmp (&str
[strl
- 5], "(sp", 3))
530 else if (!strncmp (&str
[strl
- 5], "(sb", 3))
534 { /* Memory relative. */
535 addr_modeP
->mode
= mode
;
536 j
= strl
- 5; /* Temp for end of disp[0]. */
542 if (str
[strl
] == ')')
544 if (str
[strl
] == '(')
547 while (strl
> -1 && i
!= 0);
551 as_warn (_("Invalid syntax in Memory Relative addressing mode"));
555 addr_modeP
->disp
[1] = str
;
556 addr_modeP
->disp
[0] = str
+ strl
+ 1;
557 str
[j
] = '\000'; /* Null terminate disp[0] . */
558 str
[strl
] = '\000'; /* Null terminate disp[1]. */
564 switch (str
[strl
- 3])
568 if (str
[strl
- 2] >= '0'
569 && str
[strl
- 2] < '8'
570 && str
[strl
- 4] == '(')
572 addr_modeP
->mode
= str
[strl
- 2] - '0' + 8;
573 addr_modeP
->disp
[0] = str
;
575 return -1; /* reg rel */
580 if (!strncmp (&str
[strl
- 4], "(fp", 3))
582 else if (!strncmp (&str
[strl
- 4], "(sp", 3))
584 else if (!strncmp (&str
[strl
- 4], "(sb", 3))
586 else if (!strncmp (&str
[strl
- 4], "(pc", 3))
591 addr_modeP
->mode
= mode
;
592 addr_modeP
->disp
[0] = str
;
593 str
[strl
- 4] = '\0';
595 return -1; /* Memory space. */
600 /* No trailing ')' do we have a ']' ? */
601 if (str
[strl
- 1] == ']')
603 switch (str
[strl
- 2])
618 as_warn (_("Invalid scaled-indexed mode, use (b,w,d,q)"));
620 if (str
[strl
- 3] != ':' || str
[strl
- 6] != '['
621 || str
[strl
- 5] == 'r' || str
[strl
- 4] < '0'
622 || str
[strl
- 4] > '7')
623 as_warn (_("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"));
624 } /* Scaled index. */
626 if (recursive_level
> 0)
628 as_warn (_("Scaled-indexed addressing mode combined with scaled-index"));
632 addr_modeP
->am_size
+= 1; /* scaled index byte */
633 j
= str
[strl
- 4] - '0'; /* store temporary */
634 str
[strl
- 6] = '\000'; /* nullterminate for recursive call */
635 i
= addr_mode (str
, addr_modeP
, 1);
637 if (!i
|| addr_modeP
->mode
== 20)
639 as_warn (_("Invalid or illegal addressing mode combined with scaled-index"));
643 addr_modeP
->scaled_mode
= addr_modeP
->mode
; /* Store the inferior mode. */
644 addr_modeP
->mode
= mode
;
645 addr_modeP
->scaled_reg
= j
+ 1;
651 addr_modeP
->mode
= DEFAULT
; /* Default to whatever. */
652 addr_modeP
->disp
[0] = str
;
657 /* ptr points at string addr_modeP points at struct with result This
658 routine calls addr_mode to determine the general addr.mode of the
659 operand. When this is ready it parses the displacements for size
660 specifying suffixes and determines size of immediate mode via
661 ns32k-opcode. Also builds index bytes if needed. */
664 get_addr_mode (ptr
, addr_modeP
)
666 addr_modeS
*addr_modeP
;
670 addr_mode (ptr
, addr_modeP
, 0);
672 if (addr_modeP
->mode
== DEFAULT
|| addr_modeP
->scaled_mode
== -1)
674 /* Resolve ambigious operands, this shouldn't be necessary if
675 one uses standard NSC operand syntax. But the sequent
676 compiler doesn't!!! This finds a proper addressinging mode
677 if it is implicitly stated. See ns32k-opcode.h. */
678 (void) evaluate_expr (&exprP
, ptr
); /* This call takes time Sigh! */
680 if (addr_modeP
->mode
== DEFAULT
)
682 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
683 addr_modeP
->mode
= desc
->default_model
; /* We have a label. */
685 addr_modeP
->mode
= desc
->default_modec
; /* We have a constant. */
689 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
690 addr_modeP
->scaled_mode
= desc
->default_model
;
692 addr_modeP
->scaled_mode
= desc
->default_modec
;
695 /* Must put this mess down in addr_mode to handle the scaled
699 /* It appears as the sequent compiler wants an absolute when we have
700 a label without @. Constants becomes immediates besides the addr
701 case. Think it does so with local labels too, not optimum, pcrel
702 is better. When I have time I will make gas check this and
703 select pcrel when possible Actually that is trivial. */
704 if (tmp
= addr_modeP
->scaled_reg
)
705 { /* Build indexbyte. */
706 tmp
--; /* Remember regnumber comes incremented for
708 tmp
|= addr_modeP
->scaled_mode
<< 3;
709 addr_modeP
->index_byte
= (char) tmp
;
710 addr_modeP
->am_size
+= 1;
713 if (disp_test
[addr_modeP
->mode
])
716 register char suffix
;
717 register char suffix_sub
;
720 register char *fromP
;
722 /* There was a displacement, probe for length specifying suffix. */
723 addr_modeP
->pcrel
= 0;
725 if (disp_test
[addr_modeP
->mode
])
727 /* There is a displacement. */
728 if (addr_modeP
->mode
== 27 || addr_modeP
->scaled_mode
== 27)
729 /* Do we have pcrel. mode. */
730 addr_modeP
->pcrel
= 1;
732 addr_modeP
->im_disp
= 1;
734 for (i
= 0; i
< 2; i
++)
736 suffix_sub
= suffix
= 0;
738 if (toP
= addr_modeP
->disp
[i
])
740 /* Suffix of expression, the largest size rules. */
751 as_warn (_("Premature end of suffix -- Defaulting to d"));
764 as_warn (_("Bad suffix after ':' use {b|w|d} Defaulting to d"));
769 toP
--; /* So we write over the ':' */
771 if (suffix
< suffix_sub
)
776 *toP
= '\0'; /* Terminate properly. */
777 addr_modeP
->disp_suffix
[i
] = suffix
;
778 addr_modeP
->am_size
+= suffix
? suffix
: 4;
785 if (addr_modeP
->mode
== 20)
787 /* Look in ns32k_opcode for size. */
788 addr_modeP
->disp_suffix
[0] = addr_modeP
->am_size
= desc
->im_size
;
789 addr_modeP
->im_disp
= 0;
793 return addr_modeP
->mode
;
796 /* Read an optionlist. */
799 optlist (str
, optionP
, default_map
)
800 char *str
; /* The string to extract options from. */
801 struct ns32k_option
*optionP
; /* How to search the string. */
802 unsigned long *default_map
; /* Default pattern and output. */
804 register int i
, j
, k
, strlen1
, strlen2
;
805 register char *patternP
, *strP
;
807 strlen1
= strlen (str
);
810 as_fatal (_("Very short instr to option, ie you can't do it on a NULLstr"));
812 for (i
= 0; optionP
[i
].pattern
!= 0; i
++)
814 strlen2
= strlen (optionP
[i
].pattern
);
816 for (j
= 0; j
< strlen1
; j
++)
818 patternP
= optionP
[i
].pattern
;
821 for (k
= 0; k
< strlen2
; k
++)
823 if (*(strP
++) != *(patternP
++))
829 *default_map
|= optionP
[i
].or;
830 *default_map
&= optionP
[i
].and;
836 /* Search struct for symbols.
837 This function is used to get the short integer form of reg names in
838 the instructions lmr, smr, lpr, spr return true if str is found in
842 list_search (str
, optionP
, default_map
)
843 char *str
; /* The string to match. */
844 struct ns32k_option
*optionP
; /* List to search. */
845 unsigned long *default_map
; /* Default pattern and output. */
849 for (i
= 0; optionP
[i
].pattern
!= 0; i
++)
851 if (!strncmp (optionP
[i
].pattern
, str
, 20))
853 /* Use strncmp to be safe. */
854 *default_map
|= optionP
[i
].or;
855 *default_map
&= optionP
[i
].and;
861 as_warn (_("No such entry in list. (cpu/mmu register)"));
866 evaluate_expr (resultP
, ptr
)
867 expressionS
*resultP
;
870 register char *tmp_line
;
872 tmp_line
= input_line_pointer
;
873 input_line_pointer
= ptr
;
875 input_line_pointer
= tmp_line
;
878 /* Convert operands to iif-format and adds bitfields to the opcode.
879 Operands are parsed in such an order that the opcode is updated from
880 its most significant bit, that is when the operand need to alter the
882 Be carefull not to put to objects in the same iif-slot. */
885 encode_operand (argc
, argv
, operandsP
, suffixP
, im_size
, opcode_bit_ptr
)
895 int pcrel
, tmp
, b
, loop
, pcrel_adjust
;
897 for (loop
= 0; loop
< argc
; loop
++)
899 /* What operand are we supposed to work on. */
900 i
= operandsP
[loop
<< 1] - '1';
902 as_fatal (_("Internal consistency error. check ns32k-opcode.h"));
908 switch ((d
= operandsP
[(loop
<< 1) + 1]))
910 case 'f': /* operand of sfsr turns out to be a nasty
913 case 'Z': /* float not immediate */
914 case 'F': /* 32 bit float general form */
915 case 'L': /* 64 bit float */
916 case 'I': /* integer not immediate */
919 case 'D': /* double-word */
920 case 'A': /* double-word gen-address-form ie no regs
922 get_addr_mode (argv
[i
], &addr_modeP
);
924 if ((addr_modeP
.mode
== 20) &&
925 (d
== 'I' || d
== 'Z' || d
== 'A'))
926 as_fatal (d
== 'A'? _("Address of immediate operand"):
927 _("Invalid immediate write operand."));
929 if (opcode_bit_ptr
== desc
->opcode_size
)
934 for (j
= b
; j
< (b
+ 2); j
++)
936 if (addr_modeP
.disp
[j
- b
])
940 addr_modeP
.disp_suffix
[j
- b
],
941 (unsigned long) addr_modeP
.disp
[j
- b
],
948 (addr_modeP
.scaled_reg
? addr_modeP
.scaled_mode
955 iif
.iifP
[1].object
|= ((long) addr_modeP
.mode
) << opcode_bit_ptr
;
957 if (addr_modeP
.scaled_reg
)
960 IIF (j
, 1, 1, (unsigned long) addr_modeP
.index_byte
,
961 0, 0, 0, 0, 0, NULL
, -1, 0);
965 case 'b': /* multiple instruction disp */
966 freeptr
++; /* OVE:this is an useful hack */
967 sprintf (freeptr
, "((%s-1)*%d)\000", argv
[i
], desc
->im_size
);
969 pcrel
-= 1; /* make pcrel 0 inspite of what case 'p':
972 case 'p': /* displacement - pc relative addressing */
975 case 'd': /* displacement */
976 iif
.instr_size
+= suffixP
[i
] ? suffixP
[i
] : 4;
977 IIF (12, 2, suffixP
[i
], (unsigned long) argv
[i
], 0,
978 pcrel
, pcrel_adjust
, 1, IND (BRANCH
, BYTE
), NULL
, -1, 0);
980 case 'H': /* sequent-hack: the linker wants a bit set
983 iif
.instr_size
+= suffixP
[i
] ? suffixP
[i
] : 4;
984 IIF (12, 2, suffixP
[i
], (unsigned long) argv
[i
], 0,
985 pcrel
, pcrel_adjust
, 1, IND (BRANCH
, BYTE
), NULL
, -1, 1);
987 case 'q': /* quick */
989 IIF (11, 2, 42, (unsigned long) argv
[i
], 0, 0, 0, 0, 0,
990 bit_fix_new (4, opcode_bit_ptr
, -8, 7, 0, 1, 0), -1, 0);
992 case 'r': /* register number (3 bits) */
993 list_search (argv
[i
], opt6
, &tmp
);
995 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
997 case 'O': /* setcfg instruction optionslist */
998 optlist (argv
[i
], opt3
, &tmp
);
1000 iif
.iifP
[1].object
|= tmp
<< 15;
1002 case 'C': /* cinv instruction optionslist */
1003 optlist (argv
[i
], opt4
, &tmp
);
1004 opcode_bit_ptr
-= 4;
1005 iif
.iifP
[1].object
|= tmp
<< 15; /* insert the regtype in opcode */
1007 case 'S': /* stringinstruction optionslist */
1008 optlist (argv
[i
], opt5
, &tmp
);
1009 opcode_bit_ptr
-= 4;
1010 iif
.iifP
[1].object
|= tmp
<< 15;
1013 case 'U': /* registerlist */
1014 IIF (10, 1, 1, 0, 0, 0, 0, 0, 0, NULL
, -1, 0);
1015 switch (operandsP
[(i
<< 1) + 1])
1017 case 'u': /* restore, exit */
1018 optlist (argv
[i
], opt1
, &iif
.iifP
[10].object
);
1020 case 'U': /* save,enter */
1021 optlist (argv
[i
], opt2
, &iif
.iifP
[10].object
);
1024 iif
.instr_size
+= 1;
1026 case 'M': /* mmu register */
1027 list_search (argv
[i
], mmureg
, &tmp
);
1028 opcode_bit_ptr
-= 4;
1029 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
1031 case 'P': /* cpu register */
1032 list_search (argv
[i
], cpureg
, &tmp
);
1033 opcode_bit_ptr
-= 4;
1034 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
1036 case 'g': /* inss exts */
1037 iif
.instr_size
+= 1; /* 1 byte is allocated after the opcode */
1039 (unsigned long) argv
[i
], /* i always 2 here */
1041 bit_fix_new (3, 5, 0, 7, 0, 0, 0), /* a bit_fix is targeted to
1047 (unsigned long) argv
[i
], /* i always 3 here */
1049 bit_fix_new (5, 0, 1, 32, -1, 0, -1), -1, 0);
1052 iif
.instr_size
+= 1;
1053 b
= 2 + i
; /* put the extension byte after opcode */
1054 IIF (b
, 2, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0);
1057 as_fatal (_("Bad opcode-table-option, check in file ns32k-opcode.h"));
1062 /* in: instruction line
1063 out: internal structure of instruction
1064 that has been prepared for direct conversion to fragment(s) and
1065 fixes in a systematical fashion
1066 Return-value = recursive_level. */
1067 /* Build iif of one assembly text line. */
1070 parse (line
, recursive_level
)
1072 int recursive_level
;
1074 register char *lineptr
, c
, suffix_separator
;
1078 char suffix
[MAX_ARGS
], *argv
[MAX_ARGS
]; /* No more than 4 operands. */
1080 if (recursive_level
<= 0)
1082 /* Called from md_assemble. */
1083 for (lineptr
= line
; (*lineptr
) != '\0' && (*lineptr
) != ' '; lineptr
++)
1089 if (!(desc
= (struct ns32k_opcode
*) hash_find (inst_hash_handle
, line
)))
1090 as_fatal (_("No such opcode"));
1101 if (*desc
->operands
)
1103 if (*lineptr
++ != '\0')
1108 while (*lineptr
!= '\0')
1110 if (desc
->operands
[argc
<< 1])
1113 arg_type
= desc
->operands
[(argc
<< 1) + 1];
1121 /* The operand is supposed to be a displacement. */
1122 /* Hackwarning: do not forget to update the 4
1123 cases above when editing ns32k-opcode.h. */
1124 suffix_separator
= ':';
1127 /* If this char occurs we loose. */
1128 suffix_separator
= '\255';
1132 suffix
[argc
] = 0; /* 0 when no ':' is encountered */
1133 argv
[argc
] = freeptr
;
1136 while ((c
= *lineptr
) != '\0' && c
!= sep
)
1152 if (c
== suffix_separator
)
1154 /* ':' - label/suffix separator. */
1167 as_warn (_("Bad suffix, defaulting to d"));
1169 if (lineptr
[1] == '\0' || lineptr
[1] == sep
)
1188 if (*lineptr
== '\0')
1195 as_fatal (_("Too many operands passed to instruction"));
1201 if (argc
!= strlen (desc
->operands
) / 2)
1203 if (strlen (desc
->default_args
))
1205 /* We can apply default, don't goof. */
1206 if (parse (desc
->default_args
, 1) != 1)
1207 /* Check error in default. */
1208 as_fatal (_("Wrong numbers of operands in default, check ns32k-opcodes.h"));
1212 as_fatal (_("Wrong number of operands"));
1216 for (i
= 0; i
< IIF_ENTRIES
; i
++)
1217 /* Mark all entries as void. */
1218 iif
.iifP
[i
].type
= 0;
1220 /* Build opcode iif-entry. */
1221 iif
.instr_size
= desc
->opcode_size
/ 8;
1222 IIF (1, 1, iif
.instr_size
, desc
->opcode_seed
, 0, 0, 0, 0, 0, 0, -1, 0);
1224 /* This call encodes operands to iif format. */
1227 encode_operand (argc
,
1234 return recursive_level
;
1237 /* Convert iif to fragments. From this point we start to dribble with
1238 functions in other files than this one.(Except hash.c) So, if it's
1239 possible to make an iif for an other CPU, you don't need to know
1240 what frags, relax, obstacks, etc is in order to port this
1241 assembler. You only need to know if it's possible to reduce your
1242 cpu-instruction to iif-format (takes some work) and adopt the other
1243 md_? parts according to given instructions Note that iif was
1244 invented for the clean ns32k`s architecure. */
1246 /* GAS for the ns32k has a problem. PC relative displacements are
1247 relative to the address of the opcode, not the address of the
1248 operand. We used to keep track of the offset between the operand
1249 and the opcode in pcrel_adjust for each frag and each fix. However,
1250 we get into trouble where there are two or more pc-relative
1251 operands and the size of the first one can't be determined. Then in
1252 the relax phase, the size of the first operand will change and
1253 pcrel_adjust will no longer be correct. The current solution is
1254 keep a pointer to the frag with the opcode in it and the offset in
1255 that frag for each frag and each fix. Then, when needed, we can
1256 always figure out how far it is between the opcode and the pcrel
1257 object. See also md_pcrel_adjust and md_fix_pcrel_adjust. For
1258 objects not part of an instruction, the pointer to the opcode frag
1267 unsigned int inst_offset
;
1276 memP
= frag_more (0);
1278 inst_offset
= (memP
- frag_now
->fr_literal
);
1279 inst_frag
= frag_now
;
1281 for (i
= 0; i
< IIF_ENTRIES
; i
++)
1283 if (type
= iif
.iifP
[i
].type
)
1285 /* The object exist, so handle it. */
1286 switch (size
= iif
.iifP
[i
].size
)
1290 /* It's a bitfix that operates on an existing object. */
1291 if (iif
.iifP
[i
].bit_fixP
->fx_bit_base
)
1292 /* Expand fx_bit_base to point at opcode. */
1293 iif
.iifP
[i
].bit_fixP
->fx_bit_base
= (long) inst_opcode
;
1296 case 8: /* bignum or doublefloat */
1301 /* The final size in objectmemory is known. */
1302 memP
= frag_more (size
);
1303 j
= iif
.iifP
[i
].bit_fixP
;
1307 case 1: /* The object is pure binary. */
1308 if (j
|| iif
.iifP
[i
].pcrel
)
1310 fix_new_ns32k (frag_now
,
1311 (long) (memP
- frag_now
->fr_literal
),
1316 iif
.iifP
[i
].im_disp
,
1318 iif
.iifP
[i
].bsr
, /* sequent hack */
1319 inst_frag
, inst_offset
);
1323 /* Good, just put them bytes out. */
1324 switch (iif
.iifP
[i
].im_disp
)
1327 md_number_to_chars (memP
, iif
.iifP
[i
].object
, size
);
1330 md_number_to_disp (memP
, iif
.iifP
[i
].object
, size
);
1333 as_fatal (_("iif convert internal pcrel/binary"));
1339 /* The object is a pointer at an expression, so
1340 unpack it, note that bignums may result from the
1342 evaluate_expr (&exprP
, (char *) iif
.iifP
[i
].object
);
1343 if (exprP
.X_op
== O_big
|| size
== 8)
1345 if ((k
= exprP
.X_add_number
) > 0)
1347 /* We have a bignum ie a quad. This can only
1348 happens in a long suffixed instruction. */
1350 as_warn (_("Bignum too big for long"));
1355 for (l
= 0; k
> 0; k
--, l
+= 2)
1357 md_number_to_chars (memP
+ l
,
1358 generic_bignum
[l
>> 1],
1359 sizeof (LITTLENUM_TYPE
));
1365 LITTLENUM_TYPE words
[4];
1370 gen_to_words (words
, 2, 8);
1371 md_number_to_imm (memP
, (long) words
[0],
1372 sizeof (LITTLENUM_TYPE
));
1373 md_number_to_imm (memP
+ sizeof (LITTLENUM_TYPE
),
1375 sizeof (LITTLENUM_TYPE
));
1378 gen_to_words (words
, 4, 11);
1379 md_number_to_imm (memP
, (long) words
[0],
1380 sizeof (LITTLENUM_TYPE
));
1381 md_number_to_imm (memP
+ sizeof (LITTLENUM_TYPE
),
1383 sizeof (LITTLENUM_TYPE
));
1384 md_number_to_imm ((memP
+ 2
1385 * sizeof (LITTLENUM_TYPE
)),
1387 sizeof (LITTLENUM_TYPE
));
1388 md_number_to_imm ((memP
+ 3
1389 * sizeof (LITTLENUM_TYPE
)),
1391 sizeof (LITTLENUM_TYPE
));
1398 exprP
.X_add_symbol
||
1399 exprP
.X_op_symbol
||
1402 /* The expression was undefined due to an
1403 undefined label. Create a fix so we can fix
1404 the object later. */
1405 exprP
.X_add_number
+= iif
.iifP
[i
].object_adjust
;
1406 fix_new_ns32k_exp (frag_now
,
1407 (long) (memP
- frag_now
->fr_literal
),
1411 iif
.iifP
[i
].im_disp
,
1414 inst_frag
, inst_offset
);
1418 /* Good, just put them bytes out. */
1419 switch (iif
.iifP
[i
].im_disp
)
1422 md_number_to_imm (memP
, exprP
.X_add_number
, size
);
1425 md_number_to_disp (memP
, exprP
.X_add_number
, size
);
1428 as_fatal (_("iif convert internal pcrel/pointer"));
1433 as_fatal (_("Internal logic error in iif.iifP[n].type"));
1438 /* Too bad, the object may be undefined as far as its
1439 final nsize in object memory is concerned. The size
1440 of the object in objectmemory is not explicitly
1441 given. If the object is defined its length can be
1442 determined and a fix can replace the frag. */
1444 evaluate_expr (&exprP
, (char *) iif
.iifP
[i
].object
);
1446 if ((exprP
.X_add_symbol
|| exprP
.X_op_symbol
) &&
1449 /* Size is unknown until link time so have to
1452 memP
= frag_more (size
);
1453 fix_new_ns32k_exp (frag_now
,
1454 (long) (memP
- frag_now
->fr_literal
),
1457 0, /* never iif.iifP[i].pcrel, */
1458 1, /* always iif.iifP[i].im_disp */
1462 break; /* exit this absolute hack */
1465 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
1468 if (exprP
.X_op_symbol
)
1470 /* We cant relax this case. */
1471 as_fatal (_("Can't relax difference"));
1475 /* Size is not important. This gets fixed by
1476 relax, but we assume 0 in what follows. */
1477 memP
= frag_more (4); /* Max size. */
1481 fragS
*old_frag
= frag_now
;
1482 frag_variant (rs_machine_dependent
,
1485 IND (BRANCH
, UNDEF
), /* Expecting
1490 frag_opcode_frag (old_frag
) = inst_frag
;
1491 frag_opcode_offset (old_frag
) = inst_offset
;
1492 frag_bsr (old_frag
) = iif
.iifP
[i
].bsr
;
1498 /* This duplicates code in md_number_to_disp. */
1499 if (-64 <= exprP
.X_add_number
&& exprP
.X_add_number
<= 63)
1505 if (-8192 <= exprP
.X_add_number
1506 && exprP
.X_add_number
<= 8191)
1512 if (-0x20000000 <= exprP
.X_add_number
1513 && exprP
.X_add_number
<=0x1fffffff)
1519 as_warn (_("Displacement to large for :d"));
1525 memP
= frag_more (size
);
1526 md_number_to_disp (memP
, exprP
.X_add_number
, size
);
1532 as_fatal (_("Internal logic error in iif.iifP[].type"));
1538 #ifdef BFD_ASSEMBLER
1539 /* This functionality should really be in the bfd library. */
1540 static bfd_reloc_code_real_type
1541 reloc (int size
, int pcrel
, int type
)
1544 bfd_reloc_code_real_type relocs
[] =
1546 BFD_RELOC_NS32K_IMM_8
,
1547 BFD_RELOC_NS32K_IMM_16
,
1548 BFD_RELOC_NS32K_IMM_32
,
1549 BFD_RELOC_NS32K_IMM_8_PCREL
,
1550 BFD_RELOC_NS32K_IMM_16_PCREL
,
1551 BFD_RELOC_NS32K_IMM_32_PCREL
,
1553 /* ns32k displacements. */
1554 BFD_RELOC_NS32K_DISP_8
,
1555 BFD_RELOC_NS32K_DISP_16
,
1556 BFD_RELOC_NS32K_DISP_32
,
1557 BFD_RELOC_NS32K_DISP_8_PCREL
,
1558 BFD_RELOC_NS32K_DISP_16_PCREL
,
1559 BFD_RELOC_NS32K_DISP_32_PCREL
,
1561 /* Normal 2's complement. */
1586 index
= length
+ 3 * pcrel
+ 6 * type
;
1588 if (index
>= 0 && index
< sizeof (relocs
) / sizeof (relocs
[0]))
1589 return relocs
[index
];
1592 as_bad (_("Can not do %d byte pc-relative relocation for storage type %d"),
1595 as_bad (_("Can not do %d byte relocation for storage type %d"),
1598 return BFD_RELOC_NONE
;
1607 freeptr
= freeptr_static
;
1608 parse (line
, 0); /* Explode line to more fix form in iif. */
1609 convert_iif (); /* Convert iif to frags, fix's etc. */
1611 printf (" \t\t\t%s\n", line
);
1618 /* Build a hashtable of the instructions. */
1619 const struct ns32k_opcode
*ptr
;
1621 inst_hash_handle
= hash_new ();
1623 for (ptr
= ns32k_opcodes
; ptr
< endop
; ptr
++)
1625 if ((stat
= hash_insert (inst_hash_handle
, ptr
->name
, (char *) ptr
)))
1627 as_fatal (_("Can't hash %s: %s"), ptr
->name
, stat
);
1630 /* Some private space please! */
1631 freeptr_static
= (char *) malloc (PRIVATE_SIZE
);
1634 /* Must be equal to MAX_PRECISON in atof-ieee.c. */
1635 #define MAX_LITTLENUMS 6
1637 /* Turn the string pointed to by litP into a floating point constant
1638 of type TYPE, and emit the appropriate bytes. The number of
1639 LITTLENUMS emitted is stored in *SIZEP. An error message is
1640 returned, or NULL on OK. */
1643 md_atof (type
, litP
, sizeP
)
1649 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1650 LITTLENUM_TYPE
*wordP
;
1664 return _("Bad call to MD_ATOF()");
1667 t
= atof_ieee (input_line_pointer
, type
, words
);
1669 input_line_pointer
= t
;
1671 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1673 for (wordP
= words
+ prec
; prec
--;)
1675 md_number_to_chars (litP
, (long) (*--wordP
), sizeof (LITTLENUM_TYPE
));
1676 litP
+= sizeof (LITTLENUM_TYPE
);
1682 /* Convert number to chars in correct order. */
1685 md_number_to_chars (buf
, value
, nbytes
)
1690 number_to_chars_littleendian (buf
, value
, nbytes
);
1693 /* This is a variant of md_numbers_to_chars. The reason for its'
1694 existence is the fact that ns32k uses Huffman coded
1695 displacements. This implies that the bit order is reversed in
1696 displacements and that they are prefixed with a size-tag.
1700 10xxxxxx xxxxxxxx word
1701 11xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx double word
1703 This must be taken care of and we do it here! */
1706 md_number_to_disp (buf
, val
, n
)
1714 if (val
< -64 || val
> 63)
1715 as_warn (_("Byte displacement out of range. line number not valid"));
1718 printf ("%x ", val
& 0xff);
1723 if (val
< -8192 || val
> 8191)
1724 as_warn (_("Word displacement out of range. line number not valid"));
1728 printf ("%x ", val
>> 8 & 0xff);
1730 *buf
++ = (val
>> 8);
1732 printf ("%x ", val
& 0xff);
1737 if (val
< -0x20000000 || val
>= 0x20000000)
1738 as_warn (_("Double word displacement out of range"));
1741 printf ("%x ", val
>> 24 & 0xff);
1743 *buf
++ = (val
>> 24);
1745 printf ("%x ", val
>> 16 & 0xff);
1747 *buf
++ = (val
>> 16);
1749 printf ("%x ", val
>> 8 & 0xff);
1751 *buf
++ = (val
>> 8);
1753 printf ("%x ", val
& 0xff);
1758 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1759 __LINE__
, __FILE__
);
1764 md_number_to_imm (buf
, val
, n
)
1773 printf ("%x ", val
& 0xff);
1779 printf ("%x ", val
>> 8 & 0xff);
1781 *buf
++ = (val
>> 8);
1783 printf ("%x ", val
& 0xff);
1789 printf ("%x ", val
>> 24 & 0xff);
1791 *buf
++ = (val
>> 24);
1793 printf ("%x ", val
>> 16 & 0xff);
1795 *buf
++ = (val
>> 16);
1797 printf ("%x ", val
>> 8 & 0xff);
1799 *buf
++ = (val
>> 8);
1801 printf ("%x ", val
& 0xff);
1806 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1807 __LINE__
, __FILE__
);
1811 /* Fast bitfiddling support. */
1812 /* Mask used to zero bitfield before oring in the true field. */
1814 static unsigned long l_mask
[] =
1816 0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
1817 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
1818 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
1819 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
1820 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
1821 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
1822 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
1823 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
1825 static unsigned long r_mask
[] =
1827 0x00000000, 0x00000001, 0x00000003, 0x00000007,
1828 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
1829 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
1830 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
1831 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
1832 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
1833 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
1834 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
1836 #define MASK_BITS 31
1837 /* Insert bitfield described by field_ptr and val at buf
1838 This routine is written for modification of the first 4 bytes pointed
1839 to by buf, to yield speed.
1840 The ifdef stuff is for selection between a ns32k-dependent routine
1841 and a general version. (My advice: use the general version!). */
1844 md_number_to_field (buf
, val
, field_ptr
)
1847 register bit_fixS
*field_ptr
;
1849 register unsigned long object
;
1850 register unsigned long mask
;
1851 /* define ENDIAN on a ns32k machine */
1853 register unsigned long *mem_ptr
;
1855 register char *mem_ptr
;
1857 if (field_ptr
->fx_bit_min
<= val
&& val
<= field_ptr
->fx_bit_max
)
1860 if (field_ptr
->fx_bit_base
)
1862 mem_ptr
= (unsigned long *) field_ptr
->fx_bit_base
;
1864 mem_ptr
= (unsigned long *) buf
;
1866 mem_ptr
= ((unsigned long *)
1867 ((char *) mem_ptr
+ field_ptr
->fx_bit_base_adj
));
1869 if (field_ptr
->fx_bit_base
)
1870 mem_ptr
= (char *) field_ptr
->fx_bit_base
;
1874 mem_ptr
+= field_ptr
->fx_bit_base_adj
;
1877 /* We have a nice ns32k machine with lowbyte at low-physical mem. */
1878 object
= *mem_ptr
; /* get some bytes */
1879 #else /* OVE Goof! the machine is a m68k or dito */
1880 /* That takes more byte fiddling. */
1882 object
|= mem_ptr
[3] & 0xff;
1884 object
|= mem_ptr
[2] & 0xff;
1886 object
|= mem_ptr
[1] & 0xff;
1888 object
|= mem_ptr
[0] & 0xff;
1891 mask
|= (r_mask
[field_ptr
->fx_bit_offset
]);
1892 mask
|= (l_mask
[field_ptr
->fx_bit_offset
+ field_ptr
->fx_bit_size
]);
1894 val
+= field_ptr
->fx_bit_add
;
1895 object
|= ((val
<< field_ptr
->fx_bit_offset
) & (mask
^ 0xffffffff));
1899 mem_ptr
[0] = (char) object
;
1901 mem_ptr
[1] = (char) object
;
1903 mem_ptr
[2] = (char) object
;
1905 mem_ptr
[3] = (char) object
;
1910 as_warn (_("Bit field out of range"));
1915 md_pcrel_adjust (fragP
)
1919 addressT opcode_address
;
1920 unsigned int offset
;
1922 opcode_frag
= frag_opcode_frag (fragP
);
1923 if (opcode_frag
== 0)
1926 offset
= frag_opcode_offset (fragP
);
1927 opcode_address
= offset
+ opcode_frag
->fr_address
;
1929 return fragP
->fr_address
+ fragP
->fr_fix
- opcode_address
;
1933 md_fix_pcrel_adjust (fixP
)
1936 fragS
*fragP
= fixP
->fx_frag
;
1938 addressT opcode_address
;
1939 unsigned int offset
;
1941 opcode_frag
= fix_opcode_frag (fixP
);
1942 if (opcode_frag
== 0)
1945 offset
= fix_opcode_offset (fixP
);
1946 opcode_address
= offset
+ opcode_frag
->fr_address
;
1948 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- opcode_address
;
1951 /* Apply a fixS (fixup of an instruction or data that we didn't have
1952 enough info to complete immediately) to the data in a frag.
1954 On the ns32k, everything is in a different format, so we have broken
1955 out separate functions for each kind of thing we could be fixing.
1956 They all get called from here. */
1958 #ifdef BFD_ASSEMBLER
1960 md_apply_fix (fixP
, valp
)
1965 md_apply_fix (fixP
, val
)
1970 #ifdef BFD_ASSEMBLER
1973 fragS
*fragP
= fixP
->fx_frag
;
1975 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1977 if (fix_bit_fixP (fixP
))
1978 { /* Bitfields to fix, sigh. */
1979 md_number_to_field (buf
, val
, fix_bit_fixP (fixP
));
1982 switch (fix_im_disp (fixP
))
1984 case 0: /* Immediate field. */
1985 md_number_to_imm (buf
, val
, fixP
->fx_size
);
1988 case 1: /* Displacement field. */
1989 /* Calculate offset */
1991 md_number_to_disp (buf
,
1992 (fixP
->fx_pcrel
? val
+ md_fix_pcrel_adjust (fixP
)
1993 : val
), fixP
->fx_size
);
1997 case 2: /* Pointer in a data object. */
1998 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2001 #ifdef BSD_ASSEMBLER
2006 /* Convert a relaxed displacement to ditto in final output */
2008 #ifndef BFD_ASSEMBLER
2010 md_convert_frag (headers
, sec
, fragP
)
2011 object_headers
*headers
;
2013 register fragS
*fragP
;
2016 md_convert_frag (abfd
, sec
, fragP
)
2019 register fragS
*fragP
;
2025 /* Address in gas core of the place to store the displacement. */
2026 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
2027 /* Address in object code of the displacement. */
2032 switch (fragP
->fr_subtype
)
2034 case IND (BRANCH
, BYTE
):
2037 case IND (BRANCH
, WORD
):
2040 case IND (BRANCH
, DOUBLE
):
2048 know (fragP
->fr_symbol
);
2050 object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
2052 /* The displacement of the address, from current location. */
2053 disp
= (S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
) - object_address
;
2054 disp
+= md_pcrel_adjust (fragP
);
2056 md_number_to_disp (buffer_address
, (long) disp
, (int) ext
);
2057 fragP
->fr_fix
+= ext
;
2060 /* This function returns the estimated size a variable object will occupy,
2061 one can say that we tries to guess the size of the objects before we
2062 actually know it. */
2065 md_estimate_size_before_relax (fragP
, segment
)
2066 register fragS
*fragP
;
2069 if (fragP
->fr_subtype
== IND (BRANCH
, UNDEF
))
2071 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
)
2073 /* We don't relax symbols defined in another segment. The
2074 thing to do is to assume the object will occupy 4 bytes. */
2075 fix_new_ns32k (fragP
,
2076 (int) (fragP
->fr_fix
),
2083 frag_bsr(fragP
), /*sequent hack */
2084 frag_opcode_frag (fragP
),
2085 frag_opcode_offset (fragP
));
2088 fragP
->fr_opcode
[1] = 0xff;
2094 /* Relaxable case. Set up the initial guess for the variable
2095 part of the frag. */
2096 fragP
->fr_subtype
= IND (BRANCH
, BYTE
);
2099 if (fragP
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
2102 /* Return the size of the variable part of the frag. */
2103 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2106 int md_short_jump_size
= 3;
2107 int md_long_jump_size
= 5;
2108 const int md_reloc_size
= 8; /* Size of relocation record. */
2111 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2113 addressT from_addr
, to_addr
;
2119 offset
= to_addr
- from_addr
;
2120 md_number_to_chars (ptr
, (valueT
) 0xEA, 1);
2121 md_number_to_disp (ptr
+ 1, (valueT
) offset
, 2);
2125 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2127 addressT from_addr
, to_addr
;
2133 offset
= to_addr
- from_addr
;
2134 md_number_to_chars (ptr
, (valueT
) 0xEA, 1);
2135 md_number_to_disp (ptr
+ 1, (valueT
) offset
, 4);
2138 CONST
char *md_shortopts
= "m:";
2140 struct option md_longopts
[] =
2142 {NULL
, no_argument
, NULL
, 0}
2145 size_t md_longopts_size
= sizeof (md_longopts
);
2148 md_parse_option (c
, arg
)
2155 if (!strcmp (arg
, "32032"))
2157 cpureg
= cpureg_032
;
2158 mmureg
= mmureg_032
;
2160 else if (!strcmp (arg
, "32532"))
2162 cpureg
= cpureg_532
;
2163 mmureg
= mmureg_532
;
2167 as_bad (_("invalid architecture option -m%s"), arg
);
2180 md_show_usage (stream
)
2183 fprintf (stream
, _("\
2185 -m32032 | -m32532 select variant of NS32K architecture\n"));
2188 /* Create a bit_fixS in obstack 'notes'.
2189 This struct is used to profile the normal fix. If the bit_fixP is a
2190 valid pointer (not NULL) the bit_fix data will be used to format
2194 bit_fix_new (size
, offset
, min
, max
, add
, base_type
, base_adj
)
2195 char size
; /* Length of bitfield */
2196 char offset
; /* Bit offset to bitfield */
2197 long min
; /* Signextended min for bitfield */
2198 long max
; /* Signextended max for bitfield */
2199 long add
; /* Add mask, used for huffman prefix */
2200 long base_type
; /* 0 or 1, if 1 it's exploded to opcode ptr */
2203 register bit_fixS
*bit_fixP
;
2205 bit_fixP
= (bit_fixS
*) obstack_alloc (¬es
, sizeof (bit_fixS
));
2207 bit_fixP
->fx_bit_size
= size
;
2208 bit_fixP
->fx_bit_offset
= offset
;
2209 bit_fixP
->fx_bit_base
= base_type
;
2210 bit_fixP
->fx_bit_base_adj
= base_adj
;
2211 bit_fixP
->fx_bit_max
= max
;
2212 bit_fixP
->fx_bit_min
= min
;
2213 bit_fixP
->fx_bit_add
= add
;
2219 fix_new_ns32k (frag
, where
, size
, add_symbol
, offset
, pcrel
,
2220 im_disp
, bit_fixP
, bsr
, opcode_frag
, opcode_offset
)
2221 fragS
*frag
; /* Which frag? */
2222 int where
; /* Where in that frag? */
2223 int size
; /* 1, 2 or 4 usually. */
2224 symbolS
*add_symbol
; /* X_add_symbol. */
2225 long offset
; /* X_add_number. */
2226 int pcrel
; /* TRUE if PC-relative relocation. */
2227 char im_disp
; /* true if the value to write is a
2229 bit_fixS
*bit_fixP
; /* pointer at struct of bit_fix's, ignored if
2231 char bsr
; /* sequent-linker-hack: 1 when relocobject is
2234 unsigned int opcode_offset
;
2236 fixS
*fixP
= fix_new (frag
, where
, size
, add_symbol
,
2238 #ifdef BFD_ASSEMBLER
2239 bit_fixP
? NO_RELOC
: reloc (size
, pcrel
, im_disp
)
2245 fix_opcode_frag (fixP
) = opcode_frag
;
2246 fix_opcode_offset (fixP
) = opcode_offset
;
2247 fix_im_disp (fixP
) = im_disp
;
2248 fix_bsr (fixP
) = bsr
;
2249 fix_bit_fixP (fixP
) = bit_fixP
;
2253 fix_new_ns32k_exp (frag
, where
, size
, exp
, pcrel
,
2254 im_disp
, bit_fixP
, bsr
, opcode_frag
, opcode_offset
)
2255 fragS
*frag
; /* Which frag? */
2256 int where
; /* Where in that frag? */
2257 int size
; /* 1, 2 or 4 usually. */
2258 expressionS
*exp
; /* Expression. */
2259 int pcrel
; /* TRUE if PC-relative relocation. */
2260 char im_disp
; /* true if the value to write is a
2262 bit_fixS
*bit_fixP
; /* pointer at struct of bit_fix's, ignored if
2264 char bsr
; /* sequent-linker-hack: 1 when relocobject is
2267 unsigned int opcode_offset
;
2269 fixS
*fixP
= fix_new_exp (frag
, where
, size
, exp
, pcrel
,
2270 #ifdef BFD_ASSEMBLER
2271 bit_fixP
? NO_RELOC
: reloc (size
, pcrel
, im_disp
)
2277 fix_opcode_frag (fixP
) = opcode_frag
;
2278 fix_opcode_offset (fixP
) = opcode_offset
;
2279 fix_im_disp (fixP
) = im_disp
;
2280 fix_bsr (fixP
) = bsr
;
2281 fix_bit_fixP (fixP
) = bit_fixP
;
2284 /* This is TC_CONS_FIX_NEW, called by emit_expr in read.c. */
2287 cons_fix_new_ns32k (frag
, where
, size
, exp
)
2288 fragS
*frag
; /* Which frag? */
2289 int where
; /* Where in that frag? */
2290 int size
; /* 1, 2 or 4 usually. */
2291 expressionS
*exp
; /* Expression. */
2293 fix_new_ns32k_exp (frag
, where
, size
, exp
,
2297 /* We have no need to default values of symbols. */
2300 md_undefined_symbol (name
)
2306 /* Round up a section size to the appropriate boundary. */
2309 md_section_align (segment
, size
)
2313 return size
; /* Byte alignment is fine. */
2316 /* Exactly what point is a PC-relative offset relative TO? On the
2317 ns32k, they're relative to the start of the instruction. */
2320 md_pcrel_from (fixP
)
2324 res
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2325 #ifdef SEQUENT_COMPATABILITY
2326 if (frag_bsr (fixP
->fx_frag
))
2327 res
+= 0x12 /* FOO Kludge alert! */
2332 #ifdef BFD_ASSEMBLER
2335 tc_gen_reloc (section
, fixp
)
2340 bfd_reloc_code_real_type code
;
2342 code
= reloc (fixp
->fx_size
, fixp
->fx_pcrel
, fix_im_disp (fixp
));
2344 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2345 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2346 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2347 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2349 rel
->addend
= fixp
->fx_addnumber
;
2353 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2358 name
= S_GET_NAME (fixp
->fx_addsy
);
2360 name
= _("<unknown>");
2361 as_fatal (_("Cannot find relocation type for symbol %s, code %d"),
2367 #else /* BFD_ASSEMBLER */
2371 cons_fix_new_ns32k (where
, fixP
, segment_address_in_file
)
2374 relax_addressT segment_address_in_file
;
2376 /* In: Length of relocation (or of address) in chars: 1, 2 or 4.
2377 Out: GNU LD relocation length code: 0, 1, or 2. */
2379 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
2382 know (fixP
->fx_addsy
!= NULL
);
2384 md_number_to_chars (where
,
2385 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2388 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
2389 ? S_GET_TYPE (fixP
->fx_addsy
)
2390 : fixP
->fx_addsy
->sy_number
);
2392 md_number_to_chars (where
+ 4,
2393 ((long) (r_symbolnum
)
2394 | (long) (fixP
->fx_pcrel
<< 24)
2395 | (long) (nbytes_r_length
[fixP
->fx_size
] << 25)
2396 | (long) ((!S_IS_DEFINED (fixP
->fx_addsy
)) << 27)
2397 | (long) (fix_bsr (fixP
) << 28)
2398 | (long) (fix_im_disp (fixP
) << 29)),
2402 #endif /* OBJ_AOUT */
2403 #endif /* BFD_ASSMEBLER */