2
0

cpu-exec-common.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * emulator main execution loop
  3. *
  4. * Copyright (c) 2003-2005 Fabrice Bellard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "config.h"
  20. #include "cpu.h"
  21. #include "sysemu/cpus.h"
  22. #include "exec/memory-internal.h"
  23. bool exit_request;
  24. CPUState *tcg_current_cpu;
  25. /* exit the current TB from a signal handler. The host registers are
  26. restored in a state compatible with the CPU emulator
  27. */
  28. #if defined(CONFIG_SOFTMMU)
  29. void cpu_resume_from_signal(CPUState *cpu, void *puc)
  30. {
  31. /* XXX: restore cpu registers saved in host registers */
  32. cpu->exception_index = -1;
  33. siglongjmp(cpu->jmp_env, 1);
  34. }
  35. void cpu_reload_memory_map(CPUState *cpu)
  36. {
  37. AddressSpaceDispatch *d;
  38. if (qemu_in_vcpu_thread()) {
  39. /* Do not let the guest prolong the critical section as much as it
  40. * as it desires.
  41. *
  42. * Currently, this is prevented by the I/O thread's periodinc kicking
  43. * of the VCPU thread (iothread_requesting_mutex, qemu_cpu_kick_thread)
  44. * but this will go away once TCG's execution moves out of the global
  45. * mutex.
  46. *
  47. * This pair matches cpu_exec's rcu_read_lock()/rcu_read_unlock(), which
  48. * only protects cpu->as->dispatch. Since we reload it below, we can
  49. * split the critical section.
  50. */
  51. rcu_read_unlock();
  52. rcu_read_lock();
  53. }
  54. /* The CPU and TLB are protected by the iothread lock. */
  55. d = atomic_rcu_read(&cpu->as->dispatch);
  56. cpu->memory_dispatch = d;
  57. tlb_flush(cpu, 1);
  58. }
  59. #endif
  60. void cpu_loop_exit(CPUState *cpu)
  61. {
  62. cpu->current_tb = NULL;
  63. siglongjmp(cpu->jmp_env, 1);
  64. }
  65. void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)
  66. {
  67. if (pc) {
  68. cpu_restore_state(cpu, pc);
  69. }
  70. cpu->current_tb = NULL;
  71. siglongjmp(cpu->jmp_env, 1);
  72. }