1 /* tc-i860.c -- Assemble for the I860
2 Copyright (C) 1989, 1992 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
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "opcode/i860.h"
26 void md_number_to_chars();
29 void md_convert_frag();
30 void md_create_short_jump();
31 void md_create_long_jump();
32 int md_estimate_size_before_relax();
33 void md_number_to_imm();
34 void md_number_to_disp();
35 void md_number_to_field();
36 void md_ri_to_chars();
37 static void i860_ip();
39 const relax_typeS md_relax_table[] = { 0 };
41 /* handle of the OPCODE hash table */
42 static struct hash_control *op_hash = NULL;
44 static void s_dual(), s_enddual();
49 { "dual", s_dual, 4 },
50 { "enddual", s_enddual, 4 },
51 { "atmp", s_atmp, 4 },
55 int md_short_jump_size = 4;
56 int md_long_jump_size = 4;
58 /* This array holds the chars that always start a comment. If the
59 pre-processor is disabled, these aren't very useful */
60 char comment_chars[] = "!/"; /* JF removed '|' from comment_chars */
62 /* This array holds the chars that only start a comment at the beginning of
63 a line. If the line seems to have the form '# 123 filename'
64 .line and .file directives will appear in the pre-processed output */
65 /* Note that input_file.c hand checks for '#' at the beginning of the
66 first line of the input file. This is because the compiler outputs
67 #NO_APP at the beginning of its output. */
68 /* Also note that comments like this one will always work. */
69 char line_comment_chars[] = "#/";
71 /* Chars that can be used to separate mant from exp in floating point nums */
72 char EXP_CHARS[] = "eE";
74 /* Chars that mean this number is a floating point constant */
77 char FLT_CHARS[] = "rRsSfFdDxXpP";
79 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
80 changed in read.c. Ideally it shouldn't have to know about it at all,
81 but nothing is ideal around here.
83 int size_reloc_info = sizeof(struct relocation_info);
85 static unsigned char octal[256];
86 #define isoctal(c) octal[c]
87 static unsigned char toHex[256];
95 enum expand_type expand;
96 enum highlow_type highlow;
97 enum reloc_type reloc;
103 static void print_insn(struct i860_it *insn);
106 static int getExpression(char *str);
108 #else /* not __STDC__ */
111 static void print_insn();
114 static int getExpression();
116 #endif /* not __STDC__ */
118 static char *expr_end;
119 static char last_expand; /* error if expansion after branch */
123 DUAL_OFF = 0, DUAL_ON, DUAL_DDOT, DUAL_ONDDOT,
125 static enum dual dual_mode = DUAL_OFF; /* dual-instruction mode */
128 s_dual() /* floating point instructions have dual set */
134 s_enddual() /* floating point instructions have dual set */
136 dual_mode = DUAL_OFF;
139 static int atmp = 31; /* temporary register for pseudo's */
145 if (strncmp(input_line_pointer, "sp", 2) == 0) {
146 input_line_pointer += 2;
149 else if (strncmp(input_line_pointer, "fp", 2) == 0) {
150 input_line_pointer += 2;
153 else if (strncmp(input_line_pointer, "r", 1) == 0) {
154 input_line_pointer += 1;
155 temp = get_absolute_expression();
156 if (temp >= 0 && temp <= 31)
159 as_bad("Unknown temporary pseudo register");
162 as_bad("Unknown temporary pseudo register");
164 demand_empty_rest_of_line();
168 /* This function is called once, at assembler startup time. It should
169 set up all the tables, etc. that the MD part of the assembler will need. */
173 register char *retval = NULL;
175 register unsigned int i = 0;
177 op_hash = hash_new();
179 as_fatal("Virtual memory exhausted");
181 while (i < NUMOPCODES)
183 const char *name = i860_opcodes[i].name;
184 retval = hash_insert(op_hash, name, &i860_opcodes[i]);
185 if (retval != NULL && *retval != '\0')
187 fprintf (stderr, "internal error: can't hash `%s': %s\n",
188 i860_opcodes[i].name, retval);
193 if (i860_opcodes[i].match & i860_opcodes[i].lose)
195 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
196 i860_opcodes[i].name, i860_opcodes[i].args);
200 } while (i < NUMOPCODES
201 && !strcmp(i860_opcodes[i].name, name));
205 as_fatal("Broken assembler. No assembly attempted.");
207 for (i = '0'; i < '8'; ++i)
209 for (i = '0'; i <= '9'; ++i)
211 for (i = 'a'; i <= 'f'; ++i)
212 toHex[i] = i + 10 - 'a';
213 for (i = 'A'; i <= 'F'; ++i)
214 toHex[i] = i + 10 - 'A';
228 /* int rsd; FIXME: remove this line. */
231 struct i860_it pseudo[3];
236 /* check for expandable flag to produce pseudo-instructions */
237 if (the_insn.expand != 0 && the_insn.highlow == NO_SPEC) {
238 for (i = 0; i < 3; i++)
239 pseudo[i] = the_insn;
241 switch (the_insn.expand) {
248 if (the_insn.exp.X_add_symbol == NULL &&
249 the_insn.exp.X_subtract_symbol == NULL &&
250 (the_insn.exp.X_add_number < (1 << 15) &&
251 the_insn.exp.X_add_number >= -(1 << 15)))
253 /* or l%const,r0,ireg_dest */
254 pseudo[0].opcode = (the_insn.opcode & 0x001f0000) | 0xe4000000;
255 pseudo[0].highlow = PAIR;
256 /* orh h%const,ireg_dest,ireg_dest */
257 pseudo[1].opcode = (the_insn.opcode & 0x03ffffff) | 0xec000000 |
258 ((the_insn.opcode & 0x001f0000) << 5);
259 pseudo[1].highlow = HIGH;
264 if (the_insn.exp.X_add_symbol == NULL &&
265 the_insn.exp.X_subtract_symbol == NULL)
267 /* orh ha%addr_expr,r0,r31 */
268 pseudo[0].opcode = 0xec000000 | (atmp<<16);
269 pseudo[0].highlow = HIGHADJ;
270 pseudo[0].reloc = LOW0; /* must overwrite */
271 /* l%addr_expr(r31),ireg_dest */
272 pseudo[1].opcode = (the_insn.opcode & ~0x003e0000) | (atmp << 21);
273 pseudo[1].highlow = PAIR;
277 case E_U32: /* 2nd version emulates Intel as, not doc. */
278 if (the_insn.exp.X_add_symbol == NULL &&
279 the_insn.exp.X_subtract_symbol == NULL &&
280 (the_insn.exp.X_add_number < (1 << 16) &&
281 the_insn.exp.X_add_number >= 0))
283 /* $(opcode)h h%const,ireg_src2,ireg_dest
284 pseudo[0].opcode = (the_insn.opcode & 0xf3ffffff) | 0x0c000000; */
285 /* $(opcode)h h%const,ireg_src2,r31 */
286 pseudo[0].opcode = (the_insn.opcode & 0xf3e0ffff) | 0x0c000000 |
288 pseudo[0].highlow = HIGH;
289 /* $(opcode) l%const,ireg_dest,ireg_dest
290 pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000 |
291 ((the_insn.opcode & 0x001f0000) << 5); */
292 /* $(opcode) l%const,r31,ireg_dest */
293 pseudo[1].opcode = (the_insn.opcode & 0xf01f0000) | 0x04000000 |
295 pseudo[1].highlow = PAIR;
299 case E_AND: /* 2nd version emulates Intel as, not doc. */
300 if (the_insn.exp.X_add_symbol == NULL &&
301 the_insn.exp.X_subtract_symbol == NULL &&
302 (the_insn.exp.X_add_number < (1 << 16) &&
303 the_insn.exp.X_add_number >= 0))
305 /* andnot h%const,ireg_src2,ireg_dest
306 pseudo[0].opcode = (the_insn.opcode & 0x03ffffff) | 0xd4000000; */
307 /* andnot h%const,ireg_src2,r31 */
308 pseudo[0].opcode = (the_insn.opcode & 0x03e0ffff) | 0xd4000000 |
310 pseudo[0].highlow = HIGH;
311 pseudo[0].exp.X_add_number = -1 - the_insn.exp.X_add_number;
312 /* andnot l%const,ireg_dest,ireg_dest
313 pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000 |
314 ((the_insn.opcode & 0x001f0000) << 5); */
315 /* andnot l%const,r31,ireg_dest */
316 pseudo[1].opcode = (the_insn.opcode & 0x001f0000) | 0xd4000000 |
318 pseudo[1].highlow = PAIR;
319 pseudo[1].exp.X_add_number = -1 - the_insn.exp.X_add_number;
324 if (the_insn.exp.X_add_symbol == NULL &&
325 the_insn.exp.X_subtract_symbol == NULL &&
326 (the_insn.exp.X_add_number < (1 << 15) &&
327 the_insn.exp.X_add_number >= -(1 << 15)))
329 /* orh h%const,r0,r31 */
330 pseudo[0].opcode = 0xec000000 | (atmp << 16);
331 pseudo[0].highlow = HIGH;
332 /* or l%const,r31,r31 */
333 pseudo[1].opcode = 0xe4000000 | (atmp << 21) | (atmp << 16);
334 pseudo[1].highlow = PAIR;
335 /* r31,ireg_src2,ireg_dest */
336 pseudo[2].opcode = (the_insn.opcode & ~0x0400ffff) | (atmp << 11);
337 pseudo[2].reloc = NO_RELOC;
342 as_fatal("failed sanity check.");
345 the_insn = pseudo[0];
346 /* check for expanded opcode after branch or in dual */
347 if (no_opcodes > 1 && last_expand == 1)
348 as_warn("Expanded opcode after delayed branch: `%s'", str);
349 if (no_opcodes > 1 && dual_mode != DUAL_OFF)
350 as_warn("Expanded opcode in dual mode: `%s'", str);
354 do { /* always produce at least one opcode */
356 /* put out the opcode */
357 md_number_to_chars(toP, the_insn.opcode, 4);
359 /* check for expanded opcode after branch or in dual */
360 last_expand = the_insn.pcrel;
362 /* put out the symbol-dependent stuff */
363 if (the_insn.reloc != NO_RELOC) {
364 fix_new(frag_now, /* which frag */
365 (toP - frag_now->fr_literal), /* where */
367 the_insn.exp.X_add_symbol,
368 the_insn.exp.X_subtract_symbol,
369 the_insn.exp.X_add_number,
371 /* merge bit fields into one argument */
372 (int)(((the_insn.highlow & 0x3) << 4) | (the_insn.reloc & 0xf)));
374 the_insn = pseudo[++i];
375 } while (--no_opcodes > 0);
386 /* unsigned long i; FIXME: remove this line. */
387 struct i860_opcode *insn;
389 unsigned long opcode;
395 for (s = str; islower(*s) || *s == '.' || *s == '3'; ++s)
412 as_bad("Unknown opcode: `%s'", str);
416 if (strncmp(str, "d.", 2) == 0) { /* check for d. opcode prefix */
417 if (dual_mode == DUAL_ON)
418 dual_mode = DUAL_ONDDOT;
420 dual_mode = DUAL_DDOT;
424 if ((insn = (struct i860_opcode *) hash_find(op_hash, str)) == NULL) {
425 if (dual_mode == DUAL_DDOT || dual_mode == DUAL_ONDDOT)
427 as_bad("Unknown opcode: `%s'", str);
435 opcode = insn->match;
436 memset(&the_insn, '\0', sizeof(the_insn));
437 the_insn.reloc = NO_RELOC;
440 * Build the opcode, checking as we go to make
441 * sure that the operands match
443 for (args = insn->args; ; ++args) {
446 case '\0': /* end of args */
453 case '(': /* these must match exactly */
461 case '#': /* must be at least one digit */
463 while (isdigit(*s)) {
470 case '1': /* next operand must be a register */
475 case 'f': /* frame pointer */
483 case 's': /* stack pointer */
491 case 'r': /* any register */
493 if (!isdigit(c = *s++)) {
497 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32) {
506 default: /* not this opcode */
510 * Got the register, now figure out where
511 * it goes in the opcode.
516 opcode |= mask << 11;
520 opcode |= mask << 21;
524 opcode |= mask << 16;
530 case 'e': /* next operand is a floating point register */
533 if (*s++ == 'f' && isdigit(*s)) {
536 mask = 10 * (mask - '0') + (*s++ - '0');
546 opcode |= mask << 11;
550 opcode |= mask << 21;
554 opcode |= mask << 16;
555 if (dual_mode != DUAL_OFF)
556 opcode |= (1 << 9); /* dual mode instruction */
557 if (dual_mode == DUAL_DDOT)
558 dual_mode = DUAL_OFF;
559 if (dual_mode == DUAL_ONDDOT)
561 if ((opcode & (1 << 10)) && (mask == ((opcode >> 11) & 0x1f)))
562 as_warn("Fsr1 equals fdest with Pipelining");
568 case 'c': /* next operand must be a control register */
569 if (strncmp(s, "fir", 3) == 0) {
574 if (strncmp(s, "psr", 3) == 0) {
579 if (strncmp(s, "dirbase", 7) == 0) {
584 if (strncmp(s, "db", 2) == 0) {
589 if (strncmp(s, "fsr", 3) == 0) {
594 if (strncmp(s, "epsr", 4) == 0) {
601 case '5': /* 5 bit immediate in src1 */
602 memset(&the_insn, '\0', sizeof(the_insn));
603 if ( !getExpression(s)) {
605 if (the_insn.exp.X_add_number & ~0x1f)
606 as_bad("5-bit immediate too large");
607 opcode |= (the_insn.exp.X_add_number & 0x1f) << 11;
608 memset(&the_insn, '\0', sizeof(the_insn));
609 the_insn.reloc = NO_RELOC;
614 case 'l': /* 26 bit immediate, relative branch */
615 the_insn.reloc = BRADDR;
619 case 's': /* 16 bit immediate, split relative branch */
620 /* upper 5 bits of offset in dest field */
622 the_insn.reloc = SPLIT0;
625 case 'S': /* 16 bit immediate, split (st), aligned */
626 if (opcode & (1 << 28))
628 the_insn.reloc = SPLIT2;
630 the_insn.reloc = SPLIT1;
632 the_insn.reloc = SPLIT0;
635 case 'I': /* 16 bit immediate, aligned */
636 if (opcode & (1 << 28))
638 the_insn.reloc = LOW2;
640 the_insn.reloc = LOW1;
642 the_insn.reloc = LOW0;
645 case 'i': /* 16 bit immediate */
646 the_insn.reloc = LOW0;
653 if (strncmp(s, "ha%", 3) == 0) {
654 the_insn.highlow = HIGHADJ;
656 } else if (strncmp(s, "h%", 2) == 0) {
657 the_insn.highlow = HIGH;
659 } else if (strncmp(s, "l%", 2) == 0) {
660 the_insn.highlow = PAIR;
663 the_insn.expand = insn->expand;
665 /* Note that if the getExpression() fails, we will still have
666 created U entries in the symbol table for the 'symbols'
667 in the input string. Try not to create U symbols for
670 if ( !getExpression(s)) {
677 as_fatal("failed sanity check.");
684 /* Args don't match. */
685 if (&insn[1] - i860_opcodes < NUMOPCODES
686 && !strcmp(insn->name, insn[1].name))
694 as_bad("Illegal operands");
701 the_insn.opcode = opcode;
712 save_in = input_line_pointer;
713 input_line_pointer = str;
714 switch (seg = expression(&the_insn.exp)) {
727 the_insn.error = "bad segment";
728 expr_end = input_line_pointer;
729 input_line_pointer=save_in;
732 expr_end = input_line_pointer;
733 input_line_pointer = save_in;
739 This is identical to the md_atof in m68k.c. I think this is right,
742 Turn a string in input_line_pointer into a floating point constant of type
743 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
744 emitted is stored in *sizeP. An error message is returned, or NULL on OK.
747 /* Equal to MAX_PRECISION in atof-ieee.c */
748 #define MAX_LITTLENUMS 6
751 md_atof(type,litP,sizeP)
757 LITTLENUM_TYPE words[MAX_LITTLENUMS];
758 LITTLENUM_TYPE *wordP;
790 return "Bad call to MD_ATOF()";
792 t=atof_ieee(input_line_pointer,type,words);
794 input_line_pointer=t;
795 *sizeP=prec * sizeof(LITTLENUM_TYPE);
796 for (wordP=words;prec--;) {
797 md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
798 litP+=sizeof(LITTLENUM_TYPE);
800 return ""; /* Someone should teach Dean about null pointers */
804 * Write out big-endian.
807 md_number_to_chars(buf, val, n)
824 as_fatal("failed sanity check.");
829 void md_number_to_imm(buf, val, n, fixP)
835 enum reloc_type reloc = fixP->fx_r_type & 0xf;
836 enum highlow_type highlow = (fixP->fx_r_type >> 4) & 0x3;
839 assert(n == 4); /* always on i860 */
843 case HIGHADJ: /* adjusts the high-order 16-bits */
849 case HIGH: /* selects the high-order 16-bits */
853 case PAIR: /* selects the low-order 16-bits */
863 case BRADDR: /* br, call, bc, bc.t, bnc, bnc.t w/26-bit immediate */
864 if (fixP->fx_pcrel != 1)
865 as_bad("26-bit branch w/o pc relative set: 0x%08x", val);
866 val >>= 2; /* align pcrel offset, see manual */
868 if (val >= (1 << 25) || val < -(1 << 25)) /* check for overflow */
869 as_bad("26-bit branch offset overflow: 0x%08x", val);
870 buf[0] = (buf[0] & 0xfc) | ((val >> 24) & 0x3);
876 case SPLIT2: /* 16 bit immediate, 4-byte aligned */
878 as_bad("16-bit immediate 4-byte alignment error: 0x%08x", val);
879 val &= ~0x3; /* 4-byte align value */
881 case SPLIT1: /* 16 bit immediate, 2-byte aligned */
883 as_bad("16-bit immediate 2-byte alignment error: 0x%08x", val);
884 val &= ~0x1; /* 2-byte align value */
886 case SPLIT0: /* st,bla,bte,btne w/16-bit immediate */
887 if (fixP->fx_pcrel == 1)
888 val >>= 2; /* align pcrel offset, see manual */
889 /* check for bounds */
890 if (highlow != PAIR && (val >= (1 << 16) || val < -(1 << 15)))
891 as_bad("16-bit branch offset overflow: 0x%08x", val);
892 buf[1] = (buf[1] & ~0x1f) | ((val >> 11) & 0x1f);
893 buf[2] = (buf[2] & ~0x7) | ((val >> 8) & 0x7);
894 buf[3] |= val; /* perserve bottom opcode bits */
897 case LOW4: /* fld,pfld,pst,flush 16-byte aligned */
899 as_bad("16-bit immediate 16-byte alignment error: 0x%08x", val);
900 val &= ~0xf; /* 16-byte align value */
902 case LOW3: /* fld,pfld,pst,flush 8-byte aligned */
904 as_bad("16-bit immediate 8-byte alignment error: 0x%08x", val);
905 val &= ~0x7; /* 8-byte align value */
907 case LOW2: /* 16 bit immediate, 4-byte aligned */
909 as_bad("16-bit immediate 4-byte alignment error: 0x%08x", val);
910 val &= ~0x3; /* 4-byte align value */
912 case LOW1: /* 16 bit immediate, 2-byte aligned */
914 as_bad("16-bit immediate 2-byte alignment error: 0x%08x", val);
915 val &= ~0x1; /* 2-byte align value */
917 case LOW0: /* 16 bit immediate, byte aligned */
918 /* check for bounds */
919 if (highlow != PAIR && (val >= (1 << 16) || val < -(1 << 15)))
920 as_bad("16-bit immediate overflow: 0x%08x", val);
922 buf[3] |= val; /* perserve bottom opcode bits */
926 md_number_to_chars(buf, val, 4);
931 as_bad("bad relocation type: 0x%02x", reloc);
937 /* should never be called for i860 */
939 md_create_short_jump(ptr, from_addr, to_addr, frag, to_symbol)
941 long from_addr, to_addr;
945 as_fatal("i860_create_short_jmp\n");
948 /* should never be called for i860 */
950 md_number_to_disp(buf, val, n)
955 as_fatal("md_number_to_disp\n");
958 /* should never be called for i860 */
960 md_number_to_field(buf,val,fix)
965 as_fatal("i860_number_to_field\n");
968 /* the bit-field entries in the relocation_info struct plays hell
969 with the byte-order problems of cross-assembly. So as a hack,
970 I added this mach. dependent ri twiddler. Ugly, but it gets
972 /* on i860: first 4 bytes are normal unsigned long address, next three
973 bytes are index, most sig. byte first. Byte 7 is broken up with
974 bit 7 as pcrel, bit 6 as extern, and the lower six bits as
975 relocation type (highlow 5-4). Next 4 bytes are long addend. */
976 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
978 md_ri_to_chars(ri_p, ri)
979 struct relocation_info *ri_p, ri;
982 unsigned char the_bytes[sizeof(*ri_p)];
985 md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
986 /* now the fun stuff */
987 the_bytes[4] = (ri.r_index >> 16) & 0x0ff;
988 the_bytes[5] = (ri.r_index >> 8) & 0x0ff;
989 the_bytes[6] = ri.r_index & 0x0ff;
990 the_bytes[7] = ((ri.r_extern << 7) & 0x80) | (0 & 0x60) | (ri.r_type & 0x1F);
992 md_number_to_chars(&the_bytes[8], ri.r_addend, sizeof(ri.r_addend));
993 /* now put it back where you found it, Junior... */
994 memcpy((char *) ri_p, the_bytes, sizeof(*ri_p));
998 /* should never be called for i860 */
1000 md_convert_frag(headers, fragP)
1001 object_headers *headers;
1002 register fragS *fragP;
1004 as_fatal("i860_convert_frag\n");
1007 /* should never be called for i860 */
1009 md_create_long_jump(ptr, from_addr, to_addr, frag, to_symbol)
1016 as_fatal("i860_create_long_jump\n");
1019 /* should never be called for i860 */
1021 md_estimate_size_before_relax(fragP, segtype)
1022 register fragS *fragP;
1025 as_fatal("i860_estimate_size_before_relax\n");
1030 /* for debugging only, must match enum reloc_type */
1031 static char *Reloc[] = {
1044 static char *Highlow[] = {
1053 struct i860_it *insn;
1056 fprintf(stderr, "ERROR: %s\n", insn->error);
1058 fprintf(stderr, "opcode=0x%08x\t", insn->opcode);
1059 fprintf(stderr, "expand=0x%08x\t", insn->expand);
1060 fprintf(stderr, "reloc = %s\t", Reloc[insn->reloc]);
1061 fprintf(stderr, "highlow = %s\n", Highlow[insn->highlow]);
1062 fprintf(stderr, "exp = {\n");
1063 fprintf(stderr, "\t\tX_add_symbol = %s\n",
1064 insn->exp.X_add_symbol ?
1065 (S_GET_NAME(insn->exp.X_add_symbol) ?
1066 S_GET_NAME(insn->exp.X_add_symbol) : "???") : "0");
1067 fprintf(stderr, "\t\tX_sub_symbol = %s\n",
1068 insn->exp.X_subtract_symbol ?
1069 (S_GET_NAME(insn->exp.X_subtract_symbol) ?
1070 S_GET_NAME(insn->exp.X_subtract_symbol) : "???") : "0");
1071 fprintf(stderr, "\t\tX_add_number = %d\n",
1072 insn->exp.X_add_number);
1073 fprintf(stderr, "}\n");
1076 #endif /* comment */
1079 md_parse_option(argP,cntP,vecP)
1089 * I860 relocations are completely different, so it needs
1090 * this machine dependent routine to emit them.
1093 emit_machine_reloc(fixP, segment_address_in_file)
1094 register fixS *fixP;
1095 relax_addressT segment_address_in_file;
1097 struct reloc_info_i860 ri;
1098 register symbolS *symbolP;
1099 extern char *next_object_file_charP;
1102 memset((char *) &ri, '\0', sizeof(ri));
1103 for (; fixP; fixP = fixP->fx_next) {
1105 if (fixP->fx_r_type & ~0x3f) {
1106 as_fatal("fixP->fx_r_type = %d\n", fixP->fx_r_type);
1108 ri.r_pcrel = fixP->fx_pcrel;
1109 ri.r_type = fixP->fx_r_type;
1111 if ((symbolP = fixP->fx_addsy) != NULL) {
1112 ri.r_address = fixP->fx_frag->fr_address +
1113 fixP->fx_where - segment_address_in_file;
1114 if (!S_IS_DEFINED(symbolP)) {
1116 ri.r_symbolnum = symbolP->sy_number;
1119 ri.r_symbolnum = S_GET_TYPE(symbolP);
1121 if (symbolP && symbolP->sy_frag) {
1122 ri.r_addend = symbolP->sy_frag->fr_address;
1124 ri.r_type = fixP->fx_r_type;
1125 if (fixP->fx_pcrel) {
1126 /* preserve actual offset vs. pc + 4 */
1127 ri.r_addend -= (ri.r_address + 4);
1129 ri.r_addend = fixP->fx_addnumber;
1132 md_ri_to_chars((char *) &ri, ri);
1133 append(&next_object_file_charP, (char *)& ri, sizeof(ri));
1138 #endif /* comment */
1142 /* on i860: first 4 bytes are normal unsigned long address, next three
1143 bytes are index, most sig. byte first. Byte 7 is broken up with
1144 bit 7 as pcrel, bit 6 as extern, and the lower six bits as
1145 relocation type (highlow 5-4). Next 4 bytes are long addend.
1149 struct reloc_info_i860 {
1150 unsigned long r_address;
1151 unsigned int r_symbolnum : 24;
1152 unsigned int r_pcrel : 1;
1153 unsigned int r_extern : 1;
1154 unsigned int r_type : 6;
1160 const int md_reloc_size = 12;
1162 void tc_aout_fix_to_chars(where, fixP, segment_address_in_file)
1165 relax_addressT segment_address_in_file;
1172 know(fixP->fx_addsy);
1173 know(!(fixP->fx_r_type & ~0x3f));
1175 if (!S_IS_DEFINED(fixP->fx_addsy)) {
1177 r_index = fixP->fx_addsy->sy_number;
1180 r_index = S_GET_TYPE(fixP->fx_addsy);
1183 md_number_to_chars(where,
1184 r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
1187 where[4] = (r_index >> 16) & 0x0ff;
1188 where[5] = (r_index >> 8) & 0x0ff;
1189 where[6] = r_index & 0x0ff;
1190 where[7] = (((fixP->fx_pcrel << 7) & 0x80)
1191 | ((r_extern << 6) & 0x40)
1192 | (fixP->fx_r_type & 0x3F));
1194 if (fixP->fx_addsy->sy_frag) {
1195 r_addend = fixP->fx_addsy->sy_frag->fr_address;
1198 if (fixP->fx_pcrel) {
1199 /* preserve actual offset vs. pc + 4 */
1200 r_addend -= (r_address + 4);
1202 r_addend = fixP->fx_addnumber;
1205 md_number_to_chars(&where[8], r_addend, 4);
1208 } /* tc_aout_fix_to_chars() */
1210 #endif /* OBJ_AOUT */
1212 /* Parse an operand that is machine-specific.
1213 We just return without modifying the expression if we have nothing
1218 md_operand (expressionP)
1219 expressionS *expressionP;
1223 /* We have no need to default values of symbols. */
1227 md_undefined_symbol (name)
1233 /* Round up a section size to the appropriate boundary. */
1235 md_section_align (segment, size)
1239 return size; /* Byte alignment is fine */
1242 /* Exactly what point is a PC-relative offset relative TO?
1243 On the i860, they're relative to the address of the offset, plus
1244 its size. (??? Is this right? FIXME-SOON!) */
1246 md_pcrel_from (fixP)
1249 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1253 md_apply_fix(fixP, val)
1257 char *place = fixP->fx_where + fixP->fx_frag->fr_literal;
1259 /* fixme-soon: looks to me like i860 never has bit fixes. Let's see. xoxorich. */
1260 know(fixP->fx_bit_fixP == NULL);
1261 if (!fixP->fx_bit_fixP) {
1263 /* fixme-soon: also looks like fx_im_disp is always 0. Let's see. xoxorich. */
1264 know(fixP->fx_im_disp == 0);
1265 switch (fixP->fx_im_disp) {
1267 fixP->fx_addnumber = val;
1268 md_number_to_imm(place, val, fixP->fx_size, fixP);
1271 md_number_to_disp(place,
1272 fixP->fx_pcrel ? val + fixP->fx_pcrel_adjust : val,
1275 case 2: /* fix requested for .long .word etc */
1276 md_number_to_chars(place, val, fixP->fx_size);
1279 as_fatal("Internal error in md_apply_fix() in file \"%s\"", __FILE__);
1280 } /* OVE: maybe one ought to put _imm _disp _chars in one md-func */
1282 md_number_to_field(place, val, fixP->fx_bit_fixP);
1286 } /* md_apply_fix() */
1295 /* end of tc-i860.c */