tcg-cpu-ops.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * TCG CPU-specific operations
  3. *
  4. * Copyright 2021 SUSE LLC
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. */
  9. #ifndef TCG_CPU_OPS_H
  10. #define TCG_CPU_OPS_H
  11. #include "hw/core/cpu.h"
  12. struct TCGCPUOps {
  13. /**
  14. * @initialize: Initalize TCG state
  15. *
  16. * Called when the first CPU is realized.
  17. */
  18. void (*initialize)(void);
  19. /**
  20. * @synchronize_from_tb: Synchronize state from a TCG #TranslationBlock
  21. *
  22. * This is called when we abandon execution of a TB before starting it,
  23. * and must set all parts of the CPU state which the previous TB in the
  24. * chain may not have updated.
  25. * By default, when this is NULL, a call is made to @set_pc(tb->pc).
  26. *
  27. * If more state needs to be restored, the target must implement a
  28. * function to restore all the state, and register it here.
  29. */
  30. void (*synchronize_from_tb)(CPUState *cpu, const TranslationBlock *tb);
  31. /** @cpu_exec_enter: Callback for cpu_exec preparation */
  32. void (*cpu_exec_enter)(CPUState *cpu);
  33. /** @cpu_exec_exit: Callback for cpu_exec cleanup */
  34. void (*cpu_exec_exit)(CPUState *cpu);
  35. /**
  36. * @tlb_fill: Handle a softmmu tlb miss or user-only address fault
  37. *
  38. * For system mode, if the access is valid, call tlb_set_page
  39. * and return true; if the access is invalid, and probe is
  40. * true, return false; otherwise raise an exception and do
  41. * not return. For user-only mode, always raise an exception
  42. * and do not return.
  43. */
  44. bool (*tlb_fill)(CPUState *cpu, vaddr address, int size,
  45. MMUAccessType access_type, int mmu_idx,
  46. bool probe, uintptr_t retaddr);
  47. /** @debug_excp_handler: Callback for handling debug exceptions */
  48. void (*debug_excp_handler)(CPUState *cpu);
  49. #ifdef NEED_CPU_H
  50. #if defined(CONFIG_USER_ONLY) && defined(TARGET_I386)
  51. /**
  52. * @fake_user_interrupt: Callback for 'fake exception' handling.
  53. *
  54. * Simulate 'fake exception' which will be handled outside the
  55. * cpu execution loop (hack for x86 user mode).
  56. */
  57. void (*fake_user_interrupt)(CPUState *cpu);
  58. #else
  59. /**
  60. * @do_interrupt: Callback for interrupt handling.
  61. */
  62. void (*do_interrupt)(CPUState *cpu);
  63. #endif /* !CONFIG_USER_ONLY || !TARGET_I386 */
  64. #ifdef CONFIG_SOFTMMU
  65. /** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */
  66. bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
  67. /**
  68. * @do_transaction_failed: Callback for handling failed memory transactions
  69. * (ie bus faults or external aborts; not MMU faults)
  70. */
  71. void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
  72. unsigned size, MMUAccessType access_type,
  73. int mmu_idx, MemTxAttrs attrs,
  74. MemTxResult response, uintptr_t retaddr);
  75. /**
  76. * @do_unaligned_access: Callback for unaligned access handling
  77. * The callback must exit via raising an exception.
  78. */
  79. void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
  80. MMUAccessType access_type,
  81. int mmu_idx, uintptr_t retaddr) QEMU_NORETURN;
  82. /**
  83. * @adjust_watchpoint_address: hack for cpu_check_watchpoint used by ARM
  84. */
  85. vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
  86. /**
  87. * @debug_check_watchpoint: return true if the architectural
  88. * watchpoint whose address has matched should really fire, used by ARM
  89. */
  90. bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
  91. /**
  92. * @debug_check_breakpoint: return true if the architectural
  93. * breakpoint whose PC has matched should really fire.
  94. */
  95. bool (*debug_check_breakpoint)(CPUState *cpu);
  96. /**
  97. * @io_recompile_replay_branch: Callback for cpu_io_recompile.
  98. *
  99. * The cpu has been stopped, and cpu_restore_state_from_tb has been
  100. * called. If the faulting instruction is in a delay slot, and the
  101. * target architecture requires re-execution of the branch, then
  102. * adjust the cpu state as required and return true.
  103. */
  104. bool (*io_recompile_replay_branch)(CPUState *cpu,
  105. const TranslationBlock *tb);
  106. #endif /* CONFIG_SOFTMMU */
  107. #endif /* NEED_CPU_H */
  108. };
  109. #endif /* TCG_CPU_OPS_H */