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 95abf9495SPeter Crosthwaite * version 2 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 "cpu.h" 225abf9495SPeter Crosthwaite #include "sysemu/cpus.h" 2363c91552SPaolo Bonzini #include "exec/exec-all.h" 245abf9495SPeter Crosthwaite #include "exec/memory-internal.h" 255abf9495SPeter Crosthwaite 265abf9495SPeter Crosthwaite bool exit_request; 275abf9495SPeter Crosthwaite CPUState *tcg_current_cpu; 285abf9495SPeter Crosthwaite 296886b980SPeter Maydell /* exit the current TB, but without causing any exception to be raised */ 306886b980SPeter Maydell void cpu_loop_exit_noexc(CPUState *cpu) 315abf9495SPeter Crosthwaite { 325abf9495SPeter Crosthwaite /* XXX: restore cpu registers saved in host registers */ 335abf9495SPeter Crosthwaite 345abf9495SPeter Crosthwaite cpu->exception_index = -1; 355abf9495SPeter Crosthwaite siglongjmp(cpu->jmp_env, 1); 365abf9495SPeter Crosthwaite } 375abf9495SPeter Crosthwaite 38f213e72fSPeter Maydell #if defined(CONFIG_SOFTMMU) 3932857f4dSPeter Maydell void cpu_reloading_memory_map(void) 405abf9495SPeter Crosthwaite { 415abf9495SPeter Crosthwaite if (qemu_in_vcpu_thread()) { 4253f8a5e9SPeter Maydell /* The guest can in theory prolong the RCU critical section as long 4353f8a5e9SPeter Maydell * as it feels like. The major problem with this is that because it 4453f8a5e9SPeter Maydell * can do multiple reconfigurations of the memory map within the 4553f8a5e9SPeter Maydell * critical section, we could potentially accumulate an unbounded 4653f8a5e9SPeter Maydell * collection of memory data structures awaiting reclamation. 475abf9495SPeter Crosthwaite * 4853f8a5e9SPeter Maydell * Because the only thing we're currently protecting with RCU is the 4953f8a5e9SPeter Maydell * memory data structures, it's sufficient to break the critical section 5053f8a5e9SPeter Maydell * in this callback, which we know will get called every time the 5153f8a5e9SPeter Maydell * memory map is rearranged. 5253f8a5e9SPeter Maydell * 5353f8a5e9SPeter Maydell * (If we add anything else in the system that uses RCU to protect 5453f8a5e9SPeter Maydell * its data structures, we will need to implement some other mechanism 5553f8a5e9SPeter Maydell * to force TCG CPUs to exit the critical section, at which point this 5653f8a5e9SPeter Maydell * part of this callback might become unnecessary.) 575abf9495SPeter Crosthwaite * 585abf9495SPeter Crosthwaite * This pair matches cpu_exec's rcu_read_lock()/rcu_read_unlock(), which 5932857f4dSPeter Maydell * only protects cpu->as->dispatch. Since we know our caller is about 6032857f4dSPeter Maydell * to reload it, it's safe to split the critical section. 615abf9495SPeter Crosthwaite */ 625abf9495SPeter Crosthwaite rcu_read_unlock(); 635abf9495SPeter Crosthwaite rcu_read_lock(); 645abf9495SPeter Crosthwaite } 655abf9495SPeter Crosthwaite } 665abf9495SPeter Crosthwaite #endif 675abf9495SPeter Crosthwaite 685abf9495SPeter Crosthwaite void cpu_loop_exit(CPUState *cpu) 695abf9495SPeter Crosthwaite { 705abf9495SPeter Crosthwaite siglongjmp(cpu->jmp_env, 1); 715abf9495SPeter Crosthwaite } 725abf9495SPeter Crosthwaite 735abf9495SPeter Crosthwaite void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc) 745abf9495SPeter Crosthwaite { 755abf9495SPeter Crosthwaite if (pc) { 765abf9495SPeter Crosthwaite cpu_restore_state(cpu, pc); 775abf9495SPeter Crosthwaite } 785abf9495SPeter Crosthwaite siglongjmp(cpu->jmp_env, 1); 795abf9495SPeter Crosthwaite } 80*fdbc2b57SRichard Henderson 81*fdbc2b57SRichard Henderson void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc) 82*fdbc2b57SRichard Henderson { 83*fdbc2b57SRichard Henderson cpu->exception_index = EXCP_ATOMIC; 84*fdbc2b57SRichard Henderson cpu_loop_exit_restore(cpu, pc); 85*fdbc2b57SRichard Henderson } 86