1 /* ns32k.c -- Assemble on the National Semiconductor 32k series
2 Copyright (C) 1987, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /*#define SHOW_NUM 1*//* uncomment for debugging */
28 #include "opcode/ns32k.h"
33 #define IIF_ENTRIES 13 /* number of entries in iif */
34 #define PRIVATE_SIZE 256 /* size of my garbage memory */
36 #define DEFAULT -1 /* addr_mode returns this value when
37 plain constant or label is
40 #define IIF(ptr,a1,c1,e1,g1,i1,k1,m1,o1,q1,s1,u1) \
41 iif.iifP[ptr].type= a1; \
42 iif.iifP[ptr].size= c1; \
43 iif.iifP[ptr].object= e1; \
44 iif.iifP[ptr].object_adjust= g1; \
45 iif.iifP[ptr].pcrel= i1; \
46 iif.iifP[ptr].pcrel_adjust= k1; \
47 iif.iifP[ptr].im_disp= m1; \
48 iif.iifP[ptr].relax_substate= o1; \
49 iif.iifP[ptr].bit_fixP= q1; \
50 iif.iifP[ptr].addr_mode= s1; \
51 iif.iifP[ptr].bsr= u1;
53 #ifdef SEQUENT_COMPATABILITY
54 #define LINE_COMMENT_CHARS "|"
55 #define ABSOLUTE_PREFIX '@'
56 #define IMMEDIATE_PREFIX '#'
59 #ifndef LINE_COMMENT_CHARS
60 #define LINE_COMMENT_CHARS "#"
63 const char comment_chars
[] = "#";
64 const char line_comment_chars
[] = LINE_COMMENT_CHARS
;
65 const char line_separator_chars
[] = "";
66 #if !defined(ABSOLUTE_PREFIX) && !defined(IMMEDIATE_PREFIX)
67 #define ABSOLUTE_PREFIX '@' /* One or the other MUST be defined */
72 char mode
; /* addressing mode of operand (0-31) */
73 char scaled_mode
; /* mode combined with scaled mode */
74 char scaled_reg
; /* register used in scaled+1 (1-8) */
75 char float_flag
; /* set if R0..R7 was F0..F7 ie a
76 floating-point-register */
77 char am_size
; /* estimated max size of general addr-mode
79 char im_disp
; /* if im_disp==1 we have a displacement */
80 char pcrel
; /* 1 if pcrel, this is really redundant info */
81 char disp_suffix
[2]; /* length of displacement(s), 0=undefined */
82 char *disp
[2]; /* pointer(s) at displacement(s)
83 or immediates(s) (ascii) */
84 char index_byte
; /* index byte */
86 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, do we */
97 /* UPPERCASE denotes live names when an instruction is built, IIF is
98 * used as an intermediate form to store the actual parts of the
99 * instruction. A ns32k machine instruction can be divided into a
100 * couple of sub PARTs. When an instruction is assembled the
101 * appropriate PART get an assignment. When an IIF has been completed
102 * it is converted to a FRAGment as specified in AS.H */
104 /* internal structs */
114 int type
; /* how to interpret object */
115 int size
; /* Estimated max size of object */
116 unsigned long object
; /* binary data */
117 int object_adjust
; /* number added to object */
118 int pcrel
; /* True if object is pcrel */
119 int pcrel_adjust
; /* length in bytes from the
120 instruction start to the
122 int im_disp
; /* True if the object is a displacement */
123 relax_substateT relax_substate
; /* Initial relaxsubstate */
124 bit_fixS
*bit_fixP
; /* Pointer at bit_fix struct */
125 int addr_mode
; /* What addrmode do we associate with this
127 char bsr
; /* Sequent hack */
128 } iif_entryT
; /* Internal Instruction Format */
132 int instr_size
; /* Max size of instruction in bytes. */
133 iif_entryT iifP
[IIF_ENTRIES
+ 1];
135 struct int_ins_form iif
;
137 char *input_line_pointer
;
138 /* description of the PARTs in IIF
140 * 0 total length in bytes of entries in iif
153 * For every entry there is a datalength in bytes. This is stored in size[n].
154 * 0, the objectlength is not explicitly given by the instruction
155 * and the operand is undefined. This is a case for relaxation.
156 * Reserve 4 bytes for the final object.
158 * 1, the entry contains one byte
159 * 2, the entry contains two bytes
160 * 3, the entry contains three bytes
161 * 4, the entry contains four bytes
164 * Furthermore, every entry has a data type identifier in type[n].
166 * 0, the entry is void, ignore it.
167 * 1, the entry is a binary number.
168 * 2, the entry is a pointer at an expression.
169 * Where expression may be as simple as a single '1',
170 * and as complicated as foo-bar+12,
171 * foo and bar may be undefined but suffixed by :{b|w|d} to
172 * control the length of the object.
174 * 3, the entry is a pointer at a bignum struct
177 * The low-order-byte coresponds to low physical memory.
178 * Obviously a FRAGment must be created for each valid disp in PART whose
179 * datalength is undefined (to bad) .
180 * The case where just the expression is undefined is less severe and is
181 * handled by fix. Here the number of bytes in the objectfile is known.
182 * With this representation we simplify the assembly and separates the
183 * machine dependent/independent parts in a more clean way (said OE)
186 struct ns32k_option opt1
[] = /* restore, exit */
198 struct ns32k_option opt2
[] = /* save, enter */
210 struct ns32k_option opt3
[] = /* setcfg */
218 struct ns32k_option opt4
[] = /* cinv */
225 struct ns32k_option opt5
[] = /* string inst */
232 struct ns32k_option opt6
[] = /* plain reg ext,cvtp etc */
245 #if !defined(NS32032) && !defined(NS32532)
249 struct ns32k_option cpureg_532
[] = /* lpr spr */
262 {"intbase", 0xe, 0xff},
266 struct ns32k_option mmureg_532
[] = /* lmr smr */
273 {"ivar0", 0xe, 0xff},
274 {"ivar1", 0xf, 0xff},
278 struct ns32k_option cpureg_032
[] = /* lpr spr */
285 {"intbase", 0xe, 0xff},
289 struct ns32k_option mmureg_032
[] = /* lmr smr */
305 struct ns32k_option
*cpureg
= cpureg_532
;
306 struct ns32k_option
*mmureg
= mmureg_532
;
308 struct ns32k_option
*cpureg
= cpureg_032
;
309 struct ns32k_option
*mmureg
= mmureg_032
;
313 const pseudo_typeS md_pseudo_table
[] =
318 #define IND(x,y) (((x)<<2)+(y))
320 /* those are index's to relax groups in md_relax_table ie it must be
321 multiplied by 4 to point at a group start. Viz IND(x,y) Se function
322 relax_segment in write.c for more info */
327 /* those are index's to entries in a relax group */
333 /* Those limits are calculated from the displacement start in memory.
334 The ns32k uses the begining of the instruction as displacement
335 base. This type of displacements could be handled here by moving
336 the limit window up or down. I choose to use an internal
337 displacement base-adjust as there are other routines that must
338 consider this. Also, as we have two various offset-adjusts in the
339 ns32k (acb versus br/brs/jsr/bcond), two set of limits would have
340 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 /* Parses 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
;
393 mode
= DEFAULT
; /* default */
394 addr_modeP
->scaled_mode
= 0; /* why not */
395 addr_modeP
->scaled_reg
= 0; /* if 0, not scaled index */
396 addr_modeP
->float_flag
= 0;
397 addr_modeP
->am_size
= 0;
398 addr_modeP
->im_disp
= 0;
399 addr_modeP
->pcrel
= 0; /* not set in this function */
400 addr_modeP
->disp_suffix
[0] = 0;
401 addr_modeP
->disp_suffix
[1] = 0;
402 addr_modeP
->disp
[0] = NULL
;
403 addr_modeP
->disp
[1] = NULL
;
408 } /* we don't want this */
412 /* the following three case statements controls the mode-chars
413 this is the place to ed if you want to change them */
414 #ifdef ABSOLUTE_PREFIX
415 case ABSOLUTE_PREFIX
:
416 if (str
[strl
- 1] == ']')
418 addr_modeP
->mode
= 21; /* absolute */
419 addr_modeP
->disp
[0] = str
+ 1;
422 #ifdef IMMEDIATE_PREFIX
423 case IMMEDIATE_PREFIX
:
424 if (str
[strl
- 1] == ']')
426 addr_modeP
->mode
= 20; /* immediate */
427 addr_modeP
->disp
[0] = str
+ 1;
431 if (str
[strl
- 1] != ']')
437 if (str
[2] != '\000')
439 addr_modeP
->mode
= 27; /* pc-relativ */
440 addr_modeP
->disp
[0] = str
+ 2;
444 as_warn (_("Invalid syntax in PC-relative addressing mode"));
450 if (str
[strl
- 1] != ']')
452 if ((!strncmp (str
, "ext(", 4)) && strl
> 7)
454 addr_modeP
->disp
[0] = str
+ 4;
458 { /* disp[0]'s termination point */
465 while (j
< strl
&& i
!= 0);
466 if (i
!= 0 || !(str
[j
+ 1] == '-' || str
[j
+ 1] == '+'))
468 as_warn (_("Invalid syntax in External addressing mode"));
471 str
[j
] = '\000'; /* null terminate disp[0] */
472 addr_modeP
->disp
[1] = str
+ j
+ 2;
473 addr_modeP
->mode
= 22;
487 addr_modeP
->float_flag
= 1;
489 if (str
[1] >= '0' && str
[1] < '8')
491 addr_modeP
->mode
= str
[1] - '0';
496 if (!strncmp (str
, "tos", 3))
498 addr_modeP
->mode
= 23; /* TopOfStack */
505 if (str
[strl
- 1] == ')')
507 if (str
[strl
- 2] == ')')
509 if (!strncmp (&str
[strl
- 5], "(fp", 3))
511 mode
= 16; /* Memory Relative */
513 if (!strncmp (&str
[strl
- 5], "(sp", 3))
517 if (!strncmp (&str
[strl
- 5], "(sb", 3))
522 { /* memory relative */
523 addr_modeP
->mode
= mode
;
524 j
= strl
- 5; /* temp for end of disp[0] */
529 if (str
[strl
] == ')')
531 if (str
[strl
] == '(')
534 while (strl
> -1 && i
!= 0);
537 as_warn (_("Invalid syntax in Memory Relative addressing mode"));
540 addr_modeP
->disp
[1] = str
;
541 addr_modeP
->disp
[0] = str
+ strl
+ 1;
542 str
[j
] = '\000'; /* null terminate disp[0] */
543 str
[strl
] = '\000'; /* null terminate disp[1] */
547 switch (str
[strl
- 3])
551 if (str
[strl
- 2] >= '0'
552 && str
[strl
- 2] < '8'
553 && str
[strl
- 4] == '(')
555 addr_modeP
->mode
= str
[strl
- 2] - '0' + 8;
556 addr_modeP
->disp
[0] = str
;
558 return (-1); /* reg rel */
561 if (!strncmp (&str
[strl
- 4], "(fp", 3))
565 if (!strncmp (&str
[strl
- 4], "(sp", 3))
569 if (!strncmp (&str
[strl
- 4], "(sb", 3))
573 if (!strncmp (&str
[strl
- 4], "(pc", 3))
579 addr_modeP
->mode
= mode
;
580 addr_modeP
->disp
[0] = str
;
581 str
[strl
- 4] = '\0';
582 return (-1); /* memory space */
586 /* no trailing ')' do we have a ']' ? */
587 if (str
[strl
- 1] == ']')
589 switch (str
[strl
- 2])
604 as_warn (_("Invalid scaled-indexed mode, use (b,w,d,q)"));
605 if (str
[strl
- 3] != ':' || str
[strl
- 6] != '['
606 || str
[strl
- 5] == 'r' || str
[strl
- 4] < '0'
607 || str
[strl
- 4] > '7')
609 as_warn (_("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"));
613 if (recursive_level
> 0)
615 as_warn (_("Scaled-indexed addressing mode combined with scaled-index"));
618 addr_modeP
->am_size
+= 1; /* scaled index byte */
619 j
= str
[strl
- 4] - '0'; /* store temporary */
620 str
[strl
- 6] = '\000'; /* nullterminate for recursive call */
621 i
= addr_mode (str
, addr_modeP
, 1);
622 if (!i
|| addr_modeP
->mode
== 20)
624 as_warn (_("Invalid or illegal addressing mode combined with scaled-index"));
627 addr_modeP
->scaled_mode
= addr_modeP
->mode
; /* store the inferior
629 addr_modeP
->mode
= mode
;
630 addr_modeP
->scaled_reg
= j
+ 1;
635 addr_modeP
->mode
= DEFAULT
; /* default to whatever */
636 addr_modeP
->disp
[0] = str
;
640 /* ptr points at string addr_modeP points at struct with result This
641 routine calls addr_mode to determine the general addr.mode of the
642 operand. When this is ready it parses the displacements for size
643 specifying suffixes and determines size of immediate mode via
644 ns32k-opcode. Also builds index bytes if needed. */
646 get_addr_mode (ptr
, addr_modeP
)
648 addr_modeS
*addr_modeP
;
651 addr_mode (ptr
, addr_modeP
, 0);
652 if (addr_modeP
->mode
== DEFAULT
|| addr_modeP
->scaled_mode
== -1)
654 /* resolve ambigious operands, this shouldn't be necessary if
655 one uses standard NSC operand syntax. But the sequent
656 compiler doesn't!!! This finds a proper addressinging mode
657 if it is implicitly stated. See ns32k-opcode.h */
658 (void) evaluate_expr (&exprP
, ptr
); /* this call takes time Sigh! */
659 if (addr_modeP
->mode
== DEFAULT
)
661 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
663 addr_modeP
->mode
= desc
->default_model
; /* we have a label */
667 addr_modeP
->mode
= desc
->default_modec
; /* we have a constant */
672 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
674 addr_modeP
->scaled_mode
= desc
->default_model
;
678 addr_modeP
->scaled_mode
= desc
->default_modec
;
681 /* must put this mess down in addr_mode to handle the scaled
684 /* It appears as the sequent compiler wants an absolute when we have
685 a label without @. Constants becomes immediates besides the addr
686 case. Think it does so with local labels too, not optimum, pcrel
687 is better. When I have time I will make gas check this and
688 select pcrel when possible Actually that is trivial. */
689 if (tmp
= addr_modeP
->scaled_reg
)
690 { /* build indexbyte */
691 tmp
--; /* remember regnumber comes incremented for
693 tmp
|= addr_modeP
->scaled_mode
<< 3;
694 addr_modeP
->index_byte
= (char) tmp
;
695 addr_modeP
->am_size
+= 1;
697 if (disp_test
[addr_modeP
->mode
])
698 { /* there was a displacement, probe for length
702 register char suffix
;
703 register char suffix_sub
;
706 register char *fromP
;
708 addr_modeP
->pcrel
= 0;
709 if (disp_test
[addr_modeP
->mode
])
710 { /* there is a displacement */
711 if (addr_modeP
->mode
== 27 || addr_modeP
->scaled_mode
== 27)
712 { /* do we have pcrel. mode */
713 addr_modeP
->pcrel
= 1;
715 addr_modeP
->im_disp
= 1;
716 for (i
= 0; i
< 2; i
++)
718 suffix_sub
= suffix
= 0;
719 if (toP
= addr_modeP
->disp
[i
])
720 { /* suffix of expression, the largest size
731 as_warn (_("Premature end of suffix -- Defaulting to d"));
744 as_warn (_("Bad suffix after ':' use {b|w|d} Defaulting to d"));
748 toP
--; /* So we write over the ':' */
749 if (suffix
< suffix_sub
)
753 *toP
= '\0';/* terminate properly */
754 addr_modeP
->disp_suffix
[i
] = suffix
;
755 addr_modeP
->am_size
+= suffix
? suffix
: 4;
763 if (addr_modeP
->mode
== 20)
764 { /* look in ns32k_opcode for size */
765 addr_modeP
->disp_suffix
[0] = addr_modeP
->am_size
= desc
->im_size
;
766 addr_modeP
->im_disp
= 0;
769 return addr_modeP
->mode
;
773 /* read an optionlist */
775 optlist (str
, optionP
, default_map
)
776 char *str
; /* the string to extract options from */
777 struct ns32k_option
*optionP
; /* how to search the string */
778 unsigned long *default_map
; /* default pattern and output */
780 register int i
, j
, k
, strlen1
, strlen2
;
781 register char *patternP
, *strP
;
782 strlen1
= strlen (str
);
785 as_fatal (_("Very short instr to option, ie you can't do it on a NULLstr"));
787 for (i
= 0; optionP
[i
].pattern
!= 0; i
++)
789 strlen2
= strlen (optionP
[i
].pattern
);
790 for (j
= 0; j
< strlen1
; j
++)
792 patternP
= optionP
[i
].pattern
;
794 for (k
= 0; k
< strlen2
; k
++)
796 if (*(strP
++) != *(patternP
++))
801 *default_map
|= optionP
[i
].or;
802 *default_map
&= optionP
[i
].and;
808 /* search struct for symbols
809 This function is used to get the short integer form of reg names in
810 the instructions lmr, smr, lpr, spr return true if str is found in
814 list_search (str
, optionP
, default_map
)
815 char *str
; /* the string to match */
816 struct ns32k_option
*optionP
; /* list to search */
817 unsigned long *default_map
; /* default pattern and output */
820 for (i
= 0; optionP
[i
].pattern
!= 0; i
++)
822 if (!strncmp (optionP
[i
].pattern
, str
, 20))
823 { /* use strncmp to be safe */
824 *default_map
|= optionP
[i
].or;
825 *default_map
&= optionP
[i
].and;
829 as_warn (_("No such entry in list. (cpu/mmu register)"));
834 evaluate_expr (resultP
, ptr
)
835 expressionS
*resultP
;
838 register char *tmp_line
;
840 tmp_line
= input_line_pointer
;
841 input_line_pointer
= ptr
;
843 input_line_pointer
= tmp_line
;
846 /* Convert operands to iif-format and adds bitfields to the opcode.
847 Operands are parsed in such an order that the opcode is updated from
848 its most significant bit, that is when the operand need to alter the
850 Be carefull not to put to objects in the same iif-slot.
854 encode_operand (argc
, argv
, operandsP
, suffixP
, im_size
, opcode_bit_ptr
)
864 int pcrel
, tmp
, b
, loop
, pcrel_adjust
;
865 for (loop
= 0; loop
< argc
; loop
++)
867 i
= operandsP
[loop
<< 1] - '1'; /* what operand are we supposed
870 as_fatal (_("Internal consistency error. check ns32k-opcode.h"));
874 switch ((d
= operandsP
[(loop
<< 1) + 1]))
876 case 'f': /* operand of sfsr turns out to be a nasty
879 case 'Z': /* float not immediate */
880 case 'F': /* 32 bit float general form */
881 case 'L': /* 64 bit float */
882 case 'I': /* integer not immediate */
885 case 'D': /* double-word */
886 case 'A': /* double-word gen-address-form ie no regs
888 get_addr_mode (argv
[i
], &addr_modeP
);
889 if((addr_modeP
.mode
== 20) &&
890 (d
== 'I' || d
== 'Z' || d
== 'A')) {
891 as_fatal(d
== 'A'? _("Address of immediate operand"):
892 _("Invalid immediate write operand."));
895 if (opcode_bit_ptr
== desc
->opcode_size
)
899 for (j
= b
; j
< (b
+ 2); j
++)
901 if (addr_modeP
.disp
[j
- b
])
905 addr_modeP
.disp_suffix
[j
- b
],
906 (unsigned long) addr_modeP
.disp
[j
- b
],
913 (addr_modeP
.scaled_reg
? addr_modeP
.scaled_mode
919 iif
.iifP
[1].object
|= ((long) addr_modeP
.mode
) << opcode_bit_ptr
;
920 if (addr_modeP
.scaled_reg
)
923 IIF (j
, 1, 1, (unsigned long) addr_modeP
.index_byte
,
924 0, 0, 0, 0, 0, NULL
, -1, 0);
927 case 'b': /* multiple instruction disp */
928 freeptr
++; /* OVE:this is an useful hack */
929 sprintf (freeptr
, "((%s-1)*%d)\000", argv
[i
], desc
->im_size
);
931 pcrel
-= 1; /* make pcrel 0 inspite of what case 'p':
934 case 'p': /* displacement - pc relative addressing */
937 case 'd': /* displacement */
938 iif
.instr_size
+= suffixP
[i
] ? suffixP
[i
] : 4;
939 IIF (12, 2, suffixP
[i
], (unsigned long) argv
[i
], 0,
940 pcrel
, pcrel_adjust
, 1, IND (BRANCH
, BYTE
), NULL
, -1, 0);
942 case 'H': /* sequent-hack: the linker wants a bit set
945 iif
.instr_size
+= suffixP
[i
] ? suffixP
[i
] : 4;
946 IIF (12, 2, suffixP
[i
], (unsigned long) argv
[i
], 0,
947 pcrel
, pcrel_adjust
, 1, IND (BRANCH
, BYTE
), NULL
, -1, 1);
949 case 'q': /* quick */
951 IIF (11, 2, 42, (unsigned long) argv
[i
], 0, 0, 0, 0, 0,
952 bit_fix_new (4, opcode_bit_ptr
, -8, 7, 0, 1, 0), -1, 0);
954 case 'r': /* register number (3 bits) */
955 list_search (argv
[i
], opt6
, &tmp
);
957 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
959 case 'O': /* setcfg instruction optionslist */
960 optlist (argv
[i
], opt3
, &tmp
);
962 iif
.iifP
[1].object
|= tmp
<< 15;
964 case 'C': /* cinv instruction optionslist */
965 optlist (argv
[i
], opt4
, &tmp
);
967 iif
.iifP
[1].object
|= tmp
<< 15; /* insert the regtype in opcode */
969 case 'S': /* stringinstruction optionslist */
970 optlist (argv
[i
], opt5
, &tmp
);
972 iif
.iifP
[1].object
|= tmp
<< 15;
975 case 'U': /* registerlist */
976 IIF (10, 1, 1, 0, 0, 0, 0, 0, 0, NULL
, -1, 0);
977 switch (operandsP
[(i
<< 1) + 1])
979 case 'u': /* restore, exit */
980 optlist (argv
[i
], opt1
, &iif
.iifP
[10].object
);
982 case 'U': /* save,enter */
983 optlist (argv
[i
], opt2
, &iif
.iifP
[10].object
);
988 case 'M': /* mmu register */
989 list_search (argv
[i
], mmureg
, &tmp
);
991 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
993 case 'P': /* cpu register */
994 list_search (argv
[i
], cpureg
, &tmp
);
996 iif
.iifP
[1].object
|= tmp
<< opcode_bit_ptr
;
998 case 'g': /* inss exts */
999 iif
.instr_size
+= 1; /* 1 byte is allocated after the opcode */
1001 (unsigned long) argv
[i
], /* i always 2 here */
1003 bit_fix_new (3, 5, 0, 7, 0, 0, 0), /* a bit_fix is targeted to
1009 (unsigned long) argv
[i
], /* i always 3 here */
1011 bit_fix_new (5, 0, 1, 32, -1, 0, -1), -1, 0);
1014 iif
.instr_size
+= 1;
1015 b
= 2 + i
; /* put the extension byte after opcode */
1016 IIF (b
, 2, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0);
1019 as_fatal (_("Bad opcode-table-option, check in file ns32k-opcode.h"));
1024 /* in: instruction line
1025 out: internal structure of instruction
1026 that has been prepared for direct conversion to fragment(s) and
1027 fixes in a systematical fashion
1028 Return-value = recursive_level
1030 /* build iif of one assembly text line */
1032 parse (line
, recursive_level
)
1034 int recursive_level
;
1036 register char *lineptr
, c
, suffix_separator
;
1040 char suffix
[MAX_ARGS
], *argv
[MAX_ARGS
]; /* no more than 4 operands */
1041 if (recursive_level
<= 0)
1042 { /* called from md_assemble */
1043 for (lineptr
= line
; (*lineptr
) != '\0' && (*lineptr
) != ' '; lineptr
++);
1046 if (!(desc
= (struct ns32k_opcode
*) hash_find (inst_hash_handle
, line
)))
1048 as_fatal (_("No such opcode"));
1057 if (*desc
->operands
)
1059 if (*lineptr
++ != '\0')
1063 while (*lineptr
!= '\0')
1065 if (desc
->operands
[argc
<< 1])
1068 arg_type
= desc
->operands
[(argc
<< 1) + 1];
1074 case 'H': /* the operand is supposed to be a
1076 /* Hackwarning: do not forget to update the 4
1077 cases above when editing ns32k-opcode.h */
1078 suffix_separator
= ':';
1081 suffix_separator
= '\255'; /* if this char occurs we
1084 suffix
[argc
] = 0; /* 0 when no ':' is encountered */
1085 argv
[argc
] = freeptr
;
1087 while ((c
= *lineptr
) != '\0' && c
!= sep
)
1102 if (c
== suffix_separator
)
1103 { /* ':' - label/suffix separator */
1116 as_warn (_("Bad suffix, defaulting to d"));
1118 if (lineptr
[1] == '\0' || lineptr
[1] == sep
)
1132 if (*lineptr
== '\0')
1138 as_fatal (_("Too many operands passed to instruction"));
1143 if (argc
!= strlen (desc
->operands
) / 2)
1145 if (strlen (desc
->default_args
))
1146 { /* we can apply default, dont goof */
1147 if (parse (desc
->default_args
, 1) != 1)
1148 { /* check error in default */
1149 as_fatal (_("Wrong numbers of operands in default, check ns32k-opcodes.h"));
1154 as_fatal (_("Wrong number of operands"));
1158 for (i
= 0; i
< IIF_ENTRIES
; i
++)
1160 iif
.iifP
[i
].type
= 0; /* mark all entries as void*/
1163 /* build opcode iif-entry */
1164 iif
.instr_size
= desc
->opcode_size
/ 8;
1165 IIF (1, 1, iif
.instr_size
, desc
->opcode_seed
, 0, 0, 0, 0, 0, 0, -1, 0);
1167 /* this call encodes operands to iif format */
1170 encode_operand (argc
,
1177 return recursive_level
;
1181 /* Convert iif to fragments. From this point we start to dribble with
1182 * functions in other files than this one.(Except hash.c) So, if it's
1183 * possible to make an iif for an other CPU, you don't need to know
1184 * what frags, relax, obstacks, etc is in order to port this
1185 * assembler. You only need to know if it's possible to reduce your
1186 * cpu-instruction to iif-format (takes some work) and adopt the other
1187 * md_? parts according to given instructions Note that iif was
1188 * invented for the clean ns32k`s architecure.
1191 /* GAS for the ns32k has a problem. PC relative displacements are
1192 * relative to the address of the opcode, not the address of the
1193 * operand. We used to keep track of the offset between the operand
1194 * and the opcode in pcrel_adjust for each frag and each fix. However,
1195 * we get into trouble where there are two or more pc-relative
1196 * operands and the size of the first one can't be determined. Then in
1197 * the relax phase, the size of the first operand will change and
1198 * pcrel_adjust will no longer be correct. The current solution is
1199 * keep a pointer to the frag with the opcode in it and the offset in
1200 * that frag for each frag and each fix. Then, when needed, we can
1201 * always figure out how far it is between the opcode and the pcrel
1202 * object. See also md_pcrel_adjust and md_fix_pcrel_adjust. For
1203 * objects not part of an instruction, the pointer to the opcode frag
1204 * is always zero. */
1212 unsigned int inst_offset
;
1221 memP
= frag_more (0);
1223 inst_offset
= (memP
- frag_now
->fr_literal
);
1224 inst_frag
= frag_now
;
1226 for (i
= 0; i
< IIF_ENTRIES
; i
++)
1228 if (type
= iif
.iifP
[i
].type
)
1229 { /* the object exist, so handle it */
1230 switch (size
= iif
.iifP
[i
].size
)
1233 size
= 0; /* it's a bitfix that operates on an existing
1235 if (iif
.iifP
[i
].bit_fixP
->fx_bit_base
)
1236 { /* expand fx_bit_base to point at opcode */
1237 iif
.iifP
[i
].bit_fixP
->fx_bit_base
= (long) inst_opcode
;
1239 case 8: /* bignum or doublefloat */
1243 case 4: /* the final size in objectmemory is known */
1244 memP
= frag_more(size
);
1245 j
= iif
.iifP
[i
].bit_fixP
;
1248 case 1: /* the object is pure binary */
1249 if (j
|| iif
.iifP
[i
].pcrel
)
1251 fix_new_ns32k (frag_now
,
1252 (long) (memP
- frag_now
->fr_literal
),
1257 iif
.iifP
[i
].im_disp
,
1259 iif
.iifP
[i
].bsr
, /* sequent hack */
1260 inst_frag
, inst_offset
);
1263 { /* good, just put them bytes out */
1264 switch (iif
.iifP
[i
].im_disp
)
1267 md_number_to_chars (memP
, iif
.iifP
[i
].object
, size
);
1270 md_number_to_disp (memP
, iif
.iifP
[i
].object
, size
);
1273 as_fatal (_("iif convert internal pcrel/binary"));
1278 /* the object is a pointer at an expression, so
1279 unpack it, note that bignums may result from the
1281 evaluate_expr (&exprP
, (char *) iif
.iifP
[i
].object
);
1282 if (exprP
.X_op
== O_big
|| size
== 8)
1284 if ((k
= exprP
.X_add_number
) > 0)
1286 /* we have a bignum ie a quad. This can only
1287 happens in a long suffixed instruction */
1289 as_warn (_("Bignum too big for long"));
1292 for (l
= 0; k
> 0; k
--, l
+= 2)
1294 md_number_to_chars (memP
+ l
,
1295 generic_bignum
[l
>> 1],
1296 sizeof (LITTLENUM_TYPE
));
1301 LITTLENUM_TYPE words
[4];
1306 gen_to_words (words
, 2, 8);
1307 md_number_to_imm (memP
, (long) words
[0],
1308 sizeof (LITTLENUM_TYPE
));
1309 md_number_to_imm (memP
+ sizeof (LITTLENUM_TYPE
),
1311 sizeof (LITTLENUM_TYPE
));
1314 gen_to_words (words
, 4, 11);
1315 md_number_to_imm (memP
, (long) words
[0],
1316 sizeof (LITTLENUM_TYPE
));
1317 md_number_to_imm (memP
+ sizeof (LITTLENUM_TYPE
),
1319 sizeof (LITTLENUM_TYPE
));
1320 md_number_to_imm ((memP
+ 2
1321 * sizeof (LITTLENUM_TYPE
)),
1323 sizeof (LITTLENUM_TYPE
));
1324 md_number_to_imm ((memP
+ 3
1325 * sizeof (LITTLENUM_TYPE
)),
1327 sizeof (LITTLENUM_TYPE
));
1334 exprP
.X_add_symbol
||
1335 exprP
.X_op_symbol
||
1338 /* The expression was undefined due to an
1339 undefined label. Create a fix so we can fix
1340 the object later. */
1341 exprP
.X_add_number
+= iif
.iifP
[i
].object_adjust
;
1342 fix_new_ns32k_exp (frag_now
,
1343 (long) (memP
- frag_now
->fr_literal
),
1347 iif
.iifP
[i
].im_disp
,
1350 inst_frag
, inst_offset
);
1354 /* good, just put them bytes out */
1355 switch (iif
.iifP
[i
].im_disp
)
1358 md_number_to_imm (memP
, exprP
.X_add_number
, size
);
1361 md_number_to_disp (memP
, exprP
.X_add_number
, size
);
1364 as_fatal (_("iif convert internal pcrel/pointer"));
1369 as_fatal (_("Internal logic error in iif.iifP[n].type"));
1373 /* To bad, the object may be undefined as far as its
1374 final nsize in object memory is concerned. The size
1375 of the object in objectmemory is not explicitly
1376 given. If the object is defined its length can be
1377 determined and a fix can replace the frag. */
1379 evaluate_expr (&exprP
, (char *) iif
.iifP
[i
].object
);
1380 if ((exprP
.X_add_symbol
|| exprP
.X_op_symbol
) &&
1383 /* Size is unknown until link time so have to
1386 memP
= frag_more(size
);
1387 fix_new_ns32k_exp (frag_now
,
1388 (long) (memP
- frag_now
->fr_literal
),
1391 0, /* never iif.iifP[i].pcrel, */
1392 1, /* always iif.iifP[i].im_disp */
1396 break; /* exit this absolute hack */
1399 if (exprP
.X_add_symbol
|| exprP
.X_op_symbol
)
1401 if (exprP
.X_op_symbol
)
1402 { /* We cant relax this case */
1403 as_fatal (_("Can't relax difference"));
1408 /* Size is not important. This gets fixed by relax,
1409 * but we assume 0 in what follows
1411 memP
= frag_more(4); /* Max size */
1415 fragS
*old_frag
= frag_now
;
1416 frag_variant (rs_machine_dependent
,
1419 IND (BRANCH
, UNDEF
), /* expecting the worst */
1423 frag_opcode_frag(old_frag
) = inst_frag
;
1424 frag_opcode_offset(old_frag
) = inst_offset
;
1425 frag_bsr(old_frag
) = iif
.iifP
[i
].bsr
;
1431 /* This duplicates code in md_number_to_disp */
1432 if (-64 <= exprP
.X_add_number
&& exprP
.X_add_number
<= 63)
1438 if (-8192 <= exprP
.X_add_number
1439 && exprP
.X_add_number
<= 8191)
1445 if (-0x20000000<=exprP
.X_add_number
&&
1446 exprP
.X_add_number
<=0x1fffffff)
1452 as_warn (_("Displacement to large for :d"));
1457 memP
= frag_more(size
);
1458 md_number_to_disp (memP
, exprP
.X_add_number
, size
);
1463 as_fatal (_("Internal logic error in iif.iifP[].type"));
1469 #ifdef BFD_ASSEMBLER
1470 /* This functionality should really be in the bfd library */
1471 static bfd_reloc_code_real_type
1472 reloc (int size
, int pcrel
, int type
)
1475 bfd_reloc_code_real_type relocs
[] = {
1476 BFD_RELOC_NS32K_IMM_8
,
1477 BFD_RELOC_NS32K_IMM_16
,
1478 BFD_RELOC_NS32K_IMM_32
,
1479 BFD_RELOC_NS32K_IMM_8_PCREL
,
1480 BFD_RELOC_NS32K_IMM_16_PCREL
,
1481 BFD_RELOC_NS32K_IMM_32_PCREL
,
1483 /* ns32k displacements */
1484 BFD_RELOC_NS32K_DISP_8
,
1485 BFD_RELOC_NS32K_DISP_16
,
1486 BFD_RELOC_NS32K_DISP_32
,
1487 BFD_RELOC_NS32K_DISP_8_PCREL
,
1488 BFD_RELOC_NS32K_DISP_16_PCREL
,
1489 BFD_RELOC_NS32K_DISP_32_PCREL
,
1491 /* Normal 2's complement */
1514 index
= length
+ 3 * pcrel
+ 6 * type
;
1515 if (index
>= 0 && index
< sizeof(relocs
)/sizeof(relocs
[0]))
1516 return relocs
[index
];
1518 as_bad (_("Can not do %d byte pc-relative relocation for storage type %d"),
1521 as_bad (_("Can not do %d byte relocation for storage type %d"),
1523 return BFD_RELOC_NONE
;
1533 freeptr
= freeptr_static
;
1534 parse (line
, 0); /* explode line to more fix form in iif */
1535 convert_iif (); /* convert iif to frags, fix's etc */
1537 printf (" \t\t\t%s\n", line
);
1545 /* build a hashtable of the instructions */
1546 const struct ns32k_opcode
*ptr
;
1548 inst_hash_handle
= hash_new ();
1549 for (ptr
= ns32k_opcodes
; ptr
< endop
; ptr
++)
1551 if ((stat
= hash_insert (inst_hash_handle
, ptr
->name
, (char *) ptr
)))
1553 as_fatal (_("Can't hash %s: %s"), ptr
->name
, stat
); /*fatal*/
1556 freeptr_static
= (char *) malloc (PRIVATE_SIZE
); /* some private space
1560 /* Must be equal to MAX_PRECISON in atof-ieee.c */
1561 #define MAX_LITTLENUMS 6
1563 /* Turn the string pointed to by litP into a floating point constant
1564 of type type, and emit the appropriate bytes. The number of
1565 LITTLENUMS emitted is stored in *sizeP . An error message is
1566 returned, or NULL on OK. */
1568 md_atof (type
, litP
, sizeP
)
1574 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1575 LITTLENUM_TYPE
*wordP
;
1589 return _("Bad call to MD_ATOF()");
1591 t
= atof_ieee (input_line_pointer
, type
, words
);
1593 input_line_pointer
= t
;
1595 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1596 for (wordP
= words
+ prec
; prec
--;)
1598 md_number_to_chars (litP
, (long) (*--wordP
), sizeof (LITTLENUM_TYPE
));
1599 litP
+= sizeof (LITTLENUM_TYPE
);
1604 /* Convert number to chars in correct order */
1607 md_number_to_chars (buf
, value
, nbytes
)
1612 number_to_chars_littleendian (buf
, value
, nbytes
);
1616 /* This is a variant of md_numbers_to_chars. The reason for its'
1617 existence is the fact that ns32k uses Huffman coded
1618 displacements. This implies that the bit order is reversed in
1619 displacements and that they are prefixed with a size-tag.
1623 10xxxxxx xxxxxxxx word
1624 11xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx double word
1626 This must be taken care of and we do it here! */
1628 md_number_to_disp (buf
, val
, n
)
1636 if (val
< -64 || val
> 63)
1637 as_warn (_("Byte displacement out of range. line number not valid"));
1640 printf ("%x ", val
& 0xff);
1645 if (val
< -8192 || val
> 8191)
1646 as_warn (_("Word displacement out of range. line number not valid"));
1650 printf ("%x ", val
>> 8 & 0xff);
1652 *buf
++ = (val
>> 8);
1654 printf ("%x ", val
& 0xff);
1659 if (val
< -0x20000000 || val
>= 0x20000000)
1660 as_warn (_("Double word displacement out of range"));
1663 printf ("%x ", val
>> 24 & 0xff);
1665 *buf
++ = (val
>> 24);
1667 printf ("%x ", val
>> 16 & 0xff);
1669 *buf
++ = (val
>> 16);
1671 printf ("%x ", val
>> 8 & 0xff);
1673 *buf
++ = (val
>> 8);
1675 printf ("%x ", val
& 0xff);
1680 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1681 __LINE__
, __FILE__
);
1686 md_number_to_imm (buf
, val
, n
)
1695 printf ("%x ", val
& 0xff);
1701 printf ("%x ", val
>> 8 & 0xff);
1703 *buf
++ = (val
>> 8);
1705 printf ("%x ", val
& 0xff);
1711 printf ("%x ", val
>> 24 & 0xff);
1713 *buf
++ = (val
>> 24);
1715 printf ("%x ", val
>> 16 & 0xff);
1717 *buf
++ = (val
>> 16);
1719 printf ("%x ", val
>> 8 & 0xff);
1721 *buf
++ = (val
>> 8);
1723 printf ("%x ", val
& 0xff);
1728 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1729 __LINE__
, __FILE__
);
1734 /* fast bitfiddling support */
1735 /* mask used to zero bitfield before oring in the true field */
1737 static unsigned long l_mask
[] =
1739 0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
1740 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
1741 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
1742 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
1743 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
1744 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
1745 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
1746 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
1748 static unsigned long r_mask
[] =
1750 0x00000000, 0x00000001, 0x00000003, 0x00000007,
1751 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
1752 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
1753 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
1754 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
1755 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
1756 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
1757 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
1759 #define MASK_BITS 31
1760 /* Insert bitfield described by field_ptr and val at buf
1761 This routine is written for modification of the first 4 bytes pointed
1762 to by buf, to yield speed.
1763 The ifdef stuff is for selection between a ns32k-dependent routine
1764 and a general version. (My advice: use the general version!)
1768 md_number_to_field (buf
, val
, field_ptr
)
1771 register bit_fixS
*field_ptr
;
1773 register unsigned long object
;
1774 register unsigned long mask
;
1775 /* define ENDIAN on a ns32k machine */
1777 register unsigned long *mem_ptr
;
1779 register char *mem_ptr
;
1781 if (field_ptr
->fx_bit_min
<= val
&& val
<= field_ptr
->fx_bit_max
)
1784 if (field_ptr
->fx_bit_base
)
1785 { /* override buf */
1786 mem_ptr
= (unsigned long *) field_ptr
->fx_bit_base
;
1790 mem_ptr
= (unsigned long *) buf
;
1792 mem_ptr
= ((unsigned long *)
1793 ((char *) mem_ptr
+ field_ptr
->fx_bit_base_adj
));
1795 if (field_ptr
->fx_bit_base
)
1796 { /* override buf */
1797 mem_ptr
= (char *) field_ptr
->fx_bit_base
;
1803 mem_ptr
+= field_ptr
->fx_bit_base_adj
;
1805 #ifdef ENDIAN /* we have a nice ns32k machine with lowbyte
1806 at low-physical mem */
1807 object
= *mem_ptr
; /* get some bytes */
1808 #else /* OVE Goof! the machine is a m68k or dito */
1809 /* That takes more byte fiddling */
1811 object
|= mem_ptr
[3] & 0xff;
1813 object
|= mem_ptr
[2] & 0xff;
1815 object
|= mem_ptr
[1] & 0xff;
1817 object
|= mem_ptr
[0] & 0xff;
1820 mask
|= (r_mask
[field_ptr
->fx_bit_offset
]);
1821 mask
|= (l_mask
[field_ptr
->fx_bit_offset
+ field_ptr
->fx_bit_size
]);
1823 val
+= field_ptr
->fx_bit_add
;
1824 object
|= ((val
<< field_ptr
->fx_bit_offset
) & (mask
^ 0xffffffff));
1828 mem_ptr
[0] = (char) object
;
1830 mem_ptr
[1] = (char) object
;
1832 mem_ptr
[2] = (char) object
;
1834 mem_ptr
[3] = (char) object
;
1839 as_warn (_("Bit field out of range"));
1843 int md_pcrel_adjust (fragS
*fragP
)
1846 addressT opcode_address
;
1847 unsigned int offset
;
1848 opcode_frag
= frag_opcode_frag(fragP
);
1849 if (opcode_frag
== 0)
1851 offset
= frag_opcode_offset(fragP
);
1852 opcode_address
= offset
+ opcode_frag
->fr_address
;
1853 return fragP
->fr_address
+ fragP
->fr_fix
- opcode_address
;
1856 int md_fix_pcrel_adjust (fixS
*fixP
)
1858 fragS
*fragP
= fixP
->fx_frag
;
1860 addressT opcode_address
;
1861 unsigned int offset
;
1862 opcode_frag
= fix_opcode_frag(fixP
);
1863 if (opcode_frag
== 0)
1865 offset
= fix_opcode_offset(fixP
);
1866 opcode_address
= offset
+ opcode_frag
->fr_address
;
1867 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
- opcode_address
;
1870 /* Apply a fixS (fixup of an instruction or data that we didn't have
1871 enough info to complete immediately) to the data in a frag.
1873 On the ns32k, everything is in a different format, so we have broken
1874 out separate functions for each kind of thing we could be fixing.
1875 They all get called from here. */
1877 #ifdef BFD_ASSEMBLER
1879 md_apply_fix (fixP
, valp
)
1884 md_apply_fix (fixP
, val
)
1889 #ifdef BFD_ASSEMBLER
1892 fragS
*fragP
= fixP
->fx_frag
;
1894 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1896 if (fix_bit_fixP(fixP
))
1897 { /* Bitfields to fix, sigh */
1898 md_number_to_field (buf
, val
, fix_bit_fixP(fixP
));
1901 switch (fix_im_disp(fixP
))
1904 case 0: /* Immediate field */
1905 md_number_to_imm (buf
, val
, fixP
->fx_size
);
1908 case 1: /* Displacement field */
1909 /* Calculate offset */
1911 md_number_to_disp (buf
,
1912 (fixP
->fx_pcrel
? val
+ md_fix_pcrel_adjust(fixP
)
1913 : val
), fixP
->fx_size
);
1917 case 2: /* Pointer in a data object */
1918 md_number_to_chars (buf
, val
, fixP
->fx_size
);
1921 #ifdef BSD_ASSEMBLER
1926 /* Convert a relaxed displacement to ditto in final output */
1928 #ifndef BFD_ASSEMBLER
1930 md_convert_frag (headers
, sec
, fragP
)
1931 object_headers
*headers
;
1933 register fragS
*fragP
;
1936 md_convert_frag (abfd
, sec
, fragP
)
1939 register fragS
*fragP
;
1945 /* Address in gas core of the place to store the displacement. */
1946 register char *buffer_address
= fragP
->fr_fix
+ fragP
->fr_literal
;
1947 /* Address in object code of the displacement. */
1952 switch (fragP
->fr_subtype
)
1954 case IND (BRANCH
, BYTE
):
1957 case IND (BRANCH
, WORD
):
1960 case IND (BRANCH
, DOUBLE
):
1968 know (fragP
->fr_symbol
);
1970 object_address
= fragP
->fr_fix
+ fragP
->fr_address
;
1971 /* The displacement of the address, from current location. */
1972 disp
= (S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
) - object_address
;
1973 #ifdef BFD_ASSEMBLER
1974 disp
+= symbol_get_frag (fragP
->fr_symbol
)->fr_address
;
1976 disp
+= md_pcrel_adjust(fragP
);
1978 md_number_to_disp (buffer_address
, (long) disp
, (int) ext
);
1979 fragP
->fr_fix
+= ext
;
1982 /* This function returns the estimated size a variable object will occupy,
1983 one can say that we tries to guess the size of the objects before we
1987 md_estimate_size_before_relax (fragP
, segment
)
1988 register fragS
*fragP
;
1992 old_fix
= fragP
->fr_fix
;
1993 switch (fragP
->fr_subtype
)
1995 case IND (BRANCH
, UNDEF
):
1996 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
1998 /* the symbol has been assigned a value */
1999 fragP
->fr_subtype
= IND (BRANCH
, BYTE
);
2003 /* we don't relax symbols defined in an other segment the
2004 thing to do is to assume the object will occupy 4 bytes */
2005 fix_new_ns32k (fragP
,
2006 (int) (fragP
->fr_fix
),
2013 frag_bsr(fragP
), /*sequent hack */
2014 frag_opcode_frag(fragP
),
2015 frag_opcode_offset(fragP
));
2017 /* fragP->fr_opcode[1]=0xff; */
2021 case IND (BRANCH
, BYTE
):
2027 return fragP
->fr_var
+ fragP
->fr_fix
- old_fix
;
2030 int md_short_jump_size
= 3;
2031 int md_long_jump_size
= 5;
2032 const int md_reloc_size
= 8; /* Size of relocation record */
2035 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2037 addressT from_addr
, to_addr
;
2043 offset
= to_addr
- from_addr
;
2044 md_number_to_chars (ptr
, (valueT
) 0xEA, 1);
2045 md_number_to_disp (ptr
+ 1, (valueT
) offset
, 2);
2049 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2051 addressT from_addr
, to_addr
;
2057 offset
= to_addr
- from_addr
;
2058 md_number_to_chars (ptr
, (valueT
) 0xEA, 1);
2059 md_number_to_disp (ptr
+ 1, (valueT
) offset
, 4);
2062 CONST
char *md_shortopts
= "m:";
2063 struct option md_longopts
[] = {
2064 {NULL
, no_argument
, NULL
, 0}
2066 size_t md_longopts_size
= sizeof(md_longopts
);
2069 md_parse_option (c
, arg
)
2076 if (!strcmp (arg
, "32032"))
2078 cpureg
= cpureg_032
;
2079 mmureg
= mmureg_032
;
2081 else if (!strcmp (arg
, "32532"))
2083 cpureg
= cpureg_532
;
2084 mmureg
= mmureg_532
;
2088 as_bad (_("invalid architecture option -m%s"), arg
);
2101 md_show_usage (stream
)
2104 fprintf(stream
, _("\
2106 -m32032 | -m32532 select variant of NS32K architecture\n"));
2113 * Create a bit_fixS in obstack 'notes'.
2114 * This struct is used to profile the normal fix. If the bit_fixP is a
2115 * valid pointer (not NULL) the bit_fix data will be used to format the fix.
2118 bit_fix_new (size
, offset
, min
, max
, add
, base_type
, base_adj
)
2119 char size
; /* Length of bitfield */
2120 char offset
; /* Bit offset to bitfield */
2121 long min
; /* Signextended min for bitfield */
2122 long max
; /* Signextended max for bitfield */
2123 long add
; /* Add mask, used for huffman prefix */
2124 long base_type
; /* 0 or 1, if 1 it's exploded to opcode ptr */
2127 register bit_fixS
*bit_fixP
;
2129 bit_fixP
= (bit_fixS
*) obstack_alloc (¬es
, sizeof (bit_fixS
));
2131 bit_fixP
->fx_bit_size
= size
;
2132 bit_fixP
->fx_bit_offset
= offset
;
2133 bit_fixP
->fx_bit_base
= base_type
;
2134 bit_fixP
->fx_bit_base_adj
= base_adj
;
2135 bit_fixP
->fx_bit_max
= max
;
2136 bit_fixP
->fx_bit_min
= min
;
2137 bit_fixP
->fx_bit_add
= add
;
2143 fix_new_ns32k (frag
, where
, size
, add_symbol
, offset
, pcrel
,
2144 im_disp
, bit_fixP
, bsr
, opcode_frag
, opcode_offset
)
2145 fragS
*frag
; /* Which frag? */
2146 int where
; /* Where in that frag? */
2147 int size
; /* 1, 2 or 4 usually. */
2148 symbolS
*add_symbol
; /* X_add_symbol. */
2149 long offset
; /* X_add_number. */
2150 int pcrel
; /* TRUE if PC-relative relocation. */
2151 char im_disp
; /* true if the value to write is a
2153 bit_fixS
*bit_fixP
; /* pointer at struct of bit_fix's, ignored if
2155 char bsr
; /* sequent-linker-hack: 1 when relocobject is
2158 unsigned int opcode_offset
;
2161 fixS
*fixP
= fix_new (frag
, where
, size
, add_symbol
,
2163 #ifdef BFD_ASSEMBLER
2164 bit_fixP
? NO_RELOC
: reloc(size
, pcrel
, im_disp
)
2170 fix_opcode_frag(fixP
) = opcode_frag
;
2171 fix_opcode_offset(fixP
) = opcode_offset
;
2172 fix_im_disp(fixP
) = im_disp
;
2173 fix_bsr(fixP
) = bsr
;
2174 fix_bit_fixP(fixP
) = bit_fixP
;
2175 } /* fix_new_ns32k() */
2178 fix_new_ns32k_exp (frag
, where
, size
, exp
, pcrel
,
2179 im_disp
, bit_fixP
, bsr
, opcode_frag
, opcode_offset
)
2180 fragS
*frag
; /* Which frag? */
2181 int where
; /* Where in that frag? */
2182 int size
; /* 1, 2 or 4 usually. */
2183 expressionS
*exp
; /* Expression. */
2184 int pcrel
; /* TRUE if PC-relative relocation. */
2185 char im_disp
; /* true if the value to write is a
2187 bit_fixS
*bit_fixP
; /* pointer at struct of bit_fix's, ignored if
2189 char bsr
; /* sequent-linker-hack: 1 when relocobject is
2192 unsigned int opcode_offset
;
2194 fixS
*fixP
= fix_new_exp (frag
, where
, size
, exp
, pcrel
,
2195 #ifdef BFD_ASSEMBLER
2196 bit_fixP
? NO_RELOC
: reloc(size
, pcrel
, im_disp
)
2202 fix_opcode_frag(fixP
) = opcode_frag
;
2203 fix_opcode_offset(fixP
) = opcode_offset
;
2204 fix_im_disp(fixP
) = im_disp
;
2205 fix_bsr(fixP
) = bsr
;
2206 fix_bit_fixP(fixP
) = bit_fixP
;
2207 } /* fix_new_ns32k() */
2209 /* This is TC_CONS_FIX_NEW, called by emit_expr in read.c. */
2212 cons_fix_new_ns32k (frag
, where
, size
, exp
)
2213 fragS
*frag
; /* Which frag? */
2214 int where
; /* Where in that frag? */
2215 int size
; /* 1, 2 or 4 usually. */
2216 expressionS
*exp
; /* Expression. */
2218 fix_new_ns32k_exp (frag
, where
, size
, exp
,
2222 /* We have no need to default values of symbols. */
2225 md_undefined_symbol (name
)
2231 /* Round up a section size to the appropriate boundary. */
2233 md_section_align (segment
, size
)
2237 return size
; /* Byte alignment is fine */
2240 /* Exactly what point is a PC-relative offset relative TO? On the
2241 ns32k, they're relative to the start of the instruction. */
2243 md_pcrel_from (fixP
)
2247 res
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2248 #ifdef SEQUENT_COMPATABILITY
2249 if (frag_bsr(fixP
->fx_frag
))
2250 res
+= 0x12 /* FOO Kludge alert! */
2255 #ifdef BFD_ASSEMBLER
2258 tc_gen_reloc (section
, fixp
)
2263 bfd_reloc_code_real_type code
;
2265 code
= reloc(fixp
->fx_size
, fixp
->fx_pcrel
, fix_im_disp(fixp
));
2267 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2268 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2269 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2270 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2272 rel
->addend
= fixp
->fx_addnumber
;
2276 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2281 name
= S_GET_NAME (fixp
->fx_addsy
);
2283 name
= _("<unknown>");
2284 as_fatal (_("Cannot find relocation type for symbol %s, code %d"),
2290 #else /* BFD_ASSEMBLER */
2294 cons_fix_new_ns32k (where
, fixP
, segment_address_in_file
)
2297 relax_addressT segment_address_in_file
;
2300 * In: length of relocation (or of address) in chars: 1, 2 or 4.
2301 * Out: GNU LD relocation length code: 0, 1, or 2.
2304 static unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
2307 know (fixP
->fx_addsy
!= NULL
);
2309 md_number_to_chars (where
,
2310 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
2313 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
2314 ? S_GET_TYPE (fixP
->fx_addsy
)
2315 : fixP
->fx_addsy
->sy_number
);
2317 md_number_to_chars (where
+ 4,
2318 ((long) (r_symbolnum
)
2319 | (long) (fixP
->fx_pcrel
<< 24)
2320 | (long) (nbytes_r_length
[fixP
->fx_size
] << 25)
2321 | (long) ((!S_IS_DEFINED (fixP
->fx_addsy
)) << 27)
2322 | (long) (fix_bsr(fixP
) << 28)
2323 | (long) (fix_im_disp(fixP
) << 29)),
2327 #endif /* OBJ_AOUT */
2328 #endif /* BFD_ASSMEBLER */
2330 /* end of tc-ns32k.c */