kvm_emulate.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  3. * Author: Christoffer Dall <c.dall@virtualopensystems.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License, version 2, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef __ARM_KVM_EMULATE_H__
  19. #define __ARM_KVM_EMULATE_H__
  20. #include <linux/kvm_host.h>
  21. #include <asm/kvm_asm.h>
  22. #include <asm/kvm_mmio.h>
  23. #include <asm/kvm_arm.h>
  24. unsigned long *vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num);
  25. unsigned long *vcpu_spsr(struct kvm_vcpu *vcpu);
  26. int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run);
  27. void kvm_skip_instr(struct kvm_vcpu *vcpu, bool is_wide_instr);
  28. void kvm_inject_undefined(struct kvm_vcpu *vcpu);
  29. void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
  30. void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
  31. static inline bool vcpu_mode_is_32bit(struct kvm_vcpu *vcpu)
  32. {
  33. return 1;
  34. }
  35. static inline unsigned long *vcpu_pc(struct kvm_vcpu *vcpu)
  36. {
  37. return &vcpu->arch.regs.usr_regs.ARM_pc;
  38. }
  39. static inline unsigned long *vcpu_cpsr(struct kvm_vcpu *vcpu)
  40. {
  41. return &vcpu->arch.regs.usr_regs.ARM_cpsr;
  42. }
  43. static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)
  44. {
  45. *vcpu_cpsr(vcpu) |= PSR_T_BIT;
  46. }
  47. static inline bool mode_has_spsr(struct kvm_vcpu *vcpu)
  48. {
  49. unsigned long cpsr_mode = vcpu->arch.regs.usr_regs.ARM_cpsr & MODE_MASK;
  50. return (cpsr_mode > USR_MODE && cpsr_mode < SYSTEM_MODE);
  51. }
  52. static inline bool vcpu_mode_priv(struct kvm_vcpu *vcpu)
  53. {
  54. unsigned long cpsr_mode = vcpu->arch.regs.usr_regs.ARM_cpsr & MODE_MASK;
  55. return cpsr_mode > USR_MODE;;
  56. }
  57. static inline bool kvm_vcpu_reg_is_pc(struct kvm_vcpu *vcpu, int reg)
  58. {
  59. return reg == 15;
  60. }
  61. static inline u32 kvm_vcpu_get_hsr(struct kvm_vcpu *vcpu)
  62. {
  63. return vcpu->arch.fault.hsr;
  64. }
  65. static inline unsigned long kvm_vcpu_get_hfar(struct kvm_vcpu *vcpu)
  66. {
  67. return vcpu->arch.fault.hxfar;
  68. }
  69. static inline phys_addr_t kvm_vcpu_get_fault_ipa(struct kvm_vcpu *vcpu)
  70. {
  71. return ((phys_addr_t)vcpu->arch.fault.hpfar & HPFAR_MASK) << 8;
  72. }
  73. static inline unsigned long kvm_vcpu_get_hyp_pc(struct kvm_vcpu *vcpu)
  74. {
  75. return vcpu->arch.fault.hyp_pc;
  76. }
  77. static inline bool kvm_vcpu_dabt_isvalid(struct kvm_vcpu *vcpu)
  78. {
  79. return kvm_vcpu_get_hsr(vcpu) & HSR_ISV;
  80. }
  81. static inline bool kvm_vcpu_dabt_iswrite(struct kvm_vcpu *vcpu)
  82. {
  83. return kvm_vcpu_get_hsr(vcpu) & HSR_WNR;
  84. }
  85. static inline bool kvm_vcpu_dabt_issext(struct kvm_vcpu *vcpu)
  86. {
  87. return kvm_vcpu_get_hsr(vcpu) & HSR_SSE;
  88. }
  89. #endif /* __ARM_KVM_EMULATE_H__ */