utility.hh revision 7707
12447SN/A/* 25254Sksewell@umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan 35254Sksewell@umich.edu * Copyright (c) 2007 MIPS Technologies, Inc. 45254Sksewell@umich.edu * All rights reserved. 52447SN/A * 65254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 75254Sksewell@umich.edu * modification, are permitted provided that the following conditions are 85254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 95254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 105254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 115254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 125254Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 135254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 145254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 155254Sksewell@umich.edu * this software without specific prior written permission. 162447SN/A * 175254Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 185254Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 195254Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 205254Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215254Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 225254Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 235254Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 245254Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 255254Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 265254Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 275254Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282632Sstever@eecs.umich.edu * 295254Sksewell@umich.edu * Authors: Nathan Binkert 305254Sksewell@umich.edu * Steve Reinhardt 315254Sksewell@umich.edu * Korey Sewell 322447SN/A */ 332447SN/A 342447SN/A#ifndef __ARCH_MIPS_UTILITY_HH__ 352447SN/A#define __ARCH_MIPS_UTILITY_HH__ 365222Sksewell@umich.edu#include "config/full_system.hh" 372597SN/A#include "arch/mips/types.hh" 384661Sksewell@umich.edu#include "arch/mips/isa_traits.hh" 392597SN/A#include "base/misc.hh" 406216Snate@binkert.org#include "base/types.hh" 412980Sgblack@eecs.umich.edu#include "config/full_system.hh" 424661Sksewell@umich.edu#include "cpu/thread_context.hh" 434661Sksewell@umich.edu 442980Sgblack@eecs.umich.educlass ThreadContext; 452980Sgblack@eecs.umich.edu 462597SN/Anamespace MipsISA { 472597SN/A 487707Sgblack@eecs.umich.eduuint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp); 494826Ssaidi@eecs.umich.edu 506378Sgblack@eecs.umich.edu//////////////////////////////////////////////////////////////////////// 516378Sgblack@eecs.umich.edu// 526378Sgblack@eecs.umich.edu// Floating Point Utility Functions 536378Sgblack@eecs.umich.edu// 546378Sgblack@eecs.umich.eduuint64_t fpConvert(ConvertType cvt_type, double fp_val); 556378Sgblack@eecs.umich.edudouble roundFP(double val, int digits); 566378Sgblack@eecs.umich.edudouble truncFP(double val); 572686Sksewell@umich.edu 586378Sgblack@eecs.umich.edubool getCondCode(uint32_t fcsr, int cc); 596378Sgblack@eecs.umich.eduuint32_t genCCVector(uint32_t fcsr, int num, uint32_t cc_val); 606378Sgblack@eecs.umich.eduuint32_t genInvalidVector(uint32_t fcsr); 612686Sksewell@umich.edu 626378Sgblack@eecs.umich.edubool isNan(void *val_ptr, int size); 636378Sgblack@eecs.umich.edubool isQnan(void *val_ptr, int size); 646378Sgblack@eecs.umich.edubool isSnan(void *val_ptr, int size); 652972Sgblack@eecs.umich.edu 666378Sgblack@eecs.umich.edustatic inline bool 676378Sgblack@eecs.umich.eduinUserMode(ThreadContext *tc) 686378Sgblack@eecs.umich.edu{ 696383Sgblack@eecs.umich.edu MiscReg Stat = tc->readMiscReg(MISCREG_STATUS); 706383Sgblack@eecs.umich.edu MiscReg Dbg = tc->readMiscReg(MISCREG_DEBUG); 715222Sksewell@umich.edu 726378Sgblack@eecs.umich.edu if ((Stat & 0x10000006) == 0 && // EXL, ERL or CU0 set, CP0 accessible 736378Sgblack@eecs.umich.edu (Dbg & 0x40000000) == 0 && // DM bit set, CP0 accessible 746378Sgblack@eecs.umich.edu (Stat & 0x00000018) != 0) { // KSU = 0, kernel mode is base mode 756378Sgblack@eecs.umich.edu // Unable to use Status_CU0, etc directly, using bitfields & masks 766378Sgblack@eecs.umich.edu return true; 776378Sgblack@eecs.umich.edu } else { 786378Sgblack@eecs.umich.edu return false; 795222Sksewell@umich.edu } 806378Sgblack@eecs.umich.edu} 814661Sksewell@umich.edu 826378Sgblack@eecs.umich.edutemplate <class CPU> 836378Sgblack@eecs.umich.eduvoid zeroRegisters(CPU *cpu); 845222Sksewell@umich.edu 856378Sgblack@eecs.umich.edu//////////////////////////////////////////////////////////////////////// 866378Sgblack@eecs.umich.edu// 876378Sgblack@eecs.umich.edu// Translation stuff 886378Sgblack@eecs.umich.edu// 896378Sgblack@eecs.umich.eduinline Addr 906378Sgblack@eecs.umich.eduTruncPage(Addr addr) 916378Sgblack@eecs.umich.edu{ return addr & ~(PageBytes - 1); } 925222Sksewell@umich.edu 936378Sgblack@eecs.umich.eduinline Addr 946378Sgblack@eecs.umich.eduRoundPage(Addr addr) 956378Sgblack@eecs.umich.edu{ return (addr + PageBytes - 1) & ~(PageBytes - 1); } 965222Sksewell@umich.edu 976378Sgblack@eecs.umich.edu//////////////////////////////////////////////////////////////////////// 986378Sgblack@eecs.umich.edu// 996378Sgblack@eecs.umich.edu// CPU Utility 1006378Sgblack@eecs.umich.edu// 1016378Sgblack@eecs.umich.eduvoid startupCPU(ThreadContext *tc, int cpuId); 1026329Sgblack@eecs.umich.edu 1036378Sgblack@eecs.umich.eduvoid copyRegs(ThreadContext *src, ThreadContext *dest); 1046378Sgblack@eecs.umich.eduvoid copyMiscRegs(ThreadContext *src, ThreadContext *dest); 1056378Sgblack@eecs.umich.edu 1067693SAli.Saidi@ARM.comvoid skipFunction(ThreadContext *tc); 1077693SAli.Saidi@ARM.com 1082597SN/A}; 1092447SN/A 1102686Sksewell@umich.edu 1112447SN/A#endif 112