15abf9495SPeter Crosthwaite /* 25abf9495SPeter Crosthwaite * emulator main execution loop 35abf9495SPeter Crosthwaite * 45abf9495SPeter Crosthwaite * Copyright (c) 2003-2005 Fabrice Bellard 55abf9495SPeter Crosthwaite * 65abf9495SPeter Crosthwaite * This library is free software; you can redistribute it and/or 75abf9495SPeter Crosthwaite * modify it under the terms of the GNU Lesser General Public 85abf9495SPeter Crosthwaite * License as published by the Free Software Foundation; either 9fb0343d5SThomas Huth * version 2.1 of the License, or (at your option) any later version. 105abf9495SPeter Crosthwaite * 115abf9495SPeter Crosthwaite * This library is distributed in the hope that it will be useful, 125abf9495SPeter Crosthwaite * but WITHOUT ANY WARRANTY; without even the implied warranty of 135abf9495SPeter Crosthwaite * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 145abf9495SPeter Crosthwaite * Lesser General Public License for more details. 155abf9495SPeter Crosthwaite * 165abf9495SPeter Crosthwaite * You should have received a copy of the GNU Lesser General Public 175abf9495SPeter Crosthwaite * License along with this library; if not, see <http://www.gnu.org/licenses/>. 185abf9495SPeter Crosthwaite */ 195abf9495SPeter Crosthwaite 207b31bbc2SPeter Maydell #include "qemu/osdep.h" 215abf9495SPeter Crosthwaite #include "sysemu/cpus.h" 2214a48c1dSMarkus Armbruster #include "sysemu/tcg.h" 2363c91552SPaolo Bonzini #include "exec/exec-all.h" 24*720ace24SRichard Henderson #include "qemu/plugin.h" 255abf9495SPeter Crosthwaite 268e2b7299SYang Zhong bool tcg_allowed; 278e2b7299SYang Zhong 286886b980SPeter Maydell /* exit the current TB, but without causing any exception to be raised */ 296886b980SPeter Maydell void cpu_loop_exit_noexc(CPUState *cpu) 305abf9495SPeter Crosthwaite { 315abf9495SPeter Crosthwaite cpu->exception_index = -1; 32afd46fcaSPavel Dovgalyuk cpu_loop_exit(cpu); 335abf9495SPeter Crosthwaite } 345abf9495SPeter Crosthwaite 35f213e72fSPeter Maydell #if defined(CONFIG_SOFTMMU) 3632857f4dSPeter Maydell void cpu_reloading_memory_map(void) 375abf9495SPeter Crosthwaite { 3885390939SAlex Bennée if (qemu_in_vcpu_thread() && current_cpu->running) { 3953f8a5e9SPeter Maydell /* The guest can in theory prolong the RCU critical section as long 4053f8a5e9SPeter Maydell * as it feels like. The major problem with this is that because it 4153f8a5e9SPeter Maydell * can do multiple reconfigurations of the memory map within the 4253f8a5e9SPeter Maydell * critical section, we could potentially accumulate an unbounded 4353f8a5e9SPeter Maydell * collection of memory data structures awaiting reclamation. 445abf9495SPeter Crosthwaite * 4553f8a5e9SPeter Maydell * Because the only thing we're currently protecting with RCU is the 4653f8a5e9SPeter Maydell * memory data structures, it's sufficient to break the critical section 4753f8a5e9SPeter Maydell * in this callback, which we know will get called every time the 4853f8a5e9SPeter Maydell * memory map is rearranged. 4953f8a5e9SPeter Maydell * 5053f8a5e9SPeter Maydell * (If we add anything else in the system that uses RCU to protect 5153f8a5e9SPeter Maydell * its data structures, we will need to implement some other mechanism 5253f8a5e9SPeter Maydell * to force TCG CPUs to exit the critical section, at which point this 5353f8a5e9SPeter Maydell * part of this callback might become unnecessary.) 545abf9495SPeter Crosthwaite * 555abf9495SPeter Crosthwaite * This pair matches cpu_exec's rcu_read_lock()/rcu_read_unlock(), which 5632857f4dSPeter Maydell * only protects cpu->as->dispatch. Since we know our caller is about 5732857f4dSPeter Maydell * to reload it, it's safe to split the critical section. 585abf9495SPeter Crosthwaite */ 595abf9495SPeter Crosthwaite rcu_read_unlock(); 605abf9495SPeter Crosthwaite rcu_read_lock(); 615abf9495SPeter Crosthwaite } 625abf9495SPeter Crosthwaite } 635abf9495SPeter Crosthwaite #endif 645abf9495SPeter Crosthwaite 655abf9495SPeter Crosthwaite void cpu_loop_exit(CPUState *cpu) 665abf9495SPeter Crosthwaite { 67afd46fcaSPavel Dovgalyuk /* Undo the setting in cpu_tb_exec. */ 68afd46fcaSPavel Dovgalyuk cpu->can_do_io = 1; 69e04660afSRichard Henderson /* Undo any setting in generated code. */ 70e04660afSRichard Henderson qemu_plugin_disable_mem_helpers(cpu); 715abf9495SPeter Crosthwaite siglongjmp(cpu->jmp_env, 1); 725abf9495SPeter Crosthwaite } 735abf9495SPeter Crosthwaite 745abf9495SPeter Crosthwaite void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc) 755abf9495SPeter Crosthwaite { 765abf9495SPeter Crosthwaite if (pc) { 773d419a4dSRichard Henderson cpu_restore_state(cpu, pc); 785abf9495SPeter Crosthwaite } 79afd46fcaSPavel Dovgalyuk cpu_loop_exit(cpu); 805abf9495SPeter Crosthwaite } 81fdbc2b57SRichard Henderson 82fdbc2b57SRichard Henderson void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc) 83fdbc2b57SRichard Henderson { 84fdbc2b57SRichard Henderson cpu->exception_index = EXCP_ATOMIC; 85fdbc2b57SRichard Henderson cpu_loop_exit_restore(cpu, pc); 86fdbc2b57SRichard Henderson } 87