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
);
35 process_queued_cpu_work(cs
);
39 /* just indicate that signals should be handled asap */
43 /* Match kernel's handle_diverror_c(). */
45 force_sig_fault(TARGET_SIGFPE
, TARGET_FPE_INTDIV
, env
->pc
);
50 force_sig_fault(TARGET_SIGBUS
, TARGET_BUS_ADRALN
,
51 env
->ctrl
[CR_BADADDR
]);
56 /* Match kernel's handle_illegal_c(). */
58 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLOPC
, env
->pc
);
61 /* Match kernel's handle_supervisor_instr(). */
63 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_PRVOPC
, env
->pc
);
67 switch (env
->error_code
) {
69 qemu_log_mask(CPU_LOG_INT
, "\nSyscall\n");
71 ret
= do_syscall(env
, env
->regs
[2],
72 env
->regs
[4], env
->regs
[5], env
->regs
[6],
73 env
->regs
[7], env
->regs
[8], env
->regs
[9],
76 if (ret
== -QEMU_ESIGRETURN
) {
77 /* rt_sigreturn has set all state. */
80 if (ret
== -QEMU_ERESTARTSYS
) {
85 * See the code after translate_rc_and_ret: all negative
86 * values are errors (aided by userspace restricted to 2G),
87 * errno is returned positive in r2, and error indication
90 env
->regs
[2] = abs(ret
);
91 env
->regs
[7] = ret
< 0;
95 qemu_log_mask(CPU_LOG_INT
, "\nTrap 1\n");
96 force_sig_fault(TARGET_SIGUSR1
, 0, env
->pc
);
99 qemu_log_mask(CPU_LOG_INT
, "\nTrap 2\n");
100 force_sig_fault(TARGET_SIGUSR2
, 0, env
->pc
);
103 qemu_log_mask(CPU_LOG_INT
, "\nTrap 31\n");
104 /* Match kernel's breakpoint_c(). */
106 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->pc
);
109 qemu_log_mask(CPU_LOG_INT
, "\nTrap %d\n", env
->error_code
);
110 force_sig_fault(TARGET_SIGILL
, TARGET_ILL_ILLTRP
, env
->pc
);
113 case 16: /* QEMU specific, for __kuser_cmpxchg */
115 abi_ptr g
= env
->regs
[4];
119 force_sig_fault(TARGET_SIGBUS
, TARGET_BUS_ADRALN
, g
);
122 ret
= page_get_flags(g
);
123 if (!(ret
& PAGE_VALID
)) {
124 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_MAPERR
, g
);
127 if (!(ret
& PAGE_READ
) || !(ret
& PAGE_WRITE
)) {
128 force_sig_fault(TARGET_SIGSEGV
, TARGET_SEGV_ACCERR
, g
);
134 env
->regs
[2] = qatomic_cmpxchg(h
, o
, n
) - o
;
141 force_sig_fault(TARGET_SIGTRAP
, TARGET_TRAP_BRKPT
, env
->pc
);
144 EXCP_DUMP(env
, "\nqemu: unhandled CPU exception %#x - aborting\n",
149 process_pending_signals(env
);
153 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
155 env
->regs
[R_SP
] = regs
->sp
;