]>
Commit | Line | Data |
---|---|---|
cd71c089 LV |
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" | |
a8d25326 | 21 | #include "qemu-common.h" |
cd71c089 LV |
22 | #include "qemu.h" |
23 | #include "cpu_loop-common.h" | |
24 | ||
1ef7bca2 LV |
25 | void cpu_loop(CPUOpenRISCState *env) |
26 | { | |
5ee2b02e | 27 | CPUState *cs = env_cpu(env); |
1ef7bca2 LV |
28 | int trapnr; |
29 | abi_long ret; | |
30 | target_siginfo_t info; | |
31 | ||
32 | for (;;) { | |
33 | cpu_exec_start(cs); | |
34 | trapnr = cpu_exec(cs); | |
35 | cpu_exec_end(cs); | |
36 | process_queued_cpu_work(cs); | |
37 | ||
38 | switch (trapnr) { | |
39 | case EXCP_SYSCALL: | |
40 | env->pc += 4; /* 0xc00; */ | |
41 | ret = do_syscall(env, | |
42 | cpu_get_gpr(env, 11), /* return value */ | |
43 | cpu_get_gpr(env, 3), /* r3 - r7 are params */ | |
44 | cpu_get_gpr(env, 4), | |
45 | cpu_get_gpr(env, 5), | |
46 | cpu_get_gpr(env, 6), | |
47 | cpu_get_gpr(env, 7), | |
48 | cpu_get_gpr(env, 8), 0, 0); | |
49 | if (ret == -TARGET_ERESTARTSYS) { | |
50 | env->pc -= 4; | |
51 | } else if (ret != -TARGET_QEMU_ESIGRETURN) { | |
52 | cpu_set_gpr(env, 11, ret); | |
53 | } | |
54 | break; | |
55 | case EXCP_DPF: | |
56 | case EXCP_IPF: | |
57 | case EXCP_RANGE: | |
58 | info.si_signo = TARGET_SIGSEGV; | |
59 | info.si_errno = 0; | |
60 | info.si_code = TARGET_SEGV_MAPERR; | |
61 | info._sifields._sigfault._addr = env->pc; | |
62 | queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | |
63 | break; | |
64 | case EXCP_ALIGN: | |
65 | info.si_signo = TARGET_SIGBUS; | |
66 | info.si_errno = 0; | |
67 | info.si_code = TARGET_BUS_ADRALN; | |
68 | info._sifields._sigfault._addr = env->pc; | |
69 | queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | |
70 | break; | |
71 | case EXCP_ILLEGAL: | |
72 | info.si_signo = TARGET_SIGILL; | |
73 | info.si_errno = 0; | |
74 | info.si_code = TARGET_ILL_ILLOPC; | |
75 | info._sifields._sigfault._addr = env->pc; | |
76 | queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | |
77 | break; | |
78 | case EXCP_FPE: | |
79 | info.si_signo = TARGET_SIGFPE; | |
80 | info.si_errno = 0; | |
81 | info.si_code = 0; | |
82 | info._sifields._sigfault._addr = env->pc; | |
83 | queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | |
84 | break; | |
85 | case EXCP_INTERRUPT: | |
86 | /* We processed the pending cpu work above. */ | |
87 | break; | |
88 | case EXCP_DEBUG: | |
b10089a1 PM |
89 | info.si_signo = TARGET_SIGTRAP; |
90 | info.si_errno = 0; | |
91 | info.si_code = TARGET_TRAP_BRKPT; | |
92 | queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | |
1ef7bca2 LV |
93 | break; |
94 | case EXCP_ATOMIC: | |
95 | cpu_exec_step_atomic(cs); | |
96 | break; | |
97 | default: | |
98 | g_assert_not_reached(); | |
99 | } | |
100 | process_pending_signals(env); | |
101 | } | |
102 | } | |
103 | ||
cd71c089 LV |
104 | void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) |
105 | { | |
1ef7bca2 LV |
106 | int i; |
107 | ||
108 | for (i = 0; i < 32; i++) { | |
109 | cpu_set_gpr(env, i, regs->gpr[i]); | |
110 | } | |
111 | env->pc = regs->pc; | |
112 | cpu_set_sr(env, regs->sr); | |
cd71c089 | 113 | } |