home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Source / GNU / cctools / as / i386.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-12  |  68.3 KB  |  2,255 lines

  1. /* i386.c -- Assemble code for the Intel 80386
  2.    Copyright (C) 1989, Free Software Foundation.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.    
  20. /*
  21.   Intel 80386 machine specific gas.
  22.   Written by Eliot Dresselhaus (eliot@mgm.mit.edu).
  23.   Bugs & suggestions are completely welcome.  This is free software.
  24.   Please help us make it better.
  25. */
  26.  
  27. #include <stdio.h>
  28. #include <varargs.h>
  29. #include <ctype.h>
  30.  
  31. #ifdef __GNUC__
  32. #define alloca __builtin_alloca
  33. #else
  34. extern char *alloca();
  35. #endif
  36. #ifdef USG
  37. #define index strchr
  38. #endif
  39.  
  40. #include "as.h"
  41. #include "read.h"
  42. #include "flonum.h"
  43. #include "obstack.h"
  44. #include "frags.h"
  45. #include "struc-symbol.h"
  46. #include "expr.h"
  47. #include "symbols.h"
  48. #include "hash.h"
  49. #include "md.h"
  50. #include "i386.h"
  51. #include "i386-opcode.h"
  52.  
  53. long omagic = OMAGIC;
  54. char FLT_CHARS[] = "fFdDxX";
  55. char EXP_CHARS[] = "eE";
  56. char line_comment_chars[] = "#";
  57. char comment_chars[] = "#";
  58.  
  59. /* tables for lexical analysis */
  60. static char opcode_chars[256];
  61. static char register_chars[256];
  62. static char operand_chars[256];
  63. static char space_chars[256];
  64. static char identifier_chars[256];
  65. static char digit_chars[256];
  66.  
  67. /* lexical macros */
  68. #define is_opcode_char(x) (opcode_chars[(unsigned char) x])
  69. #define is_operand_char(x) (operand_chars[(unsigned char) x])
  70. #define is_register_char(x) (register_chars[(unsigned char) x])
  71. #define is_space_char(x) (space_chars[(unsigned char) x])
  72. #define is_identifier_char(x) (identifier_chars[(unsigned char) x])
  73. #define is_digit_char(x) (digit_chars[(unsigned char) x])
  74.  
  75. /* put here all non-digit non-letter charcters that may occur in an operand */
  76. static char operand_special_chars[] = "%$-+(,)*._~/<>|&^!:";
  77.  
  78. static char *ordinal_names[] = { "first", "second", "third" };    /* for printfs */
  79.  
  80. /* md_assemble() always leaves the strings it's passed unaltered.  To
  81.    effect this we maintain a stack of saved characters that we've smashed
  82.    with '\0's (indicating end of strings for various sub-fields of the
  83.    assembler instruction). */
  84. static char save_stack[32];
  85. static char *save_stack_p;    /* stack pointer */
  86. #define END_STRING_AND_SAVE(s)      *save_stack_p++ = *s; *s = '\0'
  87. #define RESTORE_END_STRING(s)       *s = *--save_stack_p
  88.  
  89. /* The instruction we're assembling. */
  90. static i386_insn i;
  91.  
  92. /* Per instruction expressionS buffers: 2 displacements & 2 immediate max. */
  93. static expressionS disp_expressions[2], im_expressions[2];
  94.  
  95. /* pointers to ebp & esp entries in reg_hash hash table */
  96. static reg_entry *ebp, *esp;
  97.  
  98. static int this_operand;    /* current operand we are working on */
  99.  
  100. /*
  101. Interface to relax_segment.
  102. There are 2 relax states for 386 jump insns: one for conditional & one
  103. for unconditional jumps.  This is because the these two types of jumps
  104. add different sizes to frags when we're figuring out what sort of jump
  105. to choose to reach a given label.  */
  106.  
  107. /* types */
  108. #define COND_JUMP 1        /* conditional jump */
  109. #define UNCOND_JUMP 2        /* unconditional jump */
  110. /* sizes */
  111. #define BYTE 0
  112. #define WORD 1
  113. #define DWORD 2
  114. #define UNKNOWN_SIZE 3
  115.  
  116. #define ENCODE_RELAX_STATE(type,size) ((type<<2) | (size))
  117. #define SIZE_FROM_RELAX_STATE(s) \
  118.   ( (((s) & 0x3) == BYTE ? 1 : (((s) & 0x3) == WORD ? 2 : 4)) )
  119.  
  120. const relax_typeS md_relax_table[] = {
  121. /*
  122.   The fields are:
  123.    1) most positive reach of this state,
  124.    2) most negative reach of this state,
  125.    3) how many bytes this mode will add to the size of the current frag
  126.    4) which index into the table to try if we can't fit into this one.
  127. */
  128.   {1, 1, 0, 0},
  129.   {1, 1, 0, 0},
  130.   {1, 1, 0, 0},
  131.   {1, 1, 0, 0},
  132.  
  133.   /* For now we don't use word displacement jumps:  they may be
  134.      untrustworthy. */
  135.   {127+1, -128+1, 0, ENCODE_RELAX_STATE(COND_JUMP,DWORD) },
  136.   /* word conditionals add 3 bytes to frag:
  137.          2 opcode prefix; 1 displacement bytes */
  138.   {32767+2, -32768+2, 3, ENCODE_RELAX_STATE(COND_JUMP,DWORD) },
  139.   /* dword conditionals adds 4 bytes to frag:
  140.          1 opcode prefix; 3 displacement bytes */
  141.   {0, 0, 4, 0},
  142.   {1, 1, 0, 0},
  143.  
  144.   {127+1, -128+1, 0, ENCODE_RELAX_STATE(UNCOND_JUMP,DWORD) },
  145.   /* word jmp adds 2 bytes to frag:
  146.          1 opcode prefix; 1 displacement bytes */
  147.   {32767+2, -32768+2, 2, ENCODE_RELAX_STATE(UNCOND_JUMP,DWORD) },
  148.   /* dword jmp adds 3 bytes to frag:
  149.          0 opcode prefix; 3 displacement bytes */
  150.   {0, 0, 3, 0},
  151.   {1, 1, 0, 0},
  152.  
  153. };
  154.  
  155. void float_cons (), cons ();
  156.  
  157. /* Ignore certain directives generated by gcc. This probably should
  158.    not be here. */
  159. void dummy ()
  160. {
  161.   while (*input_line_pointer && *input_line_pointer != '\n')
  162.     input_line_pointer++;
  163. }
  164.  
  165. const pseudo_typeS md_pseudo_table[] = {
  166.     { "ffloat",    float_cons,    'f' },
  167.     { "dfloat",    float_cons,    'd' },
  168.     { "tfloat",    float_cons,    'x' },
  169.     { "value",      cons,           2 },
  170.     { "ident",      dummy,          0   }, /* ignore these directives */
  171.     { "def",        dummy,          0   },
  172.     { "optim",    dummy,        0   }, /* For sun386i cc */
  173.     { "version",    dummy,          0   },
  174.     { "ln",    dummy,          0   },
  175.     { 0, 0, 0 }
  176. };
  177.  
  178. /* for interface with expression () */
  179. extern char * input_line_pointer;
  180. char * index ();
  181.  
  182. char * output_invalid ();
  183. reg_entry * parse_register ();
  184.  
  185. /* obstack for constructing various things in md_begin */
  186. struct obstack o;
  187.  
  188. /* hash table for opcode lookup */
  189. static struct hash_control *op_hash = (struct hash_control *) 0;
  190. /* hash table for register lookup */
  191. static struct hash_control *reg_hash = (struct hash_control *) 0;
  192. /* hash table for prefix lookup */
  193. static struct hash_control *prefix_hash = (struct hash_control *) 0;
  194.  
  195.  
  196. void md_begin ()
  197. {
  198.   char * hash_err;
  199.  
  200.   obstack_begin (&o,4096);
  201.  
  202.   /* initialize op_hash hash table */
  203.   op_hash = hash_new();        /* xmalloc handles error */
  204.  
  205.   {
  206.     register template *optab;
  207.     register templates *core_optab;
  208.     char *prev_name;
  209.  
  210.     optab = i386_optab;        /* setup for loop */
  211.     prev_name = optab->name;
  212.     obstack_grow (&o, optab, sizeof(template));
  213.     core_optab = (templates *) xmalloc (sizeof (templates));
  214.  
  215.     for (optab++; optab < i386_optab_end; optab++) {
  216.       if (! strcmp (optab->name, prev_name)) {
  217.     /* same name as before --> append to current template list */
  218.     obstack_grow (&o, optab, sizeof(template));
  219.       } else {
  220.     /* different name --> ship out current template list;
  221.        add to hash table; & begin anew */
  222.     /* Note: end must be set before start! since obstack_next_free changes
  223.        upon opstack_finish */
  224.     core_optab->end = (template *) obstack_next_free(&o);
  225.     core_optab->start = (template *) obstack_finish(&o);
  226.     hash_err = hash_insert (op_hash, prev_name, (char *) core_optab);
  227.     if (hash_err && *hash_err) {
  228.     hash_error:
  229.       as_fatal("Internal Error:  Can't hash %s: %s",prev_name, hash_err);
  230.     }
  231.     prev_name = optab->name;
  232.     core_optab = (templates *) xmalloc (sizeof(templates));
  233.     obstack_grow (&o, optab, sizeof(template));
  234.       }
  235.     }
  236.   }
  237.   
  238.   /* initialize reg_hash hash table */
  239.   reg_hash = hash_new();
  240.   {
  241.     register reg_entry *regtab;
  242.  
  243.     for (regtab = i386_regtab; regtab < i386_regtab_end; regtab++) {
  244.       hash_err = hash_insert (reg_hash, regtab->reg_name, regtab);
  245.       if (hash_err && *hash_err) goto hash_error;
  246.     }
  247.   }
  248.  
  249.   esp = (reg_entry *) hash_find (reg_hash, "esp");
  250.   ebp = (reg_entry *) hash_find (reg_hash, "ebp");
  251.   
  252.   /* initialize reg_hash hash table */
  253.   prefix_hash = hash_new();
  254.   {
  255.     register prefix_entry *prefixtab;
  256.  
  257.     for (prefixtab = i386_prefixtab;
  258.      prefixtab < i386_prefixtab_end; prefixtab++) {
  259.       hash_err = hash_insert (prefix_hash, prefixtab->prefix_name, prefixtab);
  260.       if (hash_err && *hash_err) goto hash_error;
  261.     }
  262.   }
  263.  
  264.   /* fill in lexical tables:  opcode_chars, operand_chars, space_chars */
  265.   {  
  266.     register unsigned int c;
  267.     
  268.     bzero (opcode_chars, sizeof(opcode_chars));
  269.     bzero (operand_chars, sizeof(operand_chars));
  270.     bzero (space_chars, sizeof(space_chars));
  271.     bzero (identifier_chars, sizeof(identifier_chars));
  272.     bzero (digit_chars, sizeof(digit_chars));
  273.  
  274.     for (c = 0; c < 256; c++) {
  275.       if (islower(c) || isdigit(c)) {
  276.     opcode_chars[c] = c;
  277.     register_chars[c] = c;
  278.       } else if (isupper(c)) {
  279.     opcode_chars[c] = tolower(c);
  280.     register_chars[c] = opcode_chars[c];
  281.       } else if (c == PREFIX_SEPERATOR) {
  282.     opcode_chars[c] = c;
  283.       } else if (c == ')' || c == '(') {
  284.     register_chars[c] = c;
  285.       }
  286.       
  287.       if (isupper(c) || islower(c) || isdigit(c))
  288.     operand_chars[c] = c;
  289.       else if (c && index(operand_special_chars, c))
  290.       operand_chars[c] = c;
  291.       
  292.       if (isdigit(c) || c == '-') digit_chars[c] = c;
  293.  
  294.       if (isalpha(c) || c == '_' || c == '.' || isdigit(c))
  295.     identifier_chars[c] = c;
  296.  
  297.       if (c == ' ' || c == '\t') space_chars[c] = c;
  298.     }
  299.   }
  300. }
  301.  
  302. void md_end() {}        /* not much to do here. */
  303.  
  304.  
  305. #ifdef DEBUG386
  306.  
  307. /* debugging routines for md_assemble */
  308. static void pi (), pte (), pt (), pe (), ps ();
  309.  
  310. static void pi (line, x)
  311.      char * line;
  312.      i386_insn *x;
  313. {
  314.   register template *p;
  315.   int i;
  316.  
  317.   fprintf (stdout, "%s: template ", line);
  318.   pte (&x->tm);
  319.   fprintf (stdout, "  modrm:  mode %x  reg %x  reg/mem %x",
  320.        x->rm.mode, x->rm.reg, x->rm.regmem);
  321.   fprintf (stdout, " base %x  index %x  scale %x\n",
  322.        x->bi.base, x->bi.index, x->bi.scale);
  323.   for (i = 0; i < x->operands; i++) {
  324.     fprintf (stdout, "    #%d:  ", i+1);
  325.     pt (x->types[i]);
  326.     fprintf (stdout, "\n");
  327.     if (x->types[i] & Reg) fprintf (stdout, "%s\n", x->regs[i]->reg_name);
  328.     if (x->types[i] & Imm) pe (x->imms[i]);
  329.     if (x->types[i] & (Disp|Abs)) pe (x->disps[i]);
  330.   }
  331. }
  332.  
  333. static void pte (t)
  334.      template *t;
  335. {
  336.   int i;
  337.   fprintf (stdout, " %d operands ", t->operands);
  338.   fprintf (stdout, "opcode %x ",
  339.        t->base_opcode);
  340.   if (t->extension_opcode != None)
  341.     fprintf (stdout, "ext %x ", t->extension_opcode);
  342.   if (t->opcode_modifier&D)
  343.     fprintf (stdout, "D");
  344.   if (t->opcode_modifier&W)
  345.     fprintf (stdout, "W");
  346.   fprintf (stdout, "\n");
  347.   for (i = 0; i < t->operands; i++) {
  348.     fprintf (stdout, "    #%d type ", i+1);
  349.     pt (t->operand_types[i]);
  350.     fprintf (stdout, "\n");
  351.   }
  352. }
  353.  
  354. char *seg_names[] = {
  355. "SEG_ABSOLUTE", "SEG_TEXT", "SEG_DATA", "SEG_BSS", "SEG_UNKNOWN",
  356. "SEG_NONE", "SEG_PASS1", "SEG_GOOF", "SEG_BIG", "SEG_DIFFERENCE" };
  357.  
  358. static void pe (e)
  359.      expressionS *e;
  360. {
  361.   fprintf (stdout, "    segment       %s\n", seg_names[(int) e->X_seg]);
  362.   fprintf (stdout, "    add_number    %d (%x)\n",
  363.        e->X_add_number, e->X_add_number);
  364.   if (e->X_add_symbol) {
  365.     fprintf (stdout, "    add_symbol    ");
  366.     ps (e->X_add_symbol);
  367.     fprintf (stdout, "\n");
  368.   }
  369.   if (e->X_subtract_symbol) {
  370.     fprintf (stdout, "    sub_symbol    ");
  371.     ps (e->X_subtract_symbol);
  372.     fprintf (stdout, "\n");
  373.   }
  374. }
  375.  
  376. #define SYMBOL_TYPE(t) \
  377.   (((t&N_TYPE) == N_UNDF) ? "UNDEFINED" : \
  378.    (((t&N_TYPE) == N_ABS) ? "ABSOLUTE" : \
  379.     (((t&N_TYPE) == N_TEXT) ? "TEXT" : \
  380.      (((t&N_TYPE) == N_DATA) ? "DATA" : \
  381.       (((t&N_TYPE) == N_BSS) ? "BSS" : "Bad n_type!")))))
  382.  
  383. static void ps (s)
  384.      symbolS *s;
  385. {
  386.   fprintf (stdout, "%s type %s%s",
  387.        s->sy_nlist.n_un.n_name,
  388.        (s->sy_nlist.n_type&N_EXT) ? "EXTERNAL " : "",
  389.        SYMBOL_TYPE (s->sy_nlist.n_type));
  390. }
  391.  
  392. struct type_name {
  393.   uint mask;
  394.   char *tname;
  395. } type_names[] = {
  396.   { Reg8, "r8" }, { Reg16, "r16" }, { Reg32, "r32" }, { Imm8, "i8" },
  397.   { Imm8S, "i8s" },
  398.   { Imm16, "i16" }, { Imm32, "i32" }, { Mem8, "Mem8"}, { Mem16, "Mem16"},
  399.   { Mem32, "Mem32"}, { BaseIndex, "BaseIndex" },
  400.   { Abs8, "Abs8" }, { Abs16, "Abs16" }, { Abs32, "Abs32" },
  401.   { Disp8, "d8" }, { Disp16, "d16" },
  402.   { Disp32, "d32" }, { SReg2, "SReg2" }, { SReg3, "SReg3" }, { Acc, "Acc" },
  403.   { InOutPortReg, "InOutPortReg" }, { ShiftCount, "ShiftCount" },
  404.   { Imm1, "i1" }, { Control, "control reg" }, {Test, "test reg"},
  405.   { FloatReg, "FReg"}, {FloatAcc, "FAcc"},
  406.   { JumpAbsolute, "Jump Absolute"},
  407.   { 0, "" }
  408. };
  409.  
  410. static void pt (t)
  411.      uint t;
  412. {
  413.   register struct type_name *ty;
  414.  
  415.   if (t == Unknown) {
  416.     fprintf (stdout, "Unknown");
  417.   } else {
  418.     for (ty = type_names; ty->mask; ty++)
  419.       if (t & ty->mask) fprintf (stdout, "%s, ", ty->tname);
  420.   }
  421.   fflush (stdout);
  422. }
  423.  
  424. #endif /* DEBUG386 */
  425.  
  426. /*
  427.   This is the guts of the machine-dependent assembler.  LINE points to a
  428.   machine dependent instruction.  This funciton is supposed to emit
  429.   the frags/bytes it assembles to.
  430.  */
  431. void md_assemble (line)
  432.      char *line;
  433. {
  434.   /* Holds temlate once we've found it. */
  435.   register template * t;
  436.  
  437.   /* Possible templates for current insn */
  438.   templates *current_templates = (templates *) 0;
  439.  
  440.   /* Initialize globals. */
  441.   bzero (&i, sizeof(i));
  442.   bzero (disp_expressions, sizeof(disp_expressions));
  443.   bzero (im_expressions, sizeof(im_expressions));
  444.   save_stack_p = save_stack;    /* reset stack pointer */
  445.   
  446.   /* Fist parse an opcode & call i386_operand for the operands.
  447.      We assume that the scrubber has arranged it so that line[0] is the valid 
  448.      start of a (possibly prefixed) opcode. */
  449.   {
  450.     register char *l = line;        /* Fast place to put LINE. */
  451.  
  452.     /* TRUE if operand is pending after ','. */
  453.     uint expecting_operand = 0;
  454.     /* TRUE if we found a prefix only acceptable with string insns. */
  455.     uint expecting_string_instruction = 0;
  456.     /* Non-zero if operand parens not balenced. */
  457.     uint paren_not_balenced;
  458.     char * token_start = l;
  459.  
  460.     while (! is_space_char(*l) && *l != END_OF_INSN) {
  461.       if (! is_opcode_char(*l)) {
  462.     as_bad ("invalid character %s in opcode", output_invalid(*l));
  463.     return;
  464.       } else if (*l != PREFIX_SEPERATOR) {
  465.     *l = opcode_chars[(unsigned char) *l];    /* fold case of opcodes */
  466.     l++;
  467.       } else {      /* this opcode's got a prefix */
  468.     register int q;
  469.     register prefix_entry * prefix;
  470.  
  471.     if (l == token_start) {
  472.       as_bad ("expecting prefix; got nothing");
  473.       return;
  474.     }
  475.     END_STRING_AND_SAVE (l);
  476.     prefix = (prefix_entry *) hash_find (prefix_hash, token_start);
  477.     if (! prefix) {
  478.       as_bad ("no such opcode prefix ('%s')", token_start);
  479.       return;
  480.     }
  481.     RESTORE_END_STRING (l);
  482.     /* check for repeated prefix */
  483.     for (q = 0; q < i.prefixes; q++)
  484.       if (i.prefix[q] == prefix->prefix_code) {
  485.         as_bad ("same prefix used twice; you don't really want this!");
  486.         return;
  487.       }
  488.     if (i.prefixes == MAX_PREFIXES) {
  489.       as_bad ("too many opcode prefixes");
  490.       return;
  491.     }
  492.     i.prefix[i.prefixes++] = prefix->prefix_code;
  493.     if (prefix->prefix_code == REPE || prefix->prefix_code == REPNE)
  494.       expecting_string_instruction = TRUE;
  495.     /* skip past PREFIX_SEPERATOR and reset token_start */
  496.     token_start = ++l;
  497.       }
  498.     }
  499.     END_STRING_AND_SAVE (l);
  500.     if (token_start == l) {
  501.       as_bad ("expecting opcode; got nothing");
  502.       return;
  503.     }
  504.  
  505.     /* Lookup insn in hash; try intel & att naming conventions if appropriate;
  506.        that is:  we only use the opcode suffix 'b' 'w' or 'l' if we need to. */
  507.     current_templates = (templates *) hash_find (op_hash, token_start);
  508.     if (! current_templates) {
  509.       int last_index = strlen(token_start) - 1;
  510.       char last_char = token_start[last_index];
  511.       switch (last_char) {
  512.       case DWORD_OPCODE_SUFFIX:
  513.       case WORD_OPCODE_SUFFIX:
  514.       case BYTE_OPCODE_SUFFIX:
  515.     token_start[last_index] = '\0';
  516.     current_templates = (templates *) hash_find (op_hash, token_start);
  517.     token_start[last_index] = last_char;
  518.     i.suffix = last_char;
  519.       }
  520.       if (!current_templates) {
  521.     as_bad ("no such 386 instruction: `%s'", token_start); return;
  522.       }
  523.     }
  524.     RESTORE_END_STRING (l);
  525.  
  526.     /* check for rep/repne without a string instruction */
  527.     if (expecting_string_instruction &&
  528.     ! IS_STRING_INSTRUCTION (current_templates->
  529.                  start->base_opcode)) {
  530.       as_bad ("expecting string instruction after rep/repne");
  531.       return;
  532.     }
  533.  
  534.     /* There may be operands to parse. */
  535. #ifdef NeXT
  536.     /* The kludge in the comment below has the bug where a segment override
  537.        is not picked up if it is part of the operand.  For example:
  538.         movsl    %fs:0(%esi),0(%edi)
  539.        does not pick up the segment override %fs.  Also of course by ignoring
  540.        all characters of the operands will confuse users when errors are not
  541.        checked at all.  This is a hairy fix as the struct i386_insn was changed
  542.        in i386.h and i386_operand() was changed and some very special case
  543.        checking for each of the string instructions was added. (bug #26409) */
  544.     if (*l != END_OF_INSN)
  545. #else /* !defined(NeXT) */
  546.     if (*l != END_OF_INSN &&
  547.     /* For string instructions, we ignore any operands if given.  This
  548.        kludges, for example, 'rep/movsb %ds:(%esi), %es:(%edi)' where
  549.        the operands are always going to be the same, and are not really
  550.        encoded in machine code. */
  551.     ! IS_STRING_INSTRUCTION (current_templates->
  552.                  start->base_opcode))
  553. #endif /* NeXT */
  554.     {
  555.       /* parse operands */
  556.       do {
  557.     /* skip optional white space before operand */
  558.     while (! is_operand_char(*l) && *l != END_OF_INSN) {
  559.       if (! is_space_char(*l)) {
  560.         as_bad ("invalid character %s before %s operand",
  561.              output_invalid(*l),
  562.              ordinal_names[i.operands]);
  563.         return;
  564.       }
  565.       l++;
  566.     }
  567.     token_start = l;        /* after white space */
  568.     paren_not_balenced = 0;
  569.     while (paren_not_balenced || *l != ',') {
  570.       if (*l == END_OF_INSN) {
  571.         if (paren_not_balenced) {
  572.           as_bad ("unbalenced parenthesis in %s operand.",
  573.                ordinal_names[i.operands]);
  574.           return;
  575.         } else break;        /* we are done */
  576.       } else if (! is_operand_char(*l)) {
  577.         as_bad ("invalid character %s in %s operand",
  578.              output_invalid(*l),
  579.              ordinal_names[i.operands]);
  580.         return;
  581.       }
  582.       if (*l == '(') ++paren_not_balenced;
  583.       if (*l == ')') --paren_not_balenced;
  584.       l++;
  585.     }
  586.     if (l != token_start) {    /* yes, we've read in another operand */
  587.       uint operand_ok;
  588.       this_operand = i.operands++;
  589.       if (i.operands > MAX_OPERANDS) {
  590.         as_bad ("spurious operands; (%d operands/instruction max)",
  591.              MAX_OPERANDS);
  592.         return;
  593.       }
  594.       /* now parse operand adding info to 'i' as we go along */
  595.       END_STRING_AND_SAVE (l);
  596.       operand_ok = i386_operand (token_start);
  597.       RESTORE_END_STRING (l);    /* restore old contents */
  598.       if (!operand_ok) return;
  599.     } else {
  600.       if (expecting_operand) {
  601.       expecting_operand_after_comma:
  602.         as_bad ("expecting operand after ','; got nothing");
  603.         return;
  604.       }
  605.       if (*l == ',') {
  606.         as_bad ("expecting operand before ','; got nothing");
  607.         return;
  608.       }
  609.     }
  610.       
  611.     /* now *l must be either ',' or END_OF_INSN */
  612.     if (*l == ',') {
  613.       if (*++l == END_OF_INSN) {        /* just skip it, if it's \n complain */
  614.         goto expecting_operand_after_comma;
  615.       }
  616.       expecting_operand = TRUE;
  617.     }
  618.       } while (*l != END_OF_INSN);        /* until we get end of insn */
  619.     }
  620.   }
  621.  
  622.   /* Now we've parsed the opcode into a set of templates, and have the
  623.      operands at hand.
  624.      Next, we find a template that matches the given insn,
  625.      making sure the overlap of the given operands types is consistent
  626.      with the template operand types. */
  627.  
  628. #define MATCH(overlap,given_type) \
  629.   (overlap && \
  630.    (overlap & (JumpAbsolute|BaseIndex|Mem8)) \
  631.    == (given_type & (JumpAbsolute|BaseIndex|Mem8)))
  632.   
  633.     /* If m0 and m1 are register matches they must be consistent
  634.        with the expected operand types t0 and t1.
  635.      That is, if both m0 & m1 are register matches
  636.          i.e. ( ((m0 & (Reg)) && (m1 & (Reg)) ) ?
  637.      then, either 1. or 2. must be true:
  638.          1. the expected operand type register overlap is null:
  639.                  (t0 & t1 & Reg) == 0
  640.      AND
  641.         the given register overlap is null:
  642.                      (m0 & m1 & Reg) == 0
  643.      2. the expected operand type register overlap == the given
  644.         operand type overlap:  (t0 & t1 & m0 & m1 & Reg).
  645.      */
  646. #define CONSISTENT_REGISTER_MATCH(m0, m1, t0, t1) \
  647.     ( ((m0 & (Reg)) && (m1 & (Reg))) ? \
  648.       ( ((t0 & t1 & (Reg)) == 0 && (m0 & m1 & (Reg)) == 0) || \
  649.         ((t0 & t1) & (m0 & m1) & (Reg)) \
  650.        ) : 1)
  651.   {
  652.     register uint overlap0, overlap1;
  653.     expressionS * exp;
  654.     uint overlap2;
  655.     uint found_reverse_match;
  656.  
  657.     overlap0 = overlap1 = overlap2 = found_reverse_match = 0;
  658.     for (t = current_templates->start;
  659.      t < current_templates->end;
  660.      t++) {
  661.  
  662.       /* must have right number of operands */
  663.       if (i.operands != t->operands) continue;
  664.       else if (!t->operands) break;    /* 0 operands always matches */
  665.  
  666.       overlap0 = i.types[0] & t->operand_types[0];
  667.       switch (t->operands) {
  668.       case 1:
  669.     if (! MATCH (overlap0,i.types[0])) continue;
  670.     break;
  671.       case 2: case 3:
  672.     overlap1 = i.types[1] & t->operand_types[1];
  673.     if (! MATCH (overlap0,i.types[0]) ||
  674.         ! MATCH (overlap1,i.types[1]) ||
  675.         ! CONSISTENT_REGISTER_MATCH(overlap0, overlap1,
  676.                     t->operand_types[0],
  677.                     t->operand_types[1])) {
  678.  
  679.       /* check if other direction is valid ... */
  680.       if (! (t->opcode_modifier & COMES_IN_BOTH_DIRECTIONS))
  681.         continue;
  682.       
  683.       /* try reversing direction of operands */
  684.       overlap0 = i.types[0] & t->operand_types[1];
  685.       overlap1 = i.types[1] & t->operand_types[0];
  686.       if (! MATCH (overlap0,i.types[0]) ||
  687.           ! MATCH (overlap1,i.types[1]) ||
  688.           ! CONSISTENT_REGISTER_MATCH (overlap0, overlap1, 
  689.                        t->operand_types[0],
  690.                        t->operand_types[1])) {
  691.         /* does not match either direction */
  692.         continue;
  693.       }
  694.       /* found a reverse match here -- slip through */
  695.       /* found_reverse_match holds which of D or FloatD we've found */
  696.       found_reverse_match = t->opcode_modifier & COMES_IN_BOTH_DIRECTIONS;
  697.     }                /* endif: not forward match */
  698.     /* found either forward/reverse 2 operand match here */
  699.     if (t->operands == 3) {
  700.       overlap2 = i.types[2] & t->operand_types[2];
  701.       if (! MATCH (overlap2,i.types[2]) ||
  702.           ! CONSISTENT_REGISTER_MATCH (overlap0, overlap2,
  703.                        t->operand_types[0],
  704.                        t->operand_types[2]) ||
  705.           ! CONSISTENT_REGISTER_MATCH (overlap1, overlap2, 
  706.                        t->operand_types[1],
  707.                        t->operand_types[2]))
  708.         continue;
  709.     }
  710.     /* found either forward/reverse 2 or 3 operand match here:
  711.        slip through to break */
  712.       }
  713.       break;            /* we've found a match; break out of loop */
  714.     }                /* for (t = ... */
  715.     if (t == current_templates->end) { /* we found no match */
  716. #ifdef NeXT
  717. string_instruction_bad_match:
  718. #endif /* NeXT */
  719.       as_bad ("operands given don't match any known 386 instruction");
  720.       return;
  721.     }
  722.  
  723. #ifdef NeXT
  724.     /*
  725.      * This bit of special checking code checks the string instructions that
  726.      * have operands so that segment overrides get picked up correctly.
  727.      */
  728.     if(IS_STRING_INSTRUCTION((t->base_opcode)) && i.operands != 0){
  729.  
  730.       if(i.operands == 2){
  731.     if(t->base_opcode == MOVS_OPCODE || /* movs %seg:0(%esi),%es:0(%edi) */
  732.        t->base_opcode == CMPS_OPCODE){  /* cmps %seg:0(%esi),%es:0(%edi) */
  733.  
  734.       if(i.base_reg    != (reg_entry *)hash_find(reg_hash, "esi") ||
  735.          i.base_reg2nd != (reg_entry *)hash_find(reg_hash, "edi"))
  736.         goto string_instruction_bad_match;
  737.  
  738.       if(i.seg2nd && i.seg2nd != &es)
  739.           goto string_instruction_bad_match;
  740.  
  741.       if(i.seg)
  742.         if(add_seg_prefix(i.seg->seg_prefix))
  743.           return;
  744.     }
  745.     else if(t->base_opcode == LODS_OPCODE){ /* lods %seg:(%esi),%eax */
  746.  
  747.       if(i.base_reg != (reg_entry *)hash_find(reg_hash, "esi"))
  748.         goto string_instruction_bad_match;
  749.  
  750.       if(i.seg)
  751.         if(add_seg_prefix(i.seg->seg_prefix))
  752.           return;
  753.     }
  754.     else if(t->base_opcode == SCAS_OPCODE || /* scas %eax,%seg:(%edi) */
  755.         t->base_opcode == STOS_OPCODE){  /* stos %eax,%seg:(%edi) */
  756.  
  757.       if(i.base_reg != (reg_entry *)hash_find(reg_hash, "edi"))
  758.         goto string_instruction_bad_match;
  759.  
  760.       if(i.seg)
  761.         if(add_seg_prefix(i.seg->seg_prefix))
  762.           return;
  763.     }
  764.  
  765.     if(i.index_reg || i.index_reg2nd)
  766.       goto string_instruction_bad_match;
  767.  
  768.     if(i.disps[0]){
  769.       if(i.disps[0]->X_add_symbol || i.disps[0]->X_subtract_symbol ||
  770.          i.disps[0]->X_seg != SEG_ABSOLUTE || i.disps[0]->X_add_number != 0)
  771.           goto string_instruction_bad_match;
  772.     }
  773.  
  774.     if(i.disps[1]){
  775.       if(i.disps[1]->X_add_symbol || i.disps[1]->X_subtract_symbol ||
  776.          i.disps[1]->X_seg != SEG_ABSOLUTE || i.disps[1]->X_add_number != 0)
  777.           goto string_instruction_bad_match;
  778.     }
  779.       }
  780.       /*
  781.        * Now that the operands have been checked for correctness remove them
  782.        * so the correct opcode bytes are put out.
  783.        */
  784.       i.seg = 0;
  785.       i.base_reg = 0;
  786.       i.base_reg2nd = 0;
  787.       i.disp_operands = 0;
  788.       i.disps[0] = 0;
  789.       i.disps[1] = 0;
  790.     }
  791. #endif /* NeXT */
  792.  
  793. #ifdef NeXT
  794.     if(t->cpus && !force_cpusubtype_ALL){
  795.       if(*(t->cpus) == '5'){
  796.     if(archflag_cpusubtype == CPU_SUBTYPE_486 ||
  797.        archflag_cpusubtype == CPU_SUBTYPE_486SX)
  798.       as_bad("586 instruction not allowed with -arch i486 or -arch i486SX");
  799.     if(cpusubtype != CPU_SUBTYPE_586SX)
  800.       cpusubtype = CPU_SUBTYPE_586;
  801.       }
  802.       else if(*(t->cpus) == '4' &&
  803.           (cpusubtype != CPU_SUBTYPE_586 &&
  804.            cpusubtype != CPU_SUBTYPE_586SX))
  805.     if(cpusubtype != CPU_SUBTYPE_486SX)
  806.        cpusubtype = CPU_SUBTYPE_486;
  807.     }
  808. #endif /* NeXT */
  809.  
  810.     /* Copy the template we found (we may change it!). */
  811.     bcopy (t, &i.tm, sizeof (template));
  812.     t = &i.tm;            /* alter new copy of template */
  813.  
  814.     /* If there's no opcode suffix we try to invent one based on register
  815.        operands. */
  816.     if (! i.suffix && i.reg_operands) {
  817.       /* We take i.suffix from the LAST register operand specified.  This
  818.      assumes that the last register operands is the destination register
  819.      operand. */
  820.       int o;
  821.       for (o = 0; o < MAX_OPERANDS; o++)
  822.     if (i.types[o] & Reg) {
  823. #ifdef NeXT
  824.       /* Need to and with `Reg' because %al and %ax have `Acc' in their
  825.          types and they were coming up with a 'l' suffix. */
  826.       i.suffix = ((i.types[o] & Reg) == Reg8) ? BYTE_OPCODE_SUFFIX :
  827.         ((i.types[o] & Reg) == Reg16) ? WORD_OPCODE_SUFFIX :
  828.           DWORD_OPCODE_SUFFIX;
  829. #else /* !defined(NeXT) */
  830.       i.suffix = (i.types[o] == Reg8) ? BYTE_OPCODE_SUFFIX :
  831.         (i.types[o] == Reg16) ? WORD_OPCODE_SUFFIX :
  832.           DWORD_OPCODE_SUFFIX;
  833. #endif /* NeXT */
  834.     }
  835.     }
  836.  
  837.     /* Make still unresolved immediate matches conform to size of immediate
  838.        given in i.suffix. Note:  overlap2 cannot be an immediate!
  839.        We assume this. */
  840. #ifdef NeXT
  841.     /* Need to check for the case the immediate is larger than the suffix and
  842.        force the value of overlap to the correct immediate size. */
  843.     if(overlap0 & (Imm8|Imm8S|Imm16|Imm32)){
  844.       if(i.suffix == BYTE_OPCODE_SUFFIX && (overlap0 & (Imm8|Imm8S)) == 0)
  845.     overlap0 = Imm8|Imm8S;
  846.       else if(i.suffix == WORD_OPCODE_SUFFIX &&
  847.           (overlap0 & (Imm16|Imm8|Imm8S)) == 0)
  848.     overlap0 = Imm16;
  849.     }
  850. #endif NeXT
  851.     if ((overlap0 & (Imm8|Imm8S|Imm16|Imm32))
  852.     && overlap0 != Imm8 && overlap0 != Imm8S
  853.     && overlap0 != Imm16 && overlap0 != Imm32) {
  854.       if (! i.suffix) {
  855.     as_bad ("no opcode suffix given; can't determine immediate size");
  856.     return;
  857.       }
  858.       overlap0 &= (i.suffix == BYTE_OPCODE_SUFFIX ? (Imm8|Imm8S) :
  859.            (i.suffix == WORD_OPCODE_SUFFIX ? Imm16 : Imm32));
  860.     }
  861. #ifdef NeXT
  862.     if(overlap1 & (Imm8|Imm8S|Imm16|Imm32)){
  863.       if(i.suffix == BYTE_OPCODE_SUFFIX && (overlap1 & (Imm8|Imm8S)) == 0)
  864.     overlap1 = Imm8|Imm8S;
  865.       else if(i.suffix == WORD_OPCODE_SUFFIX &&
  866.           (overlap0 & (Imm16|Imm8|Imm8S)) == 0)
  867.     overlap1 = Imm16;
  868.     }
  869. #endif NeXT
  870.     if ((overlap1 & (Imm8|Imm8S|Imm16|Imm32))
  871.     && overlap1 != Imm8 && overlap1 != Imm8S
  872.     && overlap1 != Imm16 && overlap1 != Imm32) {
  873.       if (! i.suffix) {
  874.     as_bad ("no opcode suffix given; can't determine immediate size");
  875.     return;
  876.       }
  877.       overlap1 &= (i.suffix == BYTE_OPCODE_SUFFIX ? (Imm8|Imm8S) :
  878.            (i.suffix == WORD_OPCODE_SUFFIX ? Imm16 : Imm32));
  879.     }
  880.  
  881.     i.types[0] = overlap0;
  882.     i.types[1] = overlap1;
  883.     i.types[2] = overlap2;
  884.  
  885.     if (overlap0 & ImplicitRegister) i.reg_operands--;
  886.     if (overlap1 & ImplicitRegister) i.reg_operands--;
  887.     if (overlap2 & ImplicitRegister) i.reg_operands--;
  888.     if (overlap0 & Imm1) i.imm_operands = 0; /* kludge for shift insns */
  889.  
  890.     if (found_reverse_match) {
  891.       uint save;
  892.       save = t->operand_types[0];
  893.       t->operand_types[0] = t->operand_types[1];
  894.       t->operand_types[1] = save;
  895.     }
  896.  
  897.     /* Finalize opcode.  First, we change the opcode based on the operand
  898.        size given by i.suffix: we never have to change things for byte insns,
  899.        or when no opcode suffix is need to size the operands. */
  900.  
  901.     if (! i.suffix && (t->opcode_modifier & W)) {
  902.       as_bad ("no opcode suffix given and no register operands; can't size instruction");
  903.       return;
  904.     }
  905.  
  906.     if (i.suffix && i.suffix != BYTE_OPCODE_SUFFIX) {
  907.       /* Select between byte and word/dword operations. */
  908.       if (t->opcode_modifier & W)
  909.     t->base_opcode |= W;
  910.       /* Now select between word & dword operations via the
  911.      operand size prefix. */
  912.       if (i.suffix == WORD_OPCODE_SUFFIX) {
  913.     if (i.prefixes == MAX_PREFIXES) {
  914.       as_bad ("%d prefixes given and 'w' opcode suffix gives too many prefixes",
  915.            MAX_PREFIXES);
  916.       return;
  917.     }
  918.     i.prefix[i.prefixes++] = WORD_PREFIX_OPCODE;
  919.       }
  920.     }
  921.  
  922.     /* For insns with operands there are more diddles to do to the opcode. */
  923.     if (i.operands) {
  924.       /* If we found a reverse match we must alter the opcode direction bit
  925.      found_reverse_match holds bit to set (different for int &
  926.      float insns). */
  927.  
  928.       if (found_reverse_match) {
  929.     t->base_opcode |= found_reverse_match;
  930.       }
  931.  
  932. #if defined(i486) || defined (i586)
  933.       if (t->base_opcode  == BSWAP_OPCODE) {
  934.     t->base_opcode |= i.regs[0]->reg_num;
  935.       }
  936. #endif /* defined (i486) || defined (i586) */
  937.  
  938.       /*
  939.     The imul $imm, %reg instruction is converted into
  940.     imul $imm, %reg, %reg. */
  941.       if (t->opcode_modifier & imulKludge) {
  942.       i.regs[2] = i.regs[1]; /* Pretend we saw the 3 operand case. */
  943.       i.reg_operands = 2;
  944.       }
  945.  
  946.       /* Certain instructions expect the destination to be in the i.rm.reg
  947.      field.  This is by far the exceptional case.  For these instructions,
  948.      if the source operand is a register, we must reverse the i.rm.reg
  949.      and i.rm.regmem fields.  We accomplish this by faking that the
  950.      two register operands were given in the reverse order. */
  951.       if ((t->opcode_modifier & ReverseRegRegmem) && i.reg_operands == 2) {
  952.     uint first_reg_operand = (i.types[0] & Reg) ? 0 : 1;
  953.     uint second_reg_operand = first_reg_operand + 1;
  954.     reg_entry *tmp = i.regs[first_reg_operand];
  955.     i.regs[first_reg_operand] = i.regs[second_reg_operand];
  956.     i.regs[second_reg_operand] = tmp;
  957.       }
  958.  
  959.       if (t->opcode_modifier & ShortForm) {
  960.     /* The register or float register operand is in operand 0 or 1. */
  961.     uint o = (i.types[0] & (Reg|FloatReg)) ? 0 : 1;
  962.     /* Register goes in low 3 bits of opcode. */
  963.     t->base_opcode |= i.regs[o]->reg_num;
  964.       } else if (t->opcode_modifier & ShortFormW) {
  965.     /* Short form with 0x8 width bit.  Register is always dest. operand */
  966.     t->base_opcode |= i.regs[1]->reg_num;
  967.     if (i.suffix == WORD_OPCODE_SUFFIX ||
  968.         i.suffix == DWORD_OPCODE_SUFFIX)
  969.       t->base_opcode |= 0x8;
  970.       } else if (t->opcode_modifier & Seg2ShortForm) {
  971.     if (t->base_opcode == POP_SEG_SHORT && i.regs[0]->reg_num == 1) {
  972.       as_bad ("you can't 'pop cs' on the 386.");
  973.       return;
  974.     }
  975.     t->base_opcode |= (i.regs[0]->reg_num << 3);
  976.       } else if (t->opcode_modifier & Seg3ShortForm) {
  977.     /* 'push %fs' is 0x0fa0; 'pop %fs' is 0x0fa1.
  978.        'push %gs' is 0x0fa8; 'pop %fs' is 0x0fa9.
  979.        So, only if i.regs[0]->reg_num == 5 (%gs) do we need
  980.        to change the opcode. */
  981.     if (i.regs[0]->reg_num == 5)
  982.       t->base_opcode |= 0x08;
  983.       } else if (t->opcode_modifier & Modrm) {
  984.     /* The opcode is completed (modulo t->extension_opcode which must
  985.        be put into the modrm byte.
  986.        Now, we make the modrm & index base bytes based on all the info
  987.        we've collected. */
  988.  
  989.     /* i.reg_operands MUST be the number of real register operands;
  990.        implicit registers do not count. */
  991.     if (i.reg_operands == 2) {
  992.       uint source, dest;
  993.       source = (i.types[0] & (Reg|SReg2|SReg3|Control|Debug|Test)) ? 0 : 1;
  994.       dest = source + 1;
  995.       i.rm.mode = 3;
  996.       /* We must be careful to make sure that all segment/control/test/
  997.          debug registers go into the i.rm.reg field (despite the whether
  998.          they are source or destination operands). */
  999.       if (i.regs[dest]->reg_type & (SReg2|SReg3|Control|Debug|Test)) {
  1000.         i.rm.reg = i.regs[dest]->reg_num;
  1001.         i.rm.regmem = i.regs[source]->reg_num;
  1002.       } else {
  1003.         i.rm.reg = i.regs[source]->reg_num;
  1004.         i.rm.regmem = i.regs[dest]->reg_num;
  1005.       }
  1006.     } else {        /* if it's not 2 reg operands... */
  1007.       if (i.mem_operands) {
  1008.         uint fake_zero_displacement = FALSE;
  1009.         uint o = (i.types[0] & Mem) ? 0 : ((i.types[1] & Mem) ? 1 : 2);
  1010.         
  1011.         /* Encode memory operand into modrm byte and base index byte. */
  1012.  
  1013.         if (i.base_reg == esp && ! i.index_reg) {
  1014.           /* <disp>(%esp) becomes two byte modrm with no index register. */
  1015.           i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING;
  1016.           i.rm.mode = MODE_FROM_DISP_SIZE (i.types[o]);
  1017.           i.bi.base = ESP_REG_NUM;
  1018.           i.bi.index = NO_INDEX_REGISTER;
  1019.           i.bi.scale = 0;        /* Must be zero! */
  1020.         } else if (i.base_reg == ebp && !i.index_reg) {
  1021.           if (! (i.types[o] & Disp)) {
  1022.         /* Must fake a zero byte displacement.
  1023.            There is no direct way to code '(%ebp)' directly. */
  1024.         fake_zero_displacement = TRUE;
  1025.         /* fake_zero_displacement code does not set this. */
  1026.         i.types[o] |= Disp8;
  1027.           }
  1028.           i.rm.mode = MODE_FROM_DISP_SIZE (i.types[o]);
  1029.           i.rm.regmem = EBP_REG_NUM;
  1030.         } else if (! i.base_reg && (i.types[o] & BaseIndex)) {
  1031.           /* There are three cases here.
  1032.          Case 1:  '<32bit disp>(,1)' -- indirect absolute.
  1033.          (Same as cases 2 & 3 with NO index register)
  1034.          Case 2:  <32bit disp> (,<index>) -- no base register with disp
  1035.          Case 3:  (, <index>)       --- no base register;
  1036.          no disp (must add 32bit 0 disp). */
  1037.           i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING;
  1038.           i.rm.mode = 0;        /* 32bit mode */
  1039.           i.bi.base = NO_BASE_REGISTER;
  1040.           i.types[o] &= ~Disp;
  1041.           i.types[o] |= Disp32;    /* Must be 32bit! */
  1042.           if (i.index_reg) {        /* case 2 or case 3 */
  1043.         i.bi.index = i.index_reg->reg_num;
  1044.         i.bi.scale = i.log2_scale_factor;
  1045.         if (i.disp_operands == 0)
  1046.           fake_zero_displacement = TRUE; /* case 3 */
  1047.           } else {
  1048.         i.bi.index = NO_INDEX_REGISTER;
  1049.         i.bi.scale = 0;
  1050.           }
  1051.         } else if (i.disp_operands && !i.base_reg && !i.index_reg) {
  1052.           /* Operand is just <32bit disp> */
  1053.           i.rm.regmem = EBP_REG_NUM;
  1054.           i.rm.mode = 0;
  1055.           i.types[o] &= ~Disp;
  1056.           i.types[o] |= Disp32;
  1057.         } else {
  1058.           /* It's not a special case; rev'em up. */
  1059.           i.rm.regmem = i.base_reg->reg_num;
  1060.           i.rm.mode = MODE_FROM_DISP_SIZE (i.types[o]);
  1061.           if (i.index_reg) {
  1062.         i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING;
  1063.         i.bi.base = i.base_reg->reg_num;
  1064.         i.bi.index = i.index_reg->reg_num;
  1065.         i.bi.scale = i.log2_scale_factor;
  1066.         if (i.base_reg == ebp && i.disp_operands == 0) { /* pace */
  1067.           fake_zero_displacement = TRUE;
  1068.           i.types[o] |= Disp8;
  1069.           i.rm.mode = MODE_FROM_DISP_SIZE (i.types[o]);
  1070.         }
  1071.           }
  1072.         }
  1073.         if (fake_zero_displacement) {
  1074.           /* Fakes a zero displacement assuming that i.types[o] holds
  1075.          the correct displacement size. */
  1076.           exp = &disp_expressions[i.disp_operands++];
  1077.           i.disps[o] = exp;
  1078.           exp->X_seg = SEG_ABSOLUTE;
  1079.           exp->X_add_number = 0;
  1080.           exp->X_add_symbol = (symbolS *) 0;
  1081.           exp->X_subtract_symbol = (symbolS *) 0;
  1082.         }
  1083.  
  1084.         /* Select the correct segment for the memory operand. */
  1085.         if (i.seg) {
  1086.           uint seg_index;
  1087.           seg_entry * default_seg;
  1088.  
  1089.           if (i.rm.regmem == ESCAPE_TO_TWO_BYTE_ADDRESSING) {
  1090.         seg_index = (i.rm.mode<<3) | i.bi.base;
  1091.         default_seg = two_byte_segment_defaults [seg_index];
  1092.           } else {
  1093.         seg_index = (i.rm.mode<<3) | i.rm.regmem;
  1094.         default_seg = one_byte_segment_defaults [seg_index];
  1095.           }
  1096.           /* If the specified segment is not the default, use an
  1097.          opcode prefix to select it */
  1098.           if (i.seg != default_seg) {
  1099.         if (i.prefixes == MAX_PREFIXES) {
  1100.           as_bad ("%d prefixes given and %s segment override gives too many prefixes",
  1101.                MAX_PREFIXES, i.seg->seg_name);
  1102.           return;
  1103.         }
  1104. #ifdef NeXT
  1105.         if(add_seg_prefix(i.seg->seg_prefix))
  1106.           return;
  1107. #else /* !defined(NeXT) */
  1108.         i.prefix[i.prefixes++] = i.seg->seg_prefix;
  1109. #endif /* NeXT */
  1110.           }
  1111.         }
  1112.       }
  1113.  
  1114.       /* Fill in i.rm.reg or i.rm.regmem field with register operand
  1115.          (if any) based on t->extension_opcode. Again, we must be careful
  1116.          to make sure that segment/control/debug/test registers are coded
  1117.          into the i.rm.reg field. */
  1118.       if (i.reg_operands) {
  1119.         uint o =
  1120.           (i.types[0] & (Reg|SReg2|SReg3|Control|Debug|Test)) ? 0 :
  1121.         (i.types[1] & (Reg|SReg2|SReg3|Control|Debug|Test)) ? 1 : 2;
  1122.         /* If there is an extension opcode to put here, the register number
  1123.            must be put into the regmem field. */
  1124.         if (t->extension_opcode != None)
  1125.           i.rm.regmem = i.regs[o]->reg_num;
  1126.         else i.rm.reg = i.regs[o]->reg_num;
  1127.  
  1128.         /* Now, if no memory operand has set i.rm.mode = 0, 1, 2
  1129.            we must set it to 3 to indicate this is a register operand
  1130.            int the regmem field */
  1131.         if (! i.mem_operands) i.rm.mode = 3;
  1132.       }
  1133.  
  1134.       /* Fill in i.rm.reg field with extension opcode (if any). */
  1135.       if (t->extension_opcode != None)
  1136.         i.rm.reg = t->extension_opcode;
  1137.     }
  1138. #ifdef NeXT
  1139.       } else if (i.seg) {
  1140.     if (i.prefixes == MAX_PREFIXES) {
  1141.       as_bad ("%d prefixes given and %s segment override gives too many "
  1142.           " prefixes", MAX_PREFIXES, i.seg->seg_name);
  1143.       return;
  1144.     }
  1145.     if(add_seg_prefix(i.seg->seg_prefix))
  1146.       return;
  1147. #endif /* NeXT */
  1148.       }
  1149.     }
  1150.   }
  1151.  
  1152.   /* Handle conversion of 'int $3' --> special int3 insn. */
  1153.   if (t->base_opcode == INT_OPCODE && i.imms[0]->X_add_number == 3) {
  1154.     t->base_opcode = INT3_OPCODE;
  1155.     i.imm_operands = 0;
  1156.   }
  1157.  
  1158.   /* We are ready to output the insn. */
  1159.   {
  1160.     register char * p;
  1161.     
  1162.     /* Output jumps. */
  1163.     if (t->opcode_modifier & Jump) {
  1164.       int n = i.disps[0]->X_add_number;
  1165.       
  1166.       switch (i.disps[0]->X_seg) {
  1167.       case SEG_ABSOLUTE:
  1168. #ifndef NeXT
  1169.     if (FITS_IN_SIGNED_BYTE (n)) {
  1170.       p = frag_more (2);
  1171.       p[0] = t->base_opcode;
  1172.       p[1] = n;
  1173. #if 0 /* leave out 16 bit jumps - pace */
  1174.     } else if (FITS_IN_SIGNED_WORD (n)) {
  1175.       p = frag_more (4);
  1176.       p[0] = WORD_PREFIX_OPCODE;
  1177.       p[1] = t->base_opcode;
  1178.       md_number_to_chars (&p[2], n, 2);
  1179. #endif
  1180.     } else
  1181. #endif /* !defined(NeXT) */
  1182.     {        /* It's an absolute dword displacement. */
  1183.       if (t->base_opcode == JUMP_PC_RELATIVE) { /* pace */
  1184.         /* unconditional jump */
  1185. #ifdef NeXT
  1186.         n - (obstack_next_free(&frags) - frag_now->fr_literal);
  1187. #endif /* NeXT */
  1188.         p = frag_more (5);
  1189.         p[0] = 0xe9;
  1190.         md_number_to_chars (&p[1], n , 4);
  1191. #ifdef NeXT
  1192.         fix_new(frag_now, p - frag_now->fr_literal + 1, 4, 0, 0, n, 3);
  1193. #endif /* NeXT */
  1194.       } else {
  1195.         /* conditional jump */
  1196. #ifdef NeXT
  1197.         n - (obstack_next_free(&frags) - frag_now->fr_literal);
  1198. #endif /* NeXT */
  1199.         p = frag_more (6);
  1200.         p[0] = TWO_BYTE_OPCODE_ESCAPE;
  1201.         p[1] = t->base_opcode + 0x10;
  1202.         md_number_to_chars (&p[2], n, 4);
  1203. #ifdef NeXT
  1204.         fix_new(frag_now, p - frag_now->fr_literal + 2, 4, 0, 0, n, 3);
  1205. #endif /* NeXT */
  1206.       }
  1207.     }
  1208.     break;
  1209.       default:
  1210.     /* It's a symbol; end frag & setup for relax.
  1211.        Make sure there are 6 chars left in the current frag; if not
  1212.        we'll have to start a new one. */
  1213.     /* I caught it failing with obstack_room == 6,
  1214.        so I changed to <=   pace */
  1215.     if (obstack_room (&frags) <= 6) {
  1216.         frag_wane(frag_now);
  1217.         frag_new (0);
  1218.     }
  1219. #ifdef NeXT
  1220.     /*
  1221.      * NeXT scatter-loading forces the use of only 32 bit jumps
  1222.      * for everything that isn't local.  We assume that our compiler
  1223.      * will NOT generate jumps to local variables that are outside
  1224.      * of the scope of a block.
  1225.      */
  1226.     if (!is_local_symbol(i.disps[0]->X_add_symbol)) {
  1227.  
  1228.         if (t->base_opcode == JUMP_PC_RELATIVE) {
  1229.         p = frag_more(1);
  1230.         *p = 0xe9;      /* use 32-bit version */
  1231.         } else {
  1232.         p = frag_more (2);      /* opcode can be at most two bytes */
  1233.         /* put out high byte first: can't use md_number_to_chars! */
  1234.         *p++ = TWO_BYTE_OPCODE_ESCAPE;
  1235.         *p = (t->base_opcode + 0x10) & 0xff;
  1236.         }
  1237.         p =  frag_more (4);
  1238.         fix_new (frag_now, p - frag_now->fr_literal, 4,
  1239.          i.disps[0]->X_add_symbol, i.disps[0]->X_subtract_symbol,
  1240.          i.disps[0]->X_add_number, 1 | 2);
  1241.     } else
  1242. #endif
  1243.     {
  1244.         p = frag_more (1);
  1245.         p[0] = t->base_opcode;
  1246.         frag_var (rs_machine_dependent,
  1247.           6,        /* 2 opcode/prefix + 4 displacement */
  1248.           1,
  1249.           ((uchar) *p == JUMP_PC_RELATIVE
  1250.            ? ENCODE_RELAX_STATE (UNCOND_JUMP, BYTE)
  1251.            : ENCODE_RELAX_STATE (COND_JUMP, BYTE)),
  1252.           i.disps[0]->X_add_symbol,
  1253.           n, p);
  1254.     }
  1255.     break;
  1256.       }
  1257.     } else if (t->opcode_modifier & (JumpByte|JumpDword)) {
  1258.       int size = (t->opcode_modifier & JumpByte) ? 1 : 4;
  1259.       int n = i.disps[0]->X_add_number;
  1260.  
  1261. #ifdef NeXT
  1262.       register char *q;
  1263.  
  1264.       if((t->opcode_modifier & JumpByte) == 0 && i.suffix == 'w')
  1265.     size = 2;
  1266.  
  1267.       /* First the prefix bytes. */
  1268.       for (q = i.prefix; q < i.prefix + i.prefixes; q++) {
  1269.     p =  frag_more (1);
  1270.     md_number_to_chars (p, (uint) *q, 1);
  1271.       }
  1272. #endif NeXT
  1273.       
  1274.       if (FITS_IN_UNSIGNED_BYTE(t->base_opcode)) {
  1275.     FRAG_APPEND_1_CHAR (t->base_opcode);
  1276.       } else {
  1277.     p = frag_more (2);    /* opcode can be at most two bytes */
  1278.     /* put out high byte first: can't use md_number_to_chars! */
  1279.     *p++ = (t->base_opcode >> 8) & 0xff;
  1280.     *p = t->base_opcode & 0xff;
  1281.       }
  1282.  
  1283.       p =  frag_more (size);
  1284.       switch (i.disps[0]->X_seg) {
  1285.       case SEG_ABSOLUTE:
  1286. #ifdef NeXT
  1287.     /* two bugs here, 1) this displacement is pc relitive and this case
  1288.        with an absolute value did not subtract the pc 2) since it is
  1289.        pc relitive a relocation entry must be emitted so the link editor
  1290.        will fix this when it moves the instruction */
  1291.     md_number_to_chars (p, n -
  1292.         (obstack_next_free(&frags) - frag_now->fr_literal), size);
  1293. #else /* !defined(NeXT) */
  1294.     md_number_to_chars (p, n, size);
  1295. #endif /* NeXT */
  1296.     if (size == 1 && ! FITS_IN_SIGNED_BYTE (n)) {
  1297.       as_bad ("loop/jecx only takes byte displacement; %d shortened to %d",
  1298.            n, *p);
  1299.     }
  1300. #ifndef NeXT
  1301.     break;
  1302. #endif /* NeXT */
  1303.       default:
  1304.     {
  1305.       int pcrel = 1;
  1306. #ifdef NeXT
  1307.           /*
  1308.            * The NeXT linker has the ability to scatter blocks of
  1309.            * sections between labels.  This requires that brances to
  1310.            * labels that survive to the link phase must be able to
  1311.            * be relocated.
  1312.            */
  1313.       pcrel |= 2;
  1314. #endif
  1315.       fix_new (frag_now, p - frag_now->fr_literal, size,
  1316.          i.disps[0]->X_add_symbol, i.disps[0]->X_subtract_symbol,
  1317.          i.disps[0]->X_add_number, pcrel);
  1318.     }
  1319.     break;
  1320.       }
  1321.     } else if (t->opcode_modifier & JumpInterSegment) {
  1322.       p =  frag_more (1 + 2 + 4);    /* 1 opcode; 2 segment; 4 offset */
  1323.       p[0] = t->base_opcode;
  1324.       if (i.imms[1]->X_seg == SEG_ABSOLUTE)
  1325.     md_number_to_chars (p + 1, i.imms[1]->X_add_number, 4);
  1326.       else
  1327.     fix_new (frag_now, p + 1 -  frag_now->fr_literal, 4,
  1328.          i.imms[1]->X_add_symbol,
  1329.          i.imms[1]->X_subtract_symbol,
  1330.          i.imms[1]->X_add_number, 0);
  1331.       if (i.imms[0]->X_seg != SEG_ABSOLUTE)
  1332.     as_bad ("can't handle non absolute segment in long call/jmp");
  1333.       md_number_to_chars (p + 5, i.imms[0]->X_add_number, 2);
  1334.     } else {
  1335.       /* Output normal instructions here. */
  1336.       register char *q;
  1337.       
  1338.       /* First the prefix bytes. */
  1339.       for (q = i.prefix; q < i.prefix + i.prefixes; q++) {
  1340.     p =  frag_more (1);
  1341.     md_number_to_chars (p, (uint) *q, 1);
  1342.       }
  1343.       
  1344.       /* Now the opcode; be careful about word order here! */
  1345.       if (FITS_IN_UNSIGNED_BYTE(t->base_opcode)) {
  1346.     FRAG_APPEND_1_CHAR (t->base_opcode);
  1347.       } else if (FITS_IN_UNSIGNED_WORD(t->base_opcode)) {
  1348.     p =  frag_more (2);
  1349.     /* put out high byte first: can't use md_number_to_chars! */
  1350.     *p++ = (t->base_opcode >> 8) & 0xff;
  1351.     *p = t->base_opcode & 0xff;
  1352.       } else {            /* opcode is either 3 or 4 bytes */
  1353.     if (t->base_opcode & 0xff000000) {
  1354.       p = frag_more (4);
  1355.       *p++ = (t->base_opcode >> 24) & 0xff;
  1356.     } else p = frag_more (3);
  1357.     *p++ = (t->base_opcode >> 16) & 0xff;
  1358.     *p++ = (t->base_opcode >>  8) & 0xff;
  1359.     *p =   (t->base_opcode      ) & 0xff;
  1360.       }
  1361.  
  1362.       /* Now the modrm byte and base index byte (if present). */
  1363.       if (t->opcode_modifier & Modrm) {
  1364.     p =  frag_more (1);
  1365.     /* md_number_to_chars (p, i.rm, 1); */
  1366.     md_number_to_chars (p, (i.rm.regmem<<0 | i.rm.reg<<3 | i.rm.mode<<6), 1);
  1367.     /* If i.rm.regmem == ESP (4) && i.rm.mode != Mode 3 (Register mode)
  1368.        ==> need second modrm byte. */
  1369.     if (i.rm.regmem == ESCAPE_TO_TWO_BYTE_ADDRESSING && i.rm.mode != 3) {
  1370.       p =  frag_more (1);
  1371.       /* md_number_to_chars (p, i.bi, 1); */
  1372.       md_number_to_chars (p,(i.bi.base<<0 | i.bi.index<<3 | i.bi.scale<<6), 1);
  1373.     }
  1374.       }
  1375.       
  1376.       if (i.disp_operands) {
  1377.     register int n;
  1378.     
  1379.     for (n = 0; n < i.operands; n++) {
  1380.       if (i.disps[n]) {
  1381.         if (i.disps[n]->X_seg == SEG_ABSOLUTE) {
  1382.           if (i.types[n] & (Disp8|Abs8)) {
  1383.         p =  frag_more (1);
  1384.         md_number_to_chars (p, i.disps[n]->X_add_number, 1);
  1385.           } else if (i.types[n] & (Disp16|Abs16)) {
  1386.         p =  frag_more (2);
  1387.         md_number_to_chars (p, i.disps[n]->X_add_number, 2);
  1388.           } else {        /* Disp32|Abs32 */
  1389.         p =  frag_more (4);
  1390.         md_number_to_chars (p, i.disps[n]->X_add_number, 4);
  1391.           }
  1392.         } else {            /* not SEG_ABSOLUTE */
  1393.           /* need a 32-bit fixup (don't support 8bit non-absolute disps) */
  1394.           p =  frag_more (4);
  1395.           fix_new (frag_now, p -  frag_now->fr_literal, 4,
  1396.                i.disps[n]->X_add_symbol, i.disps[n]->X_subtract_symbol,
  1397.                i.disps[n]->X_add_number, 0);
  1398.         }
  1399.       }
  1400.     }
  1401.       }                /* end displacement output */
  1402.       
  1403.       /* output immediate */
  1404.       if (i.imm_operands) {
  1405.     register int n;
  1406.     
  1407.     for (n = 0; n < i.operands; n++) {
  1408.       if (i.imms[n]) {
  1409.         if (i.imms[n]->X_seg == SEG_ABSOLUTE) {
  1410.           if (i.types[n] & (Imm8|Imm8S)) {
  1411.         p =  frag_more (1);
  1412.         md_number_to_chars (p, i.imms[n]->X_add_number, 1);
  1413.           } else if (i.types[n] & Imm16) {
  1414.         p =  frag_more (2);
  1415.         md_number_to_chars (p, i.imms[n]->X_add_number, 2);
  1416.           } else {
  1417.         p =  frag_more (4);
  1418.         md_number_to_chars (p, i.imms[n]->X_add_number, 4);
  1419.           }
  1420.         } else {            /* not SEG_ABSOLUTE */
  1421.           /* need a 32-bit fixup (don't support 8bit non-absolute ims) */
  1422.           /* try to support other sizes ... */
  1423.           int size;
  1424.           if (i.types[n] & (Imm8|Imm8S))
  1425.         size = 1;
  1426.           else if (i.types[n] & Imm16)
  1427.         size = 2;
  1428.           else
  1429.         size = 4;
  1430.           p = frag_more (size);
  1431.           fix_new (frag_now, p - frag_now->fr_literal, size,
  1432.                i.imms[n]->X_add_symbol, i.imms[n]->X_subtract_symbol,
  1433.                i.imms[n]->X_add_number, 0);
  1434.         }
  1435.       }
  1436.     }
  1437.       }                /* end immediate output */
  1438.     }
  1439.  
  1440. #ifdef DEBUG386
  1441.     if (flagseen ['D']) {
  1442.       pi (line, &i);
  1443.     }
  1444. #endif /* DEBUG386 */
  1445.  
  1446.   }
  1447.   return;
  1448. }
  1449.  
  1450. /* Parse OPERAND_STRING into the i386_insn structure I.  Returns non-zero
  1451.    on error. */
  1452.  
  1453. int i386_operand (operand_string)
  1454.      char *operand_string;
  1455. {
  1456.   register char *op_string = operand_string;
  1457.  
  1458.   /* Address of '\0' at end of operand_string. */
  1459.   char * end_of_operand_string = operand_string + strlen(operand_string);
  1460.  
  1461.   /* Start and end of displacement string expression (if found). */
  1462.   char * displacement_string_start = 0;
  1463.   char * displacement_string_end;
  1464.  
  1465.   /* We check for an absolute prefix (differentiating,
  1466.      for example, 'jmp pc_relative_label' from 'jmp *absolute_label'. */
  1467.   if (*op_string == ABSOLUTE_PREFIX) {
  1468.     op_string++;
  1469.     i.types[this_operand] |= JumpAbsolute;
  1470.   }
  1471.  
  1472.   /* Check if operand is a register. */
  1473.   if (*op_string == REGISTER_PREFIX) {
  1474.     register reg_entry * r;
  1475.     if (! (r = parse_register (op_string))) {
  1476.       as_bad ("bad register name ('%s')", op_string);
  1477.       return 0;
  1478.     }
  1479.     /* Check for segment override, rather than segment register by
  1480.        searching for ':' after %<x>s where <x> = s, c, d, e, f, g. */
  1481.     if ((r->reg_type & (SReg2|SReg3)) && op_string[3] == ':') {
  1482.       switch (r->reg_num) {
  1483.       case 0:
  1484. #ifdef NeXT
  1485.     if(i.mem_operands != 0) i.seg2nd = &es; else
  1486. #endif /* NeXT */
  1487.     i.seg = &es; break;
  1488.       case 1:
  1489. #ifdef NeXT
  1490.     if(i.mem_operands != 0) i.seg2nd = &cs; else
  1491. #endif /* NeXT */
  1492.     i.seg = &cs; break;
  1493.       case 2:
  1494. #ifdef NeXT
  1495.     if(i.mem_operands != 0) i.seg2nd = &ss; else
  1496. #endif /* NeXT */
  1497.     i.seg = &ss; break;
  1498.       case 3:
  1499. #ifdef NeXT
  1500.     if(i.mem_operands != 0) i.seg2nd = &ds; else
  1501. #endif /* NeXT */
  1502.     i.seg = &ds; break;
  1503.       case 4:
  1504. #ifdef NeXT
  1505.     if(i.mem_operands != 0) i.seg2nd = &fs; else
  1506. #endif /* NeXT */
  1507.     i.seg = &fs; break;
  1508.       case 5:
  1509. #ifdef NeXT
  1510.     if(i.mem_operands != 0) i.seg2nd = &gs; else
  1511. #endif /* NeXT */
  1512.     i.seg = &gs; break;
  1513.       }
  1514.       op_string += 4;        /* skip % <x> s : */
  1515.       operand_string = op_string; /* Pretend given string starts here. */
  1516.       if (!is_digit_char(*op_string) && !is_identifier_char(*op_string)
  1517.       && *op_string != '(' && *op_string != ABSOLUTE_PREFIX) {
  1518.     as_bad ("bad memory operand after segment override");
  1519.     return 0;
  1520.       }
  1521.       /* Handle case of %es:*foo. */
  1522.       if (*op_string == ABSOLUTE_PREFIX) {
  1523.     op_string++;
  1524.     i.types[this_operand] |= JumpAbsolute;
  1525.       }
  1526.       goto do_memory_reference;
  1527.     }
  1528.     i.types[this_operand] |= r->reg_type;
  1529.     i.regs[this_operand] = r;
  1530.     i.reg_operands++;
  1531.   } else if (*op_string == IMMEDIATE_PREFIX) { /* ... or an immediate */
  1532.     char * save_input_line_pointer;
  1533.     register expressionS *exp;
  1534.     segT exp_seg;
  1535.     if (i.imm_operands == MAX_IMMEDIATE_OPERANDS) {
  1536.       as_bad ("only 1 or 2 immediate operands are allowed");
  1537.       return 0;
  1538.     }
  1539.     exp = &im_expressions[i.imm_operands++];
  1540.     i.imms [this_operand] = exp;
  1541.     save_input_line_pointer = input_line_pointer;
  1542.     input_line_pointer = ++op_string;        /* must advance op_string! */
  1543.     exp_seg = expression (exp);
  1544.     input_line_pointer = save_input_line_pointer;
  1545.     switch (exp_seg) {
  1546.     case SEG_NONE:    /* missing or bad expr becomes absolute 0 */
  1547.       as_bad ("missing or invalid immediate expression '%s' taken as 0",
  1548.            operand_string);
  1549.       exp->X_seg = SEG_ABSOLUTE;
  1550.       exp->X_add_number = 0;
  1551.       exp->X_add_symbol = (symbolS *) 0;
  1552.       exp->X_subtract_symbol = (symbolS *) 0;
  1553.       i.types[this_operand] |= Imm;
  1554.       break;
  1555.     case SEG_ABSOLUTE:
  1556.       i.types[this_operand] |= SMALLEST_IMM_TYPE (exp->X_add_number);
  1557.       break;
  1558.     case SEG_TEXT: case SEG_DATA: case SEG_BSS: case SEG_UNKNOWN:
  1559.       i.types[this_operand] |= Imm32; /* this is an address ==> 32bit */
  1560.       break;
  1561.     default:
  1562. seg_unimplemented:
  1563.       as_bad ("Unimplemented segment type %d in parse_operand", exp_seg);
  1564.       return 0;
  1565.     }
  1566.     /* shorten this type of this operand if the instruction wants
  1567.      * fewer bits than are present in the immediate.  The bit field
  1568.      * code can put out 'andb $0xffffff, %al', for example.   pace
  1569.      * also 'movw $foo,(%eax)'
  1570.      */
  1571.     switch (i.suffix) {
  1572.     case WORD_OPCODE_SUFFIX:
  1573.       i.types[this_operand] |= Imm16;
  1574.       break;
  1575.     case BYTE_OPCODE_SUFFIX:
  1576.       i.types[this_operand] |= Imm16 | Imm8 | Imm8S;
  1577.       break;
  1578.     }
  1579.   } else if (is_digit_char(*op_string) || is_identifier_char(*op_string)
  1580.          || *op_string == '(') {
  1581.     /* This is a memory reference of some sort. */
  1582.     register char * base_string;
  1583.     uint found_base_index_form;
  1584.  
  1585.   do_memory_reference:
  1586.     if (i.mem_operands == MAX_MEMORY_OPERANDS) {
  1587.       as_bad ("more than 1 memory reference in instruction");
  1588.       return 0;
  1589.     }
  1590.     i.mem_operands++;
  1591.  
  1592.     /* Determine type of memory operand from opcode_suffix;
  1593.        no opcode suffix implies general memory references. */
  1594.     switch (i.suffix) {
  1595.     case BYTE_OPCODE_SUFFIX:
  1596.       i.types[this_operand] |= Mem8;
  1597.       break;
  1598.     case WORD_OPCODE_SUFFIX:
  1599.       i.types[this_operand] |= Mem16;
  1600.       break;
  1601.     case DWORD_OPCODE_SUFFIX:
  1602.     default:
  1603.       i.types[this_operand] |= Mem32;
  1604.     }
  1605.  
  1606.     /*  Check for base index form.  We detect the base index form by
  1607.     looking for an ')' at the end of the operand, searching
  1608.     for the '(' matching it, and finding a REGISTER_PREFIX or ','
  1609.     after it. */
  1610.     base_string = end_of_operand_string - 1;
  1611.     found_base_index_form = FALSE;
  1612.     if (*base_string == ')') {
  1613.       uint parens_balenced = 1;
  1614.       /* We've already checked that the number of left & right ()'s are equal,
  1615.      so this loop will not be infinite. */
  1616.       do {
  1617.     base_string--;
  1618.     if (*base_string == ')') parens_balenced++;
  1619.     if (*base_string == '(') parens_balenced--;
  1620.       } while (parens_balenced);
  1621.       base_string++;            /* Skip past '('. */
  1622.       if (*base_string == REGISTER_PREFIX || *base_string == ',')
  1623.     found_base_index_form = TRUE;
  1624.     }
  1625.  
  1626.     /* If we can't parse a base index register expression, we've found
  1627.        a pure displacement expression.  We set up displacement_string_start
  1628.        and displacement_string_end for the code below. */
  1629.     if (! found_base_index_form) {
  1630.     displacement_string_start = op_string;
  1631.     displacement_string_end = end_of_operand_string;
  1632.     } else {
  1633.       char *base_reg_name, *index_reg_name, *num_string;
  1634.       int num;
  1635.  
  1636.       i.types[this_operand] |= BaseIndex;
  1637.  
  1638.       /* If there is a displacement set-up for it to be parsed later. */
  1639.       if (base_string != op_string + 1) {
  1640.     displacement_string_start = op_string;
  1641.     displacement_string_end = base_string - 1;
  1642.       }
  1643.  
  1644.       /* Find base register (if any). */
  1645.       if (*base_string != ',') {
  1646.     base_reg_name = base_string++;
  1647.     /* skip past register name & parse it */
  1648.     while (isalpha(*base_string)) base_string++;
  1649.     if (base_string == base_reg_name+1) {
  1650.       as_bad ("can't find base register name after '(%c'",
  1651.            REGISTER_PREFIX);
  1652.       return 0;
  1653.     }
  1654.     END_STRING_AND_SAVE (base_string);
  1655. #ifdef NeXT
  1656.     if (i.base_reg){
  1657.       if (! (i.base_reg2nd = parse_register (base_reg_name))) {
  1658.         as_bad ("bad base register name ('%s')", base_reg_name);
  1659.         return 0;
  1660.       }
  1661.     }
  1662.     else
  1663. #endif /* NeXT */
  1664.     if (! (i.base_reg = parse_register (base_reg_name))) {
  1665.       as_bad ("bad base register name ('%s')", base_reg_name);
  1666.       return 0;
  1667.     }
  1668.     RESTORE_END_STRING (base_string);
  1669.       }
  1670.  
  1671.       /* Now check seperator; must be ',' ==> index reg
  1672.      OR num ==> no index reg. just scale factor
  1673.      OR ')' ==> end. (scale factor = 1) */
  1674.       if (*base_string != ',' && *base_string != ')') {
  1675.     as_bad ("expecting ',' or ')' after base register in `%s'",
  1676.          operand_string);
  1677.     return 0;
  1678.       }
  1679.  
  1680.       /* There may index reg here; and there may be a scale factor. */
  1681.       if (*base_string == ',' && *(base_string+1) == REGISTER_PREFIX) {
  1682.     index_reg_name = ++base_string;
  1683.     while (isalpha(*++base_string));
  1684.     END_STRING_AND_SAVE (base_string);
  1685. #ifdef NeXT
  1686.     if (i.index_reg) {
  1687.       if(! (i.index_reg2nd = parse_register(index_reg_name))) {
  1688.         as_bad ("bad index register name ('%s')", index_reg_name);
  1689.         return 0;
  1690.       }
  1691.     }
  1692.     else
  1693. #endif /* NeXT */
  1694.     if (! (i.index_reg = parse_register(index_reg_name))) {
  1695.       as_bad ("bad index register name ('%s')", index_reg_name);
  1696.       return 0;
  1697.     }
  1698.     RESTORE_END_STRING (base_string);
  1699.       }
  1700.  
  1701.       /* Check for scale factor. */
  1702.       if (*base_string == ',' && isdigit(*(base_string+1))) {
  1703.     num_string = ++base_string;
  1704.     while (is_digit_char(*base_string)) base_string++;
  1705.     if (base_string == num_string) {
  1706.       as_bad ("can't find a scale factor after ','");
  1707.       return 0;
  1708.     }
  1709.     END_STRING_AND_SAVE (base_string);
  1710.     /* We've got a scale factor. */
  1711.     if (! sscanf (num_string, "%d", &num)) {
  1712.       as_bad ("can't parse scale factor from '%s'", num_string);
  1713.       return 0;
  1714.     }
  1715.     RESTORE_END_STRING (base_string);
  1716.     switch (num) {    /* must be 1 digit scale */
  1717.     case 1:
  1718. #ifdef NeXT
  1719.       if (i.index_reg2nd) i.log2_scale_factor2nd = 0; else
  1720. #endif /* NeXT */
  1721.       i.log2_scale_factor = 0; break;
  1722.     case 2:
  1723. #ifdef NeXT
  1724.       if (i.index_reg2nd) i.log2_scale_factor2nd = 1; else
  1725. #endif /* NeXT */
  1726.       i.log2_scale_factor = 1; break;
  1727.     case 4:
  1728. #ifdef NeXT
  1729.       if (i.index_reg2nd) i.log2_scale_factor2nd = 2; else
  1730. #endif /* NeXT */
  1731.       i.log2_scale_factor = 2; break;
  1732.     case 8:
  1733. #ifdef NeXT
  1734.       if (i.index_reg2nd) i.log2_scale_factor2nd = 3; else
  1735. #endif /* NeXT */
  1736.       i.log2_scale_factor = 3; break;
  1737.     default:
  1738.       as_bad ("expecting scale factor of 1, 2, 4, 8; got %d", num);
  1739.       return 0;
  1740.     }
  1741.       } else {
  1742.     if (! i.index_reg && *base_string == ',') {
  1743.       as_bad ("expecting index register or scale factor after ','; got '%c'",
  1744.            *(base_string+1));
  1745.       return 0;
  1746.     }
  1747.       }
  1748.     }
  1749.  
  1750.     /* If there's an expression begining the operand, parse it,
  1751.        assuming displacement_string_start and displacement_string_end
  1752.        are meaningful. */
  1753.     if (displacement_string_start) {
  1754.       register expressionS * exp;
  1755.       segT exp_seg;
  1756.       char * save_input_line_pointer;
  1757.       exp = &disp_expressions[i.disp_operands];
  1758.       i.disps [this_operand] = exp;
  1759.       i.disp_operands++;
  1760.       save_input_line_pointer = input_line_pointer;
  1761.       input_line_pointer = displacement_string_start;
  1762.       END_STRING_AND_SAVE (displacement_string_end);
  1763.       exp_seg = expression (exp);
  1764.       if(*input_line_pointer)
  1765.     as_bad("Ignoring junk '%s' after expression",input_line_pointer);
  1766.       RESTORE_END_STRING (displacement_string_end);
  1767.       input_line_pointer = save_input_line_pointer;
  1768.       switch (exp_seg) {
  1769.       case SEG_NONE:
  1770.     /* missing expr becomes absolute 0 */
  1771.     as_bad ("missing or invalid displacement '%s' taken as 0",
  1772.          operand_string);
  1773.     i.types[this_operand] |= (Disp|Abs);
  1774.     exp->X_seg = SEG_ABSOLUTE;
  1775.     exp->X_add_number = 0;
  1776.     exp->X_add_symbol = (symbolS *) 0;
  1777.     exp->X_subtract_symbol = (symbolS *) 0;
  1778.     break;
  1779.       case SEG_ABSOLUTE:
  1780.     i.types[this_operand] |= SMALLEST_DISP_TYPE (exp->X_add_number);
  1781.     break;
  1782.       case SEG_TEXT: case SEG_DATA: case SEG_BSS:
  1783.       case SEG_UNKNOWN:    /* must be 32 bit displacement (i.e. address) */
  1784.     i.types[this_operand] |= Disp32;
  1785.     break;
  1786.       default:
  1787.     goto seg_unimplemented;
  1788.       }
  1789.     }
  1790.  
  1791.     /* Make sure the memory operand we've been dealt is valid. */
  1792.     if (i.base_reg && i.index_reg &&
  1793.     ! (i.base_reg->reg_type & i.index_reg->reg_type & Reg)) {
  1794.       as_bad ("register size mismatch in (base,index,scale) expression");
  1795.       return 0;
  1796.     }
  1797.     if ((i.base_reg && (i.base_reg->reg_type & Reg32) == 0) ||
  1798.     (i.index_reg && (i.index_reg->reg_type & Reg32) == 0)) {
  1799.       as_bad ("base/index register must be 32 bit register");
  1800.       return 0;
  1801.     }
  1802.     if (i.index_reg && i.index_reg == esp) {
  1803.       as_bad ("%s may not be used as an index register", esp->reg_name);
  1804.       return 0;
  1805.     }
  1806.   } else {            /* it's not a memory operand; argh! */
  1807.     as_bad ("invalid char %s begining %s operand '%s'",
  1808.          output_invalid(*op_string), ordinal_names[this_operand],
  1809.          op_string);
  1810.     return 0;
  1811.   }
  1812.   return 1;            /* normal return */
  1813. }
  1814.  
  1815. /*
  1816.  *            md_estimate_size_before_relax()
  1817.  *
  1818.  * Called just before relax().
  1819.  * Any symbol that is now undefined will not become defined.
  1820.  * Return the correct fr_subtype in the frag.
  1821.  * Return the initial "guess for fr_var" to caller.
  1822.  * The guess for fr_var is ACTUALLY the growth beyond fr_fix.
  1823.  * Whatever we do to grow fr_fix or fr_var contributes to our returned value.
  1824.  * Although it may not be explicit in the frag, pretend fr_var starts with a
  1825.  * 0 value.
  1826.  */
  1827. int
  1828. md_estimate_size_before_relax (fragP, segment_type)
  1829.      register fragS *    fragP;
  1830.      register int    segment_type; /* N_DATA or N_TEXT. */
  1831. {
  1832.   register uchar *    opcode;
  1833.   register int        old_fr_fix;
  1834.  
  1835.   old_fr_fix = fragP -> fr_fix;
  1836.   opcode = (uchar *) fragP -> fr_opcode;
  1837.   /* We've already got fragP->fr_subtype right;  all we have to do is check
  1838.      for un-relaxable symbols. */
  1839.   if ((fragP -> fr_symbol -> sy_type & N_TYPE) != segment_type) {
  1840.     /* symbol is undefined in this segment */
  1841.     switch (opcode[0]) {
  1842.     case JUMP_PC_RELATIVE:    /* make jmp (0xeb) a dword displacement jump */
  1843.       opcode[0] = 0xe9;        /* dword disp jmp */
  1844.       fragP -> fr_fix += 4;
  1845.       fix_new (fragP, old_fr_fix, 4,
  1846.            fragP -> fr_symbol,
  1847.            (symbolS *) 0,
  1848.            fragP -> fr_offset, 1 | 2);
  1849.       break;
  1850.  
  1851.     default:
  1852.       /* This changes the byte-displacement jump 0x7N -->
  1853.      the dword-displacement jump 0x0f8N */
  1854.       opcode[1] = opcode[0] + 0x10;
  1855.       opcode[0] = TWO_BYTE_OPCODE_ESCAPE;        /* two-byte escape */
  1856.       fragP -> fr_fix += 1 + 4;    /* we've added an opcode byte */
  1857.       fix_new (fragP, old_fr_fix + 1, 4,
  1858.            fragP -> fr_symbol,
  1859.            (symbolS *) 0,
  1860.            fragP -> fr_offset, 1 | 2);
  1861.       break;
  1862.     }
  1863.     frag_wane (fragP);
  1864.   }
  1865.   return (fragP -> fr_var + fragP -> fr_fix - old_fr_fix);
  1866. }                /* md_estimate_size_before_relax() */
  1867.  
  1868. /*
  1869.  *            md_convert_frag();
  1870.  *
  1871.  * Called after relax() is finished.
  1872.  * In:    Address of frag.
  1873.  *    fr_type == rs_machine_dependent.
  1874.  *    fr_subtype is what the address relaxed to.
  1875.  *
  1876.  * Out:    Any fixSs and constants are set up.
  1877.  *    Caller will turn frag into a ".space 0".
  1878.  */
  1879. void
  1880. md_convert_frag (fragP)
  1881.      register fragS *    fragP;
  1882. {
  1883.   register uchar * opcode;
  1884.   uchar * where_to_put_displacement;
  1885.   uint target_address, opcode_address;
  1886.   uint extension;
  1887.   int displacement_from_opcode_start;
  1888.  
  1889.   opcode = (uchar *) fragP -> fr_opcode;
  1890.  
  1891.   /* Address we want to reach in file space. */
  1892.   target_address = fragP->fr_symbol->sy_value + fragP->fr_offset;
  1893.  
  1894.   /* Address opcode resides at in file space. */
  1895.   opcode_address = fragP->fr_address + fragP->fr_fix;
  1896.  
  1897.   /* Displacement from opcode start to fill into instruction. */
  1898.   displacement_from_opcode_start = target_address - opcode_address;
  1899.  
  1900.   switch (fragP->fr_subtype) {
  1901.   case ENCODE_RELAX_STATE (COND_JUMP, BYTE):
  1902.   case ENCODE_RELAX_STATE (UNCOND_JUMP, BYTE):
  1903.     /* don't have to change opcode */
  1904.     extension = 1;        /* 1 opcode + 1 displacement */
  1905.     where_to_put_displacement = &opcode[1];
  1906.     break;
  1907.  
  1908.   case ENCODE_RELAX_STATE (COND_JUMP, WORD):
  1909.     opcode[1] = TWO_BYTE_OPCODE_ESCAPE;
  1910.     opcode[2] = opcode[0] + 0x10;
  1911.     opcode[0] = WORD_PREFIX_OPCODE;
  1912.     extension = 4;        /* 3 opcode + 2 displacement */
  1913.     where_to_put_displacement = &opcode[3];
  1914.     break;
  1915.  
  1916.   case ENCODE_RELAX_STATE (UNCOND_JUMP, WORD):
  1917.     opcode[1] = 0xe9;
  1918.     opcode[0] = WORD_PREFIX_OPCODE;
  1919.     extension = 3;        /* 2 opcode + 2 displacement */
  1920.     where_to_put_displacement = &opcode[2];
  1921.     break;
  1922.  
  1923.   case ENCODE_RELAX_STATE (COND_JUMP, DWORD):
  1924.     opcode[1] = opcode[0] + 0x10;
  1925.     opcode[0] = TWO_BYTE_OPCODE_ESCAPE;
  1926.     extension = 5;        /* 2 opcode + 4 displacement */
  1927.     where_to_put_displacement = &opcode[2];
  1928.     break;
  1929.  
  1930.   case ENCODE_RELAX_STATE (UNCOND_JUMP, DWORD):
  1931.     opcode[0] = 0xe9;
  1932.     extension = 4;        /* 1 opcode + 4 displacement */
  1933.     where_to_put_displacement = &opcode[1];
  1934.     break;
  1935.  
  1936.   default:
  1937.     BAD_CASE(fragP -> fr_subtype);
  1938.     break;
  1939.   }
  1940.   /* now put displacement after opcode */
  1941.   md_number_to_chars (where_to_put_displacement,
  1942.               displacement_from_opcode_start - extension,
  1943.               SIZE_FROM_RELAX_STATE (fragP->fr_subtype));
  1944.   fragP -> fr_fix += extension;
  1945. }
  1946.  
  1947.  
  1948. int md_short_jump_size = 2;    /* size of byte displacement jmp */
  1949. int md_long_jump_size  = 5;    /* size of dword displacement jmp */
  1950.  
  1951. void md_create_short_jump(ptr, from_addr, to_addr)
  1952.      char    *ptr;
  1953.      long    from_addr, to_addr;
  1954. {
  1955.   long offset;
  1956.  
  1957.   offset = to_addr - (from_addr + 2);
  1958.   md_number_to_chars (ptr, (long) 0xeb, 1); /* opcode for byte-disp jump */
  1959.   md_number_to_chars (ptr + 1, offset, 1);
  1960. }
  1961.  
  1962. void md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1963.      char    *ptr;
  1964.      long    from_addr, to_addr;
  1965.      fragS    *frag;
  1966.      symbolS    *to_symbol;
  1967. {
  1968.   long offset;
  1969.  
  1970.   if (flagseen['m']) {
  1971.     offset = to_addr - to_symbol->sy_value;
  1972.     md_number_to_chars (ptr, 0xe9, 1); /* opcode for long jmp */
  1973.     md_number_to_chars (ptr + 1, offset, 4);
  1974.     fix_new (frag, (ptr+1) - frag->fr_literal, 4,
  1975.          to_symbol, (symbolS *) 0, (long int) 0, 0);
  1976.   } else {
  1977.     offset = to_addr - (from_addr + 5);
  1978.     md_number_to_chars(ptr, (long) 0xe9, 1);
  1979.     md_number_to_chars(ptr + 1, offset, 4);
  1980.   }
  1981. }
  1982.  
  1983. int
  1984. md_parse_option(argP,cntP,vecP)
  1985. char **argP;
  1986. int *cntP;
  1987. char ***vecP;
  1988. {
  1989.     return 1;
  1990. }
  1991.  
  1992. void                /* Knows about order of bytes in address. */
  1993. md_number_to_chars (con, value, nbytes)
  1994.      char    con [];    /* Return 'nbytes' of chars here. */
  1995.      long int    value;        /* The value of the bits. */
  1996.      int    nbytes;        /* Number of bytes in the output. */
  1997. {
  1998.   register char * p = con;
  1999.  
  2000.   switch (nbytes) {
  2001.   case 1:
  2002.     p[0] = value & 0xff;
  2003.     break;
  2004.   case 2:
  2005.     p[0] = value & 0xff;
  2006.     p[1] = (value >> 8) & 0xff;
  2007.     break;
  2008.   case 4:
  2009.     p[0] = value & 0xff;
  2010.     p[1] = (value>>8) & 0xff;
  2011.     p[2] = (value>>16) & 0xff;
  2012.     p[3] = (value>>24) & 0xff;
  2013.     break;
  2014.   default:
  2015.     BAD_CASE (nbytes);
  2016.   }
  2017. }
  2018.  
  2019. void                /* Knows about order of bytes in address. */
  2020. md_number_to_disp (con, value, nbytes)
  2021.      char    con [];    /* Return 'nbytes' of chars here. */
  2022.      long int    value;        /* The value of the bits. */
  2023.      int    nbytes;        /* Number of bytes in the output. */
  2024. {
  2025.   char * answer = alloca (nbytes);
  2026.   register char * p = answer;
  2027.  
  2028.   switch (nbytes) {
  2029.   case 1:
  2030.     *p = value;
  2031.     break;
  2032.   case 2:
  2033.     *p++   = value;
  2034.     *p = (value>>8);
  2035.     break;
  2036.   case 4:
  2037.     *p++ = value;
  2038.     *p++ = (value>>8);
  2039.     *p++ = (value>>16);
  2040.     *p = (value>>24);
  2041.     break;
  2042.   default:
  2043.     BAD_CASE (nbytes);
  2044.   }
  2045.   bcopy (answer, con, nbytes);
  2046. }
  2047.  
  2048. void                /* Knows about order of bytes in address. */
  2049. md_number_to_imm (con, value, nbytes)
  2050.      char    con [];    /* Return 'nbytes' of chars here. */
  2051.      long int    value;        /* The value of the bits. */
  2052.      int    nbytes;        /* Number of bytes in the output. */
  2053. {
  2054.   char * answer = alloca (nbytes);
  2055.   register char * p = answer;
  2056.  
  2057.   switch (nbytes) {
  2058.   case 1:
  2059.     *p = value;
  2060.     break;
  2061.   case 2:
  2062.     *p++   = value;
  2063.     *p = (value>>8);
  2064.     break;
  2065.   case 4:
  2066.     *p++ = value;
  2067.     *p++ = (value>>8);
  2068.     *p++ = (value>>16);
  2069.     *p = (value>>24);
  2070.     break;
  2071.   default:
  2072.     BAD_CASE (nbytes);
  2073.   }
  2074.   bcopy (answer, con, nbytes);
  2075. }
  2076.  
  2077. void                /* Knows about order of bytes in address. */
  2078. md_number_to_field (con, value, nbytes)
  2079.      char    con [];    /* Return 'nbytes' of chars here. */
  2080.      long int    value;        /* The value of the bits. */
  2081.      int    nbytes;        /* Number of bytes in the output. */
  2082. {
  2083.   char * answer = alloca (nbytes);
  2084.   register char * p = answer;
  2085.  
  2086.   switch (nbytes) {
  2087.   case 1:
  2088.     *p = value;
  2089.     break;
  2090.   case 2:
  2091.     *p++   = value;
  2092.     *p = (value>>8);
  2093.     break;
  2094.   case 4:
  2095.     *p++ = value;
  2096.     *p++ = (value>>8);
  2097.     *p++ = (value>>16);
  2098.     *p = (value>>24);
  2099.     break;
  2100.   default:
  2101.     BAD_CASE (nbytes);
  2102.   }
  2103.   bcopy (answer, con, nbytes);
  2104. }
  2105.  
  2106. long int            /* Knows about the byte order in a word. */
  2107. md_chars_to_number (con, nbytes)
  2108. unsigned     char    con[];    /* Low order byte 1st. */
  2109.      int    nbytes;        /* Number of bytes in the input. */
  2110. {
  2111.   long int    retval;
  2112.   for (retval=0, con+=nbytes-1; nbytes--; con--)
  2113.     {
  2114.       retval <<= BITS_PER_CHAR;
  2115.       retval |= *con;
  2116.     }
  2117.   return retval;
  2118. }
  2119.  
  2120. void md_ri_to_chars(ri_p, ri)
  2121.      struct relocation_info *ri_p, ri;
  2122. {
  2123.   unsigned char the_bytes[8];
  2124.   
  2125.   /* this is easy */
  2126.   md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  2127.   /* now the fun stuff */
  2128.   the_bytes[6] = (ri.r_symbolnum >> 16) & 0x0ff;
  2129.   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  2130.   the_bytes[4] = ri.r_symbolnum & 0x0ff;
  2131.   the_bytes[7] = (((ri.r_extern << 3)  & 0x08) | ((ri.r_length << 1) & 0x06) | 
  2132.     ((ri.r_pcrel << 0)  & 0x01)) & 0x0F; 
  2133.   /* now put it back where you found it */
  2134.   bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  2135. }
  2136.  
  2137.  
  2138. #define MAX_LITTLENUMS 6
  2139.  
  2140. /* Turn the string pointed to by litP into a floating point constant of type
  2141.    type, and emit the appropriate bytes.  The number of LITTLENUMS emitted
  2142.    is stored in *sizeP .  An error message is returned, or NULL on OK.
  2143.  */
  2144. char *
  2145. md_atof(type,litP,sizeP)
  2146.      char type;
  2147.      char *litP;
  2148.      int *sizeP;
  2149. {
  2150.   int    prec;
  2151.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2152.   LITTLENUM_TYPE *wordP;
  2153.   char    *t;
  2154.   char    *atof_ieee();
  2155.  
  2156.   switch(type) {
  2157.   case 'f':
  2158.   case 'F':
  2159.     prec = 2;
  2160.     break;
  2161.  
  2162.   case 'd':
  2163.   case 'D':
  2164.     prec = 4;
  2165.     break;
  2166.  
  2167.   case 'x':
  2168.   case 'X':
  2169.     prec = 5;
  2170.     break;
  2171.  
  2172.   default:
  2173.     *sizeP=0;
  2174.     return "Bad call to md_atof ()";
  2175.   }
  2176.   t = atof_ieee (input_line_pointer,type,words);
  2177.   if(t)
  2178.     input_line_pointer=t;
  2179.  
  2180.   *sizeP = prec * sizeof(LITTLENUM_TYPE);
  2181.   /* this loops outputs the LITTLENUMs in REVERSE order; in accord with
  2182.      the bigendian 386 */
  2183.   for(wordP = words + prec - 1;prec--;) {
  2184.     md_number_to_chars (litP, (long) (*wordP--), sizeof(LITTLENUM_TYPE));
  2185.     litP += sizeof(LITTLENUM_TYPE);
  2186.   }
  2187.   return "";    /* Someone should teach Dean about null pointers */
  2188. }
  2189.  
  2190. char output_invalid_buf[8];
  2191.  
  2192. char * output_invalid (c)
  2193.      char c;
  2194. {
  2195.   if (isprint(c)) sprintf (output_invalid_buf, "'%c'", c);
  2196.   else sprintf (output_invalid_buf, "(0x%x)", c);
  2197.   return output_invalid_buf;
  2198. }
  2199.  
  2200. reg_entry *parse_register (reg_string)
  2201.     char *reg_string;          /* reg_string starts *before* REGISTER_PREFIX */
  2202. {
  2203.   register char *s = reg_string;
  2204.   register char *p;
  2205.   char reg_name_given[MAX_REG_NAME_SIZE];
  2206.  
  2207.   s++;                /* skip REGISTER_PREFIX */
  2208.   for (p = reg_name_given; is_register_char (*s); p++, s++) {
  2209.     *p = register_chars [*s];
  2210.     if (p >= reg_name_given + MAX_REG_NAME_SIZE)
  2211.       return (reg_entry *) 0;
  2212.   }
  2213.   *p = '\0';
  2214.   return (reg_entry *) hash_find (reg_hash, reg_name_given);
  2215. }
  2216.  
  2217.  
  2218. #ifdef NeXT
  2219. int
  2220. is_local_symbol(struct symbol *sym)
  2221. {
  2222.     int c;
  2223.  
  2224.     if (sym->sy_name[0] == 'L') {
  2225.     return 1;
  2226.     }
  2227.     return 0;
  2228. }
  2229.  
  2230. int
  2231. add_seg_prefix(seg_prefix)
  2232. {
  2233.   unsigned long j;
  2234.  
  2235.   for(j = 0; j < i.prefixes; j++){
  2236.     if(i.prefix[j] == /* cs */ 0x2e ||
  2237.        i.prefix[j] == /* ds */ 0x3e ||
  2238.        i.prefix[j] == /* es */ 0x26 ||
  2239.        i.prefix[j] == /* fs */ 0x64 ||
  2240.        i.prefix[j] == /* gs */ 0x65 ||
  2241.        i.prefix[j] == /* ss */ 0x36){
  2242.       as_bad ("segment override specified more than once");
  2243.       return(1);
  2244.     }
  2245.   }
  2246.   if (i.prefixes == MAX_PREFIXES) {
  2247.     as_bad ("too many opcode prefixes");
  2248.     return(1);
  2249.   }
  2250.   i.prefix[i.prefixes++] = seg_prefix;
  2251.   return(0);
  2252. }
  2253. #endif
  2254.  
  2255.