emulenv.cc revision 4604:3ffdd00e6c02
14486Sbinkertn@umich.edu/*
27897Shestness@cs.utexas.edu * Copyright (c) 2007 The Hewlett-Packard Development Company
34486Sbinkertn@umich.edu * All rights reserved.
44486Sbinkertn@umich.edu *
54486Sbinkertn@umich.edu * Redistribution and use of this software in source and binary forms,
64486Sbinkertn@umich.edu * with or without modification, are permitted provided that the
74486Sbinkertn@umich.edu * following conditions are met:
84486Sbinkertn@umich.edu *
94486Sbinkertn@umich.edu * The software must be used only for Non-Commercial Use which means any
104486Sbinkertn@umich.edu * use which is NOT directed to receiving any direct monetary
114486Sbinkertn@umich.edu * compensation for, or commercial advantage from such use.  Illustrative
124486Sbinkertn@umich.edu * examples of non-commercial use are academic research, personal study,
134486Sbinkertn@umich.edu * teaching, education and corporate research & development.
144486Sbinkertn@umich.edu * Illustrative examples of commercial use are distributing products for
154486Sbinkertn@umich.edu * commercial advantage and providing services using the software for
164486Sbinkertn@umich.edu * commercial advantage.
174486Sbinkertn@umich.edu *
184486Sbinkertn@umich.edu * If you wish to use this software or functionality therein that may be
194486Sbinkertn@umich.edu * covered by patents for commercial use, please contact:
204486Sbinkertn@umich.edu *     Director of Intellectual Property Licensing
214486Sbinkertn@umich.edu *     Office of Strategy and Technology
224486Sbinkertn@umich.edu *     Hewlett-Packard Company
234486Sbinkertn@umich.edu *     1501 Page Mill Road
244486Sbinkertn@umich.edu *     Palo Alto, California  94304
254486Sbinkertn@umich.edu *
264486Sbinkertn@umich.edu * Redistributions of source code must retain the above copyright notice,
274486Sbinkertn@umich.edu * this list of conditions and the following disclaimer.  Redistributions
284486Sbinkertn@umich.edu * in binary form must reproduce the above copyright notice, this list of
297897Shestness@cs.utexas.edu * conditions and the following disclaimer in the documentation and/or
304486Sbinkertn@umich.edu * other materials provided with the distribution.  Neither the name of
313102SN/A * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
326654Snate@binkert.org * contributors may be used to endorse or promote products derived from
333102SN/A * this software without specific prior written permission.  No right of
343102SN/A * sublicense is granted herewith.  Derivatives of the software and
356654Snate@binkert.org * output created using the software may be prepared, but only for
363584SN/A * Non-Commercial Uses.  Derivatives of the software may be shared with
372212SN/A * others provided: (i) the others agree to abide by the list of
382902SN/A * conditions herein which includes the Non-Commercial Use restrictions;
392902SN/A * and (ii) such Derivatives of the software include the above copyright
401711SN/A * notice to acknowledge the contribution from this software where
411783SN/A * applicable, this list of conditions and the disclaimer below.
427673Snate@binkert.org *
437673Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
447673Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
457673Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
464859Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
475820Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
482902SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
497897Shestness@cs.utexas.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
507914SBrad.Beckmann@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
517914SBrad.Beckmann@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
527914SBrad.Beckmann@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
537914SBrad.Beckmann@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
547914SBrad.Beckmann@amd.com *
557914SBrad.Beckmann@amd.com * Authors: Gabe Black
567914SBrad.Beckmann@amd.com */
577914SBrad.Beckmann@amd.com
587914SBrad.Beckmann@amd.com#include "arch/x86/emulenv.hh"
597914SBrad.Beckmann@amd.com#include "base/misc.hh"
607914SBrad.Beckmann@amd.com
617914SBrad.Beckmann@amd.comusing namespace X86ISA;
627914SBrad.Beckmann@amd.com
637914SBrad.Beckmann@amd.comvoid EmulEnv::doModRM(const ExtMachInst & machInst)
646654Snate@binkert.org{
654597Sbinkertn@umich.edu    assert(machInst.modRM.mod != 3);
662424SN/A    //Use the SIB byte for addressing if the modrm byte calls for it.
672424SN/A    if (machInst.modRM.rm == 4 && machInst.addrSize != 2) {
682424SN/A        scale = 1 << machInst.sib.scale;
692570SN/A        index = machInst.sib.index;
703812SN/A        base = machInst.sib.base;
712424SN/A        //In this special case, we don't use a base. The displacement also
723125SN/A        //changes, but that's managed by the predecoder.
737580SAli.Saidi@arm.com        if (machInst.sib.base == INTREG_RBP && machInst.modRM.mod == 0)
747580SAli.Saidi@arm.com            base = NUM_INTREGS;
75        //In -this- special case, we don't use an index.
76        if (machInst.sib.index == INTREG_RSP)
77            index = NUM_INTREGS;
78    } else {
79        if (machInst.addrSize == 2) {
80            warn("I'm not really using 16 bit MODRM like I'm supposed to!\n");
81        } else {
82            scale = 0;
83            base = machInst.modRM.rm;
84            if (machInst.modRM.mod == 0 && machInst.modRM.rm == 5) {
85                base = NUM_INTREGS;
86                if (machInst.mode.submode == SixtyFourBitMode)
87                    base = NUM_INTREGS+7;
88            }
89        }
90    }
91}
92
93