]> git.proxmox.com Git - mirror_qemu.git/blob - linux-user/openrisc/cpu_loop.c
linux-user/openrisc: Abort for EXCP_RANGE, EXCP_FPE
[mirror_qemu.git] / linux-user / openrisc / cpu_loop.c
1 /*
2 * qemu user cpu loop
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
22 #include "qemu.h"
23 #include "user-internals.h"
24 #include "cpu_loop-common.h"
25 #include "signal-common.h"
26
27 void cpu_loop(CPUOpenRISCState *env)
28 {
29 CPUState *cs = env_cpu(env);
30 int trapnr;
31 abi_long ret;
32 target_siginfo_t info;
33
34 for (;;) {
35 cpu_exec_start(cs);
36 trapnr = cpu_exec(cs);
37 cpu_exec_end(cs);
38 process_queued_cpu_work(cs);
39
40 switch (trapnr) {
41 case EXCP_SYSCALL:
42 env->pc += 4; /* 0xc00; */
43 ret = do_syscall(env,
44 cpu_get_gpr(env, 11), /* return value */
45 cpu_get_gpr(env, 3), /* r3 - r7 are params */
46 cpu_get_gpr(env, 4),
47 cpu_get_gpr(env, 5),
48 cpu_get_gpr(env, 6),
49 cpu_get_gpr(env, 7),
50 cpu_get_gpr(env, 8), 0, 0);
51 if (ret == -TARGET_ERESTARTSYS) {
52 env->pc -= 4;
53 } else if (ret != -TARGET_QEMU_ESIGRETURN) {
54 cpu_set_gpr(env, 11, ret);
55 }
56 break;
57 case EXCP_DPF:
58 case EXCP_IPF:
59 info.si_signo = TARGET_SIGSEGV;
60 info.si_errno = 0;
61 info.si_code = TARGET_SEGV_MAPERR;
62 info._sifields._sigfault._addr = env->pc;
63 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
64 break;
65 case EXCP_ALIGN:
66 info.si_signo = TARGET_SIGBUS;
67 info.si_errno = 0;
68 info.si_code = TARGET_BUS_ADRALN;
69 info._sifields._sigfault._addr = env->pc;
70 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
71 break;
72 case EXCP_ILLEGAL:
73 info.si_signo = TARGET_SIGILL;
74 info.si_errno = 0;
75 info.si_code = TARGET_ILL_ILLOPC;
76 info._sifields._sigfault._addr = env->pc;
77 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
78 break;
79 case EXCP_INTERRUPT:
80 /* We processed the pending cpu work above. */
81 break;
82 case EXCP_DEBUG:
83 info.si_signo = TARGET_SIGTRAP;
84 info.si_errno = 0;
85 info.si_code = TARGET_TRAP_BRKPT;
86 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
87 break;
88 case EXCP_ATOMIC:
89 cpu_exec_step_atomic(cs);
90 break;
91 case EXCP_RANGE:
92 /* Requires SR.OVE set, which linux-user won't do. */
93 cpu_abort(cs, "Unexpected RANGE exception");
94 case EXCP_FPE:
95 /*
96 * Requires FPSCR.FPEE set. Writes to FPSCR from usermode not
97 * yet enabled in kernel ABI, so linux-user does not either.
98 */
99 cpu_abort(cs, "Unexpected FPE exception");
100 default:
101 g_assert_not_reached();
102 }
103 process_pending_signals(env);
104 }
105 }
106
107 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
108 {
109 int i;
110
111 for (i = 0; i < 32; i++) {
112 cpu_set_gpr(env, i, regs->gpr[i]);
113 }
114 env->pc = regs->pc;
115 cpu_set_sr(env, regs->sr);
116 }