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"
26 void cpu_loop(CPUNios2State
*env
)
28 CPUState
*cs
= env_cpu(env
);
33 trapnr
= cpu_exec(cs
);
38 /* just indicate that signals should be handled asap */
43 * TODO: This advance should be done in the translator, as
44 * hardware produces an advanced pc as part of all exceptions.
48 switch (env
->error_code
) {
50 qemu_log_mask(CPU_LOG_INT
, "\nSyscall\n");
52 ret
= do_syscall(env
, env
->regs
[2],
53 env
->regs
[4], env
->regs
[5], env
->regs
[6],
54 env
->regs
[7], env
->regs
[8], env
->regs
[9],
57 if (ret
== -QEMU_ESIGRETURN
) {
58 /* rt_sigreturn has set all state. */
61 if (ret
== -QEMU_ERESTARTSYS
) {
66 * See the code after translate_rc_and_ret: all negative
67 * values are errors (aided by userspace restricted to 2G),
68 * errno is returned positive in r2, and error indication
71 env
->regs
[2] = abs(ret
);
72 env
->regs
[7] = ret
< 0;
76 qemu_log_mask(CPU_LOG_INT
, "\nTrap 1\n");
77 force_sig_fault(TARGET_SIGUSR1
, 0, env
->pc
);
80 qemu_log_mask(CPU_LOG_INT
, "\nTrap 2\n");
81 force_sig_fault(TARGET_SIGUSR2
, 0, env
->pc
);
84 qemu_log_mask(CPU_LOG_INT
, "\nTrap 31\n");
85 /* Match kernel's breakpoint_c(). */
87 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->pc
);
90 qemu_log_mask(CPU_LOG_INT
, "\nTrap %d\n", env
->error_code
);
91 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLTRP
, env
->pc
);
94 case 16: /* QEMU specific, for __kuser_cmpxchg */
96 abi_ptr g
= env
->regs
[4];
100 force_sig_fault(TARGET_SIGBUS
, TARGET_BUS_ADRALN
, g
);
103 ret
= page_get_flags(g
);
104 if (!(ret
& PAGE_VALID
)) {
105 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_MAPERR
, g
);
108 if (!(ret
& PAGE_READ
) || !(ret
& PAGE_WRITE
)) {
109 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_ACCERR
, g
);
115 env
->regs
[2] = qatomic_cmpxchg(h
, o
, n
) - o
;
122 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->pc
);
125 EXCP_DUMP(env
, "\nqemu: unhandled CPU exception %#x - aborting\n",
130 process_pending_signals(env
);
134 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
136 env
->regs
[R_SP
] = regs
->sp
;