utility.cc revision 5715:e8c1d4e669a7
11689SN/A/*
22326SN/A * Copyright (c) 2007 MIPS Technologies, Inc.
31689SN/A * All rights reserved.
41689SN/A *
51689SN/A * Redistribution and use in source and binary forms, with or without
61689SN/A * modification, are permitted provided that the following conditions are
71689SN/A * met: redistributions of source code must retain the above copyright
81689SN/A * notice, this list of conditions and the following disclaimer;
91689SN/A * redistributions in binary form must reproduce the above copyright
101689SN/A * notice, this list of conditions and the following disclaimer in the
111689SN/A * documentation and/or other materials provided with the distribution;
121689SN/A * neither the name of the copyright holders nor the names of its
131689SN/A * contributors may be used to endorse or promote products derived from
141689SN/A * this software without specific prior written permission.
151689SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Korey Sewell
291689SN/A */
301689SN/A
311060SN/A#include "arch/mips/isa_traits.hh"
321060SN/A#include "arch/mips/utility.hh"
331689SN/A#include "config/full_system.hh"
341060SN/A#include "cpu/thread_context.hh"
351060SN/A#include "cpu/static_inst.hh"
361060SN/A#include "sim/serialize.hh"
371060SN/A#include "base/bitfield.hh"
382292SN/A#include "base/misc.hh"
391717SN/A
401060SN/A#if FULL_SYSTEM
411681SN/A#include "arch/mips/vtophys.hh"
422292SN/A#include "mem/vport.hh"
432873Sktlim@umich.edu#endif
441060SN/A
451061SN/A
462292SN/Ausing namespace MipsISA;
472292SN/Ausing namespace std;
482292SN/A
492292SN/Anamespace MipsISA {
502820Sktlim@umich.edu
512292SN/Auint64_t
522820Sktlim@umich.edugetArgument(ThreadContext *tc, int number, bool fp)
532820Sktlim@umich.edu{
542307SN/A#if FULL_SYSTEM
552307SN/A    if (number < NumArgumentRegs) {
561060SN/A        if (fp)
572292SN/A            return tc->readFloatRegBits(ArgumentReg[number]);
582292SN/A        else
592292SN/A            return tc->readIntReg(ArgumentReg[number]);
601060SN/A    } else {
611060SN/A        Addr sp = tc->readIntReg(StackPointerReg);
621060SN/A        VirtualPort *vp = tc->getVirtPort();
631060SN/A        uint64_t arg = vp->read<uint64_t>(sp +
641060SN/A                           (number-NumArgumentRegs) * sizeof(uint64_t));
651060SN/A        return arg;
661681SN/A    }
672292SN/A#else
681681SN/A    panic("getArgument() is Full system only\n");
692292SN/A    M5_DUMMY_RETURN
702292SN/A#endif
712292SN/A}
722292SN/A
732292SN/Auint64_t
742935Sksewell@umich.edufpConvert(ConvertType cvt_type, double fp_val)
752292SN/A{
762292SN/A
772820Sktlim@umich.edu    switch (cvt_type)
782820Sktlim@umich.edu    {
792292SN/A      case SINGLE_TO_DOUBLE:
802292SN/A        {
812820Sktlim@umich.edu            double sdouble_val = fp_val;
822820Sktlim@umich.edu            void  *sdouble_ptr = &sdouble_val;
832292SN/A            uint64_t sdp_bits  = *(uint64_t *) sdouble_ptr;
842292SN/A            return sdp_bits;
852292SN/A        }
862292SN/A
872292SN/A      case SINGLE_TO_WORD:
882292SN/A        {
892292SN/A            int32_t sword_val  = (int32_t) fp_val;
902292SN/A            void  *sword_ptr   = &sword_val;
911060SN/A            uint64_t sword_bits= *(uint32_t *) sword_ptr;
921060SN/A            return sword_bits;
931681SN/A        }
941062SN/A
952292SN/A      case WORD_TO_SINGLE:
961062SN/A        {
972301SN/A            float wfloat_val   = fp_val;
982301SN/A            void  *wfloat_ptr  = &wfloat_val;
991062SN/A            uint64_t wfloat_bits = *(uint32_t *) wfloat_ptr;
1002727Sktlim@umich.edu            return wfloat_bits;
1011062SN/A        }
1021062SN/A
1031062SN/A      case WORD_TO_DOUBLE:
1041062SN/A        {
1051062SN/A            double wdouble_val = fp_val;
1061062SN/A            void  *wdouble_ptr = &wdouble_val;
1071062SN/A            uint64_t wdp_bits  = *(uint64_t *) wdouble_ptr;
1081062SN/A            return wdp_bits;
1091062SN/A        }
1101062SN/A
1111062SN/A      default:
1121062SN/A        panic("Invalid Floating Point Conversion Type (%d). See \"types.hh\" for List of Conversions\n",cvt_type);
1131062SN/A        return 0;
1141062SN/A    }
1151062SN/A}
1161062SN/A
1171062SN/Adouble
1181062SN/AroundFP(double val, int digits)
1191062SN/A{
1201062SN/A    double digit_offset = pow(10.0,digits);
1211062SN/A    val = val * digit_offset;
1221062SN/A    val = val + 0.5;
1231062SN/A    val = floor(val);
1241062SN/A    val = val / digit_offset;
1251062SN/A    return val;
1261062SN/A}
1271062SN/A
1281062SN/Adouble
1291062SN/AtruncFP(double val)
1301062SN/A{
1311062SN/A    int trunc_val = (int) val;
1321062SN/A    return (double) trunc_val;
1331062SN/A}
1341062SN/A
1351062SN/Abool
1361062SN/AgetCondCode(uint32_t fcsr, int cc_idx)
1371062SN/A{
1381062SN/A    int shift = (cc_idx == 0) ? 23 : cc_idx + 24;
1391062SN/A    bool cc_val = (fcsr >> shift) & 0x00000001;
1401062SN/A    return cc_val;
1411062SN/A}
1422292SN/A
1432292SN/Auint32_t
1442292SN/AgenCCVector(uint32_t fcsr, int cc_num, uint32_t cc_val)
1452292SN/A{
1461062SN/A    int cc_idx = (cc_num == 0) ? 23 : cc_num + 24;
1471062SN/A
1481062SN/A    fcsr = bits(fcsr, 31, cc_idx + 1) << (cc_idx + 1) |
1491062SN/A           cc_val << cc_idx |
1501062SN/A           bits(fcsr, cc_idx - 1, 0);
1511062SN/A
1521062SN/A    return fcsr;
1532292SN/A}
1542292SN/A
1552292SN/Auint32_t
1562292SN/AgenInvalidVector(uint32_t fcsr_bits)
1572292SN/A{
1582292SN/A    //Set FCSR invalid in "flag" field
1592292SN/A    int invalid_offset = Invalid + Flag_Field;
1602292SN/A    fcsr_bits = fcsr_bits | (1 << invalid_offset);
1612292SN/A
1622292SN/A    //Set FCSR invalid in "cause" flag
1632301SN/A    int cause_offset = Invalid + Cause_Field;
1642727Sktlim@umich.edu    fcsr_bits = fcsr_bits | (1 << cause_offset);
1652353SN/A
1662727Sktlim@umich.edu    return fcsr_bits;
1672727Sktlim@umich.edu}
1682727Sktlim@umich.edu
1692727Sktlim@umich.edubool
1702353SN/AisNan(void *val_ptr, int size)
1712727Sktlim@umich.edu{
1722727Sktlim@umich.edu    switch (size)
1732727Sktlim@umich.edu    {
1742727Sktlim@umich.edu      case 32:
1752353SN/A        {
1762727Sktlim@umich.edu            uint32_t val_bits = *(uint32_t *) val_ptr;
1772727Sktlim@umich.edu            return (bits(val_bits, 30, 23) == 0xFF);
1782727Sktlim@umich.edu        }
1792301SN/A
1802301SN/A      case 64:
1812301SN/A        {
1822727Sktlim@umich.edu            uint64_t val_bits = *(uint64_t *) val_ptr;
1832301SN/A            return (bits(val_bits, 62, 52) == 0x7FF);
1842727Sktlim@umich.edu        }
1852301SN/A
1862301SN/A      default:
1872301SN/A        panic("Type unsupported. Size mismatch\n");
1882727Sktlim@umich.edu    }
1892301SN/A}
1902727Sktlim@umich.edu
1912301SN/A
1922301SN/Abool
1932301SN/AisQnan(void *val_ptr, int size)
1942727Sktlim@umich.edu{
1952301SN/A    switch (size)
1962727Sktlim@umich.edu    {
1972301SN/A      case 32:
1982301SN/A        {
1992301SN/A            uint32_t val_bits = *(uint32_t *) val_ptr;
2002727Sktlim@umich.edu            return (bits(val_bits, 30, 22) == 0x1FE);
2012301SN/A        }
2022301SN/A
2032301SN/A      case 64:
2042301SN/A        {
2052727Sktlim@umich.edu            uint64_t val_bits = *(uint64_t *) val_ptr;
2062727Sktlim@umich.edu            return (bits(val_bits, 62, 51) == 0xFFE);
2072727Sktlim@umich.edu        }
2082727Sktlim@umich.edu
2092727Sktlim@umich.edu      default:
2102727Sktlim@umich.edu        panic("Type unsupported. Size mismatch\n");
2112727Sktlim@umich.edu    }
2122727Sktlim@umich.edu}
2132727Sktlim@umich.edu
2142301SN/Abool
2152301SN/AisSnan(void *val_ptr, int size)
2162301SN/A{
2172301SN/A    switch (size)
2182301SN/A    {
2192727Sktlim@umich.edu      case 32:
2202301SN/A        {
2212326SN/A            uint32_t val_bits = *(uint32_t *) val_ptr;
2222301SN/A            return (bits(val_bits, 30, 22) == 0x1FF);
2232301SN/A        }
2242301SN/A
2252727Sktlim@umich.edu      case 64:
2262301SN/A        {
2272326SN/A            uint64_t val_bits = *(uint64_t *) val_ptr;
2282301SN/A            return (bits(val_bits, 62, 51) == 0xFFF);
2292301SN/A        }
2302301SN/A
2312727Sktlim@umich.edu      default:
2322301SN/A        panic("Type unsupported. Size mismatch\n");
2332326SN/A    }
2342301SN/A}
2352301SN/A
2362301SN/Avoid
2372727Sktlim@umich.educopyRegs(ThreadContext *src, ThreadContext *dest)
2382301SN/A{
2392326SN/A    panic("Copy Regs Not Implemented Yet\n");
2402301SN/A}
2412301SN/A
2422301SN/Avoid
2432727Sktlim@umich.educopyMiscRegs(ThreadContext *src, ThreadContext *dest)
2442301SN/A{
2452326SN/A    panic("Copy Misc. Regs Not Implemented Yet\n");
2462301SN/A}
2472301SN/A
2482727Sktlim@umich.edutemplate <class CPU>
2492301SN/Avoid
2502326SN/AzeroRegisters(CPU *cpu)
2512301SN/A{
2522326SN/A    // Insure ISA semantics
2532301SN/A    // (no longer very clean due to the change in setIntReg() in the
2542301SN/A    // cpu model.  Consider changing later.)
2552727Sktlim@umich.edu    cpu->thread->setIntReg(ZeroReg, 0);
2562301SN/A    cpu->thread->setFloatReg(ZeroReg, 0.0);
2572326SN/A}
2582301SN/A
2592326SN/Avoid
2602301SN/AstartupCPU(ThreadContext *tc, int cpuId)
2612301SN/A{
2622727Sktlim@umich.edu    tc->activate(0/*tc->threadId()*/);
2632326SN/A}
2641062SN/A
2651062SN/A} // namespace MipsISA
2661681SN/A