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 */
42 /* Match kernel's handle_diverror_c(). */
44 force_sig_fault(TARGET_SIGFPE
, TARGET_FPE_INTDIV
, env
->pc
);
49 force_sig_fault(TARGET_SIGBUS
, TARGET_BUS_ADRALN
,
50 env
->ctrl
[CR_BADADDR
]);
55 /* Match kernel's handle_illegal_c(). */
57 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLOPC
, env
->pc
);
60 /* Match kernel's handle_supervisor_instr(). */
62 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_PRVOPC
, env
->pc
);
66 switch (env
->error_code
) {
68 qemu_log_mask(CPU_LOG_INT
, "\nSyscall\n");
70 ret
= do_syscall(env
, env
->regs
[2],
71 env
->regs
[4], env
->regs
[5], env
->regs
[6],
72 env
->regs
[7], env
->regs
[8], env
->regs
[9],
75 if (ret
== -QEMU_ESIGRETURN
) {
76 /* rt_sigreturn has set all state. */
79 if (ret
== -QEMU_ERESTARTSYS
) {
84 * See the code after translate_rc_and_ret: all negative
85 * values are errors (aided by userspace restricted to 2G),
86 * errno is returned positive in r2, and error indication
89 env
->regs
[2] = abs(ret
);
90 env
->regs
[7] = ret
< 0;
94 qemu_log_mask(CPU_LOG_INT
, "\nTrap 1\n");
95 force_sig_fault(TARGET_SIGUSR1
, 0, env
->pc
);
98 qemu_log_mask(CPU_LOG_INT
, "\nTrap 2\n");
99 force_sig_fault(TARGET_SIGUSR2
, 0, env
->pc
);
102 qemu_log_mask(CPU_LOG_INT
, "\nTrap 31\n");
103 /* Match kernel's breakpoint_c(). */
105 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->pc
);
108 qemu_log_mask(CPU_LOG_INT
, "\nTrap %d\n", env
->error_code
);
109 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLTRP
, env
->pc
);
112 case 16: /* QEMU specific, for __kuser_cmpxchg */
114 abi_ptr g
= env
->regs
[4];
118 force_sig_fault(TARGET_SIGBUS
, TARGET_BUS_ADRALN
, g
);
121 ret
= page_get_flags(g
);
122 if (!(ret
& PAGE_VALID
)) {
123 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_MAPERR
, g
);
126 if (!(ret
& PAGE_READ
) || !(ret
& PAGE_WRITE
)) {
127 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_ACCERR
, g
);
133 env
->regs
[2] = qatomic_cmpxchg(h
, o
, n
) - o
;
140 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->pc
);
143 EXCP_DUMP(env
, "\nqemu: unhandled CPU exception %#x - aborting\n",
148 process_pending_signals(env
);
152 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
154 env
->regs
[R_SP
] = regs
->sp
;