utility.cc revision 5222
12686Sksewell@umich.edu/* 25222Sksewell@umich.edu * Copyright N) 2007 MIPS Technologies, Inc. All Rights Reserved 32686Sksewell@umich.edu * 45222Sksewell@umich.edu * This software is part of the M5 simulator. 52686Sksewell@umich.edu * 65222Sksewell@umich.edu * THIS IS A LEGAL AGREEMENT. BY DOWNLOADING, USING, COPYING, CREATING 75222Sksewell@umich.edu * DERIVATIVE WORKS, AND/OR DISTRIBUTING THIS SOFTWARE YOU ARE AGREEING 85222Sksewell@umich.edu * TO THESE TERMS AND CONDITIONS. 92706Sksewell@umich.edu * 105222Sksewell@umich.edu * Permission is granted to use, copy, create derivative works and 115222Sksewell@umich.edu * distribute this software and such derivative works for any purpose, 125222Sksewell@umich.edu * so long as (1) the copyright notice above, this grant of permission, 135222Sksewell@umich.edu * and the disclaimer below appear in all copies and derivative works 145222Sksewell@umich.edu * made, (2) the copyright notice above is augmented as appropriate to 155222Sksewell@umich.edu * reflect the addition of any new copyrightable work in a derivative 165222Sksewell@umich.edu * work (e.g., Copyright N) <Publication Year> Copyright Owner), and (3) 175222Sksewell@umich.edu * the name of MIPS Technologies, Inc. ($(B!H(BMIPS$(B!I(B) is not used in any 185222Sksewell@umich.edu * advertising or publicity pertaining to the use or distribution of 195222Sksewell@umich.edu * this software without specific, written prior authorization. 205222Sksewell@umich.edu * 215222Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED $(B!H(BAS IS.$(B!I(B MIPS MAKES NO WARRANTIES AND 225222Sksewell@umich.edu * DISCLAIMS ALL WARRANTIES, WHETHER EXPRESS, STATUTORY, IMPLIED OR 235222Sksewell@umich.edu * OTHERWISE, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 245222Sksewell@umich.edu * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND 255222Sksewell@umich.edu * NON-INFRINGEMENT OF THIRD PARTY RIGHTS, REGARDING THIS SOFTWARE. 265222Sksewell@umich.edu * IN NO EVENT SHALL MIPS BE LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, 275222Sksewell@umich.edu * INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL, OR PUNITIVE DAMAGES OF 285222Sksewell@umich.edu * ANY KIND OR NATURE, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT, 295222Sksewell@umich.edu * THIS SOFTWARE AND/OR THE USE OF THIS SOFTWARE, WHETHER SUCH LIABILITY 305222Sksewell@umich.edu * IS ASSERTED ON THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE OR 315222Sksewell@umich.edu * STRICT LIABILITY), OR OTHERWISE, EVEN IF MIPS HAS BEEN WARNED OF THE 325222Sksewell@umich.edu * POSSIBILITY OF ANY SUCH LOSS OR DAMAGE IN ADVANCE. 335222Sksewell@umich.edu * 345222Sksewell@umich.edu * Authors: Korey L. Sewell 352686Sksewell@umich.edu */ 362686Sksewell@umich.edu 374661Sksewell@umich.edu#include "arch/mips/isa_traits.hh" 382686Sksewell@umich.edu#include "arch/mips/utility.hh" 394661Sksewell@umich.edu#include "config/full_system.hh" 404661Sksewell@umich.edu#include "cpu/thread_context.hh" 414661Sksewell@umich.edu#include "cpu/static_inst.hh" 424661Sksewell@umich.edu#include "sim/serialize.hh" 434661Sksewell@umich.edu#include "base/bitfield.hh" 442980Sgblack@eecs.umich.edu#include "base/misc.hh" 452686Sksewell@umich.edu 465222Sksewell@umich.edu#if FULL_SYSTEM 475222Sksewell@umich.edu#include "arch/mips/vtophys.hh" 485222Sksewell@umich.edu#include "mem/vport.hh" 495222Sksewell@umich.edu#endif 505222Sksewell@umich.edu 515222Sksewell@umich.edu 522686Sksewell@umich.eduusing namespace MipsISA; 534661Sksewell@umich.eduusing namespace std; 542686Sksewell@umich.edu 555222Sksewell@umich.edunamespace MipsISA { 565222Sksewell@umich.edu 572686Sksewell@umich.eduuint64_t 585222Sksewell@umich.edugetArgument(ThreadContext *tc, int number, bool fp) 595222Sksewell@umich.edu{ 605222Sksewell@umich.edu#if FULL_SYSTEM 615222Sksewell@umich.edu if (number < NumArgumentRegs) { 625222Sksewell@umich.edu if (fp) 635222Sksewell@umich.edu return tc->readFloatRegBits(ArgumentReg[number]); 645222Sksewell@umich.edu else 655222Sksewell@umich.edu return tc->readIntReg(ArgumentReg[number]); 665222Sksewell@umich.edu } else { 675222Sksewell@umich.edu Addr sp = tc->readIntReg(StackPointerReg); 685222Sksewell@umich.edu VirtualPort *vp = tc->getVirtPort(tc); 695222Sksewell@umich.edu uint64_t arg = vp->read<uint64_t>(sp + 705222Sksewell@umich.edu (number-NumArgumentRegs) * sizeof(uint64_t)); 715222Sksewell@umich.edu tc->delVirtPort(vp); 725222Sksewell@umich.edu return arg; 735222Sksewell@umich.edu } 745222Sksewell@umich.edu#else 755222Sksewell@umich.edu panic("getArgument() is Full system only\n"); 765222Sksewell@umich.edu M5_DUMMY_RETURN 775222Sksewell@umich.edu#endif 785222Sksewell@umich.edu} 795222Sksewell@umich.edu 805222Sksewell@umich.eduuint64_t 815222Sksewell@umich.edufpConvert(ConvertType cvt_type, double fp_val) 822686Sksewell@umich.edu{ 832686Sksewell@umich.edu 842686Sksewell@umich.edu switch (cvt_type) 852686Sksewell@umich.edu { 862686Sksewell@umich.edu case SINGLE_TO_DOUBLE: 872686Sksewell@umich.edu { 882686Sksewell@umich.edu double sdouble_val = fp_val; 892686Sksewell@umich.edu void *sdouble_ptr = &sdouble_val; 902686Sksewell@umich.edu uint64_t sdp_bits = *(uint64_t *) sdouble_ptr; 912686Sksewell@umich.edu return sdp_bits; 922686Sksewell@umich.edu } 932686Sksewell@umich.edu 942686Sksewell@umich.edu case SINGLE_TO_WORD: 952686Sksewell@umich.edu { 962686Sksewell@umich.edu int32_t sword_val = (int32_t) fp_val; 972686Sksewell@umich.edu void *sword_ptr = &sword_val; 982686Sksewell@umich.edu uint64_t sword_bits= *(uint32_t *) sword_ptr; 992686Sksewell@umich.edu return sword_bits; 1002686Sksewell@umich.edu } 1012686Sksewell@umich.edu 1022686Sksewell@umich.edu case WORD_TO_SINGLE: 1032686Sksewell@umich.edu { 1042686Sksewell@umich.edu float wfloat_val = fp_val; 1052686Sksewell@umich.edu void *wfloat_ptr = &wfloat_val; 1062686Sksewell@umich.edu uint64_t wfloat_bits = *(uint32_t *) wfloat_ptr; 1072686Sksewell@umich.edu return wfloat_bits; 1082686Sksewell@umich.edu } 1092686Sksewell@umich.edu 1102686Sksewell@umich.edu case WORD_TO_DOUBLE: 1112686Sksewell@umich.edu { 1122686Sksewell@umich.edu double wdouble_val = fp_val; 1132686Sksewell@umich.edu void *wdouble_ptr = &wdouble_val; 1142686Sksewell@umich.edu uint64_t wdp_bits = *(uint64_t *) wdouble_ptr; 1152686Sksewell@umich.edu return wdp_bits; 1162686Sksewell@umich.edu } 1172686Sksewell@umich.edu 1182686Sksewell@umich.edu default: 1192686Sksewell@umich.edu panic("Invalid Floating Point Conversion Type (%d). See \"types.hh\" for List of Conversions\n",cvt_type); 1202686Sksewell@umich.edu return 0; 1212686Sksewell@umich.edu } 1222686Sksewell@umich.edu} 1232686Sksewell@umich.edu 1242686Sksewell@umich.edudouble 1255222Sksewell@umich.eduroundFP(double val, int digits) 1262686Sksewell@umich.edu{ 1272686Sksewell@umich.edu double digit_offset = pow(10.0,digits); 1282686Sksewell@umich.edu val = val * digit_offset; 1292686Sksewell@umich.edu val = val + 0.5; 1302686Sksewell@umich.edu val = floor(val); 1312686Sksewell@umich.edu val = val / digit_offset; 1322686Sksewell@umich.edu return val; 1332686Sksewell@umich.edu} 1342686Sksewell@umich.edu 1352686Sksewell@umich.edudouble 1365222Sksewell@umich.edutruncFP(double val) 1372686Sksewell@umich.edu{ 1382686Sksewell@umich.edu int trunc_val = (int) val; 1392686Sksewell@umich.edu return (double) trunc_val; 1402686Sksewell@umich.edu} 1412686Sksewell@umich.edu 1422686Sksewell@umich.edubool 1435222Sksewell@umich.edugetCondCode(uint32_t fcsr, int cc_idx) 1442686Sksewell@umich.edu{ 1452686Sksewell@umich.edu int shift = (cc_idx == 0) ? 23 : cc_idx + 24; 1462686Sksewell@umich.edu bool cc_val = (fcsr >> shift) & 0x00000001; 1472686Sksewell@umich.edu return cc_val; 1482686Sksewell@umich.edu} 1492686Sksewell@umich.edu 1502686Sksewell@umich.eduuint32_t 1515222Sksewell@umich.edugenCCVector(uint32_t fcsr, int cc_num, uint32_t cc_val) 1522686Sksewell@umich.edu{ 1532686Sksewell@umich.edu int cc_idx = (cc_num == 0) ? 23 : cc_num + 24; 1542686Sksewell@umich.edu 1552686Sksewell@umich.edu fcsr = bits(fcsr, 31, cc_idx + 1) << cc_idx + 1 | 1562686Sksewell@umich.edu cc_val << cc_idx | 1572686Sksewell@umich.edu bits(fcsr, cc_idx - 1, 0); 1582686Sksewell@umich.edu 1592686Sksewell@umich.edu return fcsr; 1602686Sksewell@umich.edu} 1612686Sksewell@umich.edu 1622686Sksewell@umich.eduuint32_t 1635222Sksewell@umich.edugenInvalidVector(uint32_t fcsr_bits) 1642686Sksewell@umich.edu{ 1652686Sksewell@umich.edu //Set FCSR invalid in "flag" field 1662686Sksewell@umich.edu int invalid_offset = Invalid + Flag_Field; 1672686Sksewell@umich.edu fcsr_bits = fcsr_bits | (1 << invalid_offset); 1682686Sksewell@umich.edu 1692686Sksewell@umich.edu //Set FCSR invalid in "cause" flag 1702686Sksewell@umich.edu int cause_offset = Invalid + Cause_Field; 1712686Sksewell@umich.edu fcsr_bits = fcsr_bits | (1 << cause_offset); 1722686Sksewell@umich.edu 1732686Sksewell@umich.edu return fcsr_bits; 1742686Sksewell@umich.edu} 1752686Sksewell@umich.edu 1762686Sksewell@umich.edubool 1775222Sksewell@umich.eduisNan(void *val_ptr, int size) 1782686Sksewell@umich.edu{ 1792686Sksewell@umich.edu switch (size) 1802686Sksewell@umich.edu { 1812686Sksewell@umich.edu case 32: 1822686Sksewell@umich.edu { 1832686Sksewell@umich.edu uint32_t val_bits = *(uint32_t *) val_ptr; 1842686Sksewell@umich.edu return (bits(val_bits, 30, 23) == 0xFF); 1852686Sksewell@umich.edu } 1862686Sksewell@umich.edu 1872686Sksewell@umich.edu case 64: 1882686Sksewell@umich.edu { 1892686Sksewell@umich.edu uint64_t val_bits = *(uint64_t *) val_ptr; 1902686Sksewell@umich.edu return (bits(val_bits, 62, 52) == 0x7FF); 1912686Sksewell@umich.edu } 1922686Sksewell@umich.edu 1932686Sksewell@umich.edu default: 1942686Sksewell@umich.edu panic("Type unsupported. Size mismatch\n"); 1952686Sksewell@umich.edu } 1962686Sksewell@umich.edu} 1972686Sksewell@umich.edu 1982686Sksewell@umich.edu 1992686Sksewell@umich.edubool 2005222Sksewell@umich.eduisQnan(void *val_ptr, int size) 2012686Sksewell@umich.edu{ 2022686Sksewell@umich.edu switch (size) 2032686Sksewell@umich.edu { 2042686Sksewell@umich.edu case 32: 2052686Sksewell@umich.edu { 2062686Sksewell@umich.edu uint32_t val_bits = *(uint32_t *) val_ptr; 2072686Sksewell@umich.edu return (bits(val_bits, 30, 22) == 0x1FE); 2082686Sksewell@umich.edu } 2092686Sksewell@umich.edu 2102686Sksewell@umich.edu case 64: 2112686Sksewell@umich.edu { 2122686Sksewell@umich.edu uint64_t val_bits = *(uint64_t *) val_ptr; 2132686Sksewell@umich.edu return (bits(val_bits, 62, 51) == 0xFFE); 2142686Sksewell@umich.edu } 2152686Sksewell@umich.edu 2162686Sksewell@umich.edu default: 2172686Sksewell@umich.edu panic("Type unsupported. Size mismatch\n"); 2182686Sksewell@umich.edu } 2192686Sksewell@umich.edu} 2202686Sksewell@umich.edu 2212686Sksewell@umich.edubool 2225222Sksewell@umich.eduisSnan(void *val_ptr, int size) 2232686Sksewell@umich.edu{ 2242686Sksewell@umich.edu switch (size) 2252686Sksewell@umich.edu { 2262686Sksewell@umich.edu case 32: 2272686Sksewell@umich.edu { 2282686Sksewell@umich.edu uint32_t val_bits = *(uint32_t *) val_ptr; 2292686Sksewell@umich.edu return (bits(val_bits, 30, 22) == 0x1FF); 2302686Sksewell@umich.edu } 2312686Sksewell@umich.edu 2322686Sksewell@umich.edu case 64: 2332686Sksewell@umich.edu { 2342686Sksewell@umich.edu uint64_t val_bits = *(uint64_t *) val_ptr; 2352686Sksewell@umich.edu return (bits(val_bits, 62, 51) == 0xFFF); 2362686Sksewell@umich.edu } 2372686Sksewell@umich.edu 2382686Sksewell@umich.edu default: 2392686Sksewell@umich.edu panic("Type unsupported. Size mismatch\n"); 2402686Sksewell@umich.edu } 2412686Sksewell@umich.edu} 2424661Sksewell@umich.edu 2435222Sksewell@umich.eduint 2445222Sksewell@umich.eduflattenIntIndex(ThreadContext * tc, int reg) 2455222Sksewell@umich.edu{ 2465222Sksewell@umich.edu return reg; 2475222Sksewell@umich.edu} 2485222Sksewell@umich.edu 2495222Sksewell@umich.edu 2504661Sksewell@umich.eduvoid 2515222Sksewell@umich.educopyRegs(ThreadContext *src, ThreadContext *dest) 2524661Sksewell@umich.edu{ 2535222Sksewell@umich.edu panic("Copy Regs Not Implemented Yet\n"); 2544661Sksewell@umich.edu} 2555222Sksewell@umich.edu 2565222Sksewell@umich.eduvoid 2575222Sksewell@umich.educopyMiscRegs(ThreadContext *src, ThreadContext *dest) 2585222Sksewell@umich.edu{ 2595222Sksewell@umich.edu panic("Copy Misc. Regs Not Implemented Yet\n"); 2605222Sksewell@umich.edu} 2615222Sksewell@umich.edu 2625222Sksewell@umich.edutemplate <class CPU> 2635222Sksewell@umich.eduvoid 2645222Sksewell@umich.eduzeroRegisters(CPU *cpu) 2655222Sksewell@umich.edu{ 2665222Sksewell@umich.edu // Insure ISA semantics 2675222Sksewell@umich.edu // (no longer very clean due to the change in setIntReg() in the 2685222Sksewell@umich.edu // cpu model. Consider changing later.) 2695222Sksewell@umich.edu cpu->thread->setIntReg(ZeroReg, 0); 2705222Sksewell@umich.edu cpu->thread->setFloatReg(ZeroReg, 0.0); 2715222Sksewell@umich.edu} 2725222Sksewell@umich.edu 2735222Sksewell@umich.eduvoid 2745222Sksewell@umich.edustartupCPU(ThreadContext *tc, int cpuId) 2755222Sksewell@umich.edu{ 2765222Sksewell@umich.edu tc->activate(0/*tc->getThreadNum()*/); 2775222Sksewell@umich.edu} 2785222Sksewell@umich.edu 2795222Sksewell@umich.edu} // namespace MipsISA 280