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" 23*63c91552SPaolo 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 295abf9495SPeter Crosthwaite /* exit the current TB from a signal handler. The host registers are 305abf9495SPeter Crosthwaite restored in a state compatible with the CPU emulator 315abf9495SPeter Crosthwaite */ 325abf9495SPeter Crosthwaite #if defined(CONFIG_SOFTMMU) 335abf9495SPeter Crosthwaite void cpu_resume_from_signal(CPUState *cpu, void *puc) 345abf9495SPeter Crosthwaite { 355abf9495SPeter Crosthwaite /* XXX: restore cpu registers saved in host registers */ 365abf9495SPeter Crosthwaite 375abf9495SPeter Crosthwaite cpu->exception_index = -1; 385abf9495SPeter Crosthwaite siglongjmp(cpu->jmp_env, 1); 395abf9495SPeter Crosthwaite } 405abf9495SPeter Crosthwaite 4132857f4dSPeter Maydell void cpu_reloading_memory_map(void) 425abf9495SPeter Crosthwaite { 435abf9495SPeter Crosthwaite if (qemu_in_vcpu_thread()) { 4453f8a5e9SPeter Maydell /* The guest can in theory prolong the RCU critical section as long 4553f8a5e9SPeter Maydell * as it feels like. The major problem with this is that because it 4653f8a5e9SPeter Maydell * can do multiple reconfigurations of the memory map within the 4753f8a5e9SPeter Maydell * critical section, we could potentially accumulate an unbounded 4853f8a5e9SPeter Maydell * collection of memory data structures awaiting reclamation. 495abf9495SPeter Crosthwaite * 5053f8a5e9SPeter Maydell * Because the only thing we're currently protecting with RCU is the 5153f8a5e9SPeter Maydell * memory data structures, it's sufficient to break the critical section 5253f8a5e9SPeter Maydell * in this callback, which we know will get called every time the 5353f8a5e9SPeter Maydell * memory map is rearranged. 5453f8a5e9SPeter Maydell * 5553f8a5e9SPeter Maydell * (If we add anything else in the system that uses RCU to protect 5653f8a5e9SPeter Maydell * its data structures, we will need to implement some other mechanism 5753f8a5e9SPeter Maydell * to force TCG CPUs to exit the critical section, at which point this 5853f8a5e9SPeter Maydell * part of this callback might become unnecessary.) 595abf9495SPeter Crosthwaite * 605abf9495SPeter Crosthwaite * This pair matches cpu_exec's rcu_read_lock()/rcu_read_unlock(), which 6132857f4dSPeter Maydell * only protects cpu->as->dispatch. Since we know our caller is about 6232857f4dSPeter Maydell * to reload it, it's safe to split the critical section. 635abf9495SPeter Crosthwaite */ 645abf9495SPeter Crosthwaite rcu_read_unlock(); 655abf9495SPeter Crosthwaite rcu_read_lock(); 665abf9495SPeter Crosthwaite } 675abf9495SPeter Crosthwaite } 685abf9495SPeter Crosthwaite #endif 695abf9495SPeter Crosthwaite 705abf9495SPeter Crosthwaite void cpu_loop_exit(CPUState *cpu) 715abf9495SPeter Crosthwaite { 725abf9495SPeter Crosthwaite siglongjmp(cpu->jmp_env, 1); 735abf9495SPeter Crosthwaite } 745abf9495SPeter Crosthwaite 755abf9495SPeter Crosthwaite void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc) 765abf9495SPeter Crosthwaite { 775abf9495SPeter Crosthwaite if (pc) { 785abf9495SPeter Crosthwaite cpu_restore_state(cpu, pc); 795abf9495SPeter Crosthwaite } 805abf9495SPeter Crosthwaite siglongjmp(cpu->jmp_env, 1); 815abf9495SPeter Crosthwaite } 82