microregop.cc revision 4953:1181cf10e11e
12SN/A/* 29952Sdam.sunwoo@arm.com * Copyright (c) 2007 The Hewlett-Packard Development Company 39952Sdam.sunwoo@arm.com * All rights reserved. 49952Sdam.sunwoo@arm.com * 59952Sdam.sunwoo@arm.com * Redistribution and use of this software in source and binary forms, 69952Sdam.sunwoo@arm.com * with or without modification, are permitted provided that the 79952Sdam.sunwoo@arm.com * following conditions are met: 89952Sdam.sunwoo@arm.com * 99952Sdam.sunwoo@arm.com * The software must be used only for Non-Commercial Use which means any 109952Sdam.sunwoo@arm.com * use which is NOT directed to receiving any direct monetary 119952Sdam.sunwoo@arm.com * compensation for, or commercial advantage from such use. Illustrative 129952Sdam.sunwoo@arm.com * examples of non-commercial use are academic research, personal study, 139952Sdam.sunwoo@arm.com * teaching, education and corporate research & development. 141762SN/A * Illustrative examples of commercial use are distributing products for 159983Sstever@gmail.com * commercial advantage and providing services using the software for 169983Sstever@gmail.com * commercial advantage. 172SN/A * 182SN/A * If you wish to use this software or functionality therein that may be 192SN/A * covered by patents for commercial use, please contact: 202SN/A * Director of Intellectual Property Licensing 212SN/A * Office of Strategy and Technology 222SN/A * Hewlett-Packard Company 232SN/A * 1501 Page Mill Road 242SN/A * Palo Alto, California 94304 252SN/A * 262SN/A * Redistributions of source code must retain the above copyright notice, 272SN/A * this list of conditions and the following disclaimer. Redistributions 282SN/A * in binary form must reproduce the above copyright notice, this list of 292SN/A * conditions and the following disclaimer in the documentation and/or 302SN/A * other materials provided with the distribution. Neither the name of 312SN/A * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 322SN/A * contributors may be used to endorse or promote products derived from 332SN/A * this software without specific prior written permission. No right of 342SN/A * sublicense is granted herewith. Derivatives of the software and 352SN/A * output created using the software may be prepared, but only for 362SN/A * Non-Commercial Uses. Derivatives of the software may be shared with 372SN/A * others provided: (i) the others agree to abide by the list of 382SN/A * conditions herein which includes the Non-Commercial Use restrictions; 392SN/A * and (ii) such Derivatives of the software include the above copyright 402SN/A * notice to acknowledge the contribution from this software where 412665Ssaidi@eecs.umich.edu * applicable, this list of conditions and the disclaimer below. 422665Ssaidi@eecs.umich.edu * 432SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 442SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 451798SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 461798SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 472SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 489983Sstever@gmail.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 499952Sdam.sunwoo@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 502SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 512SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 522SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 532SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 549983Sstever@gmail.com * 552SN/A * Authors: Gabe Black 565606Snate@binkert.org */ 572SN/A 582SN/A#include "arch/x86/insts/microregop.hh" 592SN/A#include "arch/x86/miscregs.hh" 603144Shsul@eecs.umich.edu#include "base/condcodes.hh" 612SN/A#include <string> 622SN/A 639983Sstever@gmail.comnamespace X86ISA 6411070Sandreas.sandberg@arm.com{ 6513694Sgabeblack@google.com uint64_t RegOpBase::genFlags(uint64_t oldFlags, uint64_t flagMask, 662SN/A uint64_t _dest, uint64_t _src1, uint64_t _src2, 679983Sstever@gmail.com bool subtract) const 6811294Sandreas.hansson@arm.com { 699983Sstever@gmail.com DPRINTF(Sparc, "flagMask = %#x\n", flagMask); 709983Sstever@gmail.com uint64_t flags = oldFlags & ~flagMask; 719983Sstever@gmail.com if(flagMask & CFBit) 729983Sstever@gmail.com if(findCarry(dataSize*8, _dest, _src1, _src2)) 739983Sstever@gmail.com flags |= CFBit; 749983Sstever@gmail.com if(subtract) 759983Sstever@gmail.com flags ^= CFBit; 769983Sstever@gmail.com if(flagMask & PFBit && findParity(dataSize*8, _dest)) 779983Sstever@gmail.com flags |= PFBit; 789983Sstever@gmail.com if(flagMask & ECFBit && findCarry(dataSize*8, _dest, _src1, _src2)) 799983Sstever@gmail.com flags |= ECFBit; 809983Sstever@gmail.com if(flagMask & AFBit) 819983Sstever@gmail.com if(findCarry(4, _dest, _src1, _src2)) 829983Sstever@gmail.com flags |= AFBit; 839983Sstever@gmail.com if(subtract) 849983Sstever@gmail.com flags ^= AFBit; 8511070Sandreas.sandberg@arm.com if(flagMask & EZFBit && findZero(dataSize*8, _dest)) 869983Sstever@gmail.com flags |= EZFBit; 879983Sstever@gmail.com if(flagMask & ZFBit && findZero(dataSize*8, _dest)) 8811294Sandreas.hansson@arm.com flags |= ZFBit; 892SN/A if(flagMask & SFBit && findNegative(dataSize*8, _dest)) 9011169Sandreas.hansson@arm.com flags |= SFBit; 912SN/A if(flagMask & OFBit && findOverflow(dataSize*8, _dest, _src1, _src2)) 9211169Sandreas.hansson@arm.com flags |= OFBit; 939952Sdam.sunwoo@arm.com return flags; 9411168Sandreas.hansson@arm.com } 9511168Sandreas.hansson@arm.com 962SN/A bool RegOpBase::checkCondition(uint64_t flags) const 972SN/A { 982SN/A CCFlagBits ccflags = flags; 992SN/A switch(ext) 1002SN/A { 1012SN/A case ConditionTests::True: 1022SN/A return true; 1032SN/A case ConditionTests::ECF: 1042SN/A return ccflags.ECF; 1052SN/A case ConditionTests::EZF: 1065543Ssaidi@eecs.umich.edu return ccflags.EZF; 1075543Ssaidi@eecs.umich.edu case ConditionTests::SZnZF: 1082SN/A return !(!ccflags.EZF & ccflags.ZF); 1092SN/A case ConditionTests::MSTRZ: 1105606Snate@binkert.org panic("This condition is not implemented!"); 1112SN/A case ConditionTests::STRZ: 11211169Sandreas.hansson@arm.com panic("This condition is not implemented!"); 1132SN/A case ConditionTests::MSTRC: 11411169Sandreas.hansson@arm.com panic("This condition is not implemented!"); 1152SN/A case ConditionTests::STRZnEZF: 1162SN/A return !ccflags.EZF & ccflags.ZF; 1172SN/A //And no interrupts or debug traps are waiting 1181798SN/A case ConditionTests::OF: 119 return ccflags.OF; 120 case ConditionTests::CF: 121 return ccflags.CF; 122 case ConditionTests::ZF: 123 return ccflags.ZF; 124 case ConditionTests::CvZF: 125 return ccflags.CF | ccflags.ZF; 126 case ConditionTests::SF: 127 return ccflags.SF; 128 case ConditionTests::PF: 129 return ccflags.PF; 130 case ConditionTests::SxOF: 131 return ccflags.SF ^ ccflags.OF; 132 case ConditionTests::SxOvZF: 133 return ccflags.SF ^ ccflags.OF | ccflags.ZF; 134 case ConditionTests::False: 135 return false; 136 case ConditionTests::NotECF: 137 return !ccflags.ECF; 138 case ConditionTests::NotEZF: 139 return !ccflags.EZF; 140 case ConditionTests::NotSZnZF: 141 return !ccflags.EZF & ccflags.ZF; 142 case ConditionTests::NotMSTRZ: 143 panic("This condition is not implemented!"); 144 case ConditionTests::NotSTRZ: 145 panic("This condition is not implemented!"); 146 case ConditionTests::NotMSTRC: 147 panic("This condition is not implemented!"); 148 case ConditionTests::STRnZnEZF: 149 return !ccflags.EZF & !ccflags.ZF; 150 //And no interrupts or debug traps are waiting 151 case ConditionTests::NotOF: 152 return !ccflags.OF; 153 case ConditionTests::NotCF: 154 return !ccflags.CF; 155 case ConditionTests::NotZF: 156 return !ccflags.ZF; 157 case ConditionTests::NotCvZF: 158 return !(ccflags.CF | ccflags.ZF); 159 case ConditionTests::NotSF: 160 return !ccflags.SF; 161 case ConditionTests::NotPF: 162 return !ccflags.PF; 163 case ConditionTests::NotSxOF: 164 return !(ccflags.SF ^ ccflags.OF); 165 case ConditionTests::NotSxOvZF: 166 return !(ccflags.SF ^ ccflags.OF | ccflags.ZF); 167 } 168 panic("Unknown condition: %d\n", ext); 169 return true; 170 } 171 172 std::string RegOp::generateDisassembly(Addr pc, 173 const SymbolTable *symtab) const 174 { 175 std::stringstream response; 176 177 printMnemonic(response, instMnem, mnemonic); 178 printDestReg(response, 0, dataSize); 179 response << ", "; 180 printSrcReg(response, 0, dataSize); 181 response << ", "; 182 printSrcReg(response, 1, dataSize); 183 return response.str(); 184 } 185 186 std::string RegOpImm::generateDisassembly(Addr pc, 187 const SymbolTable *symtab) const 188 { 189 std::stringstream response; 190 191 printMnemonic(response, instMnem, mnemonic); 192 printDestReg(response, 0, dataSize); 193 response << ", "; 194 printSrcReg(response, 0, dataSize); 195 ccprintf(response, ", %#x", imm8); 196 return response.str(); 197 } 198} 199