emulenv.cc revision 4848
18839Sandreas.hansson@arm.com/* 28839Sandreas.hansson@arm.com * Copyright (c) 2007 The Hewlett-Packard Development Company 38839Sandreas.hansson@arm.com * All rights reserved. 48839Sandreas.hansson@arm.com * 58839Sandreas.hansson@arm.com * Redistribution and use of this software in source and binary forms, 68839Sandreas.hansson@arm.com * with or without modification, are permitted provided that the 78839Sandreas.hansson@arm.com * following conditions are met: 88839Sandreas.hansson@arm.com * 98839Sandreas.hansson@arm.com * The software must be used only for Non-Commercial Use which means any 108839Sandreas.hansson@arm.com * use which is NOT directed to receiving any direct monetary 118839Sandreas.hansson@arm.com * compensation for, or commercial advantage from such use. Illustrative 128839Sandreas.hansson@arm.com * examples of non-commercial use are academic research, personal study, 133101Sstever@eecs.umich.edu * teaching, education and corporate research & development. 148579Ssteve.reinhardt@amd.com * Illustrative examples of commercial use are distributing products for 153101Sstever@eecs.umich.edu * commercial advantage and providing services using the software for 163101Sstever@eecs.umich.edu * commercial advantage. 173101Sstever@eecs.umich.edu * 183101Sstever@eecs.umich.edu * If you wish to use this software or functionality therein that may be 193101Sstever@eecs.umich.edu * covered by patents for commercial use, please contact: 203101Sstever@eecs.umich.edu * Director of Intellectual Property Licensing 213101Sstever@eecs.umich.edu * Office of Strategy and Technology 223101Sstever@eecs.umich.edu * Hewlett-Packard Company 233101Sstever@eecs.umich.edu * 1501 Page Mill Road 243101Sstever@eecs.umich.edu * Palo Alto, California 94304 253101Sstever@eecs.umich.edu * 263101Sstever@eecs.umich.edu * Redistributions of source code must retain the above copyright notice, 273101Sstever@eecs.umich.edu * this list of conditions and the following disclaimer. Redistributions 283101Sstever@eecs.umich.edu * in binary form must reproduce the above copyright notice, this list of 293101Sstever@eecs.umich.edu * conditions and the following disclaimer in the documentation and/or 303101Sstever@eecs.umich.edu * other materials provided with the distribution. Neither the name of 313101Sstever@eecs.umich.edu * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 323101Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from 333101Sstever@eecs.umich.edu * this software without specific prior written permission. No right of 343101Sstever@eecs.umich.edu * sublicense is granted herewith. Derivatives of the software and 353101Sstever@eecs.umich.edu * output created using the software may be prepared, but only for 363101Sstever@eecs.umich.edu * Non-Commercial Uses. Derivatives of the software may be shared with 373101Sstever@eecs.umich.edu * others provided: (i) the others agree to abide by the list of 383101Sstever@eecs.umich.edu * conditions herein which includes the Non-Commercial Use restrictions; 393101Sstever@eecs.umich.edu * and (ii) such Derivatives of the software include the above copyright 403101Sstever@eecs.umich.edu * notice to acknowledge the contribution from this software where 413101Sstever@eecs.umich.edu * applicable, this list of conditions and the disclaimer below. 427778Sgblack@eecs.umich.edu * 438839Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 443101Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 453101Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 463101Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 473101Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 483101Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 493101Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 503101Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 513101Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 523101Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 533101Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 543101Sstever@eecs.umich.edu * 553101Sstever@eecs.umich.edu * Authors: Gabe Black 563101Sstever@eecs.umich.edu */ 573101Sstever@eecs.umich.edu 583101Sstever@eecs.umich.edu#include "arch/x86/emulenv.hh" 593101Sstever@eecs.umich.edu#include "base/misc.hh" 603101Sstever@eecs.umich.edu 613101Sstever@eecs.umich.eduusing namespace X86ISA; 623885Sbinkertn@umich.edu 633885Sbinkertn@umich.eduvoid EmulEnv::doModRM(const ExtMachInst & machInst) 644762Snate@binkert.org{ 653885Sbinkertn@umich.edu assert(machInst.modRM.mod != 3); 663885Sbinkertn@umich.edu //Use the SIB byte for addressing if the modrm byte calls for it. 677528Ssteve.reinhardt@amd.com if (machInst.modRM.rm == 4 && machInst.addrSize != 2) { 683885Sbinkertn@umich.edu scale = 1 << machInst.sib.scale; 694380Sbinkertn@umich.edu index = machInst.sib.index | (machInst.rex.x << 3); 704167Sbinkertn@umich.edu base = machInst.sib.base | (machInst.rex.b << 3); 713102Sstever@eecs.umich.edu //In this special case, we don't use a base. The displacement also 723101Sstever@eecs.umich.edu //changes, but that's managed by the predecoder. 734762Snate@binkert.org if (machInst.sib.base == INTREG_RBP && machInst.modRM.mod == 0) 744762Snate@binkert.org base = NUM_INTREGS; 754762Snate@binkert.org //In -this- special case, we don't use an index. 764762Snate@binkert.org if (index == INTREG_RSP) 774762Snate@binkert.org index = NUM_INTREGS; 784762Snate@binkert.org } else { 794762Snate@binkert.org if (machInst.addrSize == 2) { 804762Snate@binkert.org warn("I'm not really using 16 bit MODRM like I'm supposed to!\n"); 814762Snate@binkert.org } else { 825033Smilesck@eecs.umich.edu scale = 0; 835033Smilesck@eecs.umich.edu base = machInst.modRM.rm | (machInst.rex.b << 3); 845033Smilesck@eecs.umich.edu if (machInst.modRM.mod == 0 && machInst.modRM.rm == 5) { 855033Smilesck@eecs.umich.edu //Since we need to use a different encoding of this 865033Smilesck@eecs.umich.edu //instruction anyway, just ignore the base in those cases 875033Smilesck@eecs.umich.edu base = NUM_INTREGS; 885033Smilesck@eecs.umich.edu } 895033Smilesck@eecs.umich.edu } 905033Smilesck@eecs.umich.edu } 915033Smilesck@eecs.umich.edu} 923101Sstever@eecs.umich.edu 933101Sstever@eecs.umich.edu