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"
22 #include "cpu_loop-common.h"
24 /* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */
25 #define S390X_FAIL_ADDR_MASK -4096LL
27 void cpu_loop(CPUS390XState
*env
)
29 CPUState
*cs
= CPU(s390_env_get_cpu(env
));
31 target_siginfo_t info
;
37 trapnr
= cpu_exec(cs
);
39 process_queued_cpu_work(cs
);
43 /* Just indicate that signals should be handled asap. */
47 n
= env
->int_svc_code
;
52 env
->psw
.addr
+= env
->int_svc_ilen
;
53 ret
= do_syscall(env
, n
, env
->regs
[2], env
->regs
[3],
54 env
->regs
[4], env
->regs
[5],
55 env
->regs
[6], env
->regs
[7], 0, 0);
56 if (ret
== -TARGET_ERESTARTSYS
) {
57 env
->psw
.addr
-= env
->int_svc_ilen
;
58 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
65 n
= TARGET_TRAP_BRKPT
;
68 n
= env
->int_pgm_code
;
73 n
= TARGET_ILL_ILLOPC
;
78 /* XXX: check env->error_code */
79 n
= TARGET_SEGV_MAPERR
;
80 addr
= env
->__excp_addr
& S390X_FAIL_ADDR_MASK
;
83 case PGM_SPECIFICATION
:
88 n
= TARGET_ILL_ILLOPN
;
91 case PGM_FIXPT_OVERFLOW
:
93 n
= TARGET_FPE_INTOVF
;
95 case PGM_FIXPT_DIVIDE
:
97 n
= TARGET_FPE_INTDIV
;
101 n
= (env
->fpc
>> 8) & 0xff;
103 /* compare-and-trap */
106 /* An IEEE exception, simulated or otherwise. */
108 n
= TARGET_FPE_FLTINV
;
109 } else if (n
& 0x40) {
110 n
= TARGET_FPE_FLTDIV
;
111 } else if (n
& 0x20) {
112 n
= TARGET_FPE_FLTOVF
;
113 } else if (n
& 0x10) {
114 n
= TARGET_FPE_FLTUND
;
115 } else if (n
& 0x08) {
116 n
= TARGET_FPE_FLTRES
;
118 /* ??? Quantum exception; BFP, DFP error. */
126 fprintf(stderr
, "Unhandled program exception: %#x\n", n
);
127 cpu_dump_state(cs
, stderr
, 0);
133 addr
= env
->psw
.addr
;
138 info
._sifields
._sigfault
._addr
= addr
;
139 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
143 cpu_exec_step_atomic(cs
);
146 fprintf(stderr
, "Unhandled trap: 0x%x\n", trapnr
);
147 cpu_dump_state(cs
, stderr
, 0);
150 process_pending_signals (env
);
154 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
157 for (i
= 0; i
< 16; i
++) {
158 env
->regs
[i
] = regs
->gprs
[i
];
160 env
->psw
.mask
= regs
->psw
.mask
;
161 env
->psw
.addr
= regs
->psw
.addr
;