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(CPUM68KState *env) 27 { 28 CPUState *cs = env_cpu(env); 29 int trapnr; 30 unsigned int n; 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_HALT_INSN: 41 /* Semihosing syscall. */ 42 env->pc += 4; 43 do_m68k_semihosting(env, env->dregs[0]); 44 break; 45 case EXCP_ILLEGAL: 46 case EXCP_LINEA: 47 case EXCP_LINEF: 48 info.si_signo = TARGET_SIGILL; 49 info.si_errno = 0; 50 info.si_code = TARGET_ILL_ILLOPN; 51 info._sifields._sigfault._addr = env->pc; 52 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 53 break; 54 case EXCP_CHK: 55 info.si_signo = TARGET_SIGFPE; 56 info.si_errno = 0; 57 info.si_code = TARGET_FPE_INTOVF; 58 info._sifields._sigfault._addr = env->pc; 59 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 60 break; 61 case EXCP_DIV0: 62 info.si_signo = TARGET_SIGFPE; 63 info.si_errno = 0; 64 info.si_code = TARGET_FPE_INTDIV; 65 info._sifields._sigfault._addr = env->pc; 66 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 67 break; 68 case EXCP_TRAP0: 69 { 70 abi_long ret; 71 n = env->dregs[0]; 72 env->pc += 2; 73 ret = do_syscall(env, 74 n, 75 env->dregs[1], 76 env->dregs[2], 77 env->dregs[3], 78 env->dregs[4], 79 env->dregs[5], 80 env->aregs[0], 81 0, 0); 82 if (ret == -TARGET_ERESTARTSYS) { 83 env->pc -= 2; 84 } else if (ret != -TARGET_QEMU_ESIGRETURN) { 85 env->dregs[0] = ret; 86 } 87 } 88 break; 89 case EXCP_INTERRUPT: 90 /* just indicate that signals should be handled asap */ 91 break; 92 case EXCP_ACCESS: 93 { 94 info.si_signo = TARGET_SIGSEGV; 95 info.si_errno = 0; 96 /* XXX: check env->error_code */ 97 info.si_code = TARGET_SEGV_MAPERR; 98 info._sifields._sigfault._addr = env->mmu.ar; 99 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 100 } 101 break; 102 case EXCP_DEBUG: 103 info.si_signo = TARGET_SIGTRAP; 104 info.si_errno = 0; 105 info.si_code = TARGET_TRAP_BRKPT; 106 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 107 break; 108 case EXCP_ATOMIC: 109 cpu_exec_step_atomic(cs); 110 break; 111 default: 112 EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr); 113 abort(); 114 } 115 process_pending_signals(env); 116 } 117 } 118 119 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) 120 { 121 CPUState *cpu = env_cpu(env); 122 TaskState *ts = cpu->opaque; 123 struct image_info *info = ts->info; 124 125 env->pc = regs->pc; 126 env->dregs[0] = regs->d0; 127 env->dregs[1] = regs->d1; 128 env->dregs[2] = regs->d2; 129 env->dregs[3] = regs->d3; 130 env->dregs[4] = regs->d4; 131 env->dregs[5] = regs->d5; 132 env->dregs[6] = regs->d6; 133 env->dregs[7] = regs->d7; 134 env->aregs[0] = regs->a0; 135 env->aregs[1] = regs->a1; 136 env->aregs[2] = regs->a2; 137 env->aregs[3] = regs->a3; 138 env->aregs[4] = regs->a4; 139 env->aregs[5] = regs->a5; 140 env->aregs[6] = regs->a6; 141 env->aregs[7] = regs->usp; 142 env->sr = regs->sr; 143 144 ts->stack_base = info->start_stack; 145 ts->heap_base = info->brk; 146 /* This will be filled in on the first SYS_HEAPINFO call. */ 147 ts->heap_limit = 0; 148 } 149