cpu_loop.c (3513B)
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 "user-internals.h" 24#include "cpu_loop-common.h" 25#include "signal-common.h" 26 27void cpu_loop(CPUCRISState *env) 28{ 29 CPUState *cs = env_cpu(env); 30 int trapnr, ret; 31 target_siginfo_t info; 32 33 while (1) { 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 0xaa: 41 { 42 info.si_signo = TARGET_SIGSEGV; 43 info.si_errno = 0; 44 /* XXX: check env->error_code */ 45 info.si_code = TARGET_SEGV_MAPERR; 46 info._sifields._sigfault._addr = env->pregs[PR_EDA]; 47 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 48 } 49 break; 50 case EXCP_INTERRUPT: 51 /* just indicate that signals should be handled asap */ 52 break; 53 case EXCP_BREAK: 54 ret = do_syscall(env, 55 env->regs[9], 56 env->regs[10], 57 env->regs[11], 58 env->regs[12], 59 env->regs[13], 60 env->pregs[7], 61 env->pregs[11], 62 0, 0); 63 if (ret == -TARGET_ERESTARTSYS) { 64 env->pc -= 2; 65 } else if (ret != -TARGET_QEMU_ESIGRETURN) { 66 env->regs[10] = ret; 67 } 68 break; 69 case EXCP_DEBUG: 70 info.si_signo = TARGET_SIGTRAP; 71 info.si_errno = 0; 72 info.si_code = TARGET_TRAP_BRKPT; 73 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); 74 break; 75 case EXCP_ATOMIC: 76 cpu_exec_step_atomic(cs); 77 break; 78 default: 79 fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr); 80 cpu_dump_state(cs, stderr, 0); 81 exit(EXIT_FAILURE); 82 } 83 process_pending_signals (env); 84 } 85} 86 87void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) 88{ 89 CPUState *cpu = env_cpu(env); 90 TaskState *ts = cpu->opaque; 91 struct image_info *info = ts->info; 92 93 env->regs[0] = regs->r0; 94 env->regs[1] = regs->r1; 95 env->regs[2] = regs->r2; 96 env->regs[3] = regs->r3; 97 env->regs[4] = regs->r4; 98 env->regs[5] = regs->r5; 99 env->regs[6] = regs->r6; 100 env->regs[7] = regs->r7; 101 env->regs[8] = regs->r8; 102 env->regs[9] = regs->r9; 103 env->regs[10] = regs->r10; 104 env->regs[11] = regs->r11; 105 env->regs[12] = regs->r12; 106 env->regs[13] = regs->r13; 107 env->regs[14] = info->start_stack; 108 env->regs[15] = regs->acr; 109 env->pc = regs->erp; 110}