Browse Source

Merged revisions 2791-2793,2798-2800,2806-2825,2829-2830,2833,2839,2898 via svnmerge from
http://svn.freepascal.org/svn/fpc/branches/linker/compiler

........
r2791 | peter | 2006-03-06 14:57:20 +0100 (Mon, 06 Mar 2006) | 3 lines

* disable internal linker if -s is used
* enable section smartlink by default for internal linker

........
r2792 | peter | 2006-03-06 14:58:23 +0100 (Mon, 06 Mar 2006) | 2 lines

* support long sectionnames

........
r2793 | peter | 2006-03-06 15:04:12 +0100 (Mon, 06 Mar 2006) | 2 lines

* register symbols in section also when reading .o files

........
r2798 | peter | 2006-03-07 10:08:07 +0100 (Tue, 07 Mar 2006) | 2 lines

* symbolrefs need to be loaded from relocations when loading a .o

........
r2799 | peter | 2006-03-07 16:17:52 +0100 (Tue, 07 Mar 2006) | 3 lines

* remove unreferenced sections
* set stacksize in peopthaeder

........
r2800 | peter | 2006-03-07 17:02:46 +0100 (Tue, 07 Mar 2006) | 2 lines

* objsection.fullname added

........
........
r2807 | peter | 2006-03-08 08:18:04 +0100 (Wed, 08 Mar 2006) | 2 lines

* powerpc64 fixes

........
r2808 | peter | 2006-03-08 08:35:53 +0100 (Wed, 08 Mar 2006) | 2 lines

* register x86_64_pecoff

........
r2809 | peter | 2006-03-08 11:26:38 +0100 (Wed, 08 Mar 2006) | 2 lines

* optimize and cleanup matches()

........
r2810 | peter | 2006-03-08 12:25:28 +0100 (Wed, 08 Mar 2006) | 2 lines

* small tweak to readdata to copy values direct without calling move()

........
r2811 | peter | 2006-03-08 15:55:21 +0100 (Wed, 08 Mar 2006) | 2 lines

* compile fix

........
........
........
........
........
........
r2817 | peter | 2006-03-09 14:20:52 +0100 (Thu, 09 Mar 2006) | 2 lines

* more readable with long secnames

........
........
........
........
........
........
........
........
r2825 | peter | 2006-03-10 09:52:05 +0100 (Fri, 10 Mar 2006) | 2 lines

* don't initialize/finalize external variables

........
r2829 | peter | 2006-03-10 10:58:08 +0100 (Fri, 10 Mar 2006) | 2 lines

* merge 64bit assembler

........
r2830 | peter | 2006-03-10 12:25:08 +0100 (Fri, 10 Mar 2006) | 2 lines

* TElfAssembler rename

........
r2833 | peter | 2006-03-10 15:22:27 +0100 (Fri, 10 Mar 2006) | 3 lines

* support & prefix to force identifier parsing, used to access fields that
have the names of a register

........
r2839 | peter | 2006-03-10 19:37:11 +0100 (Fri, 10 Mar 2006) | 2 lines

* merge stabs section flags

........
r2898 | peter | 2006-03-12 23:18:18 +0100 (Sun, 12 Mar 2006) | 2 lines

* reorder instructions for better first match

........

git-svn-id: trunk@2902 -

peter 19 years ago
parent
commit
17bc033747

+ 1 - 1
compiler/cg64f32.pas

@@ -401,7 +401,7 @@ unit cg64f32;
           LOC_CREGISTER :
             cg.a_load_reg_reg(list,OS_32,OS_32,l.register64.reghi,reg);
           LOC_CONSTANT :
-            cg.a_load_const_reg(list,OS_32,hi(l.value64),reg);
+            cg.a_load_const_reg(list,OS_32,aint(hi(l.value64)),reg);
           else
             internalerror(200203244);
         end;

+ 56 - 0
compiler/cutils.pas

@@ -60,6 +60,7 @@ interface
     procedure Replace(var s:string;s1:string;const s2:string);
     procedure Replace(var s:AnsiString;s1:string;const s2:string);
     procedure ReplaceCase(var s:string;const s1,s2:string);
+    Function MatchPattern(const pattern,what:string):boolean;
     function upper(const s : string) : string;
     function lower(const s : string) : string;
     function trimbspace(const s:string):string;
@@ -347,6 +348,61 @@ uses
       end;
 
 
+    Function MatchPattern(const pattern,what:string):boolean;
+      var
+        found : boolean;
+        i1,i2 : longint;
+      begin
+        i1:=0;
+        i2:=0;
+        if pattern='' then
+          begin
+            result:=(what='');
+            exit;
+          end;
+        found:=true;
+        repeat
+          inc(i1);
+          if (i1>length(pattern)) then
+            break;
+          inc(i2);
+          if (i2>length(what)) then
+            break;
+          case pattern[i1] of
+            '?' :
+              found:=true;
+            '*' :
+              begin
+                found:=true;
+                if (i1=length(pattern)) then
+                 i2:=length(what)
+                else
+                 if (i1<length(pattern)) and (pattern[i1+1]<>what[i2]) then
+                  begin
+                    if i2<length(what) then
+                     dec(i1)
+                  end
+                else
+                 if i2>1 then
+                  dec(i2);
+              end;
+            else
+              found:=(pattern[i1]=what[i2]) or (what[i2]='?');
+          end;
+        until not found;
+        if found then
+          begin
+            found:=(i2>=length(what)) and
+                   (
+                    (i1>length(pattern)) or
+                    ((i1=length(pattern)) and
+                     (pattern[i1]='*'))
+                   );
+          end;
+        result:=found;
+      end;
+
+
     function upper(const s : string) : string;
     {
       return uppercased string of s

File diff suppressed because it is too large
+ 264 - 271
compiler/i386/i386tab.inc


+ 14 - 0
compiler/i386/ra386int.pas

@@ -528,6 +528,20 @@ Unit Ra386int;
                  exit;
                end;
 
+             '&' : { identifier }
+               begin
+                 actasmpattern:='';
+                 c:=current_scanner.asmgetchar;
+                 while c in  ['A'..'Z','a'..'z','0'..'9','_'] do
+                  begin
+                    actasmpattern:=actasmpattern + c;
+                    c:=current_scanner.asmgetchar;
+                  end;
+                 uppervar(actasmpattern);
+                 actasmtoken:=AS_ID;
+                 exit;
+               end;
+
              ',' :
                begin
                  actasmtoken:=AS_COMMA;

+ 1 - 0
compiler/link.pas

@@ -897,6 +897,7 @@ end;
 
         { Create .exe sections and add .o sections }
         ParseScript_Order;
+        exeoutput.RemoveUnreferencedSections;
         exeoutput.RemoveEmptySections;
         if ErrorCount>0 then
           goto myexit;

+ 8 - 4
compiler/ncgutil.pas

@@ -892,6 +892,7 @@ implementation
       begin
         if (tsym(p).typ in [globalvarsym,localvarsym]) and
            (tabstractvarsym(p).refs>0) and
+           not(vo_is_external in tabstractvarsym(p).varoptions) and
            not(is_class(tabstractvarsym(p).vartype.def)) and
            tabstractvarsym(p).vartype.def.needs_inittable then
          begin
@@ -927,6 +928,7 @@ implementation
       begin
         if (tsym(p).typ=localvarsym) and
            (tlocalvarsym(p).refs>0) and
+           not(vo_is_external in tlocalvarsym(p).varoptions) and
            not(vo_is_funcret in tlocalvarsym(p).varoptions) and
            not(is_class(tlocalvarsym(p).vartype.def)) and
            tlocalvarsym(p).vartype.def.needs_inittable then
@@ -974,6 +976,7 @@ implementation
             begin
               if (tglobalvarsym(p).refs>0) and
                  not(vo_is_funcret in tglobalvarsym(p).varoptions) and
+                 not(vo_is_external in tglobalvarsym(p).varoptions) and
                  not(is_class(tglobalvarsym(p).vartype.def)) and
                  tglobalvarsym(p).vartype.def.needs_inittable then
                 finalize_sym(taasmoutput(arg),tsym(p));
@@ -1960,7 +1963,8 @@ implementation
 
     procedure insertbssdata(sym : tglobalvarsym);
       var
-        l,varalign : longint;
+        l : aint;
+        varalign : shortint;
         storefilepos : tfileposinfo;
         list : Taasmoutput;
         sectype : TAsmSectiontype;
@@ -1988,7 +1992,7 @@ implementation
             list:=asmlist[al_globals];
             sectype:=sec_bss;
           end;
-        varalign:=var_align(l);
+        varalign:=var_align(size_2_align(l));
         maybe_new_object_file(list);
         new_section(list,sectype,lower(sym.mangledname),varalign);
         if (sym.owner.symtabletype=globalsymtable) or
@@ -2176,7 +2180,7 @@ implementation
         foreachnodestatic(n,@do_get_used_regvars,@rv);
       end;
 
-{
+(*
     See comments at declaration of pusedregvarscommon
 
     function do_get_used_regvars_common(var n: tnode; arg: pointer): foreachnoderesult;
@@ -2214,7 +2218,7 @@ implementation
         rv.myregvars.mmregvars.clear;
         foreachnodestatic(n,@do_get_used_regvars_common,@rv);
       end;
-}
+*)
 
     procedure gen_sync_regvars(list:TAAsmoutput; var rv: tusedregvars);
       var

+ 151 - 46
compiler/ogbase.pas

@@ -128,6 +128,7 @@ interface
        ObjSymbolDefines  : TFPObjectList;
        { executable linking }
        ExeSection  : TExeSection;
+       Used       : boolean;
        constructor create(const Aname:string;Aalign:shortint;Aoptions:TObjSectionOptions);virtual;
        destructor  destroy;override;
        function  write(const d;l:aint):aint;
@@ -141,6 +142,7 @@ interface
        procedure AddSymbolDefine(p:TObjSymbol);
        procedure AddSymbolRef(p:TObjSymbol);
        procedure fixuprelocs;virtual;
+       function  FullName:string;
        property  Data:TDynamicArray read FData;
        property  SecOptions:TObjSectionOptions read FSecOptions write SetSecOptions;
      end;
@@ -162,10 +164,10 @@ interface
        { Special info sections that are written to during object generation }
        FStabsObjSec,
        FStabStrObjSec : TObjSection;
-       procedure section_reset(p:tnamedindexitem;arg:pointer);
-       procedure section_afteralloc(p:tnamedindexitem;arg:pointer);
-       procedure section_afterwrite(p:tnamedindexitem;arg:pointer);
-       procedure section_fixuprelocs(p:tnamedindexitem;arg:pointer);
+       procedure section_reset(p:TObject;arg:pointer);
+       procedure section_afteralloc(p:TObject;arg:pointer);
+       procedure section_afterwrite(p:TObject;arg:pointer);
+       procedure section_fixuprelocs(p:TObject;arg:pointer);
      protected
        property StabsSec:TObjSection read FStabsObjSec write FStabsObjSec;
        property StabStrSec:TObjSection read FStabStrObjSec write FStabStrObjSec;
@@ -186,6 +188,7 @@ interface
        procedure removesection(asec:TObjSection);
        procedure setsection(asec:TObjSection);
        { Symbols }
+       function  createsymbol(const aname:string):TObjSymbol;
        function  symboldefine(asmsym:TAsmSymbol):TObjSymbol;
        function  symboldefine(const aname:string;abind:TAsmsymbind;atyp:Tasmsymtype):TObjSymbol;
        function  symbolref(asmsym:TAsmSymbol):TObjSymbol;
@@ -329,6 +332,7 @@ interface
         procedure PrintMemoryMap;
         procedure FixUpSymbols;
         procedure FixUpRelocations;
+        procedure RemoveUnreferencedSections;
         procedure RemoveEmptySections;
         procedure ResolveExternals(const libname:string);virtual;
         function  writeexefile(const fn:string):boolean;
@@ -582,8 +586,8 @@ implementation
 
     procedure TObjSection.AddSymbolRef(p:TObjSymbol);
       begin
-        if p.bind=AB_LOCAL then
-          exit;
+        { Register all references, also the local references between the
+          ObjSections in an ObjData }
         ObjSymbolRefs.Add(p);
       end;
 
@@ -593,6 +597,15 @@ implementation
       end;
 
 
+    function  TObjSection.FullName:string;
+      begin
+        if assigned(objdata) then
+          result:=objdata.Name+'('+Name+')'
+        else
+          result:=Name;
+      end;
+
+
 {****************************************************************************
                                 TObjData
 ****************************************************************************}
@@ -600,7 +613,7 @@ implementation
     constructor TObjData.create(const n:string);
       begin
         inherited create;
-        FName:=n;
+        FName:=SplitFileName(n);
         { sections, the SectsIndex owns the items, the FObjSectionDict
           is only used for lookups }
         FObjSectionDict:=tdictionary.create;
@@ -681,11 +694,12 @@ implementation
           {stub} [oso_data,oso_load,oso_readonly,oso_executable],
           {stab} [oso_data,oso_noload,oso_debug],
           {stabstr} [oso_data,oso_noload,oso_strings,oso_debug],
-          {idata2} [oso_data,oso_load,oso_write],
-          {idata4} [oso_data,oso_load,oso_write],
-          {idata5} [oso_data,oso_load,oso_write],
-          {idata6} [oso_data,oso_load,oso_write],
-          {idata7} [oso_data,oso_load,oso_write],
+{$warning TODO idata keep can maybe replaced with grouping of text and idata}
+          {idata2} [oso_data,oso_load,oso_write,oso_keep],
+          {idata4} [oso_data,oso_load,oso_write,oso_keep],
+          {idata5} [oso_data,oso_load,oso_write,oso_keep],
+          {idata6} [oso_data,oso_load,oso_write,oso_keep],
+          {idata7} [oso_data,oso_load,oso_write,oso_keep],
           {edata} [oso_data,oso_load,oso_readonly],
           {eh_frame} [oso_data,oso_load,oso_readonly],
           {debug_frame} [oso_data,oso_noload,oso_debug],
@@ -741,7 +755,6 @@ implementation
       begin
         FObjSectionDict.Delete(asec.name);
         FObjSectionList.Remove(asec);
-        asec.free;
       end;
 
 
@@ -753,6 +766,18 @@ implementation
       end;
 
 
+    function TObjData.createsymbol(const aname:string):TObjSymbol;
+      begin
+        result:=TObjSymbol(FObjSymbolDict.search(aname));
+        if not assigned(result) then
+          begin
+            result:=TObjSymbol.Create(aname);
+            FObjSymbolDict.Insert(result);
+            FObjSymbolList.Add(result);
+          end;
+      end;
+
+
     function TObjData.symboldefine(asmsym:TAsmSymbol):TObjSymbol;
       begin
         if assigned(asmsym) then
@@ -780,13 +805,7 @@ implementation
       begin
         if not assigned(CurrObjSec) then
           internalerror(200603051);
-        result:=TObjSymbol(FObjSymbolDict.search(aname));
-        if not assigned(result) then
-          begin
-            result:=TObjSymbol.Create(aname);
-            FObjSymbolDict.Insert(result);
-            FObjSymbolList.Add(result);
-          end;
+        result:=CreateSymbol(aname);
         { Register also in TObjSection }
         CurrObjSec.AddSymbolDefine(result);
         result.SetAddress(CurrPass,CurrObjSec,abind,atyp);
@@ -819,13 +838,7 @@ implementation
       begin
         if not assigned(CurrObjSec) then
           internalerror(200603052);
-        result:=TObjSymbol(FObjSymbolDict.search(aname));
-        if not assigned(result) then
-          begin
-            result:=TObjSymbol.Create(aname);
-            FObjSymbolDict.Insert(result);
-            FObjSymbolList.Add(result);
-          end;
+        result:=CreateSymbol(aname);
         { Register also in TObjSection }
         CurrObjSec.AddSymbolRef(result);
       end;
@@ -875,14 +888,14 @@ implementation
       end;
 
 
-    procedure TObjData.section_afteralloc(p:tnamedindexitem;arg:pointer);
+    procedure TObjData.section_afteralloc(p:TObject;arg:pointer);
       begin
         with TObjSection(p) do
           alloc(align(size,secalign)-size);
       end;
 
 
-    procedure TObjData.section_afterwrite(p:tnamedindexitem;arg:pointer);
+    procedure TObjData.section_afterwrite(p:TObject;arg:pointer);
       begin
         with TObjSection(p) do
           begin
@@ -892,7 +905,7 @@ implementation
       end;
 
 
-    procedure TObjData.section_reset(p:tnamedindexitem;arg:pointer);
+    procedure TObjData.section_reset(p:TObject;arg:pointer);
       begin
         with TObjSection(p) do
           begin
@@ -903,9 +916,10 @@ implementation
       end;
 
 
-    procedure TObjData.section_fixuprelocs(p:tnamedindexitem;arg:pointer);
+    procedure TObjData.section_fixuprelocs(p:TObject;arg:pointer);
       begin
-        TObjSection(p).fixuprelocs;
+        if TObjSection(p).Used then
+          TObjSection(p).fixuprelocs;
       end;
 
 
@@ -936,7 +950,7 @@ implementation
 
     procedure TObjData.afteralloc;
       begin
-        FObjSectionDict.foreach(@section_afteralloc,nil);
+        FObjSectionList.ForEachCall(@section_afteralloc,nil);
       end;
 
 
@@ -945,7 +959,7 @@ implementation
         s : string[1];
         hstab : TObjStabEntry;
       begin
-        FObjSectionDict.foreach(@section_afterwrite,nil);
+        FObjSectionList.ForEachCall(@section_afterwrite,nil);
         { For the stab section we need an HdrSym which can now be
           calculated more easily }
         if assigned(StabsSec) then
@@ -966,13 +980,13 @@ implementation
 
     procedure TObjData.resetsections;
       begin
-        FObjSectionDict.foreach(@section_reset,nil);
+        FObjSectionList.ForEachCall(@section_reset,nil);
       end;
 
 
     procedure TObjData.fixuprelocs;
       begin
-        FObjSectionDict.foreach(@section_fixuprelocs,nil);
+        FObjSectionList.ForEachCall(@section_fixuprelocs,nil);
       end;
 
 
@@ -1130,8 +1144,6 @@ implementation
         FExeSectionDict.free;
         FExeSectionList.free;
         objdatalist.free;
-        internalobjdata.free;
-        commonobjdata.free;
         FWriter.free;
       end;
 
@@ -1229,19 +1241,21 @@ implementation
 
     procedure TExeOutput.Order_ObjSection(const aname:string);
       var
-        i       : longint;
+        i,j     : longint;
         objdata : TObjData;
         objsec  : TObjSection;
       begin
         if not assigned(CurrExeSec) then
           internalerror(200602181);
-{$warning TODO Add wildcard support like *(.text*)}
         for i:=0 to ObjDataList.Count-1 do
           begin
             objdata:=TObjData(ObjDataList[i]);
-            objsec:=objdata.findsection(aname);
-            if assigned(objsec) then
-              CurrExeSec.AddObjSection(objsec);
+            for j:=0 to objdata.ObjSectionList.Count-1 do
+              begin
+                objsec:=TObjSection(objdata.ObjSectionList[j]);
+                if MatchPattern(aname,objsec.name) then
+                  CurrExeSec.AddObjSection(objsec);
+              end;
           end;
       end;
 
@@ -1272,7 +1286,7 @@ implementation
           internalerror(200602254);
         fillchar(zeros,len,0);
         inc(Fzeronr);
-        objsec:=internalobjdata.createsection('*zeros'+tostr(Fzeronr),0,CurrExeSec.SecOptions+[oso_data]);
+        objsec:=internalobjdata.createsection('*zeros'+tostr(Fzeronr),0,CurrExeSec.SecOptions+[oso_data,oso_keep]);
         internalobjdata.writebytes(zeros,len);
         internalobjdata.afterwrite;
         CurrExeSec.AddObjSection(objsec);
@@ -1492,8 +1506,6 @@ implementation
             for j:=0 to objdata.ObjSymbolList.Count-1 do
               begin
                 objsym:=TObjSymbol(objdata.ObjSymbolList[j]);
-                if not assigned(objsym.ObjSection) then
-                  internalerror(200206302);
                 { Skip local symbols }
                 if objsym.bind=AB_LOCAL then
                   continue;
@@ -1691,6 +1703,99 @@ implementation
       end;
 
 
+    procedure TExeOutput.RemoveUnreferencedSections;
+      var
+        ObjSectionWorkList : TFPObjectList;
+
+        procedure AddToObjSectionWorkList(aobjsec:TObjSection);
+        begin
+          if not aobjsec.Used then
+            begin
+              aobjsec.Used:=true;
+              ObjSectionWorkList.Add(aobjsec);
+            end;
+        end;
+
+      var
+        i,j     : longint;
+        exesec  : TExeSection;
+        objdata : TObjData;
+        refobjsec,
+        objsec  : TObjSection;
+        objsym  : TObjSymbol;
+      begin
+        ObjSectionWorkList:=TFPObjectList.Create(false);
+
+        if assigned(exemap) then
+          exemap.AddHeader('Removing unreferenced sections');
+
+        { Initialize by marking all sections unused and
+          adding the sections with oso_keep flags to the ObjSectionWorkList }
+        for i:=0 to ObjDataList.Count-1 do
+          begin
+            objdata:=TObjData(ObjDataList[i]);
+            for j:=0 to objdata.ObjSectionList.Count-1 do
+              begin
+                objsec:=TObjSection(objdata.ObjSectionList[j]);
+                objsec.Used:=false;
+{$warning TODO remove debug section always keep}
+                if oso_debug in objsec.secoptions then
+                  objsec.Used:=true;
+                if (oso_keep in objsec.secoptions) then
+                  AddToObjSectionWorkList(objsec);
+              end;
+          end;
+        AddToObjSectionWorkList(entrysym.exesymbol.objsymbol.objsection);
+
+        { Process all sections, add new sections to process based
+          on the symbol references  }
+        while ObjSectionWorkList.Count>0 do
+          begin
+            objsec:=TObjSection(ObjSectionWorkList.Last);
+            if assigned(exemap) then
+              exemap.Add('Keeping '+objsec.FullName+' '+ToStr(objsec.ObjSymbolRefs.Count)+' references');
+            ObjSectionWorkList.Delete(ObjSectionWorkList.Count-1);
+            for i:=0 to objsec.ObjSymbolRefs.count-1 do
+              begin
+                objsym:=TObjSymbol(objsec.ObjSymbolRefs[i]);
+                if objsym.bind=AB_LOCAL then
+                  begin
+                    if not assigned(objsym.objsection) then
+                      internalerror(200603062);
+                    refobjsec:=objsym.objsection
+                  end
+                else
+                  begin
+                    if not(assigned(objsym.exesymbol) and
+                           assigned(objsym.exesymbol.objsymbol)) then
+                      internalerror(200603063);
+                    refobjsec:=objsym.exesymbol.objsymbol.objsection;
+                  end;
+                if assigned(exemap) then
+                  exemap.Add('  References '+refobjsec.fullname);
+                AddToObjSectionWorkList(refobjsec);
+              end;
+          end;
+
+        { Remove unused objsections from exesections }
+        for i:=0 to ExeSections.Count-1 do
+          begin
+            exesec:=TExeSection(ExeSections[i]);
+            for j:=0 to exesec.ObjSectionlist.count-1 do
+              begin
+                objsec:=TObjSection(exesec.ObjSectionlist[j]);
+                if not objsec.used then
+                  begin
+                    if assigned(exemap) then
+                      exemap.Add('Removing '+objsec.FullName);
+                    exesec.ObjSectionlist[j]:=nil;
+                  end;
+              end;
+            exesec.ObjSectionlist.Pack;
+          end;
+      end;
+
+
     procedure TExeOutput.FixUpRelocations;
       var
         i       : longint;

+ 135 - 67
compiler/ogcoff.pas

@@ -126,7 +126,7 @@ interface
          FCoffsyms,
          FCoffStrs : tdynamicarray;
          win32     : boolean;
-         nsects    : word;
+         nsects    : smallint;
          nsyms,
          sympos    : aint;
          procedure ExeSections_pass2_header(p:TObject;arg:pointer);
@@ -155,19 +155,25 @@ interface
          procedure ResolveExternals(const libname:string);override;
        end;
 
-       tTObjSymbolrec = record
+       TObjSymbolrec = record
          sym : TObjSymbol;
          orgsize : aint;
        end;
-       tTObjSymbolarray = array[0..high(word)] of tTObjSymbolrec;
+       TObjSymbolArray = array[0..high(word)] of TObjSymbolrec;
+       TObjSectionArray = array[0..high(smallint)] of TObjSection;
 
        TCoffObjInput = class(tObjInput)
        private
-         Fidx2objsec  : array[0..255] of TObjSection;
          FCoffsyms,
          FCoffStrs : tdynamicarray;
-         FSymTbl   : ^tTObjSymbolarray;
+         { Convert symidx -> TObjSymbol }
+         FSymTbl   : ^TObjSymbolArray;
+         { Convert secidx -> TObjSection }
+         FSecCount : smallint;
+         FSecTbl   : ^TObjSectionArray;
          win32     : boolean;
+         function  GetSection(secidx:longint):TObjSection;
+         function  Read_str(strpos:longint):string;
          procedure read_relocs(s:TCoffObjSection);
          procedure read_symbols(objdata:TObjData);
          procedure ObjSections_read_data(p:TObject;arg:pointer);
@@ -322,7 +328,7 @@ implementation
        { Structures which are written directly to the output file }
        coffheader=packed record
          mach   : word;
-         nsects : word;
+         nsects : smallint;
          time   : longint;
          sympos : longint;
          syms   : longint;
@@ -405,7 +411,7 @@ implementation
          strpos  : longint;
          value   : longint;
          section : smallint;
-         empty   : smallint;
+         empty   : word;
          typ     : byte;
          aux     : byte;
        end;
@@ -727,6 +733,10 @@ const win32stub : array[0..131] of byte=(
                 end
             else
               internalerror(200205183);
+            { Only debug section are allowed to have }
+            if not relocsec.used and
+               not(oso_debug in secoptions) then
+              internalerror(200603061);
             case r.typ of
               RELOC_RELATIVE  :
                 begin
@@ -1097,12 +1107,12 @@ const win32stub : array[0..131] of byte=(
 
     procedure TCoffObjOutput.create_symbols(data:TObjData);
       var
-        filename  : string[18];
-        sectionval,
-        globalval : byte;
-        i         : longint;
-        value     : aint;
-        objsym    : TObjSymbol;
+        filename   : string[18];
+        sectionval : word;
+        globalval  : byte;
+        i          : longint;
+        value      : aint;
+        objsym     : TObjSymbol;
       begin
         with TCoffObjData(data) do
          begin
@@ -1313,6 +1323,29 @@ const win32stub : array[0..131] of byte=(
       end;
 
 
+    function TCoffObjInput.GetSection(secidx:longint):TObjSection;
+      begin
+        result:=nil;
+        if (secidx<1) or (secidx>FSecCount) then
+          begin
+            Comment(V_Error,'Error reading coff file, invalid section index');
+            exit;
+          end;
+        result:=FSecTbl^[secidx];
+      end;
+
+
+    function TCoffObjInput.Read_str(strpos:longint):string;
+      begin
+        FCoffStrs.Seek(strpos-4);
+        FCoffStrs.Read(result[1],255);
+        result[255]:=#0;
+        result[0]:=chr(strlen(@result[1]));
+        if result='' then
+          Internalerror(200205172);
+      end;
+
+
     procedure TCoffObjInput.read_relocs(s:TCoffObjSection);
       var
         rel      : coffreloc;
@@ -1338,6 +1371,8 @@ const win32stub : array[0..131] of byte=(
            if assigned(p) then
             begin
               s.addsymsizereloc(rel.address-s.mempos,p,FSymTbl^[rel.sym].orgsize,rel_type);
+              { Register symbol reference in TObjSection }
+              s.AddSymbolRef(p);
             end
            else
             begin
@@ -1356,9 +1391,9 @@ const win32stub : array[0..131] of byte=(
         symidx    : aint;
         i         : longint;
         sym       : coffsymbol;
-        strname   : string;
         objsym    : TObjSymbol;
         bind      : Tasmsymbind;
+        strname   : string;
         auxrec    : array[0..17] of byte;
         objsec    : TObjSection;
       begin
@@ -1366,8 +1401,8 @@ const win32stub : array[0..131] of byte=(
          begin
            nsyms:=FCoffSyms.Size div sizeof(CoffSymbol);
            { Allocate memory for symidx -> TObjSymbol table }
-           GetMem(FSymTbl,nsyms*sizeof(tTObjSymbolrec));
-           FillChar(FSymTbl^,nsyms*sizeof(tTObjSymbolrec),0);
+           GetMem(FSymTbl,nsyms*sizeof(TObjSymbolrec));
+           FillChar(FSymTbl^,nsyms*sizeof(TObjSymbolrec),0);
            { Load the Symbols }
            FCoffSyms.Seek(0);
            symidx:=0;
@@ -1375,23 +1410,20 @@ const win32stub : array[0..131] of byte=(
             begin
               FCoffSyms.Read(sym,sizeof(sym));
               if plongint(@sym.name)^<>0 then
-               begin
-                 move(sym.name,strname[1],8);
-                 strname[9]:=#0;
-               end
+                begin
+                  move(sym.name,strname[1],8);
+                  strname[9]:=#0;
+                  strname[0]:=chr(strlen(@strname[1]));
+                  if strname='' then
+                    Internalerror(200205171);
+                end
               else
-               begin
-                 FCoffStrs.Seek(sym.strpos-4);
-                 FCoffStrs.Read(strname[1],255);
-                 strname[255]:=#0;
-               end;
-              strname[0]:=chr(strlen(@strname[1]));
-              if strname='' then
-               Internalerror(200205172);
+                strname:=Read_str(sym.strpos);
               bind:=AB_EXTERNAL;
               size:=0;
               address:=0;
               objsym:=nil;
+              objsec:=nil;
               case sym.typ of
                 COFF_SYM_GLOBAL :
                   begin
@@ -1408,16 +1440,19 @@ const win32stub : array[0..131] of byte=(
                     else
                      begin
                        bind:=AB_GLOBAL;
-                       objsec:=Fidx2objsec[sym.section];
+                       objsec:=GetSection(sym.section);
                        if sym.value>=objsec.mempos then
                          address:=sym.value-objsec.mempos;
                      end;
-                    objsym:=symbolref(strname);
+                    objsym:=CreateSymbol(strname);
                     objsym.bind:=bind;
                     objsym.typ:=AT_FUNCTION;
                     objsym.objsection:=objsec;
                     objsym.offset:=address;
                     objsym.size:=size;
+                    { Register in ObjSection }
+                    if assigned(objsec) then
+                      objsec.AddSymbolDefine(objsym);
                   end;
                 COFF_SYM_LABEL,
                 COFF_SYM_LOCAL :
@@ -1426,10 +1461,10 @@ const win32stub : array[0..131] of byte=(
                     if sym.section<>-1 then
                      begin
                        bind:=AB_LOCAL;
-                       objsec:=Fidx2objsec[sym.section];
+                       objsec:=GetSection(sym.section);
                        if sym.value>=objsec.mempos then
                          address:=sym.value-objsec.mempos;
-                       objsym:=symbolref(strname);
+                       objsym:=CreateSymbol(strname);
                        objsym.bind:=bind;
                        objsym.typ:=AT_FUNCTION;
                        objsym.objsection:=objsec;
@@ -1441,10 +1476,10 @@ const win32stub : array[0..131] of byte=(
                   begin
                     if sym.section=0 then
                       Comment(V_Error,'Error reading coff file');
-                    objsec:=Fidx2objsec[sym.section];
+                    objsec:=GetSection(sym.section);
                     if sym.value>=objsec.mempos then
                       address:=sym.value-objsec.mempos;
-                    objsym:=symbolref(strname);
+                    objsym:=CreateSymbol(strname);
                     objsym.bind:=AB_LOCAL;
                     objsym.typ:=AT_FUNCTION;
                     objsym.objsection:=objsec;
@@ -1515,7 +1550,9 @@ const win32stub : array[0..131] of byte=(
       var
         secalign : shortint;
         strsize,
+        strpos,
         i        : longint;
+        code     : longint;
         objsec   : TCoffObjSection;
         secoptions : TObjSectionOptions;
         header   : coffheader;
@@ -1528,7 +1565,6 @@ const win32stub : array[0..131] of byte=(
         FCoffStrs:=TDynamicArray.Create(strsresize);
         with TCoffObjData(objdata) do
          begin
-           FillChar(Fidx2objsec,sizeof(Fidx2objsec),0);
            { Read COFF header }
            if not reader.read(header,sizeof(coffheader)) then
              begin
@@ -1540,15 +1576,29 @@ const win32stub : array[0..131] of byte=(
                Comment(V_Error,'Not a coff file');
                exit;
              end;
-           if header.nsects>255 then
+           { Strings }
+           Reader.Seek(header.sympos+header.syms*sizeof(CoffSymbol));
+           if not Reader.Read(strsize,4) then
              begin
-               Comment(V_Error,'Too many Sections');
+               Comment(V_Error,'Error reading coff file');
+               exit;
+             end;
+           if strsize<4 then
+             begin
+               Comment(V_Error,'Error reading coff file');
+               exit;
+             end;
+           if not Reader.ReadArray(FCoffStrs,Strsize-4) then
+             begin
+               Comment(V_Error,'Error reading coff file');
                exit;
              end;
-           { Skip optheader }
-           reader.Seek(sizeof(coffheader)+header.opthdr);
-{$warning TODO Read strings first}
            { Section headers }
+           { Allocate SecIdx -> TObjSection table, secidx is 1-based }
+           FSecCount:=header.nsects;
+           GetMem(FSecTbl,(header.nsects+1)*sizeof(TObjSection));
+           FillChar(FSecTbl^,(header.nsects+1)*sizeof(TObjSection),0);
+           reader.Seek(sizeof(coffheader)+header.opthdr);
            for i:=1 to header.nsects do
              begin
                if not reader.read(sechdr,sizeof(sechdr)) then
@@ -1556,10 +1606,20 @@ const win32stub : array[0..131] of byte=(
                   Comment(V_Error,'Error reading coff file');
                   exit;
                 end;
-{$warning TODO Support long secnames}
                move(sechdr.name,secnamebuf,8);
                secnamebuf[8]:=#0;
                secname:=strpas(secnamebuf);
+               if secname[1]='/' then
+                 begin
+                   Val(Copy(secname,2,8),strpos,code);
+                   if code=0 then
+                     secname:=Read_str(strpos)
+                   else
+                     begin
+                       Comment(V_Error,'Error reading section headers coff file');
+                       secname:='error';
+                     end;
+                 end;
                if win32 then
                  pedecodesechdrflags(secname,sechdr.flags,secoptions,secalign)
                else
@@ -1568,7 +1628,7 @@ const win32stub : array[0..131] of byte=(
                    secalign:=sizeof(aint);
                  end;
                objsec:=TCoffObjSection(createsection(secname,secalign,secoptions));
-               Fidx2objsec[i]:=objsec;
+               FSecTbl^[i]:=objsec;
                if not win32 then
                  objsec.mempos:=sechdr.rvaofs;
                objsec.orgmempos:=sechdr.rvaofs;
@@ -1576,6 +1636,9 @@ const win32stub : array[0..131] of byte=(
                objsec.coffrelocpos:=sechdr.relocpos;
                objsec.datapos:=sechdr.datapos;
                objsec.Size:=sechdr.dataSize;
+{$warning TODO idata keep can maybe replaced with grouping of text and idata}
+               if Copy(objsec.name,1,6)='.idata' then
+                 include(objsec.secoptions,oso_keep);
              end;
            { ObjSymbols }
            Reader.Seek(header.sympos);
@@ -1584,22 +1647,6 @@ const win32stub : array[0..131] of byte=(
                Comment(V_Error,'Error reading coff file');
                exit;
              end;
-           { Strings }
-           if not Reader.Read(strsize,4) then
-             begin
-               Comment(V_Error,'Error reading coff file');
-               exit;
-             end;
-           if strsize<4 then
-             begin
-               Comment(V_Error,'Error reading coff file');
-               exit;
-             end;
-           if not Reader.ReadArray(FCoffStrs,Strsize-4) then
-             begin
-               Comment(V_Error,'Error reading coff file');
-               exit;
-             end;
            { Insert all ObjSymbols }
            read_symbols(objdata);
            { Section Data }
@@ -1887,8 +1934,8 @@ const win32stub : array[0..131] of byte=(
             peoptheader.FileAlignment:=SectionDataAlign;
             peoptheader.MajorOperatingSystemVersion:=4;
             peoptheader.MinorOperatingSystemVersion:=0;
-            peoptheader.MajorImageVersion:=1;
-            peoptheader.MinorImageVersion:=0;
+            peoptheader.MajorImageVersion:=dllmajor;
+            peoptheader.MinorImageVersion:=dllminor;
             peoptheader.MajorSubsystemVersion:=4;
             peoptheader.MinorSubsystemVersion:=0;
             peoptheader.Win32Version:=0;
@@ -1898,7 +1945,7 @@ const win32stub : array[0..131] of byte=(
 {$warning TODO GUI/CUI Subsystem}
             peoptheader.Subsystem:=3;
             peoptheader.DllCharacteristics:=0;
-            peoptheader.SizeOfStackReserve:=$40000;
+            peoptheader.SizeOfStackReserve:=stacksize;
             peoptheader.SizeOfStackCommit:=$1000;
             peoptheader.SizeOfHeapReserve:=$100000;
             peoptheader.SizeOfHeapCommit:=$1000;
@@ -2254,11 +2301,11 @@ const win32stub : array[0..131] of byte=(
             Concat('ENTRYNAME _mainCRTStartup');
             Concat('HEADER');
             Concat('EXESECTION .text');
-            Concat('  OBJSECTION .text');
+            Concat('  OBJSECTION .text*');
             Concat('  SYMBOL etext');
             Concat('ENDEXESECTION');
             Concat('EXESECTION .data');
-            Concat('  OBJSECTION .data');
+            Concat('  OBJSECTION .data*');
             Concat('  SYMBOL edata');
             Concat('ENDEXESECTION');
             Concat('EXESECTION .idata');
@@ -2271,10 +2318,10 @@ const win32stub : array[0..131] of byte=(
             Concat('  OBJSECTION .idata$7');
             Concat('ENDEXESECTION');
             Concat('EXESECTION .bss');
-            Concat('  OBJSECTION .bss');
+            Concat('  OBJSECTION .bss*');
             Concat('ENDEXESECTION');
             Concat('EXESECTION .rsrc');
-            Concat('  OBJSECTION .rsrc');
+            Concat('  OBJSECTION .rsrc*');
             Concat('ENDEXESECTION');
             Concat('EXESECTION .stab');
             Concat('  OBJSECTION .stab');
@@ -2292,6 +2339,7 @@ const win32stub : array[0..131] of byte=(
                                   Initialize
 *****************************************************************************}
 
+{$ifdef i386}
     const
        as_i386_coff_info : tasminfo =
           (
@@ -2340,8 +2388,23 @@ const win32stub : array[0..131] of byte=(
             labelprefix : '.L';
             comment : '';
           );
-
-
+{$endif i386}
+{$ifdef x86_64}
+    const
+       as_x86_64_pecoff_info : tasminfo =
+          (
+            id     : as_x86_64_pecoff;
+            idtxt  : 'PECOFF';
+            asmbin : '';
+            asmcmd : '';
+            supported_target : system_x86_64_win64;
+            flags : [af_outputbinary,af_smartlink_sections];
+            labelprefix : '.L';
+            comment : '';
+          );
+{$endif x86_64}
+{$ifdef arm}
+    const
        as_arm_pecoffwince_info : tasminfo =
           (
             id     : as_arm_pecoffwince;
@@ -2353,6 +2416,8 @@ const win32stub : array[0..131] of byte=(
             labelprefix : '.L';
             comment : '';
           );
+{$endif arm}
+
 
 initialization
 {$ifdef i386}
@@ -2361,6 +2426,9 @@ initialization
   RegisterAssembler(as_i386_pecoffwdosx_info,TPECoffAssembler);
   RegisterAssembler(as_i386_pecoffwince_info,TPECoffAssembler);
 {$endif i386}
+{$ifdef x86_64}
+  RegisterAssembler(as_x86_64_pecoff_info,TPECoffAssembler);
+{$endif x86_64}
 {$ifdef arm}
   RegisterAssembler(as_arm_pecoffwince_info,TPECoffAssembler);
 {$endif arm}

+ 80 - 73
compiler/ogelf.pas

@@ -36,7 +36,7 @@ interface
        ogbase;
 
     type
-       TElf32ObjSection = class(TObjSection)
+       TElfObjSection = class(TObjSection)
        public
           secshidx  : longint; { index for the section in symtab }
           shstridx,
@@ -46,13 +46,13 @@ interface
           shinfo,
           shentsize : longint;
           { relocation }
-          relocsect : TElf32ObjSection;
+          relocsect : TElfObjSection;
           constructor create(const Aname:string;Aalign:shortint;Aoptions:TObjSectionOptions);override;
           constructor create_ext(const Aname:string;Ashtype,Ashflags,Ashlink,Ashinfo:longint;Aalign:shortint;Aentsize:longint);
           destructor  destroy;override;
        end;
 
-       TElf32ObjData = class(TObjData)
+       TElfObjData = class(TObjData)
        public
          symtabsect,
          strtabsect,
@@ -61,7 +61,7 @@ interface
          gotoffsect,
          goTSect,
          plTSect,
-         symsect  : TElf32ObjSection;
+         symsect  : TElfObjSection;
          syms     : Tdynamicarray;
          constructor create(const n:string);override;
          destructor  destroy;override;
@@ -72,16 +72,16 @@ interface
          procedure writestab(offset:aint;ps:TObjSymbol;nidx,nother:byte;ndesc:word;p:pchar);override;
        end;
 
-       TElf32ObjectOutput = class(tObjOutput)
+       TElfObjectOutput = class(tObjOutput)
        private
-         elf32data : TElf32ObjData;
+         elf32data : TElfObjData;
          symidx,
          localsyms : longint;
-         procedure createrelocsection(s:TElf32ObjSection);
+         procedure createrelocsection(s:TElfObjSection);
          procedure createshstrtab;
          procedure createsymtab;
-         procedure writesectionheader(s:TElf32ObjSection);
-         procedure writesectiondata(s:TElf32ObjSection);
+         procedure writesectionheader(s:TElfObjSection);
+         procedure writesectiondata(s:TElfObjSection);
          procedure write_internal_symbol(astridx:longint;ainfo:byte;ashndx:word);
          procedure section_write_symbol(p:TObject;arg:pointer);
          procedure section_write_sh_string(p:TObject;arg:pointer);
@@ -98,7 +98,7 @@ interface
          constructor Create(smart:boolean);override;
        end;
 
-       TElf32assembler = class(tinternalassembler)
+       TElfAssembler = class(tinternalassembler)
          constructor create(smart:boolean);override;
        end;
 
@@ -507,7 +507,7 @@ implementation
                                TSection
 ****************************************************************************}
 
-    constructor TElf32ObjSection.create(const Aname:string;Aalign:shortint;Aoptions:TObjSectionOptions);
+    constructor TElfObjSection.create(const Aname:string;Aalign:shortint;Aoptions:TObjSectionOptions);
       begin
         inherited create(Aname,Aalign,aoptions);
         secshidx:=0;
@@ -521,7 +521,7 @@ implementation
       end;
 
 
-    constructor TElf32ObjSection.create_ext(const Aname:string;Ashtype,Ashflags,Ashlink,Ashinfo:longint;Aalign:shortint;Aentsize:longint);
+    constructor TElfObjSection.create_ext(const Aname:string;Ashtype,Ashflags,Ashlink,Ashinfo:longint;Aalign:shortint;Aentsize:longint);
       var
         aoptions : TObjSectionOptions;
       begin
@@ -538,7 +538,7 @@ implementation
       end;
 
 
-    destructor TElf32ObjSection.destroy;
+    destructor TElfObjSection.destroy;
       begin
         if assigned(relocsect) then
           relocsect.free;
@@ -547,19 +547,19 @@ implementation
 
 
 {****************************************************************************
-                            TElf32ObjData
+                            TElfObjData
 ****************************************************************************}
 
-    constructor TElf32ObjData.create(const n:string);
+    constructor TElfObjData.create(const n:string);
       begin
         inherited create(n);
-        CObjSection:=TElf32ObjSection;
+        CObjSection:=TElfObjSection;
         { reset }
         Syms:=TDynamicArray.Create(symbolresize);
         { default sections }
-        symtabsect:=TElf32ObjSection.create_ext('.symtab',2,0,0,0,4,sizeof(telfsymbol));
-        strtabsect:=TElf32ObjSection.create_ext('.strtab',3,0,0,0,1,0);
-        shstrtabsect:=TElf32ObjSection.create_ext('.shstrtab',3,0,0,0,1,0);
+        symtabsect:=TElfObjSection.create_ext('.symtab',2,0,0,0,4,sizeof(telfsymbol));
+        strtabsect:=TElfObjSection.create_ext('.strtab',3,0,0,0,1,0);
+        shstrtabsect:=TElfObjSection.create_ext('.shstrtab',3,0,0,0,1,0);
         { insert the empty and filename as first in strtab }
         strtabsect.writestr(#0);
         strtabsect.writestr(SplitFileName(current_module.mainsource^)+#0);
@@ -575,7 +575,7 @@ implementation
       end;
 
 
-    destructor TElf32ObjData.destroy;
+    destructor TElfObjData.destroy;
       begin
         Syms.Free;
         symtabsect.free;
@@ -585,7 +585,7 @@ implementation
       end;
 
 
-    function TElf32ObjData.sectionname(atype:TAsmSectiontype;const aname:string):string;
+    function TElfObjData.sectionname(atype:TAsmSectiontype;const aname:string):string;
       const
         secnames : array[TAsmSectiontype] of string[13] = ('',
 {$ifdef userodata}
@@ -610,7 +610,7 @@ implementation
       end;
 
 
-    function TElf32ObjData.sectiontype2align(atype:TAsmSectiontype):shortint;
+    function TElfObjData.sectiontype2align(atype:TAsmSectiontype):shortint;
       begin
         if atype=sec_stabstr then
           result:=1
@@ -619,14 +619,14 @@ implementation
       end;
 
 
-    procedure TElf32ObjData.CreateDebugSections;
+    procedure TElfObjData.CreateDebugSections;
       begin
         stabssec:=createsection(sec_stab,'');
         stabstrsec:=createsection(sec_stabstr,'');
       end;
 
 
-    procedure TElf32ObjData.writereloc(data,len:aint;p:TObjSymbol;relative:TObjRelocationType);
+    procedure TElfObjData.writereloc(data,len:aint;p:TObjSymbol;relative:TObjRelocationType);
       var
         symaddr : longint;
       begin
@@ -667,7 +667,7 @@ implementation
       end;
 
 
-    procedure TElf32ObjData.writestab(offset:aint;ps:TObjSymbol;nidx,nother:byte;ndesc:word;p:pchar);
+    procedure TElfObjData.writestab(offset:aint;ps:TObjSymbol;nidx,nother:byte;ndesc:word;p:pchar);
       var
         stab : TObjStabEntry;
       begin
@@ -690,17 +690,17 @@ implementation
 
 
 {****************************************************************************
-                            TElf32ObjectOutput
+                            TElfObjectOutput
 ****************************************************************************}
 
-    constructor TElf32ObjectOutput.create(smart:boolean);
+    constructor TElfObjectOutput.create(smart:boolean);
       begin
         inherited Create(smart);
-        CObjData:=TElf32ObjData;
+        CObjData:=TElfObjData;
       end;
 
 
-    procedure TElf32ObjectOutput.createrelocsection(s:TElf32ObjSection);
+    procedure TElfObjectOutput.createrelocsection(s:TElfObjSection);
       var
 {$ifdef ver2_0_0}
         relnative,
@@ -722,13 +722,13 @@ implementation
 {$endif userodata}
            { create the reloc section }
 {$ifdef i386}
-           s.relocsect:=TElf32ObjSection.create_ext('.rel'+s.name,9,0,symtabsect.secshidx,s.secshidx,4,8);
+           s.relocsect:=TElfObjSection.create_ext('.rel'+s.name,9,0,symtabsect.secshidx,s.secshidx,4,8);
 {$endif i386}
 {$ifdef x86_64}
-           s.relocsect:=TElf32ObjSection.create_ext('.rela'+s.name,4,0,symtabsect.secshidx,s.secshidx,4,3*8);
+           s.relocsect:=TElfObjSection.create_ext('.rela'+s.name,4,0,symtabsect.secshidx,s.secshidx,4,3*8);
 {$endif x86_64}
 {$ifdef sparc}
-           s.relocsect:=TElf32ObjSection.create_ext('.rel'+s.name,4,0,symtabsect.secshidx,s.secshidx,4,8);
+           s.relocsect:=TElfObjSection.create_ext('.rel'+s.name,4,0,symtabsect.secshidx,s.secshidx,4,8);
 {$endif sparc}
            { add the relocations }
            r:=TObjRelocation(s.relocations.first);
@@ -806,7 +806,7 @@ implementation
       end;
 
 
-    procedure TElf32ObjectOutput.write_internal_symbol(astridx:longint;ainfo:byte;ashndx:word);
+    procedure TElfObjectOutput.write_internal_symbol(astridx:longint;ainfo:byte;ashndx:word);
       var
 {$ifdef ver2_0_0}
         elfsymnative,
@@ -828,14 +828,14 @@ implementation
       end;
 
 
-    procedure TElf32ObjectOutput.section_write_symbol(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_write_symbol(p:TObject;arg:pointer);
       begin
         TObjSection(p).secsymidx:=symidx;
-        write_internal_symbol(TElf32ObjSection(p).shstridx,STT_SECTION,TElf32ObjSection(p).secshidx);
+        write_internal_symbol(TElfObjSection(p).shstridx,STT_SECTION,TElfObjSection(p).secshidx);
       end;
 
 
-    procedure TElf32ObjectOutput.createsymtab;
+    procedure TElfObjectOutput.createsymtab;
       var
 {$ifdef ver2_0_0}
         elfsymnative,
@@ -902,7 +902,7 @@ implementation
                    else
                      begin
                        if assigned(objsym.objsection) then
-                         elfsym.st_shndx:=TElf32ObjSection(objsym.objsection).secshidx
+                         elfsym.st_shndx:=TElfObjSection(objsym.objsection).secshidx
                        else
                          elfsym.st_shndx:=SHN_UNDEF;
                      end;
@@ -923,15 +923,15 @@ implementation
       end;
 
 
-    procedure TElf32ObjectOutput.section_write_sh_string(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_write_sh_string(p:TObject;arg:pointer);
       begin
-        TElf32ObjSection(p).shstridx:=elf32data.shstrtabsect.writestr(TObjSection(p).name+#0);
-        if assigned(TElf32ObjSection(p).relocsect) then
-          TElf32ObjSection(p).relocsect.shstridx:=elf32data.shstrtabsect.writestr(TElf32ObjSection(p).relocsect.name+#0);
+        TElfObjSection(p).shstridx:=elf32data.shstrtabsect.writestr(TObjSection(p).name+#0);
+        if assigned(TElfObjSection(p).relocsect) then
+          TElfObjSection(p).relocsect.shstridx:=elf32data.shstrtabsect.writestr(TElfObjSection(p).relocsect.name+#0);
       end;
 
 
-    procedure TElf32ObjectOutput.createshstrtab;
+    procedure TElfObjectOutput.createshstrtab;
       begin
         with elf32data do
          begin
@@ -947,7 +947,7 @@ implementation
       end;
 
 
-    procedure TElf32ObjectOutput.writesectionheader(s:TElf32ObjSection);
+    procedure TElfObjectOutput.writesectionheader(s:TElfObjSection);
       var
 {$ifdef ver2_0_0}
         sechdrnative,
@@ -973,70 +973,70 @@ implementation
       end;
 
 
-    procedure TElf32ObjectOutput.writesectiondata(s:TElf32ObjSection);
+    procedure TElfObjectOutput.writesectiondata(s:TElfObjSection);
       begin
         FWriter.writezeros(s.dataalignbytes);
         FWriter.writearray(s.data);
       end;
 
 
-    procedure TElf32ObjectOutput.section_count_sections(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_count_sections(p:TObject;arg:pointer);
       begin
-        TElf32ObjSection(p).secshidx:=pword(arg)^;
+        TElfObjSection(p).secshidx:=pword(arg)^;
         inc(pword(arg)^);
-        if TElf32ObjSection(p).relocations.count>0 then
+        if TElfObjSection(p).relocations.count>0 then
           inc(pword(arg)^);
       end;
 
 
-    procedure TElf32ObjectOutput.section_create_relocsec(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_create_relocsec(p:TObject;arg:pointer);
       begin
-        if (TElf32ObjSection(p).relocations.count>0) then
-          createrelocsection(TElf32ObjSection(p));
+        if (TElfObjSection(p).relocations.count>0) then
+          createrelocsection(TElfObjSection(p));
       end;
 
 
-    procedure TElf32ObjectOutput.section_set_datapos(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_set_datapos(p:TObject;arg:pointer);
       begin
         TObjSection(p).setdatapos(paint(arg)^);
       end;
 
 
-    procedure TElf32ObjectOutput.section_relocsec_set_datapos(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_relocsec_set_datapos(p:TObject;arg:pointer);
       begin
-        if assigned(TElf32ObjSection(p).relocsect) then
-          TElf32ObjSection(p).relocsect.setdatapos(paint(arg)^);
+        if assigned(TElfObjSection(p).relocsect) then
+          TElfObjSection(p).relocsect.setdatapos(paint(arg)^);
       end;
 
 
-    procedure TElf32ObjectOutput.section_write_data(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_write_data(p:TObject;arg:pointer);
       begin
         if (oso_data in TObjSection(p).secoptions) then
           begin
             if TObjSection(p).data=nil then
               internalerror(200403073);
-            writesectiondata(TElf32ObjSection(p));
+            writesectiondata(TElfObjSection(p));
           end;
       end;
 
 
-    procedure TElf32ObjectOutput.section_write_sechdr(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_write_sechdr(p:TObject;arg:pointer);
       begin
-        writesectionheader(TElf32ObjSection(p));
-        if assigned(TElf32ObjSection(p).relocsect) then
-          writesectionheader(TElf32ObjSection(p).relocsect);
+        writesectionheader(TElfObjSection(p));
+        if assigned(TElfObjSection(p).relocsect) then
+          writesectionheader(TElfObjSection(p).relocsect);
       end;
 
 
-    procedure TElf32ObjectOutput.section_write_relocsec(p:TObject;arg:pointer);
+    procedure TElfObjectOutput.section_write_relocsec(p:TObject;arg:pointer);
       begin
-        if assigned(TElf32ObjSection(p).relocsect) then
-          writesectiondata(TElf32ObjSection(p).relocsect);
+        if assigned(TElfObjSection(p).relocsect) then
+          writesectiondata(TElfObjSection(p).relocsect);
       end;
 
 
 
-    function TElf32ObjectOutput.writedata(data:TObjData):boolean;
+    function TElfObjectOutput.writedata(data:TObjData):boolean;
       var
 {$ifdef ver2_0_0}
         headernative,
@@ -1047,7 +1047,7 @@ implementation
         nsections : word;
       begin
         result:=false;
-        elf32data:=TElf32ObjData(data);
+        elf32data:=TElfObjData(data);
         with elf32data do
          begin
            { calc amount of sections we have }
@@ -1156,10 +1156,10 @@ implementation
                                TELFAssembler
 ****************************************************************************}
 
-    constructor TElf32Assembler.Create(smart:boolean);
+    constructor TElfAssembler.Create(smart:boolean);
       begin
         inherited Create(smart);
-        CObjOutput:=TElf32ObjectOutput;
+        CObjOutput:=TElfObjectOutput;
       end;
 
 
@@ -1167,7 +1167,8 @@ implementation
                                   Initialize
 *****************************************************************************}
 
-    const
+{$ifdef i386}
+     const
        as_i386_elf32_info : tasminfo =
           (
             id     : as_i386_elf32;
@@ -1179,7 +1180,9 @@ implementation
             labelprefix : '.L';
             comment : '';
           );
-
+{$endif i386}
+{$ifdef x86_64}
+     const
        as_x86_64_elf64_info : tasminfo =
           (
             id     : as_x86_64_elf64;
@@ -1191,7 +1194,9 @@ implementation
             labelprefix : '.L';
             comment : '';
           );
-
+{$endif x86_64}
+{$ifdef sparc}
+     const
        as_sparc_elf32_info : tasminfo =
           (
             id     : as_sparc_elf32;
@@ -1204,15 +1209,17 @@ implementation
             labelprefix : '.L';
             comment : '';
           );
+{$endif sparc}
+
 
 initialization
 {$ifdef i386}
-  RegisterAssembler(as_i386_elf32_info,TElf32Assembler);
+  RegisterAssembler(as_i386_elf32_info,TElfAssembler);
 {$endif i386}
 {$ifdef sparc}
-  RegisterAssembler(as_sparc_elf32_info,TElf32Assembler);
+  RegisterAssembler(as_sparc_elf32_info,TElfAssembler);
 {$endif sparc}
 {$ifdef x86_64}
-  RegisterAssembler(as_x86_64_elf64_info,TElf32Assembler);
+  RegisterAssembler(as_x86_64_elf64_info,TElfAssembler);
 {$endif x86_64}
 end.

+ 13 - 5
compiler/ogmap.pas

@@ -131,23 +131,31 @@ implementation
      procedure TExeMap.AddMemoryMapExeSection(p:texesection);
        begin
          { .text           0x000018a8     0xd958 }
-         Add(PadSpace(p.name,18)+PadSpace('0x'+HexStr(p.mempos+Fimagebase,sizeof(aint)*2),12)+
-             '0x'+HexStr(p.size,sizeof(aint)));
+         Add(PadSpace(p.name,19)+PadSpace(' 0x'+HexStr(p.mempos+Fimagebase,sizeof(aint)*2),12)+
+             ' 0x'+HexStr(p.size,sizeof(aint)));
        end;
 
 
      procedure TExeMap.AddMemoryMapObjectSection(p:TObjSection);
+       var
+         secname : string;
        begin
          { .text           0x000018a8     0xd958     object.o }
-         Add(' '+PadSpace(p.name,17)+PadSpace('0x'+HexStr(p.mempos+FImageBase,sizeof(aint)*2),12)+
-             '0x'+HexStr(p.size,sizeof(aint))+' '+p.objdata.name);
+         secname:=p.name;
+         if Length(secname)>18 then
+           begin
+             Add(' '+secname);
+             secname:='';
+           end;
+         Add(' '+PadSpace(secname,18)+PadSpace(' 0x'+HexStr(p.mempos+FImageBase,sizeof(aint)*2),12)+
+             ' 0x'+HexStr(p.size,sizeof(aint))+' '+p.objdata.name);
        end;
 
 
      procedure TExeMap.AddMemoryMapSymbol(p:TObjSymbol);
        begin
          {                 0x00001e30                setup_screens }
-         Add(Space(18)+PadSpace('0x'+HexStr(p.address+Fimagebase,sizeof(aint)*2),26)+p.name);
+         Add(Space(20)+PadSpace('0x'+HexStr(p.address+Fimagebase,sizeof(aint)*2),25)+' '+p.name);
        end;
 
 end.

+ 30 - 8
compiler/options.pas

@@ -1209,13 +1209,28 @@ begin
                 begin
                   case More[j] of
                     'i' :
-                      include(initglobalswitches,cs_link_internal);
+                      begin
+                        If UnsetBool(More, j) then
+                          exclude(initglobalswitches,cs_link_internal)
+                        else
+                          include(initglobalswitches,cs_link_internal);
+                      end;
                     'm' :
-                      include(initglobalswitches,cs_link_map);
+                      begin
+                        If UnsetBool(More, j) then
+                          exclude(initglobalswitches,cs_link_map)
+                        else
+                          include(initglobalswitches,cs_link_map);
+                      end;
                     'f' :
                       include(initglobalswitches,cs_link_pthread);
                     's' :
-                      include(initglobalswitches,cs_link_strip);
+                      begin
+                        If UnsetBool(More, j) then
+                          exclude(initglobalswitches,cs_link_strip)
+                        else
+                          include(initglobalswitches,cs_link_strip);
+                      end;
                     'c' : Cshared:=TRUE;
                     't' :
                       include(initglobalswitches,cs_link_staticflag);
@@ -2157,16 +2172,23 @@ begin
   if target_info.system=system_arm_wince then
     include(initmoduleswitches,cs_fp_emulation);
 
-  { By default don't create import section if we use the internal linker }
-  if not GenerateImportSectionSetExplicitly and
-     (cs_link_internal in aktglobalswitches) then
-    GenerateImportSection:=false;
-
   { Section smartlinking conflicts with import sections on Windows }
   if GenerateImportSection and
      (target_info.system in [system_i386_win32]) then
     exclude(target_info.flags,tf_smartlink_sections);
 
+  if (cs_link_extern in initglobalswitches) then
+    exclude(initglobalswitches,cs_link_internal);
+
+  if (cs_link_internal in initglobalswitches) then
+    begin
+      { By default don't create import section if we use the internal linker }
+      if not GenerateImportSectionSetExplicitly then
+        GenerateImportSection:=false;
+      { Enable section smartlinking }
+      include(target_info.flags,tf_smartlink_sections);
+    end;
+
 {$ifdef x86_64}
   {$warning HACK: turn off smartlinking}
   exclude(initmoduleswitches,cs_create_smart);

+ 29 - 27
compiler/owbase.pas

@@ -149,7 +149,7 @@ end;
 procedure tobjectwriter.write(const b;len:longint);
 var
   p   : pchar;
-  left,
+  bufleft,
   idx : longint;
 begin
   inc(fsize,len);
@@ -158,13 +158,13 @@ begin
   idx:=0;
   while len>0 do
    begin
-     left:=bufsize-bufidx;
-     if len>left then
+     bufleft:=bufsize-bufidx;
+     if len>bufleft then
       begin
-        move(p[idx],buf[bufidx],left);
-        dec(len,left);
-        inc(idx,left);
-        inc(bufidx,left);
+        move(p[idx],buf[bufidx],bufleft);
+        dec(len,bufleft);
+        inc(idx,bufleft);
+        inc(bufidx,bufleft);
         writebuf;
       end
      else
@@ -269,43 +269,45 @@ end;
 function tobjectreader.read(out b;len:longint):boolean;
 var
   p   : pchar;
-  left,
+  lenleft,
+  bufleft,
   idx : longint;
 begin
-  read:=false;
+  result:=false;
   if bufmax=0 then
    if not readbuf then
     exit;
   p:=pchar(@b);
   idx:=0;
-  while len>0 do
+  lenleft:=len;
+  while lenleft>0 do
    begin
-     left:=bufmax-bufidx;
-     if len>left then
+     bufleft:=bufmax-bufidx;
+     if lenleft>bufleft then
       begin
-        move(buf[bufidx],p[idx],left);
-        dec(len,left);
-        inc(idx,left);
-        inc(bufidx,left);
+        move(buf[bufidx],p[idx],bufleft);
+        dec(lenleft,bufleft);
+        inc(idx,bufleft);
+        inc(bufidx,bufleft);
         if not readbuf then
          exit;
       end
      else
       begin
-        move(buf[bufidx],p[idx],len);
-        inc(bufidx,len);
-        inc(idx,len);
+        move(buf[bufidx],p[idx],lenleft);
+        inc(bufidx,lenleft);
+        inc(idx,lenleft);
         break;
       end;
    end;
-  read:=(idx=len);
+  result:=(idx=len);
 end;
 
 
 function tobjectreader.readarray(a:TDynamicArray;len:longint):boolean;
 var
   orglen,
-  left,
+  bufleft,
   idx : longint;
 begin
   readarray:=false;
@@ -316,13 +318,13 @@ begin
   idx:=0;
   while len>0 do
    begin
-     left:=bufmax-bufidx;
-     if len>left then
+     bufleft:=bufmax-bufidx;
+     if len>bufleft then
       begin
-        a.Write(buf[bufidx],left);
-        dec(len,left);
-        inc(idx,left);
-        inc(bufidx,left);
+        a.Write(buf[bufidx],bufleft);
+        dec(len,bufleft);
+        inc(idx,bufleft);
+        inc(bufidx,bufleft);
         if not readbuf then
          exit;
       end

+ 29 - 23
compiler/ppu.pas

@@ -469,31 +469,37 @@ end;
 
 procedure tppufile.readdata(var b;len:integer);
 var
-  p   : pchar;
-  left,
-  idx : integer;
+  p,pmax,pbuf : pchar;
+  left : integer;
 begin
   p:=pchar(@b);
-  idx:=0;
-  while len>0 do
-   begin
-     left:=bufsize-bufidx;
-     if len>left then
-      begin
-        move(buf[bufidx],p[idx],left);
-        dec(len,left);
-        inc(idx,left);
-        reloadbuf;
-        if bufsize=0 then
-         exit;
-      end
-     else
-      begin
-        move(buf[bufidx],p[idx],len);
-        inc(bufidx,len);
-        exit;
-      end;
-   end;
+  pbuf:=@buf[bufidx];
+  repeat
+    left:=bufsize-bufidx;
+    if len<left then
+      break;
+    move(pbuf^,p^,left);
+    dec(len,left);
+    inc(p,left);
+    reloadbuf;
+    pbuf:=@buf[bufidx];
+    if bufsize=0 then
+      exit;
+  until false;
+  { For small values copy directly }
+  if len<=sizeof(ptrint) then
+    begin
+      pmax:=p+len;
+      while (p<pmax) do
+        begin
+          p^:=pbuf^;
+          inc(pbuf);
+          inc(p);
+        end;
+    end
+  else
+    move(pbuf^,p^,len);
+  inc(bufidx,len);
 end;
 
 

+ 1 - 1
compiler/systems/i_win.pas

@@ -33,7 +33,7 @@ unit i_win;
             name         : 'Win32 for i386';
             shortname    : 'Win32';
             flags        : [tf_files_case_aware,tf_has_dllscanner,tf_use_function_relative_addresses
-                            {,tf_smartlink_sections}{,tf_section_threadvars},tf_needs_dwarf_cfi];
+                            ,tf_smartlink_sections{,tf_section_threadvars},tf_needs_dwarf_cfi];
             cpu          : cpu_i386;
             unit_env     : 'WIN32UNITS';
             extradefines : 'MSWINDOWS;WINDOWS';

+ 82 - 91
compiler/x86/aasmcpu.pas

@@ -258,7 +258,7 @@ interface
          insentry  : PInsEntry;
          function  InsEnd:longint;
          procedure create_ot(objdata:TObjData);
-         function  Matches(p:PInsEntry):longint;
+         function  Matches(p:PInsEntry):boolean;
          function  calcsize(p:PInsEntry):shortint;
          procedure gencode(objdata:TObjData);
          function  NeedAddrPrefix(opidx:byte):boolean;
@@ -288,11 +288,12 @@ implementation
     const
      {Instruction flags }
        IF_NONE   = $00000000;
-       IF_SM     = $00000001;        { size match first two operands  }
+       IF_SM     = $00000001;  { size match first two operands  }
        IF_SM2    = $00000002;
        IF_SB     = $00000004;  { unsized operands can't be non-byte  }
        IF_SW     = $00000008;  { unsized operands can't be non-word  }
        IF_SD     = $00000010;  { unsized operands can't be nondword  }
+       IF_SMASK  = $0000001f;
        IF_AR0    = $00000020;  { SB, SW, SD applies to argument 0  }
        IF_AR1    = $00000040;  { SB, SW, SD applies to argument 1  }
        IF_AR2    = $00000060;  { SB, SW, SD applies to argument 2  }
@@ -1091,7 +1092,7 @@ implementation
       end;
 
 
-      function taicpu.Matches(p:PInsEntry):longint;
+      function taicpu.Matches(p:PInsEntry):boolean;
       { * IF_SM stands for Size Match: any operand whose size is not
        * explicitly specified by the template is `really' intended to be
        * the same size as the first size-specified operand.
@@ -1113,106 +1114,97 @@ implementation
        * required to have unspecified size in the instruction too...)
       }
       var
+        insot,
+        insflags,
+        currot,
         i,j,asize,oprs : longint;
         siz : array[0..2] of longint;
       begin
-        Matches:=100;
+        result:=false;
 
         { Check the opcode and operands }
         if (p^.opcode<>opcode) or (p^.ops<>ops) then
-         begin
-           Matches:=0;
-           exit;
-         end;
-
-        { Check that no spurious colons or TOs are present }
-        for i:=0 to p^.ops-1 do
-         if (oper[i]^.ot and (not p^.optypes[i]) and (OT_COLON or OT_TO))<>0 then
-          begin
-            Matches:=0;
-            exit;
-          end;
+          exit;
 
-        { Check that the operand flags all match up }
         for i:=0 to p^.ops-1 do
          begin
-           if ((p^.optypes[i] and (not oper[i]^.ot)) or
-               ((p^.optypes[i] and OT_SIZE_MASK) and
-                ((p^.optypes[i] xor oper[i]^.ot) and OT_SIZE_MASK)))<>0 then
-            begin
-              if ((p^.optypes[i] and (not oper[i]^.ot) and OT_NON_SIZE) or
-                  (oper[i]^.ot and OT_SIZE_MASK))<>0 then
-               begin
-                 Matches:=0;
-                 exit;
-               end
-              else
-               Matches:=1;
-            end;
-         end;
-
-      { Check operand sizes }
-        { as default an untyped size can get all the sizes, this is different
-          from nasm, but else we need to do a lot checking which opcodes want
-          size or not with the automatic size generation }
-        asize:=longint($ffffffff);
-        if (p^.flags and IF_SB)<>0 then
-          asize:=OT_BITS8
-        else if (p^.flags and IF_SW)<>0 then
-          asize:=OT_BITS16
-        else if (p^.flags and IF_SD)<>0 then
-          asize:=OT_BITS32;
-        if (p^.flags and IF_ARMASK)<>0 then
-         begin
-           siz[0]:=0;
-           siz[1]:=0;
-           siz[2]:=0;
-           if (p^.flags and IF_AR0)<>0 then
-            siz[0]:=asize
-           else if (p^.flags and IF_AR1)<>0 then
-            siz[1]:=asize
-           else if (p^.flags and IF_AR2)<>0 then
-            siz[2]:=asize;
-         end
-        else
-         begin
-         { we can leave because the size for all operands is forced to be
-           the same
-           but not if IF_SB IF_SW or IF_SD is set PM }
-           if asize=-1 then
+           insot:=p^.optypes[i];
+           currot:=oper[i]^.ot;
+           { Check that the operand flags }
+           if (insot and (not currot))<>0 then
+             exit;
+           { Check if the passed operand size matches with the required
+             instruction operand size. The second 'and' with insot is used
+             to allow matching with undefined size }
+           if ((currot xor insot) and insot and OT_SIZE_MASK)<>0 then
              exit;
-           siz[0]:=asize;
-           siz[1]:=asize;
-           siz[2]:=asize;
          end;
 
-        if (p^.flags and (IF_SM or IF_SM2))<>0 then
-         begin
-           if (p^.flags and IF_SM2)<>0 then
-            oprs:=2
-           else
-            oprs:=p^.ops;
-           for i:=0 to oprs-1 do
-            if ((p^.optypes[i] and OT_SIZE_MASK) <> 0) then
+        { Check operand sizes }
+        insflags:=p^.flags;
+        if insflags and IF_SMASK<>0 then
+          begin
+            { as default an untyped size can get all the sizes, this is different
+              from nasm, but else we need to do a lot checking which opcodes want
+              size or not with the automatic size generation }
+            asize:=-1;
+            if (insflags and IF_SB)<>0 then
+              asize:=OT_BITS8
+            else if (insflags and IF_SW)<>0 then
+              asize:=OT_BITS16
+            else if (insflags and IF_SD)<>0 then
+              asize:=OT_BITS32;
+            if (insflags and IF_ARMASK)<>0 then
              begin
-               for j:=0 to oprs-1 do
-                siz[j]:=p^.optypes[i] and OT_SIZE_MASK;
-               break;
+               siz[0]:=0;
+               siz[1]:=0;
+               siz[2]:=0;
+               if (insflags and IF_AR0)<>0 then
+                siz[0]:=asize
+               else if (insflags and IF_AR1)<>0 then
+                siz[1]:=asize
+               else if (insflags and IF_AR2)<>0 then
+                siz[2]:=asize;
+             end
+            else
+             begin
+               siz[0]:=asize;
+               siz[1]:=asize;
+               siz[2]:=asize;
              end;
-          end
-         else
-          oprs:=2;
 
-        { Check operand sizes }
-        for i:=0 to p^.ops-1 do
-         begin
-           if ((p^.optypes[i] and OT_SIZE_MASK)=0) and
-              ((oper[i]^.ot and OT_SIZE_MASK and (not siz[i]))<>0) and
-              { Immediates can always include smaller size }
-              ((oper[i]^.ot and OT_IMMEDIATE)=0) and
-               (((p^.optypes[i] and OT_SIZE_MASK) or siz[i])<(oper[i]^.ot and OT_SIZE_MASK)) then
-            Matches:=2;
-         end;
+            if (insflags and (IF_SM or IF_SM2))<>0 then
+             begin
+               if (insflags and IF_SM2)<>0 then
+                oprs:=2
+               else
+                oprs:=p^.ops;
+               for i:=0 to oprs-1 do
+                if ((p^.optypes[i] and OT_SIZE_MASK) <> 0) then
+                 begin
+                   for j:=0 to oprs-1 do
+                    siz[j]:=p^.optypes[i] and OT_SIZE_MASK;
+                   break;
+                 end;
+              end
+             else
+              oprs:=2;
+
+            { Check operand sizes }
+            for i:=0 to p^.ops-1 do
+              begin
+                insot:=p^.optypes[i];
+                currot:=oper[i]^.ot;
+                if ((insot and OT_SIZE_MASK)=0) and
+                   ((currot and OT_SIZE_MASK and (not siz[i]))<>0) and
+                   { Immediates can always include smaller size }
+                   ((currot and OT_IMMEDIATE)=0) and
+                    (((insot and OT_SIZE_MASK) or siz[i])<(currot and OT_SIZE_MASK)) then
+                  exit;
+              end;
+          end;
+
+        result:=true;
       end;
 
 
@@ -1279,13 +1271,12 @@ implementation
         insentry:=@instab[i];
         while (insentry^.opcode=opcode) do
          begin
-           if matches(insentry)=100 then
+           if matches(insentry) then
              begin
                result:=true;
                exit;
              end;
-           inc(i);
-           insentry:=@instab[i];
+           inc(insentry);
          end;
         Message1(asmw_e_invalid_opcode_and_operands,GetString);
         { No instruction found, set insentry to nil and inssize to -1 }

+ 278 - 281
compiler/x86/x86ins.dat

@@ -34,105 +34,105 @@ void                  \1\x3F                          8086
 
 [ADC,adcX]
 (Ch_Mop2, Ch_Rop1, Ch_RWFlags)
-mem,reg8              \300\1\x10\101                  8086,SM
-reg8,reg8             \300\1\x10\101                  8086
-mem,reg16             \320\300\1\x11\101              8086,SM
+reg32,reg32           \321\300\1\x11\101              386
 reg16,reg16           \320\300\1\x11\101              8086
+reg8,reg8             \300\1\x10\101                  8086
 mem,reg32             \321\300\1\x11\101              386,SM
-reg32,reg32           \321\300\1\x11\101              386
-reg8,mem              \301\1\x12\110                  8086,SM
-reg8,reg8             \301\1\x12\110                  8086
-reg16,mem             \320\301\1\x13\110              8086,SM
-reg16,reg16           \320\301\1\x13\110              8086
+mem,reg16             \320\300\1\x11\101              8086,SM
+mem,reg8              \300\1\x10\101                  8086,SM
 reg32,mem             \321\301\1\x13\110              386,SM
-reg32,reg32           \321\301\1\x13\110              386
-rm16,imm8             \320\300\1\x83\202\15           8086
+reg16,mem             \320\301\1\x13\110              8086,SM
+reg8,mem              \301\1\x12\110                  8086,SM
 rm32,imm8             \321\300\1\x83\202\15           386
-reg_al,imm            \1\x14\21                       8086,SM
-reg_ax,imm            \320\1\x15\31                   8086,SM
+rm16,imm8             \320\300\1\x83\202\15           8086
 reg_eax,imm           \321\1\x15\41                   386,SM
-rm8,imm               \300\1\x80\202\21               8086,SM
-rm16,imm              \320\300\1\x81\202\31           8086,SM
+reg_ax,imm            \320\1\x15\31                   8086,SM
+reg_al,imm            \1\x14\21                       8086,SM
 rm32,imm              \321\300\1\x81\202\41           386,SM
-mem,imm8              \300\1\x80\202\21               8086,SM
-mem,imm16             \320\300\1\x81\202\31           8086,SM
+rm16,imm              \320\300\1\x81\202\31           8086,SM
+rm8,imm               \300\1\x80\202\21               8086,SM
 mem,imm32             \321\300\1\x81\202\41           386,SM
+mem,imm16             \320\300\1\x81\202\31           8086,SM
+mem,imm8              \300\1\x80\202\21               8086,SM
+reg32,reg32           \321\301\1\x13\110              386
+reg16,reg16           \320\301\1\x13\110              8086
+reg8,reg8             \301\1\x12\110                  8086
 
 [ADD,addX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-mem,reg8              \300\17\101                     8086,SM
-reg8,reg8             \300\17\101                     8086
-mem,reg16             \320\300\1\x01\101              8086,SM
+reg32,reg32           \321\300\1\x01\101              386
 reg16,reg16           \320\300\1\x01\101              8086
+reg8,reg8             \300\17\101                     8086
 mem,reg32             \321\300\1\x01\101              386,SM
-reg32,reg32           \321\300\1\x01\101              386
-reg8,mem              \301\1\x02\110                  8086,SM
-reg8,reg8             \301\1\x02\110                  8086
-reg16,mem             \320\301\1\x03\110              8086,SM
-reg16,reg16           \320\301\1\x03\110              8086
+mem,reg16             \320\300\1\x01\101              8086,SM
+mem,reg8              \300\17\101                     8086,SM
 reg32,mem             \321\301\1\x03\110              386,SM
-reg32,reg32           \321\301\1\x03\110              386
-rm16,imm8             \320\300\1\x83\200\15           8086
+reg16,mem             \320\301\1\x03\110              8086,SM
+reg8,mem              \301\1\x02\110                  8086,SM
 rm32,imm8             \321\300\1\x83\200\15           386
-reg_al,imm            \1\x04\21                       8086,SM
-reg_ax,imm            \320\1\x05\31                   8086,SM
+rm16,imm8             \320\300\1\x83\200\15           8086
 reg_eax,imm           \321\1\x05\41                   386,SM
-rm8,imm               \300\1\x80\200\21               8086,SM
-rm16,imm              \320\300\1\x81\200\31           8086,SM
+reg_ax,imm            \320\1\x05\31                   8086,SM
+reg_al,imm            \1\x04\21                       8086,SM
 rm32,imm              \321\300\1\x81\200\41           386,SM
-mem,imm8              \300\1\x80\200\21               8086,SM
-mem,imm16             \320\300\1\x81\200\31           8086,SM
+rm16,imm              \320\300\1\x81\200\31           8086,SM
+rm8,imm               \300\1\x80\200\21               8086,SM
 mem,imm32             \321\300\1\x81\200\41           386,SM
+mem,imm16             \320\300\1\x81\200\31           8086,SM
+mem,imm8              \300\1\x80\200\21               8086,SM
+reg32,reg32           \321\301\1\x03\110              386
+reg16,reg16           \320\301\1\x03\110              8086
+reg8,reg8             \301\1\x02\110                  8086
 
 [AND,andX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-mem,reg8              \300\1\x20\101                  8086,SM
-reg8,reg8             \300\1\x20\101                  8086
-mem,reg16             \320\300\1\x21\101              8086,SM
+reg32,reg32           \321\300\1\x21\101              386
 reg16,reg16           \320\300\1\x21\101              8086
+reg8,reg8             \300\1\x20\101                  8086
 mem,reg32             \321\300\1\x21\101              386,SM
-reg32,reg32           \321\300\1\x21\101              386
-reg8,mem              \301\1\x22\110                  8086,SM
-reg8,reg8             \301\1\x22\110                  8086
-reg16,mem             \320\301\1\x23\110              8086,SM
-reg16,reg16           \320\301\1\x23\110              8086
+mem,reg16             \320\300\1\x21\101              8086,SM
+mem,reg8              \300\1\x20\101                  8086,SM
 reg32,mem             \321\301\1\x23\110              386,SM
-reg32,reg32           \321\301\1\x23\110              386
-rm16,imm8             \320\300\1\x83\204\15           8086
+reg16,mem             \320\301\1\x23\110              8086,SM
+reg8,mem              \301\1\x22\110                  8086,SM
 rm32,imm8             \321\300\1\x83\204\15           386
-reg_al,imm            \1\x24\21                       8086,SM
-reg_ax,imm            \320\1\x25\31                   8086,SM
+rm16,imm8             \320\300\1\x83\204\15           8086
 reg_eax,imm           \321\1\x25\41                   386,SM
-rm8,imm               \300\1\x80\204\21               8086,SM
-rm16,imm              \320\300\1\x81\204\31           8086,SM
+reg_ax,imm            \320\1\x25\31                   8086,SM
+reg_al,imm            \1\x24\21                       8086,SM
 rm32,imm              \321\300\1\x81\204\41           386,SM
-mem,imm8              \300\1\x80\204\21               8086,SM
-mem,imm16             \320\300\1\x81\204\31           8086,SM
+rm16,imm              \320\300\1\x81\204\31           8086,SM
+rm8,imm               \300\1\x80\204\21               8086,SM
 mem,imm32             \321\300\1\x81\204\41           386,SM
+mem,imm16             \320\300\1\x81\204\31           8086,SM
+mem,imm8              \300\1\x80\204\21               8086,SM
+reg32,reg32           \321\301\1\x23\110              386
+reg16,reg16           \320\301\1\x23\110              8086
+reg8,reg8             \301\1\x22\110                  8086
 
 [ARPL,arplX]
 (Ch_WFlags, Ch_None, Ch_None)
-mem,reg16             \300\1\x63\101                  286,PROT,SM
 reg16,reg16           \300\1\x63\101                  286,PROT
+mem,reg16             \300\1\x63\101                  286,PROT,SM
 
 [BOUND,boundX]
 (Ch_Rop1, Ch_None, Ch_None)
-reg16,mem             \320\301\1\x62\110              186
 reg32,mem             \321\301\1\x62\110              386
+reg16,mem             \320\301\1\x62\110              186
 
 [BSF,bsfX]
 (Ch_Wop2, Ch_WFlags, Ch_Rop1)
-reg16,mem             \320\301\2\x0F\xBC\110          386,SM
+reg32,reg32           \321\301\2\x0F\xBC\110          386
 reg16,reg16           \320\301\2\x0F\xBC\110          386
 reg32,mem             \321\301\2\x0F\xBC\110          386,SM
-reg32,reg32           \321\301\2\x0F\xBC\110          386
+reg16,mem             \320\301\2\x0F\xBC\110          386,SM
 
 [BSR,bsrX]
 (Ch_Wop2, Ch_WFlags, Ch_Rop1)
-reg16,mem             \320\301\2\x0F\xBD\110          386,SM
+reg32,reg32           \321\301\2\x0F\xBD\110          386
 reg16,reg16           \320\301\2\x0F\xBD\110          386
 reg32,mem             \321\301\2\x0F\xBD\110          386,SM
-reg32,reg32           \321\301\2\x0F\xBD\110          386
+reg16,mem             \320\301\2\x0F\xBD\110          386,SM
 
 [BSWAP,bswapX]
 (Ch_MOp1, Ch_None, Ch_None)
@@ -140,44 +140,49 @@ reg32                 \321\1\x0F\10\xC8               486
 
 [BT,btX]
 (Ch_WFlags, Ch_Rop1, Ch_Rop2)
-mem,reg16             \320\300\2\x0F\xA3\101          386,SM
+reg32,reg32           \321\300\2\x0F\xA3\101          386
 reg16,reg16           \320\300\2\x0F\xA3\101          386
 mem,reg32             \321\300\2\x0F\xA3\101          386,SM
-reg32,reg32           \321\300\2\x0F\xA3\101          386
-rm16,imm              \320\300\2\x0F\xBA\204\25       386,SB
+mem,reg16             \320\300\2\x0F\xA3\101          386,SM
 rm32,imm              \321\300\2\x0F\xBA\204\25       386,SB
+rm16,imm              \320\300\2\x0F\xBA\204\25       386,SB
 
 [BTC,btcX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-mem,reg16             \320\300\2\x0F\xBB\101          386,SM
+reg32,reg32           \321\300\2\x0F\xBB\101          386
 reg16,reg16           \320\300\2\x0F\xBB\101          386
 mem,reg32             \321\300\2\x0F\xBB\101          386,SM
-reg32,reg32           \321\300\2\x0F\xBB\101          386
-rm16,imm              \320\300\2\x0F\xBA\207\25       386,SB
+mem,reg16             \320\300\2\x0F\xBB\101          386,SM
 rm32,imm              \321\300\2\x0F\xBA\207\25       386,SB
+rm16,imm              \320\300\2\x0F\xBA\207\25       386,SB
 
 [BTR,btrX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-mem,reg16             \320\300\2\x0F\xB3\101          386,SM
+reg32,reg32           \321\300\2\x0F\xB3\101          386
 reg16,reg16           \320\300\2\x0F\xB3\101          386
 mem,reg32             \321\300\2\x0F\xB3\101          386,SM
-reg32,reg32           \321\300\2\x0F\xB3\101          386
-rm16,imm              \320\300\2\x0F\xBA\206\25       386,SB
+mem,reg16             \320\300\2\x0F\xB3\101          386,SM
 rm32,imm              \321\300\2\x0F\xBA\206\25       386,SB
+rm16,imm              \320\300\2\x0F\xBA\206\25       386,SB
 
 [BTS,btsX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-mem,reg16             \320\300\2\x0F\xAB\101          386,SM
+reg32,reg32           \321\300\2\x0F\xAB\101          386
 reg16,reg16           \320\300\2\x0F\xAB\101          386
 mem,reg32             \321\300\2\x0F\xAB\101          386,SM
-reg32,reg32           \321\300\2\x0F\xAB\101          386
-rm16,imm              \320\300\2\x0F\xBA\205\25       386,SB
+mem,reg16             \320\300\2\x0F\xAB\101          386,SM
 rm32,imm              \321\300\2\x0F\xBA\205\25       386,SB
+rm16,imm              \320\300\2\x0F\xBA\205\25       386,SB
 
 [CALL,call]
 ; don't know value of any register
 (Ch_ROp1, Ch_All, Ch_None)
 imm                   \323\1\xE8\64                   8086
+reg32                 \321\300\1\xFF\202              386
+reg16                 \320\300\1\xFF\202              8086
+mem32                 \321\300\1\xFF\202              386
+mem16                 \320\300\1\xFF\202              8086
+mem                   \323\300\1\xFF\202              8086
 imm|near              \323\1\xE8\64                   8086
 imm|far               \323\1\x9A\34\37                8086,ND
 imm16                 \320\1\xE8\64                   8086
@@ -197,11 +202,6 @@ mem32|far             \321\300\1\xFF\203              386
 mem|near              \323\300\1\xFF\202              8086
 mem16|near            \320\300\1\xFF\202              8086
 mem32|near            \321\300\1\xFF\202              386
-reg16                 \320\300\1\xFF\202              8086
-reg32                 \321\300\1\xFF\202              386
-mem                   \323\300\1\xFF\202              8086
-mem16                 \320\300\1\xFF\202              8086
-mem32                 \321\300\1\xFF\202              386
 
 [CBW,cbtw]
 (Ch_MEAX, Ch_None, Ch_None)
@@ -233,29 +233,29 @@ void                  \1\xF5                          8086
 
 [CMP,cmpX]
 (Ch_ROp1, Ch_ROp2, Ch_WFlags)
-mem,reg8              \300\1\x38\101                  8086,SM
-reg8,reg8             \300\1\x38\101                  8086
-mem,reg16             \320\300\1\x39\101              8086,SM
-reg16,reg16           \320\300\1\x39\101              8086
-mem,reg32             \321\300\1\x39\101              386,SM
-reg32,reg32           \321\300\1\x39\101              386
-reg8,mem              \301\1\x3A\110                  8086,SM
-reg8,reg8             \301\1\x3A\110                  8086
-reg16,mem             \320\301\1\x3B\110              8086,SM
+reg32,reg32           \321\301\1\x3B\110              386
 reg16,reg16           \320\301\1\x3B\110              8086
+reg8,reg8             \301\1\x3A\110                  8086
+mem,reg32             \321\300\1\x39\101              386,SM
+mem,reg16             \320\300\1\x39\101              8086,SM
+mem,reg8              \300\1\x38\101                  8086,SM
 reg32,mem             \321\301\1\x3B\110              386,SM
-reg32,reg32           \321\301\1\x3B\110              386
-rm16,imm8             \320\300\1\x83\207\15           8086
+reg16,mem             \320\301\1\x3B\110              8086,SM
+reg8,mem              \301\1\x3A\110                  8086,SM
 rm32,imm8             \321\300\1\x83\207\15           386
-reg_al,imm            \1\x3C\21                       8086,SM
-reg_ax,imm            \320\1\x3D\31                   8086,SM
+rm16,imm8             \320\300\1\x83\207\15           8086
 reg_eax,imm           \321\1\x3D\41                   386,SM
-rm8,imm               \300\1\x80\207\21               8086,SM
-rm16,imm              \320\300\1\x81\207\31           8086,SM
+reg_ax,imm            \320\1\x3D\31                   8086,SM
+reg_al,imm            \1\x3C\21                       8086,SM
 rm32,imm              \321\300\1\x81\207\41           386,SM
-mem,imm8              \300\1\x80\207\21               8086,SM
-mem,imm16             \320\300\1\x81\207\31           8086,SM
+rm16,imm              \320\300\1\x81\207\31           8086,SM
+rm8,imm               \300\1\x80\207\21               8086,SM
 mem,imm32             \321\300\1\x81\207\41           386,SM
+mem,imm16             \320\300\1\x81\207\31           8086,SM
+mem,imm8              \300\1\x80\207\21               8086,SM
+reg32,reg32           \321\300\1\x39\101              386
+reg16,reg16           \320\300\1\x39\101              8086
+reg8,reg8             \300\1\x38\101                  8086
 
 [CMPSB]
 (Ch_All, Ch_None, Ch_None)
@@ -273,21 +273,21 @@ void                  \332\320\1\xA7                  8086
 
 [CMPXCHG,cmpxchgX]
 (Ch_All, Ch_None, Ch_None)
-mem,reg8              \300\2\x0F\xB0\101              PENT,SM
-reg8,reg8             \300\2\x0F\xB0\101              PENT
-mem,reg16             \320\300\2\x0F\xB1\101          PENT,SM
+reg32,reg32           \321\300\2\x0F\xB1\101          PENT
 reg16,reg16           \320\300\2\x0F\xB1\101          PENT
+reg8,reg8             \300\2\x0F\xB0\101              PENT
 mem,reg32             \321\300\2\x0F\xB1\101          PENT,SM
-reg32,reg32           \321\300\2\x0F\xB1\101          PENT
+mem,reg16             \320\300\2\x0F\xB1\101          PENT,SM
+mem,reg8              \300\2\x0F\xB0\101              PENT,SM
 
 [CMPXCHG486,cmpxchg486X]
 (Ch_All, Ch_None, Ch_None)
-mem,reg8              \300\2\x0F\xA6\101              486,SM,UNDOC
-reg8,reg8             \300\2\x0F\xA6\101              486,UNDOC
-mem,reg16             \320\300\2\x0F\xA7\101          486,SM,UNDOC
+reg32,reg32           \321\300\2\x0F\xA7\101          486,UNDOC
 reg16,reg16           \320\300\2\x0F\xA7\101          486,UNDOC
+reg8,reg8             \300\2\x0F\xA6\101              486,UNDOC
 mem,reg32             \321\300\2\x0F\xA7\101          486,SM,UNDOC
-reg32,reg32           \321\300\2\x0F\xA7\101          486,UNDOC
+mem,reg16             \320\300\2\x0F\xA7\101          486,SM,UNDOC
+mem,reg8              \300\2\x0F\xA6\101              486,SM,UNDOC
 
 [CMPXCHG8B,cmpxchg8bX]
 (Ch_All, Ch_None, Ch_None)
@@ -315,17 +315,17 @@ void                  \1\x2F                          8086
 
 [DEC,decX]
 (Ch_Mop1, Ch_WFlags, Ch_None)
-reg16                 \320\10\x48                     8086
 reg32                 \321\10\x48                     386
-rm8                   \300\1\xFE\201                  8086
-rm16                  \320\300\1\xFF\201              8086
+reg16                 \320\10\x48                     8086
 rm32                  \321\300\1\xFF\201              386
+rm16                  \320\300\1\xFF\201              8086
+rm8                   \300\1\xFE\201                  8086
 
 [DIV,divX]
 (Ch_RWEAX, Ch_WEDX, Ch_WFlags)
-rm8                   \300\1\xF6\206                  8086
-rm16                  \320\300\1\xF7\206              8086
 rm32                  \321\300\1\xF7\206              386
+rm16                  \320\300\1\xF7\206              8086
+rm8                   \300\1\xF6\206                  8086
 
 [EMMS]
 (Ch_FPU, Ch_None, Ch_None)
@@ -852,10 +852,10 @@ void                  \1\xF4                          8086,PRIV
 
 [IBTS,ibtsX]
 (Ch_All, Ch_None, Ch_None)
-mem,reg16             \320\300\2\x0F\xA7\101          386,SW,UNDOC,ND
+reg32,reg32           \321\300\2\x0F\xA7\101          386,UNDOC,ND
 reg16,reg16           \320\300\2\x0F\xA7\101          386,UNDOC,ND
 mem,reg32             \321\300\2\x0F\xA7\101          386,SD,UNDOC,ND
-reg32,reg32           \321\300\2\x0F\xA7\101          386,UNDOC,ND
+mem,reg16             \320\300\2\x0F\xA7\101          386,SW,UNDOC,ND
 
 [ICEBP]
 (Ch_All, Ch_None, Ch_None)
@@ -863,31 +863,31 @@ void                  \1\xF1                          386,ND
 
 [IDIV,idivX]
 (Ch_RWEAX, Ch_WEDX, Ch_WFlags)
-rm8                   \300\1\xF6\207                  8086
-rm16                  \320\300\1\xF7\207              8086
 rm32                  \321\300\1\xF7\207              386
+rm16                  \320\300\1\xF7\207              8086
+rm8                   \300\1\xF6\207                  8086
 
 [IMUL,imulX]
 (Ch_RWEAX, Ch_WEDX, Ch_WFlags)
+reg32,reg32           \321\301\2\x0F\xAF\110          386
+reg16,reg16           \320\301\2\x0F\xAF\110          386
 rm8                   \300\1\xF6\205                  8086
 rm16                  \320\300\1\xF7\205              8086
 rm32                  \321\300\1\xF7\205              386
-reg16,mem             \320\301\2\x0F\xAF\110          386,SM
-reg16,reg16           \320\301\2\x0F\xAF\110          386
 reg32,mem             \321\301\2\x0F\xAF\110          386,SM
-reg32,reg32           \321\301\2\x0F\xAF\110          386
-reg16,mem,imm8        \320\301\1\x6B\110\16           286,SM
-reg16,reg16,imm8      \320\301\1\x6B\110\16           286
-reg16,mem,imm         \320\301\1\x69\110\32           286,SM
-reg16,reg16,imm       \320\301\1\x69\110\32           286,SM
 reg32,mem,imm8        \321\301\1\x6B\110\16           386,SM
 reg32,reg32,imm8      \321\301\1\x6B\110\16           386
 reg32,mem,imm         \321\301\1\x69\110\42           386,SM
 reg32,reg32,imm       \321\301\1\x69\110\42           386,SM
-reg16,imm8            \320\1\x6B\100\15               286
-reg16,imm             \320\1\x69\100\31               286,SM
 reg32,imm8            \321\1\x6B\100\15               386
 reg32,imm             \321\1\x69\100\41               386,SM
+reg16,mem             \320\301\2\x0F\xAF\110          386,SM
+reg16,mem,imm8        \320\301\1\x6B\110\16           286,SM
+reg16,reg16,imm8      \320\301\1\x6B\110\16           286
+reg16,mem,imm         \320\301\1\x69\110\32           286,SM
+reg16,reg16,imm       \320\301\1\x69\110\32           286,SM
+reg16,imm8            \320\1\x6B\100\15               286
+reg16,imm             \320\1\x69\100\31               286,SM
 
 [IN,inX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
@@ -900,11 +900,11 @@ reg_eax,reg_dx        \321\1\xED                      386
 
 [INC,incX]
 (Ch_Mop1, Ch_WFlags, Ch_None)
-reg16                 \320\10\x40                     8086
 reg32                 \321\10\x40                     386
-rm8                   \300\1\xFE\200                  8086
-rm16                  \320\300\1\xFF\200              8086
+reg16                 \320\10\x40                     8086
 rm32                  \321\300\1\xFF\200              386
+rm16                  \320\300\1\xFF\200              8086
+rm8                   \300\1\xFE\200                  8086
 
 [INSB]
 (Ch_WMemEDI, Ch_RWEDI, Ch_REDX)
@@ -993,11 +993,11 @@ mem32|far             \321\300\1\xFF\205              386
 mem|near              \323\300\1\xFF\204              8086
 mem16|near            \320\300\1\xFF\204              8086
 mem32|near            \321\300\1\xFF\204              386
-reg16                 \320\300\1\xFF\204              8086
 reg32                 \321\300\1\xFF\204              386
-mem                   \323\300\1\xFF\204              8086
-mem16                 \320\300\1\xFF\204              8086
+reg16                 \320\300\1\xFF\204              8086
 mem32                 \321\300\1\xFF\204              386
+mem16                 \320\300\1\xFF\204              8086
+mem                   \323\300\1\xFF\204              8086
 
 [LAHF]
 (Ch_WEAX, Ch_RFlags, Ch_None)
@@ -1005,10 +1005,10 @@ void                  \1\x9F                          8086
 
 [LAR,larX]
 (Ch_Wop2, Ch_None, Ch_None)
-reg16,mem             \320\301\2\x0F\x02\110          286,PROT,SM
+reg32,reg32           \321\301\2\x0F\x02\110          286,PROT
 reg16,reg16           \320\301\2\x0F\x02\110          286,PROT
 reg32,mem             \321\301\2\x0F\x02\110          286,PROT,SM
-reg32,reg32           \321\301\2\x0F\x02\110          286,PROT
+reg16,mem             \320\301\2\x0F\x02\110          286,PROT,SM
 
 [LCALL,lcall]
 ; don't know value of any register
@@ -1027,14 +1027,14 @@ mem32                 \321\300\1\xFF\202              386
 
 [LDS,ldsX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
-reg16,mem             \320\301\1\xC5\110              8086
 reg32,mem             \321\301\1\xC5\110              8086
+reg16,mem             \320\301\1\xC5\110              8086
 
 [LEA,leaX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
-reg16,mem             \320\301\1\x8D\110              8086
 reg32,mem             \321\301\1\x8D\110              8086
 reg32,imm32           \321\301\1\x8D\110              8086
+reg16,mem             \320\301\1\x8D\110              8086
 
 [LEAVE]
 (Ch_RWESP, Ch_WEBP, Ch_None)
@@ -1042,13 +1042,13 @@ void                  \1\xC9                          186
 
 [LES,lesX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
-reg16,mem             \320\301\1\xC4\110              8086
 reg32,mem             \321\301\1\xC4\110              8086
+reg16,mem             \320\301\1\xC4\110              8086
 
 [LFS,lfsX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
-reg16,mem             \320\301\2\x0F\xB4\110          386
 reg32,mem             \321\301\2\x0F\xB4\110          386
+reg16,mem             \320\301\2\x0F\xB4\110          386
 
 [LGDT,lgdtX]
 (Ch_None, Ch_None, Ch_None)
@@ -1056,8 +1056,8 @@ mem                   \300\2\x0F\x01\202              286,PRIV
 
 [LGS,lgsX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
-reg16,mem             \320\301\2\x0F\xB5\110          386
 reg32,mem             \321\301\2\x0F\xB5\110          386
+reg16,mem             \320\301\2\x0F\xB5\110          386
 
 [LIDT,lidtX]
 (Ch_None, Ch_None, Ch_None)
@@ -1071,11 +1071,11 @@ mem32|far             \321\300\1\xFF\205              386
 mem|near              \323\300\1\xFF\204              8086
 mem16|near            \320\300\1\xFF\204              8086
 mem32|near            \321\300\1\xFF\204              386
-reg16                 \320\300\1\xFF\204              8086
 reg32                 \321\300\1\xFF\204              386
-mem                   \323\300\1\xFF\204              8086
-mem16                 \320\300\1\xFF\204              8086
+reg16                 \320\300\1\xFF\204              8086
 mem32                 \321\300\1\xFF\204              386
+mem16                 \320\300\1\xFF\204              8086
+mem                   \323\300\1\xFF\204              8086
 
 [LLDT,lldtX]
 (Ch_None, Ch_None, Ch_None)
@@ -1145,15 +1145,15 @@ imm,reg_ecx           \311\1\xE1\50                   386
 
 [LSL,lslX]
 (Ch_Wop2, Ch_WFlags, Ch_None)
-reg16,mem             \320\301\2\x0F\x03\110          286,PROT,SM
+reg32,reg32           \321\301\2\x0F\x03\110          286,PROT
 reg16,reg16           \320\301\2\x0F\x03\110          286,PROT
 reg32,mem             \321\301\2\x0F\x03\110          286,PROT,SM
-reg32,reg32           \321\301\2\x0F\x03\110          286,PROT
+reg16,mem             \320\301\2\x0F\x03\110          286,PROT,SM
 
 [LSS,lssX]
 (Ch_Wop2, Ch_ROP1, Ch_None)
-reg16,mem             \320\301\2\x0F\xB2\110          386
 reg32,mem             \321\301\2\x0F\xB2\110          386
+reg16,mem             \320\301\2\x0F\xB2\110          386
 
 [LTR,ltrX]
 (Ch_None, Ch_None, Ch_None)
@@ -1168,6 +1168,29 @@ reg_eax,reg_ecx,reg_edx      \3\x0F\x01\xC8           PRESCOTT,ND
 
 [MOV,movX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
+reg64,reg64           \322\300\1\x89\101              X86_64
+reg32,reg32           \321\300\1\x89\101              386
+reg16,reg16           \320\300\1\x89\101              8086
+reg8,reg8             \300\1\x88\101                  8086
+mem,reg64             \322\300\1\x89\101              X86_64
+mem,reg32             \321\300\1\x89\101              386,SM
+mem,reg16             \320\300\1\x89\101              8086,SM
+mem,reg8              \300\1\x88\101                  8086,SM
+reg64,mem             \322\301\1\x8B\110              X86_64
+reg32,mem             \321\301\1\x8B\110              386,SM
+reg16,mem             \320\301\1\x8B\110              8086,SM
+reg8,mem              \301\1\x8A\110                  8086,SM
+reg64,imm             \322\10\xB8\41                  X86_64
+reg32,imm             \321\10\xB8\41                  386,SM
+reg16,imm             \320\10\xB8\31                  8086,SM
+reg8,imm              \10\xB0\21                      8086,SM
+rm64,imm              \322\300\1\xC7\200\41           X86_64
+rm32,imm              \321\300\1\xC7\200\41           386,SM
+rm16,imm              \320\300\1\xC7\200\31           8086,SM
+rm8,imm               \300\1\xC6\200\21               8086,SM
+mem,imm32             \321\300\1\xC7\200\41           386,SM
+mem,imm16             \320\300\1\xC7\200\31           8086,SM
+mem,imm8              \300\1\xC6\200\21               8086,SM
 mem,reg_cs            \320\300\1\x8C\201              8086,SM
 mem,reg_dess          \320\300\1\x8C\101              8086,SM
 mem,reg_fsgs          \320\300\1\x8C\101              386,SM
@@ -1196,38 +1219,15 @@ reg32,reg_treg        \2\x0F\x24\101                  386,PRIV,NOX86_64
 reg64,reg_cr4         \2\x0F\x20\204                  PENT,PRIV,X86_64
 reg64,reg_creg        \2\x0F\x20\101                  386,PRIV,X86_64
 reg64,reg_dreg        \2\x0F\x21\101                  386,PRIV,X86_64
-reg64,reg_treg        \2\x0F\x24\101                  386,PRIV,X86_64
-reg_cr4,reg32         \2\x0F\x22\214                  PENT,PRIV
-reg_creg,reg32        \2\x0F\x22\110                  386,PRIV
-reg_dreg,reg32        \2\x0F\x23\110                  386,PRIV
-reg_treg,reg32        \2\x0F\x26\110                  386,PRIV
-mem,reg8              \300\1\x88\101                  8086,SM
-reg8,reg8             \300\1\x88\101                  8086
-mem,reg16             \320\300\1\x89\101              8086,SM
-reg16,reg16           \320\300\1\x89\101              8086
-mem,reg32             \321\300\1\x89\101              386,SM
-reg32,reg32           \321\300\1\x89\101              386
-mem,reg64             \322\300\1\x89\101              X86_64
-reg64,reg64           \322\300\1\x89\101              X86_64
-reg8,mem              \301\1\x8A\110                  8086,SM
+reg64,reg_treg        \2\x0F\x24\101                  386,PRIV,X86_64
+reg_cr4,reg32         \2\x0F\x22\214                  PENT,PRIV
+reg_creg,reg32        \2\x0F\x22\110                  386,PRIV
+reg_dreg,reg32        \2\x0F\x23\110                  386,PRIV
+reg_treg,reg32        \2\x0F\x26\110                  386,PRIV
 reg8,reg8             \301\1\x8A\110                  8086
-reg16,mem             \320\301\1\x8B\110              8086,SM
 reg16,reg16           \320\301\1\x8B\110              8086
-reg32,mem             \321\301\1\x8B\110              386,SM
 reg32,reg32           \321\301\1\x8B\110              386
-reg64,mem             \322\301\1\x8B\110              X86_64
 reg64,reg64           \322\301\1\x8B\110              X86_64
-reg8,imm              \10\xB0\21                      8086,SM
-reg16,imm             \320\10\xB8\31                  8086,SM
-reg32,imm             \321\10\xB8\41                  386,SM
-reg64,imm             \322\10\xB8\41                  X86_64
-rm8,imm               \300\1\xC6\200\21               8086,SM
-rm16,imm              \320\300\1\xC7\200\31           8086,SM
-rm32,imm              \321\300\1\xC7\200\41           386,SM
-rm64,imm              \322\300\1\xC7\200\41           X86_64
-mem,imm8              \300\1\xC6\200\21               8086,SM
-mem,imm16             \320\300\1\xC7\200\31           8086,SM
-mem,imm32             \321\300\1\xC7\200\41           386,SM
 
 [MOVD,movd]
 (Ch_Rop1, Ch_Wop2, Ch_None)
@@ -1251,7 +1251,6 @@ xmmreg,xmmreg         \3\x66\x0F\xD6\110              WILLAMETTE,SSE2
 mem,xmmreg            \300\3\x66\x0F\xD6\101          WILLAMETTE,SSE2
 xmmreg,mem            \301\333\2\x0F\x7E\110          WILLAMETTE,SSE2
 
-
 [MOVSB]
 (Ch_All, Ch_None, Ch_None)
 void                  \1\xA4                          8086
@@ -1275,24 +1274,24 @@ void                  \320\1\xA5                      8086
 
 [MOVSX,movsX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
-reg16,mem             \320\301\2\x0F\xBE\110          386,SB
-reg16,reg8            \320\301\2\x0F\xBE\110          386
-reg32,rm8             \321\301\2\x0F\xBE\110          386
-reg32,rm16            \321\301\2\x0F\xBF\110          386
 reg64,rm16            \321\301\2\x0F\xBF\110          X86_64
+reg32,rm16            \321\301\2\x0F\xBF\110          386
+reg32,rm8             \321\301\2\x0F\xBE\110          386
+reg16,reg8            \320\301\2\x0F\xBE\110          386
+reg16,mem             \320\301\2\x0F\xBE\110          386,SB
 
 [MOVZX,movzX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
-reg16,mem             \320\301\2\x0F\xB6\110          386,SB
-reg16,reg8            \320\301\2\x0F\xB6\110          386
-reg32,rm8             \321\301\2\x0F\xB6\110          386
 reg32,rm16            \321\301\2\x0F\xB7\110          386
+reg32,rm8             \321\301\2\x0F\xB6\110          386
+reg16,reg8            \320\301\2\x0F\xB6\110          386
+reg16,mem             \320\301\2\x0F\xB6\110          386,SB
 
 [MUL,mulX]
 (Ch_RWEAX, Ch_WEDX, Ch_WFlags)
-rm8                   \300\1\xF6\204                  8086
-rm16                  \320\300\1\xF7\204              8086
 rm32                  \321\300\1\xF7\204              386
+rm16                  \320\300\1\xF7\204              8086
+rm8                   \300\1\xF6\204                  8086
 
 [MWAIT]
 (Ch_None, Ch_None, Ch_None)
@@ -1302,9 +1301,9 @@ reg_eax,reg_ecx       \3\x0F\x01\xC9		      PRESCOTT,ND
 
 [NEG,negX]
 (Ch_Mop1, Ch_None, Ch_None)
-rm8                   \300\1\xF6\203                  8086
-rm16                  \320\300\1\xF7\203              8086
 rm32                  \321\300\1\xF7\203              386
+rm16                  \320\300\1\xF7\203              8086
+rm8                   \300\1\xF6\203                  8086
 
 [NOP]
 (Ch_None, Ch_None, Ch_None)
@@ -1312,35 +1311,35 @@ void                  \1\x90                          8086
 
 [NOT,notX]
 (Ch_Mop1, Ch_WFlags, Ch_None)
-rm8                   \300\1\xF6\202                  8086
-rm16                  \320\300\1\xF7\202              8086
 rm32                  \321\300\1\xF7\202              386
+rm16                  \320\300\1\xF7\202              8086
+rm8                   \300\1\xF6\202                  8086
 
 [OR,orX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-mem,reg8              \300\1\x08\101                  8086,SM
-reg8,reg8             \300\1\x08\101                  8086
-mem,reg16             \320\300\1\x09\101              8086,SM
+reg32,reg32           \321\300\1\x09\101              386
 reg16,reg16           \320\300\1\x09\101              8086
+reg8,reg8             \300\1\x08\101                  8086
 mem,reg32             \321\300\1\x09\101              386,SM
-reg32,reg32           \321\300\1\x09\101              386
-reg8,mem              \301\1\x0A\110                  8086,SM
-reg8,reg8             \301\1\x0A\110                  8086
-reg16,mem             \320\301\1\x0B\110              8086,SM
-reg16,reg16           \320\301\1\x0B\110              8086
+mem,reg16             \320\300\1\x09\101              8086,SM
+mem,reg8              \300\1\x08\101                  8086,SM
 reg32,mem             \321\301\1\x0B\110              386,SM
-reg32,reg32           \321\301\1\x0B\110              386
-rm16,imm8             \320\300\1\x83\201\15           8086
+reg16,mem             \320\301\1\x0B\110              8086,SM
+reg8,mem              \301\1\x0A\110                  8086,SM
 rm32,imm8             \321\300\1\x83\201\15           386
-reg_al,imm            \1\x0C\21                       8086,SM
-reg_ax,imm            \320\1\x0D\31                   8086,SM
+rm16,imm8             \320\300\1\x83\201\15           8086
 reg_eax,imm           \321\1\x0D\41                   386,SM
-rm8,imm               \300\1\x80\201\21               8086,SM
-rm16,imm              \320\300\1\x81\201\31           8086,SM
+reg_ax,imm            \320\1\x0D\31                   8086,SM
+reg_al,imm            \1\x0C\21                       8086,SM
 rm32,imm              \321\300\1\x81\201\41           386,SM
-mem,imm8              \300\1\x80\201\21               8086,SM
-mem,imm16             \320\300\1\x81\201\31           8086,SM
+rm16,imm              \320\300\1\x81\201\31           8086,SM
+rm8,imm               \300\1\x80\201\21               8086,SM
 mem,imm32             \321\300\1\x81\201\41           386,SM
+mem,imm16             \320\300\1\x81\201\31           8086,SM
+mem,imm8              \300\1\x80\201\21               8086,SM
+reg32,reg32           \321\301\1\x0B\110              386
+reg16,reg16           \320\301\1\x0B\110              8086
+reg8,reg8             \301\1\x0A\110                  8086
 
 [OUT,outX]
 (Ch_Rop1, Ch_Rop2, Ch_None)
@@ -1921,27 +1920,27 @@ xmmreg,xmmreg         \3\x66\x0F\xEF\110              WILLAMETTE,SSE2
 
 [RCL,rclX]
 (Ch_Mop2, Ch_Rop1, Ch_RWFlags)
-rm8,unity             \300\1\xD0\202                  8086
-rm8,reg_cl            \300\1\xD2\202                  8086
-rm8,imm               \300\1\xC0\202\25               186,SB
-rm16,unity            \320\300\1\xD1\202              8086
-rm16,reg_cl           \320\300\1\xD3\202              8086
-rm16,imm              \320\300\1\xC1\202\25           186,SB
 rm32,unity            \321\300\1\xD1\202              386
 rm32,reg_cl           \321\300\1\xD3\202              386
 rm32,imm              \321\300\1\xC1\202\25           386,SB
+rm16,unity            \320\300\1\xD1\202              8086
+rm16,reg_cl           \320\300\1\xD3\202              8086
+rm16,imm              \320\300\1\xC1\202\25           186,SB
+rm8,unity             \300\1\xD0\202                  8086
+rm8,reg_cl            \300\1\xD2\202                  8086
+rm8,imm               \300\1\xC0\202\25               186,SB
 
 [RCR,rcrX]
 (Ch_Mop2, Ch_Rop1, Ch_RWFlags)
-rm8,unity             \300\1\xD0\203                  8086
-rm8,reg_cl            \300\1\xD2\203                  8086
-rm8,imm               \300\1\xC0\203\25               186,SB
-rm16,unity            \320\300\1\xD1\203              8086
-rm16,reg_cl           \320\300\1\xD3\203              8086
-rm16,imm              \320\300\1\xC1\203\25           186,SB
 rm32,unity            \321\300\1\xD1\203              386
 rm32,reg_cl           \321\300\1\xD3\203              386
 rm32,imm              \321\300\1\xC1\203\25           386,SB
+rm16,unity            \320\300\1\xD1\203              8086
+rm16,reg_cl           \320\300\1\xD3\203              8086
+rm16,imm              \320\300\1\xC1\203\25           186,SB
+rm8,unity             \300\1\xD0\203                  8086
+rm8,reg_cl            \300\1\xD2\203                  8086
+rm8,imm               \300\1\xC0\203\25               186,SB
 
 [RDSHR]
 (Ch_All, Ch_None, Ch_None)
@@ -1996,27 +1995,27 @@ imm                   \1\xC2\30                       8086,SW
 
 [ROL,rolX]
 (Ch_Mop2, Ch_Rop1, Ch_RWFlags)
-rm8,unity             \300\1\xD0\200                  8086
-rm8,reg_cl            \300\1\xD2\200                  8086
-rm8,imm               \300\1\xC0\200\25               186,SB
-rm16,unity            \320\300\1\xD1\200              8086
-rm16,reg_cl           \320\300\1\xD3\200              8086
-rm16,imm              \320\300\1\xC1\200\25           186,SB
 rm32,unity            \321\300\1\xD1\200              386
 rm32,reg_cl           \321\300\1\xD3\200              386
 rm32,imm              \321\300\1\xC1\200\25           386,SB
+rm16,unity            \320\300\1\xD1\200              8086
+rm16,reg_cl           \320\300\1\xD3\200              8086
+rm16,imm              \320\300\1\xC1\200\25           186,SB
+rm8,unity             \300\1\xD0\200                  8086
+rm8,reg_cl            \300\1\xD2\200                  8086
+rm8,imm               \300\1\xC0\200\25               186,SB
 
 [ROR,rorX]
 (Ch_Mop2, Ch_Rop1, Ch_RWFlags)
-rm8,unity             \300\1\xD0\201                  8086
-rm8,reg_cl            \300\1\xD2\201                  8086
-rm8,imm               \300\1\xC0\201\25               186,SB
-rm16,unity            \320\300\1\xD1\201              8086
-rm16,reg_cl           \320\300\1\xD3\201              8086
-rm16,imm              \320\300\1\xC1\201\25           186,SB
 rm32,unity            \321\300\1\xD1\201              386
 rm32,reg_cl           \321\300\1\xD3\201              386
 rm32,imm              \321\300\1\xC1\201\25           386,SB
+rm16,unity            \320\300\1\xD1\201              8086
+rm16,reg_cl           \320\300\1\xD3\201              8086
+rm16,imm              \320\300\1\xC1\201\25           186,SB
+rm8,unity             \300\1\xD0\201                  8086
+rm8,reg_cl            \300\1\xD2\201                  8086
+rm8,imm               \300\1\xC0\201\25               186,SB
 
 [RSDC]
 (Ch_All, Ch_None, Ch_None)
@@ -2036,15 +2035,15 @@ void                  \1\x9E                          8086,NOX86_64
 
 [SAL,salX]
 (Ch_Mop2, Ch_Rop1, Ch_RWFlags)
-rm8,unity             \300\1\xD0\204                  8086,ND
-rm8,reg_cl            \300\1\xD2\204                  8086,ND
-rm8,imm               \300\1\xC0\204\25               186,ND,SB
-rm16,unity            \320\300\1\xD1\204              8086,ND
-rm16,reg_cl           \320\300\1\xD3\204              8086,ND
-rm16,imm              \320\300\1\xC1\204\25           186,ND,SB
 rm32,unity            \321\300\1\xD1\204              386,ND
 rm32,reg_cl           \321\300\1\xD3\204              386,ND
 rm32,imm              \321\300\1\xC1\204\25           386,ND,SB
+rm16,unity            \320\300\1\xD1\204              8086,ND
+rm16,reg_cl           \320\300\1\xD3\204              8086,ND
+rm16,imm              \320\300\1\xC1\204\25           186,ND,SB
+rm8,unity             \300\1\xD0\204                  8086,ND
+rm8,reg_cl            \300\1\xD2\204                  8086,ND
+rm8,imm               \300\1\xC0\204\25               186,ND,SB
 
 [SALC]
 (Ch_WEAX, Ch_RFLAGS, Ch_None)
@@ -2052,15 +2051,15 @@ void                  \1\xD6                          8086,UNDOC
 
 [SAR,sarX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-rm8,unity             \300\1\xD0\207                  8086
-rm8,reg_cl            \300\1\xD2\207                  8086
-rm8,imm               \300\1\xC0\207\25               186,SB
-rm16,unity            \320\300\1\xD1\207              8086
-rm16,reg_cl           \320\300\1\xD3\207              8086
-rm16,imm              \320\300\1\xC1\207\25           186,SB
 rm32,unity            \321\300\1\xD1\207              386
 rm32,reg_cl           \321\300\1\xD3\207              386
 rm32,imm              \321\300\1\xC1\207\25           386,SB
+rm16,unity            \320\300\1\xD1\207              8086
+rm16,reg_cl           \320\300\1\xD3\207              8086
+rm16,imm              \320\300\1\xC1\207\25           186,SB
+rm8,unity             \300\1\xD0\207                  8086
+rm8,reg_cl            \300\1\xD2\207                  8086
+rm8,imm               \300\1\xC0\207\25               186,SB
 
 [SBB,sbbX]
 (Ch_Mop2, Ch_Rop1, Ch_RWFlags)
@@ -2237,37 +2236,35 @@ reg32                 \321\1\x0F\17\201               386,PROT
 
 [SUB,subX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-mem,reg8              \300\1\x28\101                  8086,SM
-reg8,reg8             \300\1\x28\101                  8086
-mem,reg16             \320\300\1\x29\101              8086,SM
-reg16,reg16           \320\300\1\x29\101              8086
-mem,reg32             \321\300\1\x29\101              386,SM
-reg32,reg32           \321\300\1\x29\101              386
-mem,reg32             \321\300\1\x29\101              386,SM
+reg64,reg64           \322\300\1\x29\101              X86_64
 reg32,reg32           \321\300\1\x29\101              386
+reg16,reg16           \320\300\1\x29\101              8086
+reg8,reg8             \300\1\x28\101                  8086
 mem,reg64             \322\300\1\x29\101              X86_64
-reg64,reg64           \322\300\1\x29\101              X86_64
-reg8,mem              \301\1\x2A\110                  8086,SM
-reg8,reg8             \301\1\x2A\110                  8086
-reg16,mem             \320\301\1\x2B\110              8086,SM
-reg16,reg16           \320\301\1\x2B\110              8086
+mem,reg32             \321\300\1\x29\101              386,SM
+mem,reg16             \320\300\1\x29\101              8086,SM
+mem,reg8              \300\1\x28\101                  8086,SM
 reg32,mem             \321\301\1\x2B\110              386,SM
-reg32,reg32           \321\301\1\x2B\110              386
-reg64,reg64           \322\301\1\x2B\110              X86_64
-rm16,imm8             \320\300\1\x83\205\15           8086
-rm32,imm8             \321\300\1\x83\205\15           386
+reg16,mem             \320\301\1\x2B\110              8086,SM
+reg8,mem              \301\1\x2A\110                  8086,SM
 rm64,imm8             \322\300\1\x83\205\15           X86_64
-reg_al,imm            \1\x2C\21                       8086,SM
-reg_ax,imm            \320\1\x2D\31                   8086,SM
-reg_eax,imm           \321\1\x2D\41                   386,SM
+rm32,imm8             \321\300\1\x83\205\15           386
+rm16,imm8             \320\300\1\x83\205\15           8086
 reg_rax,imm           \322\1\x2D\41                   X86_64
-rm8,imm               \300\1\x80\205\21               8086,SM
-rm16,imm              \320\300\1\x81\205\31           8086,SM
-rm32,imm              \321\300\1\x81\205\41           386,SM
+reg_eax,imm           \321\1\x2D\41                   386,SM
+reg_ax,imm            \320\1\x2D\31                   8086,SM
+reg_al,imm            \1\x2C\21                       8086,SM
 rm64,imm              \322\300\1\x81\205\41           X86_64
-mem,imm8              \300\1\x80\205\21               8086,SM
-mem,imm16             \320\300\1\x81\205\31           8086,SM
+rm32,imm              \321\300\1\x81\205\41           386,SM
+rm16,imm              \320\300\1\x81\205\31           8086,SM
+rm8,imm               \300\1\x80\205\21               8086,SM
 mem,imm32             \321\300\1\x81\205\41           386,SM
+mem,imm16             \320\300\1\x81\205\31           8086,SM
+mem,imm8              \300\1\x80\205\21               8086,SM
+reg64,reg64           \322\301\1\x2B\110              X86_64
+reg32,reg32           \321\301\1\x2B\110              386
+reg16,reg16           \320\301\1\x2B\110              8086
+reg8,reg8             \301\1\x2A\110                  8086
 
 [SVDC,svdcX]
 (Ch_All, Ch_None, Ch_None)
@@ -2299,24 +2296,24 @@ void                  \2\x0F\x07                      P6,PRIV,AMD
 
 [TEST,testX]
 (Ch_WFlags, Ch_Rop1, Ch_Rop2)
-mem,reg8              \300\1\x84\101                  8086,SM
-reg8,reg8             \300\1\x84\101                  8086
-mem,reg16             \320\300\1\x85\101              8086,SM
+reg32,reg32           \321\300\1\x85\101              386
 reg16,reg16           \320\300\1\x85\101              8086
+reg8,reg8             \300\1\x84\101                  8086
 mem,reg32             \321\300\1\x85\101              386,SM
-reg32,reg32           \321\300\1\x85\101              386
-reg8,mem              \301\1\x84\110                  8086,SM
-reg16,mem             \320\301\1\x85\110              8086,SM
+mem,reg16             \320\300\1\x85\101              8086,SM
+mem,reg8              \300\1\x84\101                  8086,SM
 reg32,mem             \321\301\1\x85\110              386,SM
-reg_al,imm            \1\xA8\21                       8086,SM
-reg_ax,imm            \320\1\xA9\31                   8086,SM
+reg16,mem             \320\301\1\x85\110              8086,SM
+reg8,mem              \301\1\x84\110                  8086,SM
 reg_eax,imm           \321\1\xA9\41                   386,SM
-rm8,imm               \300\1\xF6\200\21               8086,SM
-rm16,imm              \320\300\1\xF7\200\31           8086,SM
+reg_ax,imm            \320\1\xA9\31                   8086,SM
+reg_al,imm            \1\xA8\21                       8086,SM
 rm32,imm              \321\300\1\xF7\200\41           386,SM
-mem,imm8              \300\1\xF6\200\21               8086,SM
-mem,imm16             \320\300\1\xF7\200\31           8086,SM
+rm16,imm              \320\300\1\xF7\200\31           8086,SM
+rm8,imm               \300\1\xF6\200\21               8086,SM
 mem,imm32             \321\300\1\xF7\200\41           386,SM
+mem,imm16             \320\300\1\xF7\200\31           8086,SM
+mem,imm8              \300\1\xF6\200\21               8086,SM
 
 [UD1]
 (Ch_All, Ch_None, Ch_None)
@@ -2414,29 +2411,29 @@ void                  \1\xD7                          8086
 
 [XOR,xorX]
 (Ch_Mop2, Ch_Rop1, Ch_WFlags)
-mem,reg8              \300\1\x30\101                  8086,SM
-reg8,reg8             \300\1\x30\101                  8086
-mem,reg16             \320\300\1\x31\101              8086,SM
+reg32,reg32           \321\300\1\x31\101              386
 reg16,reg16           \320\300\1\x31\101              8086
+reg8,reg8             \300\1\x30\101                  8086
 mem,reg32             \321\300\1\x31\101              386,SM
-reg32,reg32           \321\300\1\x31\101              386
-reg8,mem              \301\1\x32\110                  8086,SM
-reg8,reg8             \301\1\x32\110                  8086
-reg16,mem             \320\301\1\x33\110              8086,SM
-reg16,reg16           \320\301\1\x33\110              8086
+mem,reg16             \320\300\1\x31\101              8086,SM
+mem,reg8              \300\1\x30\101                  8086,SM
 reg32,mem             \321\301\1\x33\110              386,SM
-reg32,reg32           \321\301\1\x33\110              386
-rm16,imm8             \320\300\1\x83\206\15           8086
+reg16,mem             \320\301\1\x33\110              8086,SM
+reg8,mem              \301\1\x32\110                  8086,SM
 rm32,imm8             \321\300\1\x83\206\15           386
-reg_al,imm            \1\x34\21                       8086,SM
-reg_ax,imm            \320\1\x35\31                   8086,SM
+rm16,imm8             \320\300\1\x83\206\15           8086
 reg_eax,imm           \321\1\x35\41                   386,SM
-rm8,imm               \300\1\x80\206\21               8086,SM
-rm16,imm              \320\300\1\x81\206\31           8086,SM
+reg_ax,imm            \320\1\x35\31                   8086,SM
+reg_al,imm            \1\x34\21                       8086,SM
 rm32,imm              \321\300\1\x81\206\41           386,SM
-mem,imm8              \300\1\x80\206\21               8086,SM
-mem,imm16             \320\300\1\x81\206\31           8086,SM
+rm16,imm              \320\300\1\x81\206\31           8086,SM
+rm8,imm               \300\1\x80\206\21               8086,SM
 mem,imm32             \321\300\1\x81\206\41           386,SM
+mem,imm16             \320\300\1\x81\206\31           8086,SM
+mem,imm8              \300\1\x80\206\21               8086,SM
+reg32,reg32           \321\301\1\x33\110              386
+reg16,reg16           \320\301\1\x33\110              8086
+reg8,reg8             \301\1\x32\110                  8086
 
 [XSTORE]
 (Ch_All, Ch_None, Ch_None)
@@ -2460,10 +2457,10 @@ void                  \333\3\x0F\xA7\xE8              P6,CYRIX
 
 [CMOVcc,cmovCCX]
 (Ch_ROp1, Ch_WOp2, Ch_RFLAGS)
-reg16,mem             \320\301\1\x0F\330\x40\110      P6,SM
+reg32,reg32           \321\301\1\x0F\330\x40\110      P6
 reg16,reg16           \320\301\1\x0F\330\x40\110      P6
 reg32,mem             \321\301\1\x0F\330\x40\110      P6,SM
-reg32,reg32           \321\301\1\x0F\330\x40\110      P6
+reg16,mem             \320\301\1\x0F\330\x40\110      P6,SM
 
 [Jcc]
 (Ch_None, Ch_None, Ch_None)

Some files were not shown because too many files changed in this diff