Home | History | Annotate | Line # | Download | only in config
tc-mmix.c revision 1.1.1.11
      1       1.1     skrll /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
      2  1.1.1.11  christos    Copyright (C) 2001-2026 Free Software Foundation, Inc.
      3       1.1     skrll 
      4       1.1     skrll    This file is part of GAS, the GNU Assembler.
      5       1.1     skrll 
      6       1.1     skrll    GAS is free software; you can redistribute it and/or modify
      7       1.1     skrll    it under the terms of the GNU General Public License as published by
      8       1.1     skrll    the Free Software Foundation; either version 3, or (at your option)
      9       1.1     skrll    any later version.
     10       1.1     skrll 
     11       1.1     skrll    GAS is distributed in the hope that it will be useful,
     12       1.1     skrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13       1.1     skrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14       1.1     skrll    GNU General Public License for more details.
     15       1.1     skrll 
     16       1.1     skrll    You should have received a copy of the GNU General Public License
     17       1.1     skrll    along with GAS; see the file COPYING.  If not, write to
     18       1.1     skrll    the Free Software Foundation, 51 Franklin Street - Fifth Floor,
     19       1.1     skrll    Boston, MA 02110-1301, USA.  */
     20       1.1     skrll 
     21       1.1     skrll /* Knuth's assembler mmixal does not provide a relocatable format; mmo is
     22       1.1     skrll    to be considered a final link-format.  In the final link, we make mmo,
     23       1.1     skrll    but for relocatable files, we use ELF.
     24       1.1     skrll 
     25       1.1     skrll    One goal is to provide a superset of what mmixal does, including
     26       1.1     skrll    compatible syntax, but the main purpose is to serve GCC.  */
     27       1.1     skrll 
     28       1.1     skrll 
     29       1.1     skrll #include "as.h"
     30   1.1.1.3  christos #include <limits.h>
     31       1.1     skrll #include "subsegs.h"
     32       1.1     skrll #include "elf/mmix.h"
     33       1.1     skrll #include "opcode/mmix.h"
     34       1.1     skrll #include "safe-ctype.h"
     35       1.1     skrll #include "dwarf2dbg.h"
     36       1.1     skrll #include "obstack.h"
     37       1.1     skrll 
     38       1.1     skrll /* Something to describe what we need to do with a fixup before output,
     39       1.1     skrll    for example assert something of what it became or make a relocation.  */
     40       1.1     skrll 
     41       1.1     skrll enum mmix_fixup_action
     42   1.1.1.3  christos {
     43   1.1.1.3  christos   mmix_fixup_byte,
     44   1.1.1.3  christos   mmix_fixup_register,
     45   1.1.1.3  christos   mmix_fixup_register_or_adjust_for_byte
     46   1.1.1.3  christos };
     47       1.1     skrll 
     48       1.1     skrll static int get_spec_regno (char *);
     49       1.1     skrll static int get_operands (int, char *, expressionS *);
     50       1.1     skrll static int get_putget_operands (struct mmix_opcode *, char *, expressionS *);
     51       1.1     skrll static void s_prefix (int);
     52       1.1     skrll static void s_greg (int);
     53       1.1     skrll static void s_loc (int);
     54       1.1     skrll static void s_bspec (int);
     55       1.1     skrll static void s_espec (int);
     56       1.1     skrll static void mmix_s_local (int);
     57       1.1     skrll static void mmix_greg_internal (char *);
     58       1.1     skrll static void mmix_set_geta_branch_offset (char *, offsetT);
     59       1.1     skrll static void mmix_set_jmp_offset (char *, offsetT);
     60       1.1     skrll static void mmix_fill_nops (char *, int);
     61       1.1     skrll static int cmp_greg_symbol_fixes (const void *, const void *);
     62       1.1     skrll static int cmp_greg_val_greg_symbol_fixes (const void *, const void *);
     63       1.1     skrll static void mmix_handle_rest_of_empty_line (void);
     64       1.1     skrll static void mmix_discard_rest_of_line (void);
     65       1.1     skrll static void mmix_byte (void);
     66       1.1     skrll static void mmix_cons (int);
     67       1.1     skrll 
     68       1.1     skrll /* Continue the tradition of symbols.c; use control characters to enforce
     69       1.1     skrll    magic.  These are used when replacing e.g. 8F and 8B so we can handle
     70       1.1     skrll    such labels correctly with the common parser hooks.  */
     71       1.1     skrll #define MAGIC_FB_BACKWARD_CHAR '\003'
     72       1.1     skrll #define MAGIC_FB_FORWARD_CHAR '\004'
     73       1.1     skrll 
     74       1.1     skrll /* Copy the location of a frag to a fix.  */
     75       1.1     skrll #define COPY_FR_WHERE_TO_FX(FRAG, FIX)		\
     76       1.1     skrll  do						\
     77       1.1     skrll    {						\
     78       1.1     skrll      (FIX)->fx_file = (FRAG)->fr_file;		\
     79       1.1     skrll      (FIX)->fx_line = (FRAG)->fr_line;		\
     80       1.1     skrll    }						\
     81       1.1     skrll  while (0)
     82       1.1     skrll 
     83  1.1.1.10  christos const char md_shortopts[] = "x";
     84       1.1     skrll static int current_fb_label = -1;
     85       1.1     skrll static char *pending_label = NULL;
     86       1.1     skrll 
     87       1.1     skrll static bfd_vma lowest_text_loc = (bfd_vma) -1;
     88       1.1     skrll static int text_has_contents = 0;
     89       1.1     skrll 
     90       1.1     skrll /* The alignment of the previous instruction, and a boolean for whether we
     91       1.1     skrll    want to avoid aligning the next WYDE, TETRA, OCTA or insn.  */
     92       1.1     skrll static int last_alignment = 0;
     93       1.1     skrll static int want_unaligned = 0;
     94       1.1     skrll 
     95       1.1     skrll static bfd_vma lowest_data_loc = (bfd_vma) -1;
     96       1.1     skrll static int data_has_contents = 0;
     97       1.1     skrll 
     98       1.1     skrll /* The fragS of the instruction being assembled.  Only valid from within
     99       1.1     skrll    md_assemble.  */
    100       1.1     skrll fragS *mmix_opcode_frag = NULL;
    101       1.1     skrll 
    102       1.1     skrll /* Raw GREGs as appearing in input.  These may be fewer than the number
    103       1.1     skrll    after relaxing.  */
    104       1.1     skrll static int n_of_raw_gregs = 0;
    105       1.1     skrll static struct
    106       1.1     skrll  {
    107       1.1     skrll    char *label;
    108       1.1     skrll    expressionS exp;
    109       1.1     skrll  } mmix_raw_gregs[MAX_GREGS];
    110       1.1     skrll 
    111   1.1.1.3  christos static struct loc_assert_s
    112   1.1.1.3  christos  {
    113   1.1.1.3  christos    segT old_seg;
    114   1.1.1.3  christos    symbolS *loc_sym;
    115   1.1.1.4  christos    fragS *frag;
    116   1.1.1.3  christos    struct loc_assert_s *next;
    117   1.1.1.3  christos  } *loc_asserts = NULL;
    118   1.1.1.3  christos 
    119       1.1     skrll /* Fixups for all unique GREG registers.  We store the fixups here in
    120       1.1     skrll    md_convert_frag, then we use the array to convert
    121       1.1     skrll    BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc.  The index is
    122       1.1     skrll    just a running number and is not supposed to be correlated to a
    123       1.1     skrll    register number.  */
    124       1.1     skrll static fixS *mmix_gregs[MAX_GREGS];
    125       1.1     skrll static int n_of_cooked_gregs = 0;
    126       1.1     skrll 
    127       1.1     skrll /* Pointing to the register section we use for output.  */
    128       1.1     skrll static asection *real_reg_section;
    129       1.1     skrll 
    130       1.1     skrll /* For each symbol; unknown or section symbol, we keep a list of GREG
    131       1.1     skrll    definitions sorted on increasing offset.  It seems no use keeping count
    132       1.1     skrll    to allocate less room than the maximum number of gregs when we've found
    133       1.1     skrll    one for a section or symbol.  */
    134       1.1     skrll struct mmix_symbol_gregs
    135       1.1     skrll  {
    136       1.1     skrll    int n_gregs;
    137       1.1     skrll    struct mmix_symbol_greg_fixes
    138       1.1     skrll    {
    139       1.1     skrll      fixS *fix;
    140       1.1     skrll 
    141       1.1     skrll      /* A signed type, since we may have GREGs pointing slightly before the
    142       1.1     skrll 	contents of a section.  */
    143       1.1     skrll      offsetT offs;
    144       1.1     skrll    } greg_fixes[MAX_GREGS];
    145       1.1     skrll  };
    146       1.1     skrll 
    147       1.1     skrll /* Should read insert a colon on something that starts in column 0 on
    148       1.1     skrll    this line?  */
    149       1.1     skrll static int label_without_colon_this_line = 1;
    150       1.1     skrll 
    151       1.1     skrll /* Should we automatically expand instructions into multiple insns in
    152       1.1     skrll    order to generate working code?  */
    153       1.1     skrll static int expand_op = 1;
    154       1.1     skrll 
    155       1.1     skrll /* Should we warn when expanding operands?  FIXME: test-cases for when -x
    156       1.1     skrll    is absent.  */
    157       1.1     skrll static int warn_on_expansion = 1;
    158       1.1     skrll 
    159       1.1     skrll /* Should we merge non-zero GREG register definitions?  */
    160       1.1     skrll static int merge_gregs = 1;
    161       1.1     skrll 
    162       1.1     skrll /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs
    163       1.1     skrll    (missing suitable GREG definitions) to the linker?  */
    164       1.1     skrll static int allocate_undefined_gregs_in_linker = 0;
    165       1.1     skrll 
    166       1.1     skrll /* Should we emit built-in symbols?  */
    167       1.1     skrll static int predefined_syms = 1;
    168       1.1     skrll 
    169       1.1     skrll /* Should we allow anything but the listed special register name
    170       1.1     skrll    (e.g. equated symbols)?  */
    171       1.1     skrll static int equated_spec_regs = 1;
    172       1.1     skrll 
    173       1.1     skrll /* Do we require standard GNU syntax?  */
    174       1.1     skrll int mmix_gnu_syntax = 0;
    175       1.1     skrll 
    176       1.1     skrll /* Do we globalize all symbols?  */
    177       1.1     skrll int mmix_globalize_symbols = 0;
    178       1.1     skrll 
    179       1.1     skrll /* When expanding insns, do we want to expand PUSHJ as a call to a stub
    180       1.1     skrll    (or else as a series of insns)?  */
    181       1.1     skrll int pushj_stubs = 1;
    182       1.1     skrll 
    183       1.1     skrll /* Do we know that the next semicolon is at the end of the operands field
    184       1.1     skrll    (in mmixal mode; constant 1 in GNU mode)?  */
    185       1.1     skrll int mmix_next_semicolon_is_eoln = 1;
    186       1.1     skrll 
    187       1.1     skrll /* Do we have a BSPEC in progress?  */
    188       1.1     skrll static int doing_bspec = 0;
    189   1.1.1.5  christos static const char *bspec_file;
    190       1.1     skrll static unsigned int bspec_line;
    191       1.1     skrll 
    192  1.1.1.10  christos const struct option md_longopts[] =
    193       1.1     skrll  {
    194       1.1     skrll #define OPTION_RELAX  (OPTION_MD_BASE)
    195       1.1     skrll #define OPTION_NOEXPAND  (OPTION_RELAX + 1)
    196       1.1     skrll #define OPTION_NOMERGEGREG  (OPTION_NOEXPAND + 1)
    197       1.1     skrll #define OPTION_NOSYMS  (OPTION_NOMERGEGREG + 1)
    198       1.1     skrll #define OPTION_GNU_SYNTAX  (OPTION_NOSYMS + 1)
    199       1.1     skrll #define OPTION_GLOBALIZE_SYMBOLS  (OPTION_GNU_SYNTAX + 1)
    200       1.1     skrll #define OPTION_FIXED_SPEC_REGS  (OPTION_GLOBALIZE_SYMBOLS + 1)
    201       1.1     skrll #define OPTION_LINKER_ALLOCATED_GREGS  (OPTION_FIXED_SPEC_REGS + 1)
    202       1.1     skrll #define OPTION_NOPUSHJSTUBS  (OPTION_LINKER_ALLOCATED_GREGS + 1)
    203       1.1     skrll    {"linkrelax", no_argument, NULL, OPTION_RELAX},
    204       1.1     skrll    {"no-expand", no_argument, NULL, OPTION_NOEXPAND},
    205       1.1     skrll    {"no-merge-gregs", no_argument, NULL, OPTION_NOMERGEGREG},
    206       1.1     skrll    {"no-predefined-syms", no_argument, NULL, OPTION_NOSYMS},
    207       1.1     skrll    {"gnu-syntax", no_argument, NULL, OPTION_GNU_SYNTAX},
    208       1.1     skrll    {"globalize-symbols", no_argument, NULL, OPTION_GLOBALIZE_SYMBOLS},
    209       1.1     skrll    {"fixed-special-register-names", no_argument, NULL,
    210       1.1     skrll     OPTION_FIXED_SPEC_REGS},
    211       1.1     skrll    {"linker-allocated-gregs", no_argument, NULL,
    212       1.1     skrll     OPTION_LINKER_ALLOCATED_GREGS},
    213       1.1     skrll    {"no-pushj-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS},
    214       1.1     skrll    {"no-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS},
    215       1.1     skrll    {NULL, no_argument, NULL, 0}
    216       1.1     skrll  };
    217       1.1     skrll 
    218  1.1.1.10  christos const size_t md_longopts_size = sizeof (md_longopts);
    219       1.1     skrll 
    220   1.1.1.8  christos static htab_t mmix_opcode_hash;
    221       1.1     skrll 
    222       1.1     skrll /* We use these when implementing the PREFIX pseudo.  */
    223       1.1     skrll char *mmix_current_prefix;
    224       1.1     skrll struct obstack mmix_sym_obstack;
    225       1.1     skrll 
    226       1.1     skrll 
    227       1.1     skrll /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
    228       1.1     skrll    bit length, and the relax-type shifted on top of that.  There seems to
    229       1.1     skrll    be no point in making the relaxation more fine-grained; the linker does
    230       1.1     skrll    that better and we might interfere by changing non-optimal relaxations
    231       1.1     skrll    into other insns that cannot be relaxed as easily.
    232       1.1     skrll 
    233       1.1     skrll    Groups for MMIX relaxing:
    234       1.1     skrll 
    235       1.1     skrll    1. GETA
    236       1.1     skrll       extra length: zero or three insns.
    237       1.1     skrll 
    238       1.1     skrll    2. Bcc
    239       1.1     skrll       extra length: zero or five insns.
    240       1.1     skrll 
    241       1.1     skrll    3. PUSHJ
    242       1.1     skrll       extra length: zero or four insns.
    243       1.1     skrll       Special handling to deal with transition to PUSHJSTUB.
    244       1.1     skrll 
    245       1.1     skrll    4. JMP
    246       1.1     skrll       extra length: zero or four insns.
    247       1.1     skrll 
    248       1.1     skrll    5. GREG
    249       1.1     skrll       special handling, allocates a named global register unless another
    250       1.1     skrll       is within reach for all uses.
    251       1.1     skrll 
    252       1.1     skrll    6. PUSHJSTUB
    253       1.1     skrll       special handling (mostly) for external references; assumes the
    254       1.1     skrll       linker will generate a stub if target is no longer than 256k from
    255       1.1     skrll       the end of the section plus max size of previous stubs.  Zero or
    256       1.1     skrll       four insns.  */
    257       1.1     skrll 
    258       1.1     skrll #define STATE_GETA	(1)
    259       1.1     skrll #define STATE_BCC	(2)
    260       1.1     skrll #define STATE_PUSHJ	(3)
    261       1.1     skrll #define STATE_JMP	(4)
    262       1.1     skrll #define STATE_GREG	(5)
    263       1.1     skrll #define STATE_PUSHJSTUB	(6)
    264       1.1     skrll 
    265       1.1     skrll /* No fine-grainedness here.  */
    266       1.1     skrll #define STATE_LENGTH_MASK	    (1)
    267       1.1     skrll 
    268       1.1     skrll #define STATE_ZERO		    (0)
    269       1.1     skrll #define STATE_MAX		    (1)
    270       1.1     skrll 
    271       1.1     skrll /* More descriptive name for convenience.  */
    272       1.1     skrll /* FIXME: We should start on something different, not MAX.  */
    273       1.1     skrll #define STATE_UNDF		    STATE_MAX
    274       1.1     skrll 
    275       1.1     skrll /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
    276       1.1     skrll    appropriate; we need it the other way round.  This value together with
    277       1.1     skrll    fragP->tc_frag_data shows what state the frag is in: tc_frag_data
    278       1.1     skrll    non-NULL means 0, NULL means 8 bytes.  */
    279       1.1     skrll #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
    280       1.1     skrll #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
    281       1.1     skrll 
    282       1.1     skrll /* These displacements are relative to the address following the opcode
    283       1.1     skrll    word of the instruction.  The catch-all states have zero for "reach"
    284       1.1     skrll    and "next" entries.  */
    285       1.1     skrll 
    286       1.1     skrll #define GETA_0F (65536 * 4 - 8)
    287       1.1     skrll #define GETA_0B (-65536 * 4 - 4)
    288       1.1     skrll 
    289       1.1     skrll #define GETA_MAX_LEN 4 * 4
    290       1.1     skrll #define GETA_3F 0
    291       1.1     skrll #define GETA_3B 0
    292       1.1     skrll 
    293       1.1     skrll #define BCC_0F GETA_0F
    294       1.1     skrll #define BCC_0B GETA_0B
    295       1.1     skrll 
    296       1.1     skrll #define BCC_MAX_LEN 6 * 4
    297       1.1     skrll #define BCC_5F GETA_3F
    298       1.1     skrll #define BCC_5B GETA_3B
    299       1.1     skrll 
    300       1.1     skrll #define PUSHJ_0F GETA_0F
    301       1.1     skrll #define PUSHJ_0B GETA_0B
    302       1.1     skrll 
    303       1.1     skrll #define PUSHJ_MAX_LEN 5 * 4
    304       1.1     skrll #define PUSHJ_4F GETA_3F
    305       1.1     skrll #define PUSHJ_4B GETA_3B
    306       1.1     skrll 
    307       1.1     skrll /* We'll very rarely have sections longer than LONG_MAX, but we'll make a
    308       1.1     skrll    feeble attempt at getting 64-bit values.  */
    309       1.1     skrll #define PUSHJSTUB_MAX ((offsetT) (((addressT) -1) >> 1))
    310       1.1     skrll #define PUSHJSTUB_MIN (-PUSHJSTUB_MAX - 1)
    311       1.1     skrll 
    312       1.1     skrll #define JMP_0F (65536 * 256 * 4 - 8)
    313       1.1     skrll #define JMP_0B (-65536 * 256 * 4 - 4)
    314       1.1     skrll 
    315       1.1     skrll #define JMP_MAX_LEN 5 * 4
    316       1.1     skrll #define JMP_4F 0
    317       1.1     skrll #define JMP_4B 0
    318       1.1     skrll 
    319       1.1     skrll #define RELAX_ENCODE_SHIFT 1
    320       1.1     skrll #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
    321       1.1     skrll 
    322       1.1     skrll const relax_typeS mmix_relax_table[] =
    323       1.1     skrll  {
    324       1.1     skrll    /* Error sentinel (0, 0).  */
    325       1.1     skrll    {1,		1,		0,	0},
    326       1.1     skrll 
    327       1.1     skrll    /* Unused (0, 1).  */
    328       1.1     skrll    {1,		1,		0,	0},
    329       1.1     skrll 
    330       1.1     skrll    /* GETA (1, 0).  */
    331       1.1     skrll    {GETA_0F,	GETA_0B,	0,	ENCODE_RELAX (STATE_GETA, STATE_MAX)},
    332       1.1     skrll 
    333       1.1     skrll    /* GETA (1, 1).  */
    334       1.1     skrll    {GETA_3F,	GETA_3B,
    335       1.1     skrll 		GETA_MAX_LEN - 4,	0},
    336       1.1     skrll 
    337       1.1     skrll    /* BCC (2, 0).  */
    338       1.1     skrll    {BCC_0F,	BCC_0B,		0,	ENCODE_RELAX (STATE_BCC, STATE_MAX)},
    339       1.1     skrll 
    340       1.1     skrll    /* BCC (2, 1).  */
    341       1.1     skrll    {BCC_5F,	BCC_5B,
    342       1.1     skrll 		BCC_MAX_LEN - 4,	0},
    343       1.1     skrll 
    344       1.1     skrll    /* PUSHJ (3, 0).  Next state is actually PUSHJSTUB (6, 0).  */
    345       1.1     skrll    {PUSHJ_0F,	PUSHJ_0B,	0,	ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO)},
    346       1.1     skrll 
    347       1.1     skrll    /* PUSHJ (3, 1).  */
    348       1.1     skrll    {PUSHJ_4F,	PUSHJ_4B,
    349       1.1     skrll 		PUSHJ_MAX_LEN - 4,	0},
    350       1.1     skrll 
    351       1.1     skrll    /* JMP (4, 0).  */
    352       1.1     skrll    {JMP_0F,	JMP_0B,		0,	ENCODE_RELAX (STATE_JMP, STATE_MAX)},
    353       1.1     skrll 
    354       1.1     skrll    /* JMP (4, 1).  */
    355       1.1     skrll    {JMP_4F,	JMP_4B,
    356       1.1     skrll 		JMP_MAX_LEN - 4,	0},
    357       1.1     skrll 
    358       1.1     skrll    /* GREG (5, 0), (5, 1), though the table entry isn't used.  */
    359       1.1     skrll    {0, 0, 0, 0}, {0, 0, 0, 0},
    360       1.1     skrll 
    361       1.1     skrll    /* PUSHJSTUB (6, 0).  PUSHJ (3, 0) uses the range, so we set it to infinite.  */
    362       1.1     skrll    {PUSHJSTUB_MAX, PUSHJSTUB_MIN,
    363       1.1     skrll     		0,			ENCODE_RELAX (STATE_PUSHJ, STATE_MAX)},
    364       1.1     skrll    /* PUSHJSTUB (6, 1) isn't used.  */
    365       1.1     skrll    {0, 0,	PUSHJ_MAX_LEN, 		0}
    366       1.1     skrll };
    367       1.1     skrll 
    368       1.1     skrll const pseudo_typeS md_pseudo_table[] =
    369       1.1     skrll  {
    370       1.1     skrll    /* Support " .greg sym,expr" syntax.  */
    371       1.1     skrll    {"greg", s_greg, 0},
    372       1.1     skrll 
    373       1.1     skrll    /* Support " .bspec expr" syntax.  */
    374       1.1     skrll    {"bspec", s_bspec, 1},
    375       1.1     skrll 
    376       1.1     skrll    /* Support " .espec" syntax.  */
    377       1.1     skrll    {"espec", s_espec, 1},
    378       1.1     skrll 
    379       1.1     skrll    /* Support " .local $45" syntax.  */
    380       1.1     skrll    {"local", mmix_s_local, 1},
    381       1.1     skrll 
    382       1.1     skrll    {NULL, 0, 0}
    383       1.1     skrll  };
    384       1.1     skrll 
    385  1.1.1.10  christos const char comment_chars[] = "%!";
    386       1.1     skrll 
    387       1.1     skrll /* A ':' is a valid symbol character in mmixal.  It's the prefix
    388       1.1     skrll    delimiter, but other than that, it works like a symbol character,
    389       1.1     skrll    except that we strip one off at the beginning of symbols.  An '@' is a
    390       1.1     skrll    symbol by itself (for the current location); space around it must not
    391       1.1     skrll    be stripped.  */
    392       1.1     skrll const char mmix_symbol_chars[] = ":@";
    393       1.1     skrll 
    394       1.1     skrll const char line_comment_chars[] = "*#";
    395       1.1     skrll 
    396       1.1     skrll const char line_separator_chars[] = ";";
    397       1.1     skrll 
    398   1.1.1.5  christos const char EXP_CHARS[] = "eE";
    399       1.1     skrll 
    400   1.1.1.5  christos const char FLT_CHARS[] = "rf";
    401       1.1     skrll 
    402       1.1     skrll 
    403       1.1     skrll /* Fill in the offset-related part of GETA or Bcc.  */
    404       1.1     skrll 
    405       1.1     skrll static void
    406       1.1     skrll mmix_set_geta_branch_offset (char *opcodep, offsetT value)
    407       1.1     skrll {
    408       1.1     skrll   if (value < 0)
    409       1.1     skrll     {
    410       1.1     skrll       value += 65536 * 4;
    411       1.1     skrll       opcodep[0] |= 1;
    412       1.1     skrll     }
    413       1.1     skrll 
    414       1.1     skrll   value /= 4;
    415       1.1     skrll   md_number_to_chars (opcodep + 2, value, 2);
    416       1.1     skrll }
    417       1.1     skrll 
    418       1.1     skrll /* Fill in the offset-related part of JMP.  */
    419       1.1     skrll 
    420       1.1     skrll static void
    421       1.1     skrll mmix_set_jmp_offset (char *opcodep, offsetT value)
    422       1.1     skrll {
    423       1.1     skrll   if (value < 0)
    424       1.1     skrll     {
    425       1.1     skrll       value += 65536 * 256 * 4;
    426       1.1     skrll       opcodep[0] |= 1;
    427       1.1     skrll     }
    428       1.1     skrll 
    429       1.1     skrll   value /= 4;
    430       1.1     skrll   md_number_to_chars (opcodep + 1, value, 3);
    431       1.1     skrll }
    432       1.1     skrll 
    433       1.1     skrll /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ.  */
    434       1.1     skrll 
    435       1.1     skrll static void
    436       1.1     skrll mmix_fill_nops (char *opcodep, int n)
    437       1.1     skrll {
    438       1.1     skrll   int i;
    439       1.1     skrll 
    440       1.1     skrll   for (i = 0; i < n; i++)
    441       1.1     skrll     md_number_to_chars (opcodep + i * 4, SWYM_INSN_BYTE << 24, 4);
    442       1.1     skrll }
    443       1.1     skrll 
    444       1.1     skrll /* Get up to three operands, filling them into the exp array.
    445       1.1     skrll    General idea and code stolen from the tic80 port.  */
    446       1.1     skrll 
    447       1.1     skrll static int
    448       1.1     skrll get_operands (int max_operands, char *s, expressionS *exp)
    449       1.1     skrll {
    450       1.1     skrll   char *p = s;
    451       1.1     skrll   int numexp = 0;
    452       1.1     skrll   int nextchar = ',';
    453       1.1     skrll 
    454       1.1     skrll   while (nextchar == ',')
    455       1.1     skrll     {
    456       1.1     skrll       /* Skip leading whitespace */
    457  1.1.1.10  christos       while (is_whitespace (*p))
    458       1.1     skrll 	p++;
    459       1.1     skrll 
    460       1.1     skrll       /* Check to see if we have any operands left to parse */
    461  1.1.1.10  christos       if (is_end_of_stmt (*p))
    462       1.1     skrll 	{
    463       1.1     skrll 	  break;
    464       1.1     skrll 	}
    465       1.1     skrll       else if (numexp == max_operands)
    466       1.1     skrll 	{
    467       1.1     skrll 	  /* This seems more sane than saying "too many operands".  We'll
    468       1.1     skrll 	     get here only if the trailing trash starts with a comma.  */
    469       1.1     skrll 	  as_bad (_("invalid operands"));
    470       1.1     skrll 	  mmix_discard_rest_of_line ();
    471       1.1     skrll 	  return 0;
    472       1.1     skrll 	}
    473       1.1     skrll 
    474       1.1     skrll       /* Begin operand parsing at the current scan point.  */
    475       1.1     skrll 
    476       1.1     skrll       input_line_pointer = p;
    477       1.1     skrll       expression (&exp[numexp]);
    478       1.1     skrll 
    479       1.1     skrll       if (exp[numexp].X_op == O_illegal)
    480       1.1     skrll 	{
    481       1.1     skrll 	  as_bad (_("invalid operands"));
    482       1.1     skrll 	}
    483       1.1     skrll       else if (exp[numexp].X_op == O_absent)
    484       1.1     skrll 	{
    485       1.1     skrll 	  as_bad (_("missing operand"));
    486       1.1     skrll 	}
    487       1.1     skrll 
    488       1.1     skrll       numexp++;
    489       1.1     skrll       p = input_line_pointer;
    490       1.1     skrll 
    491       1.1     skrll       /* Skip leading whitespace */
    492  1.1.1.10  christos       while (is_whitespace (*p))
    493       1.1     skrll 	p++;
    494       1.1     skrll       nextchar = *p++;
    495       1.1     skrll     }
    496       1.1     skrll 
    497       1.1     skrll   /* If we allow "naked" comments, ignore the rest of the line.  */
    498       1.1     skrll   if (nextchar != ',')
    499       1.1     skrll     {
    500       1.1     skrll       mmix_handle_rest_of_empty_line ();
    501       1.1     skrll       input_line_pointer--;
    502       1.1     skrll     }
    503       1.1     skrll 
    504       1.1     skrll   /* Mark the end of the valid operands with an illegal expression.  */
    505       1.1     skrll   exp[numexp].X_op = O_illegal;
    506       1.1     skrll 
    507  1.1.1.10  christos   return numexp;
    508       1.1     skrll }
    509       1.1     skrll 
    510       1.1     skrll /* Get the value of a special register, or -1 if the name does not match
    511       1.1     skrll    one.  NAME is a null-terminated string.  */
    512       1.1     skrll 
    513       1.1     skrll static int
    514       1.1     skrll get_spec_regno (char *name)
    515       1.1     skrll {
    516       1.1     skrll   int i;
    517       1.1     skrll 
    518       1.1     skrll   if (name == NULL)
    519       1.1     skrll     return -1;
    520       1.1     skrll 
    521       1.1     skrll   if (*name == ':')
    522       1.1     skrll     name++;
    523       1.1     skrll 
    524       1.1     skrll   /* Well, it's a short array and we'll most often just match the first
    525       1.1     skrll      entry, rJ.  */
    526       1.1     skrll   for (i = 0; mmix_spec_regs[i].name != NULL; i++)
    527       1.1     skrll     if (strcmp (name, mmix_spec_regs[i].name) == 0)
    528       1.1     skrll       return mmix_spec_regs[i].number;
    529       1.1     skrll 
    530       1.1     skrll   return -1;
    531       1.1     skrll }
    532       1.1     skrll 
    533       1.1     skrll /* For GET and PUT, parse the register names "manually", so we don't use
    534       1.1     skrll    user labels.  */
    535       1.1     skrll static int
    536       1.1     skrll get_putget_operands (struct mmix_opcode *insn, char *operands,
    537       1.1     skrll 		     expressionS *exp)
    538       1.1     skrll {
    539       1.1     skrll   expressionS *expp_reg;
    540       1.1     skrll   expressionS *expp_sreg;
    541       1.1     skrll   char *sregp = NULL;
    542       1.1     skrll   char *sregend = operands;
    543       1.1     skrll   char *p = operands;
    544       1.1     skrll   char c = *sregend;
    545       1.1     skrll   int regno;
    546       1.1     skrll 
    547       1.1     skrll   /* Skip leading whitespace */
    548  1.1.1.10  christos   while (is_whitespace (*p))
    549       1.1     skrll     p++;
    550       1.1     skrll 
    551       1.1     skrll   input_line_pointer = p;
    552       1.1     skrll 
    553       1.1     skrll   /* Initialize both possible operands to error state, in case we never
    554       1.1     skrll      get further.  */
    555       1.1     skrll   exp[0].X_op = O_illegal;
    556       1.1     skrll   exp[1].X_op = O_illegal;
    557       1.1     skrll 
    558       1.1     skrll   if (insn->operands == mmix_operands_get)
    559       1.1     skrll     {
    560       1.1     skrll       expp_reg = &exp[0];
    561       1.1     skrll       expp_sreg = &exp[1];
    562       1.1     skrll 
    563       1.1     skrll       expression (expp_reg);
    564       1.1     skrll 
    565       1.1     skrll       p = input_line_pointer;
    566       1.1     skrll 
    567       1.1     skrll       /* Skip whitespace */
    568  1.1.1.10  christos       while (is_whitespace (*p))
    569       1.1     skrll 	p++;
    570       1.1     skrll 
    571       1.1     skrll       if (*p == ',')
    572       1.1     skrll 	{
    573       1.1     skrll 	  p++;
    574       1.1     skrll 
    575       1.1     skrll 	  /* Skip whitespace */
    576  1.1.1.10  christos 	  while (is_whitespace (*p))
    577       1.1     skrll 	    p++;
    578       1.1     skrll 	  sregp = p;
    579       1.1     skrll 	  input_line_pointer = sregp;
    580   1.1.1.4  christos 	  c = get_symbol_name (&sregp);
    581       1.1     skrll 	  sregend = input_line_pointer;
    582   1.1.1.4  christos 	  if (c == '"')
    583   1.1.1.4  christos 	    ++ input_line_pointer;
    584       1.1     skrll 	}
    585       1.1     skrll     }
    586       1.1     skrll   else
    587       1.1     skrll     {
    588       1.1     skrll       expp_sreg = &exp[0];
    589       1.1     skrll       expp_reg = &exp[1];
    590       1.1     skrll 
    591   1.1.1.4  christos       c = get_symbol_name (&sregp);
    592   1.1.1.4  christos       sregend = input_line_pointer;
    593   1.1.1.4  christos       restore_line_pointer (c);
    594   1.1.1.4  christos       p = input_line_pointer;
    595       1.1     skrll 
    596       1.1     skrll       /* Skip whitespace */
    597  1.1.1.10  christos       while (is_whitespace (*p))
    598       1.1     skrll 	p++;
    599       1.1     skrll 
    600       1.1     skrll       if (*p == ',')
    601       1.1     skrll 	{
    602       1.1     skrll 	  p++;
    603       1.1     skrll 
    604       1.1     skrll 	  /* Skip whitespace */
    605  1.1.1.10  christos 	  while (is_whitespace (*p))
    606       1.1     skrll 	    p++;
    607       1.1     skrll 
    608       1.1     skrll 	  input_line_pointer = p;
    609       1.1     skrll 	  expression (expp_reg);
    610       1.1     skrll 	}
    611       1.1     skrll       *sregend = 0;
    612       1.1     skrll     }
    613       1.1     skrll 
    614       1.1     skrll   regno = get_spec_regno (sregp);
    615       1.1     skrll   *sregend = c;
    616       1.1     skrll 
    617   1.1.1.9  christos   resolve_register (expp_reg);
    618   1.1.1.9  christos 
    619       1.1     skrll   /* Let the caller issue errors; we've made sure the operands are
    620       1.1     skrll      invalid.  */
    621       1.1     skrll   if (expp_reg->X_op != O_illegal
    622       1.1     skrll       && expp_reg->X_op != O_absent
    623       1.1     skrll       && regno != -1)
    624       1.1     skrll     {
    625       1.1     skrll       expp_sreg->X_op = O_register;
    626       1.1     skrll       expp_sreg->X_add_number = regno + 256;
    627       1.1     skrll     }
    628       1.1     skrll 
    629       1.1     skrll   return 2;
    630       1.1     skrll }
    631       1.1     skrll 
    632       1.1     skrll /* Handle MMIX-specific option.  */
    633       1.1     skrll 
    634       1.1     skrll int
    635   1.1.1.5  christos md_parse_option (int c, const char *arg ATTRIBUTE_UNUSED)
    636       1.1     skrll {
    637       1.1     skrll   switch (c)
    638       1.1     skrll     {
    639       1.1     skrll     case 'x':
    640       1.1     skrll       warn_on_expansion = 0;
    641       1.1     skrll       allocate_undefined_gregs_in_linker = 1;
    642       1.1     skrll       break;
    643       1.1     skrll 
    644       1.1     skrll     case OPTION_RELAX:
    645       1.1     skrll       linkrelax = 1;
    646       1.1     skrll       break;
    647       1.1     skrll 
    648       1.1     skrll     case OPTION_NOEXPAND:
    649       1.1     skrll       expand_op = 0;
    650       1.1     skrll       break;
    651       1.1     skrll 
    652       1.1     skrll     case OPTION_NOMERGEGREG:
    653       1.1     skrll       merge_gregs = 0;
    654       1.1     skrll       break;
    655       1.1     skrll 
    656       1.1     skrll     case OPTION_NOSYMS:
    657       1.1     skrll       predefined_syms = 0;
    658       1.1     skrll       equated_spec_regs = 0;
    659       1.1     skrll       break;
    660       1.1     skrll 
    661       1.1     skrll     case OPTION_GNU_SYNTAX:
    662       1.1     skrll       mmix_gnu_syntax = 1;
    663       1.1     skrll       label_without_colon_this_line = 0;
    664       1.1     skrll       break;
    665       1.1     skrll 
    666       1.1     skrll     case OPTION_GLOBALIZE_SYMBOLS:
    667       1.1     skrll       mmix_globalize_symbols = 1;
    668       1.1     skrll       break;
    669       1.1     skrll 
    670       1.1     skrll     case OPTION_FIXED_SPEC_REGS:
    671       1.1     skrll       equated_spec_regs = 0;
    672       1.1     skrll       break;
    673       1.1     skrll 
    674       1.1     skrll     case OPTION_LINKER_ALLOCATED_GREGS:
    675       1.1     skrll       allocate_undefined_gregs_in_linker = 1;
    676       1.1     skrll       break;
    677       1.1     skrll 
    678       1.1     skrll     case OPTION_NOPUSHJSTUBS:
    679       1.1     skrll       pushj_stubs = 0;
    680       1.1     skrll       break;
    681       1.1     skrll 
    682       1.1     skrll     default:
    683       1.1     skrll       return 0;
    684       1.1     skrll     }
    685       1.1     skrll 
    686       1.1     skrll   return 1;
    687       1.1     skrll }
    688       1.1     skrll 
    689       1.1     skrll /* Display MMIX-specific help text.  */
    690       1.1     skrll 
    691       1.1     skrll void
    692       1.1     skrll md_show_usage (FILE * stream)
    693       1.1     skrll {
    694       1.1     skrll   fprintf (stream, _(" MMIX-specific command line options:\n"));
    695       1.1     skrll   fprintf (stream, _("\
    696       1.1     skrll   -fixed-special-register-names\n\
    697       1.1     skrll                           Allow only the original special register names.\n"));
    698       1.1     skrll   fprintf (stream, _("\
    699       1.1     skrll   -globalize-symbols      Make all symbols global.\n"));
    700       1.1     skrll   fprintf (stream, _("\
    701       1.1     skrll   -gnu-syntax             Turn off mmixal syntax compatibility.\n"));
    702       1.1     skrll   fprintf (stream, _("\
    703       1.1     skrll   -relax                  Create linker relaxable code.\n"));
    704       1.1     skrll   fprintf (stream, _("\
    705       1.1     skrll   -no-predefined-syms     Do not provide mmixal built-in constants.\n\
    706       1.1     skrll                           Implies -fixed-special-register-names.\n"));
    707       1.1     skrll   fprintf (stream, _("\
    708       1.1     skrll   -no-expand              Do not expand GETA, branches, PUSHJ or JUMP\n\
    709       1.1     skrll                           into multiple instructions.\n"));
    710       1.1     skrll   fprintf (stream, _("\
    711       1.1     skrll   -no-merge-gregs         Do not merge GREG definitions with nearby values.\n"));
    712       1.1     skrll   fprintf (stream, _("\
    713       1.1     skrll   -linker-allocated-gregs If there's no suitable GREG definition for the\
    714       1.1     skrll                           operands of an instruction, let the linker resolve.\n"));
    715       1.1     skrll   fprintf (stream, _("\
    716       1.1     skrll   -x                      Do not warn when an operand to GETA, a branch,\n\
    717       1.1     skrll                           PUSHJ or JUMP is not known to be within range.\n\
    718       1.1     skrll                           The linker will catch any errors.  Implies\n\
    719       1.1     skrll                           -linker-allocated-gregs."));
    720       1.1     skrll }
    721       1.1     skrll 
    722       1.1     skrll /* Step to end of line, but don't step over the end of the line.  */
    723       1.1     skrll 
    724       1.1     skrll static void
    725       1.1     skrll mmix_discard_rest_of_line (void)
    726       1.1     skrll {
    727       1.1     skrll   while (*input_line_pointer
    728  1.1.1.10  christos 	 && (! is_end_of_stmt (*input_line_pointer)
    729       1.1     skrll 	     || TC_EOL_IN_INSN (input_line_pointer)))
    730       1.1     skrll     input_line_pointer++;
    731       1.1     skrll }
    732       1.1     skrll 
    733       1.1     skrll /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
    734       1.1     skrll    otherwise just ignore the rest of the line (and skip the end-of-line
    735       1.1     skrll    delimiter).  */
    736       1.1     skrll 
    737       1.1     skrll static void
    738       1.1     skrll mmix_handle_rest_of_empty_line (void)
    739       1.1     skrll {
    740       1.1     skrll   if (mmix_gnu_syntax)
    741       1.1     skrll     demand_empty_rest_of_line ();
    742       1.1     skrll   else
    743       1.1     skrll     {
    744       1.1     skrll       mmix_discard_rest_of_line ();
    745       1.1     skrll       input_line_pointer++;
    746       1.1     skrll     }
    747       1.1     skrll }
    748       1.1     skrll 
    749       1.1     skrll /* Initialize GAS MMIX specifics.  */
    750       1.1     skrll 
    751       1.1     skrll void
    752       1.1     skrll mmix_md_begin (void)
    753       1.1     skrll {
    754       1.1     skrll   int i;
    755       1.1     skrll   const struct mmix_opcode *opcode;
    756       1.1     skrll 
    757       1.1     skrll   /* We assume nobody will use this, so don't allocate any room.  */
    758       1.1     skrll   obstack_begin (&mmix_sym_obstack, 0);
    759       1.1     skrll 
    760       1.1     skrll   /* This will break the day the "lex" thingy changes.  For now, it's the
    761       1.1     skrll      only way to make ':' part of a name, and a name beginner.  */
    762       1.1     skrll   lex_type[':'] = (LEX_NAME | LEX_BEGIN_NAME);
    763       1.1     skrll 
    764   1.1.1.8  christos   mmix_opcode_hash = str_htab_create ();
    765       1.1     skrll 
    766       1.1     skrll   real_reg_section
    767       1.1     skrll     = bfd_make_section_old_way (stdoutput, MMIX_REG_SECTION_NAME);
    768       1.1     skrll 
    769       1.1     skrll   for (opcode = mmix_opcodes; opcode->name; opcode++)
    770   1.1.1.8  christos     str_hash_insert (mmix_opcode_hash, opcode->name, opcode, 0);
    771       1.1     skrll 
    772       1.1     skrll   /* We always insert the ordinary registers 0..255 as registers.  */
    773       1.1     skrll   for (i = 0; i < 256; i++)
    774       1.1     skrll     {
    775   1.1.1.8  christos       char buf[16];
    776       1.1     skrll 
    777       1.1     skrll       /* Alternatively, we could diddle with '$' and the following number,
    778       1.1     skrll 	 but keeping the registers as symbols helps keep parsing simple.  */
    779       1.1     skrll       sprintf (buf, "$%d", i);
    780   1.1.1.8  christos       symbol_table_insert (symbol_new (buf, reg_section,
    781   1.1.1.8  christos 				       &zero_address_frag, i));
    782       1.1     skrll     }
    783       1.1     skrll 
    784       1.1     skrll   /* Insert mmixal built-in names if allowed.  */
    785       1.1     skrll   if (predefined_syms)
    786       1.1     skrll     {
    787       1.1     skrll       for (i = 0; mmix_spec_regs[i].name != NULL; i++)
    788       1.1     skrll 	symbol_table_insert (symbol_new (mmix_spec_regs[i].name,
    789       1.1     skrll 					 reg_section,
    790   1.1.1.8  christos 					 &zero_address_frag,
    791   1.1.1.8  christos 					 mmix_spec_regs[i].number + 256));
    792       1.1     skrll 
    793       1.1     skrll       /* FIXME: Perhaps these should be recognized as specials; as field
    794       1.1     skrll 	 names for those instructions.  */
    795   1.1.1.8  christos       symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section,
    796   1.1.1.8  christos 				       &zero_address_frag, 512));
    797   1.1.1.8  christos       symbol_table_insert (symbol_new ("ROUND_OFF", reg_section,
    798   1.1.1.8  christos 				       &zero_address_frag, 512 + 1));
    799   1.1.1.8  christos       symbol_table_insert (symbol_new ("ROUND_UP", reg_section,
    800   1.1.1.8  christos 				       &zero_address_frag, 512 + 2));
    801   1.1.1.8  christos       symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section,
    802   1.1.1.8  christos 				       &zero_address_frag, 512 + 3));
    803   1.1.1.8  christos       symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section,
    804   1.1.1.8  christos 				       &zero_address_frag, 512 + 4));
    805       1.1     skrll     }
    806       1.1     skrll }
    807       1.1     skrll 
    808       1.1     skrll /* Assemble one insn in STR.  */
    809       1.1     skrll 
    810       1.1     skrll void
    811       1.1     skrll md_assemble (char *str)
    812       1.1     skrll {
    813       1.1     skrll   char *operands = str;
    814       1.1     skrll   char modified_char = 0;
    815       1.1     skrll   struct mmix_opcode *instruction;
    816       1.1     skrll   fragS *opc_fragP = NULL;
    817       1.1     skrll   int max_operands = 3;
    818       1.1     skrll 
    819       1.1     skrll   /* Note that the struct frag member fr_literal in frags.h is char[], so
    820       1.1     skrll      I have to make this a plain char *.  */
    821       1.1     skrll   /* unsigned */ char *opcodep = NULL;
    822       1.1     skrll 
    823       1.1     skrll   expressionS exp[4];
    824       1.1     skrll   int n_operands = 0;
    825       1.1     skrll 
    826       1.1     skrll   /* Move to end of opcode.  */
    827       1.1     skrll   for (operands = str;
    828       1.1     skrll        is_part_of_name (*operands);
    829       1.1     skrll        ++operands)
    830       1.1     skrll     ;
    831       1.1     skrll 
    832  1.1.1.10  christos   if (is_whitespace (*operands))
    833       1.1     skrll     {
    834       1.1     skrll       modified_char = *operands;
    835       1.1     skrll       *operands++ = '\0';
    836       1.1     skrll     }
    837       1.1     skrll 
    838  1.1.1.10  christos   instruction = str_hash_find (mmix_opcode_hash, str);
    839       1.1     skrll   if (instruction == NULL)
    840       1.1     skrll     {
    841       1.1     skrll       as_bad (_("unknown opcode: `%s'"), str);
    842       1.1     skrll 
    843       1.1     skrll       /* Avoid "unhandled label" errors.  */
    844       1.1     skrll       pending_label = NULL;
    845       1.1     skrll       return;
    846       1.1     skrll     }
    847       1.1     skrll 
    848       1.1     skrll   /* Put back the character after the opcode.  */
    849       1.1     skrll   if (modified_char != 0)
    850       1.1     skrll     operands[-1] = modified_char;
    851       1.1     skrll 
    852       1.1     skrll   input_line_pointer = operands;
    853       1.1     skrll 
    854       1.1     skrll   /* Is this a mmixal pseudodirective?  */
    855       1.1     skrll   if (instruction->type == mmix_type_pseudo)
    856       1.1     skrll     {
    857       1.1     skrll       /* For mmixal compatibility, a label for an instruction (and
    858       1.1     skrll 	 emitting pseudo) refers to the _aligned_ address.  We emit the
    859       1.1     skrll 	 label here for the pseudos that don't handle it themselves.  When
    860       1.1     skrll 	 having an fb-label, emit it here, and increment the counter after
    861       1.1     skrll 	 the pseudo.  */
    862       1.1     skrll       switch (instruction->operands)
    863       1.1     skrll 	{
    864       1.1     skrll 	case mmix_operands_loc:
    865       1.1     skrll 	case mmix_operands_byte:
    866       1.1     skrll 	case mmix_operands_prefix:
    867       1.1     skrll 	case mmix_operands_local:
    868       1.1     skrll 	case mmix_operands_bspec:
    869       1.1     skrll 	case mmix_operands_espec:
    870       1.1     skrll 	  if (current_fb_label >= 0)
    871       1.1     skrll 	    colon (fb_label_name (current_fb_label, 1));
    872       1.1     skrll 	  else if (pending_label != NULL)
    873       1.1     skrll 	    {
    874       1.1     skrll 	      colon (pending_label);
    875       1.1     skrll 	      pending_label = NULL;
    876       1.1     skrll 	    }
    877       1.1     skrll 	  break;
    878       1.1     skrll 
    879       1.1     skrll 	default:
    880       1.1     skrll 	  break;
    881       1.1     skrll 	}
    882       1.1     skrll 
    883       1.1     skrll       /* Some of the pseudos emit contents, others don't.  Set a
    884       1.1     skrll 	 contents-emitted flag when we emit something into .text   */
    885       1.1     skrll       switch (instruction->operands)
    886       1.1     skrll 	{
    887       1.1     skrll 	case mmix_operands_loc:
    888       1.1     skrll 	  /* LOC */
    889       1.1     skrll 	  s_loc (0);
    890       1.1     skrll 	  break;
    891       1.1     skrll 
    892       1.1     skrll 	case mmix_operands_byte:
    893       1.1     skrll 	  /* BYTE */
    894       1.1     skrll 	  mmix_byte ();
    895       1.1     skrll 	  break;
    896       1.1     skrll 
    897       1.1     skrll 	case mmix_operands_wyde:
    898       1.1     skrll 	  /* WYDE */
    899       1.1     skrll 	  mmix_cons (2);
    900       1.1     skrll 	  break;
    901       1.1     skrll 
    902       1.1     skrll 	case mmix_operands_tetra:
    903       1.1     skrll 	  /* TETRA */
    904       1.1     skrll 	  mmix_cons (4);
    905       1.1     skrll 	  break;
    906       1.1     skrll 
    907       1.1     skrll 	case mmix_operands_octa:
    908       1.1     skrll 	  /* OCTA */
    909       1.1     skrll 	  mmix_cons (8);
    910       1.1     skrll 	  break;
    911       1.1     skrll 
    912       1.1     skrll 	case mmix_operands_prefix:
    913       1.1     skrll 	  /* PREFIX */
    914       1.1     skrll 	  s_prefix (0);
    915       1.1     skrll 	  break;
    916       1.1     skrll 
    917       1.1     skrll 	case mmix_operands_local:
    918       1.1     skrll 	  /* LOCAL */
    919       1.1     skrll 	  mmix_s_local (0);
    920       1.1     skrll 	  break;
    921       1.1     skrll 
    922       1.1     skrll 	case mmix_operands_bspec:
    923       1.1     skrll 	  /* BSPEC */
    924       1.1     skrll 	  s_bspec (0);
    925       1.1     skrll 	  break;
    926       1.1     skrll 
    927       1.1     skrll 	case mmix_operands_espec:
    928       1.1     skrll 	  /* ESPEC */
    929       1.1     skrll 	  s_espec (0);
    930       1.1     skrll 	  break;
    931       1.1     skrll 
    932       1.1     skrll 	default:
    933       1.1     skrll 	  BAD_CASE (instruction->operands);
    934       1.1     skrll 	}
    935       1.1     skrll 
    936       1.1     skrll       /* These are all working like the pseudo functions in read.c:s_...,
    937       1.1     skrll 	 in that they step over the end-of-line marker at the end of the
    938       1.1     skrll 	 line.  We don't want that here.  */
    939       1.1     skrll       input_line_pointer--;
    940       1.1     skrll 
    941       1.1     skrll       /* Step up the fb-label counter if there was a definition on this
    942       1.1     skrll 	 line.  */
    943       1.1     skrll       if (current_fb_label >= 0)
    944       1.1     skrll 	{
    945       1.1     skrll 	  fb_label_instance_inc (current_fb_label);
    946       1.1     skrll 	  current_fb_label = -1;
    947       1.1     skrll 	}
    948       1.1     skrll 
    949       1.1     skrll       /* Reset any don't-align-next-datum request, unless this was a LOC
    950       1.1     skrll          directive.  */
    951       1.1     skrll       if (instruction->operands != mmix_operands_loc)
    952       1.1     skrll 	want_unaligned = 0;
    953       1.1     skrll 
    954       1.1     skrll       return;
    955       1.1     skrll     }
    956       1.1     skrll 
    957       1.1     skrll   /* Not a pseudo; we *will* emit contents.  */
    958       1.1     skrll   if (now_seg == data_section)
    959       1.1     skrll     {
    960       1.1     skrll       if (lowest_data_loc != (bfd_vma) -1 && (lowest_data_loc & 3) != 0)
    961       1.1     skrll 	{
    962       1.1     skrll 	  if (data_has_contents)
    963       1.1     skrll 	    as_bad (_("specified location wasn't TETRA-aligned"));
    964       1.1     skrll 	  else if (want_unaligned)
    965       1.1     skrll 	    as_bad (_("unaligned data at an absolute location is not supported"));
    966       1.1     skrll 
    967       1.1     skrll 	  lowest_data_loc &= ~(bfd_vma) 3;
    968       1.1     skrll 	  lowest_data_loc += 4;
    969       1.1     skrll 	}
    970       1.1     skrll 
    971       1.1     skrll       data_has_contents = 1;
    972       1.1     skrll     }
    973       1.1     skrll   else if (now_seg == text_section)
    974       1.1     skrll     {
    975       1.1     skrll       if (lowest_text_loc != (bfd_vma) -1 && (lowest_text_loc & 3) != 0)
    976       1.1     skrll 	{
    977       1.1     skrll 	  if (text_has_contents)
    978       1.1     skrll 	    as_bad (_("specified location wasn't TETRA-aligned"));
    979       1.1     skrll 	  else if (want_unaligned)
    980       1.1     skrll 	    as_bad (_("unaligned data at an absolute location is not supported"));
    981       1.1     skrll 
    982       1.1     skrll 	  lowest_text_loc &= ~(bfd_vma) 3;
    983       1.1     skrll 	  lowest_text_loc += 4;
    984       1.1     skrll 	}
    985       1.1     skrll 
    986       1.1     skrll       text_has_contents = 1;
    987       1.1     skrll     }
    988       1.1     skrll 
    989       1.1     skrll   /* After a sequence of BYTEs or WYDEs, we need to get to instruction
    990       1.1     skrll      alignment.  For other pseudos, a ".p2align 2" is supposed to be
    991       1.1     skrll      inserted by the user.  */
    992       1.1     skrll   if (last_alignment < 2 && ! want_unaligned)
    993       1.1     skrll     {
    994       1.1     skrll       frag_align (2, 0, 0);
    995       1.1     skrll       record_alignment (now_seg, 2);
    996       1.1     skrll       last_alignment = 2;
    997       1.1     skrll     }
    998       1.1     skrll   else
    999       1.1     skrll     /* Reset any don't-align-next-datum request.  */
   1000       1.1     skrll     want_unaligned = 0;
   1001       1.1     skrll 
   1002       1.1     skrll   /* For mmixal compatibility, a label for an instruction (and emitting
   1003       1.1     skrll      pseudo) refers to the _aligned_ address.  So we have to emit the
   1004       1.1     skrll      label here.  */
   1005       1.1     skrll   if (pending_label != NULL)
   1006       1.1     skrll     {
   1007       1.1     skrll       colon (pending_label);
   1008       1.1     skrll       pending_label = NULL;
   1009       1.1     skrll     }
   1010       1.1     skrll 
   1011       1.1     skrll   /* We assume that mmix_opcodes keeps having unique mnemonics for each
   1012       1.1     skrll      opcode, so we don't have to iterate over more than one opcode; if the
   1013       1.1     skrll      syntax does not match, then there's a syntax error.  */
   1014       1.1     skrll 
   1015       1.1     skrll   /* Operands have little or no context and are all comma-separated; it is
   1016       1.1     skrll      easier to parse each expression first.   */
   1017       1.1     skrll   switch (instruction->operands)
   1018       1.1     skrll     {
   1019       1.1     skrll     case mmix_operands_reg_yz:
   1020       1.1     skrll     case mmix_operands_pop:
   1021       1.1     skrll     case mmix_operands_regaddr:
   1022       1.1     skrll     case mmix_operands_pushj:
   1023       1.1     skrll     case mmix_operands_get:
   1024       1.1     skrll     case mmix_operands_put:
   1025       1.1     skrll     case mmix_operands_set:
   1026       1.1     skrll     case mmix_operands_save:
   1027       1.1     skrll     case mmix_operands_unsave:
   1028       1.1     skrll       max_operands = 2;
   1029       1.1     skrll       break;
   1030       1.1     skrll 
   1031       1.1     skrll     case mmix_operands_sync:
   1032       1.1     skrll     case mmix_operands_jmp:
   1033       1.1     skrll     case mmix_operands_resume:
   1034       1.1     skrll       max_operands = 1;
   1035       1.1     skrll       break;
   1036       1.1     skrll 
   1037       1.1     skrll       /* The original 3 is fine for the rest.  */
   1038       1.1     skrll     default:
   1039       1.1     skrll       break;
   1040       1.1     skrll     }
   1041       1.1     skrll 
   1042       1.1     skrll   /* If this is GET or PUT, and we don't do allow those names to be
   1043       1.1     skrll      equated, we need to parse the names ourselves, so we don't pick up a
   1044       1.1     skrll      user label instead of the special register.  */
   1045       1.1     skrll   if (! equated_spec_regs
   1046       1.1     skrll       && (instruction->operands == mmix_operands_get
   1047       1.1     skrll 	  || instruction->operands == mmix_operands_put))
   1048       1.1     skrll     n_operands = get_putget_operands (instruction, operands, exp);
   1049       1.1     skrll   else
   1050       1.1     skrll     n_operands = get_operands (max_operands, operands, exp);
   1051       1.1     skrll 
   1052       1.1     skrll   /* If there's a fb-label on the current line, set that label.  This must
   1053       1.1     skrll      be done *after* evaluating expressions of operands, since neither a
   1054       1.1     skrll      "1B" nor a "1F" refers to "1H" on the same line.  */
   1055       1.1     skrll   if (current_fb_label >= 0)
   1056       1.1     skrll     {
   1057       1.1     skrll       fb_label_instance_inc (current_fb_label);
   1058       1.1     skrll       colon (fb_label_name (current_fb_label, 0));
   1059       1.1     skrll       current_fb_label = -1;
   1060       1.1     skrll     }
   1061       1.1     skrll 
   1062       1.1     skrll   /* We also assume that the length of the instruction is at least 4, the
   1063       1.1     skrll      size of an unexpanded instruction.  We need a self-contained frag
   1064       1.1     skrll      since we want the relocation to point to the instruction, not the
   1065       1.1     skrll      variant part.  */
   1066       1.1     skrll 
   1067       1.1     skrll   opcodep = frag_more (4);
   1068       1.1     skrll   mmix_opcode_frag = opc_fragP = frag_now;
   1069       1.1     skrll   frag_now->fr_opcode = opcodep;
   1070       1.1     skrll 
   1071       1.1     skrll   /* Mark start of insn for DWARF2 debug features.  */
   1072       1.1     skrll   if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
   1073       1.1     skrll     dwarf2_emit_insn (4);
   1074       1.1     skrll 
   1075       1.1     skrll   md_number_to_chars (opcodep, instruction->match, 4);
   1076       1.1     skrll 
   1077       1.1     skrll   switch (instruction->operands)
   1078       1.1     skrll     {
   1079       1.1     skrll     case mmix_operands_jmp:
   1080       1.1     skrll       if (n_operands == 0 && ! mmix_gnu_syntax)
   1081       1.1     skrll 	/* Zeros are in place - nothing needs to be done when we have no
   1082       1.1     skrll 	   operands.  */
   1083       1.1     skrll 	break;
   1084       1.1     skrll 
   1085       1.1     skrll       /* Add a frag for a JMP relaxation; we need room for max four
   1086       1.1     skrll 	 extra instructions.  We don't do any work around here to check if
   1087       1.1     skrll 	 we can determine the offset right away.  */
   1088       1.1     skrll       if (n_operands != 1 || exp[0].X_op == O_register)
   1089       1.1     skrll 	{
   1090       1.1     skrll 	  as_bad (_("invalid operand to opcode %s: `%s'"),
   1091       1.1     skrll 		  instruction->name, operands);
   1092       1.1     skrll 	  return;
   1093       1.1     skrll 	}
   1094       1.1     skrll 
   1095       1.1     skrll       if (expand_op)
   1096       1.1     skrll 	frag_var (rs_machine_dependent, 4 * 4, 0,
   1097       1.1     skrll 		  ENCODE_RELAX (STATE_JMP, STATE_UNDF),
   1098       1.1     skrll 		  exp[0].X_add_symbol,
   1099       1.1     skrll 		  exp[0].X_add_number,
   1100       1.1     skrll 		  opcodep);
   1101       1.1     skrll       else
   1102       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
   1103       1.1     skrll 		     exp + 0, 1, BFD_RELOC_MMIX_ADDR27);
   1104       1.1     skrll       break;
   1105       1.1     skrll 
   1106       1.1     skrll     case mmix_operands_pushj:
   1107       1.1     skrll       /* We take care of PUSHJ in full here.  */
   1108       1.1     skrll       if (n_operands != 2
   1109       1.1     skrll 	  || ((exp[0].X_op == O_constant || exp[0].X_op == O_register)
   1110       1.1     skrll 	      && (exp[0].X_add_number > 255 || exp[0].X_add_number < 0)))
   1111       1.1     skrll 	{
   1112       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1113       1.1     skrll 		  instruction->name, operands);
   1114       1.1     skrll 	  return;
   1115       1.1     skrll 	}
   1116       1.1     skrll 
   1117       1.1     skrll       if (exp[0].X_op == O_register || exp[0].X_op == O_constant)
   1118       1.1     skrll 	opcodep[1] = exp[0].X_add_number;
   1119       1.1     skrll       else
   1120       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1121       1.1     skrll 		     1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
   1122       1.1     skrll 
   1123       1.1     skrll       if (expand_op)
   1124       1.1     skrll 	frag_var (rs_machine_dependent, PUSHJ_MAX_LEN - 4, 0,
   1125       1.1     skrll 		  ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF),
   1126       1.1     skrll 		  exp[1].X_add_symbol,
   1127       1.1     skrll 		  exp[1].X_add_number,
   1128       1.1     skrll 		  opcodep);
   1129       1.1     skrll       else
   1130       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
   1131       1.1     skrll 		     exp + 1, 1, BFD_RELOC_MMIX_ADDR19);
   1132       1.1     skrll       break;
   1133       1.1     skrll 
   1134       1.1     skrll     case mmix_operands_regaddr:
   1135       1.1     skrll       /* GETA/branch: Add a frag for relaxation.  We don't do any work
   1136       1.1     skrll 	 around here to check if we can determine the offset right away.  */
   1137       1.1     skrll       if (n_operands != 2 || exp[1].X_op == O_register)
   1138       1.1     skrll 	{
   1139       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1140       1.1     skrll 		  instruction->name, operands);
   1141       1.1     skrll 	  return;
   1142       1.1     skrll 	}
   1143       1.1     skrll 
   1144       1.1     skrll       if (! expand_op)
   1145       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
   1146       1.1     skrll 		     exp + 1, 1, BFD_RELOC_MMIX_ADDR19);
   1147       1.1     skrll       else if (instruction->type == mmix_type_condbranch)
   1148       1.1     skrll 	frag_var (rs_machine_dependent, BCC_MAX_LEN - 4, 0,
   1149       1.1     skrll 		  ENCODE_RELAX (STATE_BCC, STATE_UNDF),
   1150       1.1     skrll 		  exp[1].X_add_symbol,
   1151       1.1     skrll 		  exp[1].X_add_number,
   1152       1.1     skrll 		  opcodep);
   1153       1.1     skrll       else
   1154       1.1     skrll 	frag_var (rs_machine_dependent, GETA_MAX_LEN - 4, 0,
   1155       1.1     skrll 		  ENCODE_RELAX (STATE_GETA, STATE_UNDF),
   1156       1.1     skrll 		  exp[1].X_add_symbol,
   1157       1.1     skrll 		  exp[1].X_add_number,
   1158       1.1     skrll 		  opcodep);
   1159       1.1     skrll       break;
   1160       1.1     skrll 
   1161       1.1     skrll     default:
   1162       1.1     skrll       break;
   1163       1.1     skrll     }
   1164       1.1     skrll 
   1165       1.1     skrll   switch (instruction->operands)
   1166       1.1     skrll     {
   1167       1.1     skrll     case mmix_operands_regs:
   1168       1.1     skrll       /* We check the number of operands here, since we're in a
   1169       1.1     skrll 	 FALLTHROUGH sequence in the next switch.  */
   1170       1.1     skrll       if (n_operands != 3 || exp[2].X_op == O_constant)
   1171       1.1     skrll 	{
   1172       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1173       1.1     skrll 		  instruction->name, operands);
   1174       1.1     skrll 	  return;
   1175       1.1     skrll 	}
   1176       1.1     skrll       /* FALLTHROUGH.  */
   1177       1.1     skrll     case mmix_operands_regs_z:
   1178       1.1     skrll       if (n_operands != 3)
   1179       1.1     skrll 	{
   1180       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1181       1.1     skrll 		  instruction->name, operands);
   1182       1.1     skrll 	  return;
   1183       1.1     skrll 	}
   1184       1.1     skrll       /* FALLTHROUGH.  */
   1185       1.1     skrll     case mmix_operands_reg_yz:
   1186       1.1     skrll     case mmix_operands_roundregs_z:
   1187       1.1     skrll     case mmix_operands_roundregs:
   1188       1.1     skrll     case mmix_operands_regs_z_opt:
   1189       1.1     skrll     case mmix_operands_neg:
   1190       1.1     skrll     case mmix_operands_regaddr:
   1191       1.1     skrll     case mmix_operands_get:
   1192       1.1     skrll     case mmix_operands_set:
   1193       1.1     skrll     case mmix_operands_save:
   1194       1.1     skrll       if (n_operands < 1
   1195       1.1     skrll 	  || (exp[0].X_op == O_register && exp[0].X_add_number > 255))
   1196       1.1     skrll 	{
   1197       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1198       1.1     skrll 		  instruction->name, operands);
   1199       1.1     skrll 	  return;
   1200       1.1     skrll 	}
   1201       1.1     skrll 
   1202       1.1     skrll       if (exp[0].X_op == O_register)
   1203       1.1     skrll 	opcodep[1] = exp[0].X_add_number;
   1204       1.1     skrll       else
   1205       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1206       1.1     skrll 		     1, exp + 0, 0, BFD_RELOC_MMIX_REG);
   1207       1.1     skrll       break;
   1208       1.1     skrll 
   1209       1.1     skrll     default:
   1210       1.1     skrll       ;
   1211       1.1     skrll     }
   1212       1.1     skrll 
   1213       1.1     skrll   /* A corresponding once-over for those who take an 8-bit constant as
   1214       1.1     skrll      their first operand.  */
   1215       1.1     skrll   switch (instruction->operands)
   1216       1.1     skrll     {
   1217       1.1     skrll     case mmix_operands_pushgo:
   1218       1.1     skrll       /* PUSHGO: X is a constant, but can be expressed as a register.
   1219       1.1     skrll 	 We handle X here and use the common machinery of T,X,3,$ for
   1220       1.1     skrll 	 the rest of the operands.  */
   1221       1.1     skrll       if (n_operands < 2
   1222       1.1     skrll 	  || ((exp[0].X_op == O_constant || exp[0].X_op == O_register)
   1223       1.1     skrll 	      && (exp[0].X_add_number > 255 || exp[0].X_add_number < 0)))
   1224       1.1     skrll 	{
   1225       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1226       1.1     skrll 		  instruction->name, operands);
   1227       1.1     skrll 	  return;
   1228       1.1     skrll 	}
   1229       1.1     skrll       else if (exp[0].X_op == O_constant || exp[0].X_op == O_register)
   1230       1.1     skrll 	opcodep[1] = exp[0].X_add_number;
   1231       1.1     skrll       else
   1232       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1233       1.1     skrll 		     1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
   1234       1.1     skrll       break;
   1235       1.1     skrll 
   1236       1.1     skrll     case mmix_operands_pop:
   1237       1.1     skrll       if ((n_operands == 0 || n_operands == 1) && ! mmix_gnu_syntax)
   1238       1.1     skrll 	break;
   1239       1.1     skrll       /* FALLTHROUGH.  */
   1240       1.1     skrll     case mmix_operands_x_regs_z:
   1241       1.1     skrll       if (n_operands < 1
   1242       1.1     skrll 	  || (exp[0].X_op == O_constant
   1243       1.1     skrll 	      && (exp[0].X_add_number > 255
   1244       1.1     skrll 		  || exp[0].X_add_number < 0)))
   1245       1.1     skrll 	{
   1246       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1247       1.1     skrll 		  instruction->name, operands);
   1248       1.1     skrll 	  return;
   1249       1.1     skrll 	}
   1250       1.1     skrll 
   1251       1.1     skrll       if (exp[0].X_op == O_constant)
   1252       1.1     skrll 	opcodep[1] = exp[0].X_add_number;
   1253       1.1     skrll       else
   1254       1.1     skrll 	/* FIXME: This doesn't bring us unsignedness checking.  */
   1255       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1256       1.1     skrll 		     1, exp + 0, 0, BFD_RELOC_8);
   1257       1.1     skrll     default:
   1258       1.1     skrll       ;
   1259       1.1     skrll     }
   1260       1.1     skrll 
   1261       1.1     skrll   /* Handle the rest.  */
   1262       1.1     skrll   switch (instruction->operands)
   1263       1.1     skrll     {
   1264       1.1     skrll     case mmix_operands_set:
   1265       1.1     skrll       /* SET: Either two registers, "$X,$Y", with Z field as zero, or
   1266       1.1     skrll 	 "$X,YZ", meaning change the opcode to SETL.  */
   1267       1.1     skrll       if (n_operands != 2
   1268       1.1     skrll 	  || (exp[1].X_op == O_constant
   1269       1.1     skrll 	      && (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0)))
   1270       1.1     skrll 	{
   1271       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1272       1.1     skrll 		  instruction->name, operands);
   1273       1.1     skrll 	  return;
   1274       1.1     skrll 	}
   1275       1.1     skrll 
   1276       1.1     skrll       if (exp[1].X_op == O_constant)
   1277       1.1     skrll 	{
   1278       1.1     skrll 	  /* There's an ambiguity with "SET $0,Y" when Y isn't defined
   1279       1.1     skrll 	     yet.  To keep things simple, we assume that Y is then a
   1280       1.1     skrll 	     register, and only change the opcode if Y is defined at this
   1281       1.1     skrll 	     point.
   1282       1.1     skrll 
   1283       1.1     skrll 	     There's no compatibility problem with mmixal, since it emits
   1284       1.1     skrll 	     errors if the field is not defined at this point.  */
   1285       1.1     skrll 	  md_number_to_chars (opcodep, SETL_INSN_BYTE, 1);
   1286       1.1     skrll 
   1287       1.1     skrll 	  opcodep[2] = (exp[1].X_add_number >> 8) & 255;
   1288       1.1     skrll 	  opcodep[3] = exp[1].X_add_number & 255;
   1289       1.1     skrll 	  break;
   1290       1.1     skrll 	}
   1291       1.1     skrll       /* FALLTHROUGH.  */
   1292       1.1     skrll     case mmix_operands_x_regs_z:
   1293       1.1     skrll       /* SYNCD: "X,$Y,$Z|Z".  */
   1294       1.1     skrll       /* FALLTHROUGH.  */
   1295       1.1     skrll     case mmix_operands_regs:
   1296       1.1     skrll       /* Three registers, $X,$Y,$Z.  */
   1297       1.1     skrll       /* FALLTHROUGH.  */
   1298       1.1     skrll     case mmix_operands_regs_z:
   1299       1.1     skrll       /* Operands "$X,$Y,$Z|Z", number of arguments checked above.  */
   1300       1.1     skrll       /* FALLTHROUGH.  */
   1301       1.1     skrll     case mmix_operands_pushgo:
   1302       1.1     skrll       /* Operands "$X|X,$Y,$Z|Z", optional Z.  */
   1303       1.1     skrll       /* FALLTHROUGH.  */
   1304       1.1     skrll     case mmix_operands_regs_z_opt:
   1305       1.1     skrll       /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0.  Any
   1306       1.1     skrll 	 operands not completely decided yet are postponed to later in
   1307       1.1     skrll 	 assembly (but not until link-time yet).  */
   1308       1.1     skrll 
   1309       1.1     skrll       if ((n_operands != 2 && n_operands != 3)
   1310       1.1     skrll 	  || (exp[1].X_op == O_register && exp[1].X_add_number > 255)
   1311       1.1     skrll 	  || (n_operands == 3
   1312       1.1     skrll 	      && ((exp[2].X_op == O_register
   1313       1.1     skrll 		   && exp[2].X_add_number > 255
   1314       1.1     skrll 		   && mmix_gnu_syntax)
   1315       1.1     skrll 		  || (exp[2].X_op == O_constant
   1316       1.1     skrll 		      && (exp[2].X_add_number > 255
   1317       1.1     skrll 			  || exp[2].X_add_number < 0)))))
   1318       1.1     skrll 	{
   1319       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1320       1.1     skrll 		  instruction->name, operands);
   1321       1.1     skrll 	  return;
   1322       1.1     skrll 	}
   1323       1.1     skrll 
   1324       1.1     skrll       if (n_operands == 2)
   1325       1.1     skrll 	{
   1326       1.1     skrll 	  symbolS *sym;
   1327   1.1.1.8  christos 	  fixS *tmpfixP;
   1328       1.1     skrll 
   1329       1.1     skrll 	  /* The last operand is immediate whenever we see just two
   1330       1.1     skrll 	     operands.  */
   1331       1.1     skrll 	  opcodep[0] |= IMM_OFFSET_BIT;
   1332       1.1     skrll 
   1333       1.1     skrll 	  /* Now, we could either have an implied "0" as the Z operand, or
   1334       1.1     skrll 	     it could be the constant of a "base address plus offset".  It
   1335       1.1     skrll 	     depends on whether it is allowed; only memory operations, as
   1336       1.1     skrll 	     signified by instruction->type and "T" and "X" operand types,
   1337       1.1     skrll 	     and it depends on whether we find a register in the second
   1338       1.1     skrll 	     operand, exp[1].  */
   1339       1.1     skrll 	  if (exp[1].X_op == O_register && exp[1].X_add_number <= 255)
   1340       1.1     skrll 	    {
   1341       1.1     skrll 	      /* A zero then; all done.  */
   1342       1.1     skrll 	      opcodep[2] = exp[1].X_add_number;
   1343       1.1     skrll 	      break;
   1344       1.1     skrll 	    }
   1345       1.1     skrll 
   1346       1.1     skrll 	  /* Not known as a register.  Is base address plus offset
   1347       1.1     skrll 	     allowed, or can we assume that it is a register anyway?  */
   1348       1.1     skrll 	  if ((instruction->operands != mmix_operands_regs_z_opt
   1349       1.1     skrll 	       && instruction->operands != mmix_operands_x_regs_z
   1350       1.1     skrll 	       && instruction->operands != mmix_operands_pushgo)
   1351       1.1     skrll 	      || (instruction->type != mmix_type_memaccess_octa
   1352       1.1     skrll 		  && instruction->type != mmix_type_memaccess_tetra
   1353       1.1     skrll 		  && instruction->type != mmix_type_memaccess_wyde
   1354       1.1     skrll 		  && instruction->type != mmix_type_memaccess_byte
   1355       1.1     skrll 		  && instruction->type != mmix_type_memaccess_block
   1356       1.1     skrll 		  && instruction->type != mmix_type_jsr
   1357       1.1     skrll 		  && instruction->type != mmix_type_branch))
   1358       1.1     skrll 	    {
   1359       1.1     skrll 	      fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1360       1.1     skrll 			   1, exp + 1, 0, BFD_RELOC_MMIX_REG);
   1361       1.1     skrll 	      break;
   1362       1.1     skrll 	    }
   1363       1.1     skrll 
   1364       1.1     skrll 	  /* To avoid getting a NULL add_symbol for constants and then
   1365       1.1     skrll 	     catching a SEGV in write_relocs since it doesn't handle
   1366       1.1     skrll 	     constants well for relocs other than PC-relative, we need to
   1367       1.1     skrll 	     pass expressions as symbols and use fix_new, not fix_new_exp.  */
   1368       1.1     skrll 	  sym = make_expr_symbol (exp + 1);
   1369       1.1     skrll 
   1370       1.1     skrll 	  /* Mark the symbol as being OK for a reloc.  */
   1371       1.1     skrll 	  symbol_get_bfdsym (sym)->flags |= BSF_KEEP;
   1372       1.1     skrll 
   1373       1.1     skrll 	  /* Now we know it can be a "base address plus offset".  Add
   1374       1.1     skrll 	     proper fixup types so we can handle this later, when we've
   1375       1.1     skrll 	     parsed everything.  */
   1376   1.1.1.8  christos 	  tmpfixP
   1377   1.1.1.8  christos 	    = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1378   1.1.1.8  christos 		       1, sym, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET);
   1379   1.1.1.8  christos 	  /* This is a non-trivial fixup: the ->fx_offset will not
   1380   1.1.1.8  christos 	     reflect the stored value, so the generic overflow test
   1381   1.1.1.8  christos 	     doesn't apply. */
   1382   1.1.1.8  christos 	  tmpfixP->fx_no_overflow = 1;
   1383       1.1     skrll 	  break;
   1384       1.1     skrll 	}
   1385       1.1     skrll 
   1386       1.1     skrll       if (exp[1].X_op == O_register)
   1387       1.1     skrll 	opcodep[2] = exp[1].X_add_number;
   1388       1.1     skrll       else
   1389       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1390       1.1     skrll 		     1, exp + 1, 0, BFD_RELOC_MMIX_REG);
   1391       1.1     skrll 
   1392       1.1     skrll       /* In mmixal compatibility mode, we allow special registers as
   1393       1.1     skrll 	 constants for the Z operand.  They have 256 added to their
   1394       1.1     skrll 	 register numbers, so the right thing will happen if we just treat
   1395       1.1     skrll 	 those as constants.  */
   1396       1.1     skrll       if (exp[2].X_op == O_register && exp[2].X_add_number <= 255)
   1397       1.1     skrll 	opcodep[3] = exp[2].X_add_number;
   1398       1.1     skrll       else if (exp[2].X_op == O_constant
   1399       1.1     skrll 	       || (exp[2].X_op == O_register && exp[2].X_add_number > 255))
   1400       1.1     skrll 	{
   1401       1.1     skrll 	  opcodep[3] = exp[2].X_add_number;
   1402       1.1     skrll 	  opcodep[0] |= IMM_OFFSET_BIT;
   1403       1.1     skrll 	}
   1404       1.1     skrll       else
   1405       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1406       1.1     skrll 		     1, exp + 2, 0,
   1407       1.1     skrll 		     (instruction->operands == mmix_operands_set
   1408       1.1     skrll 		      || instruction->operands == mmix_operands_regs)
   1409       1.1     skrll 		     ? BFD_RELOC_MMIX_REG : BFD_RELOC_MMIX_REG_OR_BYTE);
   1410       1.1     skrll       break;
   1411       1.1     skrll 
   1412       1.1     skrll     case mmix_operands_pop:
   1413       1.1     skrll       /* POP, one eight and one 16-bit operand.  */
   1414       1.1     skrll       if (n_operands == 0 && ! mmix_gnu_syntax)
   1415       1.1     skrll 	break;
   1416       1.1     skrll       if (n_operands == 1 && ! mmix_gnu_syntax)
   1417       1.1     skrll 	goto a_single_24_bit_number_operand;
   1418       1.1     skrll       /* FALLTHROUGH.  */
   1419       1.1     skrll     case mmix_operands_reg_yz:
   1420       1.1     skrll       /* A register and a 16-bit unsigned number.  */
   1421       1.1     skrll       if (n_operands != 2
   1422       1.1     skrll 	  || exp[1].X_op == O_register
   1423       1.1     skrll 	  || (exp[1].X_op == O_constant
   1424       1.1     skrll 	      && (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0)))
   1425       1.1     skrll 	{
   1426       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1427       1.1     skrll 		  instruction->name, operands);
   1428       1.1     skrll 	  return;
   1429       1.1     skrll 	}
   1430       1.1     skrll 
   1431       1.1     skrll       if (exp[1].X_op == O_constant)
   1432       1.1     skrll 	{
   1433       1.1     skrll 	  opcodep[2] = (exp[1].X_add_number >> 8) & 255;
   1434       1.1     skrll 	  opcodep[3] = exp[1].X_add_number & 255;
   1435       1.1     skrll 	}
   1436       1.1     skrll       else
   1437       1.1     skrll 	/* FIXME: This doesn't bring us unsignedness checking.  */
   1438       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1439       1.1     skrll 		     2, exp + 1, 0, BFD_RELOC_16);
   1440       1.1     skrll       break;
   1441       1.1     skrll 
   1442       1.1     skrll     case mmix_operands_jmp:
   1443       1.1     skrll       /* A JMP.  Everything is already done.  */
   1444       1.1     skrll       break;
   1445       1.1     skrll 
   1446       1.1     skrll     case mmix_operands_roundregs:
   1447       1.1     skrll       /* Two registers with optional rounding mode or constant in between.  */
   1448       1.1     skrll       if ((n_operands == 3 && exp[2].X_op == O_constant)
   1449       1.1     skrll 	  || (n_operands == 2 && exp[1].X_op == O_constant))
   1450       1.1     skrll 	{
   1451       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1452       1.1     skrll 		  instruction->name, operands);
   1453       1.1     skrll 	  return;
   1454       1.1     skrll 	}
   1455       1.1     skrll       /* FALLTHROUGH.  */
   1456       1.1     skrll     case mmix_operands_roundregs_z:
   1457       1.1     skrll       /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
   1458       1.1     skrll 	 optional and can be the corresponding constant.  */
   1459       1.1     skrll       {
   1460       1.1     skrll 	/* Which exp index holds the second operand (not the rounding
   1461       1.1     skrll 	   mode).  */
   1462       1.1     skrll 	int op2no = n_operands - 1;
   1463       1.1     skrll 
   1464       1.1     skrll 	if ((n_operands != 2 && n_operands != 3)
   1465       1.1     skrll 	    || ((exp[op2no].X_op == O_register
   1466       1.1     skrll 		 && exp[op2no].X_add_number > 255)
   1467       1.1     skrll 		|| (exp[op2no].X_op == O_constant
   1468       1.1     skrll 		    && (exp[op2no].X_add_number > 255
   1469       1.1     skrll 			|| exp[op2no].X_add_number < 0)))
   1470       1.1     skrll 	    || (n_operands == 3
   1471       1.1     skrll 		/* We don't allow for the rounding mode to be deferred; it
   1472       1.1     skrll 		   must be determined in the "first pass".  It cannot be a
   1473       1.1     skrll 		   symbol equated to a rounding mode, but defined after
   1474       1.1     skrll 		   the first use.  */
   1475       1.1     skrll 		&& ((exp[1].X_op == O_register
   1476       1.1     skrll 		     && exp[1].X_add_number < 512)
   1477       1.1     skrll 		    || (exp[1].X_op == O_constant
   1478   1.1.1.4  christos 			&& (exp[1].X_add_number < 0
   1479   1.1.1.4  christos 			    || exp[1].X_add_number > 4))
   1480       1.1     skrll 		    || (exp[1].X_op != O_register
   1481       1.1     skrll 			&& exp[1].X_op != O_constant))))
   1482       1.1     skrll 	  {
   1483       1.1     skrll 	    as_bad (_("invalid operands to opcode %s: `%s'"),
   1484       1.1     skrll 		    instruction->name, operands);
   1485       1.1     skrll 	    return;
   1486       1.1     skrll 	  }
   1487       1.1     skrll 
   1488       1.1     skrll 	/* Add rounding mode if present.  */
   1489       1.1     skrll 	if (n_operands == 3)
   1490       1.1     skrll 	  opcodep[2] = exp[1].X_add_number & 255;
   1491       1.1     skrll 
   1492       1.1     skrll 	if (exp[op2no].X_op == O_register)
   1493       1.1     skrll 	  opcodep[3] = exp[op2no].X_add_number;
   1494       1.1     skrll 	else if (exp[op2no].X_op == O_constant)
   1495       1.1     skrll 	  {
   1496       1.1     skrll 	    opcodep[3] = exp[op2no].X_add_number;
   1497       1.1     skrll 	    opcodep[0] |= IMM_OFFSET_BIT;
   1498       1.1     skrll 	  }
   1499       1.1     skrll 	else
   1500       1.1     skrll 	  fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1501       1.1     skrll 		       1, exp + op2no, 0,
   1502       1.1     skrll 		       instruction->operands == mmix_operands_roundregs
   1503       1.1     skrll 		       ? BFD_RELOC_MMIX_REG
   1504       1.1     skrll 		       : BFD_RELOC_MMIX_REG_OR_BYTE);
   1505       1.1     skrll 	break;
   1506       1.1     skrll       }
   1507       1.1     skrll 
   1508       1.1     skrll     case mmix_operands_sync:
   1509       1.1     skrll     a_single_24_bit_number_operand:
   1510       1.1     skrll       if (n_operands != 1
   1511       1.1     skrll 	  || exp[0].X_op == O_register
   1512       1.1     skrll 	  || (exp[0].X_op == O_constant
   1513       1.1     skrll 	      && (exp[0].X_add_number > 0xffffff || exp[0].X_add_number < 0)))
   1514       1.1     skrll 	{
   1515       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1516       1.1     skrll 		  instruction->name, operands);
   1517       1.1     skrll 	  return;
   1518       1.1     skrll 	}
   1519       1.1     skrll 
   1520       1.1     skrll       if (exp[0].X_op == O_constant)
   1521       1.1     skrll 	{
   1522       1.1     skrll 	  opcodep[1] = (exp[0].X_add_number >> 16) & 255;
   1523       1.1     skrll 	  opcodep[2] = (exp[0].X_add_number >> 8) & 255;
   1524       1.1     skrll 	  opcodep[3] = exp[0].X_add_number & 255;
   1525       1.1     skrll 	}
   1526       1.1     skrll       else
   1527       1.1     skrll 	/* FIXME: This doesn't bring us unsignedness checking.  */
   1528       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1529       1.1     skrll 		     3, exp + 0, 0, BFD_RELOC_24);
   1530       1.1     skrll       break;
   1531       1.1     skrll 
   1532       1.1     skrll     case mmix_operands_neg:
   1533       1.1     skrll       /* Operands "$X,Y,$Z|Z"; NEG or NEGU.  Y is optional, 0 is default.  */
   1534       1.1     skrll 
   1535       1.1     skrll       if ((n_operands != 3 && n_operands != 2)
   1536       1.1     skrll 	  || (n_operands == 3 && exp[1].X_op == O_register)
   1537       1.1     skrll 	  || ((exp[1].X_op == O_constant || exp[1].X_op == O_register)
   1538       1.1     skrll 	      && (exp[1].X_add_number > 255 || exp[1].X_add_number < 0))
   1539       1.1     skrll 	  || (n_operands == 3
   1540       1.1     skrll 	      && ((exp[2].X_op == O_register && exp[2].X_add_number > 255)
   1541       1.1     skrll 		  || (exp[2].X_op == O_constant
   1542       1.1     skrll 		      && (exp[2].X_add_number > 255
   1543       1.1     skrll 			  || exp[2].X_add_number < 0)))))
   1544       1.1     skrll 	{
   1545       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1546       1.1     skrll 		  instruction->name, operands);
   1547       1.1     skrll 	  return;
   1548       1.1     skrll 	}
   1549       1.1     skrll 
   1550       1.1     skrll       if (n_operands == 2)
   1551       1.1     skrll 	{
   1552       1.1     skrll 	  if (exp[1].X_op == O_register)
   1553       1.1     skrll 	    opcodep[3] = exp[1].X_add_number;
   1554       1.1     skrll 	  else if (exp[1].X_op == O_constant)
   1555       1.1     skrll 	    {
   1556       1.1     skrll 	      opcodep[3] = exp[1].X_add_number;
   1557       1.1     skrll 	      opcodep[0] |= IMM_OFFSET_BIT;
   1558       1.1     skrll 	    }
   1559       1.1     skrll 	  else
   1560       1.1     skrll 	    fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1561       1.1     skrll 			 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
   1562       1.1     skrll 	  break;
   1563       1.1     skrll 	}
   1564       1.1     skrll 
   1565       1.1     skrll       if (exp[1].X_op == O_constant)
   1566       1.1     skrll 	opcodep[2] = exp[1].X_add_number;
   1567       1.1     skrll       else
   1568       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1569       1.1     skrll 		     1, exp + 1, 0, BFD_RELOC_8);
   1570       1.1     skrll 
   1571       1.1     skrll       if (exp[2].X_op == O_register)
   1572       1.1     skrll 	opcodep[3] = exp[2].X_add_number;
   1573       1.1     skrll       else if (exp[2].X_op == O_constant)
   1574       1.1     skrll 	{
   1575       1.1     skrll 	  opcodep[3] = exp[2].X_add_number;
   1576       1.1     skrll 	  opcodep[0] |= IMM_OFFSET_BIT;
   1577       1.1     skrll 	}
   1578       1.1     skrll       else
   1579       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1580       1.1     skrll 		     1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
   1581       1.1     skrll       break;
   1582       1.1     skrll 
   1583       1.1     skrll     case mmix_operands_regaddr:
   1584       1.1     skrll       /* A GETA/branch-type.  */
   1585       1.1     skrll       break;
   1586       1.1     skrll 
   1587       1.1     skrll     case mmix_operands_get:
   1588       1.1     skrll       /* "$X,spec_reg"; GET.
   1589       1.1     skrll 	 Like with rounding modes, we demand that the special register or
   1590       1.1     skrll 	 symbol is already defined when we get here at the point of use.  */
   1591       1.1     skrll       if (n_operands != 2
   1592       1.1     skrll 	  || (exp[1].X_op == O_register
   1593       1.1     skrll 	      && (exp[1].X_add_number < 256 || exp[1].X_add_number >= 512))
   1594       1.1     skrll 	  || (exp[1].X_op == O_constant
   1595       1.1     skrll 	      && (exp[1].X_add_number < 0 || exp[1].X_add_number > 256))
   1596       1.1     skrll 	  || (exp[1].X_op != O_constant && exp[1].X_op != O_register))
   1597       1.1     skrll 	{
   1598       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1599       1.1     skrll 		  instruction->name, operands);
   1600       1.1     skrll 	  return;
   1601       1.1     skrll 	}
   1602       1.1     skrll 
   1603       1.1     skrll       opcodep[3] = exp[1].X_add_number - 256;
   1604       1.1     skrll       break;
   1605       1.1     skrll 
   1606       1.1     skrll     case mmix_operands_put:
   1607       1.1     skrll       /* "spec_reg,$Z|Z"; PUT.  */
   1608       1.1     skrll       if (n_operands != 2
   1609       1.1     skrll 	  || (exp[0].X_op == O_register
   1610       1.1     skrll 	      && (exp[0].X_add_number < 256 || exp[0].X_add_number >= 512))
   1611       1.1     skrll 	  || (exp[0].X_op == O_constant
   1612       1.1     skrll 	      && (exp[0].X_add_number < 0 || exp[0].X_add_number > 256))
   1613       1.1     skrll 	  || (exp[0].X_op != O_constant && exp[0].X_op != O_register))
   1614       1.1     skrll 	{
   1615       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1616       1.1     skrll 		  instruction->name, operands);
   1617       1.1     skrll 	  return;
   1618       1.1     skrll 	}
   1619       1.1     skrll 
   1620       1.1     skrll       opcodep[1] = exp[0].X_add_number - 256;
   1621       1.1     skrll 
   1622       1.1     skrll       /* Note that the Y field is zero.  */
   1623       1.1     skrll 
   1624       1.1     skrll       if (exp[1].X_op == O_register)
   1625       1.1     skrll 	opcodep[3] = exp[1].X_add_number;
   1626       1.1     skrll       else if (exp[1].X_op == O_constant)
   1627       1.1     skrll 	{
   1628       1.1     skrll 	  opcodep[3] = exp[1].X_add_number;
   1629       1.1     skrll 	  opcodep[0] |= IMM_OFFSET_BIT;
   1630       1.1     skrll 	}
   1631       1.1     skrll       else
   1632       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1633       1.1     skrll 		     1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
   1634       1.1     skrll       break;
   1635       1.1     skrll 
   1636       1.1     skrll     case mmix_operands_save:
   1637       1.1     skrll       /* "$X,0"; SAVE.  */
   1638       1.1     skrll       if (n_operands != 2
   1639       1.1     skrll 	  || exp[1].X_op != O_constant
   1640       1.1     skrll 	  || exp[1].X_add_number != 0)
   1641       1.1     skrll 	{
   1642       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1643       1.1     skrll 		  instruction->name, operands);
   1644       1.1     skrll 	  return;
   1645       1.1     skrll 	}
   1646       1.1     skrll       break;
   1647       1.1     skrll 
   1648       1.1     skrll     case mmix_operands_unsave:
   1649       1.1     skrll       if (n_operands < 2 && ! mmix_gnu_syntax)
   1650       1.1     skrll 	{
   1651       1.1     skrll 	  if (n_operands == 1)
   1652       1.1     skrll 	    {
   1653       1.1     skrll 	      if (exp[0].X_op == O_register)
   1654       1.1     skrll 		opcodep[3] = exp[0].X_add_number;
   1655       1.1     skrll 	      else
   1656       1.1     skrll 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1657       1.1     skrll 			     1, exp, 0, BFD_RELOC_MMIX_REG);
   1658       1.1     skrll 	    }
   1659       1.1     skrll 	  break;
   1660       1.1     skrll 	}
   1661       1.1     skrll 
   1662       1.1     skrll       /* "0,$Z"; UNSAVE.  */
   1663       1.1     skrll       if (n_operands != 2
   1664       1.1     skrll 	  || exp[0].X_op != O_constant
   1665       1.1     skrll 	  || exp[0].X_add_number != 0
   1666       1.1     skrll 	  || exp[1].X_op == O_constant
   1667       1.1     skrll 	  || (exp[1].X_op == O_register
   1668       1.1     skrll 	      && exp[1].X_add_number > 255))
   1669       1.1     skrll 	{
   1670       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1671       1.1     skrll 		  instruction->name, operands);
   1672       1.1     skrll 	  return;
   1673       1.1     skrll 	}
   1674       1.1     skrll 
   1675       1.1     skrll       if (exp[1].X_op == O_register)
   1676       1.1     skrll 	opcodep[3] = exp[1].X_add_number;
   1677       1.1     skrll       else
   1678       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1679       1.1     skrll 		     1, exp + 1, 0, BFD_RELOC_MMIX_REG);
   1680       1.1     skrll       break;
   1681       1.1     skrll 
   1682       1.1     skrll     case mmix_operands_xyz_opt:
   1683   1.1.1.2  christos       /* SWYM, TRIP, TRAP: zero, one, two or three operands.  It's
   1684   1.1.1.2  christos 	 unspecified whether operands are registers or constants, but
   1685   1.1.1.2  christos 	 when we find register syntax, we require operands to be literal and
   1686   1.1.1.2  christos 	 within 0..255.  */
   1687       1.1     skrll       if (n_operands == 0 && ! mmix_gnu_syntax)
   1688       1.1     skrll 	/* Zeros are in place - nothing needs to be done for zero
   1689       1.1     skrll 	   operands.  We don't allow this in GNU syntax mode, because it
   1690       1.1     skrll 	   was believed that the risk of missing to supply an operand is
   1691       1.1     skrll 	   higher than the benefit of not having to specify a zero.  */
   1692       1.1     skrll 	;
   1693       1.1     skrll       else if (n_operands == 1 && exp[0].X_op != O_register)
   1694       1.1     skrll 	{
   1695       1.1     skrll 	  if (exp[0].X_op == O_constant)
   1696       1.1     skrll 	    {
   1697   1.1.1.2  christos 	      if (exp[0].X_add_number > 255*256*256
   1698       1.1     skrll 		  || exp[0].X_add_number < 0)
   1699       1.1     skrll 		{
   1700       1.1     skrll 		  as_bad (_("invalid operands to opcode %s: `%s'"),
   1701       1.1     skrll 			  instruction->name, operands);
   1702       1.1     skrll 		  return;
   1703       1.1     skrll 		}
   1704       1.1     skrll 	      else
   1705       1.1     skrll 		{
   1706       1.1     skrll 		  opcodep[1] = (exp[0].X_add_number >> 16) & 255;
   1707       1.1     skrll 		  opcodep[2] = (exp[0].X_add_number >> 8) & 255;
   1708       1.1     skrll 		  opcodep[3] = exp[0].X_add_number & 255;
   1709       1.1     skrll 		}
   1710       1.1     skrll 	    }
   1711       1.1     skrll 	  else
   1712       1.1     skrll 	    fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1713       1.1     skrll 			 3, exp, 0, BFD_RELOC_24);
   1714       1.1     skrll 	}
   1715       1.1     skrll       else if (n_operands == 2
   1716       1.1     skrll 	       && exp[0].X_op != O_register
   1717       1.1     skrll 	       && exp[1].X_op != O_register)
   1718       1.1     skrll 	{
   1719       1.1     skrll 	  /* Two operands.  */
   1720       1.1     skrll 
   1721       1.1     skrll 	  if (exp[0].X_op == O_constant)
   1722       1.1     skrll 	    {
   1723       1.1     skrll 	      if (exp[0].X_add_number > 255
   1724       1.1     skrll 		  || exp[0].X_add_number < 0)
   1725       1.1     skrll 		{
   1726       1.1     skrll 		  as_bad (_("invalid operands to opcode %s: `%s'"),
   1727       1.1     skrll 			  instruction->name, operands);
   1728       1.1     skrll 		  return;
   1729       1.1     skrll 		}
   1730       1.1     skrll 	      else
   1731       1.1     skrll 		opcodep[1] = exp[0].X_add_number & 255;
   1732       1.1     skrll 	    }
   1733       1.1     skrll 	  else
   1734       1.1     skrll 	    fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1735       1.1     skrll 			 1, exp, 0, BFD_RELOC_8);
   1736       1.1     skrll 
   1737       1.1     skrll 	  if (exp[1].X_op == O_constant)
   1738       1.1     skrll 	    {
   1739   1.1.1.2  christos 	      if (exp[1].X_add_number > 255*256
   1740       1.1     skrll 		  || exp[1].X_add_number < 0)
   1741       1.1     skrll 		{
   1742       1.1     skrll 		  as_bad (_("invalid operands to opcode %s: `%s'"),
   1743       1.1     skrll 			  instruction->name, operands);
   1744       1.1     skrll 		  return;
   1745       1.1     skrll 		}
   1746       1.1     skrll 	      else
   1747       1.1     skrll 		{
   1748       1.1     skrll 		  opcodep[2] = (exp[1].X_add_number >> 8) & 255;
   1749       1.1     skrll 		  opcodep[3] = exp[1].X_add_number & 255;
   1750       1.1     skrll 		}
   1751       1.1     skrll 	    }
   1752       1.1     skrll 	  else
   1753       1.1     skrll 	    fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1754       1.1     skrll 			 2, exp + 1, 0, BFD_RELOC_16);
   1755       1.1     skrll 	}
   1756       1.1     skrll       else if (n_operands == 3
   1757       1.1     skrll 	       && exp[0].X_op != O_register
   1758       1.1     skrll 	       && exp[1].X_op != O_register
   1759       1.1     skrll 	       && exp[2].X_op != O_register)
   1760       1.1     skrll 	{
   1761       1.1     skrll 	  /* Three operands.  */
   1762       1.1     skrll 
   1763       1.1     skrll 	  if (exp[0].X_op == O_constant)
   1764       1.1     skrll 	    {
   1765       1.1     skrll 	      if (exp[0].X_add_number > 255
   1766       1.1     skrll 		  || exp[0].X_add_number < 0)
   1767       1.1     skrll 		{
   1768       1.1     skrll 		  as_bad (_("invalid operands to opcode %s: `%s'"),
   1769       1.1     skrll 			  instruction->name, operands);
   1770       1.1     skrll 		  return;
   1771       1.1     skrll 		}
   1772       1.1     skrll 	      else
   1773       1.1     skrll 		opcodep[1] = exp[0].X_add_number & 255;
   1774       1.1     skrll 	    }
   1775       1.1     skrll 	  else
   1776       1.1     skrll 	    fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1777       1.1     skrll 			 1, exp, 0, BFD_RELOC_8);
   1778       1.1     skrll 
   1779       1.1     skrll 	  if (exp[1].X_op == O_constant)
   1780       1.1     skrll 	    {
   1781       1.1     skrll 	      if (exp[1].X_add_number > 255
   1782       1.1     skrll 		  || exp[1].X_add_number < 0)
   1783       1.1     skrll 		{
   1784       1.1     skrll 		  as_bad (_("invalid operands to opcode %s: `%s'"),
   1785       1.1     skrll 			  instruction->name, operands);
   1786       1.1     skrll 		  return;
   1787       1.1     skrll 		}
   1788       1.1     skrll 	      else
   1789       1.1     skrll 		opcodep[2] = exp[1].X_add_number & 255;
   1790       1.1     skrll 	    }
   1791       1.1     skrll 	  else
   1792       1.1     skrll 	    fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1793       1.1     skrll 			 1, exp + 1, 0, BFD_RELOC_8);
   1794       1.1     skrll 
   1795       1.1     skrll 	  if (exp[2].X_op == O_constant)
   1796       1.1     skrll 	    {
   1797       1.1     skrll 	      if (exp[2].X_add_number > 255
   1798       1.1     skrll 		  || exp[2].X_add_number < 0)
   1799       1.1     skrll 		{
   1800       1.1     skrll 		  as_bad (_("invalid operands to opcode %s: `%s'"),
   1801       1.1     skrll 			  instruction->name, operands);
   1802       1.1     skrll 		  return;
   1803       1.1     skrll 		}
   1804       1.1     skrll 	      else
   1805       1.1     skrll 		opcodep[3] = exp[2].X_add_number & 255;
   1806       1.1     skrll 	    }
   1807       1.1     skrll 	  else
   1808       1.1     skrll 	    fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1809       1.1     skrll 			 1, exp + 2, 0, BFD_RELOC_8);
   1810       1.1     skrll 	}
   1811   1.1.1.2  christos       else
   1812       1.1     skrll 	{
   1813   1.1.1.2  christos 	  /* We can't get here for other cases.  */
   1814   1.1.1.2  christos 	  gas_assert (n_operands <= 3);
   1815   1.1.1.2  christos 
   1816   1.1.1.2  christos 	  /* The meaning of operands to TRIP and TRAP is not defined (and
   1817   1.1.1.2  christos 	     SWYM operands aren't enforced in mmixal, so let's avoid
   1818   1.1.1.2  christos 	     that).  We add combinations not handled above here as we find
   1819   1.1.1.2  christos 	     them and as they're reported.  */
   1820       1.1     skrll 	  if (n_operands == 3)
   1821       1.1     skrll 	    {
   1822       1.1     skrll 	      /* Don't require non-register operands.  Always generate
   1823       1.1     skrll 		 fixups, so we don't have to copy lots of code and create
   1824       1.1     skrll 		 maintenance problems.  TRIP is supposed to be a rare
   1825       1.1     skrll 		 instruction, so the overhead should not matter.  We
   1826       1.1     skrll 		 aren't allowed to fix_new_exp for an expression which is
   1827   1.1.1.2  christos 		 an O_register at this point, however.
   1828   1.1.1.2  christos 
   1829   1.1.1.2  christos 		 Don't use BFD_RELOC_MMIX_REG_OR_BYTE as that modifies
   1830   1.1.1.2  christos 		 the insn for a register in the Z field and we want
   1831   1.1.1.2  christos 		 consistency.  */
   1832       1.1     skrll 	      if (exp[0].X_op == O_register)
   1833       1.1     skrll 		opcodep[1] = exp[0].X_add_number;
   1834       1.1     skrll 	      else
   1835       1.1     skrll 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1836   1.1.1.2  christos 			     1, exp, 0, BFD_RELOC_8);
   1837       1.1     skrll 	      if (exp[1].X_op == O_register)
   1838       1.1     skrll 		opcodep[2] = exp[1].X_add_number;
   1839       1.1     skrll 	      else
   1840       1.1     skrll 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1841   1.1.1.2  christos 			     1, exp + 1, 0, BFD_RELOC_8);
   1842       1.1     skrll 	      if (exp[2].X_op == O_register)
   1843       1.1     skrll 		opcodep[3] = exp[2].X_add_number;
   1844       1.1     skrll 	      else
   1845       1.1     skrll 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1846   1.1.1.2  christos 			     1, exp + 2, 0, BFD_RELOC_8);
   1847       1.1     skrll 	    }
   1848       1.1     skrll 	  else if (n_operands == 2)
   1849       1.1     skrll 	    {
   1850       1.1     skrll 	      if (exp[0].X_op == O_register)
   1851   1.1.1.2  christos 		opcodep[1] = exp[0].X_add_number;
   1852       1.1     skrll 	      else
   1853   1.1.1.2  christos 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
   1854   1.1.1.2  christos 			     1, exp, 0, BFD_RELOC_8);
   1855       1.1     skrll 	      if (exp[1].X_op == O_register)
   1856       1.1     skrll 		opcodep[3] = exp[1].X_add_number;
   1857       1.1     skrll 	      else
   1858   1.1.1.2  christos 		fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
   1859   1.1.1.2  christos 			     2, exp + 1, 0, BFD_RELOC_16);
   1860       1.1     skrll 	    }
   1861       1.1     skrll 	  else
   1862       1.1     skrll 	    {
   1863   1.1.1.2  christos 	      /* We can't get here for other cases.  */
   1864   1.1.1.2  christos 	      gas_assert (n_operands == 1 && exp[0].X_op == O_register);
   1865   1.1.1.2  christos 
   1866   1.1.1.2  christos 	      opcodep[3] = exp[0].X_add_number;
   1867       1.1     skrll 	    }
   1868       1.1     skrll 	}
   1869       1.1     skrll       break;
   1870       1.1     skrll 
   1871       1.1     skrll     case mmix_operands_resume:
   1872       1.1     skrll       if (n_operands == 0 && ! mmix_gnu_syntax)
   1873       1.1     skrll 	break;
   1874       1.1     skrll 
   1875       1.1     skrll       if (n_operands != 1
   1876       1.1     skrll 	  || exp[0].X_op == O_register
   1877       1.1     skrll 	  || (exp[0].X_op == O_constant
   1878       1.1     skrll 	      && (exp[0].X_add_number < 0
   1879       1.1     skrll 		  || exp[0].X_add_number > 255)))
   1880       1.1     skrll 	{
   1881       1.1     skrll 	  as_bad (_("invalid operands to opcode %s: `%s'"),
   1882       1.1     skrll 		  instruction->name, operands);
   1883       1.1     skrll 	  return;
   1884       1.1     skrll 	}
   1885       1.1     skrll 
   1886       1.1     skrll       if (exp[0].X_op == O_constant)
   1887       1.1     skrll 	opcodep[3] = exp[0].X_add_number;
   1888       1.1     skrll       else
   1889       1.1     skrll 	fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
   1890       1.1     skrll 		     1, exp + 0, 0, BFD_RELOC_8);
   1891       1.1     skrll       break;
   1892       1.1     skrll 
   1893       1.1     skrll     case mmix_operands_pushj:
   1894       1.1     skrll       /* All is done for PUSHJ already.  */
   1895       1.1     skrll       break;
   1896       1.1     skrll 
   1897       1.1     skrll     default:
   1898       1.1     skrll       BAD_CASE (instruction->operands);
   1899       1.1     skrll     }
   1900       1.1     skrll }
   1901       1.1     skrll 
   1902       1.1     skrll /* For the benefit of insns that start with a digit, we assemble by way of
   1903       1.1     skrll    tc_unrecognized_line too, through this function.  */
   1904       1.1     skrll 
   1905       1.1     skrll int
   1906       1.1     skrll mmix_assemble_return_nonzero (char *str)
   1907       1.1     skrll {
   1908       1.1     skrll   int last_error_count = had_errors ();
   1909       1.1     skrll   char *s2 = str;
   1910       1.1     skrll   char c;
   1911       1.1     skrll 
   1912       1.1     skrll   /* Normal instruction handling downcases, so we must too.  */
   1913       1.1     skrll   while (ISALNUM (*s2))
   1914       1.1     skrll     {
   1915  1.1.1.10  christos       if (ISUPPER (*s2))
   1916       1.1     skrll 	*s2 = TOLOWER (*s2);
   1917       1.1     skrll       s2++;
   1918       1.1     skrll     }
   1919       1.1     skrll 
   1920       1.1     skrll   /* Cut the line for sake of the assembly.  */
   1921       1.1     skrll   for (s2 = str; *s2 && *s2 != '\n'; s2++)
   1922       1.1     skrll     ;
   1923       1.1     skrll 
   1924       1.1     skrll   c = *s2;
   1925       1.1     skrll   *s2 = 0;
   1926       1.1     skrll   md_assemble (str);
   1927       1.1     skrll   *s2 = c;
   1928       1.1     skrll 
   1929       1.1     skrll   return had_errors () == last_error_count;
   1930       1.1     skrll }
   1931       1.1     skrll 
   1932       1.1     skrll /* The PREFIX pseudo.  */
   1933       1.1     skrll 
   1934       1.1     skrll static void
   1935       1.1     skrll s_prefix (int unused ATTRIBUTE_UNUSED)
   1936       1.1     skrll {
   1937       1.1     skrll   char *p;
   1938       1.1     skrll   int c;
   1939       1.1     skrll 
   1940       1.1     skrll   SKIP_WHITESPACE ();
   1941       1.1     skrll 
   1942   1.1.1.4  christos   c = get_symbol_name (&p);
   1943   1.1.1.4  christos 
   1944   1.1.1.6  christos   /* Resetting prefix?  */
   1945       1.1     skrll   if (*p == ':' && p[1] == 0)
   1946       1.1     skrll     mmix_current_prefix = NULL;
   1947       1.1     skrll   else
   1948       1.1     skrll     {
   1949       1.1     skrll       /* Put this prefix on the mmix symbols obstack.  We could malloc and
   1950       1.1     skrll 	 free it separately, but then we'd have to worry about that.
   1951       1.1     skrll 	 People using up memory on prefixes have other problems.  */
   1952       1.1     skrll       obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1);
   1953       1.1     skrll       p = obstack_finish (&mmix_sym_obstack);
   1954       1.1     skrll 
   1955       1.1     skrll       /* Accumulate prefixes, and strip a leading ':'.  */
   1956       1.1     skrll       if (mmix_current_prefix != NULL || *p == ':')
   1957       1.1     skrll 	p = mmix_prefix_name (p);
   1958       1.1     skrll 
   1959       1.1     skrll       mmix_current_prefix = p;
   1960       1.1     skrll     }
   1961       1.1     skrll 
   1962   1.1.1.4  christos   (void) restore_line_pointer (c);
   1963       1.1     skrll 
   1964       1.1     skrll   mmix_handle_rest_of_empty_line ();
   1965       1.1     skrll }
   1966       1.1     skrll 
   1967       1.1     skrll /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
   1968       1.1     skrll    and store each prefixed name on a (separate) obstack.  This means that
   1969       1.1     skrll    the name is on the "notes" obstack in non-prefixed form and on the
   1970       1.1     skrll    mmix_sym_obstack in prefixed form, but currently it is not worth
   1971       1.1     skrll    rewriting the whole GAS symbol handling to improve "hooking" to avoid
   1972       1.1     skrll    that.  (It might be worth a rewrite for other reasons, though).  */
   1973       1.1     skrll 
   1974       1.1     skrll char *
   1975       1.1     skrll mmix_prefix_name (char *shortname)
   1976       1.1     skrll {
   1977       1.1     skrll   if (*shortname == ':')
   1978       1.1     skrll     return shortname + 1;
   1979       1.1     skrll 
   1980       1.1     skrll   if (mmix_current_prefix == NULL)
   1981       1.1     skrll     as_fatal (_("internal: mmix_prefix_name but empty prefix"));
   1982       1.1     skrll 
   1983       1.1     skrll   if (*shortname == '$')
   1984       1.1     skrll     return shortname;
   1985       1.1     skrll 
   1986       1.1     skrll   obstack_grow (&mmix_sym_obstack, mmix_current_prefix,
   1987       1.1     skrll 		strlen (mmix_current_prefix));
   1988       1.1     skrll   obstack_grow (&mmix_sym_obstack, shortname, strlen (shortname) + 1);
   1989       1.1     skrll   return obstack_finish (&mmix_sym_obstack);
   1990       1.1     skrll }
   1991       1.1     skrll 
   1992       1.1     skrll /* The GREG pseudo.  At LABEL, we have the name of a symbol that we
   1993       1.1     skrll    want to make a register symbol, and which should be initialized with
   1994       1.1     skrll    the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
   1995       1.1     skrll    Either and (perhaps less meaningful) both may be missing.  LABEL must
   1996       1.1     skrll    be persistent, perhaps allocated on an obstack.  */
   1997       1.1     skrll 
   1998       1.1     skrll static void
   1999       1.1     skrll mmix_greg_internal (char *label)
   2000       1.1     skrll {
   2001       1.1     skrll   expressionS *expP = &mmix_raw_gregs[n_of_raw_gregs].exp;
   2002   1.1.1.3  christos   segT section;
   2003       1.1     skrll 
   2004       1.1     skrll   /* Don't set the section to register contents section before the
   2005       1.1     skrll      expression has been parsed; it may refer to the current position.  */
   2006   1.1.1.3  christos   section = expression (expP);
   2007       1.1     skrll 
   2008       1.1     skrll   /* FIXME: Check that no expression refers to the register contents
   2009       1.1     skrll      section.  May need to be done in elf64-mmix.c.  */
   2010       1.1     skrll   if (expP->X_op == O_absent)
   2011       1.1     skrll     {
   2012       1.1     skrll       /* Default to zero if the expression was absent.  */
   2013       1.1     skrll       expP->X_op = O_constant;
   2014       1.1     skrll       expP->X_add_number = 0;
   2015       1.1     skrll       expP->X_unsigned = 0;
   2016       1.1     skrll       expP->X_add_symbol = NULL;
   2017       1.1     skrll       expP->X_op_symbol = NULL;
   2018       1.1     skrll     }
   2019       1.1     skrll 
   2020   1.1.1.3  christos   if (section == undefined_section)
   2021   1.1.1.3  christos     {
   2022   1.1.1.3  christos       /* This is an error or a LOC with an expression involving
   2023   1.1.1.3  christos 	 forward references.  For the expression to be correctly
   2024   1.1.1.3  christos 	 evaluated, we need to force a proper symbol; gas loses track
   2025   1.1.1.3  christos 	 of the segment for "local symbols".  */
   2026   1.1.1.3  christos       if (expP->X_op == O_add)
   2027   1.1.1.3  christos 	{
   2028   1.1.1.3  christos 	  symbol_get_value_expression (expP->X_op_symbol);
   2029   1.1.1.3  christos 	  symbol_get_value_expression (expP->X_add_symbol);
   2030   1.1.1.3  christos 	}
   2031   1.1.1.3  christos       else
   2032   1.1.1.3  christos 	{
   2033   1.1.1.3  christos 	  gas_assert (expP->X_op == O_symbol);
   2034   1.1.1.3  christos 	  symbol_get_value_expression (expP->X_add_symbol);
   2035   1.1.1.3  christos 	}
   2036   1.1.1.3  christos     }
   2037   1.1.1.3  christos 
   2038       1.1     skrll   /* We must handle prefixes here, as we save the labels and expressions
   2039       1.1     skrll      to be output later.  */
   2040       1.1     skrll   mmix_raw_gregs[n_of_raw_gregs].label
   2041       1.1     skrll     = mmix_current_prefix == NULL ? label : mmix_prefix_name (label);
   2042       1.1     skrll 
   2043       1.1     skrll   if (n_of_raw_gregs == MAX_GREGS - 1)
   2044       1.1     skrll     as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS);
   2045       1.1     skrll   else
   2046       1.1     skrll     n_of_raw_gregs++;
   2047       1.1     skrll 
   2048       1.1     skrll   mmix_handle_rest_of_empty_line ();
   2049       1.1     skrll }
   2050       1.1     skrll 
   2051       1.1     skrll /* The ".greg label,expr" worker.  */
   2052       1.1     skrll 
   2053       1.1     skrll static void
   2054       1.1     skrll s_greg (int unused ATTRIBUTE_UNUSED)
   2055       1.1     skrll {
   2056       1.1     skrll   char *p;
   2057       1.1     skrll   char c;
   2058       1.1     skrll 
   2059       1.1     skrll   /* This will skip over what can be a symbol and zero out the next
   2060       1.1     skrll      character, which we assume is a ',' or other meaningful delimiter.
   2061       1.1     skrll      What comes after that is the initializer expression for the
   2062       1.1     skrll      register.  */
   2063   1.1.1.4  christos   c = get_symbol_name (&p);
   2064   1.1.1.4  christos 
   2065   1.1.1.4  christos   if (c == '"')
   2066   1.1.1.4  christos     c = * ++ input_line_pointer;
   2067       1.1     skrll 
   2068  1.1.1.10  christos   if (! is_end_of_stmt (c))
   2069       1.1     skrll     input_line_pointer++;
   2070       1.1     skrll 
   2071       1.1     skrll   if (*p)
   2072       1.1     skrll     {
   2073       1.1     skrll       /* The label must be persistent; it's not used until after all input
   2074       1.1     skrll 	 has been seen.  */
   2075       1.1     skrll       obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1);
   2076       1.1     skrll       mmix_greg_internal (obstack_finish (&mmix_sym_obstack));
   2077       1.1     skrll     }
   2078       1.1     skrll   else
   2079       1.1     skrll     mmix_greg_internal (NULL);
   2080       1.1     skrll }
   2081       1.1     skrll 
   2082       1.1     skrll /* The "BSPEC expr" worker.  */
   2083       1.1     skrll 
   2084       1.1     skrll static void
   2085       1.1     skrll s_bspec (int unused ATTRIBUTE_UNUSED)
   2086       1.1     skrll {
   2087       1.1     skrll   asection *expsec;
   2088       1.1     skrll   asection *sec;
   2089       1.1     skrll   char secname[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX) + 20]
   2090       1.1     skrll     = MMIX_OTHER_SPEC_SECTION_PREFIX;
   2091       1.1     skrll   expressionS exp;
   2092       1.1     skrll   int n;
   2093       1.1     skrll 
   2094       1.1     skrll   /* Get a constant expression which we can evaluate *now*.  Supporting
   2095       1.1     skrll      more complex (though assembly-time computable) expressions is
   2096       1.1     skrll      feasible but Too Much Work for something of unknown usefulness like
   2097       1.1     skrll      BSPEC-ESPEC.  */
   2098       1.1     skrll   expsec = expression (&exp);
   2099       1.1     skrll   mmix_handle_rest_of_empty_line ();
   2100       1.1     skrll 
   2101       1.1     skrll   /* Check that we don't have another BSPEC in progress.  */
   2102       1.1     skrll   if (doing_bspec)
   2103       1.1     skrll     {
   2104       1.1     skrll       as_bad (_("BSPEC already active.  Nesting is not supported."));
   2105       1.1     skrll       return;
   2106       1.1     skrll     }
   2107       1.1     skrll 
   2108       1.1     skrll   if (exp.X_op != O_constant
   2109       1.1     skrll       || expsec != absolute_section
   2110       1.1     skrll       || exp.X_add_number < 0
   2111       1.1     skrll       || exp.X_add_number > 65535)
   2112       1.1     skrll     {
   2113       1.1     skrll       as_bad (_("invalid BSPEC expression"));
   2114       1.1     skrll       exp.X_add_number = 0;
   2115       1.1     skrll     }
   2116       1.1     skrll 
   2117       1.1     skrll   n = (int) exp.X_add_number;
   2118       1.1     skrll 
   2119       1.1     skrll   sprintf (secname + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX), "%d", n);
   2120       1.1     skrll   sec = bfd_get_section_by_name (stdoutput, secname);
   2121       1.1     skrll   if (sec == NULL)
   2122       1.1     skrll     {
   2123       1.1     skrll       /* We need a non-volatile name as it will be stored in the section
   2124       1.1     skrll          struct.  */
   2125       1.1     skrll       char *newsecname = xstrdup (secname);
   2126       1.1     skrll       sec = bfd_make_section (stdoutput, newsecname);
   2127       1.1     skrll 
   2128       1.1     skrll       if (sec == NULL)
   2129       1.1     skrll 	as_fatal (_("can't create section %s"), newsecname);
   2130       1.1     skrll 
   2131   1.1.1.7  christos       if (!bfd_set_section_flags (sec,
   2132   1.1.1.7  christos 				  bfd_section_flags (sec) | SEC_READONLY))
   2133       1.1     skrll 	as_fatal (_("can't set section flags for section %s"), newsecname);
   2134       1.1     skrll     }
   2135       1.1     skrll 
   2136       1.1     skrll   /* Tell ELF about the pending section change.  */
   2137       1.1     skrll   obj_elf_section_change_hook ();
   2138       1.1     skrll   subseg_set (sec, 0);
   2139       1.1     skrll 
   2140       1.1     skrll   /* Save position for missing ESPEC.  */
   2141   1.1.1.5  christos   bspec_file = as_where (&bspec_line);
   2142       1.1     skrll 
   2143       1.1     skrll   doing_bspec = 1;
   2144       1.1     skrll }
   2145       1.1     skrll 
   2146       1.1     skrll /* The "ESPEC" worker.  */
   2147       1.1     skrll 
   2148       1.1     skrll static void
   2149       1.1     skrll s_espec (int unused ATTRIBUTE_UNUSED)
   2150       1.1     skrll {
   2151       1.1     skrll   /* First, check that we *do* have a BSPEC in progress.  */
   2152       1.1     skrll   if (! doing_bspec)
   2153       1.1     skrll     {
   2154       1.1     skrll       as_bad (_("ESPEC without preceding BSPEC"));
   2155       1.1     skrll       return;
   2156       1.1     skrll     }
   2157       1.1     skrll 
   2158       1.1     skrll   mmix_handle_rest_of_empty_line ();
   2159       1.1     skrll   doing_bspec = 0;
   2160       1.1     skrll 
   2161       1.1     skrll   /* When we told ELF about the section change in s_bspec, it stored the
   2162       1.1     skrll      previous section for us so we can get at it with the equivalent of a
   2163       1.1     skrll      .previous pseudo.  */
   2164       1.1     skrll   obj_elf_previous (0);
   2165       1.1     skrll }
   2166       1.1     skrll 
   2167       1.1     skrll /* The " .local expr" and " local expr" worker.  We make a BFD_MMIX_LOCAL
   2168       1.1     skrll    relocation against the current position against the expression.
   2169       1.1     skrll    Implementing this by means of contents in a section lost.  */
   2170       1.1     skrll 
   2171       1.1     skrll static void
   2172       1.1     skrll mmix_s_local (int unused ATTRIBUTE_UNUSED)
   2173       1.1     skrll {
   2174       1.1     skrll   expressionS exp;
   2175       1.1     skrll 
   2176       1.1     skrll   /* Don't set the section to register contents section before the
   2177       1.1     skrll      expression has been parsed; it may refer to the current position in
   2178       1.1     skrll      some contorted way.  */
   2179       1.1     skrll   expression (&exp);
   2180       1.1     skrll 
   2181       1.1     skrll   if (exp.X_op == O_absent)
   2182       1.1     skrll     {
   2183       1.1     skrll       as_bad (_("missing local expression"));
   2184       1.1     skrll       return;
   2185       1.1     skrll     }
   2186       1.1     skrll   else if (exp.X_op == O_register)
   2187       1.1     skrll     {
   2188       1.1     skrll       /* fix_new_exp doesn't like O_register.  Should be configurable.
   2189       1.1     skrll 	 We're fine with a constant here, though.  */
   2190       1.1     skrll       exp.X_op = O_constant;
   2191       1.1     skrll     }
   2192       1.1     skrll 
   2193       1.1     skrll   fix_new_exp (frag_now, 0, 0, &exp, 0, BFD_RELOC_MMIX_LOCAL);
   2194       1.1     skrll   mmix_handle_rest_of_empty_line ();
   2195       1.1     skrll }
   2196       1.1     skrll 
   2197       1.1     skrll /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
   2198       1.1     skrll    and return it.  Sizes of other instructions are not known.  This
   2199       1.1     skrll    function may be called multiple times.  */
   2200       1.1     skrll 
   2201       1.1     skrll int
   2202       1.1     skrll md_estimate_size_before_relax (fragS *fragP, segT segment)
   2203       1.1     skrll {
   2204       1.1     skrll   int length;
   2205       1.1     skrll 
   2206       1.1     skrll #define HANDLE_RELAXABLE(state)						\
   2207       1.1     skrll  case ENCODE_RELAX (state, STATE_UNDF):					\
   2208       1.1     skrll    if (fragP->fr_symbol != NULL						\
   2209       1.1     skrll        && S_GET_SEGMENT (fragP->fr_symbol) == segment			\
   2210       1.1     skrll        && !S_IS_WEAK (fragP->fr_symbol))				\
   2211       1.1     skrll      {									\
   2212       1.1     skrll        /* The symbol lies in the same segment - a relaxable case.  */	\
   2213       1.1     skrll        fragP->fr_subtype						\
   2214       1.1     skrll 	 = ENCODE_RELAX (state, STATE_ZERO);				\
   2215       1.1     skrll      }									\
   2216       1.1     skrll    break;
   2217       1.1     skrll 
   2218       1.1     skrll   switch (fragP->fr_subtype)
   2219       1.1     skrll     {
   2220       1.1     skrll       HANDLE_RELAXABLE (STATE_GETA);
   2221       1.1     skrll       HANDLE_RELAXABLE (STATE_BCC);
   2222       1.1     skrll       HANDLE_RELAXABLE (STATE_JMP);
   2223       1.1     skrll 
   2224       1.1     skrll     case ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF):
   2225       1.1     skrll       if (fragP->fr_symbol != NULL
   2226       1.1     skrll 	  && S_GET_SEGMENT (fragP->fr_symbol) == segment
   2227       1.1     skrll 	  && !S_IS_WEAK (fragP->fr_symbol))
   2228       1.1     skrll 	/* The symbol lies in the same segment - a relaxable case.  */
   2229       1.1     skrll 	fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO);
   2230       1.1     skrll       else if (pushj_stubs)
   2231       1.1     skrll 	/* If we're to generate stubs, assume we can reach a stub after
   2232       1.1     skrll            the section.  */
   2233       1.1     skrll 	fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO);
   2234       1.1     skrll       /* FALLTHROUGH.  */
   2235       1.1     skrll     case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
   2236       1.1     skrll     case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
   2237       1.1     skrll       /* We need to distinguish different relaxation rounds.  */
   2238       1.1     skrll       seg_info (segment)->tc_segment_info_data.last_stubfrag = fragP;
   2239       1.1     skrll       break;
   2240       1.1     skrll 
   2241       1.1     skrll     case ENCODE_RELAX (STATE_GETA, STATE_ZERO):
   2242       1.1     skrll     case ENCODE_RELAX (STATE_BCC, STATE_ZERO):
   2243       1.1     skrll     case ENCODE_RELAX (STATE_JMP, STATE_ZERO):
   2244       1.1     skrll       /* When relaxing a section for the second time, we don't need to do
   2245       1.1     skrll 	 anything except making sure that fr_var is set right.  */
   2246       1.1     skrll       break;
   2247       1.1     skrll 
   2248       1.1     skrll     case STATE_GREG_DEF:
   2249       1.1     skrll       length = fragP->tc_frag_data != NULL ? 0 : 8;
   2250       1.1     skrll       fragP->fr_var = length;
   2251       1.1     skrll 
   2252       1.1     skrll       /* Don't consult the relax_table; it isn't valid for this
   2253       1.1     skrll 	 relaxation.  */
   2254       1.1     skrll       return length;
   2255       1.1     skrll       break;
   2256       1.1     skrll 
   2257       1.1     skrll     default:
   2258       1.1     skrll       BAD_CASE (fragP->fr_subtype);
   2259       1.1     skrll     }
   2260       1.1     skrll 
   2261       1.1     skrll   length = mmix_relax_table[fragP->fr_subtype].rlx_length;
   2262       1.1     skrll   fragP->fr_var = length;
   2263       1.1     skrll 
   2264       1.1     skrll   return length;
   2265       1.1     skrll }
   2266       1.1     skrll 
   2267       1.1     skrll /* Turn a string in input_line_pointer into a floating point constant of type
   2268       1.1     skrll    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
   2269       1.1     skrll    emitted is stored in *sizeP .  An error message is returned, or NULL on
   2270       1.1     skrll    OK.  */
   2271       1.1     skrll 
   2272   1.1.1.5  christos const char *
   2273       1.1     skrll md_atof (int type, char *litP, int *sizeP)
   2274       1.1     skrll {
   2275       1.1     skrll   if (type == 'r')
   2276       1.1     skrll     type = 'f';
   2277   1.1.1.5  christos   /* FIXME: Having 'f' in FLT_CHARS (and here) makes it
   2278       1.1     skrll      problematic to also have a forward reference in an expression.
   2279       1.1     skrll      The testsuite wants it, and it's customary.
   2280       1.1     skrll      We'll deal with the real problems when they come; we share the
   2281       1.1     skrll      problem with most other ports.  */
   2282   1.1.1.8  christos   return ieee_md_atof (type, litP, sizeP, true);
   2283       1.1     skrll }
   2284       1.1     skrll 
   2285       1.1     skrll /* Convert variable-sized frags into one or more fixups.  */
   2286       1.1     skrll 
   2287       1.1     skrll void
   2288       1.1     skrll md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
   2289       1.1     skrll 		 fragS *fragP)
   2290       1.1     skrll {
   2291       1.1     skrll   /* Pointer to first byte in variable-sized part of the frag.  */
   2292       1.1     skrll   char *var_partp;
   2293       1.1     skrll 
   2294       1.1     skrll   /* Pointer to first opcode byte in frag.  */
   2295       1.1     skrll   char *opcodep;
   2296       1.1     skrll 
   2297       1.1     skrll   /* Size in bytes of variable-sized part of frag.  */
   2298       1.1     skrll   int var_part_size = 0;
   2299       1.1     skrll 
   2300       1.1     skrll   /* This is part of *fragP.  It contains all information about addresses
   2301       1.1     skrll      and offsets to varying parts.  */
   2302       1.1     skrll   symbolS *symbolP;
   2303       1.1     skrll   unsigned long var_part_offset;
   2304       1.1     skrll 
   2305       1.1     skrll   /* This is the frag for the opcode.  It, rather than fragP, must be used
   2306       1.1     skrll      when emitting a frag for the opcode.  */
   2307       1.1     skrll   fragS *opc_fragP = fragP->tc_frag_data;
   2308       1.1     skrll   fixS *tmpfixP;
   2309       1.1     skrll 
   2310       1.1     skrll   /* Where, in file space, does addr point?  */
   2311       1.1     skrll   bfd_vma target_address;
   2312       1.1     skrll   bfd_vma opcode_address;
   2313       1.1     skrll 
   2314       1.1     skrll   know (fragP->fr_type == rs_machine_dependent);
   2315       1.1     skrll 
   2316       1.1     skrll   var_part_offset = fragP->fr_fix;
   2317       1.1     skrll   var_partp = fragP->fr_literal + var_part_offset;
   2318       1.1     skrll   opcodep = fragP->fr_opcode;
   2319       1.1     skrll 
   2320       1.1     skrll   symbolP = fragP->fr_symbol;
   2321       1.1     skrll 
   2322       1.1     skrll   target_address
   2323       1.1     skrll     = ((symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset);
   2324       1.1     skrll 
   2325       1.1     skrll   /* The opcode that would be extended is the last four "fixed" bytes.  */
   2326       1.1     skrll   opcode_address = fragP->fr_address + fragP->fr_fix - 4;
   2327       1.1     skrll 
   2328       1.1     skrll   switch (fragP->fr_subtype)
   2329       1.1     skrll     {
   2330       1.1     skrll     case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
   2331       1.1     skrll       /* Setting the unknown bits to 0 seems the most appropriate.  */
   2332       1.1     skrll       mmix_set_geta_branch_offset (opcodep, 0);
   2333   1.1.1.8  christos       tmpfixP = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
   2334       1.1     skrll 			 fragP->fr_symbol, fragP->fr_offset, 1,
   2335       1.1     skrll 			 BFD_RELOC_MMIX_PUSHJ_STUBBABLE);
   2336       1.1     skrll       COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
   2337       1.1     skrll       var_part_size = 0;
   2338   1.1.1.8  christos 
   2339   1.1.1.8  christos       /* This is a non-trivial fixup; we'll be calling a generated
   2340   1.1.1.8  christos 	 stub, whose address fits into the fixup.  The actual target,
   2341   1.1.1.8  christos 	 as reflected by the fixup value, is further away than fits
   2342   1.1.1.8  christos 	 into the fixup, so the generic overflow test doesn't
   2343   1.1.1.8  christos 	 apply. */
   2344   1.1.1.8  christos       tmpfixP->fx_no_overflow = 1;
   2345       1.1     skrll       break;
   2346       1.1     skrll 
   2347       1.1     skrll     case ENCODE_RELAX (STATE_GETA, STATE_ZERO):
   2348       1.1     skrll     case ENCODE_RELAX (STATE_BCC, STATE_ZERO):
   2349       1.1     skrll     case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
   2350       1.1     skrll       mmix_set_geta_branch_offset (opcodep, target_address - opcode_address);
   2351       1.1     skrll       if (linkrelax)
   2352       1.1     skrll 	{
   2353       1.1     skrll 	  tmpfixP
   2354       1.1     skrll 	    = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
   2355       1.1     skrll 		       fragP->fr_symbol, fragP->fr_offset, 1,
   2356       1.1     skrll 		       BFD_RELOC_MMIX_ADDR19);
   2357       1.1     skrll 	  COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
   2358       1.1     skrll 	}
   2359       1.1     skrll       var_part_size = 0;
   2360       1.1     skrll       break;
   2361       1.1     skrll 
   2362       1.1     skrll     case ENCODE_RELAX (STATE_JMP, STATE_ZERO):
   2363       1.1     skrll       mmix_set_jmp_offset (opcodep, target_address - opcode_address);
   2364       1.1     skrll       if (linkrelax)
   2365       1.1     skrll 	{
   2366       1.1     skrll 	  tmpfixP
   2367       1.1     skrll 	    = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
   2368       1.1     skrll 		       fragP->fr_symbol, fragP->fr_offset, 1,
   2369       1.1     skrll 		       BFD_RELOC_MMIX_ADDR27);
   2370       1.1     skrll 	  COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
   2371       1.1     skrll 	}
   2372       1.1     skrll       var_part_size = 0;
   2373       1.1     skrll       break;
   2374       1.1     skrll 
   2375       1.1     skrll     case STATE_GREG_DEF:
   2376       1.1     skrll       if (fragP->tc_frag_data == NULL)
   2377       1.1     skrll 	{
   2378       1.1     skrll 	  /* We must initialize data that's supposed to be "fixed up" to
   2379       1.1     skrll 	     avoid emitting garbage, because md_apply_fix won't do
   2380       1.1     skrll 	     anything for undefined symbols.  */
   2381       1.1     skrll 	  md_number_to_chars (var_partp, 0, 8);
   2382       1.1     skrll 	  tmpfixP
   2383       1.1     skrll 	    = fix_new (fragP, var_partp - fragP->fr_literal, 8,
   2384       1.1     skrll 		       fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_64);
   2385       1.1     skrll 	  COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
   2386       1.1     skrll 	  mmix_gregs[n_of_cooked_gregs++] = tmpfixP;
   2387       1.1     skrll 	  var_part_size = 8;
   2388       1.1     skrll 	}
   2389       1.1     skrll       else
   2390       1.1     skrll 	var_part_size = 0;
   2391       1.1     skrll       break;
   2392       1.1     skrll 
   2393       1.1     skrll #define HANDLE_MAX_RELOC(state, reloc)					\
   2394       1.1     skrll   case ENCODE_RELAX (state, STATE_MAX):					\
   2395       1.1     skrll     var_part_size							\
   2396       1.1     skrll       = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length;	\
   2397       1.1     skrll     mmix_fill_nops (var_partp, var_part_size / 4);			\
   2398       1.1     skrll     if (warn_on_expansion)						\
   2399       1.1     skrll       as_warn_where (fragP->fr_file, fragP->fr_line,			\
   2400       1.1     skrll 		     _("operand out of range, instruction expanded"));	\
   2401       1.1     skrll     tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8,	\
   2402       1.1     skrll 		       fragP->fr_symbol, fragP->fr_offset, 1, reloc);	\
   2403       1.1     skrll     COPY_FR_WHERE_TO_FX (fragP, tmpfixP);				\
   2404       1.1     skrll     break
   2405       1.1     skrll 
   2406       1.1     skrll       HANDLE_MAX_RELOC (STATE_GETA, BFD_RELOC_MMIX_GETA);
   2407       1.1     skrll       HANDLE_MAX_RELOC (STATE_BCC, BFD_RELOC_MMIX_CBRANCH);
   2408       1.1     skrll       HANDLE_MAX_RELOC (STATE_PUSHJ, BFD_RELOC_MMIX_PUSHJ);
   2409       1.1     skrll       HANDLE_MAX_RELOC (STATE_JMP, BFD_RELOC_MMIX_JMP);
   2410       1.1     skrll 
   2411       1.1     skrll     default:
   2412       1.1     skrll       BAD_CASE (fragP->fr_subtype);
   2413       1.1     skrll       break;
   2414       1.1     skrll     }
   2415       1.1     skrll 
   2416       1.1     skrll   fragP->fr_fix += var_part_size;
   2417       1.1     skrll   fragP->fr_var = 0;
   2418       1.1     skrll }
   2419       1.1     skrll 
   2420       1.1     skrll /* Applies the desired value to the specified location.
   2421       1.1     skrll    Also sets up addends for RELA type relocations.
   2422       1.1     skrll    Stolen from tc-mcore.c.
   2423       1.1     skrll 
   2424       1.1     skrll    Note that this function isn't called when linkrelax != 0.  */
   2425       1.1     skrll 
   2426       1.1     skrll void
   2427       1.1     skrll md_apply_fix (fixS *fixP, valueT *valP, segT segment)
   2428       1.1     skrll {
   2429  1.1.1.10  christos   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
   2430       1.1     skrll   /* Note: use offsetT because it is signed, valueT is unsigned.  */
   2431  1.1.1.10  christos   offsetT val = *valP;
   2432  1.1.1.10  christos   segT symsec = (fixP->fx_addsy == NULL
   2433  1.1.1.10  christos 		 ? absolute_section : S_GET_SEGMENT (fixP->fx_addsy));
   2434       1.1     skrll 
   2435       1.1     skrll   /* If the fix is relative to a symbol which is not defined, or, (if
   2436       1.1     skrll      pcrel), not in the same segment as the fix, we cannot resolve it
   2437       1.1     skrll      here.  */
   2438       1.1     skrll   if (fixP->fx_addsy != NULL
   2439       1.1     skrll       && (! S_IS_DEFINED (fixP->fx_addsy)
   2440       1.1     skrll 	  || S_IS_WEAK (fixP->fx_addsy)
   2441       1.1     skrll 	  || (fixP->fx_pcrel && symsec != segment)
   2442       1.1     skrll 	  || (! fixP->fx_pcrel
   2443       1.1     skrll 	      && symsec != absolute_section
   2444       1.1     skrll 	      && ((fixP->fx_r_type != BFD_RELOC_MMIX_REG
   2445       1.1     skrll 		   && fixP->fx_r_type != BFD_RELOC_MMIX_REG_OR_BYTE)
   2446       1.1     skrll 		  || symsec != reg_section))))
   2447       1.1     skrll     {
   2448       1.1     skrll       fixP->fx_done = 0;
   2449       1.1     skrll       return;
   2450       1.1     skrll     }
   2451       1.1     skrll   else if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
   2452       1.1     skrll 	   || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
   2453       1.1     skrll 	   || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
   2454       1.1     skrll     {
   2455       1.1     skrll       /* These are never "fixed".  */
   2456       1.1     skrll       fixP->fx_done = 0;
   2457       1.1     skrll       return;
   2458       1.1     skrll     }
   2459       1.1     skrll   else
   2460       1.1     skrll     /* We assume every other relocation is "fixed".  */
   2461       1.1     skrll     fixP->fx_done = 1;
   2462       1.1     skrll 
   2463       1.1     skrll   switch (fixP->fx_r_type)
   2464       1.1     skrll     {
   2465       1.1     skrll     case BFD_RELOC_64:
   2466       1.1     skrll     case BFD_RELOC_32:
   2467       1.1     skrll     case BFD_RELOC_24:
   2468       1.1     skrll     case BFD_RELOC_16:
   2469       1.1     skrll     case BFD_RELOC_8:
   2470       1.1     skrll     case BFD_RELOC_64_PCREL:
   2471       1.1     skrll     case BFD_RELOC_32_PCREL:
   2472       1.1     skrll     case BFD_RELOC_24_PCREL:
   2473       1.1     skrll     case BFD_RELOC_16_PCREL:
   2474       1.1     skrll     case BFD_RELOC_8_PCREL:
   2475       1.1     skrll       md_number_to_chars (buf, val, fixP->fx_size);
   2476       1.1     skrll       break;
   2477       1.1     skrll 
   2478       1.1     skrll     case BFD_RELOC_MMIX_ADDR19:
   2479       1.1     skrll       if (expand_op)
   2480       1.1     skrll 	{
   2481       1.1     skrll 	  /* This shouldn't happen.  */
   2482       1.1     skrll 	  BAD_CASE (fixP->fx_r_type);
   2483       1.1     skrll 	  break;
   2484       1.1     skrll 	}
   2485       1.1     skrll       /* FALLTHROUGH.  */
   2486       1.1     skrll     case BFD_RELOC_MMIX_GETA:
   2487       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH:
   2488       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ:
   2489       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ_STUBBABLE:
   2490       1.1     skrll       /* If this fixup is out of range, punt to the linker to emit an
   2491       1.1     skrll 	 error.  This should only happen with -no-expand.  */
   2492  1.1.1.10  christos       if (val < -((1 << 19) / 2)
   2493  1.1.1.10  christos 	  || val >= (1 << 19) / 2 - 1
   2494       1.1     skrll 	  || (val & 3) != 0)
   2495       1.1     skrll 	{
   2496       1.1     skrll 	  if (warn_on_expansion)
   2497       1.1     skrll 	    as_warn_where (fixP->fx_file, fixP->fx_line,
   2498       1.1     skrll 			   _("operand out of range"));
   2499       1.1     skrll 	  fixP->fx_done = 0;
   2500       1.1     skrll 	  val = 0;
   2501       1.1     skrll 	}
   2502       1.1     skrll       mmix_set_geta_branch_offset (buf, val);
   2503       1.1     skrll       break;
   2504       1.1     skrll 
   2505       1.1     skrll     case BFD_RELOC_MMIX_ADDR27:
   2506       1.1     skrll       if (expand_op)
   2507       1.1     skrll 	{
   2508       1.1     skrll 	  /* This shouldn't happen.  */
   2509       1.1     skrll 	  BAD_CASE (fixP->fx_r_type);
   2510       1.1     skrll 	  break;
   2511       1.1     skrll 	}
   2512       1.1     skrll       /* FALLTHROUGH.  */
   2513       1.1     skrll     case BFD_RELOC_MMIX_JMP:
   2514       1.1     skrll       /* If this fixup is out of range, punt to the linker to emit an
   2515       1.1     skrll 	 error.  This should only happen with -no-expand.  */
   2516  1.1.1.10  christos       if (val < -((1 << 27) / 2)
   2517  1.1.1.10  christos 	  || val >= (1 << 27) / 2 - 1
   2518       1.1     skrll 	  || (val & 3) != 0)
   2519       1.1     skrll 	{
   2520       1.1     skrll 	  if (warn_on_expansion)
   2521       1.1     skrll 	    as_warn_where (fixP->fx_file, fixP->fx_line,
   2522       1.1     skrll 			   _("operand out of range"));
   2523       1.1     skrll 	  fixP->fx_done = 0;
   2524       1.1     skrll 	  val = 0;
   2525       1.1     skrll 	}
   2526       1.1     skrll       mmix_set_jmp_offset (buf, val);
   2527       1.1     skrll       break;
   2528       1.1     skrll 
   2529       1.1     skrll     case BFD_RELOC_MMIX_REG_OR_BYTE:
   2530       1.1     skrll       if (fixP->fx_addsy != NULL
   2531       1.1     skrll 	  && (S_GET_SEGMENT (fixP->fx_addsy) != reg_section
   2532       1.1     skrll 	      || S_GET_VALUE (fixP->fx_addsy) > 255)
   2533       1.1     skrll 	  && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section)
   2534       1.1     skrll 	{
   2535       1.1     skrll 	  as_bad_where (fixP->fx_file, fixP->fx_line,
   2536       1.1     skrll 			_("invalid operands"));
   2537       1.1     skrll 	  /* We don't want this "symbol" appearing in output, because
   2538       1.1     skrll 	     that will fail.  */
   2539       1.1     skrll 	  fixP->fx_done = 1;
   2540       1.1     skrll 	}
   2541       1.1     skrll 
   2542       1.1     skrll       buf[0] = val;
   2543       1.1     skrll 
   2544       1.1     skrll       /* If this reloc is for a Z field, we need to adjust
   2545       1.1     skrll 	 the opcode if we got a constant here.
   2546       1.1     skrll 	 FIXME: Can we make this more robust?  */
   2547       1.1     skrll 
   2548       1.1     skrll       if ((fixP->fx_where & 3) == 3
   2549       1.1     skrll 	  && (fixP->fx_addsy == NULL
   2550       1.1     skrll 	      || S_GET_SEGMENT (fixP->fx_addsy) == absolute_section))
   2551       1.1     skrll 	buf[-3] |= IMM_OFFSET_BIT;
   2552       1.1     skrll       break;
   2553       1.1     skrll 
   2554       1.1     skrll     case BFD_RELOC_MMIX_REG:
   2555       1.1     skrll       if (fixP->fx_addsy == NULL
   2556       1.1     skrll 	  || S_GET_SEGMENT (fixP->fx_addsy) != reg_section
   2557       1.1     skrll 	  || S_GET_VALUE (fixP->fx_addsy) > 255)
   2558       1.1     skrll 	{
   2559       1.1     skrll 	  as_bad_where (fixP->fx_file, fixP->fx_line,
   2560       1.1     skrll 			_("invalid operands"));
   2561       1.1     skrll 	  fixP->fx_done = 1;
   2562       1.1     skrll 	}
   2563       1.1     skrll 
   2564       1.1     skrll       *buf = val;
   2565       1.1     skrll       break;
   2566       1.1     skrll 
   2567       1.1     skrll     case BFD_RELOC_MMIX_BASE_PLUS_OFFSET:
   2568       1.1     skrll       /* These are never "fixed".  */
   2569       1.1     skrll       fixP->fx_done = 0;
   2570       1.1     skrll       return;
   2571       1.1     skrll 
   2572       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ_1:
   2573       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ_2:
   2574       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ_3:
   2575       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH_J:
   2576       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH_1:
   2577       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH_2:
   2578       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH_3:
   2579       1.1     skrll     case BFD_RELOC_MMIX_GETA_1:
   2580       1.1     skrll     case BFD_RELOC_MMIX_GETA_2:
   2581       1.1     skrll     case BFD_RELOC_MMIX_GETA_3:
   2582       1.1     skrll     case BFD_RELOC_MMIX_JMP_1:
   2583       1.1     skrll     case BFD_RELOC_MMIX_JMP_2:
   2584       1.1     skrll     case BFD_RELOC_MMIX_JMP_3:
   2585       1.1     skrll     default:
   2586       1.1     skrll       BAD_CASE (fixP->fx_r_type);
   2587       1.1     skrll       break;
   2588       1.1     skrll     }
   2589       1.1     skrll 
   2590       1.1     skrll   if (fixP->fx_done)
   2591       1.1     skrll     /* Make sure that for completed fixups we have the value around for
   2592       1.1     skrll        use by e.g. mmix_frob_file.  */
   2593       1.1     skrll     fixP->fx_offset = val;
   2594       1.1     skrll }
   2595       1.1     skrll 
   2596       1.1     skrll /* A bsearch function for looking up a value against offsets for GREG
   2597       1.1     skrll    definitions.  */
   2598       1.1     skrll 
   2599       1.1     skrll static int
   2600       1.1     skrll cmp_greg_val_greg_symbol_fixes (const void *p1, const void *p2)
   2601       1.1     skrll {
   2602       1.1     skrll   offsetT val1 = *(offsetT *) p1;
   2603       1.1     skrll   offsetT val2 = ((struct mmix_symbol_greg_fixes *) p2)->offs;
   2604       1.1     skrll 
   2605       1.1     skrll   if (val1 >= val2 && val1 < val2 + 255)
   2606       1.1     skrll     return 0;
   2607       1.1     skrll 
   2608       1.1     skrll   if (val1 > val2)
   2609       1.1     skrll     return 1;
   2610       1.1     skrll 
   2611       1.1     skrll   return -1;
   2612       1.1     skrll }
   2613       1.1     skrll 
   2614       1.1     skrll /* Generate a machine-dependent relocation.  */
   2615       1.1     skrll 
   2616       1.1     skrll arelent *
   2617       1.1     skrll tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
   2618       1.1     skrll {
   2619       1.1     skrll   bfd_signed_vma val
   2620       1.1     skrll     = fixP->fx_offset
   2621       1.1     skrll     + (fixP->fx_addsy != NULL
   2622       1.1     skrll        && !S_IS_WEAK (fixP->fx_addsy)
   2623       1.1     skrll        && !S_IS_COMMON (fixP->fx_addsy)
   2624       1.1     skrll        ? S_GET_VALUE (fixP->fx_addsy) : 0);
   2625       1.1     skrll   arelent *relP;
   2626       1.1     skrll   bfd_reloc_code_real_type code = BFD_RELOC_NONE;
   2627       1.1     skrll   char *buf  = fixP->fx_where + fixP->fx_frag->fr_literal;
   2628       1.1     skrll   symbolS *addsy = fixP->fx_addsy;
   2629       1.1     skrll   asection *addsec = addsy == NULL ? NULL : S_GET_SEGMENT (addsy);
   2630       1.1     skrll   asymbol *baddsy = addsy != NULL ? symbol_get_bfdsym (addsy) : NULL;
   2631       1.1     skrll   bfd_vma addend
   2632       1.1     skrll     = val - (baddsy == NULL || S_IS_COMMON (addsy) || S_IS_WEAK (addsy)
   2633       1.1     skrll 	     ? 0 : bfd_asymbol_value (baddsy));
   2634       1.1     skrll 
   2635       1.1     skrll   /* A single " LOCAL expression" in the wrong section will not work when
   2636       1.1     skrll      linking to MMO; relocations for zero-content sections are then
   2637       1.1     skrll      ignored.  Normally, relocations would modify section contents, and
   2638       1.1     skrll      you'd never think or be able to do something like that.  The
   2639       1.1     skrll      relocation resulting from a LOCAL directive doesn't have an obvious
   2640       1.1     skrll      and mandatory location.  I can't figure out a way to do this better
   2641       1.1     skrll      than just helping the user around this limitation here; hopefully the
   2642       1.1     skrll      code using the local expression is around.  Putting the LOCAL
   2643       1.1     skrll      semantics in a relocation still seems right; a section didn't do.  */
   2644   1.1.1.7  christos   if (bfd_section_size (section) == 0)
   2645       1.1     skrll     as_bad_where
   2646       1.1     skrll       (fixP->fx_file, fixP->fx_line,
   2647       1.1     skrll        fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
   2648       1.1     skrll        /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
   2649       1.1     skrll 	  user-friendly, though a little bit non-substantial.  */
   2650       1.1     skrll        ? _("directive LOCAL must be placed in code or data")
   2651       1.1     skrll        : _("internal confusion: relocation in a section without contents"));
   2652       1.1     skrll 
   2653       1.1     skrll   /* FIXME: Range tests for all these.  */
   2654       1.1     skrll   switch (fixP->fx_r_type)
   2655       1.1     skrll     {
   2656       1.1     skrll     case BFD_RELOC_64:
   2657       1.1     skrll     case BFD_RELOC_32:
   2658       1.1     skrll     case BFD_RELOC_24:
   2659       1.1     skrll     case BFD_RELOC_16:
   2660       1.1     skrll     case BFD_RELOC_8:
   2661       1.1     skrll       code = fixP->fx_r_type;
   2662       1.1     skrll 
   2663       1.1     skrll       if (addsy == NULL || bfd_is_abs_section (addsec))
   2664       1.1     skrll 	{
   2665       1.1     skrll 	  /* Resolve this reloc now, as md_apply_fix would have done (not
   2666       1.1     skrll 	     called if -linkrelax).  There is no point in keeping a reloc
   2667       1.1     skrll 	     to an absolute symbol.  No reloc that is subject to
   2668       1.1     skrll 	     relaxation must be to an absolute symbol; difference
   2669       1.1     skrll 	     involving symbols in a specific section must be signalled as
   2670       1.1     skrll 	     an error if the relaxing cannot be expressed; having a reloc
   2671       1.1     skrll 	     to the resolved (now absolute) value does not help.  */
   2672       1.1     skrll 	  md_number_to_chars (buf, val, fixP->fx_size);
   2673       1.1     skrll 	  return NULL;
   2674       1.1     skrll 	}
   2675       1.1     skrll       break;
   2676       1.1     skrll 
   2677       1.1     skrll     case BFD_RELOC_64_PCREL:
   2678       1.1     skrll     case BFD_RELOC_32_PCREL:
   2679       1.1     skrll     case BFD_RELOC_24_PCREL:
   2680       1.1     skrll     case BFD_RELOC_16_PCREL:
   2681       1.1     skrll     case BFD_RELOC_8_PCREL:
   2682       1.1     skrll     case BFD_RELOC_MMIX_LOCAL:
   2683       1.1     skrll     case BFD_RELOC_VTABLE_INHERIT:
   2684       1.1     skrll     case BFD_RELOC_VTABLE_ENTRY:
   2685       1.1     skrll     case BFD_RELOC_MMIX_GETA:
   2686       1.1     skrll     case BFD_RELOC_MMIX_GETA_1:
   2687       1.1     skrll     case BFD_RELOC_MMIX_GETA_2:
   2688       1.1     skrll     case BFD_RELOC_MMIX_GETA_3:
   2689       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH:
   2690       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH_J:
   2691       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH_1:
   2692       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH_2:
   2693       1.1     skrll     case BFD_RELOC_MMIX_CBRANCH_3:
   2694       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ:
   2695       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ_1:
   2696       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ_2:
   2697       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ_3:
   2698       1.1     skrll     case BFD_RELOC_MMIX_PUSHJ_STUBBABLE:
   2699       1.1     skrll     case BFD_RELOC_MMIX_JMP:
   2700       1.1     skrll     case BFD_RELOC_MMIX_JMP_1:
   2701       1.1     skrll     case BFD_RELOC_MMIX_JMP_2:
   2702       1.1     skrll     case BFD_RELOC_MMIX_JMP_3:
   2703       1.1     skrll     case BFD_RELOC_MMIX_ADDR19:
   2704       1.1     skrll     case BFD_RELOC_MMIX_ADDR27:
   2705       1.1     skrll       code = fixP->fx_r_type;
   2706       1.1     skrll       break;
   2707       1.1     skrll 
   2708       1.1     skrll     case BFD_RELOC_MMIX_REG_OR_BYTE:
   2709       1.1     skrll       /* If we have this kind of relocation to an unknown symbol or to the
   2710       1.1     skrll 	 register contents section (that is, to a register), then we can't
   2711       1.1     skrll 	 resolve the relocation here.  */
   2712       1.1     skrll       if (addsy != NULL
   2713       1.1     skrll 	  && (bfd_is_und_section (addsec)
   2714   1.1.1.7  christos 	      || strcmp (bfd_section_name (addsec),
   2715       1.1     skrll 			 MMIX_REG_CONTENTS_SECTION_NAME) == 0))
   2716       1.1     skrll 	{
   2717       1.1     skrll 	  code = fixP->fx_r_type;
   2718       1.1     skrll 	  break;
   2719       1.1     skrll 	}
   2720       1.1     skrll 
   2721       1.1     skrll       /* If the relocation is not to the register section or to the
   2722       1.1     skrll 	 absolute section (a numeric value), then we have an error.  */
   2723       1.1     skrll       if (addsy != NULL
   2724       1.1     skrll 	  && (S_GET_SEGMENT (addsy) != real_reg_section
   2725       1.1     skrll 	      || val > 255
   2726       1.1     skrll 	      || val < 0)
   2727       1.1     skrll 	  && ! bfd_is_abs_section (addsec))
   2728       1.1     skrll 	goto badop;
   2729       1.1     skrll 
   2730       1.1     skrll       /* Set the "immediate" bit of the insn if this relocation is to Z
   2731       1.1     skrll 	 field when the value is a numeric value, i.e. not a register.  */
   2732       1.1     skrll       if ((fixP->fx_where & 3) == 3
   2733       1.1     skrll 	  && (addsy == NULL || bfd_is_abs_section (addsec)))
   2734       1.1     skrll 	buf[-3] |= IMM_OFFSET_BIT;
   2735       1.1     skrll 
   2736       1.1     skrll       buf[0] = val;
   2737       1.1     skrll       return NULL;
   2738       1.1     skrll 
   2739       1.1     skrll     case BFD_RELOC_MMIX_BASE_PLUS_OFFSET:
   2740       1.1     skrll       if (addsy != NULL
   2741   1.1.1.7  christos 	  && strcmp (bfd_section_name (addsec),
   2742       1.1     skrll 		     MMIX_REG_CONTENTS_SECTION_NAME) == 0)
   2743       1.1     skrll 	{
   2744       1.1     skrll 	  /* This changed into a register; the relocation is for the
   2745       1.1     skrll 	     register-contents section.  The constant part remains zero.  */
   2746       1.1     skrll 	  code = BFD_RELOC_MMIX_REG;
   2747       1.1     skrll 	  break;
   2748       1.1     skrll 	}
   2749       1.1     skrll 
   2750       1.1     skrll       /* If we've found out that this was indeed a register, then replace
   2751       1.1     skrll 	 with the register number.  The constant part is already zero.
   2752       1.1     skrll 
   2753       1.1     skrll 	 If we encounter any other defined symbol, then we must find a
   2754       1.1     skrll 	 suitable register and emit a reloc.  */
   2755       1.1     skrll       if (addsy == NULL || addsec != real_reg_section)
   2756       1.1     skrll 	{
   2757       1.1     skrll 	  struct mmix_symbol_gregs *gregs;
   2758       1.1     skrll 	  struct mmix_symbol_greg_fixes *fix;
   2759       1.1     skrll 
   2760       1.1     skrll 	  if (S_IS_DEFINED (addsy)
   2761       1.1     skrll 	      && !bfd_is_com_section (addsec)
   2762       1.1     skrll 	      && !S_IS_WEAK (addsy))
   2763       1.1     skrll 	    {
   2764       1.1     skrll 	      if (! symbol_section_p (addsy) && ! bfd_is_abs_section (addsec))
   2765       1.1     skrll 		as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
   2766       1.1     skrll 
   2767       1.1     skrll 	      /* If this is an absolute symbol sufficiently near
   2768       1.1     skrll 		 lowest_data_loc, then we canonicalize on the data
   2769       1.1     skrll 		 section.  Note that val is signed here; we may subtract
   2770       1.1     skrll 		 lowest_data_loc which is unsigned.  Careful with those
   2771       1.1     skrll 		 comparisons.  */
   2772       1.1     skrll 	      if (lowest_data_loc != (bfd_vma) -1
   2773       1.1     skrll 		  && (bfd_vma) val + 256 > lowest_data_loc
   2774       1.1     skrll 		  && bfd_is_abs_section (addsec))
   2775       1.1     skrll 		{
   2776  1.1.1.10  christos 		  val -= lowest_data_loc;
   2777       1.1     skrll 		  addsy = section_symbol (data_section);
   2778       1.1     skrll 		}
   2779       1.1     skrll 	      /* Likewise text section.  */
   2780       1.1     skrll 	      else if (lowest_text_loc != (bfd_vma) -1
   2781       1.1     skrll 		       && (bfd_vma) val + 256 > lowest_text_loc
   2782       1.1     skrll 		       && bfd_is_abs_section (addsec))
   2783       1.1     skrll 		{
   2784  1.1.1.10  christos 		  val -= lowest_text_loc;
   2785       1.1     skrll 		  addsy = section_symbol (text_section);
   2786       1.1     skrll 		}
   2787       1.1     skrll 	    }
   2788       1.1     skrll 
   2789       1.1     skrll 	  gregs = *symbol_get_tc (addsy);
   2790       1.1     skrll 
   2791       1.1     skrll 	  /* If that symbol does not have any associated GREG definitions,
   2792       1.1     skrll 	     we can't do anything.  */
   2793       1.1     skrll 	  if (gregs == NULL
   2794       1.1     skrll 	      || (fix = bsearch (&val, gregs->greg_fixes, gregs->n_gregs,
   2795       1.1     skrll 				 sizeof (gregs->greg_fixes[0]),
   2796       1.1     skrll 				 cmp_greg_val_greg_symbol_fixes)) == NULL
   2797       1.1     skrll 	      /* The register must not point *after* the address we want.  */
   2798       1.1     skrll 	      || fix->offs > val
   2799       1.1     skrll 	      /* Neither must the register point more than 255 bytes
   2800       1.1     skrll 		 before the address we want.  */
   2801       1.1     skrll 	      || fix->offs + 255 < val)
   2802       1.1     skrll 	    {
   2803       1.1     skrll 	      /* We can either let the linker allocate GREGs
   2804       1.1     skrll 		 automatically, or emit an error.  */
   2805       1.1     skrll 	      if (allocate_undefined_gregs_in_linker)
   2806       1.1     skrll 		{
   2807       1.1     skrll 		  /* The values in baddsy and addend are right.  */
   2808       1.1     skrll 		  code = fixP->fx_r_type;
   2809       1.1     skrll 		  break;
   2810       1.1     skrll 		}
   2811       1.1     skrll 	      else
   2812       1.1     skrll 		as_bad_where (fixP->fx_file, fixP->fx_line,
   2813       1.1     skrll 			      _("no suitable GREG definition for operands"));
   2814       1.1     skrll 	      return NULL;
   2815       1.1     skrll 	    }
   2816       1.1     skrll 	  else
   2817       1.1     skrll 	    {
   2818       1.1     skrll 	      /* Transform the base-plus-offset reloc for the actual area
   2819       1.1     skrll 		 to a reloc for the register with the address of the area.
   2820       1.1     skrll 		 Put addend for register in Z operand.  */
   2821       1.1     skrll 	      buf[1] = val - fix->offs;
   2822       1.1     skrll 	      code = BFD_RELOC_MMIX_REG;
   2823       1.1     skrll 	      baddsy
   2824       1.1     skrll 		= (bfd_get_section_by_name (stdoutput,
   2825       1.1     skrll 					    MMIX_REG_CONTENTS_SECTION_NAME)
   2826       1.1     skrll 		   ->symbol);
   2827       1.1     skrll 
   2828       1.1     skrll 	      addend = fix->fix->fx_frag->fr_address + fix->fix->fx_where;
   2829       1.1     skrll 	    }
   2830       1.1     skrll 	}
   2831       1.1     skrll       else if (S_GET_VALUE (addsy) > 255)
   2832       1.1     skrll 	as_bad_where (fixP->fx_file, fixP->fx_line,
   2833       1.1     skrll 		      _("invalid operands"));
   2834       1.1     skrll       else
   2835       1.1     skrll 	{
   2836       1.1     skrll 	  *buf = val;
   2837       1.1     skrll 	  return NULL;
   2838       1.1     skrll 	}
   2839       1.1     skrll       break;
   2840       1.1     skrll 
   2841       1.1     skrll     case BFD_RELOC_MMIX_REG:
   2842       1.1     skrll       if (addsy != NULL
   2843       1.1     skrll 	  && (bfd_is_und_section (addsec)
   2844   1.1.1.7  christos 	      || strcmp (bfd_section_name (addsec),
   2845       1.1     skrll 			 MMIX_REG_CONTENTS_SECTION_NAME) == 0))
   2846       1.1     skrll 	{
   2847       1.1     skrll 	  code = fixP->fx_r_type;
   2848       1.1     skrll 	  break;
   2849       1.1     skrll 	}
   2850       1.1     skrll 
   2851       1.1     skrll       if (addsy != NULL
   2852       1.1     skrll 	  && (addsec != real_reg_section
   2853       1.1     skrll 	      || val > 255
   2854       1.1     skrll 	      || val < 0)
   2855       1.1     skrll 	  && ! bfd_is_und_section (addsec))
   2856       1.1     skrll 	/* Drop through to error message.  */
   2857       1.1     skrll 	;
   2858       1.1     skrll       else
   2859       1.1     skrll 	{
   2860       1.1     skrll 	  buf[0] = val;
   2861       1.1     skrll 	  return NULL;
   2862       1.1     skrll 	}
   2863       1.1     skrll       /* FALLTHROUGH.  */
   2864       1.1     skrll 
   2865       1.1     skrll       /* The others are supposed to be handled by md_apply_fix.
   2866       1.1     skrll 	 FIXME: ... which isn't called when -linkrelax.  Move over
   2867       1.1     skrll 	 md_apply_fix code here for everything reasonable.  */
   2868       1.1     skrll     badop:
   2869       1.1     skrll     default:
   2870       1.1     skrll       as_bad_where
   2871       1.1     skrll 	(fixP->fx_file, fixP->fx_line,
   2872       1.1     skrll 	 _("operands were not reducible at assembly-time"));
   2873       1.1     skrll 
   2874       1.1     skrll       /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
   2875       1.1     skrll 	 assert when trying to output reg_section.  FIXME: A gas bug.  */
   2876       1.1     skrll       fixP->fx_addsy = NULL;
   2877       1.1     skrll       return NULL;
   2878       1.1     skrll     }
   2879       1.1     skrll 
   2880  1.1.1.10  christos   relP = notes_alloc (sizeof (arelent));
   2881  1.1.1.10  christos   relP->sym_ptr_ptr = notes_alloc (sizeof (asymbol *));
   2882       1.1     skrll   *relP->sym_ptr_ptr = baddsy;
   2883       1.1     skrll   relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
   2884       1.1     skrll 
   2885       1.1     skrll   relP->addend = addend;
   2886       1.1     skrll 
   2887       1.1     skrll   /* If this had been a.out, we would have had a kludge for weak symbols
   2888       1.1     skrll      here.  */
   2889       1.1     skrll 
   2890       1.1     skrll   relP->howto = bfd_reloc_type_lookup (stdoutput, code);
   2891       1.1     skrll   if (! relP->howto)
   2892       1.1     skrll     {
   2893       1.1     skrll       const char *name;
   2894       1.1     skrll 
   2895       1.1     skrll       name = S_GET_NAME (addsy);
   2896       1.1     skrll       if (name == NULL)
   2897       1.1     skrll 	name = _("<unknown>");
   2898       1.1     skrll       as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
   2899       1.1     skrll 		name, bfd_get_reloc_code_name (code));
   2900       1.1     skrll     }
   2901       1.1     skrll 
   2902       1.1     skrll   return relP;
   2903       1.1     skrll }
   2904       1.1     skrll 
   2905       1.1     skrll /* Do some reformatting of a line.  FIXME: We could transform a mmixal
   2906       1.1     skrll    line into traditional (GNU?) format, unless #NO_APP, and get rid of all
   2907       1.1     skrll    ugly labels_without_colons etc.  */
   2908       1.1     skrll 
   2909       1.1     skrll void
   2910       1.1     skrll mmix_handle_mmixal (void)
   2911       1.1     skrll {
   2912       1.1     skrll   char *insn;
   2913       1.1     skrll   char *s = input_line_pointer;
   2914       1.1     skrll   char *label = NULL;
   2915       1.1     skrll   char c;
   2916       1.1     skrll 
   2917       1.1     skrll   if (pending_label != NULL)
   2918       1.1     skrll     as_fatal (_("internal: unhandled label %s"), pending_label);
   2919       1.1     skrll 
   2920       1.1     skrll   if (mmix_gnu_syntax)
   2921       1.1     skrll     return;
   2922       1.1     skrll 
   2923       1.1     skrll   /* If we're on a line with a label, check if it's a mmixal fb-label.
   2924       1.1     skrll      Save an indicator and skip the label; it must be set only after all
   2925       1.1     skrll      fb-labels of expressions are evaluated.  */
   2926  1.1.1.10  christos   if (ISDIGIT (s[0]) && s[1] == 'H'
   2927  1.1.1.10  christos       /* A lone "1H" on a line is valid: we'll then see is_end_of_stmt()
   2928  1.1.1.10  christos 	 being true for the following character (likely a '\n' but '\n'
   2929  1.1.1.10  christos 	 doesn't count as is_whitespace).  */
   2930  1.1.1.10  christos       && (is_whitespace (s[2]) || is_end_of_stmt (s[2])))
   2931       1.1     skrll     {
   2932       1.1     skrll       current_fb_label = s[0] - '0';
   2933       1.1     skrll 
   2934       1.1     skrll       /* We have to skip the label, but also preserve the newlineness of
   2935       1.1     skrll 	 the previous character, since the caller checks that.  It's a
   2936       1.1     skrll 	 mess we blame on the caller.  */
   2937       1.1     skrll       s[1] = s[-1];
   2938       1.1     skrll       s += 2;
   2939       1.1     skrll       input_line_pointer = s;
   2940       1.1     skrll 
   2941  1.1.1.10  christos       while (is_whitespace (*s))
   2942       1.1     skrll 	s++;
   2943       1.1     skrll 
   2944       1.1     skrll       /* For errors emitted here, the book-keeping is off by one; the
   2945       1.1     skrll 	 caller is about to bump the counters.  Adjust the error messages.  */
   2946  1.1.1.10  christos       if (is_end_of_stmt (*s))
   2947       1.1     skrll 	{
   2948       1.1     skrll 	  unsigned int line;
   2949   1.1.1.5  christos 	  const char * name = as_where (&line);
   2950       1.1     skrll 	  as_bad_where (name, line + 1,
   2951       1.1     skrll 			_("[0-9]H labels may not appear alone on a line"));
   2952       1.1     skrll 	  current_fb_label = -1;
   2953       1.1     skrll 	}
   2954       1.1     skrll       if (*s == '.')
   2955       1.1     skrll 	{
   2956       1.1     skrll 	  unsigned int line;
   2957   1.1.1.5  christos 	  const char * name  = as_where (&line);
   2958       1.1     skrll 	  as_bad_where (name, line + 1,
   2959       1.1     skrll 			_("[0-9]H labels do not mix with dot-pseudos"));
   2960       1.1     skrll 	  current_fb_label = -1;
   2961       1.1     skrll 	}
   2962       1.1     skrll 
   2963       1.1     skrll       /* Back off to the last space before the opcode so we don't handle
   2964       1.1     skrll 	 the opcode as a label.  */
   2965       1.1     skrll       s--;
   2966       1.1     skrll     }
   2967       1.1     skrll   else
   2968       1.1     skrll     current_fb_label = -1;
   2969       1.1     skrll 
   2970       1.1     skrll   if (*s == '.')
   2971       1.1     skrll     {
   2972       1.1     skrll       /* If the first character is a '.', then it's a pseudodirective, not a
   2973       1.1     skrll 	 label.  Make GAS not handle label-without-colon on this line.  We
   2974       1.1     skrll 	 also don't do mmixal-specific stuff on this line.  */
   2975       1.1     skrll       label_without_colon_this_line = 0;
   2976       1.1     skrll       return;
   2977       1.1     skrll     }
   2978       1.1     skrll 
   2979  1.1.1.10  christos   if (is_end_of_stmt (*s))
   2980       1.1     skrll     /* We avoid handling empty lines here.  */
   2981       1.1     skrll     return;
   2982   1.1.1.4  christos 
   2983       1.1     skrll   if (is_name_beginner (*s))
   2984       1.1     skrll     label = s;
   2985       1.1     skrll 
   2986       1.1     skrll   /* If there is a label, skip over it.  */
   2987       1.1     skrll   while (*s && is_part_of_name (*s))
   2988       1.1     skrll     s++;
   2989       1.1     skrll 
   2990       1.1     skrll   /* Find the start of the instruction or pseudo following the label,
   2991       1.1     skrll      if there is one.  */
   2992  1.1.1.10  christos   for (insn = s; is_whitespace (*insn); insn++)
   2993       1.1     skrll     /* Empty */
   2994       1.1     skrll     ;
   2995       1.1     skrll 
   2996       1.1     skrll   /* Remove a trailing ":" off labels, as they'd otherwise be considered
   2997       1.1     skrll      part of the name.  But don't do this for local labels.  */
   2998       1.1     skrll   if (s != input_line_pointer && s[-1] == ':'
   2999       1.1     skrll       && (s - 2 != input_line_pointer
   3000       1.1     skrll 	  || ! ISDIGIT (s[-2])))
   3001       1.1     skrll     s[-1] = ' ';
   3002       1.1     skrll   else if (label != NULL
   3003       1.1     skrll 	   /* For a lone label on a line, we don't attach it to the next
   3004       1.1     skrll 	      instruction or MMIXAL-pseudo (getting its alignment).  Thus
   3005       1.1     skrll 	      is acts like a "normal" :-ended label.  Ditto if it's
   3006       1.1     skrll 	      followed by a non-MMIXAL pseudo.  */
   3007  1.1.1.10  christos 	   && !is_end_of_stmt (*insn)
   3008       1.1     skrll 	   && *insn != '.')
   3009       1.1     skrll     {
   3010       1.1     skrll       /* For labels that don't end in ":", we save it so we can later give
   3011       1.1     skrll 	 it the same alignment and address as the associated instruction.  */
   3012       1.1     skrll 
   3013       1.1     skrll       /* Make room for the label including the ending nul.  */
   3014   1.1.1.4  christos       size_t len_0 = s - label + 1;
   3015       1.1     skrll 
   3016       1.1     skrll       /* Save this label on the MMIX symbol obstack.  Saving it on an
   3017       1.1     skrll 	 obstack is needless for "IS"-pseudos, but it's harmless and we
   3018       1.1     skrll 	 avoid a little code-cluttering.  */
   3019       1.1     skrll       obstack_grow (&mmix_sym_obstack, label, len_0);
   3020       1.1     skrll       pending_label = obstack_finish (&mmix_sym_obstack);
   3021       1.1     skrll       pending_label[len_0 - 1] = 0;
   3022       1.1     skrll     }
   3023       1.1     skrll 
   3024       1.1     skrll   /* If we have a non-MMIXAL pseudo, we have not business with the rest of
   3025       1.1     skrll      the line.  */
   3026       1.1     skrll   if (*insn == '.')
   3027       1.1     skrll     return;
   3028       1.1     skrll 
   3029       1.1     skrll   /* Find local labels of operands.  Look for "[0-9][FB]" where the
   3030       1.1     skrll      characters before and after are not part of words.  Break if a single
   3031       1.1     skrll      or double quote is seen anywhere.  It means we can't have local
   3032       1.1     skrll      labels as part of list with mixed quoted and unquoted members for
   3033       1.1     skrll      mmixal compatibility but we can't have it all.  For the moment.
   3034       1.1     skrll      Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
   3035       1.1     skrll      MAGIC_FB_FORWARD_CHAR<N> respectively.  */
   3036       1.1     skrll 
   3037       1.1     skrll   /* First make sure we don't have any of the magic characters on the line
   3038       1.1     skrll      appearing as input.  */
   3039       1.1     skrll   while (*s)
   3040       1.1     skrll     {
   3041       1.1     skrll       c = *s++;
   3042  1.1.1.10  christos       if (is_end_of_stmt (c))
   3043       1.1     skrll 	break;
   3044       1.1     skrll       if (c == MAGIC_FB_BACKWARD_CHAR || c == MAGIC_FB_FORWARD_CHAR)
   3045       1.1     skrll 	as_bad (_("invalid characters in input"));
   3046       1.1     skrll     }
   3047       1.1     skrll 
   3048       1.1     skrll   /* Scan again, this time looking for ';' after operands.  */
   3049       1.1     skrll   s = insn;
   3050       1.1     skrll 
   3051       1.1     skrll   /* Skip the insn.  */
   3052  1.1.1.10  christos   while (! is_whitespace (*s) && ! is_end_of_stmt (*s))
   3053       1.1     skrll     s++;
   3054       1.1     skrll 
   3055       1.1     skrll   /* Skip the spaces after the insn.  */
   3056  1.1.1.10  christos   while (is_whitespace (*s))
   3057       1.1     skrll     s++;
   3058       1.1     skrll 
   3059       1.1     skrll   /* Skip the operands.  While doing this, replace [0-9][BF] with
   3060       1.1     skrll      (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9].  */
   3061  1.1.1.10  christos   while (! is_whitespace (c = *s) && ! is_end_of_stmt (c))
   3062       1.1     skrll     {
   3063       1.1     skrll       if (c == '"')
   3064       1.1     skrll 	{
   3065       1.1     skrll 	  s++;
   3066       1.1     skrll 
   3067       1.1     skrll 	  /* FIXME: Test-case for semi-colon in string.  */
   3068  1.1.1.10  christos 	  while (*s != '"'
   3069  1.1.1.10  christos 		 && (! is_end_of_stmt (*s) || *s == ';'))
   3070       1.1     skrll 	    s++;
   3071       1.1     skrll 
   3072       1.1     skrll 	  if (*s == '"')
   3073       1.1     skrll 	    s++;
   3074       1.1     skrll 	}
   3075       1.1     skrll       else if (ISDIGIT (c))
   3076       1.1     skrll 	{
   3077       1.1     skrll 	  if ((s[1] != 'B' && s[1] != 'F')
   3078       1.1     skrll 	      || is_part_of_name (s[-1])
   3079       1.1     skrll 	      || is_part_of_name (s[2])
   3080       1.1     skrll 	      /* Don't treat e.g. #1F as a local-label reference.  */
   3081       1.1     skrll 	      || (s != input_line_pointer && s[-1] == '#'))
   3082       1.1     skrll 	    s++;
   3083       1.1     skrll 	  else
   3084       1.1     skrll 	    {
   3085       1.1     skrll 	      s[0] = (s[1] == 'B'
   3086       1.1     skrll 		      ? MAGIC_FB_BACKWARD_CHAR : MAGIC_FB_FORWARD_CHAR);
   3087       1.1     skrll 	      s[1] = c;
   3088       1.1     skrll 	    }
   3089       1.1     skrll 	}
   3090       1.1     skrll       else
   3091       1.1     skrll 	s++;
   3092       1.1     skrll     }
   3093       1.1     skrll 
   3094       1.1     skrll   /* Skip any spaces after the operands.  */
   3095  1.1.1.10  christos   while (is_whitespace (*s))
   3096       1.1     skrll     s++;
   3097       1.1     skrll 
   3098       1.1     skrll   /* If we're now looking at a semi-colon, then it's an end-of-line
   3099       1.1     skrll      delimiter.  */
   3100       1.1     skrll   mmix_next_semicolon_is_eoln = (*s == ';');
   3101       1.1     skrll 
   3102       1.1     skrll   /* Make IS into an EQU by replacing it with "= ".  Only match upper-case
   3103       1.1     skrll      though; let lower-case be a syntax error.  */
   3104       1.1     skrll   s = insn;
   3105  1.1.1.10  christos   if (s[0] == 'I' && s[1] == 'S'
   3106  1.1.1.10  christos       && (is_whitespace (s[2]) || is_end_of_stmt (s[2])))
   3107       1.1     skrll     {
   3108       1.1     skrll       *s = '=';
   3109       1.1     skrll       s[1] = ' ';
   3110       1.1     skrll 
   3111       1.1     skrll       /* Since labels can start without ":", we have to handle "X IS 42"
   3112       1.1     skrll 	 in full here, or "X" will be parsed as a label to be set at ".".  */
   3113       1.1     skrll       input_line_pointer = s;
   3114       1.1     skrll 
   3115       1.1     skrll       /* Right after this function ends, line numbers will be bumped if
   3116       1.1     skrll 	 input_line_pointer[-1] = '\n'.  We want accurate line numbers for
   3117       1.1     skrll 	 the equals call, so we bump them before the call, and make sure
   3118       1.1     skrll 	 they aren't bumped afterwards.  */
   3119       1.1     skrll       bump_line_counters ();
   3120       1.1     skrll 
   3121       1.1     skrll       /* A fb-label is valid as an IS-label.  */
   3122       1.1     skrll       if (current_fb_label >= 0)
   3123       1.1     skrll 	{
   3124       1.1     skrll 	  char *fb_name;
   3125       1.1     skrll 
   3126       1.1     skrll 	  /* We need to save this name on our symbol obstack, since the
   3127       1.1     skrll 	     string we got in fb_label_name is volatile and will change
   3128       1.1     skrll 	     with every call to fb_label_name, like those resulting from
   3129       1.1     skrll 	     parsing the IS-operand.  */
   3130       1.1     skrll 	  fb_name = fb_label_name (current_fb_label, 1);
   3131       1.1     skrll 	  obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1);
   3132       1.1     skrll 	  equals (obstack_finish (&mmix_sym_obstack), 0);
   3133       1.1     skrll 	  fb_label_instance_inc (current_fb_label);
   3134       1.1     skrll 	  current_fb_label = -1;
   3135       1.1     skrll 	}
   3136       1.1     skrll       else
   3137       1.1     skrll 	{
   3138       1.1     skrll 	  if (pending_label == NULL)
   3139       1.1     skrll 	    as_bad (_("empty label field for IS"));
   3140       1.1     skrll 	  else
   3141       1.1     skrll 	    equals (pending_label, 0);
   3142       1.1     skrll 	  pending_label = NULL;
   3143       1.1     skrll 	}
   3144       1.1     skrll 
   3145       1.1     skrll       /* For mmixal, we can have comments without a comment-start
   3146       1.1     skrll 	 character.   */
   3147       1.1     skrll       mmix_handle_rest_of_empty_line ();
   3148       1.1     skrll       input_line_pointer--;
   3149       1.1     skrll 
   3150       1.1     skrll       input_line_pointer[-1] = ' ';
   3151       1.1     skrll     }
   3152       1.1     skrll   else if (s[0] == 'G'
   3153       1.1     skrll 	   && s[1] == 'R'
   3154   1.1.1.8  christos 	   && startswith (s, "GREG")
   3155  1.1.1.10  christos 	   && (is_whitespace (s[4]) || is_end_of_stmt (s[4])))
   3156       1.1     skrll     {
   3157       1.1     skrll       input_line_pointer = s + 4;
   3158       1.1     skrll 
   3159       1.1     skrll       /* Right after this function ends, line numbers will be bumped if
   3160       1.1     skrll 	 input_line_pointer[-1] = '\n'.  We want accurate line numbers for
   3161       1.1     skrll 	 the s_greg call, so we bump them before the call, and make sure
   3162       1.1     skrll 	 they aren't bumped afterwards.  */
   3163       1.1     skrll       bump_line_counters ();
   3164       1.1     skrll 
   3165       1.1     skrll       /* A fb-label is valid as a GREG-label.  */
   3166       1.1     skrll       if (current_fb_label >= 0)
   3167       1.1     skrll 	{
   3168       1.1     skrll 	  char *fb_name;
   3169       1.1     skrll 
   3170       1.1     skrll 	  /* We need to save this name on our symbol obstack, since the
   3171       1.1     skrll 	     string we got in fb_label_name is volatile and will change
   3172       1.1     skrll 	     with every call to fb_label_name, like those resulting from
   3173       1.1     skrll 	     parsing the IS-operand.  */
   3174       1.1     skrll 	  fb_name = fb_label_name (current_fb_label, 1);
   3175       1.1     skrll 
   3176       1.1     skrll 	  /* Make sure we save the canonical name and don't get bitten by
   3177       1.1     skrll              prefixes.  */
   3178       1.1     skrll 	  obstack_1grow (&mmix_sym_obstack, ':');
   3179       1.1     skrll 	  obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1);
   3180       1.1     skrll 	  mmix_greg_internal (obstack_finish (&mmix_sym_obstack));
   3181       1.1     skrll 	  fb_label_instance_inc (current_fb_label);
   3182       1.1     skrll 	  current_fb_label = -1;
   3183       1.1     skrll 	}
   3184       1.1     skrll       else
   3185       1.1     skrll 	mmix_greg_internal (pending_label);
   3186       1.1     skrll 
   3187       1.1     skrll       /* Back up before the end-of-line marker that was skipped in
   3188       1.1     skrll 	 mmix_greg_internal.  */
   3189       1.1     skrll       input_line_pointer--;
   3190       1.1     skrll       input_line_pointer[-1] = ' ';
   3191       1.1     skrll 
   3192       1.1     skrll       pending_label = NULL;
   3193       1.1     skrll     }
   3194       1.1     skrll   else if (pending_label != NULL)
   3195       1.1     skrll     {
   3196       1.1     skrll       input_line_pointer += strlen (pending_label);
   3197       1.1     skrll 
   3198       1.1     skrll       /* See comment above about getting line numbers bumped.  */
   3199       1.1     skrll       input_line_pointer[-1] = '\n';
   3200       1.1     skrll     }
   3201       1.1     skrll }
   3202       1.1     skrll 
   3203       1.1     skrll /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
   3204       1.1     skrll    parsing an expression.
   3205       1.1     skrll 
   3206       1.1     skrll    On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
   3207       1.1     skrll    or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
   3208       1.1     skrll    We fill in the label as an expression.  */
   3209       1.1     skrll 
   3210       1.1     skrll void
   3211       1.1     skrll mmix_fb_label (expressionS *expP)
   3212       1.1     skrll {
   3213       1.1     skrll   symbolS *sym;
   3214       1.1     skrll   char *fb_internal_name;
   3215       1.1     skrll 
   3216       1.1     skrll   /* This doesn't happen when not using mmixal syntax.  */
   3217       1.1     skrll   if (mmix_gnu_syntax
   3218       1.1     skrll       || (input_line_pointer[0] != MAGIC_FB_BACKWARD_CHAR
   3219       1.1     skrll 	  && input_line_pointer[0] != MAGIC_FB_FORWARD_CHAR))
   3220       1.1     skrll     return;
   3221       1.1     skrll 
   3222       1.1     skrll   /* The current backward reference has augmentation 0.  A forward
   3223       1.1     skrll      reference has augmentation 1, unless it's the same as a fb-label on
   3224       1.1     skrll      _this_ line, in which case we add one more so we don't refer to it.
   3225       1.1     skrll      This is the semantics of mmixal; it differs to that of common
   3226       1.1     skrll      fb-labels which refer to a here-label on the current line as a
   3227       1.1     skrll      backward reference.  */
   3228       1.1     skrll   fb_internal_name
   3229       1.1     skrll     = fb_label_name (input_line_pointer[1] - '0',
   3230       1.1     skrll 		     (input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR ? 1 : 0)
   3231       1.1     skrll 		     + ((input_line_pointer[1] - '0' == current_fb_label
   3232       1.1     skrll 			 && input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR)
   3233       1.1     skrll 			? 1 : 0));
   3234       1.1     skrll 
   3235       1.1     skrll   input_line_pointer += 2;
   3236       1.1     skrll   sym = symbol_find_or_make (fb_internal_name);
   3237       1.1     skrll 
   3238       1.1     skrll   /* We don't have to clean up unrelated fields here; we just do what the
   3239       1.1     skrll      expr machinery does, but *not* just what it does for [0-9][fb], since
   3240       1.1     skrll      we need to treat those as ordinary symbols sometimes; see testcases
   3241       1.1     skrll      err-byte2.s and fb-2.s.  */
   3242       1.1     skrll   if (S_GET_SEGMENT (sym) == absolute_section)
   3243       1.1     skrll     {
   3244       1.1     skrll       expP->X_op = O_constant;
   3245       1.1     skrll       expP->X_add_number = S_GET_VALUE (sym);
   3246       1.1     skrll     }
   3247       1.1     skrll   else
   3248       1.1     skrll     {
   3249       1.1     skrll       expP->X_op = O_symbol;
   3250       1.1     skrll       expP->X_add_symbol = sym;
   3251       1.1     skrll       expP->X_add_number = 0;
   3252       1.1     skrll     }
   3253       1.1     skrll }
   3254       1.1     skrll 
   3255       1.1     skrll /* See whether we need to force a relocation into the output file.
   3256       1.1     skrll    This is used to force out switch and PC relative relocations when
   3257       1.1     skrll    relaxing.  */
   3258       1.1     skrll 
   3259       1.1     skrll int
   3260       1.1     skrll mmix_force_relocation (fixS *fixP)
   3261       1.1     skrll {
   3262       1.1     skrll   if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
   3263       1.1     skrll       || fixP->fx_r_type == BFD_RELOC_MMIX_BASE_PLUS_OFFSET)
   3264       1.1     skrll     return 1;
   3265       1.1     skrll 
   3266       1.1     skrll   if (linkrelax)
   3267       1.1     skrll     return 1;
   3268       1.1     skrll 
   3269       1.1     skrll   /* All our pcrel relocations are must-keep.  Note that md_apply_fix is
   3270       1.1     skrll      called *after* this, and will handle getting rid of the presumed
   3271       1.1     skrll      reloc; a relocation isn't *forced* other than to be handled by
   3272       1.1     skrll      md_apply_fix (or tc_gen_reloc if linkrelax).  */
   3273       1.1     skrll   if (fixP->fx_pcrel)
   3274       1.1     skrll     return 1;
   3275       1.1     skrll 
   3276       1.1     skrll   return generic_force_reloc (fixP);
   3277       1.1     skrll }
   3278       1.1     skrll 
   3279       1.1     skrll /* The location from which a PC relative jump should be calculated,
   3280       1.1     skrll    given a PC relative reloc.  */
   3281       1.1     skrll 
   3282       1.1     skrll long
   3283       1.1     skrll md_pcrel_from_section (fixS *fixP, segT sec)
   3284       1.1     skrll {
   3285  1.1.1.10  christos   if (fixP->fx_addsy != NULL
   3286       1.1     skrll       && (! S_IS_DEFINED (fixP->fx_addsy)
   3287       1.1     skrll 	  || S_GET_SEGMENT (fixP->fx_addsy) != sec))
   3288       1.1     skrll     {
   3289       1.1     skrll       /* The symbol is undefined (or is defined but not in this section).
   3290       1.1     skrll 	 Let the linker figure it out.  */
   3291       1.1     skrll       return 0;
   3292       1.1     skrll     }
   3293       1.1     skrll 
   3294       1.1     skrll   return (fixP->fx_frag->fr_address + fixP->fx_where);
   3295       1.1     skrll }
   3296       1.1     skrll 
   3297       1.1     skrll /* Adjust the symbol table.  We make reg_section relative to the real
   3298       1.1     skrll    register section.  */
   3299       1.1     skrll 
   3300       1.1     skrll void
   3301       1.1     skrll mmix_adjust_symtab (void)
   3302       1.1     skrll {
   3303       1.1     skrll   symbolS *sym;
   3304       1.1     skrll   symbolS *regsec = section_symbol (reg_section);
   3305       1.1     skrll 
   3306       1.1     skrll   for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
   3307       1.1     skrll     if (S_GET_SEGMENT (sym) == reg_section)
   3308       1.1     skrll       {
   3309       1.1     skrll 	if (sym == regsec)
   3310       1.1     skrll 	  {
   3311       1.1     skrll 	    if (S_IS_EXTERNAL (sym) || symbol_used_in_reloc_p (sym))
   3312       1.1     skrll 	      abort ();
   3313       1.1     skrll 	    symbol_remove (sym, &symbol_rootP, &symbol_lastP);
   3314       1.1     skrll 	  }
   3315       1.1     skrll 	else
   3316       1.1     skrll 	  /* Change section to the *real* register section, so it gets
   3317       1.1     skrll 	     proper treatment when writing it out.  Only do this for
   3318       1.1     skrll 	     global symbols.  This also means we don't have to check for
   3319       1.1     skrll 	     $0..$255.  */
   3320       1.1     skrll 	  S_SET_SEGMENT (sym, real_reg_section);
   3321       1.1     skrll       }
   3322       1.1     skrll }
   3323       1.1     skrll 
   3324       1.1     skrll /* This is the expansion of LABELS_WITHOUT_COLONS.
   3325       1.1     skrll    We let md_start_line_hook tweak label_without_colon_this_line, and then
   3326       1.1     skrll    this function returns the tweaked value, and sets it to 1 for the next
   3327       1.1     skrll    line.  FIXME: Very, very brittle.  Not sure it works the way I
   3328       1.1     skrll    thought at the time I first wrote this.  */
   3329       1.1     skrll 
   3330       1.1     skrll int
   3331       1.1     skrll mmix_label_without_colon_this_line (void)
   3332       1.1     skrll {
   3333       1.1     skrll   int retval = label_without_colon_this_line;
   3334       1.1     skrll 
   3335       1.1     skrll   if (! mmix_gnu_syntax)
   3336       1.1     skrll     label_without_colon_this_line = 1;
   3337       1.1     skrll 
   3338       1.1     skrll   return retval;
   3339       1.1     skrll }
   3340       1.1     skrll 
   3341       1.1     skrll /* This is the expansion of md_relax_frag.  We go through the ordinary
   3342       1.1     skrll    relax table function except when the frag is for a GREG.  Then we have
   3343       1.1     skrll    to check whether there's another GREG by the same value that we can
   3344       1.1     skrll    join with.  */
   3345       1.1     skrll 
   3346       1.1     skrll long
   3347       1.1     skrll mmix_md_relax_frag (segT seg, fragS *fragP, long stretch)
   3348       1.1     skrll {
   3349       1.1     skrll   switch (fragP->fr_subtype)
   3350       1.1     skrll     {
   3351   1.1.1.9  christos       /* Growth for this type has been handled by mmix_md_finish and
   3352       1.1     skrll 	 correctly estimated, so there's nothing more to do here.  */
   3353       1.1     skrll     case STATE_GREG_DEF:
   3354       1.1     skrll       return 0;
   3355       1.1     skrll 
   3356       1.1     skrll     case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
   3357       1.1     skrll       {
   3358       1.1     skrll 	/* We need to handle relaxation type ourselves, since relax_frag
   3359       1.1     skrll 	   doesn't update fr_subtype if there's no size increase in the
   3360       1.1     skrll 	   current section; when going from plain PUSHJ to a stub.  This
   3361       1.1     skrll 	   is otherwise functionally the same as relax_frag in write.c,
   3362       1.1     skrll 	   simplified for this case.  */
   3363       1.1     skrll 	offsetT aim;
   3364       1.1     skrll 	addressT target;
   3365       1.1     skrll 	addressT address;
   3366       1.1     skrll 	symbolS *symbolP;
   3367       1.1     skrll 	target = fragP->fr_offset;
   3368       1.1     skrll 	address = fragP->fr_address;
   3369       1.1     skrll 	symbolP = fragP->fr_symbol;
   3370       1.1     skrll 
   3371       1.1     skrll 	if (symbolP)
   3372       1.1     skrll 	  {
   3373       1.1     skrll 	    fragS *sym_frag;
   3374       1.1     skrll 
   3375       1.1     skrll 	    sym_frag = symbol_get_frag (symbolP);
   3376       1.1     skrll 	    know (S_GET_SEGMENT (symbolP) != absolute_section
   3377       1.1     skrll 		  || sym_frag == &zero_address_frag);
   3378       1.1     skrll 	    target += S_GET_VALUE (symbolP);
   3379       1.1     skrll 
   3380       1.1     skrll 	    /* If frag has yet to be reached on this pass, assume it will
   3381       1.1     skrll 	       move by STRETCH just as we did.  If this is not so, it will
   3382       1.1     skrll 	       be because some frag between grows, and that will force
   3383       1.1     skrll 	       another pass.  */
   3384       1.1     skrll 
   3385       1.1     skrll 	    if (stretch != 0
   3386       1.1     skrll 		&& sym_frag->relax_marker != fragP->relax_marker
   3387       1.1     skrll 		&& S_GET_SEGMENT (symbolP) == seg)
   3388       1.1     skrll 	      target += stretch;
   3389       1.1     skrll 	  }
   3390       1.1     skrll 
   3391       1.1     skrll 	aim = target - address - fragP->fr_fix;
   3392       1.1     skrll 	if (aim >= PUSHJ_0B && aim <= PUSHJ_0F)
   3393       1.1     skrll 	  {
   3394       1.1     skrll 	    /* Target is reachable with a PUSHJ.  */
   3395       1.1     skrll 	    segment_info_type *seginfo = seg_info (seg);
   3396       1.1     skrll 
   3397       1.1     skrll 	    /* If we're at the end of a relaxation round, clear the stub
   3398       1.1     skrll 	       counter as initialization for the next round.  */
   3399       1.1     skrll 	    if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
   3400       1.1     skrll 	      seginfo->tc_segment_info_data.nstubs = 0;
   3401       1.1     skrll 	    return 0;
   3402       1.1     skrll 	  }
   3403       1.1     skrll 
   3404       1.1     skrll 	/* Not reachable.  Try a stub.  */
   3405       1.1     skrll 	fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO);
   3406       1.1     skrll       }
   3407       1.1     skrll       /* FALLTHROUGH.  */
   3408   1.1.1.4  christos 
   3409       1.1     skrll       /* See if this PUSHJ is redirectable to a stub.  */
   3410       1.1     skrll     case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
   3411       1.1     skrll       {
   3412       1.1     skrll 	segment_info_type *seginfo = seg_info (seg);
   3413       1.1     skrll 	fragS *lastfrag = seginfo->frchainP->frch_last;
   3414       1.1     skrll 	relax_substateT prev_type = fragP->fr_subtype;
   3415       1.1     skrll 
   3416       1.1     skrll 	/* The last frag is always an empty frag, so it suffices to look
   3417       1.1     skrll 	   at its address to know the ending address of this section.  */
   3418       1.1     skrll 	know (lastfrag->fr_type == rs_fill
   3419       1.1     skrll 	      && lastfrag->fr_fix == 0
   3420       1.1     skrll 	      && lastfrag->fr_var == 0);
   3421       1.1     skrll 
   3422       1.1     skrll 	/* For this PUSHJ to be relaxable into a call to a stub, the
   3423       1.1     skrll 	   distance must be no longer than 256k bytes from the PUSHJ to
   3424       1.1     skrll 	   the end of the section plus the maximum size of stubs so far.  */
   3425       1.1     skrll 	if ((lastfrag->fr_address
   3426       1.1     skrll 	     + stretch
   3427       1.1     skrll 	     + PUSHJ_MAX_LEN * seginfo->tc_segment_info_data.nstubs)
   3428       1.1     skrll 	    - (fragP->fr_address + fragP->fr_fix)
   3429       1.1     skrll 	    > GETA_0F
   3430       1.1     skrll 	    || !pushj_stubs)
   3431       1.1     skrll 	  fragP->fr_subtype = mmix_relax_table[prev_type].rlx_more;
   3432       1.1     skrll 	else
   3433       1.1     skrll 	  seginfo->tc_segment_info_data.nstubs++;
   3434       1.1     skrll 
   3435       1.1     skrll 	/* If we're at the end of a relaxation round, clear the stub
   3436       1.1     skrll 	   counter as initialization for the next round.  */
   3437       1.1     skrll 	if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
   3438       1.1     skrll 	  seginfo->tc_segment_info_data.nstubs = 0;
   3439       1.1     skrll 
   3440  1.1.1.10  christos 	return (mmix_relax_table[fragP->fr_subtype].rlx_length
   3441  1.1.1.10  christos 		- mmix_relax_table[prev_type].rlx_length);
   3442       1.1     skrll       }
   3443       1.1     skrll 
   3444       1.1     skrll     case ENCODE_RELAX (STATE_PUSHJ, STATE_MAX):
   3445       1.1     skrll       {
   3446       1.1     skrll 	segment_info_type *seginfo = seg_info (seg);
   3447       1.1     skrll 
   3448       1.1     skrll 	/* Need to cover all STATE_PUSHJ states to act on the last stub
   3449       1.1     skrll 	   frag (the end of this relax round; initialization for the
   3450       1.1     skrll 	   next).  */
   3451       1.1     skrll 	if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
   3452       1.1     skrll 	  seginfo->tc_segment_info_data.nstubs = 0;
   3453       1.1     skrll 
   3454       1.1     skrll 	return 0;
   3455       1.1     skrll       }
   3456       1.1     skrll 
   3457       1.1     skrll     default:
   3458       1.1     skrll       return relax_frag (seg, fragP, stretch);
   3459       1.1     skrll 
   3460       1.1     skrll     case STATE_GREG_UNDF:
   3461       1.1     skrll       BAD_CASE (fragP->fr_subtype);
   3462       1.1     skrll     }
   3463       1.1     skrll 
   3464       1.1     skrll   as_fatal (_("internal: unexpected relax type %d:%d"),
   3465       1.1     skrll 	    fragP->fr_type, fragP->fr_subtype);
   3466       1.1     skrll   return 0;
   3467       1.1     skrll }
   3468       1.1     skrll 
   3469       1.1     skrll /* Various things we punt until all input is seen.  */
   3470       1.1     skrll 
   3471       1.1     skrll void
   3472   1.1.1.9  christos mmix_md_finish (void)
   3473       1.1     skrll {
   3474       1.1     skrll   fragS *fragP;
   3475       1.1     skrll   symbolS *mainsym;
   3476       1.1     skrll   asection *regsec;
   3477   1.1.1.3  christos   struct loc_assert_s *loc_assert;
   3478       1.1     skrll   int i;
   3479       1.1     skrll 
   3480       1.1     skrll   /* The first frag of GREG:s going into the register contents section.  */
   3481       1.1     skrll   fragS *mmix_reg_contents_frags = NULL;
   3482       1.1     skrll 
   3483       1.1     skrll   /* Reset prefix.  All labels reachable at this point must be
   3484       1.1     skrll      canonicalized.  */
   3485       1.1     skrll   mmix_current_prefix = NULL;
   3486       1.1     skrll 
   3487       1.1     skrll   if (doing_bspec)
   3488       1.1     skrll     as_bad_where (bspec_file, bspec_line, _("BSPEC without ESPEC."));
   3489       1.1     skrll 
   3490       1.1     skrll   /* Emit the low LOC setting of .text.  */
   3491       1.1     skrll   if (text_has_contents && lowest_text_loc != (bfd_vma) -1)
   3492       1.1     skrll     {
   3493       1.1     skrll       symbolS *symbolP;
   3494       1.1     skrll       char locsymbol[sizeof (":") - 1
   3495       1.1     skrll 		    + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1
   3496       1.1     skrll 		    + sizeof (".text")];
   3497       1.1     skrll 
   3498       1.1     skrll       /* An exercise in non-ISO-C-ness, this one.  */
   3499       1.1     skrll       sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
   3500       1.1     skrll 	       ".text");
   3501       1.1     skrll       symbolP
   3502   1.1.1.8  christos 	= symbol_new (locsymbol, absolute_section, &zero_address_frag,
   3503   1.1.1.8  christos 		      lowest_text_loc);
   3504       1.1     skrll       S_SET_EXTERNAL (symbolP);
   3505       1.1     skrll     }
   3506       1.1     skrll 
   3507       1.1     skrll   /* Ditto .data.  */
   3508       1.1     skrll   if (data_has_contents && lowest_data_loc != (bfd_vma) -1)
   3509       1.1     skrll     {
   3510       1.1     skrll       symbolS *symbolP;
   3511       1.1     skrll       char locsymbol[sizeof (":") - 1
   3512       1.1     skrll 		     + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1
   3513       1.1     skrll 		     + sizeof (".data")];
   3514       1.1     skrll 
   3515       1.1     skrll       sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
   3516       1.1     skrll 	       ".data");
   3517       1.1     skrll       symbolP
   3518   1.1.1.8  christos 	= symbol_new (locsymbol, absolute_section, &zero_address_frag,
   3519   1.1.1.8  christos 		      lowest_data_loc);
   3520       1.1     skrll       S_SET_EXTERNAL (symbolP);
   3521       1.1     skrll     }
   3522       1.1     skrll 
   3523       1.1     skrll   /* Unless GNU syntax mode, set "Main" to be a function, so the
   3524       1.1     skrll      disassembler doesn't get confused when we write truly
   3525       1.1     skrll      mmixal-compatible code (and don't use .type).  Similarly set it
   3526       1.1     skrll      global (regardless of -globalize-symbols), so the linker sees it as
   3527       1.1     skrll      the start symbol in ELF mode.  */
   3528       1.1     skrll   mainsym = symbol_find (MMIX_START_SYMBOL_NAME);
   3529       1.1     skrll   if (mainsym != NULL && ! mmix_gnu_syntax)
   3530       1.1     skrll     {
   3531       1.1     skrll       symbol_get_bfdsym (mainsym)->flags |= BSF_FUNCTION;
   3532       1.1     skrll       S_SET_EXTERNAL (mainsym);
   3533       1.1     skrll     }
   3534       1.1     skrll 
   3535   1.1.1.3  christos   /* Check that we didn't LOC into the unknown, or rather that when it
   3536   1.1.1.3  christos      was unknown, we actually change sections.  */
   3537   1.1.1.3  christos   for (loc_assert = loc_asserts;
   3538   1.1.1.3  christos        loc_assert != NULL;
   3539   1.1.1.3  christos        loc_assert = loc_assert->next)
   3540   1.1.1.3  christos     {
   3541   1.1.1.3  christos       segT actual_seg;
   3542   1.1.1.3  christos 
   3543   1.1.1.3  christos       resolve_symbol_value (loc_assert->loc_sym);
   3544   1.1.1.3  christos       actual_seg = S_GET_SEGMENT (loc_assert->loc_sym);
   3545   1.1.1.3  christos       if (actual_seg != loc_assert->old_seg)
   3546   1.1.1.3  christos 	{
   3547   1.1.1.5  christos 	  const char *fnam;
   3548   1.1.1.3  christos 	  unsigned int line;
   3549   1.1.1.3  christos 	  int e_valid = expr_symbol_where (loc_assert->loc_sym, &fnam, &line);
   3550   1.1.1.3  christos 
   3551   1.1.1.3  christos 	  gas_assert (e_valid == 1);
   3552   1.1.1.3  christos 	  as_bad_where (fnam, line,
   3553   1.1.1.3  christos 			_("LOC to section unknown or indeterminable "
   3554   1.1.1.3  christos 			  "at first pass"));
   3555   1.1.1.4  christos 
   3556   1.1.1.4  christos 	  /* Patch up the generic location data to avoid cascading
   3557   1.1.1.4  christos 	     error messages from later passes.  (See original in
   3558   1.1.1.4  christos 	     write.c:relax_segment.)  */
   3559   1.1.1.4  christos 	  fragP = loc_assert->frag;
   3560   1.1.1.4  christos 	  fragP->fr_type = rs_align;
   3561   1.1.1.4  christos 	  fragP->fr_subtype = 0;
   3562   1.1.1.4  christos 	  fragP->fr_offset = 0;
   3563   1.1.1.4  christos 	  fragP->fr_fix = 0;
   3564   1.1.1.3  christos 	}
   3565   1.1.1.3  christos     }
   3566   1.1.1.3  christos 
   3567       1.1     skrll   if (n_of_raw_gregs != 0)
   3568       1.1     skrll     {
   3569       1.1     skrll       /* Emit GREGs.  They are collected in order of appearance, but must
   3570       1.1     skrll 	 be emitted in opposite order to both have section address regno*8
   3571       1.1     skrll 	 and the same allocation order (within a file) as mmixal.  */
   3572       1.1     skrll       segT this_segment = now_seg;
   3573       1.1     skrll       subsegT this_subsegment = now_subseg;
   3574       1.1     skrll 
   3575       1.1     skrll       regsec = bfd_make_section_old_way (stdoutput,
   3576       1.1     skrll 					 MMIX_REG_CONTENTS_SECTION_NAME);
   3577       1.1     skrll       subseg_set (regsec, 0);
   3578       1.1     skrll 
   3579       1.1     skrll       /* Finally emit the initialization-value.  Emit a variable frag, which
   3580       1.1     skrll 	 we'll fix in md_estimate_size_before_relax.  We set the initializer
   3581       1.1     skrll 	 for the tc_frag_data field to NULL, so we can use that field for
   3582       1.1     skrll 	 relaxation purposes.  */
   3583       1.1     skrll       mmix_opcode_frag = NULL;
   3584       1.1     skrll 
   3585       1.1     skrll       frag_grow (0);
   3586       1.1     skrll       mmix_reg_contents_frags = frag_now;
   3587       1.1     skrll 
   3588       1.1     skrll       for (i = n_of_raw_gregs - 1; i >= 0; i--)
   3589       1.1     skrll 	{
   3590       1.1     skrll 	  if (mmix_raw_gregs[i].label != NULL)
   3591       1.1     skrll 	    /* There's a symbol.  Let it refer to this location in the
   3592       1.1     skrll 	       register contents section.  The symbol must be globalized
   3593       1.1     skrll 	       separately.  */
   3594       1.1     skrll 	    colon (mmix_raw_gregs[i].label);
   3595       1.1     skrll 
   3596       1.1     skrll 	  frag_var (rs_machine_dependent, 8, 0, STATE_GREG_UNDF,
   3597       1.1     skrll 		    make_expr_symbol (&mmix_raw_gregs[i].exp), 0, NULL);
   3598       1.1     skrll 	}
   3599       1.1     skrll 
   3600       1.1     skrll       subseg_set (this_segment, this_subsegment);
   3601       1.1     skrll     }
   3602       1.1     skrll 
   3603       1.1     skrll   regsec = bfd_get_section_by_name (stdoutput, MMIX_REG_CONTENTS_SECTION_NAME);
   3604       1.1     skrll   /* Mark the section symbol as being OK for a reloc.  */
   3605       1.1     skrll   if (regsec != NULL)
   3606       1.1     skrll     regsec->symbol->flags |= BSF_KEEP;
   3607       1.1     skrll 
   3608       1.1     skrll   /* Iterate over frags resulting from GREGs and move those that evidently
   3609       1.1     skrll      have the same value together and point one to another.
   3610       1.1     skrll 
   3611       1.1     skrll      This works in time O(N^2) but since the upper bound for non-error use
   3612       1.1     skrll      is 223, it's best to keep this simpler algorithm.  */
   3613       1.1     skrll   for (fragP = mmix_reg_contents_frags; fragP != NULL; fragP = fragP->fr_next)
   3614       1.1     skrll     {
   3615       1.1     skrll       fragS **fpp;
   3616       1.1     skrll       fragS *fp = NULL;
   3617       1.1     skrll       fragS *osymfrag;
   3618       1.1     skrll       offsetT osymval;
   3619       1.1     skrll       expressionS *oexpP;
   3620       1.1     skrll       symbolS *symbolP = fragP->fr_symbol;
   3621       1.1     skrll 
   3622       1.1     skrll       if (fragP->fr_type != rs_machine_dependent
   3623       1.1     skrll 	  || fragP->fr_subtype != STATE_GREG_UNDF)
   3624       1.1     skrll 	continue;
   3625       1.1     skrll 
   3626       1.1     skrll       /* Whatever the outcome, we will have this GREG judged merged or
   3627       1.1     skrll 	 non-merged.  Since the tc_frag_data is NULL at this point, we
   3628       1.1     skrll 	 default to non-merged.  */
   3629       1.1     skrll       fragP->fr_subtype = STATE_GREG_DEF;
   3630       1.1     skrll 
   3631       1.1     skrll       /* If we're not supposed to merge GREG definitions, then just don't
   3632       1.1     skrll 	 look for equivalents.  */
   3633       1.1     skrll       if (! merge_gregs)
   3634       1.1     skrll 	continue;
   3635       1.1     skrll 
   3636  1.1.1.10  christos       osymval = S_GET_VALUE (symbolP);
   3637       1.1     skrll       osymfrag = symbol_get_frag (symbolP);
   3638       1.1     skrll 
   3639       1.1     skrll       /* If the symbol isn't defined, we can't say that another symbol
   3640       1.1     skrll 	 equals this frag, then.  FIXME: We can look at the "deepest"
   3641       1.1     skrll 	 defined name; if a = c and b = c then obviously a == b.  */
   3642       1.1     skrll       if (! S_IS_DEFINED (symbolP))
   3643       1.1     skrll 	continue;
   3644       1.1     skrll 
   3645       1.1     skrll       oexpP = symbol_get_value_expression (fragP->fr_symbol);
   3646       1.1     skrll 
   3647       1.1     skrll       /* If the initialization value is zero, then we must not merge them.  */
   3648       1.1     skrll       if (oexpP->X_op == O_constant && osymval == 0)
   3649       1.1     skrll 	continue;
   3650       1.1     skrll 
   3651       1.1     skrll       /* Iterate through the frags downward this one.  If we find one that
   3652       1.1     skrll 	 has the same non-zero value, move it to after this one and point
   3653       1.1     skrll 	 to it as the equivalent.  */
   3654       1.1     skrll       for (fpp = &fragP->fr_next; *fpp != NULL; fpp = &fpp[0]->fr_next)
   3655       1.1     skrll 	{
   3656       1.1     skrll 	  fp = *fpp;
   3657       1.1     skrll 
   3658       1.1     skrll 	  if (fp->fr_type != rs_machine_dependent
   3659       1.1     skrll 	      || fp->fr_subtype != STATE_GREG_UNDF)
   3660       1.1     skrll 	    continue;
   3661       1.1     skrll 
   3662       1.1     skrll 	  /* Calling S_GET_VALUE may simplify the symbol, changing from
   3663       1.1     skrll 	     expr_section etc. so call it first.  */
   3664       1.1     skrll 	  if ((offsetT) S_GET_VALUE (fp->fr_symbol) == osymval
   3665       1.1     skrll 	      && symbol_get_frag (fp->fr_symbol) == osymfrag)
   3666       1.1     skrll 	    {
   3667       1.1     skrll 	      /* Move the frag links so the one we found equivalent comes
   3668       1.1     skrll 		 after the current one, carefully considering that
   3669       1.1     skrll 		 sometimes fpp == &fragP->fr_next and the moves must be a
   3670       1.1     skrll 		 NOP then.  */
   3671       1.1     skrll 	      *fpp = fp->fr_next;
   3672       1.1     skrll 	      fp->fr_next = fragP->fr_next;
   3673       1.1     skrll 	      fragP->fr_next = fp;
   3674       1.1     skrll 	      break;
   3675       1.1     skrll 	    }
   3676       1.1     skrll 	}
   3677       1.1     skrll 
   3678       1.1     skrll       if (*fpp != NULL)
   3679       1.1     skrll 	fragP->tc_frag_data = fp;
   3680       1.1     skrll     }
   3681       1.1     skrll }
   3682       1.1     skrll 
   3683       1.1     skrll /* qsort function for mmix_symbol_gregs.  */
   3684       1.1     skrll 
   3685       1.1     skrll static int
   3686       1.1     skrll cmp_greg_symbol_fixes (const void *parg, const void *qarg)
   3687       1.1     skrll {
   3688  1.1.1.10  christos   const struct mmix_symbol_greg_fixes *p = parg;
   3689  1.1.1.10  christos   const struct mmix_symbol_greg_fixes *q = qarg;
   3690       1.1     skrll 
   3691       1.1     skrll   return p->offs > q->offs ? 1 : p->offs < q->offs ? -1 : 0;
   3692       1.1     skrll }
   3693       1.1     skrll 
   3694       1.1     skrll /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
   3695       1.1     skrll    on increasing offsets onto each section symbol or undefined symbol.
   3696       1.1     skrll 
   3697       1.1     skrll    Also, remove the register convenience section so it doesn't get output
   3698       1.1     skrll    as an ELF section.  */
   3699       1.1     skrll 
   3700       1.1     skrll void
   3701       1.1     skrll mmix_frob_file (void)
   3702       1.1     skrll {
   3703       1.1     skrll   int i;
   3704       1.1     skrll   struct mmix_symbol_gregs *all_greg_symbols[MAX_GREGS];
   3705       1.1     skrll   int n_greg_symbols = 0;
   3706       1.1     skrll 
   3707       1.1     skrll   /* Collect all greg fixups and decorate each corresponding symbol with
   3708       1.1     skrll      the greg fixups for it.  */
   3709       1.1     skrll   for (i = 0; i < n_of_cooked_gregs; i++)
   3710       1.1     skrll     {
   3711       1.1     skrll       offsetT offs;
   3712       1.1     skrll       symbolS *sym;
   3713       1.1     skrll       struct mmix_symbol_gregs *gregs;
   3714       1.1     skrll       fixS *fixP;
   3715       1.1     skrll 
   3716       1.1     skrll       fixP = mmix_gregs[i];
   3717       1.1     skrll       know (fixP->fx_r_type == BFD_RELOC_64);
   3718       1.1     skrll 
   3719       1.1     skrll       /* This case isn't doable in general anyway, methinks.  */
   3720       1.1     skrll       if (fixP->fx_subsy != NULL)
   3721       1.1     skrll 	{
   3722   1.1.1.8  christos 	  as_bad_subtract (fixP);
   3723       1.1     skrll 	  continue;
   3724       1.1     skrll 	}
   3725       1.1     skrll 
   3726       1.1     skrll       sym = fixP->fx_addsy;
   3727  1.1.1.10  christos       offs = fixP->fx_offset;
   3728       1.1     skrll 
   3729       1.1     skrll       /* If the symbol is defined, then it must be resolved to a section
   3730       1.1     skrll 	 symbol at this time, or else we don't know how to handle it.  */
   3731       1.1     skrll       if (S_IS_DEFINED (sym)
   3732       1.1     skrll 	  && !bfd_is_com_section (S_GET_SEGMENT (sym))
   3733       1.1     skrll 	  && !S_IS_WEAK (sym))
   3734       1.1     skrll 	{
   3735       1.1     skrll 	  if (! symbol_section_p (sym)
   3736       1.1     skrll 	      && ! bfd_is_abs_section (S_GET_SEGMENT (sym)))
   3737       1.1     skrll 	    as_fatal (_("internal: GREG expression not resolved to section"));
   3738       1.1     skrll 
   3739       1.1     skrll 	  offs += S_GET_VALUE (sym);
   3740       1.1     skrll 	}
   3741       1.1     skrll 
   3742       1.1     skrll       /* If this is an absolute symbol sufficiently near lowest_data_loc,
   3743       1.1     skrll 	 then we canonicalize on the data section.  Note that offs is
   3744       1.1     skrll 	 signed here; we may subtract lowest_data_loc which is unsigned.
   3745       1.1     skrll 	 Careful with those comparisons.  */
   3746       1.1     skrll       if (lowest_data_loc != (bfd_vma) -1
   3747       1.1     skrll 	  && (bfd_vma) offs + 256 > lowest_data_loc
   3748       1.1     skrll 	  && bfd_is_abs_section (S_GET_SEGMENT (sym)))
   3749       1.1     skrll 	{
   3750  1.1.1.10  christos 	  offs -= lowest_data_loc;
   3751       1.1     skrll 	  sym = section_symbol (data_section);
   3752       1.1     skrll 	}
   3753       1.1     skrll       /* Likewise text section.  */
   3754       1.1     skrll       else if (lowest_text_loc != (bfd_vma) -1
   3755       1.1     skrll 	       && (bfd_vma) offs + 256 > lowest_text_loc
   3756       1.1     skrll 	       && bfd_is_abs_section (S_GET_SEGMENT (sym)))
   3757       1.1     skrll 	{
   3758  1.1.1.10  christos 	  offs -= lowest_text_loc;
   3759       1.1     skrll 	  sym = section_symbol (text_section);
   3760       1.1     skrll 	}
   3761       1.1     skrll 
   3762       1.1     skrll       gregs = *symbol_get_tc (sym);
   3763       1.1     skrll 
   3764       1.1     skrll       if (gregs == NULL)
   3765       1.1     skrll 	{
   3766   1.1.1.5  christos 	  gregs = XNEW (struct mmix_symbol_gregs);
   3767       1.1     skrll 	  gregs->n_gregs = 0;
   3768       1.1     skrll 	  symbol_set_tc (sym, &gregs);
   3769       1.1     skrll 	  all_greg_symbols[n_greg_symbols++] = gregs;
   3770       1.1     skrll 	}
   3771       1.1     skrll 
   3772       1.1     skrll       gregs->greg_fixes[gregs->n_gregs].fix = fixP;
   3773       1.1     skrll       gregs->greg_fixes[gregs->n_gregs++].offs = offs;
   3774       1.1     skrll     }
   3775       1.1     skrll 
   3776       1.1     skrll   /* For each symbol having a GREG definition, sort those definitions on
   3777       1.1     skrll      offset.  */
   3778       1.1     skrll   for (i = 0; i < n_greg_symbols; i++)
   3779       1.1     skrll     qsort (all_greg_symbols[i]->greg_fixes, all_greg_symbols[i]->n_gregs,
   3780       1.1     skrll 	   sizeof (all_greg_symbols[i]->greg_fixes[0]), cmp_greg_symbol_fixes);
   3781       1.1     skrll 
   3782       1.1     skrll   if (real_reg_section != NULL)
   3783       1.1     skrll     {
   3784       1.1     skrll       /* FIXME: Pass error state gracefully.  */
   3785   1.1.1.7  christos       if (bfd_section_flags (real_reg_section) & SEC_HAS_CONTENTS)
   3786       1.1     skrll 	as_fatal (_("register section has contents\n"));
   3787       1.1     skrll 
   3788       1.1     skrll       bfd_section_list_remove (stdoutput, real_reg_section);
   3789       1.1     skrll       --stdoutput->section_count;
   3790       1.1     skrll     }
   3791       1.1     skrll 
   3792       1.1     skrll }
   3793       1.1     skrll 
   3794       1.1     skrll /* Provide an expression for a built-in name provided when-used.
   3795       1.1     skrll    Either a symbol that is a handler; living in 0x10*[1..8] and having
   3796       1.1     skrll    name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
   3797       1.1     skrll 
   3798       1.1     skrll    If the name isn't a built-in name and parsed into *EXPP, return zero.  */
   3799       1.1     skrll 
   3800       1.1     skrll int
   3801       1.1     skrll mmix_parse_predefined_name (char *name, expressionS *expP)
   3802       1.1     skrll {
   3803       1.1     skrll   char *canon_name;
   3804   1.1.1.5  christos   const char *handler_charp;
   3805       1.1     skrll   const char handler_chars[] = "DVWIOUZX";
   3806       1.1     skrll   symbolS *symp;
   3807       1.1     skrll 
   3808       1.1     skrll   if (! predefined_syms)
   3809       1.1     skrll     return 0;
   3810       1.1     skrll 
   3811       1.1     skrll   canon_name = tc_canonicalize_symbol_name (name);
   3812       1.1     skrll 
   3813       1.1     skrll   if (canon_name[1] == '_'
   3814       1.1     skrll       && strcmp (canon_name + 2, "Handler") == 0
   3815       1.1     skrll       && (handler_charp = strchr (handler_chars, *canon_name)) != NULL)
   3816       1.1     skrll     {
   3817       1.1     skrll       /* If the symbol doesn't exist, provide one relative to the .text
   3818       1.1     skrll 	 section.
   3819       1.1     skrll 
   3820       1.1     skrll 	 FIXME: We should provide separate sections, mapped in the linker
   3821       1.1     skrll 	 script.  */
   3822       1.1     skrll       symp = symbol_find (name);
   3823       1.1     skrll       if (symp == NULL)
   3824   1.1.1.8  christos 	symp = symbol_new (name, text_section, &zero_address_frag,
   3825   1.1.1.8  christos 			   0x10 * (handler_charp + 1 - handler_chars));
   3826       1.1     skrll     }
   3827       1.1     skrll   else
   3828       1.1     skrll     {
   3829       1.1     skrll       /* These symbols appear when referenced; needed for
   3830       1.1     skrll          mmixal-compatible programs.  */
   3831       1.1     skrll       unsigned int i;
   3832       1.1     skrll 
   3833       1.1     skrll       static const struct
   3834       1.1     skrll       {
   3835       1.1     skrll 	const char *name;
   3836       1.1     skrll 	valueT val;
   3837       1.1     skrll       } predefined_abs_syms[] =
   3838       1.1     skrll 	{
   3839       1.1     skrll 	  {"Data_Segment", (valueT) 0x20 << 56},
   3840       1.1     skrll 	  {"Pool_Segment", (valueT) 0x40 << 56},
   3841       1.1     skrll 	  {"Stack_Segment", (valueT) 0x60 << 56},
   3842       1.1     skrll 	  {"StdIn", 0},
   3843       1.1     skrll 	  {"StdOut", 1},
   3844       1.1     skrll 	  {"StdErr", 2},
   3845       1.1     skrll 	  {"TextRead", 0},
   3846       1.1     skrll 	  {"TextWrite", 1},
   3847       1.1     skrll 	  {"BinaryRead", 2},
   3848       1.1     skrll 	  {"BinaryWrite", 3},
   3849       1.1     skrll 	  {"BinaryReadWrite", 4},
   3850       1.1     skrll 	  {"Halt", 0},
   3851       1.1     skrll 	  {"Fopen", 1},
   3852       1.1     skrll 	  {"Fclose", 2},
   3853       1.1     skrll 	  {"Fread", 3},
   3854       1.1     skrll 	  {"Fgets", 4},
   3855       1.1     skrll 	  {"Fgetws", 5},
   3856       1.1     skrll 	  {"Fwrite", 6},
   3857       1.1     skrll 	  {"Fputs", 7},
   3858       1.1     skrll 	  {"Fputws", 8},
   3859       1.1     skrll 	  {"Fseek", 9},
   3860       1.1     skrll 	  {"Ftell", 10},
   3861       1.1     skrll 	  {"D_BIT", 0x80},
   3862       1.1     skrll 	  {"V_BIT", 0x40},
   3863       1.1     skrll 	  {"W_BIT", 0x20},
   3864       1.1     skrll 	  {"I_BIT", 0x10},
   3865       1.1     skrll 	  {"O_BIT", 0x08},
   3866       1.1     skrll 	  {"U_BIT", 0x04},
   3867       1.1     skrll 	  {"Z_BIT", 0x02},
   3868       1.1     skrll 	  {"X_BIT", 0x01},
   3869       1.1     skrll 	  {"Inf", 0x7ff00000}
   3870       1.1     skrll 	};
   3871       1.1     skrll 
   3872       1.1     skrll       /* If it's already in the symbol table, we shouldn't do anything.  */
   3873       1.1     skrll       symp = symbol_find (name);
   3874       1.1     skrll       if (symp != NULL)
   3875       1.1     skrll 	return 0;
   3876       1.1     skrll 
   3877       1.1     skrll       for (i = 0;
   3878       1.1     skrll 	   i < sizeof (predefined_abs_syms) / sizeof (predefined_abs_syms[0]);
   3879       1.1     skrll 	   i++)
   3880       1.1     skrll 	if (strcmp (canon_name, predefined_abs_syms[i].name) == 0)
   3881       1.1     skrll 	  {
   3882       1.1     skrll 	    symbol_table_insert (symbol_new (predefined_abs_syms[i].name,
   3883       1.1     skrll 					     absolute_section,
   3884   1.1.1.8  christos 					     &zero_address_frag,
   3885   1.1.1.8  christos 					     predefined_abs_syms[i].val));
   3886       1.1     skrll 
   3887       1.1     skrll 	    /* Let gas find the symbol we just created, through its
   3888       1.1     skrll                ordinary lookup.  */
   3889       1.1     skrll 	    return 0;
   3890       1.1     skrll 	  }
   3891       1.1     skrll 
   3892       1.1     skrll       /* Not one of those symbols.  Let gas handle it.  */
   3893       1.1     skrll       return 0;
   3894       1.1     skrll     }
   3895       1.1     skrll 
   3896       1.1     skrll   expP->X_op = O_symbol;
   3897       1.1     skrll   expP->X_add_number = 0;
   3898       1.1     skrll   expP->X_add_symbol = symp;
   3899       1.1     skrll   expP->X_op_symbol = NULL;
   3900       1.1     skrll 
   3901       1.1     skrll   return 1;
   3902       1.1     skrll }
   3903       1.1     skrll 
   3904       1.1     skrll /* Just check that we don't have a BSPEC/ESPEC pair active when changing
   3905       1.1     skrll    sections "normally", and get knowledge about alignment from the new
   3906       1.1     skrll    section.  */
   3907       1.1     skrll 
   3908       1.1     skrll void
   3909       1.1     skrll mmix_md_elf_section_change_hook (void)
   3910       1.1     skrll {
   3911       1.1     skrll   if (doing_bspec)
   3912       1.1     skrll     as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
   3913       1.1     skrll 
   3914   1.1.1.7  christos   last_alignment = bfd_section_alignment (now_seg);
   3915       1.1     skrll   want_unaligned = 0;
   3916       1.1     skrll }
   3917       1.1     skrll 
   3918       1.1     skrll /* The LOC worker.  This is like s_org, but we have to support changing
   3919       1.1     skrll    section too.   */
   3920       1.1     skrll 
   3921       1.1     skrll static void
   3922       1.1     skrll s_loc (int ignore ATTRIBUTE_UNUSED)
   3923       1.1     skrll {
   3924       1.1     skrll   segT section;
   3925       1.1     skrll   expressionS exp;
   3926       1.1     skrll   char *p;
   3927       1.1     skrll   symbolS *sym;
   3928       1.1     skrll   offsetT off;
   3929       1.1     skrll 
   3930       1.1     skrll   /* Must not have a BSPEC in progress.  */
   3931       1.1     skrll   if (doing_bspec)
   3932       1.1     skrll     {
   3933       1.1     skrll       as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
   3934       1.1     skrll       return;
   3935       1.1     skrll     }
   3936       1.1     skrll 
   3937       1.1     skrll   section = expression (&exp);
   3938       1.1     skrll 
   3939       1.1     skrll   if (exp.X_op == O_illegal
   3940       1.1     skrll       || exp.X_op == O_absent
   3941   1.1.1.3  christos       || exp.X_op == O_big)
   3942       1.1     skrll     {
   3943       1.1     skrll       as_bad (_("invalid LOC expression"));
   3944       1.1     skrll       return;
   3945       1.1     skrll     }
   3946       1.1     skrll 
   3947   1.1.1.3  christos   if (section == undefined_section)
   3948   1.1.1.3  christos     {
   3949   1.1.1.3  christos       /* This is an error or a LOC with an expression involving
   3950   1.1.1.3  christos 	 forward references.  For the expression to be correctly
   3951   1.1.1.3  christos 	 evaluated, we need to force a proper symbol; gas loses track
   3952   1.1.1.3  christos 	 of the segment for "local symbols".  */
   3953   1.1.1.3  christos       if (exp.X_op == O_add)
   3954   1.1.1.3  christos 	{
   3955   1.1.1.3  christos 	  symbol_get_value_expression (exp.X_op_symbol);
   3956   1.1.1.3  christos 	  symbol_get_value_expression (exp.X_add_symbol);
   3957   1.1.1.3  christos 	}
   3958   1.1.1.3  christos       else
   3959   1.1.1.3  christos 	{
   3960   1.1.1.3  christos 	  gas_assert (exp.X_op == O_symbol);
   3961   1.1.1.3  christos 	  symbol_get_value_expression (exp.X_add_symbol);
   3962   1.1.1.3  christos 	}
   3963   1.1.1.3  christos     }
   3964   1.1.1.3  christos 
   3965       1.1     skrll   if (section == absolute_section)
   3966       1.1     skrll     {
   3967       1.1     skrll       /* Translate a constant into a suitable section.  */
   3968       1.1     skrll 
   3969       1.1     skrll       if (exp.X_add_number < ((offsetT) 0x20 << 56))
   3970       1.1     skrll 	{
   3971       1.1     skrll 	  /* Lower than Data_Segment or in the reserved area (the
   3972       1.1     skrll 	     segment number is >= 0x80, appearing negative) - assume
   3973       1.1     skrll 	     it's .text.  */
   3974       1.1     skrll 	  section = text_section;
   3975       1.1     skrll 
   3976       1.1     skrll 	  /* Save the lowest seen location, so we can pass on this
   3977       1.1     skrll 	     information to the linker.  We don't actually org to this
   3978       1.1     skrll 	     location here, we just pass on information to the linker so
   3979       1.1     skrll 	     it can put the code there for us.  */
   3980       1.1     skrll 
   3981       1.1     skrll 	  /* If there was already a loc (that has to be set lower than
   3982       1.1     skrll 	     this one), we org at (this - lower).  There's an implicit
   3983       1.1     skrll 	     "LOC 0" before any entered code.  FIXME: handled by spurious
   3984       1.1     skrll 	     settings of text_has_contents.  */
   3985       1.1     skrll 	  if (lowest_text_loc != (bfd_vma) -1
   3986       1.1     skrll 	      && (bfd_vma) exp.X_add_number < lowest_text_loc)
   3987       1.1     skrll 	    {
   3988       1.1     skrll 	      as_bad (_("LOC expression stepping backwards is not supported"));
   3989       1.1     skrll 	      exp.X_op = O_absent;
   3990       1.1     skrll 	    }
   3991       1.1     skrll 	  else
   3992       1.1     skrll 	    {
   3993       1.1     skrll 	      if (text_has_contents && lowest_text_loc == (bfd_vma) -1)
   3994       1.1     skrll 		lowest_text_loc = 0;
   3995       1.1     skrll 
   3996       1.1     skrll 	      if (lowest_text_loc == (bfd_vma) -1)
   3997       1.1     skrll 		{
   3998       1.1     skrll 		  lowest_text_loc = exp.X_add_number;
   3999       1.1     skrll 
   4000       1.1     skrll 		  /* We want only to change the section, not set an offset.  */
   4001       1.1     skrll 		  exp.X_op = O_absent;
   4002       1.1     skrll 		}
   4003       1.1     skrll 	      else
   4004       1.1     skrll 		exp.X_add_number -= lowest_text_loc;
   4005       1.1     skrll 	    }
   4006       1.1     skrll 	}
   4007       1.1     skrll       else
   4008       1.1     skrll 	{
   4009       1.1     skrll 	  /* Do the same for the .data section, except we don't have
   4010       1.1     skrll 	     to worry about exp.X_add_number carrying a sign.  */
   4011       1.1     skrll 	  section = data_section;
   4012       1.1     skrll 
   4013       1.1     skrll 	  if (exp.X_add_number < (offsetT) lowest_data_loc)
   4014       1.1     skrll 	    {
   4015       1.1     skrll 	      as_bad (_("LOC expression stepping backwards is not supported"));
   4016       1.1     skrll 	      exp.X_op = O_absent;
   4017       1.1     skrll 	    }
   4018       1.1     skrll 	  else
   4019       1.1     skrll 	    {
   4020       1.1     skrll 	      if (data_has_contents && lowest_data_loc == (bfd_vma) -1)
   4021       1.1     skrll 		lowest_data_loc = (bfd_vma) 0x20 << 56;
   4022       1.1     skrll 
   4023       1.1     skrll 	      if (lowest_data_loc == (bfd_vma) -1)
   4024       1.1     skrll 		{
   4025       1.1     skrll 		  lowest_data_loc = exp.X_add_number;
   4026       1.1     skrll 
   4027       1.1     skrll 		  /* We want only to change the section, not set an offset.  */
   4028       1.1     skrll 		  exp.X_op = O_absent;
   4029       1.1     skrll 		}
   4030       1.1     skrll 	      else
   4031       1.1     skrll 		exp.X_add_number -= lowest_data_loc;
   4032       1.1     skrll 	    }
   4033       1.1     skrll 	}
   4034       1.1     skrll     }
   4035       1.1     skrll 
   4036   1.1.1.3  christos   /* If we can't deduce the section, it must be the current one.
   4037   1.1.1.3  christos      Below, we arrange to assert this.  */
   4038   1.1.1.3  christos   if (section != now_seg && section != undefined_section)
   4039       1.1     skrll     {
   4040       1.1     skrll       obj_elf_section_change_hook ();
   4041       1.1     skrll       subseg_set (section, 0);
   4042       1.1     skrll 
   4043       1.1     skrll       /* Call our section change hooks using the official hook.  */
   4044       1.1     skrll       md_elf_section_change_hook ();
   4045       1.1     skrll     }
   4046       1.1     skrll 
   4047       1.1     skrll   if (exp.X_op != O_absent)
   4048       1.1     skrll     {
   4049   1.1.1.3  christos       symbolS *esym = NULL;
   4050   1.1.1.3  christos 
   4051       1.1     skrll       if (exp.X_op != O_constant && exp.X_op != O_symbol)
   4052       1.1     skrll 	{
   4053       1.1     skrll 	  /* Handle complex expressions.  */
   4054   1.1.1.3  christos 	  esym = sym = make_expr_symbol (&exp);
   4055       1.1     skrll 	  off = 0;
   4056       1.1     skrll 	}
   4057       1.1     skrll       else
   4058       1.1     skrll 	{
   4059       1.1     skrll 	  sym = exp.X_add_symbol;
   4060       1.1     skrll 	  off = exp.X_add_number;
   4061   1.1.1.3  christos 
   4062   1.1.1.3  christos 	  if (section == undefined_section)
   4063   1.1.1.3  christos 	    {
   4064   1.1.1.3  christos 	      /* We need an expr_symbol when tracking sections.  In
   4065   1.1.1.3  christos 		 order to make this an expr_symbol with file and line
   4066   1.1.1.3  christos 		 tracked, we have to make the exp non-trivial; not an
   4067   1.1.1.3  christos 		 O_symbol with .X_add_number == 0.  The constant part
   4068   1.1.1.3  christos 		 is unused.  */
   4069   1.1.1.3  christos 	      exp.X_add_number = 1;
   4070   1.1.1.3  christos 	      esym = make_expr_symbol (&exp);
   4071   1.1.1.3  christos 	    }
   4072   1.1.1.3  christos 	}
   4073   1.1.1.3  christos 
   4074   1.1.1.3  christos       /* Track the LOC's where we couldn't deduce the section: assert
   4075   1.1.1.3  christos 	 that we weren't supposed to change section.  */
   4076   1.1.1.3  christos       if (section == undefined_section)
   4077   1.1.1.3  christos 	{
   4078   1.1.1.3  christos 	  struct loc_assert_s *next = loc_asserts;
   4079   1.1.1.5  christos 	  loc_asserts = XNEW (struct loc_assert_s);
   4080   1.1.1.3  christos 	  loc_asserts->next = next;
   4081   1.1.1.3  christos 	  loc_asserts->old_seg = now_seg;
   4082   1.1.1.3  christos 	  loc_asserts->loc_sym = esym;
   4083   1.1.1.4  christos 	  loc_asserts->frag = frag_now;
   4084       1.1     skrll 	}
   4085       1.1     skrll 
   4086  1.1.1.10  christos       p = frag_var (rs_org, 1, 1, 0, sym, off, NULL);
   4087       1.1     skrll       *p = 0;
   4088       1.1     skrll     }
   4089       1.1     skrll 
   4090       1.1     skrll   mmix_handle_rest_of_empty_line ();
   4091       1.1     skrll }
   4092       1.1     skrll 
   4093       1.1     skrll /* The BYTE worker.  We have to support sequences of mixed "strings",
   4094       1.1     skrll    numbers and other constant "first-pass" reducible expressions separated
   4095       1.1     skrll    by comma.  */
   4096       1.1     skrll 
   4097       1.1     skrll static void
   4098       1.1     skrll mmix_byte (void)
   4099       1.1     skrll {
   4100       1.1     skrll   unsigned int c;
   4101       1.1     skrll 
   4102       1.1     skrll   if (now_seg == text_section)
   4103       1.1     skrll     text_has_contents = 1;
   4104       1.1     skrll   else if (now_seg == data_section)
   4105       1.1     skrll     data_has_contents = 1;
   4106       1.1     skrll 
   4107       1.1     skrll   do
   4108       1.1     skrll     {
   4109       1.1     skrll       SKIP_WHITESPACE ();
   4110       1.1     skrll       switch (*input_line_pointer)
   4111       1.1     skrll 	{
   4112       1.1     skrll 	case '\"':
   4113       1.1     skrll 	  ++input_line_pointer;
   4114       1.1     skrll 	  while (is_a_char (c = next_char_of_string ()))
   4115       1.1     skrll 	    {
   4116       1.1     skrll 	      FRAG_APPEND_1_CHAR (c);
   4117       1.1     skrll 	    }
   4118       1.1     skrll 
   4119       1.1     skrll 	  if (input_line_pointer[-1] != '\"')
   4120       1.1     skrll 	    {
   4121       1.1     skrll 	      /* We will only get here in rare cases involving #NO_APP,
   4122       1.1     skrll 		 where the unterminated string is not recognized by the
   4123       1.1     skrll 		 preformatting pass.  */
   4124       1.1     skrll 	      as_bad (_("unterminated string"));
   4125       1.1     skrll 	      mmix_discard_rest_of_line ();
   4126       1.1     skrll 	      return;
   4127       1.1     skrll 	    }
   4128       1.1     skrll 	  break;
   4129       1.1     skrll 
   4130       1.1     skrll 	default:
   4131       1.1     skrll 	  {
   4132       1.1     skrll 	    expressionS exp;
   4133       1.1     skrll 	    segT expseg = expression (&exp);
   4134       1.1     skrll 
   4135       1.1     skrll 	    /* We have to allow special register names as constant numbers.  */
   4136       1.1     skrll 	    if ((expseg != absolute_section && expseg != reg_section)
   4137       1.1     skrll 		|| (exp.X_op != O_constant
   4138       1.1     skrll 		    && (exp.X_op != O_register
   4139       1.1     skrll 			|| exp.X_add_number <= 255)))
   4140       1.1     skrll 	      {
   4141       1.1     skrll 		as_bad (_("BYTE expression not a pure number"));
   4142       1.1     skrll 		mmix_discard_rest_of_line ();
   4143       1.1     skrll 		return;
   4144       1.1     skrll 	      }
   4145       1.1     skrll 	    else if ((exp.X_add_number > 255 && exp.X_op != O_register)
   4146       1.1     skrll 		     || exp.X_add_number < 0)
   4147       1.1     skrll 	      {
   4148       1.1     skrll 		/* Note that mmixal does not allow negative numbers in
   4149       1.1     skrll 		   BYTE sequences, so neither should we.  */
   4150       1.1     skrll 		as_bad (_("BYTE expression not in the range 0..255"));
   4151       1.1     skrll 		mmix_discard_rest_of_line ();
   4152       1.1     skrll 		return;
   4153       1.1     skrll 	      }
   4154       1.1     skrll 
   4155       1.1     skrll 	    FRAG_APPEND_1_CHAR (exp.X_add_number);
   4156       1.1     skrll 	  }
   4157       1.1     skrll 	  break;
   4158       1.1     skrll 	}
   4159       1.1     skrll 
   4160       1.1     skrll       SKIP_WHITESPACE ();
   4161       1.1     skrll       c = *input_line_pointer++;
   4162       1.1     skrll     }
   4163       1.1     skrll   while (c == ',');
   4164       1.1     skrll 
   4165       1.1     skrll   input_line_pointer--;
   4166       1.1     skrll 
   4167       1.1     skrll   if (mmix_gnu_syntax)
   4168       1.1     skrll     demand_empty_rest_of_line ();
   4169       1.1     skrll   else
   4170       1.1     skrll     {
   4171       1.1     skrll       mmix_discard_rest_of_line ();
   4172       1.1     skrll       /* Do like demand_empty_rest_of_line and step over the end-of-line
   4173       1.1     skrll          boundary.  */
   4174       1.1     skrll       input_line_pointer++;
   4175       1.1     skrll     }
   4176       1.1     skrll 
   4177       1.1     skrll   /* Make sure we align for the next instruction.  */
   4178       1.1     skrll   last_alignment = 0;
   4179       1.1     skrll }
   4180       1.1     skrll 
   4181       1.1     skrll /* Like cons_worker, but we have to ignore "naked comments", not barf on
   4182       1.1     skrll    them.  Implements WYDE, TETRA and OCTA.  We're a little bit more
   4183       1.1     skrll    lenient than mmix_byte but FIXME: they should eventually merge.  */
   4184       1.1     skrll 
   4185       1.1     skrll static void
   4186       1.1     skrll mmix_cons (int nbytes)
   4187       1.1     skrll {
   4188       1.1     skrll   expressionS exp;
   4189       1.1     skrll 
   4190       1.1     skrll   /* If we don't have any contents, then it's ok to have a specified start
   4191       1.1     skrll      address that is not a multiple of the max data size.  We will then
   4192       1.1     skrll      align it as necessary when we get here.  Otherwise, it's a fatal sin.  */
   4193       1.1     skrll   if (now_seg == text_section)
   4194       1.1     skrll     {
   4195       1.1     skrll       if (lowest_text_loc != (bfd_vma) -1
   4196       1.1     skrll 	  && (lowest_text_loc & (nbytes - 1)) != 0)
   4197       1.1     skrll 	{
   4198       1.1     skrll 	  if (text_has_contents)
   4199       1.1     skrll 	    as_bad (_("data item with alignment larger than location"));
   4200       1.1     skrll 	  else if (want_unaligned)
   4201       1.1     skrll 	    as_bad (_("unaligned data at an absolute location is not supported"));
   4202       1.1     skrll 
   4203       1.1     skrll 	  lowest_text_loc &= ~((bfd_vma) nbytes - 1);
   4204       1.1     skrll 	  lowest_text_loc += (bfd_vma) nbytes;
   4205       1.1     skrll 	}
   4206       1.1     skrll 
   4207       1.1     skrll       text_has_contents = 1;
   4208       1.1     skrll     }
   4209       1.1     skrll   else if (now_seg == data_section)
   4210       1.1     skrll     {
   4211       1.1     skrll       if (lowest_data_loc != (bfd_vma) -1
   4212       1.1     skrll 	  && (lowest_data_loc & (nbytes - 1)) != 0)
   4213       1.1     skrll 	{
   4214       1.1     skrll 	  if (data_has_contents)
   4215       1.1     skrll 	    as_bad (_("data item with alignment larger than location"));
   4216       1.1     skrll 	  else if (want_unaligned)
   4217       1.1     skrll 	    as_bad (_("unaligned data at an absolute location is not supported"));
   4218       1.1     skrll 
   4219       1.1     skrll 	  lowest_data_loc &= ~((bfd_vma) nbytes - 1);
   4220       1.1     skrll 	  lowest_data_loc += (bfd_vma) nbytes;
   4221       1.1     skrll 	}
   4222       1.1     skrll 
   4223       1.1     skrll       data_has_contents = 1;
   4224       1.1     skrll     }
   4225       1.1     skrll 
   4226       1.1     skrll   /* Always align these unless asked not to (valid for the current pseudo).  */
   4227       1.1     skrll   if (! want_unaligned)
   4228       1.1     skrll     {
   4229       1.1     skrll       last_alignment = nbytes == 2 ? 1 : (nbytes == 4 ? 2 : 3);
   4230       1.1     skrll       frag_align (last_alignment, 0, 0);
   4231       1.1     skrll       record_alignment (now_seg, last_alignment);
   4232       1.1     skrll     }
   4233       1.1     skrll 
   4234       1.1     skrll   /* For mmixal compatibility, a label for an instruction (and emitting
   4235       1.1     skrll      pseudo) refers to the _aligned_ address.  So we have to emit the
   4236       1.1     skrll      label here.  */
   4237       1.1     skrll   if (current_fb_label >= 0)
   4238       1.1     skrll     colon (fb_label_name (current_fb_label, 1));
   4239       1.1     skrll   else if (pending_label != NULL)
   4240       1.1     skrll     {
   4241       1.1     skrll       colon (pending_label);
   4242       1.1     skrll       pending_label = NULL;
   4243       1.1     skrll     }
   4244       1.1     skrll 
   4245       1.1     skrll   SKIP_WHITESPACE ();
   4246       1.1     skrll 
   4247  1.1.1.10  christos   if (is_end_of_stmt (*input_line_pointer))
   4248       1.1     skrll     {
   4249       1.1     skrll       /* Default to zero if the expression was absent.  */
   4250       1.1     skrll 
   4251       1.1     skrll       exp.X_op = O_constant;
   4252       1.1     skrll       exp.X_add_number = 0;
   4253       1.1     skrll       exp.X_unsigned = 0;
   4254       1.1     skrll       exp.X_add_symbol = NULL;
   4255       1.1     skrll       exp.X_op_symbol = NULL;
   4256  1.1.1.10  christos       emit_expr (&exp, nbytes);
   4257       1.1     skrll     }
   4258       1.1     skrll   else
   4259       1.1     skrll     do
   4260       1.1     skrll       {
   4261       1.1     skrll 	unsigned int c;
   4262       1.1     skrll 
   4263       1.1     skrll 	switch (*input_line_pointer)
   4264       1.1     skrll 	  {
   4265       1.1     skrll 	    /* We support strings here too; each character takes up nbytes
   4266       1.1     skrll 	       bytes.  */
   4267       1.1     skrll 	  case '\"':
   4268       1.1     skrll 	    ++input_line_pointer;
   4269       1.1     skrll 	    while (is_a_char (c = next_char_of_string ()))
   4270       1.1     skrll 	      {
   4271       1.1     skrll 		exp.X_op = O_constant;
   4272       1.1     skrll 		exp.X_add_number = c;
   4273       1.1     skrll 		exp.X_unsigned = 1;
   4274  1.1.1.10  christos 		emit_expr (&exp, nbytes);
   4275       1.1     skrll 	      }
   4276       1.1     skrll 
   4277       1.1     skrll 	    if (input_line_pointer[-1] != '\"')
   4278       1.1     skrll 	      {
   4279       1.1     skrll 		/* We will only get here in rare cases involving #NO_APP,
   4280       1.1     skrll 		   where the unterminated string is not recognized by the
   4281       1.1     skrll 		   preformatting pass.  */
   4282       1.1     skrll 		as_bad (_("unterminated string"));
   4283       1.1     skrll 		mmix_discard_rest_of_line ();
   4284       1.1     skrll 		return;
   4285       1.1     skrll 	      }
   4286       1.1     skrll 	    break;
   4287       1.1     skrll 
   4288       1.1     skrll 	  default:
   4289       1.1     skrll 	    {
   4290       1.1     skrll 	      expression (&exp);
   4291  1.1.1.10  christos 	      emit_expr (&exp, nbytes);
   4292       1.1     skrll 	      SKIP_WHITESPACE ();
   4293       1.1     skrll 	    }
   4294       1.1     skrll 	    break;
   4295       1.1     skrll 	  }
   4296       1.1     skrll       }
   4297       1.1     skrll     while (*input_line_pointer++ == ',');
   4298       1.1     skrll 
   4299       1.1     skrll   input_line_pointer--;		/* Put terminator back into stream.  */
   4300       1.1     skrll 
   4301       1.1     skrll   mmix_handle_rest_of_empty_line ();
   4302       1.1     skrll 
   4303       1.1     skrll   /* We don't need to step up the counter for the current_fb_label here;
   4304       1.1     skrll      that's handled by the caller.  */
   4305       1.1     skrll }
   4306       1.1     skrll 
   4307       1.1     skrll /* The md_do_align worker.  At present, we just record an alignment to
   4308       1.1     skrll    nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
   4309       1.1     skrll    does not use the unaligned macros when attribute packed is used.
   4310       1.1     skrll    Arguably this is a GCC bug.  */
   4311       1.1     skrll 
   4312       1.1     skrll void
   4313       1.1     skrll mmix_md_do_align (int n, char *fill ATTRIBUTE_UNUSED,
   4314       1.1     skrll 		  int len ATTRIBUTE_UNUSED, int max ATTRIBUTE_UNUSED)
   4315       1.1     skrll {
   4316       1.1     skrll   last_alignment = n;
   4317       1.1     skrll   want_unaligned = n == 0;
   4318       1.1     skrll }
   4319