process.hh revision 12074
16657Snate@binkert.org/*
26657Snate@binkert.org * Copyright (c) 2007 The Hewlett-Packard Development Company
36657Snate@binkert.org * All rights reserved.
46657Snate@binkert.org *
56657Snate@binkert.org * The license below extends only to copyright in the software and shall
66657Snate@binkert.org * not be construed as granting a license to any other intellectual
76657Snate@binkert.org * property including but not limited to intellectual property relating
86657Snate@binkert.org * to a hardware implementation of the functionality of the software
96657Snate@binkert.org * licensed hereunder.  You may use the software subject to the license
106657Snate@binkert.org * terms below provided that you ensure that this notice is replicated
116657Snate@binkert.org * unmodified and in its entirety in all distributions of the software,
126657Snate@binkert.org * modified or unmodified, in source code or in binary form.
136657Snate@binkert.org *
146657Snate@binkert.org * Redistribution and use in source and binary forms, with or without
156657Snate@binkert.org * modification, are permitted provided that the following conditions are
166657Snate@binkert.org * met: redistributions of source code must retain the above copyright
176657Snate@binkert.org * notice, this list of conditions and the following disclaimer;
186657Snate@binkert.org * redistributions in binary form must reproduce the above copyright
196657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
206657Snate@binkert.org * documentation and/or other materials provided with the distribution;
216657Snate@binkert.org * neither the name of the copyright holders nor the names of its
226657Snate@binkert.org * contributors may be used to endorse or promote products derived from
236657Snate@binkert.org * this software without specific prior written permission.
246657Snate@binkert.org *
256657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
266657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
276657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
286999Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
296657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
306657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
316657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
326657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
336657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
346657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
356657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
366657Snate@binkert.org *
376657Snate@binkert.org * Authors: Gabe Black
386657Snate@binkert.org */
396657Snate@binkert.org
406657Snate@binkert.org#ifndef __ARCH_X86_PROCESS_HH__
416657Snate@binkert.org#define __ARCH_X86_PROCESS_HH__
426657Snate@binkert.org
436657Snate@binkert.org#include <string>
446657Snate@binkert.org#include <vector>
456657Snate@binkert.org
466657Snate@binkert.org#include "mem/multi_level_page_table.hh"
476657Snate@binkert.org#include "sim/aux_vector.hh"
486657Snate@binkert.org#include "sim/process.hh"
496657Snate@binkert.org
506657Snate@binkert.orgclass SyscallDesc;
516657Snate@binkert.org
526657Snate@binkert.orgnamespace X86ISA
536657Snate@binkert.org{
546882SBrad.Beckmann@amd.com    enum X86AuxiliaryVectorTypes {
556657Snate@binkert.org        M5_AT_SYSINFO = 32,
566657Snate@binkert.org        M5_AT_SYSINFO_EHDR = 33
576657Snate@binkert.org    };
586657Snate@binkert.org
596657Snate@binkert.org    class X86Process : public Process
606657Snate@binkert.org    {
616657Snate@binkert.org      protected:
626657Snate@binkert.org        Addr _gdtStart;
636657Snate@binkert.org        Addr _gdtSize;
646657Snate@binkert.org
656657Snate@binkert.org        SyscallDesc *syscallDescs;
666657Snate@binkert.org        const int numSyscallDescs;
676657Snate@binkert.org
686657Snate@binkert.org        X86Process(ProcessParams * params, ObjectFile *objFile,
696657Snate@binkert.org                   SyscallDesc *_syscallDescs, int _numSyscallDescs);
706657Snate@binkert.org
716657Snate@binkert.org        template<class IntType>
726657Snate@binkert.org        void argsInit(int pageSize,
736657Snate@binkert.org                      std::vector<AuxVector<IntType> > extraAuxvs);
746657Snate@binkert.org
756657Snate@binkert.org      public:
766657Snate@binkert.org        Addr gdtStart()
776657Snate@binkert.org        { return _gdtStart; }
786657Snate@binkert.org
796657Snate@binkert.org        Addr gdtSize()
806657Snate@binkert.org        { return _gdtSize; }
816657Snate@binkert.org
826657Snate@binkert.org        SyscallDesc* getDesc(int callnum) override;
836657Snate@binkert.org
846657Snate@binkert.org        void setSyscallReturn(ThreadContext *tc,
856657Snate@binkert.org                              SyscallReturn return_value) override;
866657Snate@binkert.org        void clone(ThreadContext *old_tc, ThreadContext *new_tc,
876657Snate@binkert.org                   Process *process, TheISA::IntReg flags);
886657Snate@binkert.org
896657Snate@binkert.org        X86Process &
906657Snate@binkert.org        operator=(const X86Process &in)
916657Snate@binkert.org        {
926657Snate@binkert.org            if (this == &in)
936657Snate@binkert.org                return *this;
946657Snate@binkert.org
956657Snate@binkert.org            _gdtStart = in._gdtStart;
966657Snate@binkert.org            _gdtSize = in._gdtSize;
976657Snate@binkert.org            syscallDescs = in.syscallDescs;
986657Snate@binkert.org
996657Snate@binkert.org            return *this;
1006657Snate@binkert.org        }
1016657Snate@binkert.org    };
1026657Snate@binkert.org
1038086SBrad.Beckmann@amd.com    class X86_64Process : public X86Process
1048086SBrad.Beckmann@amd.com    {
1058086SBrad.Beckmann@amd.com      protected:
1066657Snate@binkert.org        X86_64Process(ProcessParams *params, ObjectFile *objFile,
1076657Snate@binkert.org                      SyscallDesc *_syscallDescs, int _numSyscallDescs);
1086657Snate@binkert.org
1096657Snate@binkert.org        class VSyscallPage
1106657Snate@binkert.org        {
1116657Snate@binkert.org          public:
1126657Snate@binkert.org            Addr base;
1136657Snate@binkert.org            Addr size;
1146657Snate@binkert.org            Addr vtimeOffset;
1156657Snate@binkert.org            Addr vgettimeofdayOffset;
1166657Snate@binkert.org
1176657Snate@binkert.org            VSyscallPage &
1186657Snate@binkert.org            operator=(const VSyscallPage &in)
1196657Snate@binkert.org            {
1206657Snate@binkert.org                if (this == &in)
1216657Snate@binkert.org                    return *this;
1226657Snate@binkert.org
1236657Snate@binkert.org                base = in.base;
1246657Snate@binkert.org                size = in.size;
1256657Snate@binkert.org                vtimeOffset = in.vtimeOffset;
1266657Snate@binkert.org                vgettimeofdayOffset = in.vgettimeofdayOffset;
1276657Snate@binkert.org
1286657Snate@binkert.org                return *this;
1296657Snate@binkert.org            }
1306657Snate@binkert.org        };
1316657Snate@binkert.org        VSyscallPage vsyscallPage;
1326657Snate@binkert.org
1336657Snate@binkert.org      public:
1346657Snate@binkert.org        void argsInit(int pageSize);
1356657Snate@binkert.org        void initState() override;
1366657Snate@binkert.org
1376657Snate@binkert.org        X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i) override;
1386657Snate@binkert.org        /// Explicitly import the otherwise hidden getSyscallArg
1396657Snate@binkert.org        using Process::getSyscallArg;
1406657Snate@binkert.org        void setSyscallArg(ThreadContext *tc, int i,
1416657Snate@binkert.org                           X86ISA::IntReg val) override;
1426657Snate@binkert.org        void clone(ThreadContext *old_tc, ThreadContext *new_tc,
1436657Snate@binkert.org                   Process *process, TheISA::IntReg flags);
1446657Snate@binkert.org    };
1456657Snate@binkert.org
1466657Snate@binkert.org    class I386Process : public X86Process
1476657Snate@binkert.org    {
1486657Snate@binkert.org      protected:
1496657Snate@binkert.org        I386Process(ProcessParams *params, ObjectFile *objFile,
1506657Snate@binkert.org                    SyscallDesc *_syscallDescs, int _numSyscallDescs);
1516657Snate@binkert.org
1526657Snate@binkert.org        class VSyscallPage
1536657Snate@binkert.org        {
1546657Snate@binkert.org          public:
1556657Snate@binkert.org            Addr base;
1566657Snate@binkert.org            Addr size;
1576657Snate@binkert.org            Addr vsyscallOffset;
1586657Snate@binkert.org            Addr vsysexitOffset;
1596657Snate@binkert.org
1606657Snate@binkert.org            VSyscallPage &
1616882SBrad.Beckmann@amd.com            operator=(const VSyscallPage &in)
1626882SBrad.Beckmann@amd.com            {
1636882SBrad.Beckmann@amd.com                if (this == &in)
1648086SBrad.Beckmann@amd.com                    return *this;
1658086SBrad.Beckmann@amd.com
1668086SBrad.Beckmann@amd.com                base = in.base;
1676657Snate@binkert.org                size = in.size;
1686657Snate@binkert.org                vsyscallOffset = in.vsyscallOffset;
1696657Snate@binkert.org                vsysexitOffset = in.vsysexitOffset;
1706657Snate@binkert.org
1716657Snate@binkert.org                return *this;
1726657Snate@binkert.org            }
1736657Snate@binkert.org        };
1746657Snate@binkert.org        VSyscallPage vsyscallPage;
1756657Snate@binkert.org
1766657Snate@binkert.org      public:
1776657Snate@binkert.org        void argsInit(int pageSize);
1786657Snate@binkert.org        void initState() override;
1796657Snate@binkert.org
1806657Snate@binkert.org        void syscall(int64_t callnum, ThreadContext *tc,
1816657Snate@binkert.org                     Fault *fault) override;
1826657Snate@binkert.org        X86ISA::IntReg getSyscallArg(ThreadContext *tc,
1836657Snate@binkert.org                                     int &i) override;
1846657Snate@binkert.org        X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i,
1856657Snate@binkert.org                                     int width) override;
1866657Snate@binkert.org        void setSyscallArg(ThreadContext *tc, int i,
1876657Snate@binkert.org                           X86ISA::IntReg val) override;
1886657Snate@binkert.org        void clone(ThreadContext *old_tc, ThreadContext *new_tc,
1896657Snate@binkert.org                   Process *process, TheISA::IntReg flags);
1906657Snate@binkert.org    };
1916657Snate@binkert.org
1926657Snate@binkert.org    /**
1936657Snate@binkert.org     * Declaration of architectural page table for x86.
1946657Snate@binkert.org     *
1956657Snate@binkert.org     * These page tables are stored in system memory and respect x86
1966657Snate@binkert.org     * specification.
1976657Snate@binkert.org     */
1986657Snate@binkert.org    typedef MultiLevelPageTable<PageTableOps> ArchPageTable;
1996657Snate@binkert.org
2006999Snate@binkert.org}
2016657Snate@binkert.org
2026657Snate@binkert.org#endif // __ARCH_X86_PROCESS_HH__
2036657Snate@binkert.org