microregop.cc revision 5077:4c25f95fa600
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2007 The Hewlett-Packard Development Company 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use of this software in source and binary forms, 612855Sgabeblack@google.com * with or without modification, are permitted provided that the 712855Sgabeblack@google.com * following conditions are met: 812855Sgabeblack@google.com * 912855Sgabeblack@google.com * The software must be used only for Non-Commercial Use which means any 1012855Sgabeblack@google.com * use which is NOT directed to receiving any direct monetary 1112855Sgabeblack@google.com * compensation for, or commercial advantage from such use. Illustrative 1212855Sgabeblack@google.com * examples of non-commercial use are academic research, personal study, 1312855Sgabeblack@google.com * teaching, education and corporate research & development. 1412855Sgabeblack@google.com * Illustrative examples of commercial use are distributing products for 1512855Sgabeblack@google.com * commercial advantage and providing services using the software for 1612855Sgabeblack@google.com * commercial advantage. 1712855Sgabeblack@google.com * 1812855Sgabeblack@google.com * If you wish to use this software or functionality therein that may be 1912855Sgabeblack@google.com * covered by patents for commercial use, please contact: 2012855Sgabeblack@google.com * Director of Intellectual Property Licensing 2112855Sgabeblack@google.com * Office of Strategy and Technology 2212855Sgabeblack@google.com * Hewlett-Packard Company 2312855Sgabeblack@google.com * 1501 Page Mill Road 2412855Sgabeblack@google.com * Palo Alto, California 94304 2512855Sgabeblack@google.com * 2612855Sgabeblack@google.com * Redistributions of source code must retain the above copyright notice, 2712855Sgabeblack@google.com * this list of conditions and the following disclaimer. Redistributions 2812855Sgabeblack@google.com * in binary form must reproduce the above copyright notice, this list of 2912855Sgabeblack@google.com * conditions and the following disclaimer in the documentation and/or 3012855Sgabeblack@google.com * other materials provided with the distribution. Neither the name of 3112855Sgabeblack@google.com * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 3212855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 3312855Sgabeblack@google.com * this software without specific prior written permission. No right of 3412855Sgabeblack@google.com * sublicense is granted herewith. Derivatives of the software and 3512855Sgabeblack@google.com * output created using the software may be prepared, but only for 3612855Sgabeblack@google.com * Non-Commercial Uses. Derivatives of the software may be shared with 3712855Sgabeblack@google.com * others provided: (i) the others agree to abide by the list of 3812855Sgabeblack@google.com * conditions herein which includes the Non-Commercial Use restrictions; 3912855Sgabeblack@google.com * and (ii) such Derivatives of the software include the above copyright 4012855Sgabeblack@google.com * notice to acknowledge the contribution from this software where 4112855Sgabeblack@google.com * applicable, this list of conditions and the disclaimer below. 4212855Sgabeblack@google.com * 4312855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4412855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4512855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4612855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4712855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4812855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4912855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 5012855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 5112855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 5212855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 5312855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5412855Sgabeblack@google.com * 5512855Sgabeblack@google.com * Authors: Gabe Black 5612855Sgabeblack@google.com */ 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com#include "arch/x86/insts/microregop.hh" 5912855Sgabeblack@google.com#include "arch/x86/miscregs.hh" 6012855Sgabeblack@google.com#include "base/condcodes.hh" 6112855Sgabeblack@google.com#include <string> 6212855Sgabeblack@google.com 6312855Sgabeblack@google.comnamespace X86ISA 6412855Sgabeblack@google.com{ 6512855Sgabeblack@google.com uint64_t RegOpBase::genFlags(uint64_t oldFlags, uint64_t flagMask, 6612855Sgabeblack@google.com uint64_t _dest, uint64_t _src1, uint64_t _src2, 6712855Sgabeblack@google.com bool subtract) const 6812855Sgabeblack@google.com { 6912855Sgabeblack@google.com DPRINTF(Sparc, "flagMask = %#x\n", flagMask); 7012855Sgabeblack@google.com uint64_t flags = oldFlags & ~flagMask; 7112855Sgabeblack@google.com if(flagMask & (ECFBit | CFBit)) 7212855Sgabeblack@google.com { 7312855Sgabeblack@google.com if(findCarry(dataSize*8, _dest, _src1, _src2)) 7412855Sgabeblack@google.com flags |= (flagMask & (ECFBit | CFBit)); 7512855Sgabeblack@google.com if(subtract) 7612855Sgabeblack@google.com flags ^= (flagMask & (ECFBit | CFBit)); 7712855Sgabeblack@google.com } 7812855Sgabeblack@google.com if(flagMask & PFBit && findParity(dataSize*8, _dest)) 7912855Sgabeblack@google.com flags |= PFBit; 8012855Sgabeblack@google.com if(flagMask & AFBit) 8112855Sgabeblack@google.com { 8212855Sgabeblack@google.com if(findCarry(4, _dest, _src1, _src2)) 83 flags |= AFBit; 84 if(subtract) 85 flags ^= AFBit; 86 } 87 if(flagMask & (EZFBit | ZFBit) && findZero(dataSize*8, _dest)) 88 flags |= (flagMask & (EZFBit | ZFBit)); 89 if(flagMask & SFBit && findNegative(dataSize*8, _dest)) 90 flags |= SFBit; 91 if(flagMask & OFBit && findOverflow(dataSize*8, _dest, _src1, _src2)) 92 flags |= OFBit; 93 return flags; 94 } 95 96 bool RegOpBase::checkCondition(uint64_t flags) const 97 { 98 CCFlagBits ccflags = flags; 99 switch(ext) 100 { 101 case ConditionTests::True: 102 return true; 103 case ConditionTests::ECF: 104 return ccflags.ECF; 105 case ConditionTests::EZF: 106 return ccflags.EZF; 107 case ConditionTests::SZnZF: 108 return !(!ccflags.EZF & ccflags.ZF); 109 case ConditionTests::MSTRZ: 110 panic("This condition is not implemented!"); 111 case ConditionTests::STRZ: 112 panic("This condition is not implemented!"); 113 case ConditionTests::MSTRC: 114 panic("This condition is not implemented!"); 115 case ConditionTests::STRZnEZF: 116 return !ccflags.EZF & ccflags.ZF; 117 //And no interrupts or debug traps are waiting 118 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