1 /* ns32k.c -- Assemble on the National Semiconductor 32k series
2 Copyright (C) 1987, 92, 93, 94, 95, 96, 1997, 1998 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 /*#define SHOW_NUM 1*//* uncomment for debugging */
27 #include "opcode/ns32k.h"
32 #define IIF_ENTRIES 13 /* number of entries in iif */
33 #define PRIVATE_SIZE 256 /* size of my garbage memory */
35 #define DEFAULT -1 /* addr_mode returns this value when
36 plain constant or label is
39 #define IIF(ptr,a1,c1,e1,g1,i1,k1,m1,o1,q1,s1,u1) \
40 iif.iifP[ptr].type= a1; \
41 iif.iifP[ptr].size= c1; \
42 iif.iifP[ptr].object= e1; \
43 iif.iifP[ptr].object_adjust= g1; \
44 iif.iifP[ptr].pcrel= i1; \
45 iif.iifP[ptr].pcrel_adjust= k1; \
46 iif.iifP[ptr].im_disp= m1; \
47 iif.iifP[ptr].relax_substate= o1; \
48 iif.iifP[ptr].bit_fixP= q1; \
49 iif.iifP[ptr].addr_mode= s1; \
50 iif.iifP[ptr].bsr= u1;
52 #ifdef SEQUENT_COMPATABILITY
53 #define LINE_COMMENT_CHARS "|"
54 #define ABSOLUTE_PREFIX '@'
55 #define IMMEDIATE_PREFIX '#'
58 #ifndef LINE_COMMENT_CHARS
59 #define LINE_COMMENT_CHARS "#"
62 const char comment_chars[] = "#";
63 const char line_comment_chars[] = LINE_COMMENT_CHARS;
64 const char line_separator_chars[] = "";
65 #if !defined(ABSOLUTE_PREFIX) && !defined(IMMEDIATE_PREFIX)
66 #define ABSOLUTE_PREFIX '@' /* One or the other MUST be defined */
71 char mode; /* addressing mode of operand (0-31) */
72 char scaled_mode; /* mode combined with scaled mode */
73 char scaled_reg; /* register used in scaled+1 (1-8) */
74 char float_flag; /* set if R0..R7 was F0..F7 ie a
75 floating-point-register */
76 char am_size; /* estimated max size of general addr-mode
78 char im_disp; /* if im_disp==1 we have a displacement */
79 char pcrel; /* 1 if pcrel, this is really redundant info */
80 char disp_suffix[2]; /* length of displacement(s), 0=undefined */
81 char *disp[2]; /* pointer(s) at displacement(s)
82 or immediates(s) (ascii) */
83 char index_byte; /* index byte */
85 typedef struct addr_mode addr_modeS;
88 char *freeptr, *freeptr_static; /* points at some number of free bytes */
89 struct hash_control *inst_hash_handle;
91 struct ns32k_opcode *desc; /* pointer at description of instruction */
92 addr_modeS addr_modeP;
93 const char EXP_CHARS[] = "eE";
94 const char FLT_CHARS[] = "fd"; /* we don't want to support lowercase, do we */
96 /* UPPERCASE denotes live names when an instruction is built, IIF is
97 * used as an intermediate form to store the actual parts of the
98 * instruction. A ns32k machine instruction can be divided into a
99 * couple of sub PARTs. When an instruction is assembled the
100 * appropriate PART get an assignment. When an IIF has been completed
101 * it is converted to a FRAGment as specified in AS.H */
103 /* internal structs */
113 int type; /* how to interpret object */
114 int size; /* Estimated max size of object */
115 unsigned long object; /* binary data */
116 int object_adjust; /* number added to object */
117 int pcrel; /* True if object is pcrel */
118 int pcrel_adjust; /* length in bytes from the
119 instruction start to the
121 int im_disp; /* True if the object is a displacement */
122 relax_substateT relax_substate; /* Initial relaxsubstate */
123 bit_fixS *bit_fixP; /* Pointer at bit_fix struct */
124 int addr_mode; /* What addrmode do we associate with this
126 char bsr; /* Sequent hack */
127 } iif_entryT; /* Internal Instruction Format */
131 int instr_size; /* Max size of instruction in bytes. */
132 iif_entryT iifP[IIF_ENTRIES + 1];
134 struct int_ins_form iif;
136 char *input_line_pointer;
137 /* description of the PARTs in IIF
139 * 0 total length in bytes of entries in iif
152 * For every entry there is a datalength in bytes. This is stored in size[n].
153 * 0, the objectlength is not explicitly given by the instruction
154 * and the operand is undefined. This is a case for relaxation.
155 * Reserve 4 bytes for the final object.
157 * 1, the entry contains one byte
158 * 2, the entry contains two bytes
159 * 3, the entry contains three bytes
160 * 4, the entry contains four bytes
163 * Furthermore, every entry has a data type identifier in type[n].
165 * 0, the entry is void, ignore it.
166 * 1, the entry is a binary number.
167 * 2, the entry is a pointer at an expression.
168 * Where expression may be as simple as a single '1',
169 * and as complicated as foo-bar+12,
170 * foo and bar may be undefined but suffixed by :{b|w|d} to
171 * control the length of the object.
173 * 3, the entry is a pointer at a bignum struct
176 * The low-order-byte coresponds to low physical memory.
177 * Obviously a FRAGment must be created for each valid disp in PART whose
178 * datalength is undefined (to bad) .
179 * The case where just the expression is undefined is less severe and is
180 * handled by fix. Here the number of bytes in the objectfile is known.
181 * With this representation we simplify the assembly and separates the
182 * machine dependent/independent parts in a more clean way (said OE)
185 struct ns32k_option opt1[] = /* restore, exit */
197 struct ns32k_option opt2[] = /* save, enter */
209 struct ns32k_option opt3[] = /* setcfg */
217 struct ns32k_option opt4[] = /* cinv */
224 struct ns32k_option opt5[] = /* string inst */
231 struct ns32k_option opt6[] = /* plain reg ext,cvtp etc */
244 #if !defined(NS32032) && !defined(NS32532)
248 struct ns32k_option cpureg_532[] = /* lpr spr */
261 {"intbase", 0xe, 0xff},
265 struct ns32k_option mmureg_532[] = /* lmr smr */
272 {"ivar0", 0xe, 0xff},
273 {"ivar1", 0xf, 0xff},
277 struct ns32k_option cpureg_032[] = /* lpr spr */
284 {"intbase", 0xe, 0xff},
288 struct ns32k_option mmureg_032[] = /* lmr smr */
304 struct ns32k_option *cpureg = cpureg_532;
305 struct ns32k_option *mmureg = mmureg_532;
307 struct ns32k_option *cpureg = cpureg_032;
308 struct ns32k_option *mmureg = mmureg_032;
312 const pseudo_typeS md_pseudo_table[] =
317 #define IND(x,y) (((x)<<2)+(y))
319 /* those are index's to relax groups in md_relax_table ie it must be
320 multiplied by 4 to point at a group start. Viz IND(x,y) Se function
321 relax_segment in write.c for more info */
326 /* those are index's to entries in a relax group */
332 /* Those limits are calculated from the displacement start in memory.
333 The ns32k uses the begining of the instruction as displacement
334 base. This type of displacements could be handled here by moving
335 the limit window up or down. I choose to use an internal
336 displacement base-adjust as there are other routines that must
337 consider this. Also, as we have two various offset-adjusts in the
338 ns32k (acb versus br/brs/jsr/bcond), two set of limits would have
339 had to be used. Now we dont have to think about that. */
342 const relax_typeS md_relax_table[] =
349 {(63), (-64), 1, IND (BRANCH, WORD)},
350 {(8192), (-8192), 2, IND (BRANCH, DOUBLE)},
355 /* Array used to test if mode contains displacements.
356 Value is true if mode contains displacement. */
359 {0, 0, 0, 0, 0, 0, 0, 0,
360 1, 1, 1, 1, 1, 1, 1, 1,
361 1, 1, 1, 0, 0, 1, 1, 0,
362 1, 1, 1, 1, 1, 1, 1, 1};
364 /* Array used to calculate max size of displacements */
369 static void evaluate_expr PARAMS ((expressionS * resultP, char *ptr));
370 static void md_number_to_disp PARAMS ((char *buf, long val, int n));
371 static void md_number_to_imm PARAMS ((char *buf, long val, int n));
373 /* Parses a general operand into an addressingmode struct
375 in: pointer at operand in ascii form
376 pointer at addr_mode struct for result
377 the level of recursion. (always 0 or 1)
379 out: data in addr_mode struct
382 addr_mode (operand, addr_modeP, recursive_level)
384 register addr_modeS *addr_modeP;
392 mode = DEFAULT; /* default */
393 addr_modeP->scaled_mode = 0; /* why not */
394 addr_modeP->scaled_reg = 0; /* if 0, not scaled index */
395 addr_modeP->float_flag = 0;
396 addr_modeP->am_size = 0;
397 addr_modeP->im_disp = 0;
398 addr_modeP->pcrel = 0; /* not set in this function */
399 addr_modeP->disp_suffix[0] = 0;
400 addr_modeP->disp_suffix[1] = 0;
401 addr_modeP->disp[0] = NULL;
402 addr_modeP->disp[1] = NULL;
407 } /* we don't want this */
411 /* the following three case statements controls the mode-chars
412 this is the place to ed if you want to change them */
413 #ifdef ABSOLUTE_PREFIX
414 case ABSOLUTE_PREFIX:
415 if (str[strl - 1] == ']')
417 addr_modeP->mode = 21; /* absolute */
418 addr_modeP->disp[0] = str + 1;
421 #ifdef IMMEDIATE_PREFIX
422 case IMMEDIATE_PREFIX:
423 if (str[strl - 1] == ']')
425 addr_modeP->mode = 20; /* immediate */
426 addr_modeP->disp[0] = str + 1;
430 if (str[strl - 1] != ']')
436 if (str[2] != '\000')
438 addr_modeP->mode = 27; /* pc-relativ */
439 addr_modeP->disp[0] = str + 2;
443 as_warn (_("Invalid syntax in PC-relative addressing mode"));
449 if (str[strl - 1] != ']')
451 if ((!strncmp (str, "ext(", 4)) && strl > 7)
453 addr_modeP->disp[0] = str + 4;
457 { /* disp[0]'s termination point */
464 while (j < strl && i != 0);
465 if (i != 0 || !(str[j + 1] == '-' || str[j + 1] == '+'))
467 as_warn (_("Invalid syntax in External addressing mode"));
470 str[j] = '\000'; /* null terminate disp[0] */
471 addr_modeP->disp[1] = str + j + 2;
472 addr_modeP->mode = 22;
486 addr_modeP->float_flag = 1;
488 if (str[1] >= '0' && str[1] < '8')
490 addr_modeP->mode = str[1] - '0';
495 if (!strncmp (str, "tos", 3))
497 addr_modeP->mode = 23; /* TopOfStack */
504 if (str[strl - 1] == ')')
506 if (str[strl - 2] == ')')
508 if (!strncmp (&str[strl - 5], "(fp", 3))
510 mode = 16; /* Memory Relative */
512 if (!strncmp (&str[strl - 5], "(sp", 3))
516 if (!strncmp (&str[strl - 5], "(sb", 3))
521 { /* memory relative */
522 addr_modeP->mode = mode;
523 j = strl - 5; /* temp for end of disp[0] */
528 if (str[strl] == ')')
530 if (str[strl] == '(')
533 while (strl > -1 && i != 0);
536 as_warn (_("Invalid syntax in Memory Relative addressing mode"));
539 addr_modeP->disp[1] = str;
540 addr_modeP->disp[0] = str + strl + 1;
541 str[j] = '\000'; /* null terminate disp[0] */
542 str[strl] = '\000'; /* null terminate disp[1] */
546 switch (str[strl - 3])
550 if (str[strl - 2] >= '0'
551 && str[strl - 2] < '8'
552 && str[strl - 4] == '(')
554 addr_modeP->mode = str[strl - 2] - '0' + 8;
555 addr_modeP->disp[0] = str;
557 return (-1); /* reg rel */
560 if (!strncmp (&str[strl - 4], "(fp", 3))
564 if (!strncmp (&str[strl - 4], "(sp", 3))
568 if (!strncmp (&str[strl - 4], "(sb", 3))
572 if (!strncmp (&str[strl - 4], "(pc", 3))
578 addr_modeP->mode = mode;
579 addr_modeP->disp[0] = str;
580 str[strl - 4] = '\0';
581 return (-1); /* memory space */
585 /* no trailing ')' do we have a ']' ? */
586 if (str[strl - 1] == ']')
588 switch (str[strl - 2])
603 as_warn (_("Invalid scaled-indexed mode, use (b,w,d,q)"));
604 if (str[strl - 3] != ':' || str[strl - 6] != '['
605 || str[strl - 5] == 'r' || str[strl - 4] < '0'
606 || str[strl - 4] > '7')
608 as_warn (_("Syntax in scaled-indexed mode, use [Rn:m] where n=[0..7] m={b,w,d,q}"));
612 if (recursive_level > 0)
614 as_warn (_("Scaled-indexed addressing mode combined with scaled-index"));
617 addr_modeP->am_size += 1; /* scaled index byte */
618 j = str[strl - 4] - '0'; /* store temporary */
619 str[strl - 6] = '\000'; /* nullterminate for recursive call */
620 i = addr_mode (str, addr_modeP, 1);
621 if (!i || addr_modeP->mode == 20)
623 as_warn (_("Invalid or illegal addressing mode combined with scaled-index"));
626 addr_modeP->scaled_mode = addr_modeP->mode; /* store the inferior
628 addr_modeP->mode = mode;
629 addr_modeP->scaled_reg = j + 1;
634 addr_modeP->mode = DEFAULT; /* default to whatever */
635 addr_modeP->disp[0] = str;
639 /* ptr points at string addr_modeP points at struct with result This
640 routine calls addr_mode to determine the general addr.mode of the
641 operand. When this is ready it parses the displacements for size
642 specifying suffixes and determines size of immediate mode via
643 ns32k-opcode. Also builds index bytes if needed. */
645 get_addr_mode (ptr, addr_modeP)
647 addr_modeS *addr_modeP;
650 addr_mode (ptr, addr_modeP, 0);
651 if (addr_modeP->mode == DEFAULT || addr_modeP->scaled_mode == -1)
653 /* resolve ambigious operands, this shouldn't be necessary if
654 one uses standard NSC operand syntax. But the sequent
655 compiler doesn't!!! This finds a proper addressinging mode
656 if it is implicitly stated. See ns32k-opcode.h */
657 (void) evaluate_expr (&exprP, ptr); /* this call takes time Sigh! */
658 if (addr_modeP->mode == DEFAULT)
660 if (exprP.X_add_symbol || exprP.X_op_symbol)
662 addr_modeP->mode = desc->default_model; /* we have a label */
666 addr_modeP->mode = desc->default_modec; /* we have a constant */
671 if (exprP.X_add_symbol || exprP.X_op_symbol)
673 addr_modeP->scaled_mode = desc->default_model;
677 addr_modeP->scaled_mode = desc->default_modec;
680 /* must put this mess down in addr_mode to handle the scaled
683 /* It appears as the sequent compiler wants an absolute when we have
684 a label without @. Constants becomes immediates besides the addr
685 case. Think it does so with local labels too, not optimum, pcrel
686 is better. When I have time I will make gas check this and
687 select pcrel when possible Actually that is trivial. */
688 if (tmp = addr_modeP->scaled_reg)
689 { /* build indexbyte */
690 tmp--; /* remember regnumber comes incremented for
692 tmp |= addr_modeP->scaled_mode << 3;
693 addr_modeP->index_byte = (char) tmp;
694 addr_modeP->am_size += 1;
696 if (disp_test[addr_modeP->mode])
697 { /* there was a displacement, probe for length
701 register char suffix;
702 register char suffix_sub;
705 register char *fromP;
707 addr_modeP->pcrel = 0;
708 if (disp_test[addr_modeP->mode])
709 { /* there is a displacement */
710 if (addr_modeP->mode == 27 || addr_modeP->scaled_mode == 27)
711 { /* do we have pcrel. mode */
712 addr_modeP->pcrel = 1;
714 addr_modeP->im_disp = 1;
715 for (i = 0; i < 2; i++)
717 suffix_sub = suffix = 0;
718 if (toP = addr_modeP->disp[i])
719 { /* suffix of expression, the largest size
730 as_warn (_("Premature end of suffix -- Defaulting to d"));
743 as_warn (_("Bad suffix after ':' use {b|w|d} Defaulting to d"));
747 toP--; /* So we write over the ':' */
748 if (suffix < suffix_sub)
752 *toP = '\0';/* terminate properly */
753 addr_modeP->disp_suffix[i] = suffix;
754 addr_modeP->am_size += suffix ? suffix : 4;
762 if (addr_modeP->mode == 20)
763 { /* look in ns32k_opcode for size */
764 addr_modeP->disp_suffix[0] = addr_modeP->am_size = desc->im_size;
765 addr_modeP->im_disp = 0;
768 return addr_modeP->mode;
772 /* read an optionlist */
774 optlist (str, optionP, default_map)
775 char *str; /* the string to extract options from */
776 struct ns32k_option *optionP; /* how to search the string */
777 unsigned long *default_map; /* default pattern and output */
779 register int i, j, k, strlen1, strlen2;
780 register char *patternP, *strP;
781 strlen1 = strlen (str);
784 as_fatal (_("Very short instr to option, ie you can't do it on a NULLstr"));
786 for (i = 0; optionP[i].pattern != 0; i++)
788 strlen2 = strlen (optionP[i].pattern);
789 for (j = 0; j < strlen1; j++)
791 patternP = optionP[i].pattern;
793 for (k = 0; k < strlen2; k++)
795 if (*(strP++) != *(patternP++))
800 *default_map |= optionP[i].or;
801 *default_map &= optionP[i].and;
807 /* search struct for symbols
808 This function is used to get the short integer form of reg names in
809 the instructions lmr, smr, lpr, spr return true if str is found in
813 list_search (str, optionP, default_map)
814 char *str; /* the string to match */
815 struct ns32k_option *optionP; /* list to search */
816 unsigned long *default_map; /* default pattern and output */
819 for (i = 0; optionP[i].pattern != 0; i++)
821 if (!strncmp (optionP[i].pattern, str, 20))
822 { /* use strncmp to be safe */
823 *default_map |= optionP[i].or;
824 *default_map &= optionP[i].and;
828 as_warn (_("No such entry in list. (cpu/mmu register)"));
833 evaluate_expr (resultP, ptr)
834 expressionS *resultP;
837 register char *tmp_line;
839 tmp_line = input_line_pointer;
840 input_line_pointer = ptr;
842 input_line_pointer = tmp_line;
845 /* Convert operands to iif-format and adds bitfields to the opcode.
846 Operands are parsed in such an order that the opcode is updated from
847 its most significant bit, that is when the operand need to alter the
849 Be carefull not to put to objects in the same iif-slot.
853 encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
863 int pcrel, tmp, b, loop, pcrel_adjust;
864 for (loop = 0; loop < argc; loop++)
866 i = operandsP[loop << 1] - '1'; /* what operand are we supposed
869 as_fatal (_("Internal consistency error. check ns32k-opcode.h"));
873 switch ((d = operandsP[(loop << 1) + 1]))
875 case 'f': /* operand of sfsr turns out to be a nasty
878 case 'Z': /* float not immediate */
879 case 'F': /* 32 bit float general form */
880 case 'L': /* 64 bit float */
881 case 'I': /* integer not immediate */
884 case 'D': /* double-word */
885 case 'A': /* double-word gen-address-form ie no regs
887 get_addr_mode (argv[i], &addr_modeP);
888 if((addr_modeP.mode == 20) &&
889 (d == 'I' || d == 'Z' || d == 'A')) {
890 as_fatal(d == 'A'? _("Address of immediate operand"):
891 _("Invalid immediate write operand."));
894 if (opcode_bit_ptr == desc->opcode_size)
898 for (j = b; j < (b + 2); j++)
900 if (addr_modeP.disp[j - b])
904 addr_modeP.disp_suffix[j - b],
905 (unsigned long) addr_modeP.disp[j - b],
912 (addr_modeP.scaled_reg ? addr_modeP.scaled_mode
918 iif.iifP[1].object |= ((long) addr_modeP.mode) << opcode_bit_ptr;
919 if (addr_modeP.scaled_reg)
922 IIF (j, 1, 1, (unsigned long) addr_modeP.index_byte,
923 0, 0, 0, 0, 0, NULL, -1, 0);
926 case 'b': /* multiple instruction disp */
927 freeptr++; /* OVE:this is an useful hack */
928 sprintf (freeptr, "((%s-1)*%d)\000", argv[i], desc->im_size);
930 pcrel -= 1; /* make pcrel 0 inspite of what case 'p':
933 case 'p': /* displacement - pc relative addressing */
936 case 'd': /* displacement */
937 iif.instr_size += suffixP[i] ? suffixP[i] : 4;
938 IIF (12, 2, suffixP[i], (unsigned long) argv[i], 0,
939 pcrel, pcrel_adjust, 1, IND (BRANCH, BYTE), NULL, -1, 0);
941 case 'H': /* sequent-hack: the linker wants a bit set
944 iif.instr_size += suffixP[i] ? suffixP[i] : 4;
945 IIF (12, 2, suffixP[i], (unsigned long) argv[i], 0,
946 pcrel, pcrel_adjust, 1, IND (BRANCH, BYTE), NULL, -1, 1);
948 case 'q': /* quick */
950 IIF (11, 2, 42, (unsigned long) argv[i], 0, 0, 0, 0, 0,
951 bit_fix_new (4, opcode_bit_ptr, -8, 7, 0, 1, 0), -1, 0);
953 case 'r': /* register number (3 bits) */
954 list_search (argv[i], opt6, &tmp);
956 iif.iifP[1].object |= tmp << opcode_bit_ptr;
958 case 'O': /* setcfg instruction optionslist */
959 optlist (argv[i], opt3, &tmp);
961 iif.iifP[1].object |= tmp << 15;
963 case 'C': /* cinv instruction optionslist */
964 optlist (argv[i], opt4, &tmp);
966 iif.iifP[1].object |= tmp << 15; /* insert the regtype in opcode */
968 case 'S': /* stringinstruction optionslist */
969 optlist (argv[i], opt5, &tmp);
971 iif.iifP[1].object |= tmp << 15;
974 case 'U': /* registerlist */
975 IIF (10, 1, 1, 0, 0, 0, 0, 0, 0, NULL, -1, 0);
976 switch (operandsP[(i << 1) + 1])
978 case 'u': /* restore, exit */
979 optlist (argv[i], opt1, &iif.iifP[10].object);
981 case 'U': /* save,enter */
982 optlist (argv[i], opt2, &iif.iifP[10].object);
987 case 'M': /* mmu register */
988 list_search (argv[i], mmureg, &tmp);
990 iif.iifP[1].object |= tmp << opcode_bit_ptr;
992 case 'P': /* cpu register */
993 list_search (argv[i], cpureg, &tmp);
995 iif.iifP[1].object |= tmp << opcode_bit_ptr;
997 case 'g': /* inss exts */
998 iif.instr_size += 1; /* 1 byte is allocated after the opcode */
1000 (unsigned long) argv[i], /* i always 2 here */
1002 bit_fix_new (3, 5, 0, 7, 0, 0, 0), /* a bit_fix is targeted to
1008 (unsigned long) argv[i], /* i always 3 here */
1010 bit_fix_new (5, 0, 1, 32, -1, 0, -1), -1, 0);
1013 iif.instr_size += 1;
1014 b = 2 + i; /* put the extension byte after opcode */
1015 IIF (b, 2, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0);
1018 as_fatal (_("Bad opcode-table-option, check in file ns32k-opcode.h"));
1023 /* in: instruction line
1024 out: internal structure of instruction
1025 that has been prepared for direct conversion to fragment(s) and
1026 fixes in a systematical fashion
1027 Return-value = recursive_level
1029 /* build iif of one assembly text line */
1031 parse (line, recursive_level)
1033 int recursive_level;
1035 register char *lineptr, c, suffix_separator;
1039 char suffix[MAX_ARGS], *argv[MAX_ARGS]; /* no more than 4 operands */
1040 if (recursive_level <= 0)
1041 { /* called from md_assemble */
1042 for (lineptr = line; (*lineptr) != '\0' && (*lineptr) != ' '; lineptr++);
1045 if (!(desc = (struct ns32k_opcode *) hash_find (inst_hash_handle, line)))
1047 as_fatal (_("No such opcode"));
1056 if (*desc->operands)
1058 if (*lineptr++ != '\0')
1062 while (*lineptr != '\0')
1064 if (desc->operands[argc << 1])
1067 arg_type = desc->operands[(argc << 1) + 1];
1073 case 'H': /* the operand is supposed to be a
1075 /* Hackwarning: do not forget to update the 4
1076 cases above when editing ns32k-opcode.h */
1077 suffix_separator = ':';
1080 suffix_separator = '\255'; /* if this char occurs we
1083 suffix[argc] = 0; /* 0 when no ':' is encountered */
1084 argv[argc] = freeptr;
1086 while ((c = *lineptr) != '\0' && c != sep)
1101 if (c == suffix_separator)
1102 { /* ':' - label/suffix separator */
1115 as_warn (_("Bad suffix, defaulting to d"));
1117 if (lineptr[1] == '\0' || lineptr[1] == sep)
1131 if (*lineptr == '\0')
1137 as_fatal (_("Too many operands passed to instruction"));
1142 if (argc != strlen (desc->operands) / 2)
1144 if (strlen (desc->default_args))
1145 { /* we can apply default, dont goof */
1146 if (parse (desc->default_args, 1) != 1)
1147 { /* check error in default */
1148 as_fatal (_("Wrong numbers of operands in default, check ns32k-opcodes.h"));
1153 as_fatal (_("Wrong number of operands"));
1157 for (i = 0; i < IIF_ENTRIES; i++)
1159 iif.iifP[i].type = 0; /* mark all entries as void*/
1162 /* build opcode iif-entry */
1163 iif.instr_size = desc->opcode_size / 8;
1164 IIF (1, 1, iif.instr_size, desc->opcode_seed, 0, 0, 0, 0, 0, 0, -1, 0);
1166 /* this call encodes operands to iif format */
1169 encode_operand (argc,
1176 return recursive_level;
1180 /* Convert iif to fragments. From this point we start to dribble with
1181 * functions in other files than this one.(Except hash.c) So, if it's
1182 * possible to make an iif for an other CPU, you don't need to know
1183 * what frags, relax, obstacks, etc is in order to port this
1184 * assembler. You only need to know if it's possible to reduce your
1185 * cpu-instruction to iif-format (takes some work) and adopt the other
1186 * md_? parts according to given instructions Note that iif was
1187 * invented for the clean ns32k`s architecure.
1190 /* GAS for the ns32k has a problem. PC relative displacements are
1191 * relative to the address of the opcode, not the address of the
1192 * operand. We used to keep track of the offset between the operand
1193 * and the opcode in pcrel_adjust for each frag and each fix. However,
1194 * we get into trouble where there are two or more pc-relative
1195 * operands and the size of the first one can't be determined. Then in
1196 * the relax phase, the size of the first operand will change and
1197 * pcrel_adjust will no longer be correct. The current solution is
1198 * keep a pointer to the frag with the opcode in it and the offset in
1199 * that frag for each frag and each fix. Then, when needed, we can
1200 * always figure out how far it is between the opcode and the pcrel
1201 * object. See also md_pcrel_adjust and md_fix_pcrel_adjust. For
1202 * objects not part of an instruction, the pointer to the opcode frag
1203 * is always zero. */
1211 unsigned int inst_offset;
1220 memP = frag_more (0);
1222 inst_offset = (memP - frag_now->fr_literal);
1223 inst_frag = frag_now;
1225 for (i = 0; i < IIF_ENTRIES; i++)
1227 if (type = iif.iifP[i].type)
1228 { /* the object exist, so handle it */
1229 switch (size = iif.iifP[i].size)
1232 size = 0; /* it's a bitfix that operates on an existing
1234 if (iif.iifP[i].bit_fixP->fx_bit_base)
1235 { /* expand fx_bit_base to point at opcode */
1236 iif.iifP[i].bit_fixP->fx_bit_base = (long) inst_opcode;
1238 case 8: /* bignum or doublefloat */
1242 case 4: /* the final size in objectmemory is known */
1243 memP = frag_more(size);
1244 j = iif.iifP[i].bit_fixP;
1247 case 1: /* the object is pure binary */
1248 if (j || iif.iifP[i].pcrel)
1250 fix_new_ns32k (frag_now,
1251 (long) (memP - frag_now->fr_literal),
1256 iif.iifP[i].im_disp,
1258 iif.iifP[i].bsr, /* sequent hack */
1259 inst_frag, inst_offset);
1262 { /* good, just put them bytes out */
1263 switch (iif.iifP[i].im_disp)
1266 md_number_to_chars (memP, iif.iifP[i].object, size);
1269 md_number_to_disp (memP, iif.iifP[i].object, size);
1272 as_fatal (_("iif convert internal pcrel/binary"));
1277 /* the object is a pointer at an expression, so
1278 unpack it, note that bignums may result from the
1280 evaluate_expr (&exprP, (char *) iif.iifP[i].object);
1281 if (exprP.X_op == O_big || size == 8)
1283 if ((k = exprP.X_add_number) > 0)
1285 /* we have a bignum ie a quad. This can only
1286 happens in a long suffixed instruction */
1288 as_warn (_("Bignum too big for long"));
1291 for (l = 0; k > 0; k--, l += 2)
1293 md_number_to_chars (memP + l,
1294 generic_bignum[l >> 1],
1295 sizeof (LITTLENUM_TYPE));
1300 LITTLENUM_TYPE words[4];
1305 gen_to_words (words, 2, 8);
1306 md_number_to_imm (memP, (long) words[0],
1307 sizeof (LITTLENUM_TYPE));
1308 md_number_to_imm (memP + sizeof (LITTLENUM_TYPE),
1310 sizeof (LITTLENUM_TYPE));
1313 gen_to_words (words, 4, 11);
1314 md_number_to_imm (memP, (long) words[0],
1315 sizeof (LITTLENUM_TYPE));
1316 md_number_to_imm (memP + sizeof (LITTLENUM_TYPE),
1318 sizeof (LITTLENUM_TYPE));
1319 md_number_to_imm ((memP + 2
1320 * sizeof (LITTLENUM_TYPE)),
1322 sizeof (LITTLENUM_TYPE));
1323 md_number_to_imm ((memP + 3
1324 * sizeof (LITTLENUM_TYPE)),
1326 sizeof (LITTLENUM_TYPE));
1333 exprP.X_add_symbol ||
1334 exprP.X_op_symbol ||
1337 /* The expression was undefined due to an
1338 undefined label. Create a fix so we can fix
1339 the object later. */
1340 exprP.X_add_number += iif.iifP[i].object_adjust;
1341 fix_new_ns32k_exp (frag_now,
1342 (long) (memP - frag_now->fr_literal),
1346 iif.iifP[i].im_disp,
1349 inst_frag, inst_offset);
1353 /* good, just put them bytes out */
1354 switch (iif.iifP[i].im_disp)
1357 md_number_to_imm (memP, exprP.X_add_number, size);
1360 md_number_to_disp (memP, exprP.X_add_number, size);
1363 as_fatal (_("iif convert internal pcrel/pointer"));
1368 as_fatal (_("Internal logic error in iif.iifP[n].type"));
1372 /* To bad, the object may be undefined as far as its
1373 final nsize in object memory is concerned. The size
1374 of the object in objectmemory is not explicitly
1375 given. If the object is defined its length can be
1376 determined and a fix can replace the frag. */
1378 evaluate_expr (&exprP, (char *) iif.iifP[i].object);
1379 if ((exprP.X_add_symbol || exprP.X_op_symbol) &&
1382 /* Size is unknown until link time so have to
1385 memP = frag_more(size);
1386 fix_new_ns32k_exp (frag_now,
1387 (long) (memP - frag_now->fr_literal),
1390 0, /* never iif.iifP[i].pcrel, */
1391 1, /* always iif.iifP[i].im_disp */
1395 break; /* exit this absolute hack */
1398 if (exprP.X_add_symbol || exprP.X_op_symbol)
1400 if (exprP.X_op_symbol)
1401 { /* We cant relax this case */
1402 as_fatal (_("Can't relax difference"));
1407 /* Size is not important. This gets fixed by relax,
1408 * but we assume 0 in what follows
1410 memP = frag_more(4); /* Max size */
1414 fragS *old_frag = frag_now;
1415 frag_variant (rs_machine_dependent,
1418 IND (BRANCH, UNDEF), /* expecting the worst */
1422 frag_opcode_frag(old_frag) = inst_frag;
1423 frag_opcode_offset(old_frag) = inst_offset;
1424 frag_bsr(old_frag) = iif.iifP[i].bsr;
1430 /* This duplicates code in md_number_to_disp */
1431 if (-64 <= exprP.X_add_number && exprP.X_add_number <= 63)
1437 if (-8192 <= exprP.X_add_number
1438 && exprP.X_add_number <= 8191)
1444 if (-0x20000000<=exprP.X_add_number &&
1445 exprP.X_add_number<=0x1fffffff)
1451 as_warn (_("Displacement to large for :d"));
1456 memP = frag_more(size);
1457 md_number_to_disp (memP, exprP.X_add_number, size);
1462 as_fatal (_("Internal logic error in iif.iifP[].type"));
1468 #ifdef BFD_ASSEMBLER
1469 /* This functionality should really be in the bfd library */
1470 static bfd_reloc_code_real_type
1471 reloc (int size, int pcrel, int type)
1474 bfd_reloc_code_real_type relocs[] = {
1475 BFD_RELOC_NS32K_IMM_8,
1476 BFD_RELOC_NS32K_IMM_16,
1477 BFD_RELOC_NS32K_IMM_32,
1478 BFD_RELOC_NS32K_IMM_8_PCREL,
1479 BFD_RELOC_NS32K_IMM_16_PCREL,
1480 BFD_RELOC_NS32K_IMM_32_PCREL,
1482 /* ns32k displacements */
1483 BFD_RELOC_NS32K_DISP_8,
1484 BFD_RELOC_NS32K_DISP_16,
1485 BFD_RELOC_NS32K_DISP_32,
1486 BFD_RELOC_NS32K_DISP_8_PCREL,
1487 BFD_RELOC_NS32K_DISP_16_PCREL,
1488 BFD_RELOC_NS32K_DISP_32_PCREL,
1490 /* Normal 2's complement */
1513 index = length + 3 * pcrel + 6 * type;
1514 if (index >= 0 && index < sizeof(relocs)/sizeof(relocs[0]))
1515 return relocs[index];
1517 as_bad (_("Can not do %d byte pc-relative relocation for storage type %d"),
1520 as_bad (_("Can not do %d byte relocation for storage type %d"),
1522 return BFD_RELOC_NONE;
1532 freeptr = freeptr_static;
1533 parse (line, 0); /* explode line to more fix form in iif */
1534 convert_iif (); /* convert iif to frags, fix's etc */
1536 printf (" \t\t\t%s\n", line);
1544 /* build a hashtable of the instructions */
1545 const struct ns32k_opcode *ptr;
1547 inst_hash_handle = hash_new ();
1548 for (ptr = ns32k_opcodes; ptr < endop; ptr++)
1550 if ((stat = hash_insert (inst_hash_handle, ptr->name, (char *) ptr)))
1552 as_fatal (_("Can't hash %s: %s"), ptr->name, stat); /*fatal*/
1555 freeptr_static = (char *) malloc (PRIVATE_SIZE); /* some private space
1559 /* Must be equal to MAX_PRECISON in atof-ieee.c */
1560 #define MAX_LITTLENUMS 6
1562 /* Turn the string pointed to by litP into a floating point constant
1563 of type type, and emit the appropriate bytes. The number of
1564 LITTLENUMS emitted is stored in *sizeP . An error message is
1565 returned, or NULL on OK. */
1567 md_atof (type, litP, sizeP)
1573 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1574 LITTLENUM_TYPE *wordP;
1588 return _("Bad call to MD_ATOF()");
1590 t = atof_ieee (input_line_pointer, type, words);
1592 input_line_pointer = t;
1594 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1595 for (wordP = words + prec; prec--;)
1597 md_number_to_chars (litP, (long) (*--wordP), sizeof (LITTLENUM_TYPE));
1598 litP += sizeof (LITTLENUM_TYPE);
1603 /* Convert number to chars in correct order */
1606 md_number_to_chars (buf, value, nbytes)
1611 number_to_chars_littleendian (buf, value, nbytes);
1615 /* This is a variant of md_numbers_to_chars. The reason for its'
1616 existence is the fact that ns32k uses Huffman coded
1617 displacements. This implies that the bit order is reversed in
1618 displacements and that they are prefixed with a size-tag.
1622 10xxxxxx xxxxxxxx word
1623 11xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx double word
1625 This must be taken care of and we do it here! */
1627 md_number_to_disp (buf, val, n)
1635 if (val < -64 || val > 63)
1636 as_warn (_("Byte displacement out of range. line number not valid"));
1639 printf ("%x ", val & 0xff);
1644 if (val < -8192 || val > 8191)
1645 as_warn (_("Word displacement out of range. line number not valid"));
1649 printf ("%x ", val >> 8 & 0xff);
1651 *buf++ = (val >> 8);
1653 printf ("%x ", val & 0xff);
1658 if (val < -0x20000000 || val >= 0x20000000)
1659 as_warn (_("Double word displacement out of range"));
1662 printf ("%x ", val >> 24 & 0xff);
1664 *buf++ = (val >> 24);
1666 printf ("%x ", val >> 16 & 0xff);
1668 *buf++ = (val >> 16);
1670 printf ("%x ", val >> 8 & 0xff);
1672 *buf++ = (val >> 8);
1674 printf ("%x ", val & 0xff);
1679 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1680 __LINE__, __FILE__);
1685 md_number_to_imm (buf, val, n)
1694 printf ("%x ", val & 0xff);
1700 printf ("%x ", val >> 8 & 0xff);
1702 *buf++ = (val >> 8);
1704 printf ("%x ", val & 0xff);
1710 printf ("%x ", val >> 24 & 0xff);
1712 *buf++ = (val >> 24);
1714 printf ("%x ", val >> 16 & 0xff);
1716 *buf++ = (val >> 16);
1718 printf ("%x ", val >> 8 & 0xff);
1720 *buf++ = (val >> 8);
1722 printf ("%x ", val & 0xff);
1727 as_fatal (_("Internal logic error. line %s, file \"%s\""),
1728 __LINE__, __FILE__);
1733 /* fast bitfiddling support */
1734 /* mask used to zero bitfield before oring in the true field */
1736 static unsigned long l_mask[] =
1738 0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
1739 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
1740 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
1741 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
1742 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
1743 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
1744 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
1745 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
1747 static unsigned long r_mask[] =
1749 0x00000000, 0x00000001, 0x00000003, 0x00000007,
1750 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
1751 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
1752 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
1753 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
1754 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
1755 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
1756 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
1758 #define MASK_BITS 31
1759 /* Insert bitfield described by field_ptr and val at buf
1760 This routine is written for modification of the first 4 bytes pointed
1761 to by buf, to yield speed.
1762 The ifdef stuff is for selection between a ns32k-dependent routine
1763 and a general version. (My advice: use the general version!)
1767 md_number_to_field (buf, val, field_ptr)
1770 register bit_fixS *field_ptr;
1772 register unsigned long object;
1773 register unsigned long mask;
1774 /* define ENDIAN on a ns32k machine */
1776 register unsigned long *mem_ptr;
1778 register char *mem_ptr;
1780 if (field_ptr->fx_bit_min <= val && val <= field_ptr->fx_bit_max)
1783 if (field_ptr->fx_bit_base)
1784 { /* override buf */
1785 mem_ptr = (unsigned long *) field_ptr->fx_bit_base;
1789 mem_ptr = (unsigned long *) buf;
1791 mem_ptr = ((unsigned long *)
1792 ((char *) mem_ptr + field_ptr->fx_bit_base_adj));
1794 if (field_ptr->fx_bit_base)
1795 { /* override buf */
1796 mem_ptr = (char *) field_ptr->fx_bit_base;
1802 mem_ptr += field_ptr->fx_bit_base_adj;
1804 #ifdef ENDIAN /* we have a nice ns32k machine with lowbyte
1805 at low-physical mem */
1806 object = *mem_ptr; /* get some bytes */
1807 #else /* OVE Goof! the machine is a m68k or dito */
1808 /* That takes more byte fiddling */
1810 object |= mem_ptr[3] & 0xff;
1812 object |= mem_ptr[2] & 0xff;
1814 object |= mem_ptr[1] & 0xff;
1816 object |= mem_ptr[0] & 0xff;
1819 mask |= (r_mask[field_ptr->fx_bit_offset]);
1820 mask |= (l_mask[field_ptr->fx_bit_offset + field_ptr->fx_bit_size]);
1822 val += field_ptr->fx_bit_add;
1823 object |= ((val << field_ptr->fx_bit_offset) & (mask ^ 0xffffffff));
1827 mem_ptr[0] = (char) object;
1829 mem_ptr[1] = (char) object;
1831 mem_ptr[2] = (char) object;
1833 mem_ptr[3] = (char) object;
1838 as_warn (_("Bit field out of range"));
1842 int md_pcrel_adjust (fragS *fragP)
1845 addressT opcode_address;
1846 unsigned int offset;
1847 opcode_frag = frag_opcode_frag(fragP);
1848 if (opcode_frag == 0)
1850 offset = frag_opcode_offset(fragP);
1851 opcode_address = offset + opcode_frag->fr_address;
1852 return fragP->fr_address + fragP->fr_fix - opcode_address;
1855 int md_fix_pcrel_adjust (fixS *fixP)
1857 fragS *fragP = fixP->fx_frag;
1859 addressT opcode_address;
1860 unsigned int offset;
1861 opcode_frag = fix_opcode_frag(fixP);
1862 if (opcode_frag == 0)
1864 offset = fix_opcode_offset(fixP);
1865 opcode_address = offset + opcode_frag->fr_address;
1866 return fixP->fx_where + fixP->fx_frag->fr_address - opcode_address;
1869 /* Apply a fixS (fixup of an instruction or data that we didn't have
1870 enough info to complete immediately) to the data in a frag.
1872 On the ns32k, everything is in a different format, so we have broken
1873 out separate functions for each kind of thing we could be fixing.
1874 They all get called from here. */
1876 #ifdef BFD_ASSEMBLER
1878 md_apply_fix (fixP, valp)
1883 md_apply_fix (fixP, val)
1888 #ifdef BFD_ASSEMBLER
1891 fragS *fragP = fixP->fx_frag;
1893 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1895 if (fix_bit_fixP(fixP))
1896 { /* Bitfields to fix, sigh */
1897 md_number_to_field (buf, val, fix_bit_fixP(fixP));
1900 switch (fix_im_disp(fixP))
1903 case 0: /* Immediate field */
1904 md_number_to_imm (buf, val, fixP->fx_size);
1907 case 1: /* Displacement field */
1908 /* Calculate offset */
1910 md_number_to_disp (buf,
1911 (fixP->fx_pcrel ? val + md_fix_pcrel_adjust(fixP)
1912 : val), fixP->fx_size);
1916 case 2: /* Pointer in a data object */
1917 md_number_to_chars (buf, val, fixP->fx_size);
1920 #ifdef BSD_ASSEMBLER
1925 /* Convert a relaxed displacement to ditto in final output */
1927 #ifndef BFD_ASSEMBLER
1929 md_convert_frag (headers, sec, fragP)
1930 object_headers *headers;
1932 register fragS *fragP;
1935 md_convert_frag (abfd, sec, fragP)
1938 register fragS *fragP;
1944 /* Address in gas core of the place to store the displacement. */
1945 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
1946 /* Address in object code of the displacement. */
1951 switch (fragP->fr_subtype)
1953 case IND (BRANCH, BYTE):
1956 case IND (BRANCH, WORD):
1959 case IND (BRANCH, DOUBLE):
1967 know (fragP->fr_symbol);
1969 object_address = fragP->fr_fix + fragP->fr_address;
1970 /* The displacement of the address, from current location. */
1971 disp = (S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset) - object_address;
1972 #ifdef BFD_ASSEMBLER
1973 disp += fragP->fr_symbol->sy_frag->fr_address;
1975 disp += md_pcrel_adjust(fragP);
1977 md_number_to_disp (buffer_address, (long) disp, (int) ext);
1978 fragP->fr_fix += ext;
1981 /* This function returns the estimated size a variable object will occupy,
1982 one can say that we tries to guess the size of the objects before we
1986 md_estimate_size_before_relax (fragP, segment)
1987 register fragS *fragP;
1991 old_fix = fragP->fr_fix;
1992 switch (fragP->fr_subtype)
1994 case IND (BRANCH, UNDEF):
1995 if (S_GET_SEGMENT (fragP->fr_symbol) == segment)
1997 /* the symbol has been assigned a value */
1998 fragP->fr_subtype = IND (BRANCH, BYTE);
2002 /* we don't relax symbols defined in an other segment the
2003 thing to do is to assume the object will occupy 4 bytes */
2004 fix_new_ns32k (fragP,
2005 (int) (fragP->fr_fix),
2012 frag_bsr(fragP), /*sequent hack */
2013 frag_opcode_frag(fragP),
2014 frag_opcode_offset(fragP));
2016 /* fragP->fr_opcode[1]=0xff; */
2020 case IND (BRANCH, BYTE):
2026 return fragP->fr_var + fragP->fr_fix - old_fix;
2029 int md_short_jump_size = 3;
2030 int md_long_jump_size = 5;
2031 const int md_reloc_size = 8; /* Size of relocation record */
2034 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2036 addressT from_addr, to_addr;
2042 offset = to_addr - from_addr;
2043 md_number_to_chars (ptr, (valueT) 0xEA, 1);
2044 md_number_to_disp (ptr + 1, (valueT) offset, 2);
2048 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2050 addressT from_addr, to_addr;
2056 offset = to_addr - from_addr;
2057 md_number_to_chars (ptr, (valueT) 0xEA, 1);
2058 md_number_to_disp (ptr + 1, (valueT) offset, 4);
2061 CONST char *md_shortopts = "m:";
2062 struct option md_longopts[] = {
2063 {NULL, no_argument, NULL, 0}
2065 size_t md_longopts_size = sizeof(md_longopts);
2068 md_parse_option (c, arg)
2075 if (!strcmp (arg, "32032"))
2077 cpureg = cpureg_032;
2078 mmureg = mmureg_032;
2080 else if (!strcmp (arg, "32532"))
2082 cpureg = cpureg_532;
2083 mmureg = mmureg_532;
2087 as_bad (_("invalid architecture option -m%s"), arg);
2100 md_show_usage (stream)
2103 fprintf(stream, _("\
2105 -m32032 | -m32532 select variant of NS32K architecture\n"));
2112 * Create a bit_fixS in obstack 'notes'.
2113 * This struct is used to profile the normal fix. If the bit_fixP is a
2114 * valid pointer (not NULL) the bit_fix data will be used to format the fix.
2117 bit_fix_new (size, offset, min, max, add, base_type, base_adj)
2118 char size; /* Length of bitfield */
2119 char offset; /* Bit offset to bitfield */
2120 long min; /* Signextended min for bitfield */
2121 long max; /* Signextended max for bitfield */
2122 long add; /* Add mask, used for huffman prefix */
2123 long base_type; /* 0 or 1, if 1 it's exploded to opcode ptr */
2126 register bit_fixS *bit_fixP;
2128 bit_fixP = (bit_fixS *) obstack_alloc (¬es, sizeof (bit_fixS));
2130 bit_fixP->fx_bit_size = size;
2131 bit_fixP->fx_bit_offset = offset;
2132 bit_fixP->fx_bit_base = base_type;
2133 bit_fixP->fx_bit_base_adj = base_adj;
2134 bit_fixP->fx_bit_max = max;
2135 bit_fixP->fx_bit_min = min;
2136 bit_fixP->fx_bit_add = add;
2142 fix_new_ns32k (frag, where, size, add_symbol, offset, pcrel,
2143 im_disp, bit_fixP, bsr, opcode_frag, opcode_offset)
2144 fragS *frag; /* Which frag? */
2145 int where; /* Where in that frag? */
2146 int size; /* 1, 2 or 4 usually. */
2147 symbolS *add_symbol; /* X_add_symbol. */
2148 long offset; /* X_add_number. */
2149 int pcrel; /* TRUE if PC-relative relocation. */
2150 char im_disp; /* true if the value to write is a
2152 bit_fixS *bit_fixP; /* pointer at struct of bit_fix's, ignored if
2154 char bsr; /* sequent-linker-hack: 1 when relocobject is
2157 unsigned int opcode_offset;
2160 fixS *fixP = fix_new (frag, where, size, add_symbol,
2162 #ifdef BFD_ASSEMBLER
2163 bit_fixP? NO_RELOC: reloc(size, pcrel, im_disp)
2169 fix_opcode_frag(fixP) = opcode_frag;
2170 fix_opcode_offset(fixP) = opcode_offset;
2171 fix_im_disp(fixP) = im_disp;
2172 fix_bsr(fixP) = bsr;
2173 fix_bit_fixP(fixP) = bit_fixP;
2174 } /* fix_new_ns32k() */
2177 fix_new_ns32k_exp (frag, where, size, exp, pcrel,
2178 im_disp, bit_fixP, bsr, opcode_frag, opcode_offset)
2179 fragS *frag; /* Which frag? */
2180 int where; /* Where in that frag? */
2181 int size; /* 1, 2 or 4 usually. */
2182 expressionS *exp; /* Expression. */
2183 int pcrel; /* TRUE if PC-relative relocation. */
2184 char im_disp; /* true if the value to write is a
2186 bit_fixS *bit_fixP; /* pointer at struct of bit_fix's, ignored if
2188 char bsr; /* sequent-linker-hack: 1 when relocobject is
2191 unsigned int opcode_offset;
2193 fixS *fixP = fix_new_exp (frag, where, size, exp, pcrel,
2194 #ifdef BFD_ASSEMBLER
2195 bit_fixP? NO_RELOC: reloc(size, pcrel, im_disp)
2201 fix_opcode_frag(fixP) = opcode_frag;
2202 fix_opcode_offset(fixP) = opcode_offset;
2203 fix_im_disp(fixP) = im_disp;
2204 fix_bsr(fixP) = bsr;
2205 fix_bit_fixP(fixP) = bit_fixP;
2206 } /* fix_new_ns32k() */
2208 /* This is TC_CONS_FIX_NEW, called by emit_expr in read.c. */
2211 cons_fix_new_ns32k (frag, where, size, exp)
2212 fragS *frag; /* Which frag? */
2213 int where; /* Where in that frag? */
2214 int size; /* 1, 2 or 4 usually. */
2215 expressionS *exp; /* Expression. */
2217 fix_new_ns32k_exp (frag, where, size, exp,
2221 /* We have no need to default values of symbols. */
2224 md_undefined_symbol (name)
2230 /* Round up a section size to the appropriate boundary. */
2232 md_section_align (segment, size)
2236 return size; /* Byte alignment is fine */
2239 /* Exactly what point is a PC-relative offset relative TO? On the
2240 ns32k, they're relative to the start of the instruction. */
2242 md_pcrel_from (fixP)
2246 res = fixP->fx_where + fixP->fx_frag->fr_address;
2247 #ifdef SEQUENT_COMPATABILITY
2248 if (frag_bsr(fixP->fx_frag))
2249 res += 0x12 /* FOO Kludge alert! */
2254 #ifdef BFD_ASSEMBLER
2257 tc_gen_reloc (section, fixp)
2262 bfd_reloc_code_real_type code;
2264 code = reloc(fixp->fx_size, fixp->fx_pcrel, fix_im_disp(fixp));
2266 rel = (arelent *) xmalloc (sizeof (arelent));
2267 rel->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2268 rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
2270 rel->addend = fixp->fx_addnumber;
2274 rel->howto = bfd_reloc_type_lookup (stdoutput, code);
2279 name = S_GET_NAME (fixp->fx_addsy);
2281 name = _("<unknown>");
2282 as_fatal (_("Cannot find relocation type for symbol %s, code %d"),
2288 #else /* BFD_ASSEMBLER */
2292 cons_fix_new_ns32k (where, fixP, segment_address_in_file)
2295 relax_addressT segment_address_in_file;
2298 * In: length of relocation (or of address) in chars: 1, 2 or 4.
2299 * Out: GNU LD relocation length code: 0, 1, or 2.
2302 static unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
2305 know (fixP->fx_addsy != NULL);
2307 md_number_to_chars (where,
2308 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
2311 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
2312 ? S_GET_TYPE (fixP->fx_addsy)
2313 : fixP->fx_addsy->sy_number);
2315 md_number_to_chars (where + 4,
2316 ((long) (r_symbolnum)
2317 | (long) (fixP->fx_pcrel << 24)
2318 | (long) (nbytes_r_length[fixP->fx_size] << 25)
2319 | (long) ((!S_IS_DEFINED (fixP->fx_addsy)) << 27)
2320 | (long) (fix_bsr(fixP) << 28)
2321 | (long) (fix_im_disp(fixP) << 29)),
2325 #endif /* OBJ_AOUT */
2326 #endif /* BFD_ASSMEBLER */
2328 /* end of tc-ns32k.c */