1 /* tc-ldx.c -- Assemble for the DLX
2 Copyright 2002 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 /* Initially created by Kuang Hwa Lin, 3/20/2002. */
23 #include "safe-ctype.h"
26 #include "opcode/dlx.h"
31 /* Make it easier to clone this machine desc into another one. */
32 #define machine_opcode dlx_opcode
33 #define machine_opcodes dlx_opcodes
34 #define machine_ip dlx_ip
35 #define machine_it dlx_it
37 #define NO_RELOC BFD_RELOC_NONE
38 #define RELOC_DLX_REL26 BFD_RELOC_DLX_JMP26
39 #define RELOC_DLX_16 BFD_RELOC_16
40 #define RELOC_DLX_REL16 BFD_RELOC_16_PCREL_S2
41 #define RELOC_DLX_HI16 BFD_RELOC_HI16_S
42 #define RELOC_DLX_LO16 BFD_RELOC_LO16
43 #define RELOC_DLX_VTINHERIT BFD_RELOC_VTABLE_INHERIT
44 #define RELOC_DLX_VTENTRY BFD_RELOC_VTABLE_ENTRY
46 /* handle of the OPCODE hash table */
47 static struct hash_control
*op_hash
= NULL
;
57 int reloc_offset
; /* Offset of reloc within insn. */
64 /* static void print_insn PARAMS ((struct machine_it *)); */
65 char * parse_operand
PARAMS ((char *, expressionS
*));
66 int md_chars_to_number
PARAMS ((unsigned char *, int));
68 static void machine_ip
PARAMS ((char *));
69 static void s_proc
PARAMS ((int));
70 static void insert_sreg
PARAMS ((char *, int));
71 static int hilo_modifier_ok
PARAMS ((char *));
72 static int is_ldst_registers
PARAMS ((char *));
73 static int match_sft_register
PARAMS ((char *));
74 static void define_some_regs
PARAMS ((void));
75 static char * dlx_parse_loadop
PARAMS ((char *));
76 static char * dlx_parse_storeop
PARAMS ((char *));
77 static char * fix_ld_st_operand
PARAMS ((unsigned long, char *));
83 /* Some additional ops that are used by gcc-dlx. */
84 {"asciiz", stringer
, 1},
89 {"endproc", s_proc
, 1},
93 /* This array holds the chars that always start a comment. If the
94 pre-processor is disabled, these aren't very useful. */
95 const char comment_chars
[] = ";";
97 /* This array holds the chars that only start a comment at the beginning of
98 a line. If the line seems to have the form '# 123 filename'
99 .line and .file directives will appear in the pre-processed output. */
100 /* Note that input_file.c hand checks for '#' at the beginning of the
101 first line of the input file. This is because the compiler outputs
102 #NO_APP at the beginning of its output. */
103 /* Also note that comments like this one will always work. */
104 const char line_comment_chars
[] = "#";
106 /* We needed an unused char for line separation to work around the
107 lack of macros, using sed and such. */
108 const char line_separator_chars
[] = "@";
110 /* Chars that can be used to separate mant from exp in floating point nums. */
111 const char EXP_CHARS
[] = "eE";
113 /* Chars that mean this number is a floating point constant.
116 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
119 insert_sreg (regname
, regnum
)
123 /* Must be large enough to hold the names of the special registers. */
127 symbol_table_insert (symbol_new (regname
, reg_section
, (valueT
) regnum
,
128 &zero_address_frag
));
129 for (i
= 0; regname
[i
]; i
++)
130 buf
[i
] = ISLOWER (regname
[i
]) ? TOUPPER (regname
[i
]) : regname
[i
];
133 symbol_table_insert (symbol_new (buf
, reg_section
, (valueT
) regnum
,
134 &zero_address_frag
));
137 /* Install symbol definitions for assorted special registers.
138 See MIPS Assembly Language Programmer's Guide page 1-4 */
144 /* Hardware representation. */
145 insert_sreg ("r0", 0);
146 insert_sreg ("r1", 1);
147 insert_sreg ("r2", 2);
148 insert_sreg ("r3", 3);
149 insert_sreg ("r4", 4);
150 insert_sreg ("r5", 5);
151 insert_sreg ("r6", 6);
152 insert_sreg ("r7", 7);
153 insert_sreg ("r8", 8);
154 insert_sreg ("r9", 9);
155 insert_sreg ("r10", 10);
156 insert_sreg ("r11", 11);
157 insert_sreg ("r12", 12);
158 insert_sreg ("r13", 13);
159 insert_sreg ("r14", 14);
160 insert_sreg ("r15", 15);
161 insert_sreg ("r16", 16);
162 insert_sreg ("r17", 17);
163 insert_sreg ("r18", 18);
164 insert_sreg ("r19", 19);
165 insert_sreg ("r20", 20);
166 insert_sreg ("r21", 21);
167 insert_sreg ("r22", 22);
168 insert_sreg ("r23", 23);
169 insert_sreg ("r24", 24);
170 insert_sreg ("r25", 25);
171 insert_sreg ("r26", 26);
172 insert_sreg ("r27", 27);
173 insert_sreg ("r28", 28);
174 insert_sreg ("r29", 29);
175 insert_sreg ("r30", 30);
176 insert_sreg ("r31", 31);
178 /* Software representation. */
179 insert_sreg ("zero", 0);
180 insert_sreg ("at", 1);
181 insert_sreg ("v0", 2);
182 insert_sreg ("v1", 3);
183 insert_sreg ("a0", 4);
184 insert_sreg ("a1", 5);
185 insert_sreg ("a2", 6);
186 insert_sreg ("a3", 7);
187 insert_sreg ("t0", 8);
188 insert_sreg ("t1", 9);
189 insert_sreg ("t2", 10);
190 insert_sreg ("t3", 11);
191 insert_sreg ("t4", 12);
192 insert_sreg ("t5", 13);
193 insert_sreg ("t6", 14);
194 insert_sreg ("t7", 15);
195 insert_sreg ("s0", 16);
196 insert_sreg ("s1", 17);
197 insert_sreg ("s2", 18);
198 insert_sreg ("s3", 19);
199 insert_sreg ("s4", 20);
200 insert_sreg ("s5", 21);
201 insert_sreg ("s6", 22);
202 insert_sreg ("s7", 23);
203 insert_sreg ("t8", 24);
204 insert_sreg ("t9", 25);
205 insert_sreg ("k0", 26);
206 insert_sreg ("k1", 27);
207 insert_sreg ("gp", 28);
208 insert_sreg ("sp", 29);
209 insert_sreg ("fp", 30);
210 insert_sreg ("ra", 31);
211 /* Special registers. */
212 insert_sreg ("pc", 0);
213 insert_sreg ("npc", 1);
214 insert_sreg ("iad", 2);
217 /* Subroutine check the string to match an register, */
220 match_sft_register (name
)
223 #define MAX_REG_NO 35
224 /* Currently we have 35 software registers defined -
225 we borrowed from MIPS. */
226 static char *soft_reg
[] =
228 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
229 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9",
230 "s0", "s1", "s2", "s3", "s4", "s5", "s7", "k0", "k1",
231 "gp", "sp", "fp", "ra", "pc", "npc", "iad",
232 "EndofTab" /* End of the Table indicator */
234 char low_name
[21], *ptr
;
237 for (ptr
= name
,idx
= 0; *ptr
!= '\0'; ptr
++)
238 low_name
[idx
++] = TOLOWER (*ptr
);
240 low_name
[idx
] = '\0';
243 while (idx
< MAX_REG_NO
&& strcmp (soft_reg
[idx
], & low_name
[0]))
246 return idx
< MAX_REG_NO
;
249 /* Subroutine check the string to match an register. */
252 is_ldst_registers (name
)
257 /* The first character of the register name got to be either %, $, r of R. */
258 if ((ptr
[0] == '%' || ptr
[0] == '$' || ptr
[0] == 'r' || ptr
[0] == 'R')
259 && ISDIGIT ((unsigned char) ptr
[1]))
262 /* Now check the software register representation. */
263 return match_sft_register (ptr
);
266 /* Subroutine of s_proc so targets can choose a different default prefix.
267 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
273 /* Record the current function so that we can issue an error message for
274 misplaced .func,.endfunc, and also so that .endfunc needs no
276 static char *current_name
;
277 static char *current_label
;
281 if (current_name
== NULL
)
283 as_bad (_("missing .proc"));
284 ignore_rest_of_line ();
288 current_name
= current_label
= NULL
;
290 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
291 input_line_pointer
++;
298 if (current_name
!= NULL
)
300 as_bad (_(".endfunc missing for previous .proc"));
301 ignore_rest_of_line ();
305 name
= input_line_pointer
;
306 delim1
= get_symbol_end ();
307 name
= xstrdup (name
);
308 *input_line_pointer
= delim1
;
311 if (*input_line_pointer
!= ',')
313 char leading_char
= 0;
315 leading_char
= bfd_get_symbol_leading_char (stdoutput
);
316 /* Missing entry point, use function's name with the leading
319 asprintf (&label
, "%c%s", leading_char
, name
);
325 ++input_line_pointer
;
327 label
= input_line_pointer
;
328 delim2
= get_symbol_end ();
329 label
= xstrdup (label
);
330 *input_line_pointer
= delim2
;
334 current_label
= label
;
336 demand_empty_rest_of_line ();
339 /* This function is called once, at assembler startup time. It should
340 set up all the tables, etc., that the MD part of the assembler will
346 const char *retval
= NULL
;
350 /* Create a new hash table. */
351 op_hash
= hash_new ();
353 /* Hash up all the opcodes for fast use later. */
354 for (i
= 0; i
< num_dlx_opcodes
; i
++)
356 const char *name
= machine_opcodes
[i
].name
;
358 retval
= hash_insert (op_hash
, name
, (PTR
) &machine_opcodes
[i
]);
362 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
363 machine_opcodes
[i
].name
, retval
);
369 as_fatal (_("Broken assembler. No assembly attempted."));
375 /* Assemble a single instruction. Its label has already been handled
376 by the generic front end. We just parse opcode and operands, and
377 produce the bytes of data and relocation. */
390 /* Put out the opcode. */
391 md_number_to_chars (toP
, the_insn
.opcode
, 4);
393 /* Put out the symbol-dependent stuff. */
394 if (the_insn
.reloc
!= NO_RELOC
)
396 fixP
= fix_new_exp (frag_now
,
397 (toP
- frag_now
->fr_literal
+ the_insn
.reloc_offset
),
398 the_insn
.size
, & the_insn
.exp
, the_insn
.pcrel
,
401 switch (fixP
->fx_r_type
)
403 case RELOC_DLX_REL26
:
404 bitP
= malloc (sizeof (bit_fixS
));
405 bitP
->fx_bit_size
= 26;
406 bitP
->fx_bit_offset
= 25;
407 bitP
->fx_bit_base
= the_insn
.opcode
& 0xFC000000;
408 bitP
->fx_bit_base_adj
= 0;
409 bitP
->fx_bit_max
= 0;
410 bitP
->fx_bit_min
= 0;
411 bitP
->fx_bit_add
= 0x03FFFFFF;
412 fixP
->fx_bit_fixP
= bitP
;
414 case RELOC_DLX_REL16
:
415 bitP
= malloc (sizeof (bit_fixS
));
416 bitP
->fx_bit_size
= 16;
417 bitP
->fx_bit_offset
= 15;
418 bitP
->fx_bit_base
= the_insn
.opcode
& 0xFFFF0000;
419 bitP
->fx_bit_base_adj
= 0;
420 bitP
->fx_bit_max
= 0;
421 bitP
->fx_bit_min
= 0;
422 bitP
->fx_bit_add
= 0x0000FFFF;
423 fixP
->fx_bit_fixP
= bitP
;
426 bitP
= malloc (sizeof (bit_fixS
));
427 bitP
->fx_bit_size
= 16;
428 bitP
->fx_bit_offset
= 15;
429 bitP
->fx_bit_base
= the_insn
.opcode
& 0xFFFF0000;
430 bitP
->fx_bit_base_adj
= 0;
431 bitP
->fx_bit_max
= 0;
432 bitP
->fx_bit_min
= 0;
433 bitP
->fx_bit_add
= 0x0000FFFF;
434 fixP
->fx_bit_fixP
= bitP
;
437 fixP
->fx_bit_fixP
= (bit_fixS
*)NULL
;
453 for (idx
= 1; ptr
[idx
] != '\0' && ptr
[idx
] != '[' && idx
< 73; idx
+= 1)
465 return (count
== 0) ? 1:0;
469 parse_operand (s
, operandp
)
471 expressionS
*operandp
;
473 char *save
= input_line_pointer
;
476 the_insn
.HI
= the_insn
.LO
= 0;
478 /* Search for %hi and %lo, make a mark and skip it. */
479 if (strncmp (s
, "%hi", 3) == 0)
486 if (strncmp (s
, "%lo", 3) == 0)
495 if (the_insn
.HI
|| the_insn
.LO
)
497 if (!hilo_modifier_ok (s
))
498 as_bad (_("Expression Error for operand modifier %%hi/%%lo\n"));
501 /* Check for the % and $ register representation */
502 if ((s
[0] == '%' || s
[0] == '$' || s
[0] == 'r' || s
[0] == 'R')
503 && ISDIGIT ((unsigned char) s
[1]))
505 /* We have a numeric register expression. No biggy. */
507 input_line_pointer
= s
;
508 (void) expression (operandp
);
509 if (operandp
->X_op
!= O_constant
510 || operandp
->X_add_number
> 31)
511 as_bad (_("Invalid expression after %%%%\n"));
512 operandp
->X_op
= O_register
;
516 /* Normal operand parsing. */
517 input_line_pointer
= s
;
518 (void) expression (operandp
);
521 new = input_line_pointer
;
522 input_line_pointer
= save
;
526 /* This function will check the opcode and return 1 if the opcode is one
527 of the load/store instruction, and it will fix the operand string to
528 the standard form so we can use the standard parse_operand routine. */
530 #define READ_OP 0x100
531 #define WRITE_OP 0x200
532 static char iBuf
[81];
535 dlx_parse_loadop (str
)
541 /* The last pair of ()/[] is the register, all other are the
542 reloc displacement, and if there is a register then it ought
543 to have a pair of ()/[]
544 This is not necessarily true, what if the load instruction come
545 without the register and with %hi/%lo modifier? */
546 for (idx
= 0; idx
< 72 && ptr
[idx
] != '\0'; idx
++)
552 as_bad (_("Bad operand for a load instruction: <%s>"), str
);
559 char rs1
[7], rd
[7], endm
, match
= '0';
574 /* No register indicated, fill in zero. */
585 /* Searching for (/[ which will match the ]/). */
586 for (pb
= idx
- 1; str
[pb
] != match
; pb
-= 1)
587 /* Match can only be either '[' or '(', if it is
588 '(' then this can be an normal expression, we'll treat
590 if (str
[pb
] == endm
|| pb
< (idx
- 5))
594 for (i
= 0; (pb
+ i
) < idx
; i
++)
599 if (is_ldst_registers (& rs1
[0]))
600 /* Point to the last character of the imm. */
606 goto badoperand_load
;
607 /* No register indicated, fill in zero and restore the imm. */
615 /* Duplicate the first register. */
616 for (i
= 0; i
< 7 && str
[i
] != ','; i
++)
620 goto badoperand_load
;
626 /* Put the '\0' back in. */
629 for (i
++, m2
= 0; i
< pb
; m2
++,i
++)
634 /* Assemble the instruction to gas intrernal format. */
635 for (i
= 0; rd
[i
] != '\0'; i
++)
640 for (pb
= 0 ; rs1
[pb
] != '\0'; i
++, pb
++)
645 for (pb
= 0; imm
[pb
] != '\0'; i
++, pb
++)
654 dlx_parse_storeop (str
)
660 /* Search for the ','. */
661 for (idx
= 0; idx
< 72 && ptr
[idx
] != ','; idx
++)
667 as_bad (_("Bad operand for a store instruction: <%s>"), str
);
672 /* idx now points to the ','. */
676 char rs1
[7], rd
[7], endm
, match
= '0';
679 /* Now parse the '(' and ')', and make idx point to ')'. */
692 /* No register indicated, fill in zero. */
703 /* Searching for (/[ which will match the ]/). */
704 for (pb
= idx
- 1; str
[pb
] != match
; pb
-= 1)
705 if (pb
< (idx
- 5) || str
[pb
] == endm
)
709 for (i
= 0; (pb
+ i
) < idx
; i
++)
710 rs1
[i
] = str
[pb
+ i
];
714 if (is_ldst_registers (& rs1
[0]))
715 /* Point to the last character of the imm. */
721 goto badoperand_store
;
723 /* No register indicated, fill in zero and restore the imm. */
731 /* No register was specified. */
734 /* Duplicate the first register. */
735 for (i
= comma
+ 1; (str
[i
] == ' ' || str
[i
] == '\t'); i
++)
738 for (m2
= 0; (m2
< 7 && str
[i
] != '\0'); i
++, m2
++)
740 if (str
[i
] != ' ' && str
[i
] != '\t')
743 goto badoperand_store
;
747 goto badoperand_store
;
752 for (i
= 0; i
< pb
; i
++)
757 /* Assemble the instruction to gas intrernal format. */
758 for (i
= 0; rd
[i
] != '\0'; i
++)
761 for (pb
= 0 ; rs1
[pb
] != '\0'; i
++, pb
++)
764 for (pb
= 0; imm
[pb
] != '\0'; i
++, pb
++)
772 fix_ld_st_operand (opcode
, str
)
773 unsigned long opcode
;
776 /* Check the opcode. */
777 switch ((int) opcode
)
787 return dlx_parse_loadop (str
);
791 return dlx_parse_storeop (str
);
797 /* Instruction parsing. Takes a string containing the opcode.
798 Operands are at input_line_pointer. Output is in the_insn.
799 Warnings or errors are generated. */
807 struct machine_opcode
*insn
;
809 unsigned long opcode
;
810 expressionS the_operand
;
811 expressionS
*operand
= &the_operand
;
812 unsigned int reg
, reg_shift
= 0;
814 /* Fixup the opcode string to all lower cases, and also
815 allow numerical digits. */
819 for (; ISALNUM (*s
); ++s
)
828 /* FIXME-SOMEDAY more whitespace. */
834 as_bad (_("Unknown opcode: `%s'"), str
);
838 /* Hash the opcode, insn will have the string from opcode table.
839 also initialized the_insn struct. */
840 if ((insn
= (struct machine_opcode
*) hash_find (op_hash
, str
)) == NULL
)
842 /* Handle the ret and return macro here. */
843 if ((strcmp (str
, "ret") == 0) || (strcmp (str
, "return") == 0))
845 memset (&the_insn
, '\0', sizeof (the_insn
));
846 the_insn
.reloc
= NO_RELOC
;
849 (unsigned long)(JROP
| 0x03e00000); /* 0x03e00000 = r31 << 21 */
852 as_bad (_("Unknown opcode `%s'."), str
);
858 opcode
= insn
->opcode
;
859 memset (&the_insn
, '\0', sizeof (the_insn
));
860 the_insn
.reloc
= NO_RELOC
;
863 /* Set the sip reloc HI16 flag. */
864 if (!set_dlx_skip_hi16_flag (1))
865 as_bad (_("Can not set dlx_skip_hi16_flag"));
867 /* Fix the operand string if it is one of load store instructions. */
868 s
= fix_ld_st_operand (opcode
, s
);
870 /* Build the opcode, checking as we go to make sure that the
872 If an operand matches, we modify the_insn or opcode appropriately,
873 and do a "continue". If an operand fails to match, we "break". */
874 if (insn
->args
[0] != '\0' && insn
->args
[0] != 'N')
876 /* Prime the pump. */
879 as_bad (_("Missing arguments for opcode <%s>."), str
);
883 s
= parse_operand (s
, operand
);
885 else if (insn
->args
[0] == 'N')
887 /* Clean up the insn and done! */
888 the_insn
.opcode
= opcode
;
892 /* Parse through the args (this is from opcode table), *s point to
893 the current character of the instruction stream. */
894 for (args
= insn
->args
;; ++args
)
903 /* We are truly done. */
904 the_insn
.opcode
= opcode
;
905 /* Clean up the HI and LO mark. */
913 as_bad (_("Too many operands: %s"), s
);
916 /* ',' Args separator */
918 /* Must match a comma. */
921 /* Parse next operand. */
922 s
= parse_operand (s
, operand
);
927 /* It can be a 'a' register or 'i' operand. */
929 /* Macro move operand/reg. */
930 if (operand
->X_op
== O_register
)
932 /* Its a register. */
937 /* The immediate 16 bits literal, bit 0-15. */
939 /* offset, unsigned. */
941 /* offset, signed. */
942 if (operand
->X_op
== O_constant
)
945 operand
->X_add_number
>>= 16;
947 opcode
|= operand
->X_add_number
& 0xFFFF;
949 if (the_insn
.HI
&& the_insn
.LO
)
950 as_bad (_("Both the_insn.HI and the_insn.LO are set : %s"), s
);
959 the_insn
.reloc
= (the_insn
.HI
) ? RELOC_DLX_HI16
: RELOC_DLX_16
;
960 the_insn
.reloc_offset
= 2;
963 the_insn
.exp
= * operand
;
969 /* offset, signed. */
970 if (operand
->X_op
== O_constant
)
972 opcode
|= operand
->X_add_number
& 0xFFFF;
975 the_insn
.reloc
= RELOC_DLX_REL16
;
976 the_insn
.reloc_offset
= 0; /* BIG-ENDIAN Byte 3 of insn. */
979 the_insn
.exp
= *operand
;
982 /* The immediate 26 bits literal, bit 0-25. */
984 /* offset, signed. */
985 if (operand
->X_op
== O_constant
)
987 opcode
|= operand
->X_add_number
& 0x3FFFFFF;
990 the_insn
.reloc
= RELOC_DLX_REL26
;
991 the_insn
.reloc_offset
= 0; /* BIG-ENDIAN Byte 3 of insn. */
994 the_insn
.exp
= *operand
;
997 /* Type 'a' Register. */
999 /* A general register at bits 21-25, rs1. */
1000 know (operand
->X_op
!= O_register
);
1004 /* Type 'b' Register. */
1006 /* A general register at bits 16-20, rs2/rd. */
1007 know (operand
->X_op
!= O_register
);
1011 /* Type 'c' Register. */
1013 /* A general register at bits 11-15, rd. */
1014 know (operand
->X_op
!= O_register
);
1018 know (operand
->X_add_symbol
== 0);
1019 know (operand
->X_op_symbol
== 0);
1020 reg
= operand
->X_add_number
;
1021 if (reg
& 0xffffffe0)
1022 as_fatal (_("failed regnum sanity check."));
1024 /* Got the register, now figure out where it goes in the opcode. */
1025 opcode
|= reg
<< reg_shift
;
1035 as_fatal (_("failed general register sanity check."));
1042 /* Types or values of args don't match. */
1043 as_bad ("Invalid operands");
1048 /* This is identical to the md_atof in m68k.c. I think this is right,
1051 Turn a string in input_line_pointer into a floating point constant
1052 of type TYPE, and store the appropriate bytes in *LITP. The number
1053 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1054 returned, or NULL on OK. */
1055 /* Dlx will not use it anyway, so I just leave it here for now. */
1057 /* Equal to MAX_PRECISION in atof-ieee.c. */
1058 #define MAX_LITTLENUMS 6
1061 md_atof (type
, litP
, sizeP
)
1067 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1068 LITTLENUM_TYPE
*wordP
;
1099 return "Bad call to MD_ATOF()";
1102 t
= atof_ieee (input_line_pointer
, type
, words
);
1104 input_line_pointer
= t
;
1106 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1108 for (wordP
= words
; prec
--;)
1110 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1111 litP
+= sizeof (LITTLENUM_TYPE
);
1117 /* Write out big-endian. */
1119 md_number_to_chars (buf
, val
, n
)
1124 number_to_chars_bigendian (buf
, val
, n
);
1127 /* md_chars_to_number: convert from target byte order to host byte order. */
1130 md_chars_to_number (val
, n
)
1131 unsigned char *val
; /* Value in target byte order. */
1132 int n
; /* Number of bytes in the input. */
1136 for (retval
= 0; n
--;)
1145 /* Definition of TC_FORCE_RELOCATION.
1146 we need this for gas to force relocation for VTABLE. */
1149 md_dlx_force_relocation (fixp
)
1152 return (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1153 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
1154 || S_FORCE_RELOC (fixp
->fx_addsy
));
1158 md_dlx_fix_adjustable (fixP
)
1161 /* We need the symbol name for the VTABLE entries. */
1162 return (fixP
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
1163 && fixP
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
);
1167 md_apply_fix3 (fixP
, valP
, seg
)
1170 segT seg ATTRIBUTE_UNUSED
;
1173 char *place
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1175 know (fixP
->fx_size
== 4);
1176 know (fixP
->fx_r_type
< NO_RELOC
);
1178 switch (fixP
->fx_r_type
)
1180 case RELOC_DLX_REL16
:
1181 if (fixP
->fx_bit_fixP
!= (bit_fixS
*) NULL
)
1183 val
= (val
& 0x0000FFFF) | fixP
->fx_bit_fixP
->fx_bit_base
;
1184 free (fixP
->fx_bit_fixP
);
1185 fixP
->fx_bit_fixP
= (bit_fixS
*) NULL
;
1189 know ((fixP
->fx_bit_fixP
!= (bit_fixS
*) NULL
));
1193 case RELOC_DLX_HI16
:
1194 if (fixP
->fx_bit_fixP
!= (bit_fixS
*) NULL
)
1196 val
= (val
>> 16) | fixP
->fx_bit_fixP
->fx_bit_base
;
1197 free (fixP
->fx_bit_fixP
);
1198 fixP
->fx_bit_fixP
= (bit_fixS
*)NULL
;
1202 know ((fixP
->fx_bit_fixP
!= (bit_fixS
*) NULL
));
1206 case RELOC_DLX_REL26
:
1207 if (fixP
->fx_bit_fixP
!= (bit_fixS
*) NULL
)
1209 val
= (val
& 0x03FFFFFF) | fixP
->fx_bit_fixP
->fx_bit_base
;
1210 free (fixP
->fx_bit_fixP
);
1211 fixP
->fx_bit_fixP
= (bit_fixS
*) NULL
;
1215 know ((fixP
->fx_bit_fixP
!= (bit_fixS
*) NULL
));
1219 case BFD_RELOC_VTABLE_INHERIT
:
1220 /* This borrowed from tc-ppc.c on a whim. */
1223 && !S_IS_DEFINED (fixP
->fx_addsy
)
1224 && !S_IS_WEAK (fixP
->fx_addsy
))
1225 S_SET_WEAK (fixP
->fx_addsy
);
1228 case BFD_RELOC_VTABLE_ENTRY
:
1236 number_to_chars_bigendian (place
, val
, fixP
->fx_size
);
1237 if (fixP
->fx_addsy
== NULL
)
1242 const char *md_shortopts
= "";
1244 struct option md_longopts
[] =
1246 {NULL
, no_argument
, NULL
, 0}
1249 size_t md_longopts_size
= sizeof (md_longopts
);
1252 md_parse_option (c
, arg
)
1253 int c ATTRIBUTE_UNUSED
;
1254 char *arg ATTRIBUTE_UNUSED
;
1260 md_show_usage (stream
)
1261 FILE *stream ATTRIBUTE_UNUSED
;
1266 /* This is called when a line is unrecognized. */
1269 dlx_unrecognized_line (c
)
1275 if (c
!= '$' || ! ISDIGIT ((unsigned char) input_line_pointer
[0]))
1278 s
= input_line_pointer
;
1281 while (ISDIGIT ((unsigned char) *s
))
1283 lab
= lab
* 10 + *s
- '0';
1289 /* Not a label definition. */
1293 if (dollar_label_defined (lab
))
1295 as_bad (_("label \"$%d\" redefined"), lab
);
1299 define_dollar_label (lab
);
1300 colon (dollar_label_name (lab
, 0));
1301 input_line_pointer
= s
+ 1;
1306 /* Default the values of symbols known that should be "predefined". We
1307 don't bother to predefine them unless you actually use one, since there
1308 are a lot of them. */
1311 md_undefined_symbol (name
)
1312 char *name ATTRIBUTE_UNUSED
;
1318 /* Parse an operand that is machine-specific, the function was called
1319 in expr.c by operand() function, when everything failed bdfore it
1323 md_operand (expressionP
)
1324 expressionS
* expressionP
;
1326 /* Check for the #number representation */
1327 if (input_line_pointer
[0] == '#' &&
1328 ISDIGIT ((unsigned char) input_line_pointer
[1]))
1330 /* We have a numeric number expression. No biggy. */
1331 input_line_pointer
+= 1; /* Skip # */
1333 (void) expression (expressionP
);
1335 if (expressionP
->X_op
!= O_constant
)
1336 as_bad (_("Invalid expression after # number\n"));
1341 else if (input_line_pointer
[0] == '$'
1342 && ISDIGIT ((unsigned char) input_line_pointer
[1]))
1348 /* This is a local label. */
1349 ++input_line_pointer
;
1350 lab
= (long) get_absolute_expression ();
1351 if (dollar_label_defined (lab
))
1353 name
= dollar_label_name (lab
, 0);
1354 sym
= symbol_find (name
);
1358 name
= dollar_label_name (lab
, 1);
1359 sym
= symbol_find_or_make (name
);
1362 expressionP
->X_op
= O_symbol
;
1363 expressionP
->X_add_symbol
= sym
;
1364 expressionP
->X_add_number
= 0;
1369 /* Round up a section size to the appropriate boundary. */
1372 md_section_align (segment
, size
)
1373 segT segment ATTRIBUTE_UNUSED
;
1376 /* Byte alignment is fine. */
1380 /* Exactly what point is a PC-relative offset relative TO?
1381 On the 29000, they're relative to the address of the instruction,
1382 which we have set up as the address of the fixup too. */
1385 md_pcrel_from (fixP
)
1388 return 4 + fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1395 tc_bfd_fix2rtype (fixP
)
1403 if (fixP
->fx_pcrel
== 0 && fixP
->fx_size
== 4)
1404 return BFD_RELOC_32
;
1406 if (fixP
->fx_pcrel
!= 0 && fixP
->fx_size
== 4)
1407 return BFD_RELOC_26_PCREL
;
1415 /* Translate internal representation of relocation info to BFD target
1417 FIXME: To what extent can we get all relevant targets to use this?
1418 The above FIXME is from a29k, but I think it is also needed here. */
1421 tc_gen_reloc (section
, fixP
)
1422 asection
*section ATTRIBUTE_UNUSED
;
1427 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1428 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
1430 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1432 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1433 "internal error: can't export reloc type %d (`%s')",
1435 bfd_get_reloc_code_name (fixP
->fx_r_type
));
1439 assert (!fixP
->fx_pcrel
== !reloc
->howto
->pc_relative
);
1441 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1442 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixP
->fx_addsy
);
1443 reloc
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1445 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1446 reloc
->address
= fixP
->fx_offset
;
1452 extern void pop_insert
PARAMS ((const pseudo_typeS
*));
1457 pop_insert (dlx_pseudo_table
);