4 * Copyright (c) 2003-2008 Fabrice Bellard
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.
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.
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/>.
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
23 #include "user-internals.h"
24 #include "cpu_loop-common.h"
25 #include "signal-common.h"
28 static int get_pgm_data_si_code(int dxc_code)
31 /* Non-simulated IEEE exceptions */
33 return TARGET_FPE_FLTINV;
35 return TARGET_FPE_FLTDIV;
39 return TARGET_FPE_FLTOVF;
43 return TARGET_FPE_FLTUND;
46 return TARGET_FPE_FLTRES;
49 * Non-IEEE and simulated IEEE:
50 * Includes compare-and-trap, quantum exception, etc.
51 * Simulated IEEE are included here to match current
57 void cpu_loop(CPUS390XState *env)
59 CPUState *cs = env_cpu(env);
66 trapnr = cpu_exec(cs);
68 process_queued_cpu_work(cs);
72 /* Just indicate that signals should be handled asap. */
76 n = env->int_svc_code;
81 env->psw.addr += env->int_svc_ilen;
82 ret = do_syscall(env, n, env->regs[2], env->regs[3],
83 env->regs[4], env->regs[5],
84 env->regs[6], env->regs[7], 0, 0);
85 if (ret == -QEMU_ERESTARTSYS) {
86 env->psw.addr -= env->int_svc_ilen;
87 } else if (ret != -QEMU_ESIGRETURN) {
94 n = TARGET_TRAP_BRKPT;
96 * For SIGTRAP the PSW must point after the instruction, which it
97 * already does thanks to s390x_tr_tb_stop(). si_addr doesn't need
103 n = env->int_pgm_code;
108 n = TARGET_ILL_ILLOPC;
111 force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_ACCERR,
115 force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR,
119 case PGM_SPECIFICATION:
124 n = TARGET_ILL_ILLOPN;
127 case PGM_FIXPT_OVERFLOW:
129 n = TARGET_FPE_INTOVF;
131 case PGM_FIXPT_DIVIDE:
133 n = TARGET_FPE_INTDIV;
137 n = (env->fpc >> 8) & 0xff;
143 n = get_pgm_data_si_code(n);
147 fprintf(stderr, "Unhandled program exception: %#x\n", n);
148 cpu_dump_state(cs, stderr, 0);
154 addr = env->psw.addr;
156 * For SIGILL and SIGFPE the PSW must point after the instruction.
158 env->psw.addr += env->int_pgm_ilen;
160 force_sig_fault(sig, n, addr);
164 cpu_exec_step_atomic(cs);
167 fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
168 cpu_dump_state(cs, stderr, 0);
171 process_pending_signals (env);
175 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
178 for (i = 0; i < 16; i++) {
179 env->regs[i] = regs->gprs[i];
181 env->psw.mask = regs->psw.mask;
182 env->psw.addr = regs->psw.addr;