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
[] = ";";
67 #if !defined(ABSOLUTE_PREFIX) && !defined(IMMEDIATE_PREFIX)
68 #define ABSOLUTE_PREFIX '@' /* One or the other MUST be defined */
73 char mode
; /* addressing mode of operand (0-31) */
74 char scaled_mode
; /* mode combined with scaled mode */
75 char scaled_reg
; /* register used in scaled+1 (1-8) */
76 char float_flag
; /* set if R0..R7 was F0..F7 ie a
77 floating-point-register */
78 char am_size
; /* estimated max size of general addr-mode
80 char im_disp
; /* if im_disp==1 we have a displacement */
81 char pcrel
; /* 1 if pcrel, this is really redundant info */
82 char disp_suffix
[2]; /* length of displacement(s), 0=undefined */
83 char *disp
[2]; /* pointer(s) at displacement(s)
84 or immediates(s) (ascii) */
85 char index_byte
; /* index byte */
87 typedef struct addr_mode addr_modeS
;
89 char *freeptr
, *freeptr_static
; /* Points at some number of free bytes. */
90 struct hash_control
*inst_hash_handle
;
92 struct ns32k_opcode
*desc
; /* Pointer at description of instruction. */
93 addr_modeS addr_modeP
;
94 const char EXP_CHARS
[] = "eE";
95 const char FLT_CHARS
[] = "fd"; /* We don't want to support lowercase,
98 /* UPPERCASE denotes live names when an instruction is built, IIF is
99 * used as an intermediate form to store the actual parts of the
100 * instruction. A ns32k machine instruction can be divided into a
101 * couple of sub PARTs. When an instruction is assembled the
102 * appropriate PART get an assignment. When an IIF has been completed
103 * it is converted to a FRAGment as specified in AS.H. */
105 /* Internal structs. */
115 int type
; /* how to interpret object */
116 int size
; /* Estimated max size of object */
117 unsigned long object
; /* binary data */
118 int object_adjust
; /* number added to object */
119 int pcrel
; /* True if object is pcrel */
120 int pcrel_adjust
; /* length in bytes from the
121 instruction start to the
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 *ptr
));
371 static void md_number_to_disp
PARAMS ((char *buf
, long val
, int n
));
372 static void md_number_to_imm
PARAMS ((char *buf
, long val
, int n
));
374 /* Parse a general operand into an addressingmode struct
376 In: pointer at operand in ascii form
377 pointer at addr_mode struct for result
378 the level of recursion. (always 0 or 1)
380 Out: data in addr_mode struct. */
383 addr_mode (operand
, addr_modeP
, recursive_level
)
385 register addr_modeS
*addr_modeP
;
394 mode
= DEFAULT
; /* default */
395 addr_modeP
->scaled_mode
= 0; /* why not */
396 addr_modeP
->scaled_reg
= 0; /* if 0, not scaled index */
397 addr_modeP
->float_flag
= 0;
398 addr_modeP
->am_size
= 0;
399 addr_modeP
->im_disp
= 0;
400 addr_modeP
->pcrel
= 0; /* not set in this function */
401 addr_modeP
->disp_suffix
[0] = 0;
402 addr_modeP
->disp_suffix
[1] = 0;
403 addr_modeP
->disp
[0] = NULL
;
404 addr_modeP
->disp
[1] = NULL
;
414 /* The following three case statements controls the mode-chars
415 this is the place to ed if you want to change them. */
416 #ifdef ABSOLUTE_PREFIX
417 case ABSOLUTE_PREFIX
:
418 if (str
[strl
- 1] == ']')
420 addr_modeP
->mode
= 21; /* absolute */
421 addr_modeP
->disp
[0] = str
+ 1;
424 #ifdef IMMEDIATE_PREFIX
425 case IMMEDIATE_PREFIX
:
426 if (str
[strl
- 1] == ']')
428 addr_modeP
->mode
= 20; /* immediate */
429 addr_modeP
->disp
[0] = str
+ 1;
433 if (str
[strl
- 1] != ']')
439 if (str
[2] != '\000')
441 addr_modeP
->mode
= 27; /* pc-relativ */
442 addr_modeP
->disp
[0] = str
+ 2;
446 as_warn (_("Invalid syntax in PC-relative addressing mode"));
452 if (str
[strl
- 1] != ']')
454 if ((!strncmp (str
, "ext(", 4)) && strl
> 7)
456 addr_modeP
->disp
[0] = str
+ 4;
460 { /* disp[0]'s termination point */
467 while (j
< strl
&& i
!= 0);
468 if (i
!= 0 || !(str
[j
+ 1] == '-' || str
[j
+ 1] == '+'))
470 as_warn (_("Invalid syntax in External addressing mode"));
473 str
[j
] = '\000'; /* null terminate disp[0] */
474 addr_modeP
->disp
[1] = str
+ j
+ 2;
475 addr_modeP
->mode
= 22;
493 addr_modeP
->float_flag
= 1;
496 if (str
[1] >= '0' && str
[1] < '8')
498 addr_modeP
->mode
= str
[1] - '0';
508 if (!strncmp (str
, "tos", 3))
510 addr_modeP
->mode
= 23; /* TopOfStack */
521 if (str
[strl
- 1] == ')')
523 if (str
[strl
- 2] == ')')
525 if (!strncmp (&str
[strl
- 5], "(fp", 3))
526 mode
= 16; /* Memory Relative. */
527 else if (!strncmp (&str
[strl
- 5], "(sp", 3))
529 else if (!strncmp (&str
[strl
- 5], "(sb", 3))
533 { /* Memory relative. */
534 addr_modeP
->mode
= mode
;
535 j
= strl
- 5; /* Temp for end of disp[0]. */
541 if (str
[strl
] == ')')
543 if (str
[strl
] == '(')
546 while (strl
> -1 && i
!= 0);
550 as_warn (_("Invalid syntax in Memory Relative addressing mode"));
554 addr_modeP
->disp
[1] = str
;
555 addr_modeP
->disp
[0] = str
+ strl
+ 1;
556 str
[j
] = '\000'; /* Null terminate disp[0] . */
557 str
[strl
] = '\000'; /* Null terminate disp[1]. */
563 switch (str
[strl
- 3])
567 if (str
[strl
- 2] >= '0'
568 && str
[strl
- 2] < '8'
569 && str
[strl
- 4] == '(')
571 addr_modeP
->mode
= str
[strl
- 2] - '0' + 8;
572 addr_modeP
->disp
[0] = str
;
574 return -1; /* reg rel */
579 if (!strncmp (&str
[strl
- 4], "(fp", 3))
581 else if (!strncmp (&str
[strl
- 4], "(sp", 3))
583 else if (!strncmp (&str
[strl
- 4], "(sb", 3))
585 else if (!strncmp (&str
[strl
- 4], "(pc", 3))
590 addr_modeP
->mode
= mode
;
591 addr_modeP
->disp
[0] = str
;
592 str
[strl
- 4] = '\0';
594 return -1; /* Memory space. */
599 /* No trailing ')' do we have a ']' ? */
600 if (str
[strl
- 1] == ']')
602 switch (str
[strl
- 2])
617 as_warn (_("Invalid scaled-indexed mode, use (b,w,d,q)"));
619 if (str
[strl
- 3] != ':' || str
[strl
- 6] != '['
620 || str
[strl
- 5] == 'r' || str
[strl
- 4] < '0'
621 || str
[strl
- 4] > '7')
622 as_warn (_("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"));
623 } /* Scaled index. */
625 if (recursive_level
> 0)
627 as_warn (_("Scaled-indexed addressing mode combined with scaled-index"));
631 addr_modeP
->am_size
+= 1; /* scaled index byte */
632 j
= str
[strl
- 4] - '0'; /* store temporary */
633 str
[strl
- 6] = '\000'; /* nullterminate for recursive call */
634 i
= addr_mode (str
, addr_modeP
, 1);
636 if (!i
|| addr_modeP
->mode
== 20)
638 as_warn (_("Invalid or illegal addressing mode combined with scaled-index"));
642 addr_modeP
->scaled_mode
= addr_modeP
->mode
; /* Store the inferior mode. */
643 addr_modeP
->mode
= mode
;
644 addr_modeP
->scaled_reg
= j
+ 1;
650 addr_modeP
->mode
= DEFAULT
; /* Default to whatever. */
651 addr_modeP
->disp
[0] = str
;
656 /* ptr points at string addr_modeP points at struct with result This
657 routine calls addr_mode to determine the general addr.mode of the
658 operand. When this is ready it parses the displacements for size
659 specifying suffixes and determines size of immediate mode via
660 ns32k-opcode. Also builds index bytes if needed. */
663 get_addr_mode (ptr
, addr_modeP
)
665 addr_modeS
*addr_modeP
;
669 addr_mode (ptr
, addr_modeP
, 0);
671 if (addr_modeP
->mode
== DEFAULT
|| addr_modeP
->scaled_mode
== -1)
673 /* Resolve ambigious operands, this shouldn't be necessary if
674 one uses standard NSC operand syntax. But the sequent
675 compiler doesn't!!! This finds a proper addressinging mode
676 if it is implicitly stated. See ns32k-opcode.h. */
677 (void) evaluate_expr (&exprP
, ptr
); /* This call takes time Sigh! */
679 if (addr_modeP
->mode
== DEFAULT
)
681 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
682 addr_modeP
->mode
= desc
->default_model
; /* We have a label. */
684 addr_modeP
->mode
= desc
->default_modec
; /* We have a constant. */
688 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
689 addr_modeP
->scaled_mode
= desc
->default_model
;
691 addr_modeP
->scaled_mode
= desc
->default_modec
;
694 /* Must put this mess down in addr_mode to handle the scaled
698 /* It appears as the sequent compiler wants an absolute when we have
699 a label without @. Constants becomes immediates besides the addr
700 case. Think it does so with local labels too, not optimum, pcrel
701 is better. When I have time I will make gas check this and
702 select pcrel when possible Actually that is trivial. */
703 if (tmp
= addr_modeP
->scaled_reg
)
704 { /* Build indexbyte. */
705 tmp
--; /* Remember regnumber comes incremented for
707 tmp
|= addr_modeP
->scaled_mode
<< 3;
708 addr_modeP
->index_byte
= (char) tmp
;
709 addr_modeP
->am_size
+= 1;
712 if (disp_test
[addr_modeP
->mode
])
715 register char suffix
;
716 register char suffix_sub
;
719 register char *fromP
;
721 /* There was a displacement, probe for length specifying suffix. */
722 addr_modeP
->pcrel
= 0;
724 if (disp_test
[addr_modeP
->mode
])
726 /* There is a displacement. */
727 if (addr_modeP
->mode
== 27 || addr_modeP
->scaled_mode
== 27)
728 /* Do we have pcrel. mode. */
729 addr_modeP
->pcrel
= 1;
731 addr_modeP
->im_disp
= 1;
733 for (i
= 0; i
< 2; i
++)
735 suffix_sub
= suffix
= 0;
737 if (toP
= addr_modeP
->disp
[i
])
739 /* Suffix of expression, the largest size rules. */
750 as_warn (_("Premature end of suffix -- Defaulting to d"));
763 as_warn (_("Bad suffix after ':' use {b|w|d} Defaulting to d"));
768 toP
--; /* So we write over the ':' */
770 if (suffix
< suffix_sub
)
775 *toP
= '\0'; /* Terminate properly. */
776 addr_modeP
->disp_suffix
[i
] = suffix
;
777 addr_modeP
->am_size
+= suffix
? suffix
: 4;
784 if (addr_modeP
->mode
== 20)
786 /* Look in ns32k_opcode for size. */
787 addr_modeP
->disp_suffix
[0] = addr_modeP
->am_size
= desc
->im_size
;
788 addr_modeP
->im_disp
= 0;
792 return addr_modeP
->mode
;
795 /* Read an optionlist. */
798 optlist (str
, optionP
, default_map
)
799 char *str
; /* The string to extract options from. */
800 struct ns32k_option
*optionP
; /* How to search the string. */
801 unsigned long *default_map
; /* Default pattern and output. */
803 register int i
, j
, k
, strlen1
, strlen2
;
804 register char *patternP
, *strP
;
806 strlen1
= strlen (str
);
809 as_fatal (_("Very short instr to option, ie you can't do it on a NULLstr"));
811 for (i
= 0; optionP
[i
].pattern
!= 0; i
++)
813 strlen2
= strlen (optionP
[i
].pattern
);
815 for (j
= 0; j
< strlen1
; j
++)
817 patternP
= optionP
[i
].pattern
;
820 for (k
= 0; k
< strlen2
; k
++)
822 if (*(strP
++) != *(patternP
++))
828 *default_map
|= optionP
[i
].or;
829 *default_map
&= optionP
[i
].and;
835 /* Search struct for symbols.
836 This function is used to get the short integer form of reg names in
837 the instructions lmr, smr, lpr, spr return true if str is found in
841 list_search (str
, optionP
, default_map
)
842 char *str
; /* The string to match. */
843 struct ns32k_option
*optionP
; /* List to search. */
844 unsigned long *default_map
; /* Default pattern and output. */
848 for (i
= 0; optionP
[i
].pattern
!= 0; i
++)
850 if (!strncmp (optionP
[i
].pattern
, str
, 20))
852 /* Use strncmp to be safe. */
853 *default_map
|= optionP
[i
].or;
854 *default_map
&= optionP
[i
].and;
860 as_warn (_("No such entry in list. (cpu/mmu register)"));
865 evaluate_expr (resultP
, ptr
)
866 expressionS
*resultP
;
869 register char *tmp_line
;
871 tmp_line
= input_line_pointer
;
872 input_line_pointer
= ptr
;
874 input_line_pointer
= tmp_line
;
877 /* Convert operands to iif-format and adds bitfields to the opcode.
878 Operands are parsed in such an order that the opcode is updated from
879 its most significant bit, that is when the operand need to alter the
881 Be carefull not to put to objects in the same iif-slot. */
884 encode_operand (argc
, argv
, operandsP
, suffixP
, im_size
, opcode_bit_ptr
)
894 int pcrel
, tmp
, b
, loop
, pcrel_adjust
;
896 for (loop
= 0; loop
< argc
; loop
++)
898 /* What operand are we supposed to work on. */
899 i
= operandsP
[loop
<< 1] - '1';
901 as_fatal (_("Internal consistency error. check ns32k-opcode.h"));
907 switch ((d
= operandsP
[(loop
<< 1) + 1]))
909 case 'f': /* operand of sfsr turns out to be a nasty
912 case 'Z': /* float not immediate */
913 case 'F': /* 32 bit float general form */
914 case 'L': /* 64 bit float */
915 case 'I': /* integer not immediate */
918 case 'D': /* double-word */
919 case 'A': /* double-word gen-address-form ie no regs
921 get_addr_mode (argv
[i
], &addr_modeP
);
923 if ((addr_modeP
.mode
== 20) &&
924 (d
== 'I' || d
== 'Z' || d
== 'A'))
925 as_fatal (d
== 'A'? _("Address of immediate operand"):
926 _("Invalid immediate write operand."));
928 if (opcode_bit_ptr
== desc
->opcode_size
)
933 for (j
= b
; j
< (b
+ 2); j
++)
935 if (addr_modeP
.disp
[j
- b
])
939 addr_modeP
.disp_suffix
[j
- b
],
940 (unsigned long) addr_modeP
.disp
[j
- b
],
947 (addr_modeP
.scaled_reg
? addr_modeP
.scaled_mode
954 iif
.iifP
[1].object
|= ((long) addr_modeP
.mode
) << opcode_bit_ptr
;
956 if (addr_modeP
.scaled_reg
)
959 IIF (j
, 1, 1, (unsigned long) addr_modeP
.index_byte
,
960 0, 0, 0, 0, 0, NULL
, -1, 0);
964 case 'b': /* multiple instruction disp */
965 freeptr
++; /* OVE:this is an useful hack */
966 sprintf (freeptr
, "((%s-1)*%d)\000", argv
[i
], desc
->im_size
);
968 pcrel
-= 1; /* make pcrel 0 inspite of what case 'p':
971 case 'p': /* displacement - pc relative addressing */
974 case 'd': /* displacement */
975 iif
.instr_size
+= suffixP
[i
] ? suffixP
[i
] : 4;
976 IIF (12, 2, suffixP
[i
], (unsigned long) argv
[i
], 0,
977 pcrel
, pcrel_adjust
, 1, IND (BRANCH
, BYTE
), NULL
, -1, 0);
979 case 'H': /* sequent-hack: the linker wants a bit set
982 iif
.instr_size
+= suffixP
[i
] ? suffixP
[i
] : 4;
983 IIF (12, 2, suffixP
[i
], (unsigned long) argv
[i
], 0,
984 pcrel
, pcrel_adjust
, 1, IND (BRANCH
, BYTE
), NULL
, -1, 1);
986 case 'q': /* quick */
988 IIF (11, 2, 42, (unsigned long) argv
[i
], 0, 0, 0, 0, 0,
989 bit_fix_new (4, opcode_bit_ptr
, -8, 7, 0, 1, 0), -1, 0);
991 case 'r': /* register number (3 bits) */
992 list_search (argv
[i
], opt6
, &tmp
);
994 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
996 case 'O': /* setcfg instruction optionslist */
997 optlist (argv
[i
], opt3
, &tmp
);
999 iif
.iifP
[1].object
|= tmp
<< 15;
1001 case 'C': /* cinv instruction optionslist */
1002 optlist (argv
[i
], opt4
, &tmp
);
1003 opcode_bit_ptr
-= 4;
1004 iif
.iifP
[1].object
|= tmp
<< 15; /* insert the regtype in opcode */
1006 case 'S': /* stringinstruction optionslist */
1007 optlist (argv
[i
], opt5
, &tmp
);
1008 opcode_bit_ptr
-= 4;
1009 iif
.iifP
[1].object
|= tmp
<< 15;
1012 case 'U': /* registerlist */
1013 IIF (10, 1, 1, 0, 0, 0, 0, 0, 0, NULL
, -1, 0);
1014 switch (operandsP
[(i
<< 1) + 1])
1016 case 'u': /* restore, exit */
1017 optlist (argv
[i
], opt1
, &iif
.iifP
[10].object
);
1019 case 'U': /* save,enter */
1020 optlist (argv
[i
], opt2
, &iif
.iifP
[10].object
);
1023 iif
.instr_size
+= 1;
1025 case 'M': /* mmu register */
1026 list_search (argv
[i
], mmureg
, &tmp
);
1027 opcode_bit_ptr
-= 4;
1028 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
1030 case 'P': /* cpu register */
1031 list_search (argv
[i
], cpureg
, &tmp
);
1032 opcode_bit_ptr
-= 4;
1033 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
1035 case 'g': /* inss exts */
1036 iif
.instr_size
+= 1; /* 1 byte is allocated after the opcode */
1038 (unsigned long) argv
[i
], /* i always 2 here */
1040 bit_fix_new (3, 5, 0, 7, 0, 0, 0), /* a bit_fix is targeted to
1046 (unsigned long) argv
[i
], /* i always 3 here */
1048 bit_fix_new (5, 0, 1, 32, -1, 0, -1), -1, 0);
1051 iif
.instr_size
+= 1;
1052 b
= 2 + i
; /* put the extension byte after opcode */
1053 IIF (b
, 2, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0);
1056 as_fatal (_("Bad opcode-table-option, check in file ns32k-opcode.h"));
1061 /* in: instruction line
1062 out: internal structure of instruction
1063 that has been prepared for direct conversion to fragment(s) and
1064 fixes in a systematical fashion
1065 Return-value = recursive_level. */
1066 /* Build iif of one assembly text line. */
1069 parse (line
, recursive_level
)
1071 int recursive_level
;
1073 register char *lineptr
, c
, suffix_separator
;
1077 char suffix
[MAX_ARGS
], *argv
[MAX_ARGS
]; /* No more than 4 operands. */
1079 if (recursive_level
<= 0)
1081 /* Called from md_assemble. */
1082 for (lineptr
= line
; (*lineptr
) != '\0' && (*lineptr
) != ' '; lineptr
++)
1088 if (!(desc
= (struct ns32k_opcode
*) hash_find (inst_hash_handle
, line
)))
1089 as_fatal (_("No such opcode"));
1100 if (*desc
->operands
)
1102 if (*lineptr
++ != '\0')
1107 while (*lineptr
!= '\0')
1109 if (desc
->operands
[argc
<< 1])
1112 arg_type
= desc
->operands
[(argc
<< 1) + 1];
1120 /* The operand is supposed to be a displacement. */
1121 /* Hackwarning: do not forget to update the 4
1122 cases above when editing ns32k-opcode.h. */
1123 suffix_separator
= ':';
1126 /* If this char occurs we loose. */
1127 suffix_separator
= '\255';
1131 suffix
[argc
] = 0; /* 0 when no ':' is encountered */
1132 argv
[argc
] = freeptr
;
1135 while ((c
= *lineptr
) != '\0' && c
!= sep
)
1151 if (c
== suffix_separator
)
1153 /* ':' - label/suffix separator. */
1166 as_warn (_("Bad suffix, defaulting to d"));
1168 if (lineptr
[1] == '\0' || lineptr
[1] == sep
)
1187 if (*lineptr
== '\0')
1194 as_fatal (_("Too many operands passed to instruction"));
1200 if (argc
!= strlen (desc
->operands
) / 2)
1202 if (strlen (desc
->default_args
))
1204 /* We can apply default, don't goof. */
1205 if (parse (desc
->default_args
, 1) != 1)
1206 /* Check error in default. */
1207 as_fatal (_("Wrong numbers of operands in default, check ns32k-opcodes.h"));
1211 as_fatal (_("Wrong number of operands"));
1215 for (i
= 0; i
< IIF_ENTRIES
; i
++)
1216 /* Mark all entries as void. */
1217 iif
.iifP
[i
].type
= 0;
1219 /* Build opcode iif-entry. */
1220 iif
.instr_size
= desc
->opcode_size
/ 8;
1221 IIF (1, 1, iif
.instr_size
, desc
->opcode_seed
, 0, 0, 0, 0, 0, 0, -1, 0);
1223 /* This call encodes operands to iif format. */
1226 encode_operand (argc
,
1233 return recursive_level
;
1236 /* Convert iif to fragments. From this point we start to dribble with
1237 functions in other files than this one.(Except hash.c) So, if it's
1238 possible to make an iif for an other CPU, you don't need to know
1239 what frags, relax, obstacks, etc is in order to port this
1240 assembler. You only need to know if it's possible to reduce your
1241 cpu-instruction to iif-format (takes some work) and adopt the other
1242 md_? parts according to given instructions Note that iif was
1243 invented for the clean ns32k`s architecure. */
1245 /* GAS for the ns32k has a problem. PC relative displacements are
1246 relative to the address of the opcode, not the address of the
1247 operand. We used to keep track of the offset between the operand
1248 and the opcode in pcrel_adjust for each frag and each fix. However,
1249 we get into trouble where there are two or more pc-relative
1250 operands and the size of the first one can't be determined. Then in
1251 the relax phase, the size of the first operand will change and
1252 pcrel_adjust will no longer be correct. The current solution is
1253 keep a pointer to the frag with the opcode in it and the offset in
1254 that frag for each frag and each fix. Then, when needed, we can
1255 always figure out how far it is between the opcode and the pcrel
1256 object. See also md_pcrel_adjust and md_fix_pcrel_adjust. For
1257 objects not part of an instruction, the pointer to the opcode frag
1266 unsigned int inst_offset
;
1275 memP
= frag_more (0);
1277 inst_offset
= (memP
- frag_now
->fr_literal
);
1278 inst_frag
= frag_now
;
1280 for (i
= 0; i
< IIF_ENTRIES
; i
++)
1282 if (type
= iif
.iifP
[i
].type
)
1284 /* The object exist, so handle it. */
1285 switch (size
= iif
.iifP
[i
].size
)
1289 /* It's a bitfix that operates on an existing object. */
1290 if (iif
.iifP
[i
].bit_fixP
->fx_bit_base
)
1291 /* Expand fx_bit_base to point at opcode. */
1292 iif
.iifP
[i
].bit_fixP
->fx_bit_base
= (long) inst_opcode
;
1295 case 8: /* bignum or doublefloat */
1300 /* The final size in objectmemory is known. */
1301 memP
= frag_more (size
);
1302 j
= iif
.iifP
[i
].bit_fixP
;
1306 case 1: /* The object is pure binary. */
1307 if (j
|| iif
.iifP
[i
].pcrel
)
1309 fix_new_ns32k (frag_now
,
1310 (long) (memP
- frag_now
->fr_literal
),
1315 iif
.iifP
[i
].im_disp
,
1317 iif
.iifP
[i
].bsr
, /* sequent hack */
1318 inst_frag
, inst_offset
);
1322 /* Good, just put them bytes out. */
1323 switch (iif
.iifP
[i
].im_disp
)
1326 md_number_to_chars (memP
, iif
.iifP
[i
].object
, size
);
1329 md_number_to_disp (memP
, iif
.iifP
[i
].object
, size
);
1332 as_fatal (_("iif convert internal pcrel/binary"));
1338 /* The object is a pointer at an expression, so
1339 unpack it, note that bignums may result from the
1341 evaluate_expr (&exprP
, (char *) iif
.iifP
[i
].object
);
1342 if (exprP
.X_op
== O_big
|| size
== 8)
1344 if ((k
= exprP
.X_add_number
) > 0)
1346 /* We have a bignum ie a quad. This can only
1347 happens in a long suffixed instruction. */
1349 as_warn (_("Bignum too big for long"));
1354 for (l
= 0; k
> 0; k
--, l
+= 2)
1356 md_number_to_chars (memP
+ l
,
1357 generic_bignum
[l
>> 1],
1358 sizeof (LITTLENUM_TYPE
));
1364 LITTLENUM_TYPE words
[4];
1369 gen_to_words (words
, 2, 8);
1370 md_number_to_imm (memP
, (long) words
[0],
1371 sizeof (LITTLENUM_TYPE
));
1372 md_number_to_imm (memP
+ sizeof (LITTLENUM_TYPE
),
1374 sizeof (LITTLENUM_TYPE
));
1377 gen_to_words (words
, 4, 11);
1378 md_number_to_imm (memP
, (long) words
[0],
1379 sizeof (LITTLENUM_TYPE
));
1380 md_number_to_imm (memP
+ sizeof (LITTLENUM_TYPE
),
1382 sizeof (LITTLENUM_TYPE
));
1383 md_number_to_imm ((memP
+ 2
1384 * sizeof (LITTLENUM_TYPE
)),
1386 sizeof (LITTLENUM_TYPE
));
1387 md_number_to_imm ((memP
+ 3
1388 * sizeof (LITTLENUM_TYPE
)),
1390 sizeof (LITTLENUM_TYPE
));
1397 exprP
.X_add_symbol
||
1398 exprP
.X_op_symbol
||
1401 /* The expression was undefined due to an
1402 undefined label. Create a fix so we can fix
1403 the object later. */
1404 exprP
.X_add_number
+= iif
.iifP
[i
].object_adjust
;
1405 fix_new_ns32k_exp (frag_now
,
1406 (long) (memP
- frag_now
->fr_literal
),
1410 iif
.iifP
[i
].im_disp
,
1413 inst_frag
, inst_offset
);
1417 /* Good, just put them bytes out. */
1418 switch (iif
.iifP
[i
].im_disp
)
1421 md_number_to_imm (memP
, exprP
.X_add_number
, size
);
1424 md_number_to_disp (memP
, exprP
.X_add_number
, size
);
1427 as_fatal (_("iif convert internal pcrel/pointer"));
1432 as_fatal (_("Internal logic error in iif.iifP[n].type"));
1437 /* Too bad, the object may be undefined as far as its
1438 final nsize in object memory is concerned. The size
1439 of the object in objectmemory is not explicitly
1440 given. If the object is defined its length can be
1441 determined and a fix can replace the frag. */
1443 evaluate_expr (&exprP
, (char *) iif
.iifP
[i
].object
);
1445 if ((exprP
.X_add_symbol
|| exprP
.X_op_symbol
) &&
1448 /* Size is unknown until link time so have to
1451 memP
= frag_more (size
);
1452 fix_new_ns32k_exp (frag_now
,
1453 (long) (memP
- frag_now
->fr_literal
),
1456 0, /* never iif.iifP[i].pcrel, */
1457 1, /* always iif.iifP[i].im_disp */
1461 break; /* exit this absolute hack */
1464 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
1467 if (exprP
.X_op_symbol
)
1469 /* We cant relax this case. */
1470 as_fatal (_("Can't relax difference"));
1474 /* Size is not important. This gets fixed by
1475 relax, but we assume 0 in what follows. */
1476 memP
= frag_more (4); /* Max size. */
1480 fragS
*old_frag
= frag_now
;
1481 frag_variant (rs_machine_dependent
,
1484 IND (BRANCH
, UNDEF
), /* Expecting
1489 frag_opcode_frag (old_frag
) = inst_frag
;
1490 frag_opcode_offset (old_frag
) = inst_offset
;
1491 frag_bsr (old_frag
) = iif
.iifP
[i
].bsr
;
1497 /* This duplicates code in md_number_to_disp. */
1498 if (-64 <= exprP
.X_add_number
&& exprP
.X_add_number
<= 63)
1504 if (-8192 <= exprP
.X_add_number
1505 && exprP
.X_add_number
<= 8191)
1511 if (-0x20000000 <= exprP
.X_add_number
1512 && exprP
.X_add_number
<=0x1fffffff)
1518 as_warn (_("Displacement to large for :d"));
1524 memP
= frag_more (size
);
1525 md_number_to_disp (memP
, exprP
.X_add_number
, size
);
1531 as_fatal (_("Internal logic error in iif.iifP[].type"));
1537 #ifdef BFD_ASSEMBLER
1538 /* This functionality should really be in the bfd library. */
1539 static bfd_reloc_code_real_type
1540 reloc (int size
, int pcrel
, int type
)
1543 bfd_reloc_code_real_type relocs
[] =
1545 BFD_RELOC_NS32K_IMM_8
,
1546 BFD_RELOC_NS32K_IMM_16
,
1547 BFD_RELOC_NS32K_IMM_32
,
1548 BFD_RELOC_NS32K_IMM_8_PCREL
,
1549 BFD_RELOC_NS32K_IMM_16_PCREL
,
1550 BFD_RELOC_NS32K_IMM_32_PCREL
,
1552 /* ns32k displacements. */
1553 BFD_RELOC_NS32K_DISP_8
,
1554 BFD_RELOC_NS32K_DISP_16
,
1555 BFD_RELOC_NS32K_DISP_32
,
1556 BFD_RELOC_NS32K_DISP_8_PCREL
,
1557 BFD_RELOC_NS32K_DISP_16_PCREL
,
1558 BFD_RELOC_NS32K_DISP_32_PCREL
,
1560 /* Normal 2's complement. */
1585 index
= length
+ 3 * pcrel
+ 6 * type
;
1587 if (index
>= 0 && index
< sizeof (relocs
) / sizeof (relocs
[0]))
1588 return relocs
[index
];
1591 as_bad (_("Can not do %d byte pc-relative relocation for storage type %d"),
1594 as_bad (_("Can not do %d byte relocation for storage type %d"),
1597 return BFD_RELOC_NONE
;
1606 freeptr
= freeptr_static
;
1607 parse (line
, 0); /* Explode line to more fix form in iif. */
1608 convert_iif (); /* Convert iif to frags, fix's etc. */
1610 printf (" \t\t\t%s\n", line
);
1617 /* Build a hashtable of the instructions. */
1618 const struct ns32k_opcode
*ptr
;
1620 inst_hash_handle
= hash_new ();
1622 for (ptr
= ns32k_opcodes
; ptr
< endop
; ptr
++)
1624 if ((stat
= hash_insert (inst_hash_handle
, ptr
->name
, (char *) ptr
)))
1626 as_fatal (_("Can't hash %s: %s"), ptr
->name
, stat
);
1629 /* Some private space please! */
1630 freeptr_static
= (char *) malloc (PRIVATE_SIZE
);
1633 /* Must be equal to MAX_PRECISON in atof-ieee.c. */
1634 #define MAX_LITTLENUMS 6
1636 /* Turn the string pointed to by litP into a floating point constant
1637 of type TYPE, and emit the appropriate bytes. The number of
1638 LITTLENUMS emitted is stored in *SIZEP. An error message is
1639 returned, or NULL on OK. */
1642 md_atof (type
, litP
, sizeP
)
1648 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1649 LITTLENUM_TYPE
*wordP
;
1663 return _("Bad call to MD_ATOF()");
1666 t
= atof_ieee (input_line_pointer
, type
, words
);
1668 input_line_pointer
= t
;
1670 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1672 for (wordP
= words
+ prec
; prec
--;)
1674 md_number_to_chars (litP
, (long) (*--wordP
), sizeof (LITTLENUM_TYPE
));
1675 litP
+= sizeof (LITTLENUM_TYPE
);
1681 /* Convert number to chars in correct order. */
1684 md_number_to_chars (buf
, value
, nbytes
)
1689 number_to_chars_littleendian (buf
, value
, nbytes
);
1692 /* This is a variant of md_numbers_to_chars. The reason for its'
1693 existence is the fact that ns32k uses Huffman coded
1694 displacements. This implies that the bit order is reversed in
1695 displacements and that they are prefixed with a size-tag.
1699 10xxxxxx xxxxxxxx word
1700 11xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx double word
1702 This must be taken care of and we do it here! */
1705 md_number_to_disp (buf
, val
, n
)
1713 if (val
< -64 || val
> 63)
1714 as_warn (_("Byte displacement out of range. line number not valid"));
1717 printf ("%x ", val
& 0xff);
1722 if (val
< -8192 || val
> 8191)
1723 as_warn (_("Word displacement out of range. line number not valid"));
1727 printf ("%x ", val
>> 8 & 0xff);
1729 *buf
++ = (val
>> 8);
1731 printf ("%x ", val
& 0xff);
1736 if (val
< -0x20000000 || val
>= 0x20000000)
1737 as_warn (_("Double word displacement out of range"));
1740 printf ("%x ", val
>> 24 & 0xff);
1742 *buf
++ = (val
>> 24);
1744 printf ("%x ", val
>> 16 & 0xff);
1746 *buf
++ = (val
>> 16);
1748 printf ("%x ", val
>> 8 & 0xff);
1750 *buf
++ = (val
>> 8);
1752 printf ("%x ", val
& 0xff);
1757 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1758 __LINE__
, __FILE__
);
1763 md_number_to_imm (buf
, val
, n
)
1772 printf ("%x ", val
& 0xff);
1778 printf ("%x ", val
>> 8 & 0xff);
1780 *buf
++ = (val
>> 8);
1782 printf ("%x ", val
& 0xff);
1788 printf ("%x ", val
>> 24 & 0xff);
1790 *buf
++ = (val
>> 24);
1792 printf ("%x ", val
>> 16 & 0xff);
1794 *buf
++ = (val
>> 16);
1796 printf ("%x ", val
>> 8 & 0xff);
1798 *buf
++ = (val
>> 8);
1800 printf ("%x ", val
& 0xff);
1805 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1806 __LINE__
, __FILE__
);
1810 /* Fast bitfiddling support. */
1811 /* Mask used to zero bitfield before oring in the true field. */
1813 static unsigned long l_mask
[] =
1815 0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
1816 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
1817 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
1818 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
1819 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
1820 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
1821 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
1822 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
1824 static unsigned long r_mask
[] =
1826 0x00000000, 0x00000001, 0x00000003, 0x00000007,
1827 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
1828 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
1829 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
1830 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
1831 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
1832 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
1833 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
1835 #define MASK_BITS 31
1836 /* Insert bitfield described by field_ptr and val at buf
1837 This routine is written for modification of the first 4 bytes pointed
1838 to by buf, to yield speed.
1839 The ifdef stuff is for selection between a ns32k-dependent routine
1840 and a general version. (My advice: use the general version!). */
1843 md_number_to_field (buf
, val
, field_ptr
)
1846 register bit_fixS
*field_ptr
;
1848 register unsigned long object
;
1849 register unsigned long mask
;
1850 /* define ENDIAN on a ns32k machine */
1852 register unsigned long *mem_ptr
;
1854 register char *mem_ptr
;
1856 if (field_ptr
->fx_bit_min
<= val
&& val
<= field_ptr
->fx_bit_max
)
1859 if (field_ptr
->fx_bit_base
)
1861 mem_ptr
= (unsigned long *) field_ptr
->fx_bit_base
;
1863 mem_ptr
= (unsigned long *) buf
;
1865 mem_ptr
= ((unsigned long *)
1866 ((char *) mem_ptr
+ field_ptr
->fx_bit_base_adj
));
1868 if (field_ptr
->fx_bit_base
)
1869 mem_ptr
= (char *) field_ptr
->fx_bit_base
;
1873 mem_ptr
+= field_ptr
->fx_bit_base_adj
;
1876 /* We have a nice ns32k machine with lowbyte at low-physical mem. */
1877 object
= *mem_ptr
; /* get some bytes */
1878 #else /* OVE Goof! the machine is a m68k or dito */
1879 /* That takes more byte fiddling. */
1881 object
|= mem_ptr
[3] & 0xff;
1883 object
|= mem_ptr
[2] & 0xff;
1885 object
|= mem_ptr
[1] & 0xff;
1887 object
|= mem_ptr
[0] & 0xff;
1890 mask
|= (r_mask
[field_ptr
->fx_bit_offset
]);
1891 mask
|= (l_mask
[field_ptr
->fx_bit_offset
+ field_ptr
->fx_bit_size
]);
1893 val
+= field_ptr
->fx_bit_add
;
1894 object
|= ((val
<< field_ptr
->fx_bit_offset
) & (mask
^ 0xffffffff));
1898 mem_ptr
[0] = (char) object
;
1900 mem_ptr
[1] = (char) object
;
1902 mem_ptr
[2] = (char) object
;
1904 mem_ptr
[3] = (char) object
;
1909 as_warn (_("Bit field out of range"));
1914 md_pcrel_adjust (fragP
)
1918 addressT opcode_address
;
1919 unsigned int offset
;
1921 opcode_frag
= frag_opcode_frag (fragP
);
1922 if (opcode_frag
== 0)
1925 offset
= frag_opcode_offset (fragP
);
1926 opcode_address
= offset
+ opcode_frag
->fr_address
;
1928 return fragP
->fr_address
+ fragP
->fr_fix
- opcode_address
;
1932 md_fix_pcrel_adjust (fixP
)
1935 fragS
*fragP
= fixP
->fx_frag
;
1937 addressT opcode_address
;
1938 unsigned int offset
;
1940 opcode_frag
= fix_opcode_frag (fixP
);
1941 if (opcode_frag
== 0)
1944 offset
= fix_opcode_offset (fixP
);
1945 opcode_address
= offset
+ opcode_frag
->fr_address
;
1947 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- opcode_address
;
1950 /* Apply a fixS (fixup of an instruction or data that we didn't have
1951 enough info to complete immediately) to the data in a frag.
1953 On the ns32k, everything is in a different format, so we have broken
1954 out separate functions for each kind of thing we could be fixing.
1955 They all get called from here. */
1958 md_apply_fix3 (fixP
, valP
, seg
)
1961 segT seg ATTRIBUTE_UNUSED
;
1963 long val
= * (long *) valP
;
1964 fragS
*fragP
= fixP
->fx_frag
;
1965 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1967 if (fix_bit_fixP (fixP
))
1968 /* Bitfields to fix, sigh. */
1969 md_number_to_field (buf
, val
, fix_bit_fixP (fixP
));
1971 else switch (fix_im_disp (fixP
))
1974 /* Immediate field. */
1975 md_number_to_imm (buf
, val
, fixP
->fx_size
);
1979 /* Displacement field. */
1980 /* Calculate offset */
1981 md_number_to_disp (buf
,
1982 (fixP
->fx_pcrel
? val
+ md_fix_pcrel_adjust (fixP
)
1983 : val
), fixP
->fx_size
);
1987 /* Pointer in a data object. */
1988 md_number_to_chars (buf
, val
, fixP
->fx_size
);
1992 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1996 /* Convert a relaxed displacement to ditto in final output */
1998 #ifndef BFD_ASSEMBLER
2000 md_convert_frag (headers
, sec
, fragP
)
2001 object_headers
*headers
;
2003 register fragS
*fragP
;
2006 md_convert_frag (abfd
, sec
, fragP
)
2009 register fragS
*fragP
;
2015 /* Address in gas core of the place to store the displacement. */
2016 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
2017 /* Address in object code of the displacement. */
2022 switch (fragP
->fr_subtype
)
2024 case IND (BRANCH
, BYTE
):
2027 case IND (BRANCH
, WORD
):
2030 case IND (BRANCH
, DOUBLE
):
2038 know (fragP
->fr_symbol
);
2040 object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
2042 /* The displacement of the address, from current location. */
2043 disp
= (S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
) - object_address
;
2044 disp
+= md_pcrel_adjust (fragP
);
2046 md_number_to_disp (buffer_address
, (long) disp
, (int) ext
);
2047 fragP
->fr_fix
+= ext
;
2050 /* This function returns the estimated size a variable object will occupy,
2051 one can say that we tries to guess the size of the objects before we
2052 actually know it. */
2055 md_estimate_size_before_relax (fragP
, segment
)
2056 register fragS
*fragP
;
2059 if (fragP
->fr_subtype
== IND (BRANCH
, UNDEF
))
2061 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
)
2063 /* We don't relax symbols defined in another segment. The
2064 thing to do is to assume the object will occupy 4 bytes. */
2065 fix_new_ns32k (fragP
,
2066 (int) (fragP
->fr_fix
),
2073 frag_bsr(fragP
), /*sequent hack */
2074 frag_opcode_frag (fragP
),
2075 frag_opcode_offset (fragP
));
2078 fragP
->fr_opcode
[1] = 0xff;
2084 /* Relaxable case. Set up the initial guess for the variable
2085 part of the frag. */
2086 fragP
->fr_subtype
= IND (BRANCH
, BYTE
);
2089 if (fragP
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
2092 /* Return the size of the variable part of the frag. */
2093 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2096 int md_short_jump_size
= 3;
2097 int md_long_jump_size
= 5;
2098 const int md_reloc_size
= 8; /* Size of relocation record. */
2101 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2103 addressT from_addr
, to_addr
;
2109 offset
= to_addr
- from_addr
;
2110 md_number_to_chars (ptr
, (valueT
) 0xEA, 1);
2111 md_number_to_disp (ptr
+ 1, (valueT
) offset
, 2);
2115 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2117 addressT from_addr
, to_addr
;
2123 offset
= to_addr
- from_addr
;
2124 md_number_to_chars (ptr
, (valueT
) 0xEA, 1);
2125 md_number_to_disp (ptr
+ 1, (valueT
) offset
, 4);
2128 CONST
char *md_shortopts
= "m:";
2130 struct option md_longopts
[] =
2132 {NULL
, no_argument
, NULL
, 0}
2135 size_t md_longopts_size
= sizeof (md_longopts
);
2138 md_parse_option (c
, arg
)
2145 if (!strcmp (arg
, "32032"))
2147 cpureg
= cpureg_032
;
2148 mmureg
= mmureg_032
;
2150 else if (!strcmp (arg
, "32532"))
2152 cpureg
= cpureg_532
;
2153 mmureg
= mmureg_532
;
2157 as_bad (_("invalid architecture option -m%s"), arg
);
2170 md_show_usage (stream
)
2173 fprintf (stream
, _("\
2175 -m32032 | -m32532 select variant of NS32K architecture\n"));
2178 /* Create a bit_fixS in obstack 'notes'.
2179 This struct is used to profile the normal fix. If the bit_fixP is a
2180 valid pointer (not NULL) the bit_fix data will be used to format
2184 bit_fix_new (size
, offset
, min
, max
, add
, base_type
, base_adj
)
2185 char size
; /* Length of bitfield */
2186 char offset
; /* Bit offset to bitfield */
2187 long min
; /* Signextended min for bitfield */
2188 long max
; /* Signextended max for bitfield */
2189 long add
; /* Add mask, used for huffman prefix */
2190 long base_type
; /* 0 or 1, if 1 it's exploded to opcode ptr */
2193 register bit_fixS
*bit_fixP
;
2195 bit_fixP
= (bit_fixS
*) obstack_alloc (¬es
, sizeof (bit_fixS
));
2197 bit_fixP
->fx_bit_size
= size
;
2198 bit_fixP
->fx_bit_offset
= offset
;
2199 bit_fixP
->fx_bit_base
= base_type
;
2200 bit_fixP
->fx_bit_base_adj
= base_adj
;
2201 bit_fixP
->fx_bit_max
= max
;
2202 bit_fixP
->fx_bit_min
= min
;
2203 bit_fixP
->fx_bit_add
= add
;
2209 fix_new_ns32k (frag
, where
, size
, add_symbol
, offset
, pcrel
,
2210 im_disp
, bit_fixP
, bsr
, opcode_frag
, opcode_offset
)
2211 fragS
*frag
; /* Which frag? */
2212 int where
; /* Where in that frag? */
2213 int size
; /* 1, 2 or 4 usually. */
2214 symbolS
*add_symbol
; /* X_add_symbol. */
2215 long offset
; /* X_add_number. */
2216 int pcrel
; /* TRUE if PC-relative relocation. */
2217 char im_disp
; /* true if the value to write is a
2219 bit_fixS
*bit_fixP
; /* pointer at struct of bit_fix's, ignored if
2221 char bsr
; /* sequent-linker-hack: 1 when relocobject is
2224 unsigned int opcode_offset
;
2226 fixS
*fixP
= fix_new (frag
, where
, size
, add_symbol
,
2228 #ifdef BFD_ASSEMBLER
2229 bit_fixP
? NO_RELOC
: reloc (size
, pcrel
, im_disp
)
2235 fix_opcode_frag (fixP
) = opcode_frag
;
2236 fix_opcode_offset (fixP
) = opcode_offset
;
2237 fix_im_disp (fixP
) = im_disp
;
2238 fix_bsr (fixP
) = bsr
;
2239 fix_bit_fixP (fixP
) = bit_fixP
;
2243 fix_new_ns32k_exp (frag
, where
, size
, exp
, pcrel
,
2244 im_disp
, bit_fixP
, bsr
, opcode_frag
, opcode_offset
)
2245 fragS
*frag
; /* Which frag? */
2246 int where
; /* Where in that frag? */
2247 int size
; /* 1, 2 or 4 usually. */
2248 expressionS
*exp
; /* Expression. */
2249 int pcrel
; /* TRUE if PC-relative relocation. */
2250 char im_disp
; /* true if the value to write is a
2252 bit_fixS
*bit_fixP
; /* pointer at struct of bit_fix's, ignored if
2254 char bsr
; /* sequent-linker-hack: 1 when relocobject is
2257 unsigned int opcode_offset
;
2259 fixS
*fixP
= fix_new_exp (frag
, where
, size
, exp
, pcrel
,
2260 #ifdef BFD_ASSEMBLER
2261 bit_fixP
? NO_RELOC
: reloc (size
, pcrel
, im_disp
)
2267 fix_opcode_frag (fixP
) = opcode_frag
;
2268 fix_opcode_offset (fixP
) = opcode_offset
;
2269 fix_im_disp (fixP
) = im_disp
;
2270 fix_bsr (fixP
) = bsr
;
2271 fix_bit_fixP (fixP
) = bit_fixP
;
2274 /* This is TC_CONS_FIX_NEW, called by emit_expr in read.c. */
2277 cons_fix_new_ns32k (frag
, where
, size
, exp
)
2278 fragS
*frag
; /* Which frag? */
2279 int where
; /* Where in that frag? */
2280 int size
; /* 1, 2 or 4 usually. */
2281 expressionS
*exp
; /* Expression. */
2283 fix_new_ns32k_exp (frag
, where
, size
, exp
,
2287 /* We have no need to default values of symbols. */
2290 md_undefined_symbol (name
)
2296 /* Round up a section size to the appropriate boundary. */
2299 md_section_align (segment
, size
)
2303 return size
; /* Byte alignment is fine. */
2306 /* Exactly what point is a PC-relative offset relative TO? On the
2307 ns32k, they're relative to the start of the instruction. */
2310 md_pcrel_from (fixP
)
2314 res
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2315 #ifdef SEQUENT_COMPATABILITY
2316 if (frag_bsr (fixP
->fx_frag
))
2317 res
+= 0x12 /* FOO Kludge alert! */
2322 #ifdef BFD_ASSEMBLER
2325 tc_gen_reloc (section
, fixp
)
2330 bfd_reloc_code_real_type code
;
2332 code
= reloc (fixp
->fx_size
, fixp
->fx_pcrel
, fix_im_disp (fixp
));
2334 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2335 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2336 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2337 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2339 rel
->addend
= fixp
->fx_addnumber
;
2343 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2348 name
= S_GET_NAME (fixp
->fx_addsy
);
2350 name
= _("<unknown>");
2351 as_fatal (_("Cannot find relocation type for symbol %s, code %d"),
2357 #else /* BFD_ASSEMBLER */
2361 cons_fix_new_ns32k (where
, fixP
, segment_address_in_file
)
2364 relax_addressT segment_address_in_file
;
2366 /* In: Length of relocation (or of address) in chars: 1, 2 or 4.
2367 Out: GNU LD relocation length code: 0, 1, or 2. */
2369 static unsigned char nbytes_r_length
[] = { 42, 0, 1, 42, 2 };
2372 know (fixP
->fx_addsy
!= NULL
);
2374 md_number_to_chars (where
,
2375 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2378 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
2379 ? S_GET_TYPE (fixP
->fx_addsy
)
2380 : fixP
->fx_addsy
->sy_number
);
2382 md_number_to_chars (where
+ 4,
2383 ((long) (r_symbolnum
)
2384 | (long) (fixP
->fx_pcrel
<< 24)
2385 | (long) (nbytes_r_length
[fixP
->fx_size
] << 25)
2386 | (long) ((!S_IS_DEFINED (fixP
->fx_addsy
)) << 27)
2387 | (long) (fix_bsr (fixP
) << 28)
2388 | (long) (fix_im_disp (fixP
) << 29)),
2392 #endif /* OBJ_AOUT */
2393 #endif /* BFD_ASSMEBLER */