static_inst.cc revision 4679:0b39fa8f5eb8
1/* 2 * Copyright (c) 2007 The Hewlett-Packard Development Company 3 * All rights reserved. 4 * 5 * Redistribution and use of this software in source and binary forms, 6 * with or without modification, are permitted provided that the 7 * following conditions are met: 8 * 9 * The software must be used only for Non-Commercial Use which means any 10 * use which is NOT directed to receiving any direct monetary 11 * compensation for, or commercial advantage from such use. Illustrative 12 * examples of non-commercial use are academic research, personal study, 13 * teaching, education and corporate research & development. 14 * Illustrative examples of commercial use are distributing products for 15 * commercial advantage and providing services using the software for 16 * commercial advantage. 17 * 18 * If you wish to use this software or functionality therein that may be 19 * covered by patents for commercial use, please contact: 20 * Director of Intellectual Property Licensing 21 * Office of Strategy and Technology 22 * Hewlett-Packard Company 23 * 1501 Page Mill Road 24 * Palo Alto, California 94304 25 * 26 * Redistributions of source code must retain the above copyright notice, 27 * this list of conditions and the following disclaimer. Redistributions 28 * in binary form must reproduce the above copyright notice, this list of 29 * conditions and the following disclaimer in the documentation and/or 30 * other materials provided with the distribution. Neither the name of 31 * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 32 * contributors may be used to endorse or promote products derived from 33 * this software without specific prior written permission. No right of 34 * sublicense is granted herewith. Derivatives of the software and 35 * output created using the software may be prepared, but only for 36 * Non-Commercial Uses. Derivatives of the software may be shared with 37 * others provided: (i) the others agree to abide by the list of 38 * conditions herein which includes the Non-Commercial Use restrictions; 39 * and (ii) such Derivatives of the software include the above copyright 40 * notice to acknowledge the contribution from this software where 41 * applicable, this list of conditions and the disclaimer below. 42 * 43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 * 55 * Authors: Gabe Black 56 */ 57 58#include "arch/x86/insts/static_inst.hh" 59 60namespace X86ISA 61{ 62 void X86StaticInst::printMnemonic(std::ostream &os, 63 const char * mnemonic) const 64 { 65 ccprintf(os, "\t%s ", mnemonic); 66 } 67 68 void X86StaticInst::printMnemonic(std::ostream &os, 69 const char * instMnemonic, const char * mnemonic) const 70 { 71 ccprintf(os, "\t%s : %s ", instMnemonic, mnemonic); 72 } 73 74 void X86StaticInst::printSegment(std::ostream &os, int segment) const 75 { 76 switch (segment) 77 { 78 case 0: 79 ccprintf(os, "ES"); 80 break; 81 case 1: 82 ccprintf(os, "CS"); 83 break; 84 case 2: 85 ccprintf(os, "SS"); 86 break; 87 case 3: 88 ccprintf(os, "DS"); 89 break; 90 case 4: 91 ccprintf(os, "FS"); 92 break; 93 case 5: 94 ccprintf(os, "GS"); 95 break; 96 default: 97 panic("Unrecognized segment %d\n", segment); 98 } 99 } 100 101 void 102 X86StaticInst::printSrcReg(std::ostream &os, int reg) const 103 { 104 if(_numSrcRegs > reg) 105 printReg(os, _srcRegIdx[reg]); 106 } 107 108 void 109 X86StaticInst::printDestReg(std::ostream &os, int reg) const 110 { 111 if(_numDestRegs > reg) 112 printReg(os, _destRegIdx[reg]); 113 } 114 115 void 116 X86StaticInst::printReg(std::ostream &os, int reg) const 117 { 118 if (reg < FP_Base_DepTag) { 119 //FIXME These should print differently depending on the 120 //mode etc, but for now this will get the point across 121 switch (reg) { 122 case INTREG_RAX: 123 ccprintf(os, "rax"); 124 break; 125 case INTREG_RBX: 126 ccprintf(os, "rbx"); 127 break; 128 case INTREG_RCX: 129 ccprintf(os, "rcx"); 130 break; 131 case INTREG_RDX: 132 ccprintf(os, "rdx"); 133 break; 134 case INTREG_RSP: 135 ccprintf(os, "rsp"); 136 break; 137 case INTREG_RBP: 138 ccprintf(os, "rbp"); 139 break; 140 case INTREG_RSI: 141 ccprintf(os, "rsi"); 142 break; 143 case INTREG_RDI: 144 ccprintf(os, "rdi"); 145 break; 146 case INTREG_R8W: 147 ccprintf(os, "r8"); 148 break; 149 case INTREG_R9W: 150 ccprintf(os, "r9"); 151 break; 152 case INTREG_R10W: 153 ccprintf(os, "r10"); 154 break; 155 case INTREG_R11W: 156 ccprintf(os, "r11"); 157 break; 158 case INTREG_R12W: 159 ccprintf(os, "r12"); 160 break; 161 case INTREG_R13W: 162 ccprintf(os, "r13"); 163 break; 164 case INTREG_R14W: 165 ccprintf(os, "r14"); 166 break; 167 case INTREG_R15W: 168 ccprintf(os, "r15"); 169 break; 170 default: 171 ccprintf(os, "t%d", reg - NUM_INTREGS); 172 } 173 } else if (reg < Ctrl_Base_DepTag) { 174 ccprintf(os, "%%f%d", reg - FP_Base_DepTag); 175 } else { 176 switch (reg - Ctrl_Base_DepTag) { 177 default: 178 ccprintf(os, "%%ctrl%d", reg - Ctrl_Base_DepTag); 179 } 180 } 181 } 182 183 std::string X86StaticInst::generateDisassembly(Addr pc, 184 const SymbolTable *symtab) const 185 { 186 std::stringstream ss; 187 188 printMnemonic(ss, mnemonic); 189 190 return ss.str(); 191 } 192} 193