utility.hh revision 8300
16019Shines@cs.fsu.edu/*
211929SMatteo.Andreozzi@arm.com * Copyright (c) 2007 The Hewlett-Packard Development Company
37189Sgblack@eecs.umich.edu * All rights reserved.
47189Sgblack@eecs.umich.edu *
57189Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
67189Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
77189Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
87189Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
97189Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
107189Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
117189Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
127189Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
137189Sgblack@eecs.umich.edu *
146019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without
156019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are
166019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright
176019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer;
186019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright
196019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the
206019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution;
216019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its
226019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from
236019Shines@cs.fsu.edu * this software without specific prior written permission.
246019Shines@cs.fsu.edu *
256019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
266019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
276019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
286019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
296019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
306019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
316019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
326019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
336019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
346019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
356019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
366019Shines@cs.fsu.edu *
376019Shines@cs.fsu.edu * Authors: Gabe Black
386019Shines@cs.fsu.edu */
396019Shines@cs.fsu.edu
406019Shines@cs.fsu.edu#ifndef __ARCH_X86_UTILITY_HH__
416735Sgblack@eecs.umich.edu#define __ARCH_X86_UTILITY_HH__
426735Sgblack@eecs.umich.edu
4310037SARM gem5 Developers#include "arch/x86/regs/misc.hh"
4410037SARM gem5 Developers#include "arch/x86/types.hh"
456019Shines@cs.fsu.edu#include "base/hashmap.hh"
466019Shines@cs.fsu.edu#include "base/misc.hh"
476019Shines@cs.fsu.edu#include "base/types.hh"
486019Shines@cs.fsu.edu#include "config/full_system.hh"
496019Shines@cs.fsu.edu#include "cpu/static_inst.hh"
507362Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
5110037SARM gem5 Developers
526735Sgblack@eecs.umich.educlass ThreadContext;
538229Snate@binkert.org
546019Shines@cs.fsu.edunamespace X86ISA
558782Sgblack@eecs.umich.edu{
566019Shines@cs.fsu.edu
576019Shines@cs.fsu.edu    inline PCState
586019Shines@cs.fsu.edu    buildRetPC(const PCState &curPC, const PCState &callPC)
596019Shines@cs.fsu.edu    {
606019Shines@cs.fsu.edu        PCState retPC = callPC;
6111294Sandreas.hansson@arm.com        retPC.uEnd();
626019Shines@cs.fsu.edu        return retPC;
637362Sgblack@eecs.umich.edu    }
646019Shines@cs.fsu.edu
656019Shines@cs.fsu.edu    uint64_t
6610037SARM gem5 Developers    getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp);
6710037SARM gem5 Developers
6810037SARM gem5 Developers    static inline bool
6910037SARM gem5 Developers    inUserMode(ThreadContext *tc)
7010037SARM gem5 Developers    {
7110037SARM gem5 Developers#if FULL_SYSTEM
7210037SARM gem5 Developers        HandyM5Reg m5reg = tc->readMiscRegNoEffect(MISCREG_M5_REG);
7310037SARM gem5 Developers        return m5reg.cpl == 3;
7410037SARM gem5 Developers#else
7510037SARM gem5 Developers        return true;
766735Sgblack@eecs.umich.edu#endif
7710037SARM gem5 Developers    }
786735Sgblack@eecs.umich.edu
796019Shines@cs.fsu.edu    /**
8010037SARM gem5 Developers     * Function to insure ISA semantics about 0 registers.
8110037SARM gem5 Developers     * @param tc The thread context.
8210037SARM gem5 Developers     */
8310037SARM gem5 Developers    template <class TC>
8410037SARM gem5 Developers    void zeroRegisters(TC *tc);
857362Sgblack@eecs.umich.edu
8610037SARM gem5 Developers#if FULL_SYSTEM
8710037SARM gem5 Developers
8810037SARM gem5 Developers    void initCPU(ThreadContext *tc, int cpuId);
8910037SARM gem5 Developers
9010037SARM gem5 Developers#endif
9110037SARM gem5 Developers
9210037SARM gem5 Developers    void startupCPU(ThreadContext *tc, int cpuId);
9310037SARM gem5 Developers
9410037SARM gem5 Developers    void copyRegs(ThreadContext *src, ThreadContext *dest);
9510037SARM gem5 Developers
9610037SARM gem5 Developers    void copyMiscRegs(ThreadContext *src, ThreadContext *dest);
9710037SARM gem5 Developers
9810037SARM gem5 Developers    void skipFunction(ThreadContext *tc);
9910037SARM gem5 Developers
10010037SARM gem5 Developers    inline void
1017611SGene.Wu@arm.com    advancePC(PCState &pc, const StaticInstPtr inst)
10210037SARM gem5 Developers    {
10310037SARM gem5 Developers        inst->advancePC(pc);
10410037SARM gem5 Developers    }
10510037SARM gem5 Developers
10610037SARM gem5 Developers    inline uint64_t
10710037SARM gem5 Developers    getExecutingAsid(ThreadContext *tc)
10810037SARM gem5 Developers    {
10910037SARM gem5 Developers        return 0;
11010037SARM gem5 Developers    }
11110037SARM gem5 Developers
11210037SARM gem5 Developers};
11310037SARM gem5 Developers
11410037SARM gem5 Developers#endif // __ARCH_X86_UTILITY_HH__
11510037SARM gem5 Developers