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