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 "user-internals.h"
23 #include "cpu_loop-common.h"
24 #include "signal-common.h"
27 static int get_pgm_data_si_code(int dxc_code
)
30 /* Non-simulated IEEE exceptions */
32 return TARGET_FPE_FLTINV
;
34 return TARGET_FPE_FLTDIV
;
38 return TARGET_FPE_FLTOVF
;
42 return TARGET_FPE_FLTUND
;
45 return TARGET_FPE_FLTRES
;
48 * Non-IEEE and simulated IEEE:
49 * Includes compare-and-trap, quantum exception, etc.
50 * Simulated IEEE are included here to match current
56 void cpu_loop(CPUS390XState
*env
)
58 CPUState
*cs
= env_cpu(env
);
65 trapnr
= cpu_exec(cs
);
67 process_queued_cpu_work(cs
);
71 /* Just indicate that signals should be handled asap. */
75 n
= env
->int_svc_code
;
80 env
->psw
.addr
+= env
->int_svc_ilen
;
81 ret
= do_syscall(env
, n
, env
->regs
[2], env
->regs
[3],
82 env
->regs
[4], env
->regs
[5],
83 env
->regs
[6], env
->regs
[7], 0, 0);
84 if (ret
== -QEMU_ERESTARTSYS
) {
85 env
->psw
.addr
-= env
->int_svc_ilen
;
86 } else if (ret
!= -QEMU_ESIGRETURN
) {
93 n
= TARGET_TRAP_BRKPT
;
95 * For SIGTRAP the PSW must point after the instruction, which it
96 * already does thanks to s390x_tr_tb_stop(). si_addr doesn't need
102 n
= env
->int_pgm_code
;
107 n
= TARGET_ILL_ILLOPC
;
110 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_ACCERR
,
114 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_MAPERR
,
118 case PGM_SPECIFICATION
:
123 n
= TARGET_ILL_ILLOPN
;
126 case PGM_FIXPT_OVERFLOW
:
128 n
= TARGET_FPE_INTOVF
;
130 case PGM_FIXPT_DIVIDE
:
132 n
= TARGET_FPE_INTDIV
;
136 n
= (env
->fpc
>> 8) & 0xff;
142 n
= get_pgm_data_si_code(n
);
146 fprintf(stderr
, "Unhandled program exception: %#x\n", n
);
147 cpu_dump_state(cs
, stderr
, 0);
153 addr
= env
->psw
.addr
;
155 * For SIGILL and SIGFPE the PSW must point after the instruction.
157 env
->psw
.addr
+= env
->int_pgm_ilen
;
159 force_sig_fault(sig
, n
, addr
);
163 cpu_exec_step_atomic(cs
);
166 fprintf(stderr
, "Unhandled trap: 0x%x\n", trapnr
);
167 cpu_dump_state(cs
, stderr
, 0);
170 process_pending_signals (env
);
174 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
177 for (i
= 0; i
< 16; i
++) {
178 env
->regs
[i
] = regs
->gprs
[i
];
180 env
->psw
.mask
= regs
->psw
.mask
;
181 env
->psw
.addr
= regs
->psw
.addr
;