root / linux-user / main.c @ b53d44e5
History | View | Annotate | Download (94.5 kB)
1 | 31e31b8a | bellard | /*
|
---|---|---|---|
2 | 93ac68bc | bellard | * qemu user main
|
3 | 5fafdf24 | ths | *
|
4 | 68d0f70e | bellard | * Copyright (c) 2003-2008 Fabrice Bellard
|
5 | 31e31b8a | bellard | *
|
6 | 31e31b8a | bellard | * This program is free software; you can redistribute it and/or modify
|
7 | 31e31b8a | bellard | * it under the terms of the GNU General Public License as published by
|
8 | 31e31b8a | bellard | * the Free Software Foundation; either version 2 of the License, or
|
9 | 31e31b8a | bellard | * (at your option) any later version.
|
10 | 31e31b8a | bellard | *
|
11 | 31e31b8a | bellard | * This program is distributed in the hope that it will be useful,
|
12 | 31e31b8a | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 31e31b8a | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 31e31b8a | bellard | * GNU General Public License for more details.
|
15 | 31e31b8a | bellard | *
|
16 | 31e31b8a | bellard | * You should have received a copy of the GNU General Public License
|
17 | 8167ee88 | Blue Swirl | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
18 | 31e31b8a | bellard | */
|
19 | 31e31b8a | bellard | #include <stdlib.h> |
20 | 31e31b8a | bellard | #include <stdio.h> |
21 | 31e31b8a | bellard | #include <stdarg.h> |
22 | 04369ff2 | bellard | #include <string.h> |
23 | 31e31b8a | bellard | #include <errno.h> |
24 | 0ecfa993 | bellard | #include <unistd.h> |
25 | e441570f | balrog | #include <sys/mman.h> |
26 | edf8e2af | Mika Westerberg | #include <sys/syscall.h> |
27 | 31e31b8a | bellard | |
28 | 3ef693a0 | bellard | #include "qemu.h" |
29 | ca10f867 | aurel32 | #include "qemu-common.h" |
30 | 902b3d5c | malc | #include "cache-utils.h" |
31 | d5975363 | pbrook | /* For tb_lock */
|
32 | d5975363 | pbrook | #include "exec-all.h" |
33 | 31e31b8a | bellard | |
34 | 04a6dfeb | aurel32 | |
35 | 04a6dfeb | aurel32 | #include "envlist.h" |
36 | 04a6dfeb | aurel32 | |
37 | 3ef693a0 | bellard | #define DEBUG_LOGFILE "/tmp/qemu.log" |
38 | 586314f2 | bellard | |
39 | d088d664 | aurel32 | char *exec_path;
|
40 | d088d664 | aurel32 | |
41 | 1b530a6d | aurel32 | int singlestep;
|
42 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
43 | 379f6698 | Paul Brook | unsigned long mmap_min_addr; |
44 | 379f6698 | Paul Brook | unsigned long guest_base; |
45 | 379f6698 | Paul Brook | int have_guest_base;
|
46 | 379f6698 | Paul Brook | #endif
|
47 | 1b530a6d | aurel32 | |
48 | 74cd30b8 | bellard | static const char *interp_prefix = CONFIG_QEMU_PREFIX; |
49 | c5937220 | pbrook | const char *qemu_uname_release = CONFIG_UNAME_RELEASE; |
50 | 586314f2 | bellard | |
51 | 9de5e440 | bellard | /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
|
52 | 9de5e440 | bellard | we allocate a bigger stack. Need a better solution, for example
|
53 | 9de5e440 | bellard | by remapping the process stack directly at the right place */
|
54 | 9de5e440 | bellard | unsigned long x86_stack_size = 512 * 1024; |
55 | 31e31b8a | bellard | |
56 | 31e31b8a | bellard | void gemu_log(const char *fmt, ...) |
57 | 31e31b8a | bellard | { |
58 | 31e31b8a | bellard | va_list ap; |
59 | 31e31b8a | bellard | |
60 | 31e31b8a | bellard | va_start(ap, fmt); |
61 | 31e31b8a | bellard | vfprintf(stderr, fmt, ap); |
62 | 31e31b8a | bellard | va_end(ap); |
63 | 31e31b8a | bellard | } |
64 | 31e31b8a | bellard | |
65 | 8fcd3692 | blueswir1 | #if defined(TARGET_I386)
|
66 | a541f297 | bellard | int cpu_get_pic_interrupt(CPUState *env)
|
67 | 92ccca6a | bellard | { |
68 | 92ccca6a | bellard | return -1; |
69 | 92ccca6a | bellard | } |
70 | 8fcd3692 | blueswir1 | #endif
|
71 | 92ccca6a | bellard | |
72 | 28ab0e2e | bellard | /* timers for rdtsc */
|
73 | 28ab0e2e | bellard | |
74 | 1dce7c3c | bellard | #if 0
|
75 | 28ab0e2e | bellard | |
76 | 28ab0e2e | bellard | static uint64_t emu_time;
|
77 | 28ab0e2e | bellard | |
78 | 28ab0e2e | bellard | int64_t cpu_get_real_ticks(void)
|
79 | 28ab0e2e | bellard | {
|
80 | 28ab0e2e | bellard | return emu_time++;
|
81 | 28ab0e2e | bellard | }
|
82 | 28ab0e2e | bellard | |
83 | 28ab0e2e | bellard | #endif
|
84 | 28ab0e2e | bellard | |
85 | 2f7bb878 | Juan Quintela | #if defined(CONFIG_USE_NPTL)
|
86 | d5975363 | pbrook | /***********************************************************/
|
87 | d5975363 | pbrook | /* Helper routines for implementing atomic operations. */
|
88 | d5975363 | pbrook | |
89 | d5975363 | pbrook | /* To implement exclusive operations we force all cpus to syncronise.
|
90 | d5975363 | pbrook | We don't require a full sync, only that no cpus are executing guest code.
|
91 | d5975363 | pbrook | The alternative is to map target atomic ops onto host equivalents,
|
92 | d5975363 | pbrook | which requires quite a lot of per host/target work. */
|
93 | c2764719 | pbrook | static pthread_mutex_t cpu_list_mutex = PTHREAD_MUTEX_INITIALIZER;
|
94 | d5975363 | pbrook | static pthread_mutex_t exclusive_lock = PTHREAD_MUTEX_INITIALIZER;
|
95 | d5975363 | pbrook | static pthread_cond_t exclusive_cond = PTHREAD_COND_INITIALIZER;
|
96 | d5975363 | pbrook | static pthread_cond_t exclusive_resume = PTHREAD_COND_INITIALIZER;
|
97 | d5975363 | pbrook | static int pending_cpus; |
98 | d5975363 | pbrook | |
99 | d5975363 | pbrook | /* Make sure everything is in a consistent state for calling fork(). */
|
100 | d5975363 | pbrook | void fork_start(void) |
101 | d5975363 | pbrook | { |
102 | d5975363 | pbrook | mmap_fork_start(); |
103 | d5975363 | pbrook | pthread_mutex_lock(&tb_lock); |
104 | d5975363 | pbrook | pthread_mutex_lock(&exclusive_lock); |
105 | d5975363 | pbrook | } |
106 | d5975363 | pbrook | |
107 | d5975363 | pbrook | void fork_end(int child) |
108 | d5975363 | pbrook | { |
109 | d5975363 | pbrook | if (child) {
|
110 | d5975363 | pbrook | /* Child processes created by fork() only have a single thread.
|
111 | d5975363 | pbrook | Discard information about the parent threads. */
|
112 | d5975363 | pbrook | first_cpu = thread_env; |
113 | d5975363 | pbrook | thread_env->next_cpu = NULL;
|
114 | d5975363 | pbrook | pending_cpus = 0;
|
115 | d5975363 | pbrook | pthread_mutex_init(&exclusive_lock, NULL);
|
116 | c2764719 | pbrook | pthread_mutex_init(&cpu_list_mutex, NULL);
|
117 | d5975363 | pbrook | pthread_cond_init(&exclusive_cond, NULL);
|
118 | d5975363 | pbrook | pthread_cond_init(&exclusive_resume, NULL);
|
119 | d5975363 | pbrook | pthread_mutex_init(&tb_lock, NULL);
|
120 | 2b1319c8 | aurel32 | gdbserver_fork(thread_env); |
121 | d5975363 | pbrook | } else {
|
122 | d5975363 | pbrook | pthread_mutex_unlock(&exclusive_lock); |
123 | d5975363 | pbrook | pthread_mutex_unlock(&tb_lock); |
124 | d5975363 | pbrook | } |
125 | d5975363 | pbrook | mmap_fork_end(child); |
126 | d5975363 | pbrook | } |
127 | d5975363 | pbrook | |
128 | d5975363 | pbrook | /* Wait for pending exclusive operations to complete. The exclusive lock
|
129 | d5975363 | pbrook | must be held. */
|
130 | d5975363 | pbrook | static inline void exclusive_idle(void) |
131 | d5975363 | pbrook | { |
132 | d5975363 | pbrook | while (pending_cpus) {
|
133 | d5975363 | pbrook | pthread_cond_wait(&exclusive_resume, &exclusive_lock); |
134 | d5975363 | pbrook | } |
135 | d5975363 | pbrook | } |
136 | d5975363 | pbrook | |
137 | d5975363 | pbrook | /* Start an exclusive operation.
|
138 | d5975363 | pbrook | Must only be called from outside cpu_arm_exec. */
|
139 | d5975363 | pbrook | static inline void start_exclusive(void) |
140 | d5975363 | pbrook | { |
141 | d5975363 | pbrook | CPUState *other; |
142 | d5975363 | pbrook | pthread_mutex_lock(&exclusive_lock); |
143 | d5975363 | pbrook | exclusive_idle(); |
144 | d5975363 | pbrook | |
145 | d5975363 | pbrook | pending_cpus = 1;
|
146 | d5975363 | pbrook | /* Make all other cpus stop executing. */
|
147 | d5975363 | pbrook | for (other = first_cpu; other; other = other->next_cpu) {
|
148 | d5975363 | pbrook | if (other->running) {
|
149 | d5975363 | pbrook | pending_cpus++; |
150 | 3098dba0 | aurel32 | cpu_exit(other); |
151 | d5975363 | pbrook | } |
152 | d5975363 | pbrook | } |
153 | d5975363 | pbrook | if (pending_cpus > 1) { |
154 | d5975363 | pbrook | pthread_cond_wait(&exclusive_cond, &exclusive_lock); |
155 | d5975363 | pbrook | } |
156 | d5975363 | pbrook | } |
157 | d5975363 | pbrook | |
158 | d5975363 | pbrook | /* Finish an exclusive operation. */
|
159 | d5975363 | pbrook | static inline void end_exclusive(void) |
160 | d5975363 | pbrook | { |
161 | d5975363 | pbrook | pending_cpus = 0;
|
162 | d5975363 | pbrook | pthread_cond_broadcast(&exclusive_resume); |
163 | d5975363 | pbrook | pthread_mutex_unlock(&exclusive_lock); |
164 | d5975363 | pbrook | } |
165 | d5975363 | pbrook | |
166 | d5975363 | pbrook | /* Wait for exclusive ops to finish, and begin cpu execution. */
|
167 | d5975363 | pbrook | static inline void cpu_exec_start(CPUState *env) |
168 | d5975363 | pbrook | { |
169 | d5975363 | pbrook | pthread_mutex_lock(&exclusive_lock); |
170 | d5975363 | pbrook | exclusive_idle(); |
171 | d5975363 | pbrook | env->running = 1;
|
172 | d5975363 | pbrook | pthread_mutex_unlock(&exclusive_lock); |
173 | d5975363 | pbrook | } |
174 | d5975363 | pbrook | |
175 | d5975363 | pbrook | /* Mark cpu as not executing, and release pending exclusive ops. */
|
176 | d5975363 | pbrook | static inline void cpu_exec_end(CPUState *env) |
177 | d5975363 | pbrook | { |
178 | d5975363 | pbrook | pthread_mutex_lock(&exclusive_lock); |
179 | d5975363 | pbrook | env->running = 0;
|
180 | d5975363 | pbrook | if (pending_cpus > 1) { |
181 | d5975363 | pbrook | pending_cpus--; |
182 | d5975363 | pbrook | if (pending_cpus == 1) { |
183 | d5975363 | pbrook | pthread_cond_signal(&exclusive_cond); |
184 | d5975363 | pbrook | } |
185 | d5975363 | pbrook | } |
186 | d5975363 | pbrook | exclusive_idle(); |
187 | d5975363 | pbrook | pthread_mutex_unlock(&exclusive_lock); |
188 | d5975363 | pbrook | } |
189 | c2764719 | pbrook | |
190 | c2764719 | pbrook | void cpu_list_lock(void) |
191 | c2764719 | pbrook | { |
192 | c2764719 | pbrook | pthread_mutex_lock(&cpu_list_mutex); |
193 | c2764719 | pbrook | } |
194 | c2764719 | pbrook | |
195 | c2764719 | pbrook | void cpu_list_unlock(void) |
196 | c2764719 | pbrook | { |
197 | c2764719 | pbrook | pthread_mutex_unlock(&cpu_list_mutex); |
198 | c2764719 | pbrook | } |
199 | 2f7bb878 | Juan Quintela | #else /* if !CONFIG_USE_NPTL */ |
200 | d5975363 | pbrook | /* These are no-ops because we are not threadsafe. */
|
201 | d5975363 | pbrook | static inline void cpu_exec_start(CPUState *env) |
202 | d5975363 | pbrook | { |
203 | d5975363 | pbrook | } |
204 | d5975363 | pbrook | |
205 | d5975363 | pbrook | static inline void cpu_exec_end(CPUState *env) |
206 | d5975363 | pbrook | { |
207 | d5975363 | pbrook | } |
208 | d5975363 | pbrook | |
209 | d5975363 | pbrook | static inline void start_exclusive(void) |
210 | d5975363 | pbrook | { |
211 | d5975363 | pbrook | } |
212 | d5975363 | pbrook | |
213 | d5975363 | pbrook | static inline void end_exclusive(void) |
214 | d5975363 | pbrook | { |
215 | d5975363 | pbrook | } |
216 | d5975363 | pbrook | |
217 | d5975363 | pbrook | void fork_start(void) |
218 | d5975363 | pbrook | { |
219 | d5975363 | pbrook | } |
220 | d5975363 | pbrook | |
221 | d5975363 | pbrook | void fork_end(int child) |
222 | d5975363 | pbrook | { |
223 | 2b1319c8 | aurel32 | if (child) {
|
224 | 2b1319c8 | aurel32 | gdbserver_fork(thread_env); |
225 | 2b1319c8 | aurel32 | } |
226 | d5975363 | pbrook | } |
227 | c2764719 | pbrook | |
228 | c2764719 | pbrook | void cpu_list_lock(void) |
229 | c2764719 | pbrook | { |
230 | c2764719 | pbrook | } |
231 | c2764719 | pbrook | |
232 | c2764719 | pbrook | void cpu_list_unlock(void) |
233 | c2764719 | pbrook | { |
234 | c2764719 | pbrook | } |
235 | d5975363 | pbrook | #endif
|
236 | d5975363 | pbrook | |
237 | d5975363 | pbrook | |
238 | a541f297 | bellard | #ifdef TARGET_I386
|
239 | a541f297 | bellard | /***********************************************************/
|
240 | a541f297 | bellard | /* CPUX86 core interface */
|
241 | a541f297 | bellard | |
242 | 02a1602e | bellard | void cpu_smm_update(CPUState *env)
|
243 | 02a1602e | bellard | { |
244 | 02a1602e | bellard | } |
245 | 02a1602e | bellard | |
246 | 28ab0e2e | bellard | uint64_t cpu_get_tsc(CPUX86State *env) |
247 | 28ab0e2e | bellard | { |
248 | 28ab0e2e | bellard | return cpu_get_real_ticks();
|
249 | 28ab0e2e | bellard | } |
250 | 28ab0e2e | bellard | |
251 | 5fafdf24 | ths | static void write_dt(void *ptr, unsigned long addr, unsigned long limit, |
252 | f4beb510 | bellard | int flags)
|
253 | 6dbad63e | bellard | { |
254 | f4beb510 | bellard | unsigned int e1, e2; |
255 | 53a5960a | pbrook | uint32_t *p; |
256 | 6dbad63e | bellard | e1 = (addr << 16) | (limit & 0xffff); |
257 | 6dbad63e | bellard | e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000); |
258 | f4beb510 | bellard | e2 |= flags; |
259 | 53a5960a | pbrook | p = ptr; |
260 | d538e8f5 | malc | p[0] = tswap32(e1);
|
261 | d538e8f5 | malc | p[1] = tswap32(e2);
|
262 | f4beb510 | bellard | } |
263 | f4beb510 | bellard | |
264 | e441570f | balrog | static uint64_t *idt_table;
|
265 | eb38c52c | blueswir1 | #ifdef TARGET_X86_64
|
266 | d2fd1af7 | bellard | static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, |
267 | d2fd1af7 | bellard | uint64_t addr, unsigned int sel) |
268 | f4beb510 | bellard | { |
269 | 4dbc422b | bellard | uint32_t *p, e1, e2; |
270 | f4beb510 | bellard | e1 = (addr & 0xffff) | (sel << 16); |
271 | f4beb510 | bellard | e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); |
272 | 53a5960a | pbrook | p = ptr; |
273 | 4dbc422b | bellard | p[0] = tswap32(e1);
|
274 | 4dbc422b | bellard | p[1] = tswap32(e2);
|
275 | 4dbc422b | bellard | p[2] = tswap32(addr >> 32); |
276 | 4dbc422b | bellard | p[3] = 0; |
277 | 6dbad63e | bellard | } |
278 | d2fd1af7 | bellard | /* only dpl matters as we do only user space emulation */
|
279 | d2fd1af7 | bellard | static void set_idt(int n, unsigned int dpl) |
280 | d2fd1af7 | bellard | { |
281 | d2fd1af7 | bellard | set_gate64(idt_table + n * 2, 0, dpl, 0, 0); |
282 | d2fd1af7 | bellard | } |
283 | d2fd1af7 | bellard | #else
|
284 | d2fd1af7 | bellard | static void set_gate(void *ptr, unsigned int type, unsigned int dpl, |
285 | d2fd1af7 | bellard | uint32_t addr, unsigned int sel) |
286 | d2fd1af7 | bellard | { |
287 | 4dbc422b | bellard | uint32_t *p, e1, e2; |
288 | d2fd1af7 | bellard | e1 = (addr & 0xffff) | (sel << 16); |
289 | d2fd1af7 | bellard | e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); |
290 | d2fd1af7 | bellard | p = ptr; |
291 | 4dbc422b | bellard | p[0] = tswap32(e1);
|
292 | 4dbc422b | bellard | p[1] = tswap32(e2);
|
293 | d2fd1af7 | bellard | } |
294 | d2fd1af7 | bellard | |
295 | f4beb510 | bellard | /* only dpl matters as we do only user space emulation */
|
296 | f4beb510 | bellard | static void set_idt(int n, unsigned int dpl) |
297 | f4beb510 | bellard | { |
298 | f4beb510 | bellard | set_gate(idt_table + n, 0, dpl, 0, 0); |
299 | f4beb510 | bellard | } |
300 | d2fd1af7 | bellard | #endif
|
301 | 31e31b8a | bellard | |
302 | 89e957e7 | bellard | void cpu_loop(CPUX86State *env)
|
303 | 1b6b029e | bellard | { |
304 | bc8a22cc | bellard | int trapnr;
|
305 | 992f48a0 | blueswir1 | abi_ulong pc; |
306 | c227f099 | Anthony Liguori | target_siginfo_t info; |
307 | 851e67a1 | bellard | |
308 | 1b6b029e | bellard | for(;;) {
|
309 | bc8a22cc | bellard | trapnr = cpu_x86_exec(env); |
310 | bc8a22cc | bellard | switch(trapnr) {
|
311 | f4beb510 | bellard | case 0x80: |
312 | d2fd1af7 | bellard | /* linux syscall from int $0x80 */
|
313 | 5fafdf24 | ths | env->regs[R_EAX] = do_syscall(env, |
314 | 5fafdf24 | ths | env->regs[R_EAX], |
315 | f4beb510 | bellard | env->regs[R_EBX], |
316 | f4beb510 | bellard | env->regs[R_ECX], |
317 | f4beb510 | bellard | env->regs[R_EDX], |
318 | f4beb510 | bellard | env->regs[R_ESI], |
319 | f4beb510 | bellard | env->regs[R_EDI], |
320 | f4beb510 | bellard | env->regs[R_EBP]); |
321 | f4beb510 | bellard | break;
|
322 | d2fd1af7 | bellard | #ifndef TARGET_ABI32
|
323 | d2fd1af7 | bellard | case EXCP_SYSCALL:
|
324 | d2fd1af7 | bellard | /* linux syscall from syscall intruction */
|
325 | d2fd1af7 | bellard | env->regs[R_EAX] = do_syscall(env, |
326 | d2fd1af7 | bellard | env->regs[R_EAX], |
327 | d2fd1af7 | bellard | env->regs[R_EDI], |
328 | d2fd1af7 | bellard | env->regs[R_ESI], |
329 | d2fd1af7 | bellard | env->regs[R_EDX], |
330 | d2fd1af7 | bellard | env->regs[10],
|
331 | d2fd1af7 | bellard | env->regs[8],
|
332 | d2fd1af7 | bellard | env->regs[9]);
|
333 | d2fd1af7 | bellard | env->eip = env->exception_next_eip; |
334 | d2fd1af7 | bellard | break;
|
335 | d2fd1af7 | bellard | #endif
|
336 | f4beb510 | bellard | case EXCP0B_NOSEG:
|
337 | f4beb510 | bellard | case EXCP0C_STACK:
|
338 | f4beb510 | bellard | info.si_signo = SIGBUS; |
339 | f4beb510 | bellard | info.si_errno = 0;
|
340 | f4beb510 | bellard | info.si_code = TARGET_SI_KERNEL; |
341 | f4beb510 | bellard | info._sifields._sigfault._addr = 0;
|
342 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
343 | f4beb510 | bellard | break;
|
344 | 1b6b029e | bellard | case EXCP0D_GPF:
|
345 | d2fd1af7 | bellard | /* XXX: potential problem if ABI32 */
|
346 | 84409ddb | j_mayer | #ifndef TARGET_X86_64
|
347 | 851e67a1 | bellard | if (env->eflags & VM_MASK) {
|
348 | 89e957e7 | bellard | handle_vm86_fault(env); |
349 | 84409ddb | j_mayer | } else
|
350 | 84409ddb | j_mayer | #endif
|
351 | 84409ddb | j_mayer | { |
352 | f4beb510 | bellard | info.si_signo = SIGSEGV; |
353 | f4beb510 | bellard | info.si_errno = 0;
|
354 | f4beb510 | bellard | info.si_code = TARGET_SI_KERNEL; |
355 | f4beb510 | bellard | info._sifields._sigfault._addr = 0;
|
356 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
357 | 1b6b029e | bellard | } |
358 | 1b6b029e | bellard | break;
|
359 | b689bc57 | bellard | case EXCP0E_PAGE:
|
360 | b689bc57 | bellard | info.si_signo = SIGSEGV; |
361 | b689bc57 | bellard | info.si_errno = 0;
|
362 | b689bc57 | bellard | if (!(env->error_code & 1)) |
363 | b689bc57 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
364 | b689bc57 | bellard | else
|
365 | b689bc57 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
366 | 970a87a6 | bellard | info._sifields._sigfault._addr = env->cr[2];
|
367 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
368 | b689bc57 | bellard | break;
|
369 | 9de5e440 | bellard | case EXCP00_DIVZ:
|
370 | 84409ddb | j_mayer | #ifndef TARGET_X86_64
|
371 | bc8a22cc | bellard | if (env->eflags & VM_MASK) {
|
372 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
373 | 84409ddb | j_mayer | } else
|
374 | 84409ddb | j_mayer | #endif
|
375 | 84409ddb | j_mayer | { |
376 | bc8a22cc | bellard | /* division by zero */
|
377 | bc8a22cc | bellard | info.si_signo = SIGFPE; |
378 | bc8a22cc | bellard | info.si_errno = 0;
|
379 | bc8a22cc | bellard | info.si_code = TARGET_FPE_INTDIV; |
380 | bc8a22cc | bellard | info._sifields._sigfault._addr = env->eip; |
381 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
382 | bc8a22cc | bellard | } |
383 | 9de5e440 | bellard | break;
|
384 | 01df040b | aliguori | case EXCP01_DB:
|
385 | 447db213 | bellard | case EXCP03_INT3:
|
386 | 84409ddb | j_mayer | #ifndef TARGET_X86_64
|
387 | 447db213 | bellard | if (env->eflags & VM_MASK) {
|
388 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
389 | 84409ddb | j_mayer | } else
|
390 | 84409ddb | j_mayer | #endif
|
391 | 84409ddb | j_mayer | { |
392 | 447db213 | bellard | info.si_signo = SIGTRAP; |
393 | 447db213 | bellard | info.si_errno = 0;
|
394 | 01df040b | aliguori | if (trapnr == EXCP01_DB) {
|
395 | 447db213 | bellard | info.si_code = TARGET_TRAP_BRKPT; |
396 | 447db213 | bellard | info._sifields._sigfault._addr = env->eip; |
397 | 447db213 | bellard | } else {
|
398 | 447db213 | bellard | info.si_code = TARGET_SI_KERNEL; |
399 | 447db213 | bellard | info._sifields._sigfault._addr = 0;
|
400 | 447db213 | bellard | } |
401 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
402 | 447db213 | bellard | } |
403 | 447db213 | bellard | break;
|
404 | 9de5e440 | bellard | case EXCP04_INTO:
|
405 | 9de5e440 | bellard | case EXCP05_BOUND:
|
406 | 84409ddb | j_mayer | #ifndef TARGET_X86_64
|
407 | bc8a22cc | bellard | if (env->eflags & VM_MASK) {
|
408 | 447db213 | bellard | handle_vm86_trap(env, trapnr); |
409 | 84409ddb | j_mayer | } else
|
410 | 84409ddb | j_mayer | #endif
|
411 | 84409ddb | j_mayer | { |
412 | bc8a22cc | bellard | info.si_signo = SIGSEGV; |
413 | bc8a22cc | bellard | info.si_errno = 0;
|
414 | b689bc57 | bellard | info.si_code = TARGET_SI_KERNEL; |
415 | bc8a22cc | bellard | info._sifields._sigfault._addr = 0;
|
416 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
417 | bc8a22cc | bellard | } |
418 | 9de5e440 | bellard | break;
|
419 | 9de5e440 | bellard | case EXCP06_ILLOP:
|
420 | 9de5e440 | bellard | info.si_signo = SIGILL; |
421 | 9de5e440 | bellard | info.si_errno = 0;
|
422 | 9de5e440 | bellard | info.si_code = TARGET_ILL_ILLOPN; |
423 | 9de5e440 | bellard | info._sifields._sigfault._addr = env->eip; |
424 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
425 | 9de5e440 | bellard | break;
|
426 | 9de5e440 | bellard | case EXCP_INTERRUPT:
|
427 | 9de5e440 | bellard | /* just indicate that signals should be handled asap */
|
428 | 9de5e440 | bellard | break;
|
429 | 1fddef4b | bellard | case EXCP_DEBUG:
|
430 | 1fddef4b | bellard | { |
431 | 1fddef4b | bellard | int sig;
|
432 | 1fddef4b | bellard | |
433 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
434 | 1fddef4b | bellard | if (sig)
|
435 | 1fddef4b | bellard | { |
436 | 1fddef4b | bellard | info.si_signo = sig; |
437 | 1fddef4b | bellard | info.si_errno = 0;
|
438 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
439 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
440 | 1fddef4b | bellard | } |
441 | 1fddef4b | bellard | } |
442 | 1fddef4b | bellard | break;
|
443 | 1b6b029e | bellard | default:
|
444 | 970a87a6 | bellard | pc = env->segs[R_CS].base + env->eip; |
445 | 5fafdf24 | ths | fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
|
446 | bc8a22cc | bellard | (long)pc, trapnr);
|
447 | 1b6b029e | bellard | abort(); |
448 | 1b6b029e | bellard | } |
449 | 66fb9763 | bellard | process_pending_signals(env); |
450 | 1b6b029e | bellard | } |
451 | 1b6b029e | bellard | } |
452 | b346ff46 | bellard | #endif
|
453 | b346ff46 | bellard | |
454 | b346ff46 | bellard | #ifdef TARGET_ARM
|
455 | b346ff46 | bellard | |
456 | 992f48a0 | blueswir1 | static void arm_cache_flush(abi_ulong start, abi_ulong last) |
457 | 6f1f31c0 | bellard | { |
458 | 992f48a0 | blueswir1 | abi_ulong addr, last1; |
459 | 6f1f31c0 | bellard | |
460 | 6f1f31c0 | bellard | if (last < start)
|
461 | 6f1f31c0 | bellard | return;
|
462 | 6f1f31c0 | bellard | addr = start; |
463 | 6f1f31c0 | bellard | for(;;) {
|
464 | 6f1f31c0 | bellard | last1 = ((addr + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK) - 1;
|
465 | 6f1f31c0 | bellard | if (last1 > last)
|
466 | 6f1f31c0 | bellard | last1 = last; |
467 | 6f1f31c0 | bellard | tb_invalidate_page_range(addr, last1 + 1);
|
468 | 6f1f31c0 | bellard | if (last1 == last)
|
469 | 6f1f31c0 | bellard | break;
|
470 | 6f1f31c0 | bellard | addr = last1 + 1;
|
471 | 6f1f31c0 | bellard | } |
472 | 6f1f31c0 | bellard | } |
473 | 6f1f31c0 | bellard | |
474 | fbb4a2e3 | pbrook | /* Handle a jump to the kernel code page. */
|
475 | fbb4a2e3 | pbrook | static int |
476 | fbb4a2e3 | pbrook | do_kernel_trap(CPUARMState *env) |
477 | fbb4a2e3 | pbrook | { |
478 | fbb4a2e3 | pbrook | uint32_t addr; |
479 | fbb4a2e3 | pbrook | uint32_t cpsr; |
480 | fbb4a2e3 | pbrook | uint32_t val; |
481 | fbb4a2e3 | pbrook | |
482 | fbb4a2e3 | pbrook | switch (env->regs[15]) { |
483 | fbb4a2e3 | pbrook | case 0xffff0fa0: /* __kernel_memory_barrier */ |
484 | fbb4a2e3 | pbrook | /* ??? No-op. Will need to do better for SMP. */
|
485 | fbb4a2e3 | pbrook | break;
|
486 | fbb4a2e3 | pbrook | case 0xffff0fc0: /* __kernel_cmpxchg */ |
487 | d5975363 | pbrook | /* XXX: This only works between threads, not between processes.
|
488 | d5975363 | pbrook | It's probably possible to implement this with native host
|
489 | d5975363 | pbrook | operations. However things like ldrex/strex are much harder so
|
490 | d5975363 | pbrook | there's not much point trying. */
|
491 | d5975363 | pbrook | start_exclusive(); |
492 | fbb4a2e3 | pbrook | cpsr = cpsr_read(env); |
493 | fbb4a2e3 | pbrook | addr = env->regs[2];
|
494 | fbb4a2e3 | pbrook | /* FIXME: This should SEGV if the access fails. */
|
495 | fbb4a2e3 | pbrook | if (get_user_u32(val, addr))
|
496 | fbb4a2e3 | pbrook | val = ~env->regs[0];
|
497 | fbb4a2e3 | pbrook | if (val == env->regs[0]) { |
498 | fbb4a2e3 | pbrook | val = env->regs[1];
|
499 | fbb4a2e3 | pbrook | /* FIXME: Check for segfaults. */
|
500 | fbb4a2e3 | pbrook | put_user_u32(val, addr); |
501 | fbb4a2e3 | pbrook | env->regs[0] = 0; |
502 | fbb4a2e3 | pbrook | cpsr |= CPSR_C; |
503 | fbb4a2e3 | pbrook | } else {
|
504 | fbb4a2e3 | pbrook | env->regs[0] = -1; |
505 | fbb4a2e3 | pbrook | cpsr &= ~CPSR_C; |
506 | fbb4a2e3 | pbrook | } |
507 | fbb4a2e3 | pbrook | cpsr_write(env, cpsr, CPSR_C); |
508 | d5975363 | pbrook | end_exclusive(); |
509 | fbb4a2e3 | pbrook | break;
|
510 | fbb4a2e3 | pbrook | case 0xffff0fe0: /* __kernel_get_tls */ |
511 | fbb4a2e3 | pbrook | env->regs[0] = env->cp15.c13_tls2;
|
512 | fbb4a2e3 | pbrook | break;
|
513 | fbb4a2e3 | pbrook | default:
|
514 | fbb4a2e3 | pbrook | return 1; |
515 | fbb4a2e3 | pbrook | } |
516 | fbb4a2e3 | pbrook | /* Jump back to the caller. */
|
517 | fbb4a2e3 | pbrook | addr = env->regs[14];
|
518 | fbb4a2e3 | pbrook | if (addr & 1) { |
519 | fbb4a2e3 | pbrook | env->thumb = 1;
|
520 | fbb4a2e3 | pbrook | addr &= ~1;
|
521 | fbb4a2e3 | pbrook | } |
522 | fbb4a2e3 | pbrook | env->regs[15] = addr;
|
523 | fbb4a2e3 | pbrook | |
524 | fbb4a2e3 | pbrook | return 0; |
525 | fbb4a2e3 | pbrook | } |
526 | fbb4a2e3 | pbrook | |
527 | b346ff46 | bellard | void cpu_loop(CPUARMState *env)
|
528 | b346ff46 | bellard | { |
529 | b346ff46 | bellard | int trapnr;
|
530 | b346ff46 | bellard | unsigned int n, insn; |
531 | c227f099 | Anthony Liguori | target_siginfo_t info; |
532 | b5ff1b31 | bellard | uint32_t addr; |
533 | 3b46e624 | ths | |
534 | b346ff46 | bellard | for(;;) {
|
535 | d5975363 | pbrook | cpu_exec_start(env); |
536 | b346ff46 | bellard | trapnr = cpu_arm_exec(env); |
537 | d5975363 | pbrook | cpu_exec_end(env); |
538 | b346ff46 | bellard | switch(trapnr) {
|
539 | b346ff46 | bellard | case EXCP_UDEF:
|
540 | c6981055 | bellard | { |
541 | c6981055 | bellard | TaskState *ts = env->opaque; |
542 | c6981055 | bellard | uint32_t opcode; |
543 | 6d9a42be | aurel32 | int rc;
|
544 | c6981055 | bellard | |
545 | c6981055 | bellard | /* we handle the FPU emulation here, as Linux */
|
546 | c6981055 | bellard | /* we get the opcode */
|
547 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
548 | 2f619698 | bellard | get_user_u32(opcode, env->regs[15]);
|
549 | 3b46e624 | ths | |
550 | 6d9a42be | aurel32 | rc = EmulateAll(opcode, &ts->fpa, env); |
551 | 6d9a42be | aurel32 | if (rc == 0) { /* illegal instruction */ |
552 | c6981055 | bellard | info.si_signo = SIGILL; |
553 | c6981055 | bellard | info.si_errno = 0;
|
554 | c6981055 | bellard | info.si_code = TARGET_ILL_ILLOPN; |
555 | c6981055 | bellard | info._sifields._sigfault._addr = env->regs[15];
|
556 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
557 | 6d9a42be | aurel32 | } else if (rc < 0) { /* FP exception */ |
558 | 6d9a42be | aurel32 | int arm_fpe=0; |
559 | 6d9a42be | aurel32 | |
560 | 6d9a42be | aurel32 | /* translate softfloat flags to FPSR flags */
|
561 | 6d9a42be | aurel32 | if (-rc & float_flag_invalid)
|
562 | 6d9a42be | aurel32 | arm_fpe |= BIT_IOC; |
563 | 6d9a42be | aurel32 | if (-rc & float_flag_divbyzero)
|
564 | 6d9a42be | aurel32 | arm_fpe |= BIT_DZC; |
565 | 6d9a42be | aurel32 | if (-rc & float_flag_overflow)
|
566 | 6d9a42be | aurel32 | arm_fpe |= BIT_OFC; |
567 | 6d9a42be | aurel32 | if (-rc & float_flag_underflow)
|
568 | 6d9a42be | aurel32 | arm_fpe |= BIT_UFC; |
569 | 6d9a42be | aurel32 | if (-rc & float_flag_inexact)
|
570 | 6d9a42be | aurel32 | arm_fpe |= BIT_IXC; |
571 | 6d9a42be | aurel32 | |
572 | 6d9a42be | aurel32 | FPSR fpsr = ts->fpa.fpsr; |
573 | 6d9a42be | aurel32 | //printf("fpsr 0x%x, arm_fpe 0x%x\n",fpsr,arm_fpe);
|
574 | 6d9a42be | aurel32 | |
575 | 6d9a42be | aurel32 | if (fpsr & (arm_fpe << 16)) { /* exception enabled? */ |
576 | 6d9a42be | aurel32 | info.si_signo = SIGFPE; |
577 | 6d9a42be | aurel32 | info.si_errno = 0;
|
578 | 6d9a42be | aurel32 | |
579 | 6d9a42be | aurel32 | /* ordered by priority, least first */
|
580 | 6d9a42be | aurel32 | if (arm_fpe & BIT_IXC) info.si_code = TARGET_FPE_FLTRES;
|
581 | 6d9a42be | aurel32 | if (arm_fpe & BIT_UFC) info.si_code = TARGET_FPE_FLTUND;
|
582 | 6d9a42be | aurel32 | if (arm_fpe & BIT_OFC) info.si_code = TARGET_FPE_FLTOVF;
|
583 | 6d9a42be | aurel32 | if (arm_fpe & BIT_DZC) info.si_code = TARGET_FPE_FLTDIV;
|
584 | 6d9a42be | aurel32 | if (arm_fpe & BIT_IOC) info.si_code = TARGET_FPE_FLTINV;
|
585 | 6d9a42be | aurel32 | |
586 | 6d9a42be | aurel32 | info._sifields._sigfault._addr = env->regs[15];
|
587 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
588 | 6d9a42be | aurel32 | } else {
|
589 | 6d9a42be | aurel32 | env->regs[15] += 4; |
590 | 6d9a42be | aurel32 | } |
591 | 6d9a42be | aurel32 | |
592 | 6d9a42be | aurel32 | /* accumulate unenabled exceptions */
|
593 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_IXE)) && (arm_fpe & BIT_IXC))
|
594 | 6d9a42be | aurel32 | fpsr |= BIT_IXC; |
595 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_UFE)) && (arm_fpe & BIT_UFC))
|
596 | 6d9a42be | aurel32 | fpsr |= BIT_UFC; |
597 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_OFE)) && (arm_fpe & BIT_OFC))
|
598 | 6d9a42be | aurel32 | fpsr |= BIT_OFC; |
599 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_DZE)) && (arm_fpe & BIT_DZC))
|
600 | 6d9a42be | aurel32 | fpsr |= BIT_DZC; |
601 | 6d9a42be | aurel32 | if ((!(fpsr & BIT_IOE)) && (arm_fpe & BIT_IOC))
|
602 | 6d9a42be | aurel32 | fpsr |= BIT_IOC; |
603 | 6d9a42be | aurel32 | ts->fpa.fpsr=fpsr; |
604 | 6d9a42be | aurel32 | } else { /* everything OK */ |
605 | c6981055 | bellard | /* increment PC */
|
606 | c6981055 | bellard | env->regs[15] += 4; |
607 | c6981055 | bellard | } |
608 | c6981055 | bellard | } |
609 | b346ff46 | bellard | break;
|
610 | b346ff46 | bellard | case EXCP_SWI:
|
611 | 06c949e6 | pbrook | case EXCP_BKPT:
|
612 | b346ff46 | bellard | { |
613 | ce4defa0 | pbrook | env->eabi = 1;
|
614 | b346ff46 | bellard | /* system call */
|
615 | 06c949e6 | pbrook | if (trapnr == EXCP_BKPT) {
|
616 | 06c949e6 | pbrook | if (env->thumb) {
|
617 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
618 | 2f619698 | bellard | get_user_u16(insn, env->regs[15]);
|
619 | 06c949e6 | pbrook | n = insn & 0xff;
|
620 | 06c949e6 | pbrook | env->regs[15] += 2; |
621 | 06c949e6 | pbrook | } else {
|
622 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
623 | 2f619698 | bellard | get_user_u32(insn, env->regs[15]);
|
624 | 06c949e6 | pbrook | n = (insn & 0xf) | ((insn >> 4) & 0xff0); |
625 | 06c949e6 | pbrook | env->regs[15] += 4; |
626 | 06c949e6 | pbrook | } |
627 | 192c7bd9 | bellard | } else {
|
628 | 06c949e6 | pbrook | if (env->thumb) {
|
629 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
630 | 2f619698 | bellard | get_user_u16(insn, env->regs[15] - 2); |
631 | 06c949e6 | pbrook | n = insn & 0xff;
|
632 | 06c949e6 | pbrook | } else {
|
633 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
634 | 2f619698 | bellard | get_user_u32(insn, env->regs[15] - 4); |
635 | 06c949e6 | pbrook | n = insn & 0xffffff;
|
636 | 06c949e6 | pbrook | } |
637 | 192c7bd9 | bellard | } |
638 | 192c7bd9 | bellard | |
639 | 6f1f31c0 | bellard | if (n == ARM_NR_cacheflush) {
|
640 | 6f1f31c0 | bellard | arm_cache_flush(env->regs[0], env->regs[1]); |
641 | a4f81979 | bellard | } else if (n == ARM_NR_semihosting |
642 | a4f81979 | bellard | || n == ARM_NR_thumb_semihosting) { |
643 | a4f81979 | bellard | env->regs[0] = do_arm_semihosting (env);
|
644 | ce4defa0 | pbrook | } else if (n == 0 || n >= ARM_SYSCALL_BASE |
645 | 192c7bd9 | bellard | || (env->thumb && n == ARM_THUMB_SYSCALL)) { |
646 | b346ff46 | bellard | /* linux syscall */
|
647 | ce4defa0 | pbrook | if (env->thumb || n == 0) { |
648 | 192c7bd9 | bellard | n = env->regs[7];
|
649 | 192c7bd9 | bellard | } else {
|
650 | 192c7bd9 | bellard | n -= ARM_SYSCALL_BASE; |
651 | ce4defa0 | pbrook | env->eabi = 0;
|
652 | 192c7bd9 | bellard | } |
653 | fbb4a2e3 | pbrook | if ( n > ARM_NR_BASE) {
|
654 | fbb4a2e3 | pbrook | switch (n) {
|
655 | fbb4a2e3 | pbrook | case ARM_NR_cacheflush:
|
656 | fbb4a2e3 | pbrook | arm_cache_flush(env->regs[0], env->regs[1]); |
657 | fbb4a2e3 | pbrook | break;
|
658 | fbb4a2e3 | pbrook | case ARM_NR_set_tls:
|
659 | fbb4a2e3 | pbrook | cpu_set_tls(env, env->regs[0]);
|
660 | fbb4a2e3 | pbrook | env->regs[0] = 0; |
661 | fbb4a2e3 | pbrook | break;
|
662 | fbb4a2e3 | pbrook | default:
|
663 | fbb4a2e3 | pbrook | gemu_log("qemu: Unsupported ARM syscall: 0x%x\n",
|
664 | fbb4a2e3 | pbrook | n); |
665 | fbb4a2e3 | pbrook | env->regs[0] = -TARGET_ENOSYS;
|
666 | fbb4a2e3 | pbrook | break;
|
667 | fbb4a2e3 | pbrook | } |
668 | fbb4a2e3 | pbrook | } else {
|
669 | fbb4a2e3 | pbrook | env->regs[0] = do_syscall(env,
|
670 | fbb4a2e3 | pbrook | n, |
671 | fbb4a2e3 | pbrook | env->regs[0],
|
672 | fbb4a2e3 | pbrook | env->regs[1],
|
673 | fbb4a2e3 | pbrook | env->regs[2],
|
674 | fbb4a2e3 | pbrook | env->regs[3],
|
675 | fbb4a2e3 | pbrook | env->regs[4],
|
676 | fbb4a2e3 | pbrook | env->regs[5]);
|
677 | fbb4a2e3 | pbrook | } |
678 | b346ff46 | bellard | } else {
|
679 | b346ff46 | bellard | goto error;
|
680 | b346ff46 | bellard | } |
681 | b346ff46 | bellard | } |
682 | b346ff46 | bellard | break;
|
683 | 43fff238 | bellard | case EXCP_INTERRUPT:
|
684 | 43fff238 | bellard | /* just indicate that signals should be handled asap */
|
685 | 43fff238 | bellard | break;
|
686 | 68016c62 | bellard | case EXCP_PREFETCH_ABORT:
|
687 | eae473c1 | balrog | addr = env->cp15.c6_insn; |
688 | b5ff1b31 | bellard | goto do_segv;
|
689 | 68016c62 | bellard | case EXCP_DATA_ABORT:
|
690 | eae473c1 | balrog | addr = env->cp15.c6_data; |
691 | b5ff1b31 | bellard | goto do_segv;
|
692 | b5ff1b31 | bellard | do_segv:
|
693 | 68016c62 | bellard | { |
694 | 68016c62 | bellard | info.si_signo = SIGSEGV; |
695 | 68016c62 | bellard | info.si_errno = 0;
|
696 | 68016c62 | bellard | /* XXX: check env->error_code */
|
697 | 68016c62 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
698 | b5ff1b31 | bellard | info._sifields._sigfault._addr = addr; |
699 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
700 | 68016c62 | bellard | } |
701 | 68016c62 | bellard | break;
|
702 | 1fddef4b | bellard | case EXCP_DEBUG:
|
703 | 1fddef4b | bellard | { |
704 | 1fddef4b | bellard | int sig;
|
705 | 1fddef4b | bellard | |
706 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
707 | 1fddef4b | bellard | if (sig)
|
708 | 1fddef4b | bellard | { |
709 | 1fddef4b | bellard | info.si_signo = sig; |
710 | 1fddef4b | bellard | info.si_errno = 0;
|
711 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
712 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
713 | 1fddef4b | bellard | } |
714 | 1fddef4b | bellard | } |
715 | 1fddef4b | bellard | break;
|
716 | fbb4a2e3 | pbrook | case EXCP_KERNEL_TRAP:
|
717 | fbb4a2e3 | pbrook | if (do_kernel_trap(env))
|
718 | fbb4a2e3 | pbrook | goto error;
|
719 | fbb4a2e3 | pbrook | break;
|
720 | b346ff46 | bellard | default:
|
721 | b346ff46 | bellard | error:
|
722 | 5fafdf24 | ths | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
723 | b346ff46 | bellard | trapnr); |
724 | 7fe48483 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
725 | b346ff46 | bellard | abort(); |
726 | b346ff46 | bellard | } |
727 | b346ff46 | bellard | process_pending_signals(env); |
728 | b346ff46 | bellard | } |
729 | b346ff46 | bellard | } |
730 | b346ff46 | bellard | |
731 | b346ff46 | bellard | #endif
|
732 | 1b6b029e | bellard | |
733 | 93ac68bc | bellard | #ifdef TARGET_SPARC
|
734 | ed23fbd9 | blueswir1 | #define SPARC64_STACK_BIAS 2047 |
735 | 93ac68bc | bellard | |
736 | 060366c5 | bellard | //#define DEBUG_WIN
|
737 | 060366c5 | bellard | |
738 | 2623cbaf | bellard | /* WARNING: dealing with register windows _is_ complicated. More info
|
739 | 2623cbaf | bellard | can be found at http://www.sics.se/~psm/sparcstack.html */
|
740 | 060366c5 | bellard | static inline int get_reg_index(CPUSPARCState *env, int cwp, int index) |
741 | 060366c5 | bellard | { |
742 | 1a14026e | blueswir1 | index = (index + cwp * 16) % (16 * env->nwindows); |
743 | 060366c5 | bellard | /* wrap handling : if cwp is on the last window, then we use the
|
744 | 060366c5 | bellard | registers 'after' the end */
|
745 | 1a14026e | blueswir1 | if (index < 8 && env->cwp == env->nwindows - 1) |
746 | 1a14026e | blueswir1 | index += 16 * env->nwindows;
|
747 | 060366c5 | bellard | return index;
|
748 | 060366c5 | bellard | } |
749 | 060366c5 | bellard | |
750 | 2623cbaf | bellard | /* save the register window 'cwp1' */
|
751 | 2623cbaf | bellard | static inline void save_window_offset(CPUSPARCState *env, int cwp1) |
752 | 060366c5 | bellard | { |
753 | 2623cbaf | bellard | unsigned int i; |
754 | 992f48a0 | blueswir1 | abi_ulong sp_ptr; |
755 | 3b46e624 | ths | |
756 | 53a5960a | pbrook | sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
|
757 | ed23fbd9 | blueswir1 | #ifdef TARGET_SPARC64
|
758 | ed23fbd9 | blueswir1 | if (sp_ptr & 3) |
759 | ed23fbd9 | blueswir1 | sp_ptr += SPARC64_STACK_BIAS; |
760 | ed23fbd9 | blueswir1 | #endif
|
761 | 060366c5 | bellard | #if defined(DEBUG_WIN)
|
762 | 2daf0284 | blueswir1 | printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n", |
763 | 2daf0284 | blueswir1 | sp_ptr, cwp1); |
764 | 060366c5 | bellard | #endif
|
765 | 2623cbaf | bellard | for(i = 0; i < 16; i++) { |
766 | 2f619698 | bellard | /* FIXME - what to do if put_user() fails? */
|
767 | 2f619698 | bellard | put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
|
768 | 992f48a0 | blueswir1 | sp_ptr += sizeof(abi_ulong);
|
769 | 2623cbaf | bellard | } |
770 | 060366c5 | bellard | } |
771 | 060366c5 | bellard | |
772 | 060366c5 | bellard | static void save_window(CPUSPARCState *env) |
773 | 060366c5 | bellard | { |
774 | 5ef54116 | bellard | #ifndef TARGET_SPARC64
|
775 | 2623cbaf | bellard | unsigned int new_wim; |
776 | 1a14026e | blueswir1 | new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) & |
777 | 1a14026e | blueswir1 | ((1LL << env->nwindows) - 1); |
778 | 1a14026e | blueswir1 | save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
|
779 | 2623cbaf | bellard | env->wim = new_wim; |
780 | 5ef54116 | bellard | #else
|
781 | 1a14026e | blueswir1 | save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
|
782 | 5ef54116 | bellard | env->cansave++; |
783 | 5ef54116 | bellard | env->canrestore--; |
784 | 5ef54116 | bellard | #endif
|
785 | 060366c5 | bellard | } |
786 | 060366c5 | bellard | |
787 | 060366c5 | bellard | static void restore_window(CPUSPARCState *env) |
788 | 060366c5 | bellard | { |
789 | eda52953 | blueswir1 | #ifndef TARGET_SPARC64
|
790 | eda52953 | blueswir1 | unsigned int new_wim; |
791 | eda52953 | blueswir1 | #endif
|
792 | eda52953 | blueswir1 | unsigned int i, cwp1; |
793 | 992f48a0 | blueswir1 | abi_ulong sp_ptr; |
794 | 3b46e624 | ths | |
795 | eda52953 | blueswir1 | #ifndef TARGET_SPARC64
|
796 | 1a14026e | blueswir1 | new_wim = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) & |
797 | 1a14026e | blueswir1 | ((1LL << env->nwindows) - 1); |
798 | eda52953 | blueswir1 | #endif
|
799 | 3b46e624 | ths | |
800 | 060366c5 | bellard | /* restore the invalid window */
|
801 | 1a14026e | blueswir1 | cwp1 = cpu_cwp_inc(env, env->cwp + 1);
|
802 | 53a5960a | pbrook | sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
|
803 | ed23fbd9 | blueswir1 | #ifdef TARGET_SPARC64
|
804 | ed23fbd9 | blueswir1 | if (sp_ptr & 3) |
805 | ed23fbd9 | blueswir1 | sp_ptr += SPARC64_STACK_BIAS; |
806 | ed23fbd9 | blueswir1 | #endif
|
807 | 060366c5 | bellard | #if defined(DEBUG_WIN)
|
808 | 2daf0284 | blueswir1 | printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n", |
809 | 2daf0284 | blueswir1 | sp_ptr, cwp1); |
810 | 060366c5 | bellard | #endif
|
811 | 2623cbaf | bellard | for(i = 0; i < 16; i++) { |
812 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
813 | 2f619698 | bellard | get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
|
814 | 992f48a0 | blueswir1 | sp_ptr += sizeof(abi_ulong);
|
815 | 2623cbaf | bellard | } |
816 | 5ef54116 | bellard | #ifdef TARGET_SPARC64
|
817 | 5ef54116 | bellard | env->canrestore++; |
818 | 1a14026e | blueswir1 | if (env->cleanwin < env->nwindows - 1) |
819 | 1a14026e | blueswir1 | env->cleanwin++; |
820 | 5ef54116 | bellard | env->cansave--; |
821 | eda52953 | blueswir1 | #else
|
822 | eda52953 | blueswir1 | env->wim = new_wim; |
823 | 5ef54116 | bellard | #endif
|
824 | 060366c5 | bellard | } |
825 | 060366c5 | bellard | |
826 | 060366c5 | bellard | static void flush_windows(CPUSPARCState *env) |
827 | 060366c5 | bellard | { |
828 | 060366c5 | bellard | int offset, cwp1;
|
829 | 2623cbaf | bellard | |
830 | 2623cbaf | bellard | offset = 1;
|
831 | 060366c5 | bellard | for(;;) {
|
832 | 060366c5 | bellard | /* if restore would invoke restore_window(), then we can stop */
|
833 | 1a14026e | blueswir1 | cwp1 = cpu_cwp_inc(env, env->cwp + offset); |
834 | eda52953 | blueswir1 | #ifndef TARGET_SPARC64
|
835 | 060366c5 | bellard | if (env->wim & (1 << cwp1)) |
836 | 060366c5 | bellard | break;
|
837 | eda52953 | blueswir1 | #else
|
838 | eda52953 | blueswir1 | if (env->canrestore == 0) |
839 | eda52953 | blueswir1 | break;
|
840 | eda52953 | blueswir1 | env->cansave++; |
841 | eda52953 | blueswir1 | env->canrestore--; |
842 | eda52953 | blueswir1 | #endif
|
843 | 2623cbaf | bellard | save_window_offset(env, cwp1); |
844 | 060366c5 | bellard | offset++; |
845 | 060366c5 | bellard | } |
846 | 1a14026e | blueswir1 | cwp1 = cpu_cwp_inc(env, env->cwp + 1);
|
847 | eda52953 | blueswir1 | #ifndef TARGET_SPARC64
|
848 | eda52953 | blueswir1 | /* set wim so that restore will reload the registers */
|
849 | 2623cbaf | bellard | env->wim = 1 << cwp1;
|
850 | eda52953 | blueswir1 | #endif
|
851 | 2623cbaf | bellard | #if defined(DEBUG_WIN)
|
852 | 2623cbaf | bellard | printf("flush_windows: nb=%d\n", offset - 1); |
853 | 80a9d035 | bellard | #endif
|
854 | 2623cbaf | bellard | } |
855 | 060366c5 | bellard | |
856 | 93ac68bc | bellard | void cpu_loop (CPUSPARCState *env)
|
857 | 93ac68bc | bellard | { |
858 | 060366c5 | bellard | int trapnr, ret;
|
859 | c227f099 | Anthony Liguori | target_siginfo_t info; |
860 | 3b46e624 | ths | |
861 | 060366c5 | bellard | while (1) { |
862 | 060366c5 | bellard | trapnr = cpu_sparc_exec (env); |
863 | 3b46e624 | ths | |
864 | 060366c5 | bellard | switch (trapnr) {
|
865 | 5ef54116 | bellard | #ifndef TARGET_SPARC64
|
866 | 5fafdf24 | ths | case 0x88: |
867 | 060366c5 | bellard | case 0x90: |
868 | 5ef54116 | bellard | #else
|
869 | cb33da57 | blueswir1 | case 0x110: |
870 | 5ef54116 | bellard | case 0x16d: |
871 | 5ef54116 | bellard | #endif
|
872 | 060366c5 | bellard | ret = do_syscall (env, env->gregs[1],
|
873 | 5fafdf24 | ths | env->regwptr[0], env->regwptr[1], |
874 | 5fafdf24 | ths | env->regwptr[2], env->regwptr[3], |
875 | 060366c5 | bellard | env->regwptr[4], env->regwptr[5]); |
876 | 060366c5 | bellard | if ((unsigned int)ret >= (unsigned int)(-515)) { |
877 | 992f48a0 | blueswir1 | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
|
878 | 27908725 | bellard | env->xcc |= PSR_CARRY; |
879 | 27908725 | bellard | #else
|
880 | 060366c5 | bellard | env->psr |= PSR_CARRY; |
881 | 27908725 | bellard | #endif
|
882 | 060366c5 | bellard | ret = -ret; |
883 | 060366c5 | bellard | } else {
|
884 | 992f48a0 | blueswir1 | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
|
885 | 27908725 | bellard | env->xcc &= ~PSR_CARRY; |
886 | 27908725 | bellard | #else
|
887 | 060366c5 | bellard | env->psr &= ~PSR_CARRY; |
888 | 27908725 | bellard | #endif
|
889 | 060366c5 | bellard | } |
890 | 060366c5 | bellard | env->regwptr[0] = ret;
|
891 | 060366c5 | bellard | /* next instruction */
|
892 | 060366c5 | bellard | env->pc = env->npc; |
893 | 060366c5 | bellard | env->npc = env->npc + 4;
|
894 | 060366c5 | bellard | break;
|
895 | 060366c5 | bellard | case 0x83: /* flush windows */ |
896 | 992f48a0 | blueswir1 | #ifdef TARGET_ABI32
|
897 | 992f48a0 | blueswir1 | case 0x103: |
898 | 992f48a0 | blueswir1 | #endif
|
899 | 2623cbaf | bellard | flush_windows(env); |
900 | 060366c5 | bellard | /* next instruction */
|
901 | 060366c5 | bellard | env->pc = env->npc; |
902 | 060366c5 | bellard | env->npc = env->npc + 4;
|
903 | 060366c5 | bellard | break;
|
904 | 3475187d | bellard | #ifndef TARGET_SPARC64
|
905 | 060366c5 | bellard | case TT_WIN_OVF: /* window overflow */ |
906 | 060366c5 | bellard | save_window(env); |
907 | 060366c5 | bellard | break;
|
908 | 060366c5 | bellard | case TT_WIN_UNF: /* window underflow */ |
909 | 060366c5 | bellard | restore_window(env); |
910 | 060366c5 | bellard | break;
|
911 | 61ff6f58 | bellard | case TT_TFAULT:
|
912 | 61ff6f58 | bellard | case TT_DFAULT:
|
913 | 61ff6f58 | bellard | { |
914 | 61ff6f58 | bellard | info.si_signo = SIGSEGV; |
915 | 61ff6f58 | bellard | info.si_errno = 0;
|
916 | 61ff6f58 | bellard | /* XXX: check env->error_code */
|
917 | 61ff6f58 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
918 | 61ff6f58 | bellard | info._sifields._sigfault._addr = env->mmuregs[4];
|
919 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
920 | 61ff6f58 | bellard | } |
921 | 61ff6f58 | bellard | break;
|
922 | 3475187d | bellard | #else
|
923 | 5ef54116 | bellard | case TT_SPILL: /* window overflow */ |
924 | 5ef54116 | bellard | save_window(env); |
925 | 5ef54116 | bellard | break;
|
926 | 5ef54116 | bellard | case TT_FILL: /* window underflow */ |
927 | 5ef54116 | bellard | restore_window(env); |
928 | 5ef54116 | bellard | break;
|
929 | 7f84a729 | blueswir1 | case TT_TFAULT:
|
930 | 7f84a729 | blueswir1 | case TT_DFAULT:
|
931 | 7f84a729 | blueswir1 | { |
932 | 7f84a729 | blueswir1 | info.si_signo = SIGSEGV; |
933 | 7f84a729 | blueswir1 | info.si_errno = 0;
|
934 | 7f84a729 | blueswir1 | /* XXX: check env->error_code */
|
935 | 7f84a729 | blueswir1 | info.si_code = TARGET_SEGV_MAPERR; |
936 | 7f84a729 | blueswir1 | if (trapnr == TT_DFAULT)
|
937 | 7f84a729 | blueswir1 | info._sifields._sigfault._addr = env->dmmuregs[4];
|
938 | 7f84a729 | blueswir1 | else
|
939 | 8194f35a | Igor Kovalenko | info._sifields._sigfault._addr = cpu_tsptr(env)->tpc; |
940 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
941 | 7f84a729 | blueswir1 | } |
942 | 7f84a729 | blueswir1 | break;
|
943 | 27524dc3 | bellard | #ifndef TARGET_ABI32
|
944 | 5bfb56b2 | blueswir1 | case 0x16e: |
945 | 5bfb56b2 | blueswir1 | flush_windows(env); |
946 | 5bfb56b2 | blueswir1 | sparc64_get_context(env); |
947 | 5bfb56b2 | blueswir1 | break;
|
948 | 5bfb56b2 | blueswir1 | case 0x16f: |
949 | 5bfb56b2 | blueswir1 | flush_windows(env); |
950 | 5bfb56b2 | blueswir1 | sparc64_set_context(env); |
951 | 5bfb56b2 | blueswir1 | break;
|
952 | 3475187d | bellard | #endif
|
953 | 27524dc3 | bellard | #endif
|
954 | 48dc41eb | bellard | case EXCP_INTERRUPT:
|
955 | 48dc41eb | bellard | /* just indicate that signals should be handled asap */
|
956 | 48dc41eb | bellard | break;
|
957 | 1fddef4b | bellard | case EXCP_DEBUG:
|
958 | 1fddef4b | bellard | { |
959 | 1fddef4b | bellard | int sig;
|
960 | 1fddef4b | bellard | |
961 | 1fddef4b | bellard | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
962 | 1fddef4b | bellard | if (sig)
|
963 | 1fddef4b | bellard | { |
964 | 1fddef4b | bellard | info.si_signo = sig; |
965 | 1fddef4b | bellard | info.si_errno = 0;
|
966 | 1fddef4b | bellard | info.si_code = TARGET_TRAP_BRKPT; |
967 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
968 | 1fddef4b | bellard | } |
969 | 1fddef4b | bellard | } |
970 | 1fddef4b | bellard | break;
|
971 | 060366c5 | bellard | default:
|
972 | 060366c5 | bellard | printf ("Unhandled trap: 0x%x\n", trapnr);
|
973 | 7fe48483 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
974 | 060366c5 | bellard | exit (1);
|
975 | 060366c5 | bellard | } |
976 | 060366c5 | bellard | process_pending_signals (env); |
977 | 060366c5 | bellard | } |
978 | 93ac68bc | bellard | } |
979 | 93ac68bc | bellard | |
980 | 93ac68bc | bellard | #endif
|
981 | 93ac68bc | bellard | |
982 | 67867308 | bellard | #ifdef TARGET_PPC
|
983 | 9fddaa0c | bellard | static inline uint64_t cpu_ppc_get_tb (CPUState *env) |
984 | 9fddaa0c | bellard | { |
985 | 9fddaa0c | bellard | /* TO FIX */
|
986 | 9fddaa0c | bellard | return 0; |
987 | 9fddaa0c | bellard | } |
988 | 3b46e624 | ths | |
989 | 9fddaa0c | bellard | uint32_t cpu_ppc_load_tbl (CPUState *env) |
990 | 9fddaa0c | bellard | { |
991 | 9fddaa0c | bellard | return cpu_ppc_get_tb(env) & 0xFFFFFFFF; |
992 | 9fddaa0c | bellard | } |
993 | 3b46e624 | ths | |
994 | 9fddaa0c | bellard | uint32_t cpu_ppc_load_tbu (CPUState *env) |
995 | 9fddaa0c | bellard | { |
996 | 9fddaa0c | bellard | return cpu_ppc_get_tb(env) >> 32; |
997 | 9fddaa0c | bellard | } |
998 | 3b46e624 | ths | |
999 | a062e36c | j_mayer | uint32_t cpu_ppc_load_atbl (CPUState *env) |
1000 | 9fddaa0c | bellard | { |
1001 | a062e36c | j_mayer | return cpu_ppc_get_tb(env) & 0xFFFFFFFF; |
1002 | 9fddaa0c | bellard | } |
1003 | 5fafdf24 | ths | |
1004 | a062e36c | j_mayer | uint32_t cpu_ppc_load_atbu (CPUState *env) |
1005 | 9fddaa0c | bellard | { |
1006 | a062e36c | j_mayer | return cpu_ppc_get_tb(env) >> 32; |
1007 | 9fddaa0c | bellard | } |
1008 | 76a66253 | j_mayer | |
1009 | 76a66253 | j_mayer | uint32_t cpu_ppc601_load_rtcu (CPUState *env) |
1010 | 76a66253 | j_mayer | __attribute__ (( alias ("cpu_ppc_load_tbu") ));
|
1011 | 76a66253 | j_mayer | |
1012 | 76a66253 | j_mayer | uint32_t cpu_ppc601_load_rtcl (CPUState *env) |
1013 | 9fddaa0c | bellard | { |
1014 | 76a66253 | j_mayer | return cpu_ppc_load_tbl(env) & 0x3FFFFF80; |
1015 | 9fddaa0c | bellard | } |
1016 | 76a66253 | j_mayer | |
1017 | a750fc0b | j_mayer | /* XXX: to be fixed */
|
1018 | c227f099 | Anthony Liguori | int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, target_ulong *valp) |
1019 | a750fc0b | j_mayer | { |
1020 | a750fc0b | j_mayer | return -1; |
1021 | a750fc0b | j_mayer | } |
1022 | a750fc0b | j_mayer | |
1023 | c227f099 | Anthony Liguori | int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, target_ulong val) |
1024 | a750fc0b | j_mayer | { |
1025 | a750fc0b | j_mayer | return -1; |
1026 | a750fc0b | j_mayer | } |
1027 | a750fc0b | j_mayer | |
1028 | 001faf32 | Blue Swirl | #define EXCP_DUMP(env, fmt, ...) \
|
1029 | 001faf32 | Blue Swirl | do { \
|
1030 | 001faf32 | Blue Swirl | fprintf(stderr, fmt , ## __VA_ARGS__); \ |
1031 | 001faf32 | Blue Swirl | cpu_dump_state(env, stderr, fprintf, 0); \
|
1032 | 001faf32 | Blue Swirl | qemu_log(fmt, ## __VA_ARGS__); \ |
1033 | 430c7ec7 | malc | if (logfile) \
|
1034 | 430c7ec7 | malc | log_cpu_state(env, 0); \
|
1035 | e1833e1f | j_mayer | } while (0) |
1036 | e1833e1f | j_mayer | |
1037 | 56f066bb | Nathan Froyd | static int do_store_exclusive(CPUPPCState *env) |
1038 | 56f066bb | Nathan Froyd | { |
1039 | 56f066bb | Nathan Froyd | target_ulong addr; |
1040 | 56f066bb | Nathan Froyd | target_ulong page_addr; |
1041 | 56f066bb | Nathan Froyd | target_ulong val; |
1042 | 56f066bb | Nathan Froyd | int flags;
|
1043 | 56f066bb | Nathan Froyd | int segv = 0; |
1044 | 56f066bb | Nathan Froyd | |
1045 | 56f066bb | Nathan Froyd | addr = env->reserve_ea; |
1046 | 56f066bb | Nathan Froyd | page_addr = addr & TARGET_PAGE_MASK; |
1047 | 56f066bb | Nathan Froyd | start_exclusive(); |
1048 | 56f066bb | Nathan Froyd | mmap_lock(); |
1049 | 56f066bb | Nathan Froyd | flags = page_get_flags(page_addr); |
1050 | 56f066bb | Nathan Froyd | if ((flags & PAGE_READ) == 0) { |
1051 | 56f066bb | Nathan Froyd | segv = 1;
|
1052 | 56f066bb | Nathan Froyd | } else {
|
1053 | 56f066bb | Nathan Froyd | int reg = env->reserve_info & 0x1f; |
1054 | 56f066bb | Nathan Froyd | int size = (env->reserve_info >> 5) & 0xf; |
1055 | 56f066bb | Nathan Froyd | int stored = 0; |
1056 | 56f066bb | Nathan Froyd | |
1057 | 56f066bb | Nathan Froyd | if (addr == env->reserve_addr) {
|
1058 | 56f066bb | Nathan Froyd | switch (size) {
|
1059 | 56f066bb | Nathan Froyd | case 1: segv = get_user_u8(val, addr); break; |
1060 | 56f066bb | Nathan Froyd | case 2: segv = get_user_u16(val, addr); break; |
1061 | 56f066bb | Nathan Froyd | case 4: segv = get_user_u32(val, addr); break; |
1062 | 56f066bb | Nathan Froyd | #if defined(TARGET_PPC64)
|
1063 | 56f066bb | Nathan Froyd | case 8: segv = get_user_u64(val, addr); break; |
1064 | 56f066bb | Nathan Froyd | #endif
|
1065 | 56f066bb | Nathan Froyd | default: abort();
|
1066 | 56f066bb | Nathan Froyd | } |
1067 | 56f066bb | Nathan Froyd | if (!segv && val == env->reserve_val) {
|
1068 | 56f066bb | Nathan Froyd | val = env->gpr[reg]; |
1069 | 56f066bb | Nathan Froyd | switch (size) {
|
1070 | 56f066bb | Nathan Froyd | case 1: segv = put_user_u8(val, addr); break; |
1071 | 56f066bb | Nathan Froyd | case 2: segv = put_user_u16(val, addr); break; |
1072 | 56f066bb | Nathan Froyd | case 4: segv = put_user_u32(val, addr); break; |
1073 | 56f066bb | Nathan Froyd | #if defined(TARGET_PPC64)
|
1074 | 56f066bb | Nathan Froyd | case 8: segv = put_user_u64(val, addr); break; |
1075 | 56f066bb | Nathan Froyd | #endif
|
1076 | 56f066bb | Nathan Froyd | default: abort();
|
1077 | 56f066bb | Nathan Froyd | } |
1078 | 56f066bb | Nathan Froyd | if (!segv) {
|
1079 | 56f066bb | Nathan Froyd | stored = 1;
|
1080 | 56f066bb | Nathan Froyd | } |
1081 | 56f066bb | Nathan Froyd | } |
1082 | 56f066bb | Nathan Froyd | } |
1083 | 56f066bb | Nathan Froyd | env->crf[0] = (stored << 1) | xer_so; |
1084 | 56f066bb | Nathan Froyd | env->reserve_addr = (target_ulong)-1;
|
1085 | 56f066bb | Nathan Froyd | } |
1086 | 56f066bb | Nathan Froyd | if (!segv) {
|
1087 | 56f066bb | Nathan Froyd | env->nip += 4;
|
1088 | 56f066bb | Nathan Froyd | } |
1089 | 56f066bb | Nathan Froyd | mmap_unlock(); |
1090 | 56f066bb | Nathan Froyd | end_exclusive(); |
1091 | 56f066bb | Nathan Froyd | return segv;
|
1092 | 56f066bb | Nathan Froyd | } |
1093 | 56f066bb | Nathan Froyd | |
1094 | 67867308 | bellard | void cpu_loop(CPUPPCState *env)
|
1095 | 67867308 | bellard | { |
1096 | c227f099 | Anthony Liguori | target_siginfo_t info; |
1097 | 61190b14 | bellard | int trapnr;
|
1098 | 61190b14 | bellard | uint32_t ret; |
1099 | 3b46e624 | ths | |
1100 | 67867308 | bellard | for(;;) {
|
1101 | 56f066bb | Nathan Froyd | cpu_exec_start(env); |
1102 | 67867308 | bellard | trapnr = cpu_ppc_exec(env); |
1103 | 56f066bb | Nathan Froyd | cpu_exec_end(env); |
1104 | 67867308 | bellard | switch(trapnr) {
|
1105 | e1833e1f | j_mayer | case POWERPC_EXCP_NONE:
|
1106 | e1833e1f | j_mayer | /* Just go on */
|
1107 | 67867308 | bellard | break;
|
1108 | e1833e1f | j_mayer | case POWERPC_EXCP_CRITICAL: /* Critical input */ |
1109 | e1833e1f | j_mayer | cpu_abort(env, "Critical interrupt while in user mode. "
|
1110 | e1833e1f | j_mayer | "Aborting\n");
|
1111 | 61190b14 | bellard | break;
|
1112 | e1833e1f | j_mayer | case POWERPC_EXCP_MCHECK: /* Machine check exception */ |
1113 | e1833e1f | j_mayer | cpu_abort(env, "Machine check exception while in user mode. "
|
1114 | e1833e1f | j_mayer | "Aborting\n");
|
1115 | e1833e1f | j_mayer | break;
|
1116 | e1833e1f | j_mayer | case POWERPC_EXCP_DSI: /* Data storage exception */ |
1117 | 90e189ec | Blue Swirl | EXCP_DUMP(env, "Invalid data memory access: 0x" TARGET_FMT_lx "\n", |
1118 | e1833e1f | j_mayer | env->spr[SPR_DAR]); |
1119 | e1833e1f | j_mayer | /* XXX: check this. Seems bugged */
|
1120 | 2be0071f | bellard | switch (env->error_code & 0xFF000000) { |
1121 | 2be0071f | bellard | case 0x40000000: |
1122 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1123 | 61190b14 | bellard | info.si_errno = 0;
|
1124 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
1125 | 61190b14 | bellard | break;
|
1126 | 2be0071f | bellard | case 0x04000000: |
1127 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
1128 | 61190b14 | bellard | info.si_errno = 0;
|
1129 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLADR; |
1130 | 61190b14 | bellard | break;
|
1131 | 2be0071f | bellard | case 0x08000000: |
1132 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1133 | 61190b14 | bellard | info.si_errno = 0;
|
1134 | 61190b14 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
1135 | 61190b14 | bellard | break;
|
1136 | 61190b14 | bellard | default:
|
1137 | 61190b14 | bellard | /* Let's send a regular segfault... */
|
1138 | e1833e1f | j_mayer | EXCP_DUMP(env, "Invalid segfault errno (%02x)\n",
|
1139 | e1833e1f | j_mayer | env->error_code); |
1140 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1141 | 61190b14 | bellard | info.si_errno = 0;
|
1142 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
1143 | 61190b14 | bellard | break;
|
1144 | 61190b14 | bellard | } |
1145 | 67867308 | bellard | info._sifields._sigfault._addr = env->nip; |
1146 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1147 | 67867308 | bellard | break;
|
1148 | e1833e1f | j_mayer | case POWERPC_EXCP_ISI: /* Instruction storage exception */ |
1149 | 90e189ec | Blue Swirl | EXCP_DUMP(env, "Invalid instruction fetch: 0x\n" TARGET_FMT_lx
|
1150 | 90e189ec | Blue Swirl | "\n", env->spr[SPR_SRR0]);
|
1151 | e1833e1f | j_mayer | /* XXX: check this */
|
1152 | 2be0071f | bellard | switch (env->error_code & 0xFF000000) { |
1153 | 2be0071f | bellard | case 0x40000000: |
1154 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1155 | 67867308 | bellard | info.si_errno = 0;
|
1156 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
1157 | 61190b14 | bellard | break;
|
1158 | 2be0071f | bellard | case 0x10000000: |
1159 | 2be0071f | bellard | case 0x08000000: |
1160 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1161 | 61190b14 | bellard | info.si_errno = 0;
|
1162 | 61190b14 | bellard | info.si_code = TARGET_SEGV_ACCERR; |
1163 | 61190b14 | bellard | break;
|
1164 | 61190b14 | bellard | default:
|
1165 | 61190b14 | bellard | /* Let's send a regular segfault... */
|
1166 | e1833e1f | j_mayer | EXCP_DUMP(env, "Invalid segfault errno (%02x)\n",
|
1167 | e1833e1f | j_mayer | env->error_code); |
1168 | 61190b14 | bellard | info.si_signo = TARGET_SIGSEGV; |
1169 | 61190b14 | bellard | info.si_errno = 0;
|
1170 | 61190b14 | bellard | info.si_code = TARGET_SEGV_MAPERR; |
1171 | 61190b14 | bellard | break;
|
1172 | 61190b14 | bellard | } |
1173 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
1174 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1175 | 67867308 | bellard | break;
|
1176 | e1833e1f | j_mayer | case POWERPC_EXCP_EXTERNAL: /* External input */ |
1177 | e1833e1f | j_mayer | cpu_abort(env, "External interrupt while in user mode. "
|
1178 | e1833e1f | j_mayer | "Aborting\n");
|
1179 | e1833e1f | j_mayer | break;
|
1180 | e1833e1f | j_mayer | case POWERPC_EXCP_ALIGN: /* Alignment exception */ |
1181 | e1833e1f | j_mayer | EXCP_DUMP(env, "Unaligned memory access\n");
|
1182 | e1833e1f | j_mayer | /* XXX: check this */
|
1183 | 61190b14 | bellard | info.si_signo = TARGET_SIGBUS; |
1184 | 67867308 | bellard | info.si_errno = 0;
|
1185 | 61190b14 | bellard | info.si_code = TARGET_BUS_ADRALN; |
1186 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
1187 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1188 | 67867308 | bellard | break;
|
1189 | e1833e1f | j_mayer | case POWERPC_EXCP_PROGRAM: /* Program exception */ |
1190 | e1833e1f | j_mayer | /* XXX: check this */
|
1191 | 61190b14 | bellard | switch (env->error_code & ~0xF) { |
1192 | e1833e1f | j_mayer | case POWERPC_EXCP_FP:
|
1193 | e1833e1f | j_mayer | EXCP_DUMP(env, "Floating point program exception\n");
|
1194 | 61190b14 | bellard | info.si_signo = TARGET_SIGFPE; |
1195 | 61190b14 | bellard | info.si_errno = 0;
|
1196 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
1197 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_OX:
|
1198 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTOVF; |
1199 | 61190b14 | bellard | break;
|
1200 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_UX:
|
1201 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTUND; |
1202 | 61190b14 | bellard | break;
|
1203 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_ZX:
|
1204 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXZDZ:
|
1205 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTDIV; |
1206 | 61190b14 | bellard | break;
|
1207 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_XX:
|
1208 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTRES; |
1209 | 61190b14 | bellard | break;
|
1210 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXSOFT:
|
1211 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTINV; |
1212 | 61190b14 | bellard | break;
|
1213 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXSNAN:
|
1214 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXISI:
|
1215 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXIDI:
|
1216 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXIMZ:
|
1217 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXVC:
|
1218 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXSQRT:
|
1219 | e1833e1f | j_mayer | case POWERPC_EXCP_FP_VXCVI:
|
1220 | 61190b14 | bellard | info.si_code = TARGET_FPE_FLTSUB; |
1221 | 61190b14 | bellard | break;
|
1222 | 61190b14 | bellard | default:
|
1223 | e1833e1f | j_mayer | EXCP_DUMP(env, "Unknown floating point exception (%02x)\n",
|
1224 | e1833e1f | j_mayer | env->error_code); |
1225 | e1833e1f | j_mayer | break;
|
1226 | 61190b14 | bellard | } |
1227 | e1833e1f | j_mayer | break;
|
1228 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL:
|
1229 | e1833e1f | j_mayer | EXCP_DUMP(env, "Invalid instruction\n");
|
1230 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
1231 | 61190b14 | bellard | info.si_errno = 0;
|
1232 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
1233 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL_INVAL:
|
1234 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLOPC; |
1235 | 61190b14 | bellard | break;
|
1236 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL_LSWX:
|
1237 | a750fc0b | j_mayer | info.si_code = TARGET_ILL_ILLOPN; |
1238 | 61190b14 | bellard | break;
|
1239 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL_SPR:
|
1240 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVREG; |
1241 | 61190b14 | bellard | break;
|
1242 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL_FP:
|
1243 | 61190b14 | bellard | info.si_code = TARGET_ILL_COPROC; |
1244 | 61190b14 | bellard | break;
|
1245 | 61190b14 | bellard | default:
|
1246 | e1833e1f | j_mayer | EXCP_DUMP(env, "Unknown invalid operation (%02x)\n",
|
1247 | e1833e1f | j_mayer | env->error_code & 0xF);
|
1248 | 61190b14 | bellard | info.si_code = TARGET_ILL_ILLADR; |
1249 | 61190b14 | bellard | break;
|
1250 | 61190b14 | bellard | } |
1251 | 61190b14 | bellard | break;
|
1252 | e1833e1f | j_mayer | case POWERPC_EXCP_PRIV:
|
1253 | e1833e1f | j_mayer | EXCP_DUMP(env, "Privilege violation\n");
|
1254 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
1255 | 61190b14 | bellard | info.si_errno = 0;
|
1256 | 61190b14 | bellard | switch (env->error_code & 0xF) { |
1257 | e1833e1f | j_mayer | case POWERPC_EXCP_PRIV_OPC:
|
1258 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVOPC; |
1259 | 61190b14 | bellard | break;
|
1260 | e1833e1f | j_mayer | case POWERPC_EXCP_PRIV_REG:
|
1261 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVREG; |
1262 | e1833e1f | j_mayer | break;
|
1263 | 61190b14 | bellard | default:
|
1264 | e1833e1f | j_mayer | EXCP_DUMP(env, "Unknown privilege violation (%02x)\n",
|
1265 | e1833e1f | j_mayer | env->error_code & 0xF);
|
1266 | 61190b14 | bellard | info.si_code = TARGET_ILL_PRVOPC; |
1267 | 61190b14 | bellard | break;
|
1268 | 61190b14 | bellard | } |
1269 | 61190b14 | bellard | break;
|
1270 | e1833e1f | j_mayer | case POWERPC_EXCP_TRAP:
|
1271 | e1833e1f | j_mayer | cpu_abort(env, "Tried to call a TRAP\n");
|
1272 | e1833e1f | j_mayer | break;
|
1273 | 61190b14 | bellard | default:
|
1274 | 61190b14 | bellard | /* Should not happen ! */
|
1275 | e1833e1f | j_mayer | cpu_abort(env, "Unknown program exception (%02x)\n",
|
1276 | e1833e1f | j_mayer | env->error_code); |
1277 | e1833e1f | j_mayer | break;
|
1278 | 61190b14 | bellard | } |
1279 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
1280 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1281 | 67867308 | bellard | break;
|
1282 | e1833e1f | j_mayer | case POWERPC_EXCP_FPU: /* Floating-point unavailable exception */ |
1283 | e1833e1f | j_mayer | EXCP_DUMP(env, "No floating point allowed\n");
|
1284 | 61190b14 | bellard | info.si_signo = TARGET_SIGILL; |
1285 | 67867308 | bellard | info.si_errno = 0;
|
1286 | 61190b14 | bellard | info.si_code = TARGET_ILL_COPROC; |
1287 | 61190b14 | bellard | info._sifields._sigfault._addr = env->nip - 4;
|
1288 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1289 | 67867308 | bellard | break;
|
1290 | e1833e1f | j_mayer | case POWERPC_EXCP_SYSCALL: /* System call exception */ |
1291 | e1833e1f | j_mayer | cpu_abort(env, "Syscall exception while in user mode. "
|
1292 | e1833e1f | j_mayer | "Aborting\n");
|
1293 | 61190b14 | bellard | break;
|
1294 | e1833e1f | j_mayer | case POWERPC_EXCP_APU: /* Auxiliary processor unavailable */ |
1295 | e1833e1f | j_mayer | EXCP_DUMP(env, "No APU instruction allowed\n");
|
1296 | e1833e1f | j_mayer | info.si_signo = TARGET_SIGILL; |
1297 | e1833e1f | j_mayer | info.si_errno = 0;
|
1298 | e1833e1f | j_mayer | info.si_code = TARGET_ILL_COPROC; |
1299 | e1833e1f | j_mayer | info._sifields._sigfault._addr = env->nip - 4;
|
1300 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1301 | 61190b14 | bellard | break;
|
1302 | e1833e1f | j_mayer | case POWERPC_EXCP_DECR: /* Decrementer exception */ |
1303 | e1833e1f | j_mayer | cpu_abort(env, "Decrementer interrupt while in user mode. "
|
1304 | e1833e1f | j_mayer | "Aborting\n");
|
1305 | 61190b14 | bellard | break;
|
1306 | e1833e1f | j_mayer | case POWERPC_EXCP_FIT: /* Fixed-interval timer interrupt */ |
1307 | e1833e1f | j_mayer | cpu_abort(env, "Fix interval timer interrupt while in user mode. "
|
1308 | e1833e1f | j_mayer | "Aborting\n");
|
1309 | e1833e1f | j_mayer | break;
|
1310 | e1833e1f | j_mayer | case POWERPC_EXCP_WDT: /* Watchdog timer interrupt */ |
1311 | e1833e1f | j_mayer | cpu_abort(env, "Watchdog timer interrupt while in user mode. "
|
1312 | e1833e1f | j_mayer | "Aborting\n");
|
1313 | e1833e1f | j_mayer | break;
|
1314 | e1833e1f | j_mayer | case POWERPC_EXCP_DTLB: /* Data TLB error */ |
1315 | e1833e1f | j_mayer | cpu_abort(env, "Data TLB exception while in user mode. "
|
1316 | e1833e1f | j_mayer | "Aborting\n");
|
1317 | e1833e1f | j_mayer | break;
|
1318 | e1833e1f | j_mayer | case POWERPC_EXCP_ITLB: /* Instruction TLB error */ |
1319 | e1833e1f | j_mayer | cpu_abort(env, "Instruction TLB exception while in user mode. "
|
1320 | e1833e1f | j_mayer | "Aborting\n");
|
1321 | e1833e1f | j_mayer | break;
|
1322 | e1833e1f | j_mayer | case POWERPC_EXCP_SPEU: /* SPE/embedded floating-point unavail. */ |
1323 | e1833e1f | j_mayer | EXCP_DUMP(env, "No SPE/floating-point instruction allowed\n");
|
1324 | e1833e1f | j_mayer | info.si_signo = TARGET_SIGILL; |
1325 | e1833e1f | j_mayer | info.si_errno = 0;
|
1326 | e1833e1f | j_mayer | info.si_code = TARGET_ILL_COPROC; |
1327 | e1833e1f | j_mayer | info._sifields._sigfault._addr = env->nip - 4;
|
1328 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1329 | e1833e1f | j_mayer | break;
|
1330 | e1833e1f | j_mayer | case POWERPC_EXCP_EFPDI: /* Embedded floating-point data IRQ */ |
1331 | e1833e1f | j_mayer | cpu_abort(env, "Embedded floating-point data IRQ not handled\n");
|
1332 | e1833e1f | j_mayer | break;
|
1333 | e1833e1f | j_mayer | case POWERPC_EXCP_EFPRI: /* Embedded floating-point round IRQ */ |
1334 | e1833e1f | j_mayer | cpu_abort(env, "Embedded floating-point round IRQ not handled\n");
|
1335 | e1833e1f | j_mayer | break;
|
1336 | e1833e1f | j_mayer | case POWERPC_EXCP_EPERFM: /* Embedded performance monitor IRQ */ |
1337 | e1833e1f | j_mayer | cpu_abort(env, "Performance monitor exception not handled\n");
|
1338 | e1833e1f | j_mayer | break;
|
1339 | e1833e1f | j_mayer | case POWERPC_EXCP_DOORI: /* Embedded doorbell interrupt */ |
1340 | e1833e1f | j_mayer | cpu_abort(env, "Doorbell interrupt while in user mode. "
|
1341 | e1833e1f | j_mayer | "Aborting\n");
|
1342 | e1833e1f | j_mayer | break;
|
1343 | e1833e1f | j_mayer | case POWERPC_EXCP_DOORCI: /* Embedded doorbell critical interrupt */ |
1344 | e1833e1f | j_mayer | cpu_abort(env, "Doorbell critical interrupt while in user mode. "
|
1345 | e1833e1f | j_mayer | "Aborting\n");
|
1346 | e1833e1f | j_mayer | break;
|
1347 | e1833e1f | j_mayer | case POWERPC_EXCP_RESET: /* System reset exception */ |
1348 | e1833e1f | j_mayer | cpu_abort(env, "Reset interrupt while in user mode. "
|
1349 | e1833e1f | j_mayer | "Aborting\n");
|
1350 | e1833e1f | j_mayer | break;
|
1351 | e1833e1f | j_mayer | case POWERPC_EXCP_DSEG: /* Data segment exception */ |
1352 | e1833e1f | j_mayer | cpu_abort(env, "Data segment exception while in user mode. "
|
1353 | e1833e1f | j_mayer | "Aborting\n");
|
1354 | e1833e1f | j_mayer | break;
|
1355 | e1833e1f | j_mayer | case POWERPC_EXCP_ISEG: /* Instruction segment exception */ |
1356 | e1833e1f | j_mayer | cpu_abort(env, "Instruction segment exception "
|
1357 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1358 | e1833e1f | j_mayer | break;
|
1359 | e85e7c6e | j_mayer | /* PowerPC 64 with hypervisor mode support */
|
1360 | e1833e1f | j_mayer | case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception */ |
1361 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor decrementer interrupt "
|
1362 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1363 | e1833e1f | j_mayer | break;
|
1364 | e1833e1f | j_mayer | case POWERPC_EXCP_TRACE: /* Trace exception */ |
1365 | e1833e1f | j_mayer | /* Nothing to do:
|
1366 | e1833e1f | j_mayer | * we use this exception to emulate step-by-step execution mode.
|
1367 | e1833e1f | j_mayer | */
|
1368 | e1833e1f | j_mayer | break;
|
1369 | e85e7c6e | j_mayer | /* PowerPC 64 with hypervisor mode support */
|
1370 | e1833e1f | j_mayer | case POWERPC_EXCP_HDSI: /* Hypervisor data storage exception */ |
1371 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor data storage exception "
|
1372 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1373 | e1833e1f | j_mayer | break;
|
1374 | e1833e1f | j_mayer | case POWERPC_EXCP_HISI: /* Hypervisor instruction storage excp */ |
1375 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor instruction storage exception "
|
1376 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1377 | e1833e1f | j_mayer | break;
|
1378 | e1833e1f | j_mayer | case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception */ |
1379 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor data segment exception "
|
1380 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1381 | e1833e1f | j_mayer | break;
|
1382 | e1833e1f | j_mayer | case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment excp */ |
1383 | e1833e1f | j_mayer | cpu_abort(env, "Hypervisor instruction segment exception "
|
1384 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1385 | e1833e1f | j_mayer | break;
|
1386 | e1833e1f | j_mayer | case POWERPC_EXCP_VPU: /* Vector unavailable exception */ |
1387 | e1833e1f | j_mayer | EXCP_DUMP(env, "No Altivec instructions allowed\n");
|
1388 | e1833e1f | j_mayer | info.si_signo = TARGET_SIGILL; |
1389 | e1833e1f | j_mayer | info.si_errno = 0;
|
1390 | e1833e1f | j_mayer | info.si_code = TARGET_ILL_COPROC; |
1391 | e1833e1f | j_mayer | info._sifields._sigfault._addr = env->nip - 4;
|
1392 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1393 | e1833e1f | j_mayer | break;
|
1394 | e1833e1f | j_mayer | case POWERPC_EXCP_PIT: /* Programmable interval timer IRQ */ |
1395 | e1833e1f | j_mayer | cpu_abort(env, "Programable interval timer interrupt "
|
1396 | e1833e1f | j_mayer | "while in user mode. Aborting\n");
|
1397 | e1833e1f | j_mayer | break;
|
1398 | e1833e1f | j_mayer | case POWERPC_EXCP_IO: /* IO error exception */ |
1399 | e1833e1f | j_mayer | cpu_abort(env, "IO error exception while in user mode. "
|
1400 | e1833e1f | j_mayer | "Aborting\n");
|
1401 | e1833e1f | j_mayer | break;
|
1402 | e1833e1f | j_mayer | case POWERPC_EXCP_RUNM: /* Run mode exception */ |
1403 | e1833e1f | j_mayer | cpu_abort(env, "Run mode exception while in user mode. "
|
1404 | e1833e1f | j_mayer | "Aborting\n");
|
1405 | e1833e1f | j_mayer | break;
|
1406 | e1833e1f | j_mayer | case POWERPC_EXCP_EMUL: /* Emulation trap exception */ |
1407 | e1833e1f | j_mayer | cpu_abort(env, "Emulation trap exception not handled\n");
|
1408 | e1833e1f | j_mayer | break;
|
1409 | e1833e1f | j_mayer | case POWERPC_EXCP_IFTLB: /* Instruction fetch TLB error */ |
1410 | e1833e1f | j_mayer | cpu_abort(env, "Instruction fetch TLB exception "
|
1411 | e1833e1f | j_mayer | "while in user-mode. Aborting");
|
1412 | e1833e1f | j_mayer | break;
|
1413 | e1833e1f | j_mayer | case POWERPC_EXCP_DLTLB: /* Data load TLB miss */ |
1414 | e1833e1f | j_mayer | cpu_abort(env, "Data load TLB exception while in user-mode. "
|
1415 | e1833e1f | j_mayer | "Aborting");
|
1416 | e1833e1f | j_mayer | break;
|
1417 | e1833e1f | j_mayer | case POWERPC_EXCP_DSTLB: /* Data store TLB miss */ |
1418 | e1833e1f | j_mayer | cpu_abort(env, "Data store TLB exception while in user-mode. "
|
1419 | e1833e1f | j_mayer | "Aborting");
|
1420 | e1833e1f | j_mayer | break;
|
1421 | e1833e1f | j_mayer | case POWERPC_EXCP_FPA: /* Floating-point assist exception */ |
1422 | e1833e1f | j_mayer | cpu_abort(env, "Floating-point assist exception not handled\n");
|
1423 | e1833e1f | j_mayer | break;
|
1424 | e1833e1f | j_mayer | case POWERPC_EXCP_IABR: /* Instruction address breakpoint */ |
1425 | e1833e1f | j_mayer | cpu_abort(env, "Instruction address breakpoint exception "
|
1426 | e1833e1f | j_mayer | "not handled\n");
|
1427 | e1833e1f | j_mayer | break;
|
1428 | e1833e1f | j_mayer | case POWERPC_EXCP_SMI: /* System management interrupt */ |
1429 | e1833e1f | j_mayer | cpu_abort(env, "System management interrupt while in user mode. "
|
1430 | e1833e1f | j_mayer | "Aborting\n");
|
1431 | e1833e1f | j_mayer | break;
|
1432 | e1833e1f | j_mayer | case POWERPC_EXCP_THERM: /* Thermal interrupt */ |
1433 | e1833e1f | j_mayer | cpu_abort(env, "Thermal interrupt interrupt while in user mode. "
|
1434 | e1833e1f | j_mayer | "Aborting\n");
|
1435 | e1833e1f | j_mayer | break;
|
1436 | e1833e1f | j_mayer | case POWERPC_EXCP_PERFM: /* Embedded performance monitor IRQ */ |
1437 | e1833e1f | j_mayer | cpu_abort(env, "Performance monitor exception not handled\n");
|
1438 | e1833e1f | j_mayer | break;
|
1439 | e1833e1f | j_mayer | case POWERPC_EXCP_VPUA: /* Vector assist exception */ |
1440 | e1833e1f | j_mayer | cpu_abort(env, "Vector assist exception not handled\n");
|
1441 | e1833e1f | j_mayer | break;
|
1442 | e1833e1f | j_mayer | case POWERPC_EXCP_SOFTP: /* Soft patch exception */ |
1443 | e1833e1f | j_mayer | cpu_abort(env, "Soft patch exception not handled\n");
|
1444 | e1833e1f | j_mayer | break;
|
1445 | e1833e1f | j_mayer | case POWERPC_EXCP_MAINT: /* Maintenance exception */ |
1446 | e1833e1f | j_mayer | cpu_abort(env, "Maintenance exception while in user mode. "
|
1447 | e1833e1f | j_mayer | "Aborting\n");
|
1448 | e1833e1f | j_mayer | break;
|
1449 | e1833e1f | j_mayer | case POWERPC_EXCP_STOP: /* stop translation */ |
1450 | e1833e1f | j_mayer | /* We did invalidate the instruction cache. Go on */
|
1451 | e1833e1f | j_mayer | break;
|
1452 | e1833e1f | j_mayer | case POWERPC_EXCP_BRANCH: /* branch instruction: */ |
1453 | e1833e1f | j_mayer | /* We just stopped because of a branch. Go on */
|
1454 | e1833e1f | j_mayer | break;
|
1455 | e1833e1f | j_mayer | case POWERPC_EXCP_SYSCALL_USER:
|
1456 | e1833e1f | j_mayer | /* system call in user-mode emulation */
|
1457 | e1833e1f | j_mayer | /* WARNING:
|
1458 | e1833e1f | j_mayer | * PPC ABI uses overflow flag in cr0 to signal an error
|
1459 | e1833e1f | j_mayer | * in syscalls.
|
1460 | e1833e1f | j_mayer | */
|
1461 | e1833e1f | j_mayer | #if 0
|
1462 | e1833e1f | j_mayer | printf("syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n", env->gpr[0],
|
1463 | e1833e1f | j_mayer | env->gpr[3], env->gpr[4], env->gpr[5], env->gpr[6]);
|
1464 | e1833e1f | j_mayer | #endif
|
1465 | e1833e1f | j_mayer | env->crf[0] &= ~0x1; |
1466 | e1833e1f | j_mayer | ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4], |
1467 | e1833e1f | j_mayer | env->gpr[5], env->gpr[6], env->gpr[7], |
1468 | e1833e1f | j_mayer | env->gpr[8]);
|
1469 | bcd4933a | Nathan Froyd | if (ret == (uint32_t)(-TARGET_QEMU_ESIGRETURN)) {
|
1470 | bcd4933a | Nathan Froyd | /* Returning from a successful sigreturn syscall.
|
1471 | bcd4933a | Nathan Froyd | Avoid corrupting register state. */
|
1472 | bcd4933a | Nathan Froyd | break;
|
1473 | bcd4933a | Nathan Froyd | } |
1474 | e1833e1f | j_mayer | if (ret > (uint32_t)(-515)) { |
1475 | e1833e1f | j_mayer | env->crf[0] |= 0x1; |
1476 | e1833e1f | j_mayer | ret = -ret; |
1477 | 61190b14 | bellard | } |
1478 | e1833e1f | j_mayer | env->gpr[3] = ret;
|
1479 | e1833e1f | j_mayer | #if 0
|
1480 | e1833e1f | j_mayer | printf("syscall returned 0x%08x (%d)\n", ret, ret);
|
1481 | e1833e1f | j_mayer | #endif
|
1482 | e1833e1f | j_mayer | break;
|
1483 | 56f066bb | Nathan Froyd | case POWERPC_EXCP_STCX:
|
1484 | 56f066bb | Nathan Froyd | if (do_store_exclusive(env)) {
|
1485 | 56f066bb | Nathan Froyd | info.si_signo = TARGET_SIGSEGV; |
1486 | 56f066bb | Nathan Froyd | info.si_errno = 0;
|
1487 | 56f066bb | Nathan Froyd | info.si_code = TARGET_SEGV_MAPERR; |
1488 | 56f066bb | Nathan Froyd | info._sifields._sigfault._addr = env->nip; |
1489 | 56f066bb | Nathan Froyd | queue_signal(env, info.si_signo, &info); |
1490 | 56f066bb | Nathan Froyd | } |
1491 | 56f066bb | Nathan Froyd | break;
|
1492 | 71f75756 | aurel32 | case EXCP_DEBUG:
|
1493 | 71f75756 | aurel32 | { |
1494 | 71f75756 | aurel32 | int sig;
|
1495 | 71f75756 | aurel32 | |
1496 | 71f75756 | aurel32 | sig = gdb_handlesig(env, TARGET_SIGTRAP); |
1497 | 71f75756 | aurel32 | if (sig) {
|
1498 | 71f75756 | aurel32 | info.si_signo = sig; |
1499 | 71f75756 | aurel32 | info.si_errno = 0;
|
1500 | 71f75756 | aurel32 | info.si_code = TARGET_TRAP_BRKPT; |
1501 | 71f75756 | aurel32 | queue_signal(env, info.si_signo, &info); |
1502 | 71f75756 | aurel32 | } |
1503 | 71f75756 | aurel32 | } |
1504 | 71f75756 | aurel32 | break;
|
1505 | 56ba31ff | j_mayer | case EXCP_INTERRUPT:
|
1506 | 56ba31ff | j_mayer | /* just indicate that signals should be handled asap */
|
1507 | 56ba31ff | j_mayer | break;
|
1508 | e1833e1f | j_mayer | default:
|
1509 | e1833e1f | j_mayer | cpu_abort(env, "Unknown exception 0x%d. Aborting\n", trapnr);
|
1510 | e1833e1f | j_mayer | break;
|
1511 | 67867308 | bellard | } |
1512 | 67867308 | bellard | process_pending_signals(env); |
1513 | 67867308 | bellard | } |
1514 | 67867308 | bellard | } |
1515 | 67867308 | bellard | #endif
|
1516 | 67867308 | bellard | |
1517 | 048f6b4d | bellard | #ifdef TARGET_MIPS
|
1518 | 048f6b4d | bellard | |
1519 | 048f6b4d | bellard | #define MIPS_SYS(name, args) args,
|
1520 | 048f6b4d | bellard | |
1521 | 048f6b4d | bellard | static const uint8_t mips_syscall_args[] = { |
1522 | 048f6b4d | bellard | MIPS_SYS(sys_syscall , 0) /* 4000 */ |
1523 | 048f6b4d | bellard | MIPS_SYS(sys_exit , 1)
|
1524 | 048f6b4d | bellard | MIPS_SYS(sys_fork , 0)
|
1525 | 048f6b4d | bellard | MIPS_SYS(sys_read , 3)
|
1526 | 048f6b4d | bellard | MIPS_SYS(sys_write , 3)
|
1527 | 048f6b4d | bellard | MIPS_SYS(sys_open , 3) /* 4005 */ |
1528 | 048f6b4d | bellard | MIPS_SYS(sys_close , 1)
|
1529 | 048f6b4d | bellard | MIPS_SYS(sys_waitpid , 3)
|
1530 | 048f6b4d | bellard | MIPS_SYS(sys_creat , 2)
|
1531 | 048f6b4d | bellard | MIPS_SYS(sys_link , 2)
|
1532 | 048f6b4d | bellard | MIPS_SYS(sys_unlink , 1) /* 4010 */ |
1533 | 048f6b4d | bellard | MIPS_SYS(sys_execve , 0)
|
1534 | 048f6b4d | bellard | MIPS_SYS(sys_chdir , 1)
|
1535 | 048f6b4d | bellard | MIPS_SYS(sys_time , 1)
|
1536 | 048f6b4d | bellard | MIPS_SYS(sys_mknod , 3)
|
1537 | 048f6b4d | bellard | MIPS_SYS(sys_chmod , 2) /* 4015 */ |
1538 | 048f6b4d | bellard | MIPS_SYS(sys_lchown , 3)
|
1539 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1540 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_stat */ |
1541 | 048f6b4d | bellard | MIPS_SYS(sys_lseek , 3)
|
1542 | 048f6b4d | bellard | MIPS_SYS(sys_getpid , 0) /* 4020 */ |
1543 | 048f6b4d | bellard | MIPS_SYS(sys_mount , 5)
|
1544 | 048f6b4d | bellard | MIPS_SYS(sys_oldumount , 1)
|
1545 | 048f6b4d | bellard | MIPS_SYS(sys_setuid , 1)
|
1546 | 048f6b4d | bellard | MIPS_SYS(sys_getuid , 0)
|
1547 | 048f6b4d | bellard | MIPS_SYS(sys_stime , 1) /* 4025 */ |
1548 | 048f6b4d | bellard | MIPS_SYS(sys_ptrace , 4)
|
1549 | 048f6b4d | bellard | MIPS_SYS(sys_alarm , 1)
|
1550 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_fstat */ |
1551 | 048f6b4d | bellard | MIPS_SYS(sys_pause , 0)
|
1552 | 048f6b4d | bellard | MIPS_SYS(sys_utime , 2) /* 4030 */ |
1553 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1554 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1555 | 048f6b4d | bellard | MIPS_SYS(sys_access , 2)
|
1556 | 048f6b4d | bellard | MIPS_SYS(sys_nice , 1)
|
1557 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4035 */ |
1558 | 048f6b4d | bellard | MIPS_SYS(sys_sync , 0)
|
1559 | 048f6b4d | bellard | MIPS_SYS(sys_kill , 2)
|
1560 | 048f6b4d | bellard | MIPS_SYS(sys_rename , 2)
|
1561 | 048f6b4d | bellard | MIPS_SYS(sys_mkdir , 2)
|
1562 | 048f6b4d | bellard | MIPS_SYS(sys_rmdir , 1) /* 4040 */ |
1563 | 048f6b4d | bellard | MIPS_SYS(sys_dup , 1)
|
1564 | 048f6b4d | bellard | MIPS_SYS(sys_pipe , 0)
|
1565 | 048f6b4d | bellard | MIPS_SYS(sys_times , 1)
|
1566 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1567 | 048f6b4d | bellard | MIPS_SYS(sys_brk , 1) /* 4045 */ |
1568 | 048f6b4d | bellard | MIPS_SYS(sys_setgid , 1)
|
1569 | 048f6b4d | bellard | MIPS_SYS(sys_getgid , 0)
|
1570 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was signal(2) */ |
1571 | 048f6b4d | bellard | MIPS_SYS(sys_geteuid , 0)
|
1572 | 048f6b4d | bellard | MIPS_SYS(sys_getegid , 0) /* 4050 */ |
1573 | 048f6b4d | bellard | MIPS_SYS(sys_acct , 0)
|
1574 | 048f6b4d | bellard | MIPS_SYS(sys_umount , 2)
|
1575 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1576 | 048f6b4d | bellard | MIPS_SYS(sys_ioctl , 3)
|
1577 | 048f6b4d | bellard | MIPS_SYS(sys_fcntl , 3) /* 4055 */ |
1578 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 2)
|
1579 | 048f6b4d | bellard | MIPS_SYS(sys_setpgid , 2)
|
1580 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1581 | 048f6b4d | bellard | MIPS_SYS(sys_olduname , 1)
|
1582 | 048f6b4d | bellard | MIPS_SYS(sys_umask , 1) /* 4060 */ |
1583 | 048f6b4d | bellard | MIPS_SYS(sys_chroot , 1)
|
1584 | 048f6b4d | bellard | MIPS_SYS(sys_ustat , 2)
|
1585 | 048f6b4d | bellard | MIPS_SYS(sys_dup2 , 2)
|
1586 | 048f6b4d | bellard | MIPS_SYS(sys_getppid , 0)
|
1587 | 048f6b4d | bellard | MIPS_SYS(sys_getpgrp , 0) /* 4065 */ |
1588 | 048f6b4d | bellard | MIPS_SYS(sys_setsid , 0)
|
1589 | 048f6b4d | bellard | MIPS_SYS(sys_sigaction , 3)
|
1590 | 048f6b4d | bellard | MIPS_SYS(sys_sgetmask , 0)
|
1591 | 048f6b4d | bellard | MIPS_SYS(sys_ssetmask , 1)
|
1592 | 048f6b4d | bellard | MIPS_SYS(sys_setreuid , 2) /* 4070 */ |
1593 | 048f6b4d | bellard | MIPS_SYS(sys_setregid , 2)
|
1594 | 048f6b4d | bellard | MIPS_SYS(sys_sigsuspend , 0)
|
1595 | 048f6b4d | bellard | MIPS_SYS(sys_sigpending , 1)
|
1596 | 048f6b4d | bellard | MIPS_SYS(sys_sethostname , 2)
|
1597 | 048f6b4d | bellard | MIPS_SYS(sys_setrlimit , 2) /* 4075 */ |
1598 | 048f6b4d | bellard | MIPS_SYS(sys_getrlimit , 2)
|
1599 | 048f6b4d | bellard | MIPS_SYS(sys_getrusage , 2)
|
1600 | 048f6b4d | bellard | MIPS_SYS(sys_gettimeofday, 2)
|
1601 | 048f6b4d | bellard | MIPS_SYS(sys_settimeofday, 2)
|
1602 | 048f6b4d | bellard | MIPS_SYS(sys_getgroups , 2) /* 4080 */ |
1603 | 048f6b4d | bellard | MIPS_SYS(sys_setgroups , 2)
|
1604 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* old_select */ |
1605 | 048f6b4d | bellard | MIPS_SYS(sys_symlink , 2)
|
1606 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_lstat */ |
1607 | 048f6b4d | bellard | MIPS_SYS(sys_readlink , 3) /* 4085 */ |
1608 | 048f6b4d | bellard | MIPS_SYS(sys_uselib , 1)
|
1609 | 048f6b4d | bellard | MIPS_SYS(sys_swapon , 2)
|
1610 | 048f6b4d | bellard | MIPS_SYS(sys_reboot , 3)
|
1611 | 048f6b4d | bellard | MIPS_SYS(old_readdir , 3)
|
1612 | 048f6b4d | bellard | MIPS_SYS(old_mmap , 6) /* 4090 */ |
1613 | 048f6b4d | bellard | MIPS_SYS(sys_munmap , 2)
|
1614 | 048f6b4d | bellard | MIPS_SYS(sys_truncate , 2)
|
1615 | 048f6b4d | bellard | MIPS_SYS(sys_ftruncate , 2)
|
1616 | 048f6b4d | bellard | MIPS_SYS(sys_fchmod , 2)
|
1617 | 048f6b4d | bellard | MIPS_SYS(sys_fchown , 3) /* 4095 */ |
1618 | 048f6b4d | bellard | MIPS_SYS(sys_getpriority , 2)
|
1619 | 048f6b4d | bellard | MIPS_SYS(sys_setpriority , 3)
|
1620 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1621 | 048f6b4d | bellard | MIPS_SYS(sys_statfs , 2)
|
1622 | 048f6b4d | bellard | MIPS_SYS(sys_fstatfs , 2) /* 4100 */ |
1623 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was ioperm(2) */ |
1624 | 048f6b4d | bellard | MIPS_SYS(sys_socketcall , 2)
|
1625 | 048f6b4d | bellard | MIPS_SYS(sys_syslog , 3)
|
1626 | 048f6b4d | bellard | MIPS_SYS(sys_setitimer , 3)
|
1627 | 048f6b4d | bellard | MIPS_SYS(sys_getitimer , 2) /* 4105 */ |
1628 | 048f6b4d | bellard | MIPS_SYS(sys_newstat , 2)
|
1629 | 048f6b4d | bellard | MIPS_SYS(sys_newlstat , 2)
|
1630 | 048f6b4d | bellard | MIPS_SYS(sys_newfstat , 2)
|
1631 | 048f6b4d | bellard | MIPS_SYS(sys_uname , 1)
|
1632 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4110 was iopl(2) */ |
1633 | 048f6b4d | bellard | MIPS_SYS(sys_vhangup , 0)
|
1634 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_idle() */ |
1635 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_vm86 */ |
1636 | 048f6b4d | bellard | MIPS_SYS(sys_wait4 , 4)
|
1637 | 048f6b4d | bellard | MIPS_SYS(sys_swapoff , 1) /* 4115 */ |
1638 | 048f6b4d | bellard | MIPS_SYS(sys_sysinfo , 1)
|
1639 | 048f6b4d | bellard | MIPS_SYS(sys_ipc , 6)
|
1640 | 048f6b4d | bellard | MIPS_SYS(sys_fsync , 1)
|
1641 | 048f6b4d | bellard | MIPS_SYS(sys_sigreturn , 0)
|
1642 | 18113962 | Paul Brook | MIPS_SYS(sys_clone , 6) /* 4120 */ |
1643 | 048f6b4d | bellard | MIPS_SYS(sys_setdomainname, 2)
|
1644 | 048f6b4d | bellard | MIPS_SYS(sys_newuname , 1)
|
1645 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_modify_ldt */ |
1646 | 048f6b4d | bellard | MIPS_SYS(sys_adjtimex , 1)
|
1647 | 048f6b4d | bellard | MIPS_SYS(sys_mprotect , 3) /* 4125 */ |
1648 | 048f6b4d | bellard | MIPS_SYS(sys_sigprocmask , 3)
|
1649 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was create_module */ |
1650 | 048f6b4d | bellard | MIPS_SYS(sys_init_module , 5)
|
1651 | 048f6b4d | bellard | MIPS_SYS(sys_delete_module, 1)
|
1652 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4130 was get_kernel_syms */ |
1653 | 048f6b4d | bellard | MIPS_SYS(sys_quotactl , 0)
|
1654 | 048f6b4d | bellard | MIPS_SYS(sys_getpgid , 1)
|
1655 | 048f6b4d | bellard | MIPS_SYS(sys_fchdir , 1)
|
1656 | 048f6b4d | bellard | MIPS_SYS(sys_bdflush , 2)
|
1657 | 048f6b4d | bellard | MIPS_SYS(sys_sysfs , 3) /* 4135 */ |
1658 | 048f6b4d | bellard | MIPS_SYS(sys_personality , 1)
|
1659 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* for afs_syscall */ |
1660 | 048f6b4d | bellard | MIPS_SYS(sys_setfsuid , 1)
|
1661 | 048f6b4d | bellard | MIPS_SYS(sys_setfsgid , 1)
|
1662 | 048f6b4d | bellard | MIPS_SYS(sys_llseek , 5) /* 4140 */ |
1663 | 048f6b4d | bellard | MIPS_SYS(sys_getdents , 3)
|
1664 | 048f6b4d | bellard | MIPS_SYS(sys_select , 5)
|
1665 | 048f6b4d | bellard | MIPS_SYS(sys_flock , 2)
|
1666 | 048f6b4d | bellard | MIPS_SYS(sys_msync , 3)
|
1667 | 048f6b4d | bellard | MIPS_SYS(sys_readv , 3) /* 4145 */ |
1668 | 048f6b4d | bellard | MIPS_SYS(sys_writev , 3)
|
1669 | 048f6b4d | bellard | MIPS_SYS(sys_cacheflush , 3)
|
1670 | 048f6b4d | bellard | MIPS_SYS(sys_cachectl , 3)
|
1671 | 048f6b4d | bellard | MIPS_SYS(sys_sysmips , 4)
|
1672 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4150 */ |
1673 | 048f6b4d | bellard | MIPS_SYS(sys_getsid , 1)
|
1674 | 048f6b4d | bellard | MIPS_SYS(sys_fdatasync , 0)
|
1675 | 048f6b4d | bellard | MIPS_SYS(sys_sysctl , 1)
|
1676 | 048f6b4d | bellard | MIPS_SYS(sys_mlock , 2)
|
1677 | 048f6b4d | bellard | MIPS_SYS(sys_munlock , 2) /* 4155 */ |
1678 | 048f6b4d | bellard | MIPS_SYS(sys_mlockall , 1)
|
1679 | 048f6b4d | bellard | MIPS_SYS(sys_munlockall , 0)
|
1680 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setparam, 2)
|
1681 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getparam, 2)
|
1682 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setscheduler, 3) /* 4160 */ |
1683 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getscheduler, 1)
|
1684 | 048f6b4d | bellard | MIPS_SYS(sys_sched_yield , 0)
|
1685 | 048f6b4d | bellard | MIPS_SYS(sys_sched_get_priority_max, 1)
|
1686 | 048f6b4d | bellard | MIPS_SYS(sys_sched_get_priority_min, 1)
|
1687 | 048f6b4d | bellard | MIPS_SYS(sys_sched_rr_get_interval, 2) /* 4165 */ |
1688 | 048f6b4d | bellard | MIPS_SYS(sys_nanosleep, 2)
|
1689 | 048f6b4d | bellard | MIPS_SYS(sys_mremap , 4)
|
1690 | 048f6b4d | bellard | MIPS_SYS(sys_accept , 3)
|
1691 | 048f6b4d | bellard | MIPS_SYS(sys_bind , 3)
|
1692 | 048f6b4d | bellard | MIPS_SYS(sys_connect , 3) /* 4170 */ |
1693 | 048f6b4d | bellard | MIPS_SYS(sys_getpeername , 3)
|
1694 | 048f6b4d | bellard | MIPS_SYS(sys_getsockname , 3)
|
1695 | 048f6b4d | bellard | MIPS_SYS(sys_getsockopt , 5)
|
1696 | 048f6b4d | bellard | MIPS_SYS(sys_listen , 2)
|
1697 | 048f6b4d | bellard | MIPS_SYS(sys_recv , 4) /* 4175 */ |
1698 | 048f6b4d | bellard | MIPS_SYS(sys_recvfrom , 6)
|
1699 | 048f6b4d | bellard | MIPS_SYS(sys_recvmsg , 3)
|
1700 | 048f6b4d | bellard | MIPS_SYS(sys_send , 4)
|
1701 | 048f6b4d | bellard | MIPS_SYS(sys_sendmsg , 3)
|
1702 | 048f6b4d | bellard | MIPS_SYS(sys_sendto , 6) /* 4180 */ |
1703 | 048f6b4d | bellard | MIPS_SYS(sys_setsockopt , 5)
|
1704 | 048f6b4d | bellard | MIPS_SYS(sys_shutdown , 2)
|
1705 | 048f6b4d | bellard | MIPS_SYS(sys_socket , 3)
|
1706 | 048f6b4d | bellard | MIPS_SYS(sys_socketpair , 4)
|
1707 | 048f6b4d | bellard | MIPS_SYS(sys_setresuid , 3) /* 4185 */ |
1708 | 048f6b4d | bellard | MIPS_SYS(sys_getresuid , 3)
|
1709 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* was sys_query_module */ |
1710 | 048f6b4d | bellard | MIPS_SYS(sys_poll , 3)
|
1711 | 048f6b4d | bellard | MIPS_SYS(sys_nfsservctl , 3)
|
1712 | 048f6b4d | bellard | MIPS_SYS(sys_setresgid , 3) /* 4190 */ |
1713 | 048f6b4d | bellard | MIPS_SYS(sys_getresgid , 3)
|
1714 | 048f6b4d | bellard | MIPS_SYS(sys_prctl , 5)
|
1715 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigreturn, 0)
|
1716 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigaction, 4)
|
1717 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigprocmask, 4) /* 4195 */ |
1718 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigpending, 2)
|
1719 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigtimedwait, 4)
|
1720 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigqueueinfo, 3)
|
1721 | 048f6b4d | bellard | MIPS_SYS(sys_rt_sigsuspend, 0)
|
1722 | 048f6b4d | bellard | MIPS_SYS(sys_pread64 , 6) /* 4200 */ |
1723 | 048f6b4d | bellard | MIPS_SYS(sys_pwrite64 , 6)
|
1724 | 048f6b4d | bellard | MIPS_SYS(sys_chown , 3)
|
1725 | 048f6b4d | bellard | MIPS_SYS(sys_getcwd , 2)
|
1726 | 048f6b4d | bellard | MIPS_SYS(sys_capget , 2)
|
1727 | 048f6b4d | bellard | MIPS_SYS(sys_capset , 2) /* 4205 */ |
1728 | 048f6b4d | bellard | MIPS_SYS(sys_sigaltstack , 0)
|
1729 | 048f6b4d | bellard | MIPS_SYS(sys_sendfile , 4)
|
1730 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1731 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1732 | 048f6b4d | bellard | MIPS_SYS(sys_mmap2 , 6) /* 4210 */ |
1733 | 048f6b4d | bellard | MIPS_SYS(sys_truncate64 , 4)
|
1734 | 048f6b4d | bellard | MIPS_SYS(sys_ftruncate64 , 4)
|
1735 | 048f6b4d | bellard | MIPS_SYS(sys_stat64 , 2)
|
1736 | 048f6b4d | bellard | MIPS_SYS(sys_lstat64 , 2)
|
1737 | 048f6b4d | bellard | MIPS_SYS(sys_fstat64 , 2) /* 4215 */ |
1738 | 048f6b4d | bellard | MIPS_SYS(sys_pivot_root , 2)
|
1739 | 048f6b4d | bellard | MIPS_SYS(sys_mincore , 3)
|
1740 | 048f6b4d | bellard | MIPS_SYS(sys_madvise , 3)
|
1741 | 048f6b4d | bellard | MIPS_SYS(sys_getdents64 , 3)
|
1742 | 048f6b4d | bellard | MIPS_SYS(sys_fcntl64 , 3) /* 4220 */ |
1743 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0)
|
1744 | 048f6b4d | bellard | MIPS_SYS(sys_gettid , 0)
|
1745 | 048f6b4d | bellard | MIPS_SYS(sys_readahead , 5)
|
1746 | 048f6b4d | bellard | MIPS_SYS(sys_setxattr , 5)
|
1747 | 048f6b4d | bellard | MIPS_SYS(sys_lsetxattr , 5) /* 4225 */ |
1748 | 048f6b4d | bellard | MIPS_SYS(sys_fsetxattr , 5)
|
1749 | 048f6b4d | bellard | MIPS_SYS(sys_getxattr , 4)
|
1750 | 048f6b4d | bellard | MIPS_SYS(sys_lgetxattr , 4)
|
1751 | 048f6b4d | bellard | MIPS_SYS(sys_fgetxattr , 4)
|
1752 | 048f6b4d | bellard | MIPS_SYS(sys_listxattr , 3) /* 4230 */ |
1753 | 048f6b4d | bellard | MIPS_SYS(sys_llistxattr , 3)
|
1754 | 048f6b4d | bellard | MIPS_SYS(sys_flistxattr , 3)
|
1755 | 048f6b4d | bellard | MIPS_SYS(sys_removexattr , 2)
|
1756 | 048f6b4d | bellard | MIPS_SYS(sys_lremovexattr, 2)
|
1757 | 048f6b4d | bellard | MIPS_SYS(sys_fremovexattr, 2) /* 4235 */ |
1758 | 048f6b4d | bellard | MIPS_SYS(sys_tkill , 2)
|
1759 | 048f6b4d | bellard | MIPS_SYS(sys_sendfile64 , 5)
|
1760 | 048f6b4d | bellard | MIPS_SYS(sys_futex , 2)
|
1761 | 048f6b4d | bellard | MIPS_SYS(sys_sched_setaffinity, 3)
|
1762 | 048f6b4d | bellard | MIPS_SYS(sys_sched_getaffinity, 3) /* 4240 */ |
1763 | 048f6b4d | bellard | MIPS_SYS(sys_io_setup , 2)
|
1764 | 048f6b4d | bellard | MIPS_SYS(sys_io_destroy , 1)
|
1765 | 048f6b4d | bellard | MIPS_SYS(sys_io_getevents, 5)
|
1766 | 048f6b4d | bellard | MIPS_SYS(sys_io_submit , 3)
|
1767 | 048f6b4d | bellard | MIPS_SYS(sys_io_cancel , 3) /* 4245 */ |
1768 | 048f6b4d | bellard | MIPS_SYS(sys_exit_group , 1)
|
1769 | 048f6b4d | bellard | MIPS_SYS(sys_lookup_dcookie, 3)
|
1770 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_create, 1)
|
1771 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_ctl , 4)
|
1772 | 048f6b4d | bellard | MIPS_SYS(sys_epoll_wait , 3) /* 4250 */ |
1773 | 048f6b4d | bellard | MIPS_SYS(sys_remap_file_pages, 5)
|
1774 | 048f6b4d | bellard | MIPS_SYS(sys_set_tid_address, 1)
|
1775 | 048f6b4d | bellard | MIPS_SYS(sys_restart_syscall, 0)
|
1776 | 048f6b4d | bellard | MIPS_SYS(sys_fadvise64_64, 7)
|
1777 | 048f6b4d | bellard | MIPS_SYS(sys_statfs64 , 3) /* 4255 */ |
1778 | 048f6b4d | bellard | MIPS_SYS(sys_fstatfs64 , 2)
|
1779 | 048f6b4d | bellard | MIPS_SYS(sys_timer_create, 3)
|
1780 | 048f6b4d | bellard | MIPS_SYS(sys_timer_settime, 4)
|
1781 | 048f6b4d | bellard | MIPS_SYS(sys_timer_gettime, 2)
|
1782 | 048f6b4d | bellard | MIPS_SYS(sys_timer_getoverrun, 1) /* 4260 */ |
1783 | 048f6b4d | bellard | MIPS_SYS(sys_timer_delete, 1)
|
1784 | 048f6b4d | bellard | MIPS_SYS(sys_clock_settime, 2)
|
1785 | 048f6b4d | bellard | MIPS_SYS(sys_clock_gettime, 2)
|
1786 | 048f6b4d | bellard | MIPS_SYS(sys_clock_getres, 2)
|
1787 | 048f6b4d | bellard | MIPS_SYS(sys_clock_nanosleep, 4) /* 4265 */ |
1788 | 048f6b4d | bellard | MIPS_SYS(sys_tgkill , 3)
|
1789 | 048f6b4d | bellard | MIPS_SYS(sys_utimes , 2)
|
1790 | 048f6b4d | bellard | MIPS_SYS(sys_mbind , 4)
|
1791 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_get_mempolicy */ |
1792 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* 4270 sys_set_mempolicy */ |
1793 | 048f6b4d | bellard | MIPS_SYS(sys_mq_open , 4)
|
1794 | 048f6b4d | bellard | MIPS_SYS(sys_mq_unlink , 1)
|
1795 | 048f6b4d | bellard | MIPS_SYS(sys_mq_timedsend, 5)
|
1796 | 048f6b4d | bellard | MIPS_SYS(sys_mq_timedreceive, 5)
|
1797 | 048f6b4d | bellard | MIPS_SYS(sys_mq_notify , 2) /* 4275 */ |
1798 | 048f6b4d | bellard | MIPS_SYS(sys_mq_getsetattr, 3)
|
1799 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* sys_vserver */ |
1800 | 048f6b4d | bellard | MIPS_SYS(sys_waitid , 4)
|
1801 | 048f6b4d | bellard | MIPS_SYS(sys_ni_syscall , 0) /* available, was setaltroot */ |
1802 | 048f6b4d | bellard | MIPS_SYS(sys_add_key , 5)
|
1803 | 388bb21a | ths | MIPS_SYS(sys_request_key, 4)
|
1804 | 048f6b4d | bellard | MIPS_SYS(sys_keyctl , 5)
|
1805 | 6f5b89a0 | ths | MIPS_SYS(sys_set_thread_area, 1)
|
1806 | 388bb21a | ths | MIPS_SYS(sys_inotify_init, 0)
|
1807 | 388bb21a | ths | MIPS_SYS(sys_inotify_add_watch, 3) /* 4285 */ |
1808 | 388bb21a | ths | MIPS_SYS(sys_inotify_rm_watch, 2)
|
1809 | 388bb21a | ths | MIPS_SYS(sys_migrate_pages, 4)
|
1810 | 388bb21a | ths | MIPS_SYS(sys_openat, 4)
|
1811 | 388bb21a | ths | MIPS_SYS(sys_mkdirat, 3)
|
1812 | 388bb21a | ths | MIPS_SYS(sys_mknodat, 4) /* 4290 */ |
1813 | 388bb21a | ths | MIPS_SYS(sys_fchownat, 5)
|
1814 | 388bb21a | ths | MIPS_SYS(sys_futimesat, 3)
|
1815 | 388bb21a | ths | MIPS_SYS(sys_fstatat64, 4)
|
1816 | 388bb21a | ths | MIPS_SYS(sys_unlinkat, 3)
|
1817 | 388bb21a | ths | MIPS_SYS(sys_renameat, 4) /* 4295 */ |
1818 | 388bb21a | ths | MIPS_SYS(sys_linkat, 5)
|
1819 | 388bb21a | ths | MIPS_SYS(sys_symlinkat, 3)
|
1820 | 388bb21a | ths | MIPS_SYS(sys_readlinkat, 4)
|
1821 | 388bb21a | ths | MIPS_SYS(sys_fchmodat, 3)
|
1822 | 388bb21a | ths | MIPS_SYS(sys_faccessat, 3) /* 4300 */ |
1823 | 388bb21a | ths | MIPS_SYS(sys_pselect6, 6)
|
1824 | 388bb21a | ths | MIPS_SYS(sys_ppoll, 5)
|
1825 | 388bb21a | ths | MIPS_SYS(sys_unshare, 1)
|
1826 | 388bb21a | ths | MIPS_SYS(sys_splice, 4)
|
1827 | 388bb21a | ths | MIPS_SYS(sys_sync_file_range, 7) /* 4305 */ |
1828 | 388bb21a | ths | MIPS_SYS(sys_tee, 4)
|
1829 | 388bb21a | ths | MIPS_SYS(sys_vmsplice, 4)
|
1830 | 388bb21a | ths | MIPS_SYS(sys_move_pages, 6)
|
1831 | 388bb21a | ths | MIPS_SYS(sys_set_robust_list, 2)
|
1832 | 388bb21a | ths | MIPS_SYS(sys_get_robust_list, 3) /* 4310 */ |
1833 | 388bb21a | ths | MIPS_SYS(sys_kexec_load, 4)
|
1834 | 388bb21a | ths | MIPS_SYS(sys_getcpu, 3)
|
1835 | 388bb21a | ths | MIPS_SYS(sys_epoll_pwait, 6)
|
1836 | 388bb21a | ths | MIPS_SYS(sys_ioprio_set, 3)
|
1837 | 388bb21a | ths | MIPS_SYS(sys_ioprio_get, 2)
|
1838 | 048f6b4d | bellard | }; |
1839 | 048f6b4d | bellard | |
1840 | 048f6b4d | bellard | #undef MIPS_SYS
|
1841 | 048f6b4d | bellard | |
1842 | 590bc601 | Paul Brook | static int do_store_exclusive(CPUMIPSState *env) |
1843 | 590bc601 | Paul Brook | { |
1844 | 590bc601 | Paul Brook | target_ulong addr; |
1845 | 590bc601 | Paul Brook | target_ulong page_addr; |
1846 | 590bc601 | Paul Brook | target_ulong val; |
1847 | 590bc601 | Paul Brook | int flags;
|
1848 | 590bc601 | Paul Brook | int segv = 0; |
1849 | 590bc601 | Paul Brook | int reg;
|
1850 | 590bc601 | Paul Brook | int d;
|
1851 | 590bc601 | Paul Brook | |
1852 | 590bc601 | Paul Brook | addr = env->CP0_LLAddr; |
1853 | 590bc601 | Paul Brook | page_addr = addr & TARGET_PAGE_MASK; |
1854 | 590bc601 | Paul Brook | start_exclusive(); |
1855 | 590bc601 | Paul Brook | mmap_lock(); |
1856 | 590bc601 | Paul Brook | flags = page_get_flags(page_addr); |
1857 | 590bc601 | Paul Brook | if ((flags & PAGE_READ) == 0) { |
1858 | 590bc601 | Paul Brook | segv = 1;
|
1859 | 590bc601 | Paul Brook | } else {
|
1860 | 590bc601 | Paul Brook | reg = env->llreg & 0x1f;
|
1861 | 590bc601 | Paul Brook | d = (env->llreg & 0x20) != 0; |
1862 | 590bc601 | Paul Brook | if (d) {
|
1863 | 590bc601 | Paul Brook | segv = get_user_s64(val, addr); |
1864 | 590bc601 | Paul Brook | } else {
|
1865 | 590bc601 | Paul Brook | segv = get_user_s32(val, addr); |
1866 | 590bc601 | Paul Brook | } |
1867 | 590bc601 | Paul Brook | if (!segv) {
|
1868 | 590bc601 | Paul Brook | if (val != env->llval) {
|
1869 | 590bc601 | Paul Brook | env->active_tc.gpr[reg] = 0;
|
1870 | 590bc601 | Paul Brook | } else {
|
1871 | 590bc601 | Paul Brook | if (d) {
|
1872 | 590bc601 | Paul Brook | segv = put_user_u64(env->llnewval, addr); |
1873 | 590bc601 | Paul Brook | } else {
|
1874 | 590bc601 | Paul Brook | segv = put_user_u32(env->llnewval, addr); |
1875 | 590bc601 | Paul Brook | } |
1876 | 590bc601 | Paul Brook | if (!segv) {
|
1877 | 590bc601 | Paul Brook | env->active_tc.gpr[reg] = 1;
|
1878 | 590bc601 | Paul Brook | } |
1879 | 590bc601 | Paul Brook | } |
1880 | 590bc601 | Paul Brook | } |
1881 | 590bc601 | Paul Brook | } |
1882 | 590bc601 | Paul Brook | env->CP0_LLAddr = -1;
|
1883 | 590bc601 | Paul Brook | if (!segv) {
|
1884 | 590bc601 | Paul Brook | env->active_tc.PC += 4;
|
1885 | 590bc601 | Paul Brook | } |
1886 | 590bc601 | Paul Brook | mmap_unlock(); |
1887 | 590bc601 | Paul Brook | end_exclusive(); |
1888 | 590bc601 | Paul Brook | return segv;
|
1889 | 590bc601 | Paul Brook | } |
1890 | 590bc601 | Paul Brook | |
1891 | 048f6b4d | bellard | void cpu_loop(CPUMIPSState *env)
|
1892 | 048f6b4d | bellard | { |
1893 | c227f099 | Anthony Liguori | target_siginfo_t info; |
1894 | 388bb21a | ths | int trapnr, ret;
|
1895 | 048f6b4d | bellard | unsigned int syscall_num; |
1896 | 048f6b4d | bellard | |
1897 | 048f6b4d | bellard | for(;;) {
|
1898 | 590bc601 | Paul Brook | cpu_exec_start(env); |
1899 | 048f6b4d | bellard | trapnr = cpu_mips_exec(env); |
1900 | 590bc601 | Paul Brook | cpu_exec_end(env); |
1901 | 048f6b4d | bellard | switch(trapnr) {
|
1902 | 048f6b4d | bellard | case EXCP_SYSCALL:
|
1903 | b5dc7732 | ths | syscall_num = env->active_tc.gpr[2] - 4000; |
1904 | b5dc7732 | ths | env->active_tc.PC += 4;
|
1905 | 388bb21a | ths | if (syscall_num >= sizeof(mips_syscall_args)) { |
1906 | 388bb21a | ths | ret = -ENOSYS; |
1907 | 388bb21a | ths | } else {
|
1908 | 388bb21a | ths | int nb_args;
|
1909 | 992f48a0 | blueswir1 | abi_ulong sp_reg; |
1910 | 992f48a0 | blueswir1 | abi_ulong arg5 = 0, arg6 = 0, arg7 = 0, arg8 = 0; |
1911 | 388bb21a | ths | |
1912 | 388bb21a | ths | nb_args = mips_syscall_args[syscall_num]; |
1913 | b5dc7732 | ths | sp_reg = env->active_tc.gpr[29];
|
1914 | 388bb21a | ths | switch (nb_args) {
|
1915 | 388bb21a | ths | /* these arguments are taken from the stack */
|
1916 | 2f619698 | bellard | /* FIXME - what to do if get_user() fails? */
|
1917 | 2f619698 | bellard | case 8: get_user_ual(arg8, sp_reg + 28); |
1918 | 2f619698 | bellard | case 7: get_user_ual(arg7, sp_reg + 24); |
1919 | 2f619698 | bellard | case 6: get_user_ual(arg6, sp_reg + 20); |
1920 | 2f619698 | bellard | case 5: get_user_ual(arg5, sp_reg + 16); |
1921 | 388bb21a | ths | default:
|
1922 | 388bb21a | ths | break;
|
1923 | 048f6b4d | bellard | } |
1924 | b5dc7732 | ths | ret = do_syscall(env, env->active_tc.gpr[2],
|
1925 | b5dc7732 | ths | env->active_tc.gpr[4],
|
1926 | b5dc7732 | ths | env->active_tc.gpr[5],
|
1927 | b5dc7732 | ths | env->active_tc.gpr[6],
|
1928 | b5dc7732 | ths | env->active_tc.gpr[7],
|
1929 | 388bb21a | ths | arg5, arg6/*, arg7, arg8*/);
|
1930 | 388bb21a | ths | } |
1931 | 0b1bcb00 | pbrook | if (ret == -TARGET_QEMU_ESIGRETURN) {
|
1932 | 0b1bcb00 | pbrook | /* Returning from a successful sigreturn syscall.
|
1933 | 0b1bcb00 | pbrook | Avoid clobbering register state. */
|
1934 | 0b1bcb00 | pbrook | break;
|
1935 | 0b1bcb00 | pbrook | } |
1936 | 388bb21a | ths | if ((unsigned int)ret >= (unsigned int)(-1133)) { |
1937 | b5dc7732 | ths | env->active_tc.gpr[7] = 1; /* error flag */ |
1938 | 388bb21a | ths | ret = -ret; |
1939 | 388bb21a | ths | } else {
|
1940 | b5dc7732 | ths | env->active_tc.gpr[7] = 0; /* error flag */ |
1941 | 048f6b4d | bellard | } |
1942 | b5dc7732 | ths | env->active_tc.gpr[2] = ret;
|
1943 | 048f6b4d | bellard | break;
|
1944 | ca7c2b1b | ths | case EXCP_TLBL:
|
1945 | ca7c2b1b | ths | case EXCP_TLBS:
|
1946 | e4474235 | pbrook | info.si_signo = TARGET_SIGSEGV; |
1947 | e4474235 | pbrook | info.si_errno = 0;
|
1948 | e4474235 | pbrook | /* XXX: check env->error_code */
|
1949 | e4474235 | pbrook | info.si_code = TARGET_SEGV_MAPERR; |
1950 | e4474235 | pbrook | info._sifields._sigfault._addr = env->CP0_BadVAddr; |
1951 | e4474235 | pbrook | queue_signal(env, info.si_signo, &info); |
1952 | e4474235 | pbrook | break;
|
1953 | 6900e84b | bellard | case EXCP_CpU:
|
1954 | 048f6b4d | bellard | case EXCP_RI:
|
1955 | bc1ad2de | bellard | info.si_signo = TARGET_SIGILL; |
1956 | bc1ad2de | bellard | info.si_errno = 0;
|
1957 | bc1ad2de | bellard | info.si_code = 0;
|
1958 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1959 | 048f6b4d | bellard | break;
|
1960 | 106ec879 | bellard | case EXCP_INTERRUPT:
|
1961 | 106ec879 | bellard | /* just indicate that signals should be handled asap */
|
1962 | 106ec879 | bellard | break;
|
1963 | d08b2a28 | pbrook | case EXCP_DEBUG:
|
1964 | d08b2a28 | pbrook | { |
1965 | d08b2a28 | pbrook | int sig;
|
1966 | d08b2a28 | pbrook | |
1967 | d08b2a28 | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
1968 | d08b2a28 | pbrook | if (sig)
|
1969 | d08b2a28 | pbrook | { |
1970 | d08b2a28 | pbrook | info.si_signo = sig; |
1971 | d08b2a28 | pbrook | info.si_errno = 0;
|
1972 | d08b2a28 | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
1973 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
1974 | d08b2a28 | pbrook | } |
1975 | d08b2a28 | pbrook | } |
1976 | d08b2a28 | pbrook | break;
|
1977 | 590bc601 | Paul Brook | case EXCP_SC:
|
1978 | 590bc601 | Paul Brook | if (do_store_exclusive(env)) {
|
1979 | 590bc601 | Paul Brook | info.si_signo = TARGET_SIGSEGV; |
1980 | 590bc601 | Paul Brook | info.si_errno = 0;
|
1981 | 590bc601 | Paul Brook | info.si_code = TARGET_SEGV_MAPERR; |
1982 | 590bc601 | Paul Brook | info._sifields._sigfault._addr = env->active_tc.PC; |
1983 | 590bc601 | Paul Brook | queue_signal(env, info.si_signo, &info); |
1984 | 590bc601 | Paul Brook | } |
1985 | 590bc601 | Paul Brook | break;
|
1986 | 048f6b4d | bellard | default:
|
1987 | 048f6b4d | bellard | // error:
|
1988 | 5fafdf24 | ths | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
1989 | 048f6b4d | bellard | trapnr); |
1990 | 048f6b4d | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
1991 | 048f6b4d | bellard | abort(); |
1992 | 048f6b4d | bellard | } |
1993 | 048f6b4d | bellard | process_pending_signals(env); |
1994 | 048f6b4d | bellard | } |
1995 | 048f6b4d | bellard | } |
1996 | 048f6b4d | bellard | #endif
|
1997 | 048f6b4d | bellard | |
1998 | fdf9b3e8 | bellard | #ifdef TARGET_SH4
|
1999 | fdf9b3e8 | bellard | void cpu_loop (CPUState *env)
|
2000 | fdf9b3e8 | bellard | { |
2001 | fdf9b3e8 | bellard | int trapnr, ret;
|
2002 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2003 | 3b46e624 | ths | |
2004 | fdf9b3e8 | bellard | while (1) { |
2005 | fdf9b3e8 | bellard | trapnr = cpu_sh4_exec (env); |
2006 | 3b46e624 | ths | |
2007 | fdf9b3e8 | bellard | switch (trapnr) {
|
2008 | fdf9b3e8 | bellard | case 0x160: |
2009 | 0b6d3ae0 | aurel32 | env->pc += 2;
|
2010 | 5fafdf24 | ths | ret = do_syscall(env, |
2011 | 5fafdf24 | ths | env->gregs[3],
|
2012 | 5fafdf24 | ths | env->gregs[4],
|
2013 | 5fafdf24 | ths | env->gregs[5],
|
2014 | 5fafdf24 | ths | env->gregs[6],
|
2015 | 5fafdf24 | ths | env->gregs[7],
|
2016 | 5fafdf24 | ths | env->gregs[0],
|
2017 | fca743f3 | ths | env->gregs[1]);
|
2018 | 9c2a9ea1 | pbrook | env->gregs[0] = ret;
|
2019 | fdf9b3e8 | bellard | break;
|
2020 | c3b5bc8a | ths | case EXCP_INTERRUPT:
|
2021 | c3b5bc8a | ths | /* just indicate that signals should be handled asap */
|
2022 | c3b5bc8a | ths | break;
|
2023 | 355fb23d | pbrook | case EXCP_DEBUG:
|
2024 | 355fb23d | pbrook | { |
2025 | 355fb23d | pbrook | int sig;
|
2026 | 355fb23d | pbrook | |
2027 | 355fb23d | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2028 | 355fb23d | pbrook | if (sig)
|
2029 | 355fb23d | pbrook | { |
2030 | 355fb23d | pbrook | info.si_signo = sig; |
2031 | 355fb23d | pbrook | info.si_errno = 0;
|
2032 | 355fb23d | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
2033 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2034 | 355fb23d | pbrook | } |
2035 | 355fb23d | pbrook | } |
2036 | 355fb23d | pbrook | break;
|
2037 | c3b5bc8a | ths | case 0xa0: |
2038 | c3b5bc8a | ths | case 0xc0: |
2039 | c3b5bc8a | ths | info.si_signo = SIGSEGV; |
2040 | c3b5bc8a | ths | info.si_errno = 0;
|
2041 | c3b5bc8a | ths | info.si_code = TARGET_SEGV_MAPERR; |
2042 | c3b5bc8a | ths | info._sifields._sigfault._addr = env->tea; |
2043 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2044 | c3b5bc8a | ths | break;
|
2045 | c3b5bc8a | ths | |
2046 | fdf9b3e8 | bellard | default:
|
2047 | fdf9b3e8 | bellard | printf ("Unhandled trap: 0x%x\n", trapnr);
|
2048 | fdf9b3e8 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
2049 | fdf9b3e8 | bellard | exit (1);
|
2050 | fdf9b3e8 | bellard | } |
2051 | fdf9b3e8 | bellard | process_pending_signals (env); |
2052 | fdf9b3e8 | bellard | } |
2053 | fdf9b3e8 | bellard | } |
2054 | fdf9b3e8 | bellard | #endif
|
2055 | fdf9b3e8 | bellard | |
2056 | 48733d19 | ths | #ifdef TARGET_CRIS
|
2057 | 48733d19 | ths | void cpu_loop (CPUState *env)
|
2058 | 48733d19 | ths | { |
2059 | 48733d19 | ths | int trapnr, ret;
|
2060 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2061 | 48733d19 | ths | |
2062 | 48733d19 | ths | while (1) { |
2063 | 48733d19 | ths | trapnr = cpu_cris_exec (env); |
2064 | 48733d19 | ths | switch (trapnr) {
|
2065 | 48733d19 | ths | case 0xaa: |
2066 | 48733d19 | ths | { |
2067 | 48733d19 | ths | info.si_signo = SIGSEGV; |
2068 | 48733d19 | ths | info.si_errno = 0;
|
2069 | 48733d19 | ths | /* XXX: check env->error_code */
|
2070 | 48733d19 | ths | info.si_code = TARGET_SEGV_MAPERR; |
2071 | e00c1e71 | edgar_igl | info._sifields._sigfault._addr = env->pregs[PR_EDA]; |
2072 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2073 | 48733d19 | ths | } |
2074 | 48733d19 | ths | break;
|
2075 | b6d3abda | edgar_igl | case EXCP_INTERRUPT:
|
2076 | b6d3abda | edgar_igl | /* just indicate that signals should be handled asap */
|
2077 | b6d3abda | edgar_igl | break;
|
2078 | 48733d19 | ths | case EXCP_BREAK:
|
2079 | 48733d19 | ths | ret = do_syscall(env, |
2080 | 48733d19 | ths | env->regs[9],
|
2081 | 48733d19 | ths | env->regs[10],
|
2082 | 48733d19 | ths | env->regs[11],
|
2083 | 48733d19 | ths | env->regs[12],
|
2084 | 48733d19 | ths | env->regs[13],
|
2085 | 48733d19 | ths | env->pregs[7],
|
2086 | 48733d19 | ths | env->pregs[11]);
|
2087 | 48733d19 | ths | env->regs[10] = ret;
|
2088 | 48733d19 | ths | break;
|
2089 | 48733d19 | ths | case EXCP_DEBUG:
|
2090 | 48733d19 | ths | { |
2091 | 48733d19 | ths | int sig;
|
2092 | 48733d19 | ths | |
2093 | 48733d19 | ths | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2094 | 48733d19 | ths | if (sig)
|
2095 | 48733d19 | ths | { |
2096 | 48733d19 | ths | info.si_signo = sig; |
2097 | 48733d19 | ths | info.si_errno = 0;
|
2098 | 48733d19 | ths | info.si_code = TARGET_TRAP_BRKPT; |
2099 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2100 | 48733d19 | ths | } |
2101 | 48733d19 | ths | } |
2102 | 48733d19 | ths | break;
|
2103 | 48733d19 | ths | default:
|
2104 | 48733d19 | ths | printf ("Unhandled trap: 0x%x\n", trapnr);
|
2105 | 48733d19 | ths | cpu_dump_state(env, stderr, fprintf, 0);
|
2106 | 48733d19 | ths | exit (1);
|
2107 | 48733d19 | ths | } |
2108 | 48733d19 | ths | process_pending_signals (env); |
2109 | 48733d19 | ths | } |
2110 | 48733d19 | ths | } |
2111 | 48733d19 | ths | #endif
|
2112 | 48733d19 | ths | |
2113 | b779e29e | Edgar E. Iglesias | #ifdef TARGET_MICROBLAZE
|
2114 | b779e29e | Edgar E. Iglesias | void cpu_loop (CPUState *env)
|
2115 | b779e29e | Edgar E. Iglesias | { |
2116 | b779e29e | Edgar E. Iglesias | int trapnr, ret;
|
2117 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2118 | b779e29e | Edgar E. Iglesias | |
2119 | b779e29e | Edgar E. Iglesias | while (1) { |
2120 | b779e29e | Edgar E. Iglesias | trapnr = cpu_mb_exec (env); |
2121 | b779e29e | Edgar E. Iglesias | switch (trapnr) {
|
2122 | b779e29e | Edgar E. Iglesias | case 0xaa: |
2123 | b779e29e | Edgar E. Iglesias | { |
2124 | b779e29e | Edgar E. Iglesias | info.si_signo = SIGSEGV; |
2125 | b779e29e | Edgar E. Iglesias | info.si_errno = 0;
|
2126 | b779e29e | Edgar E. Iglesias | /* XXX: check env->error_code */
|
2127 | b779e29e | Edgar E. Iglesias | info.si_code = TARGET_SEGV_MAPERR; |
2128 | b779e29e | Edgar E. Iglesias | info._sifields._sigfault._addr = 0;
|
2129 | b779e29e | Edgar E. Iglesias | queue_signal(env, info.si_signo, &info); |
2130 | b779e29e | Edgar E. Iglesias | } |
2131 | b779e29e | Edgar E. Iglesias | break;
|
2132 | b779e29e | Edgar E. Iglesias | case EXCP_INTERRUPT:
|
2133 | b779e29e | Edgar E. Iglesias | /* just indicate that signals should be handled asap */
|
2134 | b779e29e | Edgar E. Iglesias | break;
|
2135 | b779e29e | Edgar E. Iglesias | case EXCP_BREAK:
|
2136 | b779e29e | Edgar E. Iglesias | /* Return address is 4 bytes after the call. */
|
2137 | b779e29e | Edgar E. Iglesias | env->regs[14] += 4; |
2138 | b779e29e | Edgar E. Iglesias | ret = do_syscall(env, |
2139 | b779e29e | Edgar E. Iglesias | env->regs[12],
|
2140 | b779e29e | Edgar E. Iglesias | env->regs[5],
|
2141 | b779e29e | Edgar E. Iglesias | env->regs[6],
|
2142 | b779e29e | Edgar E. Iglesias | env->regs[7],
|
2143 | b779e29e | Edgar E. Iglesias | env->regs[8],
|
2144 | b779e29e | Edgar E. Iglesias | env->regs[9],
|
2145 | b779e29e | Edgar E. Iglesias | env->regs[10]);
|
2146 | b779e29e | Edgar E. Iglesias | env->regs[3] = ret;
|
2147 | b779e29e | Edgar E. Iglesias | env->sregs[SR_PC] = env->regs[14];
|
2148 | b779e29e | Edgar E. Iglesias | break;
|
2149 | b779e29e | Edgar E. Iglesias | case EXCP_DEBUG:
|
2150 | b779e29e | Edgar E. Iglesias | { |
2151 | b779e29e | Edgar E. Iglesias | int sig;
|
2152 | b779e29e | Edgar E. Iglesias | |
2153 | b779e29e | Edgar E. Iglesias | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2154 | b779e29e | Edgar E. Iglesias | if (sig)
|
2155 | b779e29e | Edgar E. Iglesias | { |
2156 | b779e29e | Edgar E. Iglesias | info.si_signo = sig; |
2157 | b779e29e | Edgar E. Iglesias | info.si_errno = 0;
|
2158 | b779e29e | Edgar E. Iglesias | info.si_code = TARGET_TRAP_BRKPT; |
2159 | b779e29e | Edgar E. Iglesias | queue_signal(env, info.si_signo, &info); |
2160 | b779e29e | Edgar E. Iglesias | } |
2161 | b779e29e | Edgar E. Iglesias | } |
2162 | b779e29e | Edgar E. Iglesias | break;
|
2163 | b779e29e | Edgar E. Iglesias | default:
|
2164 | b779e29e | Edgar E. Iglesias | printf ("Unhandled trap: 0x%x\n", trapnr);
|
2165 | b779e29e | Edgar E. Iglesias | cpu_dump_state(env, stderr, fprintf, 0);
|
2166 | b779e29e | Edgar E. Iglesias | exit (1);
|
2167 | b779e29e | Edgar E. Iglesias | } |
2168 | b779e29e | Edgar E. Iglesias | process_pending_signals (env); |
2169 | b779e29e | Edgar E. Iglesias | } |
2170 | b779e29e | Edgar E. Iglesias | } |
2171 | b779e29e | Edgar E. Iglesias | #endif
|
2172 | b779e29e | Edgar E. Iglesias | |
2173 | e6e5906b | pbrook | #ifdef TARGET_M68K
|
2174 | e6e5906b | pbrook | |
2175 | e6e5906b | pbrook | void cpu_loop(CPUM68KState *env)
|
2176 | e6e5906b | pbrook | { |
2177 | e6e5906b | pbrook | int trapnr;
|
2178 | e6e5906b | pbrook | unsigned int n; |
2179 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2180 | e6e5906b | pbrook | TaskState *ts = env->opaque; |
2181 | 3b46e624 | ths | |
2182 | e6e5906b | pbrook | for(;;) {
|
2183 | e6e5906b | pbrook | trapnr = cpu_m68k_exec(env); |
2184 | e6e5906b | pbrook | switch(trapnr) {
|
2185 | e6e5906b | pbrook | case EXCP_ILLEGAL:
|
2186 | e6e5906b | pbrook | { |
2187 | e6e5906b | pbrook | if (ts->sim_syscalls) {
|
2188 | e6e5906b | pbrook | uint16_t nr; |
2189 | e6e5906b | pbrook | nr = lduw(env->pc + 2);
|
2190 | e6e5906b | pbrook | env->pc += 4;
|
2191 | e6e5906b | pbrook | do_m68k_simcall(env, nr); |
2192 | e6e5906b | pbrook | } else {
|
2193 | e6e5906b | pbrook | goto do_sigill;
|
2194 | e6e5906b | pbrook | } |
2195 | e6e5906b | pbrook | } |
2196 | e6e5906b | pbrook | break;
|
2197 | a87295e8 | pbrook | case EXCP_HALT_INSN:
|
2198 | e6e5906b | pbrook | /* Semihosing syscall. */
|
2199 | a87295e8 | pbrook | env->pc += 4;
|
2200 | e6e5906b | pbrook | do_m68k_semihosting(env, env->dregs[0]);
|
2201 | e6e5906b | pbrook | break;
|
2202 | e6e5906b | pbrook | case EXCP_LINEA:
|
2203 | e6e5906b | pbrook | case EXCP_LINEF:
|
2204 | e6e5906b | pbrook | case EXCP_UNSUPPORTED:
|
2205 | e6e5906b | pbrook | do_sigill:
|
2206 | e6e5906b | pbrook | info.si_signo = SIGILL; |
2207 | e6e5906b | pbrook | info.si_errno = 0;
|
2208 | e6e5906b | pbrook | info.si_code = TARGET_ILL_ILLOPN; |
2209 | e6e5906b | pbrook | info._sifields._sigfault._addr = env->pc; |
2210 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2211 | e6e5906b | pbrook | break;
|
2212 | e6e5906b | pbrook | case EXCP_TRAP0:
|
2213 | e6e5906b | pbrook | { |
2214 | e6e5906b | pbrook | ts->sim_syscalls = 0;
|
2215 | e6e5906b | pbrook | n = env->dregs[0];
|
2216 | e6e5906b | pbrook | env->pc += 2;
|
2217 | 5fafdf24 | ths | env->dregs[0] = do_syscall(env,
|
2218 | 5fafdf24 | ths | n, |
2219 | e6e5906b | pbrook | env->dregs[1],
|
2220 | e6e5906b | pbrook | env->dregs[2],
|
2221 | e6e5906b | pbrook | env->dregs[3],
|
2222 | e6e5906b | pbrook | env->dregs[4],
|
2223 | e6e5906b | pbrook | env->dregs[5],
|
2224 | bb7ec043 | pbrook | env->aregs[0]);
|
2225 | e6e5906b | pbrook | } |
2226 | e6e5906b | pbrook | break;
|
2227 | e6e5906b | pbrook | case EXCP_INTERRUPT:
|
2228 | e6e5906b | pbrook | /* just indicate that signals should be handled asap */
|
2229 | e6e5906b | pbrook | break;
|
2230 | e6e5906b | pbrook | case EXCP_ACCESS:
|
2231 | e6e5906b | pbrook | { |
2232 | e6e5906b | pbrook | info.si_signo = SIGSEGV; |
2233 | e6e5906b | pbrook | info.si_errno = 0;
|
2234 | e6e5906b | pbrook | /* XXX: check env->error_code */
|
2235 | e6e5906b | pbrook | info.si_code = TARGET_SEGV_MAPERR; |
2236 | e6e5906b | pbrook | info._sifields._sigfault._addr = env->mmu.ar; |
2237 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2238 | e6e5906b | pbrook | } |
2239 | e6e5906b | pbrook | break;
|
2240 | e6e5906b | pbrook | case EXCP_DEBUG:
|
2241 | e6e5906b | pbrook | { |
2242 | e6e5906b | pbrook | int sig;
|
2243 | e6e5906b | pbrook | |
2244 | e6e5906b | pbrook | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2245 | e6e5906b | pbrook | if (sig)
|
2246 | e6e5906b | pbrook | { |
2247 | e6e5906b | pbrook | info.si_signo = sig; |
2248 | e6e5906b | pbrook | info.si_errno = 0;
|
2249 | e6e5906b | pbrook | info.si_code = TARGET_TRAP_BRKPT; |
2250 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2251 | e6e5906b | pbrook | } |
2252 | e6e5906b | pbrook | } |
2253 | e6e5906b | pbrook | break;
|
2254 | e6e5906b | pbrook | default:
|
2255 | 5fafdf24 | ths | fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
2256 | e6e5906b | pbrook | trapnr); |
2257 | e6e5906b | pbrook | cpu_dump_state(env, stderr, fprintf, 0);
|
2258 | e6e5906b | pbrook | abort(); |
2259 | e6e5906b | pbrook | } |
2260 | e6e5906b | pbrook | process_pending_signals(env); |
2261 | e6e5906b | pbrook | } |
2262 | e6e5906b | pbrook | } |
2263 | e6e5906b | pbrook | #endif /* TARGET_M68K */ |
2264 | e6e5906b | pbrook | |
2265 | 7a3148a9 | j_mayer | #ifdef TARGET_ALPHA
|
2266 | 7a3148a9 | j_mayer | void cpu_loop (CPUState *env)
|
2267 | 7a3148a9 | j_mayer | { |
2268 | e96efcfc | j_mayer | int trapnr;
|
2269 | c227f099 | Anthony Liguori | target_siginfo_t info; |
2270 | 3b46e624 | ths | |
2271 | 7a3148a9 | j_mayer | while (1) { |
2272 | 7a3148a9 | j_mayer | trapnr = cpu_alpha_exec (env); |
2273 | 3b46e624 | ths | |
2274 | 7a3148a9 | j_mayer | switch (trapnr) {
|
2275 | 7a3148a9 | j_mayer | case EXCP_RESET:
|
2276 | 7a3148a9 | j_mayer | fprintf(stderr, "Reset requested. Exit\n");
|
2277 | 7a3148a9 | j_mayer | exit(1);
|
2278 | 7a3148a9 | j_mayer | break;
|
2279 | 7a3148a9 | j_mayer | case EXCP_MCHK:
|
2280 | 7a3148a9 | j_mayer | fprintf(stderr, "Machine check exception. Exit\n");
|
2281 | 7a3148a9 | j_mayer | exit(1);
|
2282 | 7a3148a9 | j_mayer | break;
|
2283 | 7a3148a9 | j_mayer | case EXCP_ARITH:
|
2284 | 7a3148a9 | j_mayer | fprintf(stderr, "Arithmetic trap.\n");
|
2285 | 7a3148a9 | j_mayer | exit(1);
|
2286 | 7a3148a9 | j_mayer | break;
|
2287 | 7a3148a9 | j_mayer | case EXCP_HW_INTERRUPT:
|
2288 | 5fafdf24 | ths | fprintf(stderr, "External interrupt. Exit\n");
|
2289 | 7a3148a9 | j_mayer | exit(1);
|
2290 | 7a3148a9 | j_mayer | break;
|
2291 | 7a3148a9 | j_mayer | case EXCP_DFAULT:
|
2292 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU data fault\n");
|
2293 | 7a3148a9 | j_mayer | exit(1);
|
2294 | 7a3148a9 | j_mayer | break;
|
2295 | 7a3148a9 | j_mayer | case EXCP_DTB_MISS_PAL:
|
2296 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU data TLB miss in PALcode\n");
|
2297 | 7a3148a9 | j_mayer | exit(1);
|
2298 | 7a3148a9 | j_mayer | break;
|
2299 | 7a3148a9 | j_mayer | case EXCP_ITB_MISS:
|
2300 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU instruction TLB miss\n");
|
2301 | 7a3148a9 | j_mayer | exit(1);
|
2302 | 7a3148a9 | j_mayer | break;
|
2303 | 7a3148a9 | j_mayer | case EXCP_ITB_ACV:
|
2304 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU instruction access violation\n");
|
2305 | 7a3148a9 | j_mayer | exit(1);
|
2306 | 7a3148a9 | j_mayer | break;
|
2307 | 7a3148a9 | j_mayer | case EXCP_DTB_MISS_NATIVE:
|
2308 | 7a3148a9 | j_mayer | fprintf(stderr, "MMU data TLB miss\n");
|
2309 | 7a3148a9 | j_mayer | exit(1);
|
2310 | 7a3148a9 | j_mayer | break;
|
2311 | 7a3148a9 | j_mayer | case EXCP_UNALIGN:
|
2312 | 7a3148a9 | j_mayer | fprintf(stderr, "Unaligned access\n");
|
2313 | 7a3148a9 | j_mayer | exit(1);
|
2314 | 7a3148a9 | j_mayer | break;
|
2315 | 7a3148a9 | j_mayer | case EXCP_OPCDEC:
|
2316 | 7a3148a9 | j_mayer | fprintf(stderr, "Invalid instruction\n");
|
2317 | 7a3148a9 | j_mayer | exit(1);
|
2318 | 7a3148a9 | j_mayer | break;
|
2319 | 7a3148a9 | j_mayer | case EXCP_FEN:
|
2320 | 7a3148a9 | j_mayer | fprintf(stderr, "Floating-point not allowed\n");
|
2321 | 7a3148a9 | j_mayer | exit(1);
|
2322 | 7a3148a9 | j_mayer | break;
|
2323 | 7a3148a9 | j_mayer | case EXCP_CALL_PAL ... (EXCP_CALL_PALP - 1): |
2324 | 7a3148a9 | j_mayer | call_pal(env, (trapnr >> 6) | 0x80); |
2325 | 7a3148a9 | j_mayer | break;
|
2326 | 7a3148a9 | j_mayer | case EXCP_CALL_PALP ... (EXCP_CALL_PALE - 1): |
2327 | 7f75ffd3 | blueswir1 | fprintf(stderr, "Privileged call to PALcode\n");
|
2328 | 7a3148a9 | j_mayer | exit(1);
|
2329 | 7a3148a9 | j_mayer | break;
|
2330 | 7a3148a9 | j_mayer | case EXCP_DEBUG:
|
2331 | 7a3148a9 | j_mayer | { |
2332 | 7a3148a9 | j_mayer | int sig;
|
2333 | 7a3148a9 | j_mayer | |
2334 | 7a3148a9 | j_mayer | sig = gdb_handlesig (env, TARGET_SIGTRAP); |
2335 | 7a3148a9 | j_mayer | if (sig)
|
2336 | 7a3148a9 | j_mayer | { |
2337 | 7a3148a9 | j_mayer | info.si_signo = sig; |
2338 | 7a3148a9 | j_mayer | info.si_errno = 0;
|
2339 | 7a3148a9 | j_mayer | info.si_code = TARGET_TRAP_BRKPT; |
2340 | 624f7979 | pbrook | queue_signal(env, info.si_signo, &info); |
2341 | 7a3148a9 | j_mayer | } |
2342 | 7a3148a9 | j_mayer | } |
2343 | 7a3148a9 | j_mayer | break;
|
2344 | 7a3148a9 | j_mayer | default:
|
2345 | 7a3148a9 | j_mayer | printf ("Unhandled trap: 0x%x\n", trapnr);
|
2346 | 7a3148a9 | j_mayer | cpu_dump_state(env, stderr, fprintf, 0);
|
2347 | 7a3148a9 | j_mayer | exit (1);
|
2348 | 7a3148a9 | j_mayer | } |
2349 | 7a3148a9 | j_mayer | process_pending_signals (env); |
2350 | 7a3148a9 | j_mayer | } |
2351 | 7a3148a9 | j_mayer | } |
2352 | 7a3148a9 | j_mayer | #endif /* TARGET_ALPHA */ |
2353 | 7a3148a9 | j_mayer | |
2354 | 8fcd3692 | blueswir1 | static void usage(void) |
2355 | 31e31b8a | bellard | { |
2356 | 4a19f1ec | pbrook | printf("qemu-" TARGET_ARCH " version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" |
2357 | 68d0f70e | bellard | "usage: qemu-" TARGET_ARCH " [options] program [arguments...]\n" |
2358 | b346ff46 | bellard | "Linux CPU emulator (compiled for %s emulation)\n"
|
2359 | d691f669 | bellard | "\n"
|
2360 | 68d0f70e | bellard | "Standard options:\n"
|
2361 | b12b6a18 | ths | "-h print this help\n"
|
2362 | b12b6a18 | ths | "-g port wait gdb connection to port\n"
|
2363 | b12b6a18 | ths | "-L path set the elf interpreter prefix (default=%s)\n"
|
2364 | b12b6a18 | ths | "-s size set the stack size in bytes (default=%ld)\n"
|
2365 | b12b6a18 | ths | "-cpu model select CPU (-cpu ? for list)\n"
|
2366 | b12b6a18 | ths | "-drop-ld-preload drop LD_PRELOAD for target process\n"
|
2367 | 04a6dfeb | aurel32 | "-E var=value sets/modifies targets environment variable(s)\n"
|
2368 | 04a6dfeb | aurel32 | "-U var unsets targets environment variable(s)\n"
|
2369 | 7d8cec95 | aurel32 | "-0 argv0 forces target process argv[0] to be argv0\n"
|
2370 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
2371 | 379f6698 | Paul Brook | "-B address set guest_base address to address\n"
|
2372 | 379f6698 | Paul Brook | #endif
|
2373 | 54936004 | bellard | "\n"
|
2374 | 68d0f70e | bellard | "Debug options:\n"
|
2375 | 6f1f31c0 | bellard | "-d options activate log (logfile=%s)\n"
|
2376 | b6741956 | bellard | "-p pagesize set the host page size to 'pagesize'\n"
|
2377 | 1b530a6d | aurel32 | "-singlestep always run in singlestep mode\n"
|
2378 | b01bcae6 | balrog | "-strace log system calls\n"
|
2379 | b01bcae6 | balrog | "\n"
|
2380 | 68d0f70e | bellard | "Environment variables:\n"
|
2381 | b01bcae6 | balrog | "QEMU_STRACE Print system calls and arguments similar to the\n"
|
2382 | b01bcae6 | balrog | " 'strace' program. Enable by setting to any value.\n"
|
2383 | 04a6dfeb | aurel32 | "You can use -E and -U options to set/unset environment variables\n"
|
2384 | 04a6dfeb | aurel32 | "for target process. It is possible to provide several variables\n"
|
2385 | 04a6dfeb | aurel32 | "by repeating the option. For example:\n"
|
2386 | 04a6dfeb | aurel32 | " -E var1=val2 -E var2=val2 -U LD_PRELOAD -U LD_DEBUG\n"
|
2387 | 04a6dfeb | aurel32 | "Note that if you provide several changes to single variable\n"
|
2388 | 04a6dfeb | aurel32 | "last change will stay in effect.\n"
|
2389 | b01bcae6 | balrog | , |
2390 | b346ff46 | bellard | TARGET_ARCH, |
2391 | 5fafdf24 | ths | interp_prefix, |
2392 | 54936004 | bellard | x86_stack_size, |
2393 | 54936004 | bellard | DEBUG_LOGFILE); |
2394 | 2d18e637 | blueswir1 | exit(1);
|
2395 | 31e31b8a | bellard | } |
2396 | 31e31b8a | bellard | |
2397 | d5975363 | pbrook | THREAD CPUState *thread_env; |
2398 | 59faf6d6 | bellard | |
2399 | edf8e2af | Mika Westerberg | void task_settid(TaskState *ts)
|
2400 | edf8e2af | Mika Westerberg | { |
2401 | edf8e2af | Mika Westerberg | if (ts->ts_tid == 0) { |
2402 | 2f7bb878 | Juan Quintela | #ifdef CONFIG_USE_NPTL
|
2403 | edf8e2af | Mika Westerberg | ts->ts_tid = (pid_t)syscall(SYS_gettid); |
2404 | edf8e2af | Mika Westerberg | #else
|
2405 | edf8e2af | Mika Westerberg | /* when no threads are used, tid becomes pid */
|
2406 | edf8e2af | Mika Westerberg | ts->ts_tid = getpid(); |
2407 | edf8e2af | Mika Westerberg | #endif
|
2408 | edf8e2af | Mika Westerberg | } |
2409 | edf8e2af | Mika Westerberg | } |
2410 | edf8e2af | Mika Westerberg | |
2411 | edf8e2af | Mika Westerberg | void stop_all_tasks(void) |
2412 | edf8e2af | Mika Westerberg | { |
2413 | edf8e2af | Mika Westerberg | /*
|
2414 | edf8e2af | Mika Westerberg | * We trust that when using NPTL, start_exclusive()
|
2415 | edf8e2af | Mika Westerberg | * handles thread stopping correctly.
|
2416 | edf8e2af | Mika Westerberg | */
|
2417 | edf8e2af | Mika Westerberg | start_exclusive(); |
2418 | edf8e2af | Mika Westerberg | } |
2419 | edf8e2af | Mika Westerberg | |
2420 | c3a92833 | pbrook | /* Assumes contents are already zeroed. */
|
2421 | 624f7979 | pbrook | void init_task_state(TaskState *ts)
|
2422 | 624f7979 | pbrook | { |
2423 | 624f7979 | pbrook | int i;
|
2424 | 624f7979 | pbrook | |
2425 | 624f7979 | pbrook | ts->used = 1;
|
2426 | 624f7979 | pbrook | ts->first_free = ts->sigqueue_table; |
2427 | 624f7979 | pbrook | for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) { |
2428 | 624f7979 | pbrook | ts->sigqueue_table[i].next = &ts->sigqueue_table[i + 1];
|
2429 | 624f7979 | pbrook | } |
2430 | 624f7979 | pbrook | ts->sigqueue_table[i].next = NULL;
|
2431 | 624f7979 | pbrook | } |
2432 | 624f7979 | pbrook | |
2433 | 902b3d5c | malc | int main(int argc, char **argv, char **envp) |
2434 | 31e31b8a | bellard | { |
2435 | 31e31b8a | bellard | const char *filename; |
2436 | b1f9be31 | j_mayer | const char *cpu_model; |
2437 | 01ffc75b | bellard | struct target_pt_regs regs1, *regs = ®s1;
|
2438 | 31e31b8a | bellard | struct image_info info1, *info = &info1;
|
2439 | edf8e2af | Mika Westerberg | struct linux_binprm bprm;
|
2440 | 851e67a1 | bellard | TaskState ts1, *ts = &ts1; |
2441 | b346ff46 | bellard | CPUState *env; |
2442 | 586314f2 | bellard | int optind;
|
2443 | d691f669 | bellard | const char *r; |
2444 | 74c33bed | bellard | int gdbstub_port = 0; |
2445 | 04a6dfeb | aurel32 | char **target_environ, **wrk;
|
2446 | 7d8cec95 | aurel32 | char **target_argv;
|
2447 | 7d8cec95 | aurel32 | int target_argc;
|
2448 | 04a6dfeb | aurel32 | envlist_t *envlist = NULL;
|
2449 | 7d8cec95 | aurel32 | const char *argv0 = NULL; |
2450 | 7d8cec95 | aurel32 | int i;
|
2451 | fd4d81dd | Arnaud Patard | int ret;
|
2452 | b12b6a18 | ths | |
2453 | 31e31b8a | bellard | if (argc <= 1) |
2454 | 44de1b33 | pbrook | usage(); |
2455 | f801f97e | bellard | |
2456 | 902b3d5c | malc | qemu_cache_utils_init(envp); |
2457 | 902b3d5c | malc | |
2458 | cc38b844 | bellard | /* init debug */
|
2459 | cc38b844 | bellard | cpu_set_log_filename(DEBUG_LOGFILE); |
2460 | cc38b844 | bellard | |
2461 | 04a6dfeb | aurel32 | if ((envlist = envlist_create()) == NULL) { |
2462 | 04a6dfeb | aurel32 | (void) fprintf(stderr, "Unable to allocate envlist\n"); |
2463 | 04a6dfeb | aurel32 | exit(1);
|
2464 | 04a6dfeb | aurel32 | } |
2465 | 04a6dfeb | aurel32 | |
2466 | 04a6dfeb | aurel32 | /* add current environment into the list */
|
2467 | 04a6dfeb | aurel32 | for (wrk = environ; *wrk != NULL; wrk++) { |
2468 | 04a6dfeb | aurel32 | (void) envlist_setenv(envlist, *wrk);
|
2469 | 04a6dfeb | aurel32 | } |
2470 | 04a6dfeb | aurel32 | |
2471 | b1f9be31 | j_mayer | cpu_model = NULL;
|
2472 | 586314f2 | bellard | optind = 1;
|
2473 | d691f669 | bellard | for(;;) {
|
2474 | d691f669 | bellard | if (optind >= argc)
|
2475 | d691f669 | bellard | break;
|
2476 | d691f669 | bellard | r = argv[optind]; |
2477 | d691f669 | bellard | if (r[0] != '-') |
2478 | d691f669 | bellard | break;
|
2479 | 586314f2 | bellard | optind++; |
2480 | d691f669 | bellard | r++; |
2481 | d691f669 | bellard | if (!strcmp(r, "-")) { |
2482 | d691f669 | bellard | break;
|
2483 | d691f669 | bellard | } else if (!strcmp(r, "d")) { |
2484 | e19e89a5 | bellard | int mask;
|
2485 | c7cd6a37 | blueswir1 | const CPULogItem *item;
|
2486 | 6f1f31c0 | bellard | |
2487 | 6f1f31c0 | bellard | if (optind >= argc)
|
2488 | 6f1f31c0 | bellard | break;
|
2489 | 3b46e624 | ths | |
2490 | 6f1f31c0 | bellard | r = argv[optind++]; |
2491 | 6f1f31c0 | bellard | mask = cpu_str_to_log_mask(r); |
2492 | e19e89a5 | bellard | if (!mask) {
|
2493 | e19e89a5 | bellard | printf("Log items (comma separated):\n");
|
2494 | e19e89a5 | bellard | for(item = cpu_log_items; item->mask != 0; item++) { |
2495 | e19e89a5 | bellard | printf("%-10s %s\n", item->name, item->help);
|
2496 | e19e89a5 | bellard | } |
2497 | e19e89a5 | bellard | exit(1);
|
2498 | e19e89a5 | bellard | } |
2499 | e19e89a5 | bellard | cpu_set_log(mask); |
2500 | 04a6dfeb | aurel32 | } else if (!strcmp(r, "E")) { |
2501 | 04a6dfeb | aurel32 | r = argv[optind++]; |
2502 | 04a6dfeb | aurel32 | if (envlist_setenv(envlist, r) != 0) |
2503 | 04a6dfeb | aurel32 | usage(); |
2504 | 04a6dfeb | aurel32 | } else if (!strcmp(r, "U")) { |
2505 | 04a6dfeb | aurel32 | r = argv[optind++]; |
2506 | 04a6dfeb | aurel32 | if (envlist_unsetenv(envlist, r) != 0) |
2507 | 04a6dfeb | aurel32 | usage(); |
2508 | 7d8cec95 | aurel32 | } else if (!strcmp(r, "0")) { |
2509 | 7d8cec95 | aurel32 | r = argv[optind++]; |
2510 | 7d8cec95 | aurel32 | argv0 = r; |
2511 | d691f669 | bellard | } else if (!strcmp(r, "s")) { |
2512 | 491150db | aurel32 | if (optind >= argc)
|
2513 | 491150db | aurel32 | break;
|
2514 | d691f669 | bellard | r = argv[optind++]; |
2515 | d691f669 | bellard | x86_stack_size = strtol(r, (char **)&r, 0); |
2516 | d691f669 | bellard | if (x86_stack_size <= 0) |
2517 | 44de1b33 | pbrook | usage(); |
2518 | d691f669 | bellard | if (*r == 'M') |
2519 | d691f669 | bellard | x86_stack_size *= 1024 * 1024; |
2520 | d691f669 | bellard | else if (*r == 'k' || *r == 'K') |
2521 | d691f669 | bellard | x86_stack_size *= 1024;
|
2522 | d691f669 | bellard | } else if (!strcmp(r, "L")) { |
2523 | d691f669 | bellard | interp_prefix = argv[optind++]; |
2524 | 54936004 | bellard | } else if (!strcmp(r, "p")) { |
2525 | 491150db | aurel32 | if (optind >= argc)
|
2526 | 491150db | aurel32 | break;
|
2527 | 83fb7adf | bellard | qemu_host_page_size = atoi(argv[optind++]); |
2528 | 83fb7adf | bellard | if (qemu_host_page_size == 0 || |
2529 | 83fb7adf | bellard | (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { |
2530 | 54936004 | bellard | fprintf(stderr, "page size must be a power of two\n");
|
2531 | 54936004 | bellard | exit(1);
|
2532 | 54936004 | bellard | } |
2533 | 1fddef4b | bellard | } else if (!strcmp(r, "g")) { |
2534 | 491150db | aurel32 | if (optind >= argc)
|
2535 | 491150db | aurel32 | break;
|
2536 | 74c33bed | bellard | gdbstub_port = atoi(argv[optind++]); |
2537 | c5937220 | pbrook | } else if (!strcmp(r, "r")) { |
2538 | c5937220 | pbrook | qemu_uname_release = argv[optind++]; |
2539 | b1f9be31 | j_mayer | } else if (!strcmp(r, "cpu")) { |
2540 | b1f9be31 | j_mayer | cpu_model = argv[optind++]; |
2541 | 491150db | aurel32 | if (cpu_model == NULL || strcmp(cpu_model, "?") == 0) { |
2542 | c732abe2 | j_mayer | /* XXX: implement xxx_cpu_list for targets that still miss it */
|
2543 | c732abe2 | j_mayer | #if defined(cpu_list)
|
2544 | c732abe2 | j_mayer | cpu_list(stdout, &fprintf); |
2545 | b1f9be31 | j_mayer | #endif
|
2546 | 2d18e637 | blueswir1 | exit(1);
|
2547 | b1f9be31 | j_mayer | } |
2548 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
2549 | 379f6698 | Paul Brook | } else if (!strcmp(r, "B")) { |
2550 | 379f6698 | Paul Brook | guest_base = strtol(argv[optind++], NULL, 0); |
2551 | 379f6698 | Paul Brook | have_guest_base = 1;
|
2552 | 379f6698 | Paul Brook | #endif
|
2553 | b12b6a18 | ths | } else if (!strcmp(r, "drop-ld-preload")) { |
2554 | 04a6dfeb | aurel32 | (void) envlist_unsetenv(envlist, "LD_PRELOAD"); |
2555 | 1b530a6d | aurel32 | } else if (!strcmp(r, "singlestep")) { |
2556 | 1b530a6d | aurel32 | singlestep = 1;
|
2557 | b6741956 | bellard | } else if (!strcmp(r, "strace")) { |
2558 | b6741956 | bellard | do_strace = 1;
|
2559 | 5fafdf24 | ths | } else
|
2560 | c6981055 | bellard | { |
2561 | d691f669 | bellard | usage(); |
2562 | d691f669 | bellard | } |
2563 | 586314f2 | bellard | } |
2564 | d691f669 | bellard | if (optind >= argc)
|
2565 | d691f669 | bellard | usage(); |
2566 | 586314f2 | bellard | filename = argv[optind]; |
2567 | d088d664 | aurel32 | exec_path = argv[optind]; |
2568 | 586314f2 | bellard | |
2569 | 31e31b8a | bellard | /* Zero out regs */
|
2570 | 01ffc75b | bellard | memset(regs, 0, sizeof(struct target_pt_regs)); |
2571 | 31e31b8a | bellard | |
2572 | 31e31b8a | bellard | /* Zero out image_info */
|
2573 | 31e31b8a | bellard | memset(info, 0, sizeof(struct image_info)); |
2574 | 31e31b8a | bellard | |
2575 | edf8e2af | Mika Westerberg | memset(&bprm, 0, sizeof (bprm)); |
2576 | edf8e2af | Mika Westerberg | |
2577 | 74cd30b8 | bellard | /* Scan interp_prefix dir for replacement files. */
|
2578 | 74cd30b8 | bellard | init_paths(interp_prefix); |
2579 | 74cd30b8 | bellard | |
2580 | 46027c07 | bellard | if (cpu_model == NULL) { |
2581 | aaed909a | bellard | #if defined(TARGET_I386)
|
2582 | 46027c07 | bellard | #ifdef TARGET_X86_64
|
2583 | 46027c07 | bellard | cpu_model = "qemu64";
|
2584 | 46027c07 | bellard | #else
|
2585 | 46027c07 | bellard | cpu_model = "qemu32";
|
2586 | 46027c07 | bellard | #endif
|
2587 | aaed909a | bellard | #elif defined(TARGET_ARM)
|
2588 | 088ab16c | pbrook | cpu_model = "any";
|
2589 | aaed909a | bellard | #elif defined(TARGET_M68K)
|
2590 | aaed909a | bellard | cpu_model = "any";
|
2591 | aaed909a | bellard | #elif defined(TARGET_SPARC)
|
2592 | aaed909a | bellard | #ifdef TARGET_SPARC64
|
2593 | aaed909a | bellard | cpu_model = "TI UltraSparc II";
|
2594 | aaed909a | bellard | #else
|
2595 | aaed909a | bellard | cpu_model = "Fujitsu MB86904";
|
2596 | 46027c07 | bellard | #endif
|
2597 | aaed909a | bellard | #elif defined(TARGET_MIPS)
|
2598 | aaed909a | bellard | #if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
|
2599 | aaed909a | bellard | cpu_model = "20Kc";
|
2600 | aaed909a | bellard | #else
|
2601 | aaed909a | bellard | cpu_model = "24Kf";
|
2602 | aaed909a | bellard | #endif
|
2603 | aaed909a | bellard | #elif defined(TARGET_PPC)
|
2604 | 7ded4f52 | bellard | #ifdef TARGET_PPC64
|
2605 | 7ded4f52 | bellard | cpu_model = "970";
|
2606 | 7ded4f52 | bellard | #else
|
2607 | aaed909a | bellard | cpu_model = "750";
|
2608 | 7ded4f52 | bellard | #endif
|
2609 | aaed909a | bellard | #else
|
2610 | aaed909a | bellard | cpu_model = "any";
|
2611 | aaed909a | bellard | #endif
|
2612 | aaed909a | bellard | } |
2613 | 26a5f13b | bellard | cpu_exec_init_all(0);
|
2614 | 83fb7adf | bellard | /* NOTE: we need to init the CPU at this stage to get
|
2615 | 83fb7adf | bellard | qemu_host_page_size */
|
2616 | aaed909a | bellard | env = cpu_init(cpu_model); |
2617 | aaed909a | bellard | if (!env) {
|
2618 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
2619 | aaed909a | bellard | exit(1);
|
2620 | aaed909a | bellard | } |
2621 | d5975363 | pbrook | thread_env = env; |
2622 | 3b46e624 | ths | |
2623 | b6741956 | bellard | if (getenv("QEMU_STRACE")) { |
2624 | b6741956 | bellard | do_strace = 1;
|
2625 | b92c47c1 | ths | } |
2626 | b92c47c1 | ths | |
2627 | 04a6dfeb | aurel32 | target_environ = envlist_to_environ(envlist, NULL);
|
2628 | 04a6dfeb | aurel32 | envlist_free(envlist); |
2629 | b12b6a18 | ths | |
2630 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
2631 | 379f6698 | Paul Brook | /*
|
2632 | 379f6698 | Paul Brook | * Now that page sizes are configured in cpu_init() we can do
|
2633 | 379f6698 | Paul Brook | * proper page alignment for guest_base.
|
2634 | 379f6698 | Paul Brook | */
|
2635 | 379f6698 | Paul Brook | guest_base = HOST_PAGE_ALIGN(guest_base); |
2636 | 379f6698 | Paul Brook | |
2637 | 379f6698 | Paul Brook | /*
|
2638 | 379f6698 | Paul Brook | * Read in mmap_min_addr kernel parameter. This value is used
|
2639 | 379f6698 | Paul Brook | * When loading the ELF image to determine whether guest_base
|
2640 | 379f6698 | Paul Brook | * is needed.
|
2641 | 379f6698 | Paul Brook | *
|
2642 | 379f6698 | Paul Brook | * When user has explicitly set the quest base, we skip this
|
2643 | 379f6698 | Paul Brook | * test.
|
2644 | 379f6698 | Paul Brook | */
|
2645 | 379f6698 | Paul Brook | if (!have_guest_base) {
|
2646 | 379f6698 | Paul Brook | FILE *fp; |
2647 | 379f6698 | Paul Brook | |
2648 | 379f6698 | Paul Brook | if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) { |
2649 | 379f6698 | Paul Brook | unsigned long tmp; |
2650 | 379f6698 | Paul Brook | if (fscanf(fp, "%lu", &tmp) == 1) { |
2651 | 379f6698 | Paul Brook | mmap_min_addr = tmp; |
2652 | 379f6698 | Paul Brook | qemu_log("host mmap_min_addr=0x%lx\n", mmap_min_addr);
|
2653 | 379f6698 | Paul Brook | } |
2654 | 379f6698 | Paul Brook | fclose(fp); |
2655 | 379f6698 | Paul Brook | } |
2656 | 379f6698 | Paul Brook | } |
2657 | 379f6698 | Paul Brook | #endif /* CONFIG_USE_GUEST_BASE */ |
2658 | 379f6698 | Paul Brook | |
2659 | 7d8cec95 | aurel32 | /*
|
2660 | 7d8cec95 | aurel32 | * Prepare copy of argv vector for target.
|
2661 | 7d8cec95 | aurel32 | */
|
2662 | 7d8cec95 | aurel32 | target_argc = argc - optind; |
2663 | 7d8cec95 | aurel32 | target_argv = calloc(target_argc + 1, sizeof (char *)); |
2664 | 7d8cec95 | aurel32 | if (target_argv == NULL) { |
2665 | 7d8cec95 | aurel32 | (void) fprintf(stderr, "Unable to allocate memory for target_argv\n"); |
2666 | 7d8cec95 | aurel32 | exit(1);
|
2667 | 7d8cec95 | aurel32 | } |
2668 | 7d8cec95 | aurel32 | |
2669 | 7d8cec95 | aurel32 | /*
|
2670 | 7d8cec95 | aurel32 | * If argv0 is specified (using '-0' switch) we replace
|
2671 | 7d8cec95 | aurel32 | * argv[0] pointer with the given one.
|
2672 | 7d8cec95 | aurel32 | */
|
2673 | 7d8cec95 | aurel32 | i = 0;
|
2674 | 7d8cec95 | aurel32 | if (argv0 != NULL) { |
2675 | 7d8cec95 | aurel32 | target_argv[i++] = strdup(argv0); |
2676 | 7d8cec95 | aurel32 | } |
2677 | 7d8cec95 | aurel32 | for (; i < target_argc; i++) {
|
2678 | 7d8cec95 | aurel32 | target_argv[i] = strdup(argv[optind + i]); |
2679 | 7d8cec95 | aurel32 | } |
2680 | 7d8cec95 | aurel32 | target_argv[target_argc] = NULL;
|
2681 | 7d8cec95 | aurel32 | |
2682 | edf8e2af | Mika Westerberg | memset(ts, 0, sizeof(TaskState)); |
2683 | edf8e2af | Mika Westerberg | init_task_state(ts); |
2684 | edf8e2af | Mika Westerberg | /* build Task State */
|
2685 | edf8e2af | Mika Westerberg | ts->info = info; |
2686 | edf8e2af | Mika Westerberg | ts->bprm = &bprm; |
2687 | edf8e2af | Mika Westerberg | env->opaque = ts; |
2688 | edf8e2af | Mika Westerberg | task_settid(ts); |
2689 | edf8e2af | Mika Westerberg | |
2690 | fd4d81dd | Arnaud Patard | ret = loader_exec(filename, target_argv, target_environ, regs, |
2691 | fd4d81dd | Arnaud Patard | info, &bprm); |
2692 | fd4d81dd | Arnaud Patard | if (ret != 0) { |
2693 | fd4d81dd | Arnaud Patard | printf("Error %d while loading %s\n", ret, filename);
|
2694 | b12b6a18 | ths | _exit(1);
|
2695 | b12b6a18 | ths | } |
2696 | b12b6a18 | ths | |
2697 | 7d8cec95 | aurel32 | for (i = 0; i < target_argc; i++) { |
2698 | 7d8cec95 | aurel32 | free(target_argv[i]); |
2699 | 7d8cec95 | aurel32 | } |
2700 | 7d8cec95 | aurel32 | free(target_argv); |
2701 | 7d8cec95 | aurel32 | |
2702 | b12b6a18 | ths | for (wrk = target_environ; *wrk; wrk++) {
|
2703 | b12b6a18 | ths | free(*wrk); |
2704 | 31e31b8a | bellard | } |
2705 | 3b46e624 | ths | |
2706 | b12b6a18 | ths | free(target_environ); |
2707 | b12b6a18 | ths | |
2708 | 2e77eac6 | blueswir1 | if (qemu_log_enabled()) {
|
2709 | 379f6698 | Paul Brook | #if defined(CONFIG_USE_GUEST_BASE)
|
2710 | 379f6698 | Paul Brook | qemu_log("guest_base 0x%lx\n", guest_base);
|
2711 | 379f6698 | Paul Brook | #endif
|
2712 | 2e77eac6 | blueswir1 | log_page_dump(); |
2713 | 2e77eac6 | blueswir1 | |
2714 | 2e77eac6 | blueswir1 | qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); |
2715 | 2e77eac6 | blueswir1 | qemu_log("end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); |
2716 | 2e77eac6 | blueswir1 | qemu_log("start_code 0x" TARGET_ABI_FMT_lx "\n", |
2717 | 2e77eac6 | blueswir1 | info->start_code); |
2718 | 2e77eac6 | blueswir1 | qemu_log("start_data 0x" TARGET_ABI_FMT_lx "\n", |
2719 | 2e77eac6 | blueswir1 | info->start_data); |
2720 | 2e77eac6 | blueswir1 | qemu_log("end_data 0x" TARGET_ABI_FMT_lx "\n", info->end_data); |
2721 | 2e77eac6 | blueswir1 | qemu_log("start_stack 0x" TARGET_ABI_FMT_lx "\n", |
2722 | 2e77eac6 | blueswir1 | info->start_stack); |
2723 | 2e77eac6 | blueswir1 | qemu_log("brk 0x" TARGET_ABI_FMT_lx "\n", info->brk); |
2724 | 2e77eac6 | blueswir1 | qemu_log("entry 0x" TARGET_ABI_FMT_lx "\n", info->entry); |
2725 | 2e77eac6 | blueswir1 | } |
2726 | 31e31b8a | bellard | |
2727 | 53a5960a | pbrook | target_set_brk(info->brk); |
2728 | 31e31b8a | bellard | syscall_init(); |
2729 | 66fb9763 | bellard | signal_init(); |
2730 | 31e31b8a | bellard | |
2731 | b346ff46 | bellard | #if defined(TARGET_I386)
|
2732 | 2e255c6b | bellard | cpu_x86_set_cpl(env, 3);
|
2733 | 2e255c6b | bellard | |
2734 | 3802ce26 | bellard | env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
|
2735 | 1bde465e | bellard | env->hflags |= HF_PE_MASK; |
2736 | 1bde465e | bellard | if (env->cpuid_features & CPUID_SSE) {
|
2737 | 1bde465e | bellard | env->cr[4] |= CR4_OSFXSR_MASK;
|
2738 | 1bde465e | bellard | env->hflags |= HF_OSFXSR_MASK; |
2739 | 1bde465e | bellard | } |
2740 | d2fd1af7 | bellard | #ifndef TARGET_ABI32
|
2741 | 4dbc422b | bellard | /* enable 64 bit mode if possible */
|
2742 | 4dbc422b | bellard | if (!(env->cpuid_ext2_features & CPUID_EXT2_LM)) {
|
2743 | 4dbc422b | bellard | fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n");
|
2744 | 4dbc422b | bellard | exit(1);
|
2745 | 4dbc422b | bellard | } |
2746 | d2fd1af7 | bellard | env->cr[4] |= CR4_PAE_MASK;
|
2747 | 4dbc422b | bellard | env->efer |= MSR_EFER_LMA | MSR_EFER_LME; |
2748 | d2fd1af7 | bellard | env->hflags |= HF_LMA_MASK; |
2749 | d2fd1af7 | bellard | #endif
|
2750 | 1bde465e | bellard | |
2751 | 415e561f | bellard | /* flags setup : we activate the IRQs by default as in user mode */
|
2752 | 415e561f | bellard | env->eflags |= IF_MASK; |
2753 | 3b46e624 | ths | |
2754 | 6dbad63e | bellard | /* linux register setup */
|
2755 | d2fd1af7 | bellard | #ifndef TARGET_ABI32
|
2756 | 84409ddb | j_mayer | env->regs[R_EAX] = regs->rax; |
2757 | 84409ddb | j_mayer | env->regs[R_EBX] = regs->rbx; |
2758 | 84409ddb | j_mayer | env->regs[R_ECX] = regs->rcx; |
2759 | 84409ddb | j_mayer | env->regs[R_EDX] = regs->rdx; |
2760 | 84409ddb | j_mayer | env->regs[R_ESI] = regs->rsi; |
2761 | 84409ddb | j_mayer | env->regs[R_EDI] = regs->rdi; |
2762 | 84409ddb | j_mayer | env->regs[R_EBP] = regs->rbp; |
2763 | 84409ddb | j_mayer | env->regs[R_ESP] = regs->rsp; |
2764 | 84409ddb | j_mayer | env->eip = regs->rip; |
2765 | 84409ddb | j_mayer | #else
|
2766 | 0ecfa993 | bellard | env->regs[R_EAX] = regs->eax; |
2767 | 0ecfa993 | bellard | env->regs[R_EBX] = regs->ebx; |
2768 | 0ecfa993 | bellard | env->regs[R_ECX] = regs->ecx; |
2769 | 0ecfa993 | bellard | env->regs[R_EDX] = regs->edx; |
2770 | 0ecfa993 | bellard | env->regs[R_ESI] = regs->esi; |
2771 | 0ecfa993 | bellard | env->regs[R_EDI] = regs->edi; |
2772 | 0ecfa993 | bellard | env->regs[R_EBP] = regs->ebp; |
2773 | 0ecfa993 | bellard | env->regs[R_ESP] = regs->esp; |
2774 | dab2ed99 | bellard | env->eip = regs->eip; |
2775 | 84409ddb | j_mayer | #endif
|
2776 | 31e31b8a | bellard | |
2777 | f4beb510 | bellard | /* linux interrupt setup */
|
2778 | e441570f | balrog | #ifndef TARGET_ABI32
|
2779 | e441570f | balrog | env->idt.limit = 511;
|
2780 | e441570f | balrog | #else
|
2781 | e441570f | balrog | env->idt.limit = 255;
|
2782 | e441570f | balrog | #endif
|
2783 | e441570f | balrog | env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), |
2784 | e441570f | balrog | PROT_READ|PROT_WRITE, |
2785 | e441570f | balrog | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); |
2786 | e441570f | balrog | idt_table = g2h(env->idt.base); |
2787 | f4beb510 | bellard | set_idt(0, 0); |
2788 | f4beb510 | bellard | set_idt(1, 0); |
2789 | f4beb510 | bellard | set_idt(2, 0); |
2790 | f4beb510 | bellard | set_idt(3, 3); |
2791 | f4beb510 | bellard | set_idt(4, 3); |
2792 | ec95da6c | bellard | set_idt(5, 0); |
2793 | f4beb510 | bellard | set_idt(6, 0); |
2794 | f4beb510 | bellard | set_idt(7, 0); |
2795 | f4beb510 | bellard | set_idt(8, 0); |
2796 | f4beb510 | bellard | set_idt(9, 0); |
2797 | f4beb510 | bellard | set_idt(10, 0); |
2798 | f4beb510 | bellard | set_idt(11, 0); |
2799 | f4beb510 | bellard | set_idt(12, 0); |
2800 | f4beb510 | bellard | set_idt(13, 0); |
2801 | f4beb510 | bellard | set_idt(14, 0); |
2802 | f4beb510 | bellard | set_idt(15, 0); |
2803 | f4beb510 | bellard | set_idt(16, 0); |
2804 | f4beb510 | bellard | set_idt(17, 0); |
2805 | f4beb510 | bellard | set_idt(18, 0); |
2806 | f4beb510 | bellard | set_idt(19, 0); |
2807 | f4beb510 | bellard | set_idt(0x80, 3); |
2808 | f4beb510 | bellard | |
2809 | 6dbad63e | bellard | /* linux segment setup */
|
2810 | 8d18e893 | bellard | { |
2811 | 8d18e893 | bellard | uint64_t *gdt_table; |
2812 | e441570f | balrog | env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, |
2813 | e441570f | balrog | PROT_READ|PROT_WRITE, |
2814 | e441570f | balrog | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); |
2815 | 8d18e893 | bellard | env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; |
2816 | e441570f | balrog | gdt_table = g2h(env->gdt.base); |
2817 | d2fd1af7 | bellard | #ifdef TARGET_ABI32
|
2818 | 8d18e893 | bellard | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, |
2819 | 8d18e893 | bellard | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
2820 | 8d18e893 | bellard | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); |
2821 | d2fd1af7 | bellard | #else
|
2822 | d2fd1af7 | bellard | /* 64 bit code segment */
|
2823 | d2fd1af7 | bellard | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, |
2824 | d2fd1af7 | bellard | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
2825 | d2fd1af7 | bellard | DESC_L_MASK | |
2826 | d2fd1af7 | bellard | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); |
2827 | d2fd1af7 | bellard | #endif
|
2828 | 8d18e893 | bellard | write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, |
2829 | 8d18e893 | bellard | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
2830 | 8d18e893 | bellard | (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); |
2831 | 8d18e893 | bellard | } |
2832 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
2833 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
2834 | d2fd1af7 | bellard | #ifdef TARGET_ABI32
|
2835 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
2836 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
2837 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_FS, __USER_DS); |
2838 | 6dbad63e | bellard | cpu_x86_load_seg(env, R_GS, __USER_DS); |
2839 | d6eb40f6 | ths | /* This hack makes Wine work... */
|
2840 | d6eb40f6 | ths | env->segs[R_FS].selector = 0;
|
2841 | d2fd1af7 | bellard | #else
|
2842 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_DS, 0);
|
2843 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_ES, 0);
|
2844 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_FS, 0);
|
2845 | d2fd1af7 | bellard | cpu_x86_load_seg(env, R_GS, 0);
|
2846 | d2fd1af7 | bellard | #endif
|
2847 | b346ff46 | bellard | #elif defined(TARGET_ARM)
|
2848 | b346ff46 | bellard | { |
2849 | b346ff46 | bellard | int i;
|
2850 | b5ff1b31 | bellard | cpsr_write(env, regs->uregs[16], 0xffffffff); |
2851 | b346ff46 | bellard | for(i = 0; i < 16; i++) { |
2852 | b346ff46 | bellard | env->regs[i] = regs->uregs[i]; |
2853 | b346ff46 | bellard | } |
2854 | b346ff46 | bellard | } |
2855 | 93ac68bc | bellard | #elif defined(TARGET_SPARC)
|
2856 | 060366c5 | bellard | { |
2857 | 060366c5 | bellard | int i;
|
2858 | 060366c5 | bellard | env->pc = regs->pc; |
2859 | 060366c5 | bellard | env->npc = regs->npc; |
2860 | 060366c5 | bellard | env->y = regs->y; |
2861 | 060366c5 | bellard | for(i = 0; i < 8; i++) |
2862 | 060366c5 | bellard | env->gregs[i] = regs->u_regs[i]; |
2863 | 060366c5 | bellard | for(i = 0; i < 8; i++) |
2864 | 060366c5 | bellard | env->regwptr[i] = regs->u_regs[i + 8];
|
2865 | 060366c5 | bellard | } |
2866 | 67867308 | bellard | #elif defined(TARGET_PPC)
|
2867 | 67867308 | bellard | { |
2868 | 67867308 | bellard | int i;
|
2869 | 3fc6c082 | bellard | |
2870 | 0411a972 | j_mayer | #if defined(TARGET_PPC64)
|
2871 | 0411a972 | j_mayer | #if defined(TARGET_ABI32)
|
2872 | 0411a972 | j_mayer | env->msr &= ~((target_ulong)1 << MSR_SF);
|
2873 | e85e7c6e | j_mayer | #else
|
2874 | 0411a972 | j_mayer | env->msr |= (target_ulong)1 << MSR_SF;
|
2875 | 0411a972 | j_mayer | #endif
|
2876 | 84409ddb | j_mayer | #endif
|
2877 | 67867308 | bellard | env->nip = regs->nip; |
2878 | 67867308 | bellard | for(i = 0; i < 32; i++) { |
2879 | 67867308 | bellard | env->gpr[i] = regs->gpr[i]; |
2880 | 67867308 | bellard | } |
2881 | 67867308 | bellard | } |
2882 | e6e5906b | pbrook | #elif defined(TARGET_M68K)
|
2883 | e6e5906b | pbrook | { |
2884 | e6e5906b | pbrook | env->pc = regs->pc; |
2885 | e6e5906b | pbrook | env->dregs[0] = regs->d0;
|
2886 | e6e5906b | pbrook | env->dregs[1] = regs->d1;
|
2887 | e6e5906b | pbrook | env->dregs[2] = regs->d2;
|
2888 | e6e5906b | pbrook | env->dregs[3] = regs->d3;
|
2889 | e6e5906b | pbrook | env->dregs[4] = regs->d4;
|
2890 | e6e5906b | pbrook | env->dregs[5] = regs->d5;
|
2891 | e6e5906b | pbrook | env->dregs[6] = regs->d6;
|
2892 | e6e5906b | pbrook | env->dregs[7] = regs->d7;
|
2893 | e6e5906b | pbrook | env->aregs[0] = regs->a0;
|
2894 | e6e5906b | pbrook | env->aregs[1] = regs->a1;
|
2895 | e6e5906b | pbrook | env->aregs[2] = regs->a2;
|
2896 | e6e5906b | pbrook | env->aregs[3] = regs->a3;
|
2897 | e6e5906b | pbrook | env->aregs[4] = regs->a4;
|
2898 | e6e5906b | pbrook | env->aregs[5] = regs->a5;
|
2899 | e6e5906b | pbrook | env->aregs[6] = regs->a6;
|
2900 | e6e5906b | pbrook | env->aregs[7] = regs->usp;
|
2901 | e6e5906b | pbrook | env->sr = regs->sr; |
2902 | e6e5906b | pbrook | ts->sim_syscalls = 1;
|
2903 | e6e5906b | pbrook | } |
2904 | b779e29e | Edgar E. Iglesias | #elif defined(TARGET_MICROBLAZE)
|
2905 | b779e29e | Edgar E. Iglesias | { |
2906 | b779e29e | Edgar E. Iglesias | env->regs[0] = regs->r0;
|
2907 | b779e29e | Edgar E. Iglesias | env->regs[1] = regs->r1;
|
2908 | b779e29e | Edgar E. Iglesias | env->regs[2] = regs->r2;
|
2909 | b779e29e | Edgar E. Iglesias | env->regs[3] = regs->r3;
|
2910 | b779e29e | Edgar E. Iglesias | env->regs[4] = regs->r4;
|
2911 | b779e29e | Edgar E. Iglesias | env->regs[5] = regs->r5;
|
2912 | b779e29e | Edgar E. Iglesias | env->regs[6] = regs->r6;
|
2913 | b779e29e | Edgar E. Iglesias | env->regs[7] = regs->r7;
|
2914 | b779e29e | Edgar E. Iglesias | env->regs[8] = regs->r8;
|
2915 | b779e29e | Edgar E. Iglesias | env->regs[9] = regs->r9;
|
2916 | b779e29e | Edgar E. Iglesias | env->regs[10] = regs->r10;
|
2917 | b779e29e | Edgar E. Iglesias | env->regs[11] = regs->r11;
|
2918 | b779e29e | Edgar E. Iglesias | env->regs[12] = regs->r12;
|
2919 | b779e29e | Edgar E. Iglesias | env->regs[13] = regs->r13;
|
2920 | b779e29e | Edgar E. Iglesias | env->regs[14] = regs->r14;
|
2921 | b779e29e | Edgar E. Iglesias | env->regs[15] = regs->r15;
|
2922 | b779e29e | Edgar E. Iglesias | env->regs[16] = regs->r16;
|
2923 | b779e29e | Edgar E. Iglesias | env->regs[17] = regs->r17;
|
2924 | b779e29e | Edgar E. Iglesias | env->regs[18] = regs->r18;
|
2925 | b779e29e | Edgar E. Iglesias | env->regs[19] = regs->r19;
|
2926 | b779e29e | Edgar E. Iglesias | env->regs[20] = regs->r20;
|
2927 | b779e29e | Edgar E. Iglesias | env->regs[21] = regs->r21;
|
2928 | b779e29e | Edgar E. Iglesias | env->regs[22] = regs->r22;
|
2929 | b779e29e | Edgar E. Iglesias | env->regs[23] = regs->r23;
|
2930 | b779e29e | Edgar E. Iglesias | env->regs[24] = regs->r24;
|
2931 | b779e29e | Edgar E. Iglesias | env->regs[25] = regs->r25;
|
2932 | b779e29e | Edgar E. Iglesias | env->regs[26] = regs->r26;
|
2933 | b779e29e | Edgar E. Iglesias | env->regs[27] = regs->r27;
|
2934 | b779e29e | Edgar E. Iglesias | env->regs[28] = regs->r28;
|
2935 | b779e29e | Edgar E. Iglesias | env->regs[29] = regs->r29;
|
2936 | b779e29e | Edgar E. Iglesias | env->regs[30] = regs->r30;
|
2937 | b779e29e | Edgar E. Iglesias | env->regs[31] = regs->r31;
|
2938 | b779e29e | Edgar E. Iglesias | env->sregs[SR_PC] = regs->pc; |
2939 | b779e29e | Edgar E. Iglesias | } |
2940 | 048f6b4d | bellard | #elif defined(TARGET_MIPS)
|
2941 | 048f6b4d | bellard | { |
2942 | 048f6b4d | bellard | int i;
|
2943 | 048f6b4d | bellard | |
2944 | 048f6b4d | bellard | for(i = 0; i < 32; i++) { |
2945 | b5dc7732 | ths | env->active_tc.gpr[i] = regs->regs[i]; |
2946 | 048f6b4d | bellard | } |
2947 | b5dc7732 | ths | env->active_tc.PC = regs->cp0_epc; |
2948 | 048f6b4d | bellard | } |
2949 | fdf9b3e8 | bellard | #elif defined(TARGET_SH4)
|
2950 | fdf9b3e8 | bellard | { |
2951 | fdf9b3e8 | bellard | int i;
|
2952 | fdf9b3e8 | bellard | |
2953 | fdf9b3e8 | bellard | for(i = 0; i < 16; i++) { |
2954 | fdf9b3e8 | bellard | env->gregs[i] = regs->regs[i]; |
2955 | fdf9b3e8 | bellard | } |
2956 | fdf9b3e8 | bellard | env->pc = regs->pc; |
2957 | fdf9b3e8 | bellard | } |
2958 | 7a3148a9 | j_mayer | #elif defined(TARGET_ALPHA)
|
2959 | 7a3148a9 | j_mayer | { |
2960 | 7a3148a9 | j_mayer | int i;
|
2961 | 7a3148a9 | j_mayer | |
2962 | 7a3148a9 | j_mayer | for(i = 0; i < 28; i++) { |
2963 | 992f48a0 | blueswir1 | env->ir[i] = ((abi_ulong *)regs)[i]; |
2964 | 7a3148a9 | j_mayer | } |
2965 | 7a3148a9 | j_mayer | env->ipr[IPR_USP] = regs->usp; |
2966 | 7a3148a9 | j_mayer | env->ir[30] = regs->usp;
|
2967 | 7a3148a9 | j_mayer | env->pc = regs->pc; |
2968 | 7a3148a9 | j_mayer | env->unique = regs->unique; |
2969 | 7a3148a9 | j_mayer | } |
2970 | 48733d19 | ths | #elif defined(TARGET_CRIS)
|
2971 | 48733d19 | ths | { |
2972 | 48733d19 | ths | env->regs[0] = regs->r0;
|
2973 | 48733d19 | ths | env->regs[1] = regs->r1;
|
2974 | 48733d19 | ths | env->regs[2] = regs->r2;
|
2975 | 48733d19 | ths | env->regs[3] = regs->r3;
|
2976 | 48733d19 | ths | env->regs[4] = regs->r4;
|
2977 | 48733d19 | ths | env->regs[5] = regs->r5;
|
2978 | 48733d19 | ths | env->regs[6] = regs->r6;
|
2979 | 48733d19 | ths | env->regs[7] = regs->r7;
|
2980 | 48733d19 | ths | env->regs[8] = regs->r8;
|
2981 | 48733d19 | ths | env->regs[9] = regs->r9;
|
2982 | 48733d19 | ths | env->regs[10] = regs->r10;
|
2983 | 48733d19 | ths | env->regs[11] = regs->r11;
|
2984 | 48733d19 | ths | env->regs[12] = regs->r12;
|
2985 | 48733d19 | ths | env->regs[13] = regs->r13;
|
2986 | 48733d19 | ths | env->regs[14] = info->start_stack;
|
2987 | 48733d19 | ths | env->regs[15] = regs->acr;
|
2988 | 48733d19 | ths | env->pc = regs->erp; |
2989 | 48733d19 | ths | } |
2990 | b346ff46 | bellard | #else
|
2991 | b346ff46 | bellard | #error unsupported target CPU
|
2992 | b346ff46 | bellard | #endif
|
2993 | 31e31b8a | bellard | |
2994 | a87295e8 | pbrook | #if defined(TARGET_ARM) || defined(TARGET_M68K)
|
2995 | a87295e8 | pbrook | ts->stack_base = info->start_stack; |
2996 | a87295e8 | pbrook | ts->heap_base = info->brk; |
2997 | a87295e8 | pbrook | /* This will be filled in on the first SYS_HEAPINFO call. */
|
2998 | a87295e8 | pbrook | ts->heap_limit = 0;
|
2999 | a87295e8 | pbrook | #endif
|
3000 | a87295e8 | pbrook | |
3001 | 74c33bed | bellard | if (gdbstub_port) {
|
3002 | 74c33bed | bellard | gdbserver_start (gdbstub_port); |
3003 | 1fddef4b | bellard | gdb_handlesig(env, 0);
|
3004 | 1fddef4b | bellard | } |
3005 | 1b6b029e | bellard | cpu_loop(env); |
3006 | 1b6b029e | bellard | /* never exits */
|
3007 | 31e31b8a | bellard | return 0; |
3008 | 31e31b8a | bellard | } |