]>
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" | |
21 | #include "qemu.h" | |
3b249d26 | 22 | #include "user-internals.h" |
cd71c089 | 23 | #include "cpu_loop-common.h" |
2113aed6 | 24 | #include "signal-common.h" |
cd71c089 | 25 | |
e256aefe LV |
26 | void cpu_loop(CPUAlphaState *env) |
27 | { | |
1c7ad260 | 28 | CPUState *cs = env_cpu(env); |
1c165977 | 29 | int trapnr, si_code; |
e256aefe LV |
30 | abi_long sysret; |
31 | ||
32 | while (1) { | |
33 | bool arch_interrupt = true; | |
34 | ||
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_RESET: | |
42 | fprintf(stderr, "Reset requested. Exit\n"); | |
43 | exit(EXIT_FAILURE); | |
44 | break; | |
45 | case EXCP_MCHK: | |
46 | fprintf(stderr, "Machine check exception. Exit\n"); | |
47 | exit(EXIT_FAILURE); | |
48 | break; | |
49 | case EXCP_SMP_INTERRUPT: | |
50 | case EXCP_CLK_INTERRUPT: | |
51 | case EXCP_DEV_INTERRUPT: | |
52 | fprintf(stderr, "External interrupt. Exit\n"); | |
53 | exit(EXIT_FAILURE); | |
54 | break; | |
e256aefe LV |
55 | case EXCP_OPCDEC: |
56 | do_sigill: | |
1c165977 | 57 | force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc); |
e256aefe LV |
58 | break; |
59 | case EXCP_ARITH: | |
1c165977 | 60 | force_sig_fault(TARGET_SIGFPE, TARGET_FPE_FLTINV, env->pc); |
e256aefe LV |
61 | break; |
62 | case EXCP_FEN: | |
63 | /* No-op. Linux simply re-enables the FPU. */ | |
64 | break; | |
65 | case EXCP_CALL_PAL: | |
66 | switch (env->error_code) { | |
67 | case 0x80: | |
68 | /* BPT */ | |
1c165977 | 69 | goto do_sigtrap_brkpt; |
e256aefe LV |
70 | case 0x81: |
71 | /* BUGCHK */ | |
1c165977 | 72 | goto do_sigtrap_unk; |
e256aefe LV |
73 | case 0x83: |
74 | /* CALLSYS */ | |
75 | trapnr = env->ir[IR_V0]; | |
76 | sysret = do_syscall(env, trapnr, | |
77 | env->ir[IR_A0], env->ir[IR_A1], | |
78 | env->ir[IR_A2], env->ir[IR_A3], | |
79 | env->ir[IR_A4], env->ir[IR_A5], | |
80 | 0, 0); | |
af254a27 | 81 | if (sysret == -QEMU_ERESTARTSYS) { |
e256aefe LV |
82 | env->pc -= 4; |
83 | break; | |
84 | } | |
57a0c938 | 85 | if (sysret == -QEMU_ESIGRETURN) { |
e256aefe LV |
86 | break; |
87 | } | |
88 | /* Syscall writes 0 to V0 to bypass error check, similar | |
89 | to how this is handled internal to Linux kernel. | |
90 | (Ab)use trapnr temporarily as boolean indicating error. */ | |
91 | trapnr = (env->ir[IR_V0] != 0 && sysret < 0); | |
92 | env->ir[IR_V0] = (trapnr ? -sysret : sysret); | |
93 | env->ir[IR_A3] = trapnr; | |
94 | break; | |
95 | case 0x86: | |
96 | /* IMB */ | |
97 | /* ??? We can probably elide the code using page_unprotect | |
98 | that is checking for self-modifying code. Instead we | |
99 | could simply call tb_flush here. Until we work out the | |
100 | changes required to turn off the extra write protection, | |
101 | this can be a no-op. */ | |
102 | break; | |
103 | case 0x9E: | |
104 | /* RDUNIQUE */ | |
105 | /* Handled in the translator for usermode. */ | |
106 | abort(); | |
107 | case 0x9F: | |
108 | /* WRUNIQUE */ | |
109 | /* Handled in the translator for usermode. */ | |
110 | abort(); | |
111 | case 0xAA: | |
112 | /* GENTRAP */ | |
e256aefe LV |
113 | switch (env->ir[IR_A0]) { |
114 | case TARGET_GEN_INTOVF: | |
1c165977 | 115 | si_code = TARGET_FPE_INTOVF; |
e256aefe LV |
116 | break; |
117 | case TARGET_GEN_INTDIV: | |
1c165977 | 118 | si_code = TARGET_FPE_INTDIV; |
e256aefe LV |
119 | break; |
120 | case TARGET_GEN_FLTOVF: | |
1c165977 | 121 | si_code = TARGET_FPE_FLTOVF; |
e256aefe LV |
122 | break; |
123 | case TARGET_GEN_FLTUND: | |
1c165977 | 124 | si_code = TARGET_FPE_FLTUND; |
e256aefe LV |
125 | break; |
126 | case TARGET_GEN_FLTINV: | |
1c165977 | 127 | si_code = TARGET_FPE_FLTINV; |
e256aefe LV |
128 | break; |
129 | case TARGET_GEN_FLTINE: | |
1c165977 | 130 | si_code = TARGET_FPE_FLTRES; |
e256aefe LV |
131 | break; |
132 | case TARGET_GEN_ROPRAND: | |
1c165977 | 133 | si_code = TARGET_FPE_FLTUNK; |
e256aefe LV |
134 | break; |
135 | default: | |
1c165977 | 136 | goto do_sigtrap_unk; |
e256aefe | 137 | } |
1c165977 | 138 | force_sig_fault(TARGET_SIGFPE, si_code, env->pc); |
e256aefe LV |
139 | break; |
140 | default: | |
141 | goto do_sigill; | |
142 | } | |
143 | break; | |
144 | case EXCP_DEBUG: | |
1c165977 RH |
145 | do_sigtrap_brkpt: |
146 | force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); | |
147 | break; | |
148 | do_sigtrap_unk: | |
149 | force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_UNK, env->pc); | |
e256aefe LV |
150 | break; |
151 | case EXCP_INTERRUPT: | |
152 | /* Just indicate that signals should be handled asap. */ | |
153 | break; | |
154 | case EXCP_ATOMIC: | |
155 | cpu_exec_step_atomic(cs); | |
156 | arch_interrupt = false; | |
157 | break; | |
158 | default: | |
84ca4fa9 | 159 | fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr); |
90c84c56 | 160 | cpu_dump_state(cs, stderr, 0); |
e256aefe LV |
161 | exit(EXIT_FAILURE); |
162 | } | |
163 | process_pending_signals (env); | |
164 | ||
165 | /* Most of the traps imply a transition through PALcode, which | |
166 | implies an REI instruction has been executed. Which means | |
167 | that RX and LOCK_ADDR should be cleared. But there are a | |
168 | few exceptions for traps internal to QEMU. */ | |
169 | if (arch_interrupt) { | |
170 | env->flags &= ~ENV_FLAG_RX_FLAG; | |
171 | env->lock_addr = -1; | |
172 | } | |
173 | } | |
174 | } | |
175 | ||
cd71c089 LV |
176 | void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) |
177 | { | |
e256aefe LV |
178 | int i; |
179 | ||
180 | for(i = 0; i < 28; i++) { | |
181 | env->ir[i] = ((abi_ulong *)regs)[i]; | |
182 | } | |
183 | env->ir[IR_SP] = regs->usp; | |
184 | env->pc = regs->pc; | |
cd71c089 | 185 | } |