1 /* 2 * qemu user cpu loop 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program 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 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "qemu/osdep.h" 21 #include "qemu-common.h" 22 #include "qemu.h" 23 #include "cpu_loop-common.h" 24 #include "signal-common.h" 25 26 void cpu_loop(CPUOpenRISCState *env) 27 { 28 CPUState *cs = env_cpu(env); 29 int trapnr; 30 abi_long ret; 31 target_siginfo_t info; 32 33 for (;;) { 34 cpu_exec_start(cs); 35 trapnr = cpu_exec(cs); 36 cpu_exec_end(cs); 37 process_queued_cpu_work(cs); 38 39 switch (trapnr) { 40 case EXCP_SYSCALL: 41 env->pc += 4; /* 0xc00; */ 42 ret = do_syscall(env, 43 cpu_get_gpr(env, 11), /* return value */ 44 cpu_get_gpr(env, 3), /* r3 - r7 are params */ 45 cpu_get_gpr(env, 4), 46 cpu_get_gpr(env, 5), 47 cpu_get_gpr(env, 6), 48 cpu_get_gpr(env, 7), 49 cpu_get_gpr(env, 8), 0, 0); 50 if (ret == -TARGET_ERESTARTSYS) { 51 env->pc -= 4; 52 } else if (ret != -TARGET_QEMU_ESIGRETURN) { 53 cpu_set_gpr(env, 11, ret); 54 } 55 break; 56 case EXCP_DPF: 57 case EXCP_IPF: 58 case EXCP_RANGE: 59 info.si_signo = TARGET_SIGSEGV; 60 info.si_errno = 0; 61 info.si_code = TARGET_SEGV_MAPERR; 62 info._sifields._sigfault._addr = env->pc; 63 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 64 break; 65 case EXCP_ALIGN: 66 info.si_signo = TARGET_SIGBUS; 67 info.si_errno = 0; 68 info.si_code = TARGET_BUS_ADRALN; 69 info._sifields._sigfault._addr = env->pc; 70 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 71 break; 72 case EXCP_ILLEGAL: 73 info.si_signo = TARGET_SIGILL; 74 info.si_errno = 0; 75 info.si_code = TARGET_ILL_ILLOPC; 76 info._sifields._sigfault._addr = env->pc; 77 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 78 break; 79 case EXCP_FPE: 80 info.si_signo = TARGET_SIGFPE; 81 info.si_errno = 0; 82 info.si_code = 0; 83 info._sifields._sigfault._addr = env->pc; 84 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 85 break; 86 case EXCP_INTERRUPT: 87 /* We processed the pending cpu work above. */ 88 break; 89 case EXCP_DEBUG: 90 info.si_signo = TARGET_SIGTRAP; 91 info.si_errno = 0; 92 info.si_code = TARGET_TRAP_BRKPT; 93 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 94 break; 95 case EXCP_ATOMIC: 96 cpu_exec_step_atomic(cs); 97 break; 98 default: 99 g_assert_not_reached(); 100 } 101 process_pending_signals(env); 102 } 103 } 104 105 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) 106 { 107 int i; 108 109 for (i = 0; i < 32; i++) { 110 cpu_set_gpr(env, i, regs->gpr[i]); 111 } 112 env->pc = regs->pc; 113 cpu_set_sr(env, regs->sr); 114 } 115