X86: Respect segment override prefixes even when there's no ModRM byte.
authorGabe Black <gblack@eecs.umich.edu>
Fri, 27 Feb 2009 17:23:58 +0000 (09:23 -0800)
committerGabe Black <gblack@eecs.umich.edu>
Fri, 27 Feb 2009 17:23:58 +0000 (09:23 -0800)
src/arch/x86/emulenv.cc
src/arch/x86/emulenv.hh
src/arch/x86/isa/macroop.isa

index 30ed80942933d4f282c65d8eeae6da350f99c351..0d7b32130f4c669cce3c7bd854d7af7fd149e204 100644 (file)
@@ -105,3 +105,11 @@ void EmulEnv::doModRM(const ExtMachInst & machInst)
     }
 }
 
+void EmulEnv::setSeg(const ExtMachInst & machInst)
+{
+    seg = SEGMENT_REG_DS;
+    //Handle any segment override that might have been in the instruction
+    int segFromInst = machInst.legacy.seg;
+    if (segFromInst)
+        seg = (SegmentRegIndex)(segFromInst - 1);
+}
index 1044dbdf9e404a2ea1f7f3da61b34c222affbb48..cdb1bf863929a202b7d225298a763782955f3696 100644 (file)
@@ -86,6 +86,7 @@ namespace X86ISA
         {;}
 
         void doModRM(const ExtMachInst & machInst);
+        void setSeg(const ExtMachInst & machInst);
     };
 };
 
index 8eaf5f7867c8bbbf7fb5f6a2dcf182e1f17f9bcd..3a836ff686f0abb3dfcb204f246c3fc4fbb3f430 100644 (file)
@@ -135,7 +135,7 @@ def template MacroConstructor {{
             %(adjust_env)s;
             %(adjust_imm)s;
             %(adjust_disp)s;
-            %(do_modrm)s;
+            %(init_env)s;
             %(constructor)s;
             const char *macrocodeBlock = "%(class_name)s";
             //alloc_microops is the code that sets up the microops
@@ -166,7 +166,7 @@ let {{
             }
             self.declared = False
             self.adjust_env = ""
-            self.doModRM = ""
+            self.init_env = ""
             self.adjust_imm = '''
                 uint64_t adjustedImm = IMMEDIATE;
                 //This is to pacify gcc in case the immediate isn't used.
@@ -228,7 +228,7 @@ let {{
                                  "adjust_disp" : self.adjust_disp,
                                  "disassembly" : env.disassembly,
                                  "regSize" : regSize,
-                                 "do_modrm" : self.doModRM})
+                                 "init_env" : self.initEnv})
             return MacroConstructor.subst(iop) + \
                    MacroDisassembly.subst(iop);
 }};
@@ -304,6 +304,7 @@ let {{
 
 let {{
     doModRMString = "env.doModRM(machInst);\n"
+    noModRMString = "env.setSeg(machInst);\n"
     def genMacroop(Name, env):
         blocks = OutputBlocks()
         if not macroopDict.has_key(Name):
@@ -311,7 +312,9 @@ let {{
         macroop = macroopDict[Name]
         if not macroop.declared:
             if env.doModRM:
-                macroop.doModRM = doModRMString
+                macroop.initEnv = doModRMString
+            else:
+                macroop.initEnv = noModRMString
             blocks.header_output = macroop.getDeclaration()
             blocks.decoder_output = macroop.getDefinition(env)
             macroop.declared = True