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