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 "cpu_loop-common.h"
25 /* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */
26 #define S390X_FAIL_ADDR_MASK -4096LL
28 void cpu_loop(CPUS390XState
*env
)
30 CPUState
*cs
= env_cpu(env
);
32 target_siginfo_t info
;
38 trapnr
= cpu_exec(cs
);
40 process_queued_cpu_work(cs
);
44 /* Just indicate that signals should be handled asap. */
48 n
= env
->int_svc_code
;
53 env
->psw
.addr
+= env
->int_svc_ilen
;
54 ret
= do_syscall(env
, n
, env
->regs
[2], env
->regs
[3],
55 env
->regs
[4], env
->regs
[5],
56 env
->regs
[6], env
->regs
[7], 0, 0);
57 if (ret
== -TARGET_ERESTARTSYS
) {
58 env
->psw
.addr
-= env
->int_svc_ilen
;
59 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
66 n
= TARGET_TRAP_BRKPT
;
69 n
= env
->int_pgm_code
;
74 n
= TARGET_ILL_ILLOPC
;
79 /* XXX: check env->error_code */
80 n
= TARGET_SEGV_MAPERR
;
81 addr
= env
->__excp_addr
& S390X_FAIL_ADDR_MASK
;
84 case PGM_SPECIFICATION
:
89 n
= TARGET_ILL_ILLOPN
;
92 case PGM_FIXPT_OVERFLOW
:
94 n
= TARGET_FPE_INTOVF
;
96 case PGM_FIXPT_DIVIDE
:
98 n
= TARGET_FPE_INTDIV
;
102 n
= (env
->fpc
>> 8) & 0xff;
104 /* compare-and-trap */
107 /* An IEEE exception, simulated or otherwise. */
109 n
= TARGET_FPE_FLTINV
;
110 } else if (n
& 0x40) {
111 n
= TARGET_FPE_FLTDIV
;
112 } else if (n
& 0x20) {
113 n
= TARGET_FPE_FLTOVF
;
114 } else if (n
& 0x10) {
115 n
= TARGET_FPE_FLTUND
;
116 } else if (n
& 0x08) {
117 n
= TARGET_FPE_FLTRES
;
119 /* ??? Quantum exception; BFP, DFP error. */
127 fprintf(stderr
, "Unhandled program exception: %#x\n", n
);
128 cpu_dump_state(cs
, stderr
, 0);
134 addr
= env
->psw
.addr
;
139 info
._sifields
._sigfault
._addr
= addr
;
140 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
144 cpu_exec_step_atomic(cs
);
147 fprintf(stderr
, "Unhandled trap: 0x%x\n", trapnr
);
148 cpu_dump_state(cs
, stderr
, 0);
151 process_pending_signals (env
);
155 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
158 for (i
= 0; i
< 16; i
++) {
159 env
->regs
[i
] = regs
->gprs
[i
];
161 env
->psw
.mask
= regs
->psw
.mask
;
162 env
->psw
.addr
= regs
->psw
.addr
;