system.hh revision 12100
16691Stjones1@inf.ed.ac.uk/*
26691Stjones1@inf.ed.ac.uk * Copyright (c) 2010, 2012-2013, 2015-2016 ARM Limited
36691Stjones1@inf.ed.ac.uk * All rights reserved
46691Stjones1@inf.ed.ac.uk *
56691Stjones1@inf.ed.ac.uk * The license below extends only to copyright in the software and shall
66691Stjones1@inf.ed.ac.uk * not be construed as granting a license to any other intellectual
76691Stjones1@inf.ed.ac.uk * property including but not limited to intellectual property relating
86691Stjones1@inf.ed.ac.uk * to a hardware implementation of the functionality of the software
96691Stjones1@inf.ed.ac.uk * licensed hereunder.  You may use the software subject to the license
106691Stjones1@inf.ed.ac.uk * terms below provided that you ensure that this notice is replicated
116691Stjones1@inf.ed.ac.uk * unmodified and in its entirety in all distributions of the software,
126691Stjones1@inf.ed.ac.uk * modified or unmodified, in source code or in binary form.
136691Stjones1@inf.ed.ac.uk *
146691Stjones1@inf.ed.ac.uk * Copyright (c) 2002-2005 The Regents of The University of Michigan
156691Stjones1@inf.ed.ac.uk * All rights reserved.
166691Stjones1@inf.ed.ac.uk *
176691Stjones1@inf.ed.ac.uk * Redistribution and use in source and binary forms, with or without
186691Stjones1@inf.ed.ac.uk * modification, are permitted provided that the following conditions are
196691Stjones1@inf.ed.ac.uk * met: redistributions of source code must retain the above copyright
206691Stjones1@inf.ed.ac.uk * notice, this list of conditions and the following disclaimer;
216691Stjones1@inf.ed.ac.uk * redistributions in binary form must reproduce the above copyright
226691Stjones1@inf.ed.ac.uk * notice, this list of conditions and the following disclaimer in the
236691Stjones1@inf.ed.ac.uk * documentation and/or other materials provided with the distribution;
246691Stjones1@inf.ed.ac.uk * neither the name of the copyright holders nor the names of its
256691Stjones1@inf.ed.ac.uk * contributors may be used to endorse or promote products derived from
266691Stjones1@inf.ed.ac.uk * this software without specific prior written permission.
276691Stjones1@inf.ed.ac.uk *
286691Stjones1@inf.ed.ac.uk * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296691Stjones1@inf.ed.ac.uk * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306691Stjones1@inf.ed.ac.uk * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316691Stjones1@inf.ed.ac.uk * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
326691Stjones1@inf.ed.ac.uk * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336691Stjones1@inf.ed.ac.uk * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346691Stjones1@inf.ed.ac.uk * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
356691Stjones1@inf.ed.ac.uk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366691Stjones1@inf.ed.ac.uk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376691Stjones1@inf.ed.ac.uk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386691Stjones1@inf.ed.ac.uk * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396691Stjones1@inf.ed.ac.uk *
406691Stjones1@inf.ed.ac.uk * Authors: Ali Saidi
416691Stjones1@inf.ed.ac.uk */
426691Stjones1@inf.ed.ac.uk
436691Stjones1@inf.ed.ac.uk#ifndef __ARCH_ARM_SYSTEM_HH__
446691Stjones1@inf.ed.ac.uk#define __ARCH_ARM_SYSTEM_HH__
457506Stjones1@inf.ed.ac.uk
466691Stjones1@inf.ed.ac.uk#include <memory>
476691Stjones1@inf.ed.ac.uk#include <string>
488335Snate@binkert.org#include <vector>
496691Stjones1@inf.ed.ac.uk
506691Stjones1@inf.ed.ac.uk#include "kern/linux/events.hh"
516691Stjones1@inf.ed.ac.uk#include "params/ArmSystem.hh"
526691Stjones1@inf.ed.ac.uk#include "params/GenericArmSystem.hh"
536691Stjones1@inf.ed.ac.uk#include "sim/sim_object.hh"
546691Stjones1@inf.ed.ac.uk#include "sim/system.hh"
556691Stjones1@inf.ed.ac.uk
566691Stjones1@inf.ed.ac.ukclass GenericTimer;
576691Stjones1@inf.ed.ac.ukclass ThreadContext;
586691Stjones1@inf.ed.ac.uk
596691Stjones1@inf.ed.ac.ukclass ArmSystem : public System
606691Stjones1@inf.ed.ac.uk{
616691Stjones1@inf.ed.ac.uk  protected:
626691Stjones1@inf.ed.ac.uk    /**
63     * PC based event to skip the dprink() call and emulate its
64     * functionality
65     */
66    Linux::DebugPrintkEvent *debugPrintkEvent;
67
68    /** Bootloaders */
69    std::vector<std::unique_ptr<ObjectFile>> bootLoaders;
70
71    /**
72     * Pointer to the bootloader object
73     */
74    ObjectFile *bootldr;
75
76    /**
77     * True if this system implements the Security Extensions
78     */
79    const bool _haveSecurity;
80
81    /**
82     * True if this system implements the Large Physical Address Extension
83     */
84    const bool _haveLPAE;
85
86    /**
87     * True if this system implements the virtualization Extensions
88     */
89    const bool _haveVirtualization;
90
91    /**
92     * Pointer to the Generic Timer wrapper.
93     */
94    GenericTimer *_genericTimer;
95
96    /**
97     * True if the register width of the highest implemented exception level is
98     * 64 bits (ARMv8)
99     */
100    bool _highestELIs64;
101
102    /**
103     * Reset address if the highest implemented exception level is 64 bits
104     * (ARMv8)
105     */
106    const Addr _resetAddr64;
107
108    /**
109     * Supported physical address range in bits if the highest implemented
110     * exception level is 64 bits (ARMv8)
111     */
112    const uint8_t _physAddrRange64;
113
114    /**
115     * True if ASID is 16 bits in AArch64 (ARMv8)
116     */
117    const bool _haveLargeAsid64;
118
119    /**
120     * Range for memory-mapped m5 pseudo ops. The range will be
121     * invalid/empty if disabled.
122     */
123    const AddrRange _m5opRange;
124
125  protected:
126    /**
127     * Get a boot loader that matches the kernel.
128     *
129     * @param obj Kernel binary
130     * @return Pointer to boot loader ObjectFile or nullptr if there
131     *         is no matching boot loader.
132     */
133    ObjectFile *getBootLoader(ObjectFile *const obj);
134
135  public:
136    typedef ArmSystemParams Params;
137    const Params *
138    params() const
139    {
140        return dynamic_cast<const Params *>(_params);
141    }
142
143    ArmSystem(Params *p);
144    ~ArmSystem();
145
146    /**
147     * Initialise the system
148     */
149    virtual void initState();
150
151    virtual Addr fixFuncEventAddr(Addr addr)
152    {
153        // Remove the low bit that thumb symbols have set
154        // but that aren't actually odd aligned
155        if (addr & 0x1)
156            return addr & ~1;
157        return addr;
158    }
159
160    /** true if this a multiprocessor system */
161    bool multiProc;
162
163    /** Returns true if this system implements the Security Extensions */
164    bool haveSecurity() const { return _haveSecurity; }
165
166    /** Returns true if this system implements the Large Physical Address
167     * Extension */
168    bool haveLPAE() const { return _haveLPAE; }
169
170    /** Returns true if this system implements the virtualization
171      * Extensions
172      */
173    bool haveVirtualization() const { return _haveVirtualization; }
174
175    /** Sets the pointer to the Generic Timer. */
176    void setGenericTimer(GenericTimer *generic_timer)
177    {
178        _genericTimer = generic_timer;
179    }
180
181    /** Get a pointer to the system's generic timer model */
182    GenericTimer *getGenericTimer() const { return _genericTimer; }
183
184    /** Returns true if the register width of the highest implemented exception
185     * level is 64 bits (ARMv8) */
186    bool highestELIs64() const { return _highestELIs64; }
187
188    /** Returns the highest implemented exception level */
189    ExceptionLevel highestEL() const
190    {
191        if (_haveSecurity)
192            return EL3;
193        if (_haveVirtualization)
194            return EL2;
195        return EL1;
196    }
197
198    /** Returns the reset address if the highest implemented exception level is
199     * 64 bits (ARMv8) */
200    Addr resetAddr64() const { return _resetAddr64; }
201
202    /** Returns true if ASID is 16 bits in AArch64 (ARMv8) */
203    bool haveLargeAsid64() const { return _haveLargeAsid64; }
204
205    /** Returns the supported physical address range in bits if the highest
206     * implemented exception level is 64 bits (ARMv8) */
207    uint8_t physAddrRange64() const { return _physAddrRange64; }
208
209    /** Returns the supported physical address range in bits */
210    uint8_t physAddrRange() const
211    {
212        if (_highestELIs64)
213            return _physAddrRange64;
214        if (_haveLPAE)
215            return 40;
216        return 32;
217    }
218
219    /** Returns the physical address mask */
220    Addr physAddrMask() const
221    {
222        return mask(physAddrRange());
223    }
224
225    /**
226     * Range used by memory-mapped m5 pseudo-ops if enabled. Returns
227     * an invalid/empty range if disabled.
228     */
229    const AddrRange &m5opRange() const { return _m5opRange; }
230
231    /** Returns true if the system of a specific thread context implements the
232     * Security Extensions
233     */
234    static bool haveSecurity(ThreadContext *tc);
235
236    /** Returns true if the system of a specific thread context implements the
237     * virtualization Extensions
238     */
239    static bool haveVirtualization(ThreadContext *tc);
240
241    /** Returns true if the system of a specific thread context implements the
242     * Large Physical Address Extension
243     */
244    static bool haveLPAE(ThreadContext *tc);
245
246    /** Returns true if the register width of the highest implemented exception
247     * level for the system of a specific thread context is 64 bits (ARMv8)
248     */
249    static bool highestELIs64(ThreadContext *tc);
250
251    /** Returns the highest implemented exception level for the system of a
252     * specific thread context
253     */
254    static ExceptionLevel highestEL(ThreadContext *tc);
255
256    /** Returns the reset address if the highest implemented exception level for
257     * the system of a specific thread context is 64 bits (ARMv8)
258     */
259    static Addr resetAddr64(ThreadContext *tc);
260
261    /** Returns the supported physical address range in bits for the system of a
262     * specific thread context
263     */
264    static uint8_t physAddrRange(ThreadContext *tc);
265
266    /** Returns the physical address mask for the system of a specific thread
267     * context
268     */
269    static Addr physAddrMask(ThreadContext *tc);
270
271    /** Returns true if ASID is 16 bits for the system of a specific thread
272     * context while in AArch64 (ARMv8) */
273    static bool haveLargeAsid64(ThreadContext *tc);
274};
275
276class GenericArmSystem : public ArmSystem
277{
278  public:
279    typedef GenericArmSystemParams Params;
280    const Params *
281    params() const
282    {
283        return dynamic_cast<const Params *>(_params);
284    }
285
286    GenericArmSystem(Params *p) : ArmSystem(p) {};
287    virtual ~GenericArmSystem() {};
288
289    /**
290     * Initialise the system
291     */
292    virtual void initState();
293};
294
295#endif
296