utility.hh revision 7087:fb8d5786ff30
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 2007 The Hewlett-Packard Development Company 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * The license below extends only to copyright in the software and shall 66145Snate@binkert.org * not be construed as granting a license to any other intellectual 76145Snate@binkert.org * property including but not limited to intellectual property relating 86145Snate@binkert.org * to a hardware implementation of the functionality of the software 96145Snate@binkert.org * licensed hereunder. You may use the software subject to the license 106145Snate@binkert.org * terms below provided that you ensure that this notice is replicated 116145Snate@binkert.org * unmodified and in its entirety in all distributions of the software, 126145Snate@binkert.org * modified or unmodified, in source code or in binary form. 136145Snate@binkert.org * 146145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 156145Snate@binkert.org * modification, are permitted provided that the following conditions are 166145Snate@binkert.org * met: redistributions of source code must retain the above copyright 176145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 186145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 196145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 206145Snate@binkert.org * documentation and/or other materials provided with the distribution; 216145Snate@binkert.org * neither the name of the copyright holders nor the names of its 226145Snate@binkert.org * contributors may be used to endorse or promote products derived from 236145Snate@binkert.org * this software without specific prior written permission. 246145Snate@binkert.org * 256145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 266145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 276145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 286145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 296145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 306145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 316145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 326145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 336145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 346145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 356145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 366145Snate@binkert.org * 376145Snate@binkert.org * Authors: Gabe Black 386145Snate@binkert.org */ 396145Snate@binkert.org 406145Snate@binkert.org#ifndef __ARCH_X86_UTILITY_HH__ 416145Snate@binkert.org#define __ARCH_X86_UTILITY_HH__ 426145Snate@binkert.org 436145Snate@binkert.org#include "arch/x86/miscregs.hh" 446145Snate@binkert.org#include "arch/x86/types.hh" 456145Snate@binkert.org#include "base/hashmap.hh" 466145Snate@binkert.org#include "base/misc.hh" 476145Snate@binkert.org#include "base/types.hh" 486145Snate@binkert.org#include "config/full_system.hh" 496145Snate@binkert.org#include "cpu/thread_context.hh" 506145Snate@binkert.org 516145Snate@binkert.orgclass ThreadContext; 526145Snate@binkert.org 536145Snate@binkert.orgnamespace __hash_namespace { 546145Snate@binkert.org template<> 556145Snate@binkert.org struct hash<X86ISA::ExtMachInst> { 566145Snate@binkert.org size_t operator()(const X86ISA::ExtMachInst &emi) const { 576145Snate@binkert.org return (((uint64_t)emi.legacy << 56) | 586145Snate@binkert.org ((uint64_t)emi.rex << 48) | 596145Snate@binkert.org ((uint64_t)emi.modRM << 40) | 606145Snate@binkert.org ((uint64_t)emi.sib << 32) | 616145Snate@binkert.org ((uint64_t)emi.opcode.num << 24) | 626145Snate@binkert.org ((uint64_t)emi.opcode.prefixA << 16) | 636145Snate@binkert.org ((uint64_t)emi.opcode.prefixB << 8) | 646145Snate@binkert.org ((uint64_t)emi.opcode.op)) ^ 656145Snate@binkert.org emi.immediate ^ emi.displacement ^ 666145Snate@binkert.org emi.mode ^ 676145Snate@binkert.org emi.opSize ^ emi.addrSize ^ 686145Snate@binkert.org emi.stackSize ^ emi.dispSize; 696145Snate@binkert.org }; 706145Snate@binkert.org }; 716145Snate@binkert.org} 726145Snate@binkert.org 736145Snate@binkert.orgnamespace X86ISA 746145Snate@binkert.org{ 756145Snate@binkert.org uint64_t getArgument(ThreadContext *tc, int number, bool fp); 766145Snate@binkert.org 776145Snate@binkert.org static inline bool 786145Snate@binkert.org inUserMode(ThreadContext *tc) 796145Snate@binkert.org { 806145Snate@binkert.org#if FULL_SYSTEM 816145Snate@binkert.org HandyM5Reg m5reg = tc->readMiscRegNoEffect(MISCREG_M5_REG); 826145Snate@binkert.org return m5reg.cpl == 3; 836145Snate@binkert.org#else 846145Snate@binkert.org return true; 856145Snate@binkert.org#endif 866145Snate@binkert.org } 876145Snate@binkert.org 886145Snate@binkert.org inline bool isCallerSaveIntegerRegister(unsigned int reg) { 896145Snate@binkert.org panic("register classification not implemented"); 906145Snate@binkert.org return false; 916145Snate@binkert.org } 92 93 inline bool isCalleeSaveIntegerRegister(unsigned int reg) { 94 panic("register classification not implemented"); 95 return false; 96 } 97 98 inline bool isCallerSaveFloatRegister(unsigned int reg) { 99 panic("register classification not implemented"); 100 return false; 101 } 102 103 inline bool isCalleeSaveFloatRegister(unsigned int reg) { 104 panic("register classification not implemented"); 105 return false; 106 } 107 108 // Instruction address compression hooks 109 inline Addr realPCToFetchPC(const Addr &addr) 110 { 111 return addr; 112 } 113 114 inline Addr fetchPCToRealPC(const Addr &addr) 115 { 116 return addr; 117 } 118 119 // the size of "fetched" instructions (not necessarily the size 120 // of real instructions for PISA) 121 inline size_t fetchInstSize() 122 { 123 return sizeof(MachInst); 124 } 125 126 /** 127 * Function to insure ISA semantics about 0 registers. 128 * @param tc The thread context. 129 */ 130 template <class TC> 131 void zeroRegisters(TC *tc); 132 133#if FULL_SYSTEM 134 135 void initCPU(ThreadContext *tc, int cpuId); 136 137#endif 138 139 void startupCPU(ThreadContext *tc, int cpuId); 140 141 void copyRegs(ThreadContext *src, ThreadContext *dest); 142 143 void copyMiscRegs(ThreadContext *src, ThreadContext *dest); 144}; 145 146#endif // __ARCH_X86_UTILITY_HH__ 147