utility.hh revision 7878
12SN/A/*
21762SN/A * Copyright (c) 2010 ARM Limited
32SN/A * All rights reserved
42SN/A *
52SN/A * The license below extends only to copyright in the software and shall
62SN/A * not be construed as granting a license to any other intellectual
72SN/A * property including but not limited to intellectual property relating
82SN/A * to a hardware implementation of the functionality of the software
92SN/A * licensed hereunder.  You may use the software subject to the license
102SN/A * terms below provided that you ensure that this notice is replicated
112SN/A * unmodified and in its entirety in all distributions of the software,
122SN/A * modified or unmodified, in source code or in binary form.
132SN/A *
142SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
152SN/A * Copyright (c) 2007-2008 The Florida State University
162SN/A * All rights reserved.
172SN/A *
182SN/A * Redistribution and use in source and binary forms, with or without
192SN/A * modification, are permitted provided that the following conditions are
202SN/A * met: redistributions of source code must retain the above copyright
212SN/A * notice, this list of conditions and the following disclaimer;
222SN/A * redistributions in binary form must reproduce the above copyright
232SN/A * notice, this list of conditions and the following disclaimer in the
242SN/A * documentation and/or other materials provided with the distribution;
252SN/A * neither the name of the copyright holders nor the names of its
262SN/A * contributors may be used to endorse or promote products derived from
272665Ssaidi@eecs.umich.edu * this software without specific prior written permission.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372432SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
381147SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
393453Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402984Sgblack@eecs.umich.edu *
412984Sgblack@eecs.umich.edu * Authors: Korey Sewell
421147SN/A *          Stephen Hines
432517SN/A */
445034Smilesck@eecs.umich.edu
455034Smilesck@eecs.umich.edu#ifndef __ARCH_ARM_UTILITY_HH__
462984Sgblack@eecs.umich.edu#define __ARCH_ARM_UTILITY_HH__
475358Sgblack@eecs.umich.edu
482SN/A#include "arch/arm/isa_traits.hh"
492680Sktlim@umich.edu#include "arch/arm/miscregs.hh"
502SN/A#include "arch/arm/types.hh"
513453Sgblack@eecs.umich.edu#include "base/misc.hh"
522SN/A#include "base/trace.hh"
535004Sgblack@eecs.umich.edu#include "base/types.hh"
542SN/A#include "cpu/static_inst.hh"
555358Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
563453Sgblack@eecs.umich.edu
573453Sgblack@eecs.umich.edunamespace ArmISA {
583453Sgblack@eecs.umich.edu
595004Sgblack@eecs.umich.eduinline PCState
602SN/AbuildRetPC(const PCState &curPC, const PCState &callPC)
615004Sgblack@eecs.umich.edu{
625004Sgblack@eecs.umich.edu    PCState retPC = callPC;
635004Sgblack@eecs.umich.edu    retPC.uEnd();
642SN/A    return retPC;
653453Sgblack@eecs.umich.edu}
665004Sgblack@eecs.umich.edu
672SN/Ainline bool
683453Sgblack@eecs.umich.edutestPredicate(CPSR cpsr, ConditionCode code)
695034Smilesck@eecs.umich.edu{
705034Smilesck@eecs.umich.edu    switch (code)
713453Sgblack@eecs.umich.edu    {
722SN/A        case COND_EQ: return  cpsr.z;
733453Sgblack@eecs.umich.edu        case COND_NE: return !cpsr.z;
742SN/A        case COND_CS: return  cpsr.c;
755004Sgblack@eecs.umich.edu        case COND_CC: return !cpsr.c;
765004Sgblack@eecs.umich.edu        case COND_MI: return  cpsr.n;
772SN/A        case COND_PL: return !cpsr.n;
783453Sgblack@eecs.umich.edu        case COND_VS: return  cpsr.v;
793453Sgblack@eecs.umich.edu        case COND_VC: return !cpsr.v;
803453Sgblack@eecs.umich.edu        case COND_HI: return  (cpsr.c && !cpsr.z);
812SN/A        case COND_LS: return !(cpsr.c && !cpsr.z);
825358Sgblack@eecs.umich.edu        case COND_GE: return !(cpsr.n ^ cpsr.v);
835358Sgblack@eecs.umich.edu        case COND_LT: return  (cpsr.n ^ cpsr.v);
845358Sgblack@eecs.umich.edu        case COND_GT: return !(cpsr.n ^ cpsr.v || cpsr.z);
855358Sgblack@eecs.umich.edu        case COND_LE: return  (cpsr.n ^ cpsr.v || cpsr.z);
865358Sgblack@eecs.umich.edu        case COND_AL: return true;
875358Sgblack@eecs.umich.edu        case COND_UC: return true;
883453Sgblack@eecs.umich.edu        default:
893453Sgblack@eecs.umich.edu            panic("Unhandled predicate condition: %d\n", code);
903453Sgblack@eecs.umich.edu    }
913453Sgblack@eecs.umich.edu}
923453Sgblack@eecs.umich.edu
933453Sgblack@eecs.umich.edu/**
942SN/A * Function to insure ISA semantics about 0 registers.
953453Sgblack@eecs.umich.edu * @param tc The thread context.
962SN/A */
973453Sgblack@eecs.umich.edutemplate <class TC>
983453Sgblack@eecs.umich.eduvoid zeroRegisters(TC *tc);
993453Sgblack@eecs.umich.edu
1004957Sacolyte@umich.eduinline void startupCPU(ThreadContext *tc, int cpuId)
1014957Sacolyte@umich.edu{
1025004Sgblack@eecs.umich.edu    tc->activate(0);
1035004Sgblack@eecs.umich.edu}
1045004Sgblack@eecs.umich.edu
1055004Sgblack@eecs.umich.eduvoid copyRegs(ThreadContext *src, ThreadContext *dest);
1065004Sgblack@eecs.umich.edu
1075004Sgblack@eecs.umich.edustatic inline void
1085004Sgblack@eecs.umich.educopyMiscRegs(ThreadContext *src, ThreadContext *dest)
1095004Sgblack@eecs.umich.edu{
1105004Sgblack@eecs.umich.edu    panic("Copy Misc. Regs Not Implemented Yet\n");
1115004Sgblack@eecs.umich.edu}
1125004Sgblack@eecs.umich.edu
1134967Sacolyte@umich.eduvoid initCPU(ThreadContext *tc, int cpuId);
1143453Sgblack@eecs.umich.edu
1152SN/Astatic inline bool
1163453Sgblack@eecs.umich.eduinUserMode(CPSR cpsr)
1173453Sgblack@eecs.umich.edu{
1183453Sgblack@eecs.umich.edu    return cpsr.mode == MODE_USER;
1193453Sgblack@eecs.umich.edu}
1203453Sgblack@eecs.umich.edu
1213453Sgblack@eecs.umich.edustatic inline bool
1223453Sgblack@eecs.umich.eduinUserMode(ThreadContext *tc)
1232SN/A{
1243453Sgblack@eecs.umich.edu    return inUserMode(tc->readMiscRegNoEffect(MISCREG_CPSR));
1255034Smilesck@eecs.umich.edu}
1265034Smilesck@eecs.umich.edu
1273453Sgblack@eecs.umich.edustatic inline bool
1282SN/AinPrivilegedMode(CPSR cpsr)
1294967Sacolyte@umich.edu{
1303453Sgblack@eecs.umich.edu    return !inUserMode(cpsr);
1312SN/A}
1323453Sgblack@eecs.umich.edu
1333453Sgblack@eecs.umich.edustatic inline bool
1343453Sgblack@eecs.umich.eduinPrivilegedMode(ThreadContext *tc)
1353453Sgblack@eecs.umich.edu{
1363453Sgblack@eecs.umich.edu    return !inUserMode(tc);
1373453Sgblack@eecs.umich.edu}
1383453Sgblack@eecs.umich.edu
1393453Sgblack@eecs.umich.edustatic inline bool
1403453Sgblack@eecs.umich.eduvfpEnabled(CPACR cpacr, CPSR cpsr)
1413453Sgblack@eecs.umich.edu{
1423453Sgblack@eecs.umich.edu    return cpacr.cp10 == 0x3 ||
1433453Sgblack@eecs.umich.edu        (cpacr.cp10 == 0x1 && inPrivilegedMode(cpsr));
1443453Sgblack@eecs.umich.edu}
1453453Sgblack@eecs.umich.edu
1463453Sgblack@eecs.umich.edustatic inline bool
1472SN/AvfpEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc)
1483453Sgblack@eecs.umich.edu{
1495034Smilesck@eecs.umich.edu    return fpexc.en && vfpEnabled(cpacr, cpsr);
1505034Smilesck@eecs.umich.edu}
1513453Sgblack@eecs.umich.edu
1523453Sgblack@eecs.umich.edustatic inline bool
1534967Sacolyte@umich.eduneonEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc)
1543453Sgblack@eecs.umich.edu{
1553453Sgblack@eecs.umich.edu    return !cpacr.asedis && vfpEnabled(cpacr, cpsr, fpexc);
1562SN/A}
1572SN/A
158uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp);
159
160Fault setCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2);
161Fault readCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2);
162
163void skipFunction(ThreadContext *tc);
164
165inline void
166advancePC(PCState &pc, const StaticInstPtr inst)
167{
168    inst->advancePC(pc);
169}
170
171Addr truncPage(Addr addr);
172Addr roundPage(Addr addr);
173
174};
175
176
177#endif
178