gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
x86_cpu.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Andreas Sandberg
3  * All rights reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Andreas Sandberg
29  */
30 
31 #ifndef __CPU_KVM_X86_CPU_HH__
32 #define __CPU_KVM_X86_CPU_HH__
33 
34 #include "cpu/kvm/base.hh"
35 #include "cpu/kvm/vm.hh"
36 #include "params/X86KvmCPU.hh"
37 
41 class X86KvmCPU : public BaseKvmCPU
42 {
43  public:
44  X86KvmCPU(X86KvmCPUParams *params);
45  virtual ~X86KvmCPU();
46 
47  void startup() override;
48 
50  void dump() const override;
51  void dumpFpuRegs() const;
52  void dumpIntRegs() const;
53  void dumpSpecRegs() const;
54  void dumpDebugRegs() const;
55  void dumpXCRs() const;
56  void dumpXSave() const;
57  void dumpVCpuEvents() const;
58  void dumpMSRs() const;
61  protected:
63 
64  Tick kvmRun(Tick ticks) override;
65 
81  Tick kvmRunDrain() override;
82 
84  Tick kvmRunWrapper(Tick ticks);
85 
86  uint64_t getHostCycles() const override;
87 
94  void setCPUID(const struct kvm_cpuid2 &cpuid);
95  void setCPUID(const Kvm::CPUIDVector &cpuid);
103  void setMSRs(const struct kvm_msrs &msrs);
104  void setMSRs(const KvmMSRVector &msrs);
105  void getMSRs(struct kvm_msrs &msrs) const;
106  void setMSR(uint32_t index, uint64_t value);
107  uint64_t getMSR(uint32_t index) const;
118  const Kvm::MSRIndexVector &getMsrIntersection() const;
119 
125  void getDebugRegisters(struct kvm_debugregs &regs) const;
126  void setDebugRegisters(const struct kvm_debugregs &regs);
127  void getXCRs(struct kvm_xcrs &regs) const;
128  void setXCRs(const struct kvm_xcrs &regs);
129  void getXSave(struct kvm_xsave &xsave) const;
130  void setXSave(const struct kvm_xsave &xsave);
131  void getVCpuEvents(struct kvm_vcpu_events &events) const;
132  void setVCpuEvents(const struct kvm_vcpu_events &events);
135  void updateKvmState() override;
136  void updateThreadContext() override;
137 
141  void deliverInterrupts();
142 
146  Tick handleKvmExitIO() override;
147 
148  Tick handleKvmExitIRQWindowOpen() override;
149 
161  bool archIsDrained() const override;
162 
163  private:
171  void updateKvmStateRegs();
173  void updateKvmStateSRegs();
184  void updateKvmStateFPU();
200  void updateKvmStateFPUXSave();
202  void updateKvmStateMSRs();
212  void updateThreadContextRegs(const struct kvm_regs &regs,
213  const struct kvm_sregs &sregs);
215  void updateThreadContextSRegs(const struct kvm_sregs &sregs);
217  void updateThreadContextFPU(const struct kvm_fpu &fpu);
219  void updateThreadContextXSave(const struct kvm_xsave &kxsave);
225  void updateCPUID();
226 
235  void handleIOMiscReg32(int miscreg);
236 
238  mutable Kvm::MSRIndexVector cachedMsrIntersection;
239 
244  bool haveXSave;
249  bool useXSave;
251  bool haveXCRs;
253 };
254 
255 #endif
void handleIOMiscReg32(int miscreg)
Handle a 32-bit IO access that should be mapped to a MiscReg.
Definition: x86_cpu.cc:1283
void setXCRs(const struct kvm_xcrs &regs)
Definition: x86_cpu.cc:1590
void setMSRs(const struct kvm_msrs &msrs)
Methods to access MSRs in the guest.
Definition: x86_cpu.cc:1480
Bitfield< 30, 0 > index
void setDebugRegisters(const struct kvm_debugregs &regs)
Definition: x86_cpu.cc:1572
void deliverInterrupts()
Inject pending interrupts from gem5 into the virtual CPU.
Definition: x86_cpu.cc:1134
bool haveXSave
Kvm::capXSave() available?
Definition: x86_cpu.hh:244
void updateKvmStateFPUXSave()
Update FPU and SIMD registers using the XSave API.
Definition: x86_cpu.cc:880
Tick handleKvmExitIRQWindowOpen() override
The guest exited because an interrupt window was requested.
Definition: x86_cpu.cc:1370
void updateKvmStateRegs()
Support routines to update the state of the KVM CPU from gem5's state representation.
Definition: x86_cpu.cc:684
void setVCpuEvents(const struct kvm_vcpu_events &events)
Definition: x86_cpu.cc:1619
void updateThreadContextFPU(const struct kvm_fpu &fpu)
Update FPU and SIMD registers using the legacy API.
Definition: x86_cpu.cc:1080
uint64_t getMSR(uint32_t index) const
Definition: x86_cpu.cc:1524
void dumpDebugRegs() const
Definition: x86_cpu.cc:605
void setCPUID(const struct kvm_cpuid2 &cpuid)
Methods to access CPUID information using the extended API.
Definition: x86_cpu.cc:1460
void updateThreadContextSRegs(const struct kvm_sregs &sregs)
Update control registers (CRx, segments, etc.)
Definition: x86_cpu.cc:1024
Bitfield< 28, 21 > cpuid
Definition: dt_constants.hh:94
Base class for KVM based CPU models.
Definition: base.hh:78
void dumpXCRs() const
Definition: x86_cpu.cc:619
STL vector class.
Definition: stl.hh:40
void getMSRs(struct kvm_msrs &msrs) const
Definition: x86_cpu.cc:1500
void updateKvmState() override
Update the KVM state from the current thread context.
Definition: x86_cpu.cc:671
void getVCpuEvents(struct kvm_vcpu_events &events) const
Definition: x86_cpu.cc:1612
void dump() const override
Dump the internal state to the terminal.
Definition: x86_cpu.cc:566
bool archIsDrained() const override
Check if there are pending events in the vCPU that prevents it from being drained.
Definition: x86_cpu.cc:1379
uint64_t Tick
Tick count type.
Definition: types.hh:63
void updateCPUID()
Transfer gem5's CPUID values into the virtual CPU.
Definition: x86_cpu.cc:1424
void dumpFpuRegs() const
Definition: x86_cpu.cc:581
const Kvm::MSRIndexVector & getMsrIntersection() const
Get a list of MSRs supported by both gem5 and KVM.
Definition: x86_cpu.cc:1540
void dumpVCpuEvents() const
Definition: x86_cpu.cc:643
void dumpIntRegs() const
Definition: x86_cpu.cc:589
void updateKvmStateFPU()
Update FPU and SIMD registers.
Definition: x86_cpu.cc:905
void updateThreadContextMSRs()
Update MSR registers.
Definition: x86_cpu.cc:1104
void updateThreadContextRegs(const struct kvm_regs &regs, const struct kvm_sregs &sregs)
Support routines to update the state of gem5's thread context from KVM's state representation.
Definition: x86_cpu.cc:970
void startup() override
Definition: x86_cpu.cc:552
void setMSR(uint32_t index, uint64_t value)
Definition: x86_cpu.cc:1509
void updateKvmStateSRegs()
Update control registers (CRx, segments, etc.)
Definition: x86_cpu.cc:751
Tick handleKvmExitIO() override
Handle x86 legacy IO (in/out)
Definition: x86_cpu.cc:1308
bool useXSave
Should the XSave interface be used to sync the FPU and SIMD registers?
Definition: x86_cpu.hh:249
void getXSave(struct kvm_xsave &xsave) const
Definition: x86_cpu.cc:1597
void getDebugRegisters(struct kvm_debugregs &regs) const
Wrappers around KVM's state transfer methods.
Definition: x86_cpu.cc:1561
void setXSave(const struct kvm_xsave &xsave)
Definition: x86_cpu.cc:1604
std::vector< struct kvm_msr_entry > KvmMSRVector
Definition: x86_cpu.hh:62
uint64_t getHostCycles() const override
Get the value of the hardware cycle counter in the guest.
Definition: x86_cpu.cc:1277
void getXCRs(struct kvm_xcrs &regs) const
Definition: x86_cpu.cc:1583
Tick kvmRunDrain() override
Run the virtual CPU until draining completes.
Definition: x86_cpu.cc:1233
void updateThreadContext() override
Update the current thread context with the KVM state.
Definition: x86_cpu.cc:936
Tick kvmRunWrapper(Tick ticks)
Wrapper that synchronizes state in kvm_run.
Definition: x86_cpu.cc:1258
void updateKvmStateMSRs()
Update MSR registers.
Definition: x86_cpu.cc:914
virtual ~X86KvmCPU()
Definition: x86_cpu.cc:547
Tick kvmRun(Tick ticks) override
Request KVM to run the guest for a given number of ticks.
Definition: x86_cpu.cc:1187
void updateKvmStateFPULegacy()
Update FPU and SIMD registers using the legacy API.
Definition: x86_cpu.cc:856
void dumpMSRs() const
Definition: x86_cpu.cc:651
void updateThreadContextXSave(const struct kvm_xsave &kxsave)
Update FPU and SIMD registers using the XSave API.
Definition: x86_cpu.cc:1091
bool haveXCRs
Kvm::capXCRs() available?
Definition: x86_cpu.hh:251
void dumpXSave() const
Definition: x86_cpu.cc:631
X86KvmCPU(X86KvmCPUParams *params)
Definition: x86_cpu.cc:519
void dumpSpecRegs() const
Definition: x86_cpu.cc:597
bool haveDebugRegs
Kvm::capDebugRegs() available?
Definition: x86_cpu.hh:242
x86 implementation of a KVM-based hardware virtualized CPU.
Definition: x86_cpu.hh:41
Kvm::MSRIndexVector cachedMsrIntersection
Cached intersection of supported MSRs.
Definition: x86_cpu.hh:238

Generated on Fri Jun 9 2017 13:03:42 for gem5 by doxygen 1.8.6