static_inst.cc revision 4679:0b39fa8f5eb8
1955SN/A/* 2955SN/A * Copyright (c) 2007 The Hewlett-Packard Development Company 31762SN/A * All rights reserved. 4955SN/A * 5955SN/A * Redistribution and use of this software in source and binary forms, 6955SN/A * with or without modification, are permitted provided that the 7955SN/A * following conditions are met: 8955SN/A * 9955SN/A * The software must be used only for Non-Commercial Use which means any 10955SN/A * use which is NOT directed to receiving any direct monetary 11955SN/A * compensation for, or commercial advantage from such use. Illustrative 12955SN/A * examples of non-commercial use are academic research, personal study, 13955SN/A * teaching, education and corporate research & development. 14955SN/A * Illustrative examples of commercial use are distributing products for 15955SN/A * commercial advantage and providing services using the software for 16955SN/A * commercial advantage. 17955SN/A * 18955SN/A * If you wish to use this software or functionality therein that may be 19955SN/A * covered by patents for commercial use, please contact: 20955SN/A * Director of Intellectual Property Licensing 21955SN/A * Office of Strategy and Technology 22955SN/A * Hewlett-Packard Company 23955SN/A * 1501 Page Mill Road 24955SN/A * Palo Alto, California 94304 25955SN/A * 26955SN/A * Redistributions of source code must retain the above copyright notice, 27955SN/A * this list of conditions and the following disclaimer. Redistributions 282665Ssaidi@eecs.umich.edu * in binary form must reproduce the above copyright notice, this list of 292665Ssaidi@eecs.umich.edu * conditions and the following disclaimer in the documentation and/or 30955SN/A * other materials provided with the distribution. Neither the name of 31955SN/A * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 32955SN/A * contributors may be used to endorse or promote products derived from 33955SN/A * this software without specific prior written permission. No right of 34955SN/A * sublicense is granted herewith. Derivatives of the software and 352632Sstever@eecs.umich.edu * output created using the software may be prepared, but only for 362632Sstever@eecs.umich.edu * Non-Commercial Uses. Derivatives of the software may be shared with 372632Sstever@eecs.umich.edu * others provided: (i) the others agree to abide by the list of 382632Sstever@eecs.umich.edu * conditions herein which includes the Non-Commercial Use restrictions; 39955SN/A * and (ii) such Derivatives of the software include the above copyright 402632Sstever@eecs.umich.edu * notice to acknowledge the contribution from this software where 412632Sstever@eecs.umich.edu * applicable, this list of conditions and the disclaimer below. 422761Sstever@eecs.umich.edu * 432632Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 442632Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 452632Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 462761Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 472761Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 482761Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 492632Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 502632Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 512761Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 522761Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 532761Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 542761Sstever@eecs.umich.edu * 552761Sstever@eecs.umich.edu * Authors: Gabe Black 562632Sstever@eecs.umich.edu */ 572632Sstever@eecs.umich.edu 582632Sstever@eecs.umich.edu#include "arch/x86/insts/static_inst.hh" 592632Sstever@eecs.umich.edu 602632Sstever@eecs.umich.edunamespace X86ISA 612632Sstever@eecs.umich.edu{ 622632Sstever@eecs.umich.edu void X86StaticInst::printMnemonic(std::ostream &os, 63955SN/A const char * mnemonic) const 64955SN/A { 65955SN/A ccprintf(os, "\t%s ", mnemonic); 66955SN/A } 67955SN/A 685396Ssaidi@eecs.umich.edu void X86StaticInst::printMnemonic(std::ostream &os, 694202Sbinkertn@umich.edu const char * instMnemonic, const char * mnemonic) const 705342Sstever@gmail.com { 71955SN/A ccprintf(os, "\t%s : %s ", instMnemonic, mnemonic); 725273Sstever@gmail.com } 735273Sstever@gmail.com 742656Sstever@eecs.umich.edu void X86StaticInst::printSegment(std::ostream &os, int segment) const 752656Sstever@eecs.umich.edu { 762656Sstever@eecs.umich.edu switch (segment) 772656Sstever@eecs.umich.edu { 782656Sstever@eecs.umich.edu case 0: 792656Sstever@eecs.umich.edu ccprintf(os, "ES"); 802656Sstever@eecs.umich.edu break; 812653Sstever@eecs.umich.edu case 1: 825227Ssaidi@eecs.umich.edu ccprintf(os, "CS"); 835227Ssaidi@eecs.umich.edu break; 845227Ssaidi@eecs.umich.edu case 2: 855227Ssaidi@eecs.umich.edu ccprintf(os, "SS"); 865396Ssaidi@eecs.umich.edu break; 875396Ssaidi@eecs.umich.edu case 3: 885396Ssaidi@eecs.umich.edu ccprintf(os, "DS"); 895396Ssaidi@eecs.umich.edu break; 905396Ssaidi@eecs.umich.edu case 4: 915396Ssaidi@eecs.umich.edu ccprintf(os, "FS"); 925396Ssaidi@eecs.umich.edu break; 935396Ssaidi@eecs.umich.edu case 5: 945396Ssaidi@eecs.umich.edu ccprintf(os, "GS"); 955396Ssaidi@eecs.umich.edu break; 965396Ssaidi@eecs.umich.edu default: 975396Ssaidi@eecs.umich.edu panic("Unrecognized segment %d\n", segment); 985396Ssaidi@eecs.umich.edu } 995396Ssaidi@eecs.umich.edu } 1005396Ssaidi@eecs.umich.edu 1015396Ssaidi@eecs.umich.edu void 1025396Ssaidi@eecs.umich.edu X86StaticInst::printSrcReg(std::ostream &os, int reg) const 1035396Ssaidi@eecs.umich.edu { 1045396Ssaidi@eecs.umich.edu if(_numSrcRegs > reg) 1055396Ssaidi@eecs.umich.edu printReg(os, _srcRegIdx[reg]); 1065396Ssaidi@eecs.umich.edu } 1075396Ssaidi@eecs.umich.edu 1085396Ssaidi@eecs.umich.edu void 1095396Ssaidi@eecs.umich.edu X86StaticInst::printDestReg(std::ostream &os, int reg) const 1105396Ssaidi@eecs.umich.edu { 1115396Ssaidi@eecs.umich.edu if(_numDestRegs > reg) 1125396Ssaidi@eecs.umich.edu printReg(os, _destRegIdx[reg]); 1135396Ssaidi@eecs.umich.edu } 1145396Ssaidi@eecs.umich.edu 1155396Ssaidi@eecs.umich.edu void 1165396Ssaidi@eecs.umich.edu X86StaticInst::printReg(std::ostream &os, int reg) const 1175396Ssaidi@eecs.umich.edu { 1185396Ssaidi@eecs.umich.edu if (reg < FP_Base_DepTag) { 1195396Ssaidi@eecs.umich.edu //FIXME These should print differently depending on the 1205396Ssaidi@eecs.umich.edu //mode etc, but for now this will get the point across 1215396Ssaidi@eecs.umich.edu switch (reg) { 1225396Ssaidi@eecs.umich.edu case INTREG_RAX: 1235396Ssaidi@eecs.umich.edu ccprintf(os, "rax"); 1245396Ssaidi@eecs.umich.edu break; 1255396Ssaidi@eecs.umich.edu case INTREG_RBX: 1265396Ssaidi@eecs.umich.edu ccprintf(os, "rbx"); 1275396Ssaidi@eecs.umich.edu break; 1285396Ssaidi@eecs.umich.edu case INTREG_RCX: 1295396Ssaidi@eecs.umich.edu ccprintf(os, "rcx"); 1305396Ssaidi@eecs.umich.edu break; 1315396Ssaidi@eecs.umich.edu case INTREG_RDX: 1325396Ssaidi@eecs.umich.edu ccprintf(os, "rdx"); 1335396Ssaidi@eecs.umich.edu break; 1345396Ssaidi@eecs.umich.edu case INTREG_RSP: 1355396Ssaidi@eecs.umich.edu ccprintf(os, "rsp"); 1365396Ssaidi@eecs.umich.edu break; 1375396Ssaidi@eecs.umich.edu case INTREG_RBP: 1385396Ssaidi@eecs.umich.edu ccprintf(os, "rbp"); 1395396Ssaidi@eecs.umich.edu break; 1405396Ssaidi@eecs.umich.edu case INTREG_RSI: 1415396Ssaidi@eecs.umich.edu ccprintf(os, "rsi"); 1425396Ssaidi@eecs.umich.edu break; 1435396Ssaidi@eecs.umich.edu case INTREG_RDI: 1445396Ssaidi@eecs.umich.edu ccprintf(os, "rdi"); 1455396Ssaidi@eecs.umich.edu break; 1465396Ssaidi@eecs.umich.edu case INTREG_R8W: 1475396Ssaidi@eecs.umich.edu ccprintf(os, "r8"); 1485396Ssaidi@eecs.umich.edu break; 1495396Ssaidi@eecs.umich.edu case INTREG_R9W: 1504781Snate@binkert.org ccprintf(os, "r9"); 1511852SN/A break; 152955SN/A case INTREG_R10W: 153955SN/A ccprintf(os, "r10"); 154955SN/A break; 1553717Sstever@eecs.umich.edu case INTREG_R11W: 1563716Sstever@eecs.umich.edu ccprintf(os, "r11"); 157955SN/A break; 1581533SN/A case INTREG_R12W: 1593716Sstever@eecs.umich.edu ccprintf(os, "r12"); 1601533SN/A break; 1614678Snate@binkert.org case INTREG_R13W: 1624678Snate@binkert.org ccprintf(os, "r13"); 1634678Snate@binkert.org break; 1644678Snate@binkert.org case INTREG_R14W: 1654678Snate@binkert.org ccprintf(os, "r14"); 1664678Snate@binkert.org break; 1674678Snate@binkert.org case INTREG_R15W: 1684678Snate@binkert.org ccprintf(os, "r15"); 1694678Snate@binkert.org break; 1704678Snate@binkert.org default: 1714678Snate@binkert.org ccprintf(os, "t%d", reg - NUM_INTREGS); 1724678Snate@binkert.org } 1734678Snate@binkert.org } else if (reg < Ctrl_Base_DepTag) { 1744678Snate@binkert.org ccprintf(os, "%%f%d", reg - FP_Base_DepTag); 1754678Snate@binkert.org } else { 1764678Snate@binkert.org switch (reg - Ctrl_Base_DepTag) { 1774678Snate@binkert.org default: 1784678Snate@binkert.org ccprintf(os, "%%ctrl%d", reg - Ctrl_Base_DepTag); 1794678Snate@binkert.org } 1804678Snate@binkert.org } 1814678Snate@binkert.org } 1824973Ssaidi@eecs.umich.edu 1834678Snate@binkert.org std::string X86StaticInst::generateDisassembly(Addr pc, 1844678Snate@binkert.org const SymbolTable *symtab) const 1854678Snate@binkert.org { 1864678Snate@binkert.org std::stringstream ss; 1874678Snate@binkert.org 1884678Snate@binkert.org printMnemonic(ss, mnemonic); 189955SN/A 190955SN/A return ss.str(); 1912632Sstever@eecs.umich.edu } 1922632Sstever@eecs.umich.edu} 193955SN/A