gem5  v20.1.0.0
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 
29 #ifndef __CPU_KVM_X86_CPU_HH__
30 #define __CPU_KVM_X86_CPU_HH__
31 
32 #include "cpu/kvm/base.hh"
33 #include "cpu/kvm/vm.hh"
34 #include "params/X86KvmCPU.hh"
35 
39 class X86KvmCPU : public BaseKvmCPU
40 {
41  public:
42  X86KvmCPU(X86KvmCPUParams *params);
43  virtual ~X86KvmCPU();
44 
45  void startup() override;
46 
48  void dump() const override;
49  void dumpFpuRegs() const;
50  void dumpIntRegs() const;
51  void dumpSpecRegs() const;
52  void dumpDebugRegs() const;
53  void dumpXCRs() const;
54  void dumpXSave() const;
55  void dumpVCpuEvents() const;
56  void dumpMSRs() const;
59  protected:
61 
62  Tick kvmRun(Tick ticks) override;
63 
79  Tick kvmRunDrain() override;
80 
82  Tick kvmRunWrapper(Tick ticks);
83 
84  uint64_t getHostCycles() const override;
85 
92  void setCPUID(const struct kvm_cpuid2 &cpuid);
93  void setCPUID(const Kvm::CPUIDVector &cpuid);
101  void setMSRs(const struct kvm_msrs &msrs);
102  void setMSRs(const KvmMSRVector &msrs);
103  void getMSRs(struct kvm_msrs &msrs) const;
104  void setMSR(uint32_t index, uint64_t value);
105  uint64_t getMSR(uint32_t index) const;
116  const Kvm::MSRIndexVector &getMsrIntersection() const;
117 
123  void getDebugRegisters(struct kvm_debugregs &regs) const;
124  void setDebugRegisters(const struct kvm_debugregs &regs);
125  void getXCRs(struct kvm_xcrs &regs) const;
126  void setXCRs(const struct kvm_xcrs &regs);
127  void getXSave(struct kvm_xsave &xsave) const;
128  void setXSave(const struct kvm_xsave &xsave);
129  void getVCpuEvents(struct kvm_vcpu_events &events) const;
130  void setVCpuEvents(const struct kvm_vcpu_events &events);
133  void updateKvmState() override;
134  void updateThreadContext() override;
135 
139  void deliverInterrupts();
140 
144  Tick handleKvmExitIO() override;
145 
146  Tick handleKvmExitIRQWindowOpen() override;
147 
159  bool archIsDrained() const override;
160 
161  private:
169  void updateKvmStateRegs();
171  void updateKvmStateSRegs();
182  void updateKvmStateFPU();
198  void updateKvmStateFPUXSave();
200  void updateKvmStateMSRs();
210  void updateThreadContextRegs(const struct kvm_regs &regs,
211  const struct kvm_sregs &sregs);
213  void updateThreadContextSRegs(const struct kvm_sregs &sregs);
215  void updateThreadContextFPU(const struct kvm_fpu &fpu);
217  void updateThreadContextXSave(const struct kvm_xsave &kxsave);
223  void updateCPUID();
224 
233  void handleIOMiscReg32(int miscreg);
234 
236  mutable Kvm::MSRIndexVector cachedMsrIntersection;
237 
242  bool haveXSave;
247  bool useXSave;
249  bool haveXCRs;
251 };
252 
253 #endif
X86KvmCPU
x86 implementation of a KVM-based hardware virtualized CPU.
Definition: x86_cpu.hh:39
X86KvmCPU::handleKvmExitIO
Tick handleKvmExitIO() override
Handle x86 legacy IO (in/out)
Definition: x86_cpu.cc:1307
X86KvmCPU::getVCpuEvents
void getVCpuEvents(struct kvm_vcpu_events &events) const
Definition: x86_cpu.cc:1612
X86KvmCPU::updateThreadContextFPU
void updateThreadContextFPU(const struct kvm_fpu &fpu)
Update FPU and SIMD registers using the legacy API.
Definition: x86_cpu.cc:1077
X86KvmCPU::getMsrIntersection
const Kvm::MSRIndexVector & getMsrIntersection() const
Get a list of MSRs supported by both gem5 and KVM.
Definition: x86_cpu.cc:1540
X86KvmCPU::archIsDrained
bool archIsDrained() const override
Check if there are pending events in the vCPU that prevents it from being drained.
Definition: x86_cpu.cc:1379
X86KvmCPU::updateThreadContext
void updateThreadContext() override
Update the current thread context with the KVM state.
Definition: x86_cpu.cc:938
X86KvmCPU::getXSave
void getXSave(struct kvm_xsave &xsave) const
Definition: x86_cpu.cc:1597
MipsISA::cpuid
Bitfield< 28, 21 > cpuid
Definition: dt_constants.hh:92
MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:44
X86KvmCPU::haveXSave
bool haveXSave
Kvm::capXSave() available?
Definition: x86_cpu.hh:242
X86KvmCPU::dumpVCpuEvents
void dumpVCpuEvents() const
Definition: x86_cpu.cc:647
X86KvmCPU::startup
void startup() override
Definition: x86_cpu.cc:556
X86KvmCPU::updateThreadContextMSRs
void updateThreadContextMSRs()
Update MSR registers.
Definition: x86_cpu.cc:1101
X86KvmCPU::dumpIntRegs
void dumpIntRegs() const
Definition: x86_cpu.cc:593
X86KvmCPU::getMSR
uint64_t getMSR(uint32_t index) const
Definition: x86_cpu.cc:1524
X86KvmCPU::dumpFpuRegs
void dumpFpuRegs() const
Definition: x86_cpu.cc:585
X86KvmCPU::updateThreadContextRegs
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:972
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
X86KvmCPU::dumpXSave
void dumpXSave() const
Definition: x86_cpu.cc:635
X86KvmCPU::setCPUID
void setCPUID(const struct kvm_cpuid2 &cpuid)
Methods to access CPUID information using the extended API.
Definition: x86_cpu.cc:1460
std::vector
STL vector class.
Definition: stl.hh:37
X86KvmCPU::KvmMSRVector
std::vector< struct kvm_msr_entry > KvmMSRVector
Definition: x86_cpu.hh:60
X86KvmCPU::dump
void dump() const override
Dump the internal state to the terminal.
Definition: x86_cpu.cc:570
X86KvmCPU::kvmRunWrapper
Tick kvmRunWrapper(Tick ticks)
Wrapper that synchronizes state in kvm_run.
Definition: x86_cpu.cc:1257
X86KvmCPU::updateKvmStateMSRs
void updateKvmStateMSRs()
Update MSR registers.
Definition: x86_cpu.cc:916
X86KvmCPU::setMSR
void setMSR(uint32_t index, uint64_t value)
Definition: x86_cpu.cc:1509
X86KvmCPU::handleKvmExitIRQWindowOpen
Tick handleKvmExitIRQWindowOpen() override
The guest exited because an interrupt window was requested.
Definition: x86_cpu.cc:1370
X86KvmCPU::setMSRs
void setMSRs(const struct kvm_msrs &msrs)
Methods to access MSRs in the guest.
Definition: x86_cpu.cc:1480
X86KvmCPU::deliverInterrupts
void deliverInterrupts()
Inject pending interrupts from gem5 into the virtual CPU.
Definition: x86_cpu.cc:1131
X86KvmCPU::haveDebugRegs
bool haveDebugRegs
Kvm::capDebugRegs() available?
Definition: x86_cpu.hh:240
BaseKvmCPU
Base class for KVM based CPU models.
Definition: base.hh:77
X86KvmCPU::dumpDebugRegs
void dumpDebugRegs() const
Definition: x86_cpu.cc:609
X86KvmCPU::kvmRunDrain
Tick kvmRunDrain() override
Run the virtual CPU until draining completes.
Definition: x86_cpu.cc:1232
X86KvmCPU::getHostCycles
uint64_t getHostCycles() const override
Get the value of the hardware cycle counter in the guest.
Definition: x86_cpu.cc:1276
X86KvmCPU::getXCRs
void getXCRs(struct kvm_xcrs &regs) const
Definition: x86_cpu.cc:1583
X86KvmCPU::kvmRun
Tick kvmRun(Tick ticks) override
Request KVM to run the guest for a given number of ticks.
Definition: x86_cpu.cc:1184
X86KvmCPU::X86KvmCPU
X86KvmCPU(X86KvmCPUParams *params)
Definition: x86_cpu.cc:523
X86KvmCPU::dumpXCRs
void dumpXCRs() const
Definition: x86_cpu.cc:623
X86KvmCPU::handleIOMiscReg32
void handleIOMiscReg32(int miscreg)
Handle a 32-bit IO access that should be mapped to a MiscReg.
Definition: x86_cpu.cc:1282
X86KvmCPU::setDebugRegisters
void setDebugRegisters(const struct kvm_debugregs &regs)
Definition: x86_cpu.cc:1572
X86KvmCPU::updateKvmStateFPULegacy
void updateKvmStateFPULegacy()
Update FPU and SIMD registers using the legacy API.
Definition: x86_cpu.cc:858
X86KvmCPU::updateCPUID
void updateCPUID()
Transfer gem5's CPUID values into the virtual CPU.
Definition: x86_cpu.cc:1424
X86KvmCPU::getMSRs
void getMSRs(struct kvm_msrs &msrs) const
Definition: x86_cpu.cc:1500
BaseCPU::params
const Params * params() const
Definition: base.hh:296
X86KvmCPU::useXSave
bool useXSave
Should the XSave interface be used to sync the FPU and SIMD registers?
Definition: x86_cpu.hh:247
X86KvmCPU::updateThreadContextXSave
void updateThreadContextXSave(const struct kvm_xsave &kxsave)
Update FPU and SIMD registers using the XSave API.
Definition: x86_cpu.cc:1088
base.hh
vm.hh
X86KvmCPU::updateKvmStateFPU
void updateKvmStateFPU()
Update FPU and SIMD registers.
Definition: x86_cpu.cc:907
X86KvmCPU::setXSave
void setXSave(const struct kvm_xsave &xsave)
Definition: x86_cpu.cc:1604
X86KvmCPU::setVCpuEvents
void setVCpuEvents(const struct kvm_vcpu_events &events)
Definition: x86_cpu.cc:1619
X86KvmCPU::~X86KvmCPU
virtual ~X86KvmCPU()
Definition: x86_cpu.cc:551
X86KvmCPU::dumpSpecRegs
void dumpSpecRegs() const
Definition: x86_cpu.cc:601
X86KvmCPU::dumpMSRs
void dumpMSRs() const
Definition: x86_cpu.cc:655
X86KvmCPU::getDebugRegisters
void getDebugRegisters(struct kvm_debugregs &regs) const
Wrappers around KVM's state transfer methods.
Definition: x86_cpu.cc:1561
X86KvmCPU::haveXCRs
bool haveXCRs
Kvm::capXCRs() available?
Definition: x86_cpu.hh:249
X86KvmCPU::updateKvmStateSRegs
void updateKvmStateSRegs()
Update control registers (CRx, segments, etc.)
Definition: x86_cpu.cc:755
X86KvmCPU::updateKvmStateRegs
void updateKvmStateRegs()
Support routines to update the state of the KVM CPU from gem5's state representation.
Definition: x86_cpu.cc:688
X86KvmCPU::updateKvmState
void updateKvmState() override
Update the KVM state from the current thread context.
Definition: x86_cpu.cc:675
X86KvmCPU::updateKvmStateFPUXSave
void updateKvmStateFPUXSave()
Update FPU and SIMD registers using the XSave API.
Definition: x86_cpu.cc:882
X86KvmCPU::setXCRs
void setXCRs(const struct kvm_xcrs &regs)
Definition: x86_cpu.cc:1590
X86KvmCPU::updateThreadContextSRegs
void updateThreadContextSRegs(const struct kvm_sregs &sregs)
Update control registers (CRx, segments, etc.)
Definition: x86_cpu.cc:1026
X86KvmCPU::cachedMsrIntersection
Kvm::MSRIndexVector cachedMsrIntersection
Cached intersection of supported MSRs.
Definition: x86_cpu.hh:236

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17