Statistics
| Branch: | Revision:

root / linux-user / main.c @ e1833e1f

History | View | Annotate | Download (70.8 kB)

1 31e31b8a bellard
/*
2 93ac68bc bellard
 *  qemu user main
3 5fafdf24 ths
 *
4 31e31b8a bellard
 *  Copyright (c) 2003 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 31e31b8a bellard
 *  along with this program; if not, write to the Free Software
18 31e31b8a bellard
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 31e31b8a bellard
 */
20 31e31b8a bellard
#include <stdlib.h>
21 31e31b8a bellard
#include <stdio.h>
22 31e31b8a bellard
#include <stdarg.h>
23 04369ff2 bellard
#include <string.h>
24 31e31b8a bellard
#include <errno.h>
25 0ecfa993 bellard
#include <unistd.h>
26 31e31b8a bellard
27 3ef693a0 bellard
#include "qemu.h"
28 31e31b8a bellard
29 3ef693a0 bellard
#define DEBUG_LOGFILE "/tmp/qemu.log"
30 586314f2 bellard
31 83fb7adf bellard
#ifdef __APPLE__
32 83fb7adf bellard
#include <crt_externs.h>
33 83fb7adf bellard
# define environ  (*_NSGetEnviron())
34 83fb7adf bellard
#endif
35 83fb7adf bellard
36 74cd30b8 bellard
static const char *interp_prefix = CONFIG_QEMU_PREFIX;
37 c5937220 pbrook
const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
38 586314f2 bellard
39 3a4739d6 bellard
#if defined(__i386__) && !defined(CONFIG_STATIC)
40 f801f97e bellard
/* Force usage of an ELF interpreter even if it is an ELF shared
41 f801f97e bellard
   object ! */
42 f801f97e bellard
const char interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
43 4304763b bellard
#endif
44 74cd30b8 bellard
45 93ac68bc bellard
/* for recent libc, we add these dummy symbols which are not declared
46 74cd30b8 bellard
   when generating a linked object (bug in ld ?) */
47 fbf59244 bellard
#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined(CONFIG_STATIC)
48 c6981055 bellard
long __preinit_array_start[0];
49 c6981055 bellard
long __preinit_array_end[0];
50 74cd30b8 bellard
long __init_array_start[0];
51 74cd30b8 bellard
long __init_array_end[0];
52 74cd30b8 bellard
long __fini_array_start[0];
53 74cd30b8 bellard
long __fini_array_end[0];
54 74cd30b8 bellard
#endif
55 74cd30b8 bellard
56 9de5e440 bellard
/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
57 9de5e440 bellard
   we allocate a bigger stack. Need a better solution, for example
58 9de5e440 bellard
   by remapping the process stack directly at the right place */
59 9de5e440 bellard
unsigned long x86_stack_size = 512 * 1024;
60 31e31b8a bellard
61 31e31b8a bellard
void gemu_log(const char *fmt, ...)
62 31e31b8a bellard
{
63 31e31b8a bellard
    va_list ap;
64 31e31b8a bellard
65 31e31b8a bellard
    va_start(ap, fmt);
66 31e31b8a bellard
    vfprintf(stderr, fmt, ap);
67 31e31b8a bellard
    va_end(ap);
68 31e31b8a bellard
}
69 31e31b8a bellard
70 61190b14 bellard
void cpu_outb(CPUState *env, int addr, int val)
71 367e86e8 bellard
{
72 367e86e8 bellard
    fprintf(stderr, "outb: port=0x%04x, data=%02x\n", addr, val);
73 367e86e8 bellard
}
74 367e86e8 bellard
75 61190b14 bellard
void cpu_outw(CPUState *env, int addr, int val)
76 367e86e8 bellard
{
77 367e86e8 bellard
    fprintf(stderr, "outw: port=0x%04x, data=%04x\n", addr, val);
78 367e86e8 bellard
}
79 367e86e8 bellard
80 61190b14 bellard
void cpu_outl(CPUState *env, int addr, int val)
81 367e86e8 bellard
{
82 367e86e8 bellard
    fprintf(stderr, "outl: port=0x%04x, data=%08x\n", addr, val);
83 367e86e8 bellard
}
84 367e86e8 bellard
85 61190b14 bellard
int cpu_inb(CPUState *env, int addr)
86 367e86e8 bellard
{
87 367e86e8 bellard
    fprintf(stderr, "inb: port=0x%04x\n", addr);
88 367e86e8 bellard
    return 0;
89 367e86e8 bellard
}
90 367e86e8 bellard
91 61190b14 bellard
int cpu_inw(CPUState *env, int addr)
92 367e86e8 bellard
{
93 367e86e8 bellard
    fprintf(stderr, "inw: port=0x%04x\n", addr);
94 367e86e8 bellard
    return 0;
95 367e86e8 bellard
}
96 367e86e8 bellard
97 61190b14 bellard
int cpu_inl(CPUState *env, int addr)
98 367e86e8 bellard
{
99 367e86e8 bellard
    fprintf(stderr, "inl: port=0x%04x\n", addr);
100 367e86e8 bellard
    return 0;
101 367e86e8 bellard
}
102 367e86e8 bellard
103 a541f297 bellard
int cpu_get_pic_interrupt(CPUState *env)
104 92ccca6a bellard
{
105 92ccca6a bellard
    return -1;
106 92ccca6a bellard
}
107 92ccca6a bellard
108 28ab0e2e bellard
/* timers for rdtsc */
109 28ab0e2e bellard
110 1dce7c3c bellard
#if 0
111 28ab0e2e bellard

112 28ab0e2e bellard
static uint64_t emu_time;
113 28ab0e2e bellard

114 28ab0e2e bellard
int64_t cpu_get_real_ticks(void)
115 28ab0e2e bellard
{
116 28ab0e2e bellard
    return emu_time++;
117 28ab0e2e bellard
}
118 28ab0e2e bellard

119 28ab0e2e bellard
#endif
120 28ab0e2e bellard
121 a541f297 bellard
#ifdef TARGET_I386
122 a541f297 bellard
/***********************************************************/
123 a541f297 bellard
/* CPUX86 core interface */
124 a541f297 bellard
125 02a1602e bellard
void cpu_smm_update(CPUState *env)
126 02a1602e bellard
{
127 02a1602e bellard
}
128 02a1602e bellard
129 28ab0e2e bellard
uint64_t cpu_get_tsc(CPUX86State *env)
130 28ab0e2e bellard
{
131 28ab0e2e bellard
    return cpu_get_real_ticks();
132 28ab0e2e bellard
}
133 28ab0e2e bellard
134 5fafdf24 ths
static void write_dt(void *ptr, unsigned long addr, unsigned long limit,
135 f4beb510 bellard
                     int flags)
136 6dbad63e bellard
{
137 f4beb510 bellard
    unsigned int e1, e2;
138 53a5960a pbrook
    uint32_t *p;
139 6dbad63e bellard
    e1 = (addr << 16) | (limit & 0xffff);
140 6dbad63e bellard
    e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000);
141 f4beb510 bellard
    e2 |= flags;
142 53a5960a pbrook
    p = ptr;
143 53a5960a pbrook
    p[0] = tswapl(e1);
144 53a5960a pbrook
    p[1] = tswapl(e2);
145 f4beb510 bellard
}
146 f4beb510 bellard
147 5fafdf24 ths
static void set_gate(void *ptr, unsigned int type, unsigned int dpl,
148 f4beb510 bellard
                     unsigned long addr, unsigned int sel)
149 f4beb510 bellard
{
150 f4beb510 bellard
    unsigned int e1, e2;
151 53a5960a pbrook
    uint32_t *p;
152 f4beb510 bellard
    e1 = (addr & 0xffff) | (sel << 16);
153 f4beb510 bellard
    e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
154 53a5960a pbrook
    p = ptr;
155 53a5960a pbrook
    p[0] = tswapl(e1);
156 53a5960a pbrook
    p[1] = tswapl(e2);
157 6dbad63e bellard
}
158 6dbad63e bellard
159 6dbad63e bellard
uint64_t gdt_table[6];
160 f4beb510 bellard
uint64_t idt_table[256];
161 f4beb510 bellard
162 f4beb510 bellard
/* only dpl matters as we do only user space emulation */
163 f4beb510 bellard
static void set_idt(int n, unsigned int dpl)
164 f4beb510 bellard
{
165 f4beb510 bellard
    set_gate(idt_table + n, 0, dpl, 0, 0);
166 f4beb510 bellard
}
167 31e31b8a bellard
168 89e957e7 bellard
void cpu_loop(CPUX86State *env)
169 1b6b029e bellard
{
170 bc8a22cc bellard
    int trapnr;
171 80a9d035 bellard
    target_ulong pc;
172 9de5e440 bellard
    target_siginfo_t info;
173 851e67a1 bellard
174 1b6b029e bellard
    for(;;) {
175 bc8a22cc bellard
        trapnr = cpu_x86_exec(env);
176 bc8a22cc bellard
        switch(trapnr) {
177 f4beb510 bellard
        case 0x80:
178 f4beb510 bellard
            /* linux syscall */
179 5fafdf24 ths
            env->regs[R_EAX] = do_syscall(env,
180 5fafdf24 ths
                                          env->regs[R_EAX],
181 f4beb510 bellard
                                          env->regs[R_EBX],
182 f4beb510 bellard
                                          env->regs[R_ECX],
183 f4beb510 bellard
                                          env->regs[R_EDX],
184 f4beb510 bellard
                                          env->regs[R_ESI],
185 f4beb510 bellard
                                          env->regs[R_EDI],
186 f4beb510 bellard
                                          env->regs[R_EBP]);
187 f4beb510 bellard
            break;
188 f4beb510 bellard
        case EXCP0B_NOSEG:
189 f4beb510 bellard
        case EXCP0C_STACK:
190 f4beb510 bellard
            info.si_signo = SIGBUS;
191 f4beb510 bellard
            info.si_errno = 0;
192 f4beb510 bellard
            info.si_code = TARGET_SI_KERNEL;
193 f4beb510 bellard
            info._sifields._sigfault._addr = 0;
194 f4beb510 bellard
            queue_signal(info.si_signo, &info);
195 f4beb510 bellard
            break;
196 1b6b029e bellard
        case EXCP0D_GPF:
197 84409ddb j_mayer
#ifndef TARGET_X86_64
198 851e67a1 bellard
            if (env->eflags & VM_MASK) {
199 89e957e7 bellard
                handle_vm86_fault(env);
200 84409ddb j_mayer
            } else
201 84409ddb j_mayer
#endif
202 84409ddb j_mayer
            {
203 f4beb510 bellard
                info.si_signo = SIGSEGV;
204 f4beb510 bellard
                info.si_errno = 0;
205 f4beb510 bellard
                info.si_code = TARGET_SI_KERNEL;
206 f4beb510 bellard
                info._sifields._sigfault._addr = 0;
207 f4beb510 bellard
                queue_signal(info.si_signo, &info);
208 1b6b029e bellard
            }
209 1b6b029e bellard
            break;
210 b689bc57 bellard
        case EXCP0E_PAGE:
211 b689bc57 bellard
            info.si_signo = SIGSEGV;
212 b689bc57 bellard
            info.si_errno = 0;
213 b689bc57 bellard
            if (!(env->error_code & 1))
214 b689bc57 bellard
                info.si_code = TARGET_SEGV_MAPERR;
215 b689bc57 bellard
            else
216 b689bc57 bellard
                info.si_code = TARGET_SEGV_ACCERR;
217 970a87a6 bellard
            info._sifields._sigfault._addr = env->cr[2];
218 b689bc57 bellard
            queue_signal(info.si_signo, &info);
219 b689bc57 bellard
            break;
220 9de5e440 bellard
        case EXCP00_DIVZ:
221 84409ddb j_mayer
#ifndef TARGET_X86_64
222 bc8a22cc bellard
            if (env->eflags & VM_MASK) {
223 447db213 bellard
                handle_vm86_trap(env, trapnr);
224 84409ddb j_mayer
            } else
225 84409ddb j_mayer
#endif
226 84409ddb j_mayer
            {
227 bc8a22cc bellard
                /* division by zero */
228 bc8a22cc bellard
                info.si_signo = SIGFPE;
229 bc8a22cc bellard
                info.si_errno = 0;
230 bc8a22cc bellard
                info.si_code = TARGET_FPE_INTDIV;
231 bc8a22cc bellard
                info._sifields._sigfault._addr = env->eip;
232 bc8a22cc bellard
                queue_signal(info.si_signo, &info);
233 bc8a22cc bellard
            }
234 9de5e440 bellard
            break;
235 447db213 bellard
        case EXCP01_SSTP:
236 447db213 bellard
        case EXCP03_INT3:
237 84409ddb j_mayer
#ifndef TARGET_X86_64
238 447db213 bellard
            if (env->eflags & VM_MASK) {
239 447db213 bellard
                handle_vm86_trap(env, trapnr);
240 84409ddb j_mayer
            } else
241 84409ddb j_mayer
#endif
242 84409ddb j_mayer
            {
243 447db213 bellard
                info.si_signo = SIGTRAP;
244 447db213 bellard
                info.si_errno = 0;
245 447db213 bellard
                if (trapnr == EXCP01_SSTP) {
246 447db213 bellard
                    info.si_code = TARGET_TRAP_BRKPT;
247 447db213 bellard
                    info._sifields._sigfault._addr = env->eip;
248 447db213 bellard
                } else {
249 447db213 bellard
                    info.si_code = TARGET_SI_KERNEL;
250 447db213 bellard
                    info._sifields._sigfault._addr = 0;
251 447db213 bellard
                }
252 447db213 bellard
                queue_signal(info.si_signo, &info);
253 447db213 bellard
            }
254 447db213 bellard
            break;
255 9de5e440 bellard
        case EXCP04_INTO:
256 9de5e440 bellard
        case EXCP05_BOUND:
257 84409ddb j_mayer
#ifndef TARGET_X86_64
258 bc8a22cc bellard
            if (env->eflags & VM_MASK) {
259 447db213 bellard
                handle_vm86_trap(env, trapnr);
260 84409ddb j_mayer
            } else
261 84409ddb j_mayer
#endif
262 84409ddb j_mayer
            {
263 bc8a22cc bellard
                info.si_signo = SIGSEGV;
264 bc8a22cc bellard
                info.si_errno = 0;
265 b689bc57 bellard
                info.si_code = TARGET_SI_KERNEL;
266 bc8a22cc bellard
                info._sifields._sigfault._addr = 0;
267 bc8a22cc bellard
                queue_signal(info.si_signo, &info);
268 bc8a22cc bellard
            }
269 9de5e440 bellard
            break;
270 9de5e440 bellard
        case EXCP06_ILLOP:
271 9de5e440 bellard
            info.si_signo = SIGILL;
272 9de5e440 bellard
            info.si_errno = 0;
273 9de5e440 bellard
            info.si_code = TARGET_ILL_ILLOPN;
274 9de5e440 bellard
            info._sifields._sigfault._addr = env->eip;
275 9de5e440 bellard
            queue_signal(info.si_signo, &info);
276 9de5e440 bellard
            break;
277 9de5e440 bellard
        case EXCP_INTERRUPT:
278 9de5e440 bellard
            /* just indicate that signals should be handled asap */
279 9de5e440 bellard
            break;
280 1fddef4b bellard
        case EXCP_DEBUG:
281 1fddef4b bellard
            {
282 1fddef4b bellard
                int sig;
283 1fddef4b bellard
284 1fddef4b bellard
                sig = gdb_handlesig (env, TARGET_SIGTRAP);
285 1fddef4b bellard
                if (sig)
286 1fddef4b bellard
                  {
287 1fddef4b bellard
                    info.si_signo = sig;
288 1fddef4b bellard
                    info.si_errno = 0;
289 1fddef4b bellard
                    info.si_code = TARGET_TRAP_BRKPT;
290 1fddef4b bellard
                    queue_signal(info.si_signo, &info);
291 1fddef4b bellard
                  }
292 1fddef4b bellard
            }
293 1fddef4b bellard
            break;
294 1b6b029e bellard
        default:
295 970a87a6 bellard
            pc = env->segs[R_CS].base + env->eip;
296 5fafdf24 ths
            fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
297 bc8a22cc bellard
                    (long)pc, trapnr);
298 1b6b029e bellard
            abort();
299 1b6b029e bellard
        }
300 66fb9763 bellard
        process_pending_signals(env);
301 1b6b029e bellard
    }
302 1b6b029e bellard
}
303 b346ff46 bellard
#endif
304 b346ff46 bellard
305 b346ff46 bellard
#ifdef TARGET_ARM
306 b346ff46 bellard
307 6f1f31c0 bellard
/* XXX: find a better solution */
308 6f1f31c0 bellard
extern void tb_invalidate_page_range(target_ulong start, target_ulong end);
309 6f1f31c0 bellard
310 6f1f31c0 bellard
static void arm_cache_flush(target_ulong start, target_ulong last)
311 6f1f31c0 bellard
{
312 6f1f31c0 bellard
    target_ulong addr, last1;
313 6f1f31c0 bellard
314 6f1f31c0 bellard
    if (last < start)
315 6f1f31c0 bellard
        return;
316 6f1f31c0 bellard
    addr = start;
317 6f1f31c0 bellard
    for(;;) {
318 6f1f31c0 bellard
        last1 = ((addr + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK) - 1;
319 6f1f31c0 bellard
        if (last1 > last)
320 6f1f31c0 bellard
            last1 = last;
321 6f1f31c0 bellard
        tb_invalidate_page_range(addr, last1 + 1);
322 6f1f31c0 bellard
        if (last1 == last)
323 6f1f31c0 bellard
            break;
324 6f1f31c0 bellard
        addr = last1 + 1;
325 6f1f31c0 bellard
    }
326 6f1f31c0 bellard
}
327 6f1f31c0 bellard
328 b346ff46 bellard
void cpu_loop(CPUARMState *env)
329 b346ff46 bellard
{
330 b346ff46 bellard
    int trapnr;
331 b346ff46 bellard
    unsigned int n, insn;
332 b346ff46 bellard
    target_siginfo_t info;
333 b5ff1b31 bellard
    uint32_t addr;
334 3b46e624 ths
335 b346ff46 bellard
    for(;;) {
336 b346ff46 bellard
        trapnr = cpu_arm_exec(env);
337 b346ff46 bellard
        switch(trapnr) {
338 b346ff46 bellard
        case EXCP_UDEF:
339 c6981055 bellard
            {
340 c6981055 bellard
                TaskState *ts = env->opaque;
341 c6981055 bellard
                uint32_t opcode;
342 c6981055 bellard
343 c6981055 bellard
                /* we handle the FPU emulation here, as Linux */
344 c6981055 bellard
                /* we get the opcode */
345 53a5960a pbrook
                opcode = tget32(env->regs[15]);
346 3b46e624 ths
347 19b045de pbrook
                if (EmulateAll(opcode, &ts->fpa, env) == 0) {
348 c6981055 bellard
                    info.si_signo = SIGILL;
349 c6981055 bellard
                    info.si_errno = 0;
350 c6981055 bellard
                    info.si_code = TARGET_ILL_ILLOPN;
351 c6981055 bellard
                    info._sifields._sigfault._addr = env->regs[15];
352 c6981055 bellard
                    queue_signal(info.si_signo, &info);
353 c6981055 bellard
                } else {
354 c6981055 bellard
                    /* increment PC */
355 c6981055 bellard
                    env->regs[15] += 4;
356 c6981055 bellard
                }
357 c6981055 bellard
            }
358 b346ff46 bellard
            break;
359 b346ff46 bellard
        case EXCP_SWI:
360 06c949e6 pbrook
        case EXCP_BKPT:
361 b346ff46 bellard
            {
362 ce4defa0 pbrook
                env->eabi = 1;
363 b346ff46 bellard
                /* system call */
364 06c949e6 pbrook
                if (trapnr == EXCP_BKPT) {
365 06c949e6 pbrook
                    if (env->thumb) {
366 53a5960a pbrook
                        insn = tget16(env->regs[15]);
367 06c949e6 pbrook
                        n = insn & 0xff;
368 06c949e6 pbrook
                        env->regs[15] += 2;
369 06c949e6 pbrook
                    } else {
370 53a5960a pbrook
                        insn = tget32(env->regs[15]);
371 06c949e6 pbrook
                        n = (insn & 0xf) | ((insn >> 4) & 0xff0);
372 06c949e6 pbrook
                        env->regs[15] += 4;
373 06c949e6 pbrook
                    }
374 192c7bd9 bellard
                } else {
375 06c949e6 pbrook
                    if (env->thumb) {
376 53a5960a pbrook
                        insn = tget16(env->regs[15] - 2);
377 06c949e6 pbrook
                        n = insn & 0xff;
378 06c949e6 pbrook
                    } else {
379 53a5960a pbrook
                        insn = tget32(env->regs[15] - 4);
380 06c949e6 pbrook
                        n = insn & 0xffffff;
381 06c949e6 pbrook
                    }
382 192c7bd9 bellard
                }
383 192c7bd9 bellard
384 6f1f31c0 bellard
                if (n == ARM_NR_cacheflush) {
385 6f1f31c0 bellard
                    arm_cache_flush(env->regs[0], env->regs[1]);
386 a4f81979 bellard
                } else if (n == ARM_NR_semihosting
387 a4f81979 bellard
                           || n == ARM_NR_thumb_semihosting) {
388 a4f81979 bellard
                    env->regs[0] = do_arm_semihosting (env);
389 ce4defa0 pbrook
                } else if (n == 0 || n >= ARM_SYSCALL_BASE
390 192c7bd9 bellard
                           || (env->thumb && n == ARM_THUMB_SYSCALL)) {
391 b346ff46 bellard
                    /* linux syscall */
392 ce4defa0 pbrook
                    if (env->thumb || n == 0) {
393 192c7bd9 bellard
                        n = env->regs[7];
394 192c7bd9 bellard
                    } else {
395 192c7bd9 bellard
                        n -= ARM_SYSCALL_BASE;
396 ce4defa0 pbrook
                        env->eabi = 0;
397 192c7bd9 bellard
                    }
398 5fafdf24 ths
                    env->regs[0] = do_syscall(env,
399 5fafdf24 ths
                                              n,
400 b346ff46 bellard
                                              env->regs[0],
401 b346ff46 bellard
                                              env->regs[1],
402 b346ff46 bellard
                                              env->regs[2],
403 b346ff46 bellard
                                              env->regs[3],
404 b346ff46 bellard
                                              env->regs[4],
405 e1a2849c bellard
                                              env->regs[5]);
406 b346ff46 bellard
                } else {
407 b346ff46 bellard
                    goto error;
408 b346ff46 bellard
                }
409 b346ff46 bellard
            }
410 b346ff46 bellard
            break;
411 43fff238 bellard
        case EXCP_INTERRUPT:
412 43fff238 bellard
            /* just indicate that signals should be handled asap */
413 43fff238 bellard
            break;
414 68016c62 bellard
        case EXCP_PREFETCH_ABORT:
415 b5ff1b31 bellard
            addr = env->cp15.c6_data;
416 b5ff1b31 bellard
            goto do_segv;
417 68016c62 bellard
        case EXCP_DATA_ABORT:
418 b5ff1b31 bellard
            addr = env->cp15.c6_insn;
419 b5ff1b31 bellard
            goto do_segv;
420 b5ff1b31 bellard
        do_segv:
421 68016c62 bellard
            {
422 68016c62 bellard
                info.si_signo = SIGSEGV;
423 68016c62 bellard
                info.si_errno = 0;
424 68016c62 bellard
                /* XXX: check env->error_code */
425 68016c62 bellard
                info.si_code = TARGET_SEGV_MAPERR;
426 b5ff1b31 bellard
                info._sifields._sigfault._addr = addr;
427 68016c62 bellard
                queue_signal(info.si_signo, &info);
428 68016c62 bellard
            }
429 68016c62 bellard
            break;
430 1fddef4b bellard
        case EXCP_DEBUG:
431 1fddef4b bellard
            {
432 1fddef4b bellard
                int sig;
433 1fddef4b bellard
434 1fddef4b bellard
                sig = gdb_handlesig (env, TARGET_SIGTRAP);
435 1fddef4b bellard
                if (sig)
436 1fddef4b bellard
                  {
437 1fddef4b bellard
                    info.si_signo = sig;
438 1fddef4b bellard
                    info.si_errno = 0;
439 1fddef4b bellard
                    info.si_code = TARGET_TRAP_BRKPT;
440 1fddef4b bellard
                    queue_signal(info.si_signo, &info);
441 1fddef4b bellard
                  }
442 1fddef4b bellard
            }
443 1fddef4b bellard
            break;
444 b346ff46 bellard
        default:
445 b346ff46 bellard
        error:
446 5fafdf24 ths
            fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
447 b346ff46 bellard
                    trapnr);
448 7fe48483 bellard
            cpu_dump_state(env, stderr, fprintf, 0);
449 b346ff46 bellard
            abort();
450 b346ff46 bellard
        }
451 b346ff46 bellard
        process_pending_signals(env);
452 b346ff46 bellard
    }
453 b346ff46 bellard
}
454 b346ff46 bellard
455 b346ff46 bellard
#endif
456 1b6b029e bellard
457 93ac68bc bellard
#ifdef TARGET_SPARC
458 93ac68bc bellard
459 060366c5 bellard
//#define DEBUG_WIN
460 060366c5 bellard
461 2623cbaf bellard
/* WARNING: dealing with register windows _is_ complicated. More info
462 2623cbaf bellard
   can be found at http://www.sics.se/~psm/sparcstack.html */
463 060366c5 bellard
static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
464 060366c5 bellard
{
465 060366c5 bellard
    index = (index + cwp * 16) & (16 * NWINDOWS - 1);
466 060366c5 bellard
    /* wrap handling : if cwp is on the last window, then we use the
467 060366c5 bellard
       registers 'after' the end */
468 060366c5 bellard
    if (index < 8 && env->cwp == (NWINDOWS - 1))
469 060366c5 bellard
        index += (16 * NWINDOWS);
470 060366c5 bellard
    return index;
471 060366c5 bellard
}
472 060366c5 bellard
473 2623cbaf bellard
/* save the register window 'cwp1' */
474 2623cbaf bellard
static inline void save_window_offset(CPUSPARCState *env, int cwp1)
475 060366c5 bellard
{
476 2623cbaf bellard
    unsigned int i;
477 53a5960a pbrook
    target_ulong sp_ptr;
478 3b46e624 ths
479 53a5960a pbrook
    sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
480 060366c5 bellard
#if defined(DEBUG_WIN)
481 5fafdf24 ths
    printf("win_overflow: sp_ptr=0x%x save_cwp=%d\n",
482 060366c5 bellard
           (int)sp_ptr, cwp1);
483 060366c5 bellard
#endif
484 2623cbaf bellard
    for(i = 0; i < 16; i++) {
485 53a5960a pbrook
        tputl(sp_ptr, env->regbase[get_reg_index(env, cwp1, 8 + i)]);
486 53a5960a pbrook
        sp_ptr += sizeof(target_ulong);
487 2623cbaf bellard
    }
488 060366c5 bellard
}
489 060366c5 bellard
490 060366c5 bellard
static void save_window(CPUSPARCState *env)
491 060366c5 bellard
{
492 5ef54116 bellard
#ifndef TARGET_SPARC64
493 2623cbaf bellard
    unsigned int new_wim;
494 2623cbaf bellard
    new_wim = ((env->wim >> 1) | (env->wim << (NWINDOWS - 1))) &
495 2623cbaf bellard
        ((1LL << NWINDOWS) - 1);
496 2623cbaf bellard
    save_window_offset(env, (env->cwp - 2) & (NWINDOWS - 1));
497 2623cbaf bellard
    env->wim = new_wim;
498 5ef54116 bellard
#else
499 5ef54116 bellard
    save_window_offset(env, (env->cwp - 2) & (NWINDOWS - 1));
500 5ef54116 bellard
    env->cansave++;
501 5ef54116 bellard
    env->canrestore--;
502 5ef54116 bellard
#endif
503 060366c5 bellard
}
504 060366c5 bellard
505 060366c5 bellard
static void restore_window(CPUSPARCState *env)
506 060366c5 bellard
{
507 060366c5 bellard
    unsigned int new_wim, i, cwp1;
508 53a5960a pbrook
    target_ulong sp_ptr;
509 3b46e624 ths
510 060366c5 bellard
    new_wim = ((env->wim << 1) | (env->wim >> (NWINDOWS - 1))) &
511 060366c5 bellard
        ((1LL << NWINDOWS) - 1);
512 3b46e624 ths
513 060366c5 bellard
    /* restore the invalid window */
514 060366c5 bellard
    cwp1 = (env->cwp + 1) & (NWINDOWS - 1);
515 53a5960a pbrook
    sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
516 060366c5 bellard
#if defined(DEBUG_WIN)
517 5fafdf24 ths
    printf("win_underflow: sp_ptr=0x%x load_cwp=%d\n",
518 060366c5 bellard
           (int)sp_ptr, cwp1);
519 060366c5 bellard
#endif
520 2623cbaf bellard
    for(i = 0; i < 16; i++) {
521 53a5960a pbrook
        env->regbase[get_reg_index(env, cwp1, 8 + i)] = tgetl(sp_ptr);
522 53a5960a pbrook
        sp_ptr += sizeof(target_ulong);
523 2623cbaf bellard
    }
524 060366c5 bellard
    env->wim = new_wim;
525 5ef54116 bellard
#ifdef TARGET_SPARC64
526 5ef54116 bellard
    env->canrestore++;
527 5ef54116 bellard
    if (env->cleanwin < NWINDOWS - 1)
528 5ef54116 bellard
        env->cleanwin++;
529 5ef54116 bellard
    env->cansave--;
530 5ef54116 bellard
#endif
531 060366c5 bellard
}
532 060366c5 bellard
533 060366c5 bellard
static void flush_windows(CPUSPARCState *env)
534 060366c5 bellard
{
535 060366c5 bellard
    int offset, cwp1;
536 2623cbaf bellard
537 2623cbaf bellard
    offset = 1;
538 060366c5 bellard
    for(;;) {
539 060366c5 bellard
        /* if restore would invoke restore_window(), then we can stop */
540 2623cbaf bellard
        cwp1 = (env->cwp + offset) & (NWINDOWS - 1);
541 060366c5 bellard
        if (env->wim & (1 << cwp1))
542 060366c5 bellard
            break;
543 2623cbaf bellard
        save_window_offset(env, cwp1);
544 060366c5 bellard
        offset++;
545 060366c5 bellard
    }
546 2623cbaf bellard
    /* set wim so that restore will reload the registers */
547 2623cbaf bellard
    cwp1 = (env->cwp + 1) & (NWINDOWS - 1);
548 2623cbaf bellard
    env->wim = 1 << cwp1;
549 2623cbaf bellard
#if defined(DEBUG_WIN)
550 2623cbaf bellard
    printf("flush_windows: nb=%d\n", offset - 1);
551 80a9d035 bellard
#endif
552 2623cbaf bellard
}
553 060366c5 bellard
554 93ac68bc bellard
void cpu_loop (CPUSPARCState *env)
555 93ac68bc bellard
{
556 060366c5 bellard
    int trapnr, ret;
557 61ff6f58 bellard
    target_siginfo_t info;
558 3b46e624 ths
559 060366c5 bellard
    while (1) {
560 060366c5 bellard
        trapnr = cpu_sparc_exec (env);
561 3b46e624 ths
562 060366c5 bellard
        switch (trapnr) {
563 5ef54116 bellard
#ifndef TARGET_SPARC64
564 5fafdf24 ths
        case 0x88:
565 060366c5 bellard
        case 0x90:
566 5ef54116 bellard
#else
567 5ef54116 bellard
        case 0x16d:
568 5ef54116 bellard
#endif
569 060366c5 bellard
            ret = do_syscall (env, env->gregs[1],
570 5fafdf24 ths
                              env->regwptr[0], env->regwptr[1],
571 5fafdf24 ths
                              env->regwptr[2], env->regwptr[3],
572 060366c5 bellard
                              env->regwptr[4], env->regwptr[5]);
573 060366c5 bellard
            if ((unsigned int)ret >= (unsigned int)(-515)) {
574 27908725 bellard
#ifdef TARGET_SPARC64
575 27908725 bellard
                env->xcc |= PSR_CARRY;
576 27908725 bellard
#else
577 060366c5 bellard
                env->psr |= PSR_CARRY;
578 27908725 bellard
#endif
579 060366c5 bellard
                ret = -ret;
580 060366c5 bellard
            } else {
581 27908725 bellard
#ifdef TARGET_SPARC64
582 27908725 bellard
                env->xcc &= ~PSR_CARRY;
583 27908725 bellard
#else
584 060366c5 bellard
                env->psr &= ~PSR_CARRY;
585 27908725 bellard
#endif
586 060366c5 bellard
            }
587 060366c5 bellard
            env->regwptr[0] = ret;
588 060366c5 bellard
            /* next instruction */
589 060366c5 bellard
            env->pc = env->npc;
590 060366c5 bellard
            env->npc = env->npc + 4;
591 060366c5 bellard
            break;
592 060366c5 bellard
        case 0x83: /* flush windows */
593 2623cbaf bellard
            flush_windows(env);
594 060366c5 bellard
            /* next instruction */
595 060366c5 bellard
            env->pc = env->npc;
596 060366c5 bellard
            env->npc = env->npc + 4;
597 060366c5 bellard
            break;
598 3475187d bellard
#ifndef TARGET_SPARC64
599 060366c5 bellard
        case TT_WIN_OVF: /* window overflow */
600 060366c5 bellard
            save_window(env);
601 060366c5 bellard
            break;
602 060366c5 bellard
        case TT_WIN_UNF: /* window underflow */
603 060366c5 bellard
            restore_window(env);
604 060366c5 bellard
            break;
605 61ff6f58 bellard
        case TT_TFAULT:
606 61ff6f58 bellard
        case TT_DFAULT:
607 61ff6f58 bellard
            {
608 61ff6f58 bellard
                info.si_signo = SIGSEGV;
609 61ff6f58 bellard
                info.si_errno = 0;
610 61ff6f58 bellard
                /* XXX: check env->error_code */
611 61ff6f58 bellard
                info.si_code = TARGET_SEGV_MAPERR;
612 61ff6f58 bellard
                info._sifields._sigfault._addr = env->mmuregs[4];
613 61ff6f58 bellard
                queue_signal(info.si_signo, &info);
614 61ff6f58 bellard
            }
615 61ff6f58 bellard
            break;
616 3475187d bellard
#else
617 5ef54116 bellard
        case TT_SPILL: /* window overflow */
618 5ef54116 bellard
            save_window(env);
619 5ef54116 bellard
            break;
620 5ef54116 bellard
        case TT_FILL: /* window underflow */
621 5ef54116 bellard
            restore_window(env);
622 5ef54116 bellard
            break;
623 7f84a729 blueswir1
        case TT_TFAULT:
624 7f84a729 blueswir1
        case TT_DFAULT:
625 7f84a729 blueswir1
            {
626 7f84a729 blueswir1
                info.si_signo = SIGSEGV;
627 7f84a729 blueswir1
                info.si_errno = 0;
628 7f84a729 blueswir1
                /* XXX: check env->error_code */
629 7f84a729 blueswir1
                info.si_code = TARGET_SEGV_MAPERR;
630 7f84a729 blueswir1
                if (trapnr == TT_DFAULT)
631 7f84a729 blueswir1
                    info._sifields._sigfault._addr = env->dmmuregs[4];
632 7f84a729 blueswir1
                else
633 7f84a729 blueswir1
                    info._sifields._sigfault._addr = env->tpc[env->tl];
634 7f84a729 blueswir1
                queue_signal(info.si_signo, &info);
635 7f84a729 blueswir1
            }
636 7f84a729 blueswir1
            break;
637 3475187d bellard
#endif
638 48dc41eb bellard
        case EXCP_INTERRUPT:
639 48dc41eb bellard
            /* just indicate that signals should be handled asap */
640 48dc41eb bellard
            break;
641 1fddef4b bellard
        case EXCP_DEBUG:
642 1fddef4b bellard
            {
643 1fddef4b bellard
                int sig;
644 1fddef4b bellard
645 1fddef4b bellard
                sig = gdb_handlesig (env, TARGET_SIGTRAP);
646 1fddef4b bellard
                if (sig)
647 1fddef4b bellard
                  {
648 1fddef4b bellard
                    info.si_signo = sig;
649 1fddef4b bellard
                    info.si_errno = 0;
650 1fddef4b bellard
                    info.si_code = TARGET_TRAP_BRKPT;
651 1fddef4b bellard
                    queue_signal(info.si_signo, &info);
652 1fddef4b bellard
                  }
653 1fddef4b bellard
            }
654 1fddef4b bellard
            break;
655 060366c5 bellard
        default:
656 060366c5 bellard
            printf ("Unhandled trap: 0x%x\n", trapnr);
657 7fe48483 bellard
            cpu_dump_state(env, stderr, fprintf, 0);
658 060366c5 bellard
            exit (1);
659 060366c5 bellard
        }
660 060366c5 bellard
        process_pending_signals (env);
661 060366c5 bellard
    }
662 93ac68bc bellard
}
663 93ac68bc bellard
664 93ac68bc bellard
#endif
665 93ac68bc bellard
666 67867308 bellard
#ifdef TARGET_PPC
667 9fddaa0c bellard
668 9fddaa0c bellard
static inline uint64_t cpu_ppc_get_tb (CPUState *env)
669 9fddaa0c bellard
{
670 9fddaa0c bellard
    /* TO FIX */
671 9fddaa0c bellard
    return 0;
672 9fddaa0c bellard
}
673 3b46e624 ths
674 9fddaa0c bellard
uint32_t cpu_ppc_load_tbl (CPUState *env)
675 9fddaa0c bellard
{
676 9fddaa0c bellard
    return cpu_ppc_get_tb(env) & 0xFFFFFFFF;
677 9fddaa0c bellard
}
678 3b46e624 ths
679 9fddaa0c bellard
uint32_t cpu_ppc_load_tbu (CPUState *env)
680 9fddaa0c bellard
{
681 9fddaa0c bellard
    return cpu_ppc_get_tb(env) >> 32;
682 9fddaa0c bellard
}
683 3b46e624 ths
684 9fddaa0c bellard
static void cpu_ppc_store_tb (CPUState *env, uint64_t value)
685 9fddaa0c bellard
{
686 9fddaa0c bellard
    /* TO FIX */
687 9fddaa0c bellard
}
688 9fddaa0c bellard
689 9fddaa0c bellard
void cpu_ppc_store_tbu (CPUState *env, uint32_t value)
690 9fddaa0c bellard
{
691 9fddaa0c bellard
    cpu_ppc_store_tb(env, ((uint64_t)value << 32) | cpu_ppc_load_tbl(env));
692 9fddaa0c bellard
}
693 5fafdf24 ths
694 9fddaa0c bellard
void cpu_ppc_store_tbl (CPUState *env, uint32_t value)
695 9fddaa0c bellard
{
696 9fddaa0c bellard
    cpu_ppc_store_tb(env, ((uint64_t)cpu_ppc_load_tbl(env) << 32) | value);
697 9fddaa0c bellard
}
698 76a66253 j_mayer
699 76a66253 j_mayer
void cpu_ppc601_store_rtcu (CPUState *env, uint32_t value)
700 76a66253 j_mayer
__attribute__ (( alias ("cpu_ppc_store_tbu") ));
701 76a66253 j_mayer
702 76a66253 j_mayer
uint32_t cpu_ppc601_load_rtcu (CPUState *env)
703 76a66253 j_mayer
__attribute__ (( alias ("cpu_ppc_load_tbu") ));
704 76a66253 j_mayer
705 76a66253 j_mayer
void cpu_ppc601_store_rtcl (CPUState *env, uint32_t value)
706 9fddaa0c bellard
{
707 76a66253 j_mayer
    cpu_ppc_store_tbl(env, value & 0x3FFFFF80);
708 9fddaa0c bellard
}
709 76a66253 j_mayer
710 76a66253 j_mayer
uint32_t cpu_ppc601_load_rtcl (CPUState *env)
711 9fddaa0c bellard
{
712 76a66253 j_mayer
    return cpu_ppc_load_tbl(env) & 0x3FFFFF80;
713 9fddaa0c bellard
}
714 76a66253 j_mayer
715 a750fc0b j_mayer
/* XXX: to be fixed */
716 a750fc0b j_mayer
int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, target_ulong *valp)
717 a750fc0b j_mayer
{
718 a750fc0b j_mayer
    return -1;
719 a750fc0b j_mayer
}
720 a750fc0b j_mayer
721 a750fc0b j_mayer
int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, target_ulong val)
722 a750fc0b j_mayer
{
723 a750fc0b j_mayer
    return -1;
724 a750fc0b j_mayer
}
725 a750fc0b j_mayer
726 e1833e1f j_mayer
#define EXCP_DUMP(env, fmt, args...)                                         \
727 e1833e1f j_mayer
do {                                                                          \
728 e1833e1f j_mayer
    fprintf(stderr, fmt , ##args);                                            \
729 e1833e1f j_mayer
    cpu_dump_state(env, stderr, fprintf, 0);                                  \
730 e1833e1f j_mayer
    if (loglevel != 0) {                                                      \
731 e1833e1f j_mayer
        fprintf(logfile, fmt , ##args);                                       \
732 e1833e1f j_mayer
        cpu_dump_state(env, logfile, fprintf, 0);                             \
733 e1833e1f j_mayer
    }                                                                         \
734 e1833e1f j_mayer
} while (0)
735 e1833e1f j_mayer
736 67867308 bellard
void cpu_loop(CPUPPCState *env)
737 67867308 bellard
{
738 67867308 bellard
    target_siginfo_t info;
739 61190b14 bellard
    int trapnr;
740 61190b14 bellard
    uint32_t ret;
741 3b46e624 ths
742 67867308 bellard
    for(;;) {
743 67867308 bellard
        trapnr = cpu_ppc_exec(env);
744 67867308 bellard
        switch(trapnr) {
745 e1833e1f j_mayer
        case POWERPC_EXCP_NONE:
746 e1833e1f j_mayer
            /* Just go on */
747 67867308 bellard
            break;
748 e1833e1f j_mayer
        case POWERPC_EXCP_CRITICAL: /* Critical input                        */
749 e1833e1f j_mayer
            cpu_abort(env, "Critical interrupt while in user mode. "
750 e1833e1f j_mayer
                      "Aborting\n");
751 61190b14 bellard
            break;
752 e1833e1f j_mayer
        case POWERPC_EXCP_MCHECK:   /* Machine check exception               */
753 e1833e1f j_mayer
            cpu_abort(env, "Machine check exception while in user mode. "
754 e1833e1f j_mayer
                      "Aborting\n");
755 e1833e1f j_mayer
            break;
756 e1833e1f j_mayer
        case POWERPC_EXCP_DSI:      /* Data storage exception                */
757 e1833e1f j_mayer
            EXCP_DUMP(env, "Invalid data memory access: 0x" ADDRX "\n",
758 e1833e1f j_mayer
                      env->spr[SPR_DAR]);
759 e1833e1f j_mayer
            /* XXX: check this. Seems bugged */
760 2be0071f bellard
            switch (env->error_code & 0xFF000000) {
761 2be0071f bellard
            case 0x40000000:
762 61190b14 bellard
                info.si_signo = TARGET_SIGSEGV;
763 61190b14 bellard
                info.si_errno = 0;
764 61190b14 bellard
                info.si_code = TARGET_SEGV_MAPERR;
765 61190b14 bellard
                break;
766 2be0071f bellard
            case 0x04000000:
767 61190b14 bellard
                info.si_signo = TARGET_SIGILL;
768 61190b14 bellard
                info.si_errno = 0;
769 61190b14 bellard
                info.si_code = TARGET_ILL_ILLADR;
770 61190b14 bellard
                break;
771 2be0071f bellard
            case 0x08000000:
772 61190b14 bellard
                info.si_signo = TARGET_SIGSEGV;
773 61190b14 bellard
                info.si_errno = 0;
774 61190b14 bellard
                info.si_code = TARGET_SEGV_ACCERR;
775 61190b14 bellard
                break;
776 61190b14 bellard
            default:
777 61190b14 bellard
                /* Let's send a regular segfault... */
778 e1833e1f j_mayer
                EXCP_DUMP(env, "Invalid segfault errno (%02x)\n",
779 e1833e1f j_mayer
                          env->error_code);
780 61190b14 bellard
                info.si_signo = TARGET_SIGSEGV;
781 61190b14 bellard
                info.si_errno = 0;
782 61190b14 bellard
                info.si_code = TARGET_SEGV_MAPERR;
783 61190b14 bellard
                break;
784 61190b14 bellard
            }
785 67867308 bellard
            info._sifields._sigfault._addr = env->nip;
786 67867308 bellard
            queue_signal(info.si_signo, &info);
787 67867308 bellard
            break;
788 e1833e1f j_mayer
        case POWERPC_EXCP_ISI:      /* Instruction storage exception         */
789 e1833e1f j_mayer
            EXCP_DUMP(env, "Invalid instruction fetch: 0x\n" ADDRX "\n",
790 e1833e1f j_mayer
                      env->spr[SPR_DAR]);
791 e1833e1f j_mayer
            /* XXX: check this */
792 2be0071f bellard
            switch (env->error_code & 0xFF000000) {
793 2be0071f bellard
            case 0x40000000:
794 61190b14 bellard
                info.si_signo = TARGET_SIGSEGV;
795 67867308 bellard
            info.si_errno = 0;
796 61190b14 bellard
                info.si_code = TARGET_SEGV_MAPERR;
797 61190b14 bellard
                break;
798 2be0071f bellard
            case 0x10000000:
799 2be0071f bellard
            case 0x08000000:
800 61190b14 bellard
                info.si_signo = TARGET_SIGSEGV;
801 61190b14 bellard
                info.si_errno = 0;
802 61190b14 bellard
                info.si_code = TARGET_SEGV_ACCERR;
803 61190b14 bellard
                break;
804 61190b14 bellard
            default:
805 61190b14 bellard
                /* Let's send a regular segfault... */
806 e1833e1f j_mayer
                EXCP_DUMP(env, "Invalid segfault errno (%02x)\n",
807 e1833e1f j_mayer
                          env->error_code);
808 61190b14 bellard
                info.si_signo = TARGET_SIGSEGV;
809 61190b14 bellard
                info.si_errno = 0;
810 61190b14 bellard
                info.si_code = TARGET_SEGV_MAPERR;
811 61190b14 bellard
                break;
812 61190b14 bellard
            }
813 61190b14 bellard
            info._sifields._sigfault._addr = env->nip - 4;
814 67867308 bellard
            queue_signal(info.si_signo, &info);
815 67867308 bellard
            break;
816 e1833e1f j_mayer
        case POWERPC_EXCP_EXTERNAL: /* External input                        */
817 e1833e1f j_mayer
            cpu_abort(env, "External interrupt while in user mode. "
818 e1833e1f j_mayer
                      "Aborting\n");
819 e1833e1f j_mayer
            break;
820 e1833e1f j_mayer
        case POWERPC_EXCP_ALIGN:    /* Alignment exception                   */
821 e1833e1f j_mayer
            EXCP_DUMP(env, "Unaligned memory access\n");
822 e1833e1f j_mayer
            /* XXX: check this */
823 61190b14 bellard
            info.si_signo = TARGET_SIGBUS;
824 67867308 bellard
            info.si_errno = 0;
825 61190b14 bellard
            info.si_code = TARGET_BUS_ADRALN;
826 61190b14 bellard
            info._sifields._sigfault._addr = env->nip - 4;
827 67867308 bellard
            queue_signal(info.si_signo, &info);
828 67867308 bellard
            break;
829 e1833e1f j_mayer
        case POWERPC_EXCP_PROGRAM:  /* Program exception                     */
830 e1833e1f j_mayer
            /* XXX: check this */
831 61190b14 bellard
            switch (env->error_code & ~0xF) {
832 e1833e1f j_mayer
            case POWERPC_EXCP_FP:
833 e1833e1f j_mayer
                EXCP_DUMP(env, "Floating point program exception\n");
834 61190b14 bellard
                /* Set FX */
835 61190b14 bellard
                env->fpscr[7] |= 0x8;
836 61190b14 bellard
                /* Finally, update FEX */
837 61190b14 bellard
                if ((((env->fpscr[7] & 0x3) << 3) | (env->fpscr[6] >> 1)) &
838 61190b14 bellard
                    ((env->fpscr[1] << 1) | (env->fpscr[0] >> 3)))
839 61190b14 bellard
                    env->fpscr[7] |= 0x4;
840 61190b14 bellard
                info.si_signo = TARGET_SIGFPE;
841 61190b14 bellard
                info.si_errno = 0;
842 61190b14 bellard
                switch (env->error_code & 0xF) {
843 e1833e1f j_mayer
                case POWERPC_EXCP_FP_OX:
844 61190b14 bellard
                    info.si_code = TARGET_FPE_FLTOVF;
845 61190b14 bellard
                    break;
846 e1833e1f j_mayer
                case POWERPC_EXCP_FP_UX:
847 61190b14 bellard
                    info.si_code = TARGET_FPE_FLTUND;
848 61190b14 bellard
                    break;
849 e1833e1f j_mayer
                case POWERPC_EXCP_FP_ZX:
850 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXZDZ:
851 61190b14 bellard
                    info.si_code = TARGET_FPE_FLTDIV;
852 61190b14 bellard
                    break;
853 e1833e1f j_mayer
                case POWERPC_EXCP_FP_XX:
854 61190b14 bellard
                    info.si_code = TARGET_FPE_FLTRES;
855 61190b14 bellard
                    break;
856 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXSOFT:
857 61190b14 bellard
                    info.si_code = TARGET_FPE_FLTINV;
858 61190b14 bellard
                    break;
859 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXNAN:
860 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXISI:
861 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXIDI:
862 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXIMZ:
863 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXVC:
864 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXSQRT:
865 e1833e1f j_mayer
                case POWERPC_EXCP_FP_VXCVI:
866 61190b14 bellard
                    info.si_code = TARGET_FPE_FLTSUB;
867 61190b14 bellard
                    break;
868 61190b14 bellard
                default:
869 e1833e1f j_mayer
                    EXCP_DUMP(env, "Unknown floating point exception (%02x)\n",
870 e1833e1f j_mayer
                              env->error_code);
871 e1833e1f j_mayer
                    break;
872 61190b14 bellard
                }
873 e1833e1f j_mayer
                break;
874 e1833e1f j_mayer
            case POWERPC_EXCP_INVAL:
875 e1833e1f j_mayer
                EXCP_DUMP(env, "Invalid instruction\n");
876 61190b14 bellard
                info.si_signo = TARGET_SIGILL;
877 61190b14 bellard
                info.si_errno = 0;
878 61190b14 bellard
                switch (env->error_code & 0xF) {
879 e1833e1f j_mayer
                case POWERPC_EXCP_INVAL_INVAL:
880 61190b14 bellard
                    info.si_code = TARGET_ILL_ILLOPC;
881 61190b14 bellard
                    break;
882 e1833e1f j_mayer
                case POWERPC_EXCP_INVAL_LSWX:
883 a750fc0b j_mayer
                    info.si_code = TARGET_ILL_ILLOPN;
884 61190b14 bellard
                    break;
885 e1833e1f j_mayer
                case POWERPC_EXCP_INVAL_SPR:
886 61190b14 bellard
                    info.si_code = TARGET_ILL_PRVREG;
887 61190b14 bellard
                    break;
888 e1833e1f j_mayer
                case POWERPC_EXCP_INVAL_FP:
889 61190b14 bellard
                    info.si_code = TARGET_ILL_COPROC;
890 61190b14 bellard
                    break;
891 61190b14 bellard
                default:
892 e1833e1f j_mayer
                    EXCP_DUMP(env, "Unknown invalid operation (%02x)\n",
893 e1833e1f j_mayer
                              env->error_code & 0xF);
894 61190b14 bellard
                    info.si_code = TARGET_ILL_ILLADR;
895 61190b14 bellard
                    break;
896 61190b14 bellard
                }
897 61190b14 bellard
                break;
898 e1833e1f j_mayer
            case POWERPC_EXCP_PRIV:
899 e1833e1f j_mayer
                EXCP_DUMP(env, "Privilege violation\n");
900 61190b14 bellard
                info.si_signo = TARGET_SIGILL;
901 61190b14 bellard
                info.si_errno = 0;
902 61190b14 bellard
                switch (env->error_code & 0xF) {
903 e1833e1f j_mayer
                case POWERPC_EXCP_PRIV_OPC:
904 61190b14 bellard
                    info.si_code = TARGET_ILL_PRVOPC;
905 61190b14 bellard
                    break;
906 e1833e1f j_mayer
                case POWERPC_EXCP_PRIV_REG:
907 61190b14 bellard
                    info.si_code = TARGET_ILL_PRVREG;
908 e1833e1f j_mayer
                    break;
909 61190b14 bellard
                default:
910 e1833e1f j_mayer
                    EXCP_DUMP(env, "Unknown privilege violation (%02x)\n",
911 e1833e1f j_mayer
                              env->error_code & 0xF);
912 61190b14 bellard
                    info.si_code = TARGET_ILL_PRVOPC;
913 61190b14 bellard
                    break;
914 61190b14 bellard
                }
915 61190b14 bellard
                break;
916 e1833e1f j_mayer
            case POWERPC_EXCP_TRAP:
917 e1833e1f j_mayer
                cpu_abort(env, "Tried to call a TRAP\n");
918 e1833e1f j_mayer
                break;
919 61190b14 bellard
            default:
920 61190b14 bellard
                /* Should not happen ! */
921 e1833e1f j_mayer
                cpu_abort(env, "Unknown program exception (%02x)\n",
922 e1833e1f j_mayer
                          env->error_code);
923 e1833e1f j_mayer
                break;
924 61190b14 bellard
            }
925 61190b14 bellard
            info._sifields._sigfault._addr = env->nip - 4;
926 67867308 bellard
            queue_signal(info.si_signo, &info);
927 67867308 bellard
            break;
928 e1833e1f j_mayer
        case POWERPC_EXCP_FPU:      /* Floating-point unavailable exception  */
929 e1833e1f j_mayer
            EXCP_DUMP(env, "No floating point allowed\n");
930 61190b14 bellard
            info.si_signo = TARGET_SIGILL;
931 67867308 bellard
            info.si_errno = 0;
932 61190b14 bellard
            info.si_code = TARGET_ILL_COPROC;
933 61190b14 bellard
            info._sifields._sigfault._addr = env->nip - 4;
934 67867308 bellard
            queue_signal(info.si_signo, &info);
935 67867308 bellard
            break;
936 e1833e1f j_mayer
        case POWERPC_EXCP_SYSCALL:  /* System call exception                 */
937 e1833e1f j_mayer
            cpu_abort(env, "Syscall exception while in user mode. "
938 e1833e1f j_mayer
                      "Aborting\n");
939 61190b14 bellard
            break;
940 e1833e1f j_mayer
        case POWERPC_EXCP_APU:      /* Auxiliary processor unavailable       */
941 e1833e1f j_mayer
            EXCP_DUMP(env, "No APU instruction allowed\n");
942 e1833e1f j_mayer
            info.si_signo = TARGET_SIGILL;
943 e1833e1f j_mayer
            info.si_errno = 0;
944 e1833e1f j_mayer
            info.si_code = TARGET_ILL_COPROC;
945 e1833e1f j_mayer
            info._sifields._sigfault._addr = env->nip - 4;
946 e1833e1f j_mayer
            queue_signal(info.si_signo, &info);
947 61190b14 bellard
            break;
948 e1833e1f j_mayer
        case POWERPC_EXCP_DECR:     /* Decrementer exception                 */
949 e1833e1f j_mayer
            cpu_abort(env, "Decrementer interrupt while in user mode. "
950 e1833e1f j_mayer
                      "Aborting\n");
951 61190b14 bellard
            break;
952 e1833e1f j_mayer
        case POWERPC_EXCP_FIT:      /* Fixed-interval timer interrupt        */
953 e1833e1f j_mayer
            cpu_abort(env, "Fix interval timer interrupt while in user mode. "
954 e1833e1f j_mayer
                      "Aborting\n");
955 e1833e1f j_mayer
            break;
956 e1833e1f j_mayer
        case POWERPC_EXCP_WDT:      /* Watchdog timer interrupt              */
957 e1833e1f j_mayer
            cpu_abort(env, "Watchdog timer interrupt while in user mode. "
958 e1833e1f j_mayer
                      "Aborting\n");
959 e1833e1f j_mayer
            break;
960 e1833e1f j_mayer
        case POWERPC_EXCP_DTLB:     /* Data TLB error                        */
961 e1833e1f j_mayer
            cpu_abort(env, "Data TLB exception while in user mode. "
962 e1833e1f j_mayer
                      "Aborting\n");
963 e1833e1f j_mayer
            break;
964 e1833e1f j_mayer
        case POWERPC_EXCP_ITLB:     /* Instruction TLB error                 */
965 e1833e1f j_mayer
            cpu_abort(env, "Instruction TLB exception while in user mode. "
966 e1833e1f j_mayer
                      "Aborting\n");
967 e1833e1f j_mayer
            break;
968 e1833e1f j_mayer
        case POWERPC_EXCP_DEBUG:    /* Debug interrupt                       */
969 e1833e1f j_mayer
            /* XXX: check this */
970 1fddef4b bellard
            {
971 1fddef4b bellard
                int sig;
972 1fddef4b bellard
973 e1833e1f j_mayer
                sig = gdb_handlesig(env, TARGET_SIGTRAP);
974 e1833e1f j_mayer
                if (sig) {
975 1fddef4b bellard
                    info.si_signo = sig;
976 1fddef4b bellard
                    info.si_errno = 0;
977 1fddef4b bellard
                    info.si_code = TARGET_TRAP_BRKPT;
978 1fddef4b bellard
                    queue_signal(info.si_signo, &info);
979 1fddef4b bellard
                  }
980 1fddef4b bellard
            }
981 1fddef4b bellard
            break;
982 e1833e1f j_mayer
#if defined(TARGET_PPCEMB)
983 e1833e1f j_mayer
        case POWERPC_EXCP_SPEU:     /* SPE/embedded floating-point unavail.  */
984 e1833e1f j_mayer
            EXCP_DUMP(env, "No SPE/floating-point instruction allowed\n");
985 e1833e1f j_mayer
            info.si_signo = TARGET_SIGILL;
986 e1833e1f j_mayer
            info.si_errno = 0;
987 e1833e1f j_mayer
            info.si_code = TARGET_ILL_COPROC;
988 e1833e1f j_mayer
            info._sifields._sigfault._addr = env->nip - 4;
989 e1833e1f j_mayer
            queue_signal(info.si_signo, &info);
990 e1833e1f j_mayer
            break;
991 e1833e1f j_mayer
        case POWERPC_EXCP_EFPDI:    /* Embedded floating-point data IRQ      */
992 e1833e1f j_mayer
            cpu_abort(env, "Embedded floating-point data IRQ not handled\n");
993 e1833e1f j_mayer
            break;
994 e1833e1f j_mayer
        case POWERPC_EXCP_EFPRI:    /* Embedded floating-point round IRQ     */
995 e1833e1f j_mayer
            cpu_abort(env, "Embedded floating-point round IRQ not handled\n");
996 e1833e1f j_mayer
            break;
997 e1833e1f j_mayer
        case POWERPC_EXCP_EPERFM:   /* Embedded performance monitor IRQ      */
998 e1833e1f j_mayer
            cpu_abort(env, "Performance monitor exception not handled\n");
999 e1833e1f j_mayer
            break;
1000 e1833e1f j_mayer
        case POWERPC_EXCP_DOORI:    /* Embedded doorbell interrupt           */
1001 e1833e1f j_mayer
            cpu_abort(env, "Doorbell interrupt while in user mode. "
1002 e1833e1f j_mayer
                       "Aborting\n");
1003 e1833e1f j_mayer
            break;
1004 e1833e1f j_mayer
        case POWERPC_EXCP_DOORCI:   /* Embedded doorbell critical interrupt  */
1005 e1833e1f j_mayer
            cpu_abort(env, "Doorbell critical interrupt while in user mode. "
1006 e1833e1f j_mayer
                      "Aborting\n");
1007 e1833e1f j_mayer
            break;
1008 e1833e1f j_mayer
        case POWERPC_EXCP_RESET:    /* System reset exception                */
1009 e1833e1f j_mayer
            cpu_abort(env, "Reset interrupt while in user mode. "
1010 e1833e1f j_mayer
                      "Aborting\n");
1011 e1833e1f j_mayer
            break;
1012 e1833e1f j_mayer
#endif /* defined(TARGET_PPCEMB) */
1013 e1833e1f j_mayer
#if defined(TARGET_PPC64) /* PowerPC 64 */
1014 e1833e1f j_mayer
        case POWERPC_EXCP_DSEG:     /* Data segment exception                */
1015 e1833e1f j_mayer
            cpu_abort(env, "Data segment exception while in user mode. "
1016 e1833e1f j_mayer
                      "Aborting\n");
1017 e1833e1f j_mayer
            break;
1018 e1833e1f j_mayer
        case POWERPC_EXCP_ISEG:     /* Instruction segment exception         */
1019 e1833e1f j_mayer
            cpu_abort(env, "Instruction segment exception "
1020 e1833e1f j_mayer
                      "while in user mode. Aborting\n");
1021 e1833e1f j_mayer
            break;
1022 e1833e1f j_mayer
#endif /* defined(TARGET_PPC64) */
1023 e1833e1f j_mayer
#if defined(TARGET_PPC64H) /* PowerPC 64 with hypervisor mode support */
1024 e1833e1f j_mayer
        case POWERPC_EXCP_HDECR:    /* Hypervisor decrementer exception      */
1025 e1833e1f j_mayer
            cpu_abort(env, "Hypervisor decrementer interrupt "
1026 e1833e1f j_mayer
                      "while in user mode. Aborting\n");
1027 e1833e1f j_mayer
            break;
1028 e1833e1f j_mayer
#endif /* defined(TARGET_PPC64H) */
1029 e1833e1f j_mayer
        case POWERPC_EXCP_TRACE:    /* Trace exception                       */
1030 e1833e1f j_mayer
            /* Nothing to do:
1031 e1833e1f j_mayer
             * we use this exception to emulate step-by-step execution mode.
1032 e1833e1f j_mayer
             */
1033 e1833e1f j_mayer
            break;
1034 e1833e1f j_mayer
#if defined(TARGET_PPC64H) /* PowerPC 64 with hypervisor mode support */
1035 e1833e1f j_mayer
        case POWERPC_EXCP_HDSI:     /* Hypervisor data storage exception     */
1036 e1833e1f j_mayer
            cpu_abort(env, "Hypervisor data storage exception "
1037 e1833e1f j_mayer
                      "while in user mode. Aborting\n");
1038 e1833e1f j_mayer
            break;
1039 e1833e1f j_mayer
        case POWERPC_EXCP_HISI:     /* Hypervisor instruction storage excp   */
1040 e1833e1f j_mayer
            cpu_abort(env, "Hypervisor instruction storage exception "
1041 e1833e1f j_mayer
                      "while in user mode. Aborting\n");
1042 e1833e1f j_mayer
            break;
1043 e1833e1f j_mayer
        case POWERPC_EXCP_HDSEG:    /* Hypervisor data segment exception     */
1044 e1833e1f j_mayer
            cpu_abort(env, "Hypervisor data segment exception "
1045 e1833e1f j_mayer
                      "while in user mode. Aborting\n");
1046 e1833e1f j_mayer
            break;
1047 e1833e1f j_mayer
        case POWERPC_EXCP_HISEG:    /* Hypervisor instruction segment excp   */
1048 e1833e1f j_mayer
            cpu_abort(env, "Hypervisor instruction segment exception "
1049 e1833e1f j_mayer
                      "while in user mode. Aborting\n");
1050 e1833e1f j_mayer
            break;
1051 e1833e1f j_mayer
#endif /* defined(TARGET_PPC64H) */
1052 e1833e1f j_mayer
        case POWERPC_EXCP_VPU:      /* Vector unavailable exception          */
1053 e1833e1f j_mayer
            EXCP_DUMP(env, "No Altivec instructions allowed\n");
1054 e1833e1f j_mayer
            info.si_signo = TARGET_SIGILL;
1055 e1833e1f j_mayer
            info.si_errno = 0;
1056 e1833e1f j_mayer
            info.si_code = TARGET_ILL_COPROC;
1057 e1833e1f j_mayer
            info._sifields._sigfault._addr = env->nip - 4;
1058 e1833e1f j_mayer
            queue_signal(info.si_signo, &info);
1059 e1833e1f j_mayer
            break;
1060 e1833e1f j_mayer
        case POWERPC_EXCP_PIT:      /* Programmable interval timer IRQ       */
1061 e1833e1f j_mayer
            cpu_abort(env, "Programable interval timer interrupt "
1062 e1833e1f j_mayer
                      "while in user mode. Aborting\n");
1063 e1833e1f j_mayer
            break;
1064 e1833e1f j_mayer
        case POWERPC_EXCP_IO:       /* IO error exception                    */
1065 e1833e1f j_mayer
            cpu_abort(env, "IO error exception while in user mode. "
1066 e1833e1f j_mayer
                      "Aborting\n");
1067 e1833e1f j_mayer
            break;
1068 e1833e1f j_mayer
        case POWERPC_EXCP_RUNM:     /* Run mode exception                    */
1069 e1833e1f j_mayer
            cpu_abort(env, "Run mode exception while in user mode. "
1070 e1833e1f j_mayer
                      "Aborting\n");
1071 e1833e1f j_mayer
            break;
1072 e1833e1f j_mayer
        case POWERPC_EXCP_EMUL:     /* Emulation trap exception              */
1073 e1833e1f j_mayer
            cpu_abort(env, "Emulation trap exception not handled\n");
1074 e1833e1f j_mayer
            break;
1075 e1833e1f j_mayer
        case POWERPC_EXCP_IFTLB:    /* Instruction fetch TLB error           */
1076 e1833e1f j_mayer
            cpu_abort(env, "Instruction fetch TLB exception "
1077 e1833e1f j_mayer
                      "while in user-mode. Aborting");
1078 e1833e1f j_mayer
            break;
1079 e1833e1f j_mayer
        case POWERPC_EXCP_DLTLB:    /* Data load TLB miss                    */
1080 e1833e1f j_mayer
            cpu_abort(env, "Data load TLB exception while in user-mode. "
1081 e1833e1f j_mayer
                      "Aborting");
1082 e1833e1f j_mayer
            break;
1083 e1833e1f j_mayer
        case POWERPC_EXCP_DSTLB:    /* Data store TLB miss                   */
1084 e1833e1f j_mayer
            cpu_abort(env, "Data store TLB exception while in user-mode. "
1085 e1833e1f j_mayer
                      "Aborting");
1086 e1833e1f j_mayer
            break;
1087 e1833e1f j_mayer
        case POWERPC_EXCP_FPA:      /* Floating-point assist exception       */
1088 e1833e1f j_mayer
            cpu_abort(env, "Floating-point assist exception not handled\n");
1089 e1833e1f j_mayer
            break;
1090 e1833e1f j_mayer
        case POWERPC_EXCP_IABR:     /* Instruction address breakpoint        */
1091 e1833e1f j_mayer
            cpu_abort(env, "Instruction address breakpoint exception "
1092 e1833e1f j_mayer
                      "not handled\n");
1093 e1833e1f j_mayer
            break;
1094 e1833e1f j_mayer
        case POWERPC_EXCP_SMI:      /* System management interrupt           */
1095 e1833e1f j_mayer
            cpu_abort(env, "System management interrupt while in user mode. "
1096 e1833e1f j_mayer
                      "Aborting\n");
1097 e1833e1f j_mayer
            break;
1098 e1833e1f j_mayer
        case POWERPC_EXCP_THERM:    /* Thermal interrupt                     */
1099 e1833e1f j_mayer
            cpu_abort(env, "Thermal interrupt interrupt while in user mode. "
1100 e1833e1f j_mayer
                      "Aborting\n");
1101 e1833e1f j_mayer
            break;
1102 e1833e1f j_mayer
        case POWERPC_EXCP_PERFM:   /* Embedded performance monitor IRQ      */
1103 e1833e1f j_mayer
            cpu_abort(env, "Performance monitor exception not handled\n");
1104 e1833e1f j_mayer
            break;
1105 e1833e1f j_mayer
        case POWERPC_EXCP_VPUA:     /* Vector assist exception               */
1106 e1833e1f j_mayer
            cpu_abort(env, "Vector assist exception not handled\n");
1107 e1833e1f j_mayer
            break;
1108 e1833e1f j_mayer
        case POWERPC_EXCP_SOFTP:    /* Soft patch exception                  */
1109 e1833e1f j_mayer
            cpu_abort(env, "Soft patch exception not handled\n");
1110 e1833e1f j_mayer
            break;
1111 e1833e1f j_mayer
        case POWERPC_EXCP_MAINT:    /* Maintenance exception                 */
1112 e1833e1f j_mayer
            cpu_abort(env, "Maintenance exception while in user mode. "
1113 e1833e1f j_mayer
                      "Aborting\n");
1114 e1833e1f j_mayer
            break;
1115 e1833e1f j_mayer
        case POWERPC_EXCP_STOP:     /* stop translation                      */
1116 e1833e1f j_mayer
            /* We did invalidate the instruction cache. Go on */
1117 e1833e1f j_mayer
            break;
1118 e1833e1f j_mayer
        case POWERPC_EXCP_BRANCH:   /* branch instruction:                   */
1119 e1833e1f j_mayer
            /* We just stopped because of a branch. Go on */
1120 e1833e1f j_mayer
            break;
1121 e1833e1f j_mayer
        case POWERPC_EXCP_SYSCALL_USER:
1122 e1833e1f j_mayer
            /* system call in user-mode emulation */
1123 e1833e1f j_mayer
            /* WARNING:
1124 e1833e1f j_mayer
             * PPC ABI uses overflow flag in cr0 to signal an error
1125 e1833e1f j_mayer
             * in syscalls.
1126 e1833e1f j_mayer
             */
1127 e1833e1f j_mayer
#if 0
1128 e1833e1f j_mayer
            printf("syscall %d 0x%08x 0x%08x 0x%08x 0x%08x\n", env->gpr[0],
1129 e1833e1f j_mayer
                   env->gpr[3], env->gpr[4], env->gpr[5], env->gpr[6]);
1130 e1833e1f j_mayer
#endif
1131 e1833e1f j_mayer
            env->crf[0] &= ~0x1;
1132 e1833e1f j_mayer
            ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4],
1133 e1833e1f j_mayer
                             env->gpr[5], env->gpr[6], env->gpr[7],
1134 e1833e1f j_mayer
                             env->gpr[8]);
1135 e1833e1f j_mayer
            if (ret > (uint32_t)(-515)) {
1136 e1833e1f j_mayer
                env->crf[0] |= 0x1;
1137 e1833e1f j_mayer
                ret = -ret;
1138 61190b14 bellard
            }
1139 e1833e1f j_mayer
            env->gpr[3] = ret;
1140 e1833e1f j_mayer
#if 0
1141 e1833e1f j_mayer
            printf("syscall returned 0x%08x (%d)\n", ret, ret);
1142 e1833e1f j_mayer
#endif
1143 e1833e1f j_mayer
            break;
1144 e1833e1f j_mayer
        default:
1145 e1833e1f j_mayer
            cpu_abort(env, "Unknown exception 0x%d. Aborting\n", trapnr);
1146 e1833e1f j_mayer
            break;
1147 67867308 bellard
        }
1148 67867308 bellard
        process_pending_signals(env);
1149 67867308 bellard
    }
1150 67867308 bellard
}
1151 67867308 bellard
#endif
1152 67867308 bellard
1153 048f6b4d bellard
#ifdef TARGET_MIPS
1154 048f6b4d bellard
1155 048f6b4d bellard
#define MIPS_SYS(name, args) args,
1156 048f6b4d bellard
1157 048f6b4d bellard
static const uint8_t mips_syscall_args[] = {
1158 048f6b4d bellard
        MIPS_SYS(sys_syscall        , 0)        /* 4000 */
1159 048f6b4d bellard
        MIPS_SYS(sys_exit        , 1)
1160 048f6b4d bellard
        MIPS_SYS(sys_fork        , 0)
1161 048f6b4d bellard
        MIPS_SYS(sys_read        , 3)
1162 048f6b4d bellard
        MIPS_SYS(sys_write        , 3)
1163 048f6b4d bellard
        MIPS_SYS(sys_open        , 3)        /* 4005 */
1164 048f6b4d bellard
        MIPS_SYS(sys_close        , 1)
1165 048f6b4d bellard
        MIPS_SYS(sys_waitpid        , 3)
1166 048f6b4d bellard
        MIPS_SYS(sys_creat        , 2)
1167 048f6b4d bellard
        MIPS_SYS(sys_link        , 2)
1168 048f6b4d bellard
        MIPS_SYS(sys_unlink        , 1)        /* 4010 */
1169 048f6b4d bellard
        MIPS_SYS(sys_execve        , 0)
1170 048f6b4d bellard
        MIPS_SYS(sys_chdir        , 1)
1171 048f6b4d bellard
        MIPS_SYS(sys_time        , 1)
1172 048f6b4d bellard
        MIPS_SYS(sys_mknod        , 3)
1173 048f6b4d bellard
        MIPS_SYS(sys_chmod        , 2)        /* 4015 */
1174 048f6b4d bellard
        MIPS_SYS(sys_lchown        , 3)
1175 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1176 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was sys_stat */
1177 048f6b4d bellard
        MIPS_SYS(sys_lseek        , 3)
1178 048f6b4d bellard
        MIPS_SYS(sys_getpid        , 0)        /* 4020 */
1179 048f6b4d bellard
        MIPS_SYS(sys_mount        , 5)
1180 048f6b4d bellard
        MIPS_SYS(sys_oldumount        , 1)
1181 048f6b4d bellard
        MIPS_SYS(sys_setuid        , 1)
1182 048f6b4d bellard
        MIPS_SYS(sys_getuid        , 0)
1183 048f6b4d bellard
        MIPS_SYS(sys_stime        , 1)        /* 4025 */
1184 048f6b4d bellard
        MIPS_SYS(sys_ptrace        , 4)
1185 048f6b4d bellard
        MIPS_SYS(sys_alarm        , 1)
1186 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was sys_fstat */
1187 048f6b4d bellard
        MIPS_SYS(sys_pause        , 0)
1188 048f6b4d bellard
        MIPS_SYS(sys_utime        , 2)        /* 4030 */
1189 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1190 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1191 048f6b4d bellard
        MIPS_SYS(sys_access        , 2)
1192 048f6b4d bellard
        MIPS_SYS(sys_nice        , 1)
1193 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* 4035 */
1194 048f6b4d bellard
        MIPS_SYS(sys_sync        , 0)
1195 048f6b4d bellard
        MIPS_SYS(sys_kill        , 2)
1196 048f6b4d bellard
        MIPS_SYS(sys_rename        , 2)
1197 048f6b4d bellard
        MIPS_SYS(sys_mkdir        , 2)
1198 048f6b4d bellard
        MIPS_SYS(sys_rmdir        , 1)        /* 4040 */
1199 048f6b4d bellard
        MIPS_SYS(sys_dup                , 1)
1200 048f6b4d bellard
        MIPS_SYS(sys_pipe        , 0)
1201 048f6b4d bellard
        MIPS_SYS(sys_times        , 1)
1202 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1203 048f6b4d bellard
        MIPS_SYS(sys_brk                , 1)        /* 4045 */
1204 048f6b4d bellard
        MIPS_SYS(sys_setgid        , 1)
1205 048f6b4d bellard
        MIPS_SYS(sys_getgid        , 0)
1206 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was signal(2) */
1207 048f6b4d bellard
        MIPS_SYS(sys_geteuid        , 0)
1208 048f6b4d bellard
        MIPS_SYS(sys_getegid        , 0)        /* 4050 */
1209 048f6b4d bellard
        MIPS_SYS(sys_acct        , 0)
1210 048f6b4d bellard
        MIPS_SYS(sys_umount        , 2)
1211 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1212 048f6b4d bellard
        MIPS_SYS(sys_ioctl        , 3)
1213 048f6b4d bellard
        MIPS_SYS(sys_fcntl        , 3)        /* 4055 */
1214 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 2)
1215 048f6b4d bellard
        MIPS_SYS(sys_setpgid        , 2)
1216 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1217 048f6b4d bellard
        MIPS_SYS(sys_olduname        , 1)
1218 048f6b4d bellard
        MIPS_SYS(sys_umask        , 1)        /* 4060 */
1219 048f6b4d bellard
        MIPS_SYS(sys_chroot        , 1)
1220 048f6b4d bellard
        MIPS_SYS(sys_ustat        , 2)
1221 048f6b4d bellard
        MIPS_SYS(sys_dup2        , 2)
1222 048f6b4d bellard
        MIPS_SYS(sys_getppid        , 0)
1223 048f6b4d bellard
        MIPS_SYS(sys_getpgrp        , 0)        /* 4065 */
1224 048f6b4d bellard
        MIPS_SYS(sys_setsid        , 0)
1225 048f6b4d bellard
        MIPS_SYS(sys_sigaction        , 3)
1226 048f6b4d bellard
        MIPS_SYS(sys_sgetmask        , 0)
1227 048f6b4d bellard
        MIPS_SYS(sys_ssetmask        , 1)
1228 048f6b4d bellard
        MIPS_SYS(sys_setreuid        , 2)        /* 4070 */
1229 048f6b4d bellard
        MIPS_SYS(sys_setregid        , 2)
1230 048f6b4d bellard
        MIPS_SYS(sys_sigsuspend        , 0)
1231 048f6b4d bellard
        MIPS_SYS(sys_sigpending        , 1)
1232 048f6b4d bellard
        MIPS_SYS(sys_sethostname        , 2)
1233 048f6b4d bellard
        MIPS_SYS(sys_setrlimit        , 2)        /* 4075 */
1234 048f6b4d bellard
        MIPS_SYS(sys_getrlimit        , 2)
1235 048f6b4d bellard
        MIPS_SYS(sys_getrusage        , 2)
1236 048f6b4d bellard
        MIPS_SYS(sys_gettimeofday, 2)
1237 048f6b4d bellard
        MIPS_SYS(sys_settimeofday, 2)
1238 048f6b4d bellard
        MIPS_SYS(sys_getgroups        , 2)        /* 4080 */
1239 048f6b4d bellard
        MIPS_SYS(sys_setgroups        , 2)
1240 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* old_select */
1241 048f6b4d bellard
        MIPS_SYS(sys_symlink        , 2)
1242 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was sys_lstat */
1243 048f6b4d bellard
        MIPS_SYS(sys_readlink        , 3)        /* 4085 */
1244 048f6b4d bellard
        MIPS_SYS(sys_uselib        , 1)
1245 048f6b4d bellard
        MIPS_SYS(sys_swapon        , 2)
1246 048f6b4d bellard
        MIPS_SYS(sys_reboot        , 3)
1247 048f6b4d bellard
        MIPS_SYS(old_readdir        , 3)
1248 048f6b4d bellard
        MIPS_SYS(old_mmap        , 6)        /* 4090 */
1249 048f6b4d bellard
        MIPS_SYS(sys_munmap        , 2)
1250 048f6b4d bellard
        MIPS_SYS(sys_truncate        , 2)
1251 048f6b4d bellard
        MIPS_SYS(sys_ftruncate        , 2)
1252 048f6b4d bellard
        MIPS_SYS(sys_fchmod        , 2)
1253 048f6b4d bellard
        MIPS_SYS(sys_fchown        , 3)        /* 4095 */
1254 048f6b4d bellard
        MIPS_SYS(sys_getpriority        , 2)
1255 048f6b4d bellard
        MIPS_SYS(sys_setpriority        , 3)
1256 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1257 048f6b4d bellard
        MIPS_SYS(sys_statfs        , 2)
1258 048f6b4d bellard
        MIPS_SYS(sys_fstatfs        , 2)        /* 4100 */
1259 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was ioperm(2) */
1260 048f6b4d bellard
        MIPS_SYS(sys_socketcall        , 2)
1261 048f6b4d bellard
        MIPS_SYS(sys_syslog        , 3)
1262 048f6b4d bellard
        MIPS_SYS(sys_setitimer        , 3)
1263 048f6b4d bellard
        MIPS_SYS(sys_getitimer        , 2)        /* 4105 */
1264 048f6b4d bellard
        MIPS_SYS(sys_newstat        , 2)
1265 048f6b4d bellard
        MIPS_SYS(sys_newlstat        , 2)
1266 048f6b4d bellard
        MIPS_SYS(sys_newfstat        , 2)
1267 048f6b4d bellard
        MIPS_SYS(sys_uname        , 1)
1268 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* 4110 was iopl(2) */
1269 048f6b4d bellard
        MIPS_SYS(sys_vhangup        , 0)
1270 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was sys_idle() */
1271 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was sys_vm86 */
1272 048f6b4d bellard
        MIPS_SYS(sys_wait4        , 4)
1273 048f6b4d bellard
        MIPS_SYS(sys_swapoff        , 1)        /* 4115 */
1274 048f6b4d bellard
        MIPS_SYS(sys_sysinfo        , 1)
1275 048f6b4d bellard
        MIPS_SYS(sys_ipc                , 6)
1276 048f6b4d bellard
        MIPS_SYS(sys_fsync        , 1)
1277 048f6b4d bellard
        MIPS_SYS(sys_sigreturn        , 0)
1278 048f6b4d bellard
        MIPS_SYS(sys_clone        , 0)        /* 4120 */
1279 048f6b4d bellard
        MIPS_SYS(sys_setdomainname, 2)
1280 048f6b4d bellard
        MIPS_SYS(sys_newuname        , 1)
1281 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* sys_modify_ldt */
1282 048f6b4d bellard
        MIPS_SYS(sys_adjtimex        , 1)
1283 048f6b4d bellard
        MIPS_SYS(sys_mprotect        , 3)        /* 4125 */
1284 048f6b4d bellard
        MIPS_SYS(sys_sigprocmask        , 3)
1285 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was create_module */
1286 048f6b4d bellard
        MIPS_SYS(sys_init_module        , 5)
1287 048f6b4d bellard
        MIPS_SYS(sys_delete_module, 1)
1288 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* 4130        was get_kernel_syms */
1289 048f6b4d bellard
        MIPS_SYS(sys_quotactl        , 0)
1290 048f6b4d bellard
        MIPS_SYS(sys_getpgid        , 1)
1291 048f6b4d bellard
        MIPS_SYS(sys_fchdir        , 1)
1292 048f6b4d bellard
        MIPS_SYS(sys_bdflush        , 2)
1293 048f6b4d bellard
        MIPS_SYS(sys_sysfs        , 3)        /* 4135 */
1294 048f6b4d bellard
        MIPS_SYS(sys_personality        , 1)
1295 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* for afs_syscall */
1296 048f6b4d bellard
        MIPS_SYS(sys_setfsuid        , 1)
1297 048f6b4d bellard
        MIPS_SYS(sys_setfsgid        , 1)
1298 048f6b4d bellard
        MIPS_SYS(sys_llseek        , 5)        /* 4140 */
1299 048f6b4d bellard
        MIPS_SYS(sys_getdents        , 3)
1300 048f6b4d bellard
        MIPS_SYS(sys_select        , 5)
1301 048f6b4d bellard
        MIPS_SYS(sys_flock        , 2)
1302 048f6b4d bellard
        MIPS_SYS(sys_msync        , 3)
1303 048f6b4d bellard
        MIPS_SYS(sys_readv        , 3)        /* 4145 */
1304 048f6b4d bellard
        MIPS_SYS(sys_writev        , 3)
1305 048f6b4d bellard
        MIPS_SYS(sys_cacheflush        , 3)
1306 048f6b4d bellard
        MIPS_SYS(sys_cachectl        , 3)
1307 048f6b4d bellard
        MIPS_SYS(sys_sysmips        , 4)
1308 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* 4150 */
1309 048f6b4d bellard
        MIPS_SYS(sys_getsid        , 1)
1310 048f6b4d bellard
        MIPS_SYS(sys_fdatasync        , 0)
1311 048f6b4d bellard
        MIPS_SYS(sys_sysctl        , 1)
1312 048f6b4d bellard
        MIPS_SYS(sys_mlock        , 2)
1313 048f6b4d bellard
        MIPS_SYS(sys_munlock        , 2)        /* 4155 */
1314 048f6b4d bellard
        MIPS_SYS(sys_mlockall        , 1)
1315 048f6b4d bellard
        MIPS_SYS(sys_munlockall        , 0)
1316 048f6b4d bellard
        MIPS_SYS(sys_sched_setparam, 2)
1317 048f6b4d bellard
        MIPS_SYS(sys_sched_getparam, 2)
1318 048f6b4d bellard
        MIPS_SYS(sys_sched_setscheduler, 3)        /* 4160 */
1319 048f6b4d bellard
        MIPS_SYS(sys_sched_getscheduler, 1)
1320 048f6b4d bellard
        MIPS_SYS(sys_sched_yield        , 0)
1321 048f6b4d bellard
        MIPS_SYS(sys_sched_get_priority_max, 1)
1322 048f6b4d bellard
        MIPS_SYS(sys_sched_get_priority_min, 1)
1323 048f6b4d bellard
        MIPS_SYS(sys_sched_rr_get_interval, 2)        /* 4165 */
1324 048f6b4d bellard
        MIPS_SYS(sys_nanosleep,        2)
1325 048f6b4d bellard
        MIPS_SYS(sys_mremap        , 4)
1326 048f6b4d bellard
        MIPS_SYS(sys_accept        , 3)
1327 048f6b4d bellard
        MIPS_SYS(sys_bind        , 3)
1328 048f6b4d bellard
        MIPS_SYS(sys_connect        , 3)        /* 4170 */
1329 048f6b4d bellard
        MIPS_SYS(sys_getpeername        , 3)
1330 048f6b4d bellard
        MIPS_SYS(sys_getsockname        , 3)
1331 048f6b4d bellard
        MIPS_SYS(sys_getsockopt        , 5)
1332 048f6b4d bellard
        MIPS_SYS(sys_listen        , 2)
1333 048f6b4d bellard
        MIPS_SYS(sys_recv        , 4)        /* 4175 */
1334 048f6b4d bellard
        MIPS_SYS(sys_recvfrom        , 6)
1335 048f6b4d bellard
        MIPS_SYS(sys_recvmsg        , 3)
1336 048f6b4d bellard
        MIPS_SYS(sys_send        , 4)
1337 048f6b4d bellard
        MIPS_SYS(sys_sendmsg        , 3)
1338 048f6b4d bellard
        MIPS_SYS(sys_sendto        , 6)        /* 4180 */
1339 048f6b4d bellard
        MIPS_SYS(sys_setsockopt        , 5)
1340 048f6b4d bellard
        MIPS_SYS(sys_shutdown        , 2)
1341 048f6b4d bellard
        MIPS_SYS(sys_socket        , 3)
1342 048f6b4d bellard
        MIPS_SYS(sys_socketpair        , 4)
1343 048f6b4d bellard
        MIPS_SYS(sys_setresuid        , 3)        /* 4185 */
1344 048f6b4d bellard
        MIPS_SYS(sys_getresuid        , 3)
1345 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* was sys_query_module */
1346 048f6b4d bellard
        MIPS_SYS(sys_poll        , 3)
1347 048f6b4d bellard
        MIPS_SYS(sys_nfsservctl        , 3)
1348 048f6b4d bellard
        MIPS_SYS(sys_setresgid        , 3)        /* 4190 */
1349 048f6b4d bellard
        MIPS_SYS(sys_getresgid        , 3)
1350 048f6b4d bellard
        MIPS_SYS(sys_prctl        , 5)
1351 048f6b4d bellard
        MIPS_SYS(sys_rt_sigreturn, 0)
1352 048f6b4d bellard
        MIPS_SYS(sys_rt_sigaction, 4)
1353 048f6b4d bellard
        MIPS_SYS(sys_rt_sigprocmask, 4)        /* 4195 */
1354 048f6b4d bellard
        MIPS_SYS(sys_rt_sigpending, 2)
1355 048f6b4d bellard
        MIPS_SYS(sys_rt_sigtimedwait, 4)
1356 048f6b4d bellard
        MIPS_SYS(sys_rt_sigqueueinfo, 3)
1357 048f6b4d bellard
        MIPS_SYS(sys_rt_sigsuspend, 0)
1358 048f6b4d bellard
        MIPS_SYS(sys_pread64        , 6)        /* 4200 */
1359 048f6b4d bellard
        MIPS_SYS(sys_pwrite64        , 6)
1360 048f6b4d bellard
        MIPS_SYS(sys_chown        , 3)
1361 048f6b4d bellard
        MIPS_SYS(sys_getcwd        , 2)
1362 048f6b4d bellard
        MIPS_SYS(sys_capget        , 2)
1363 048f6b4d bellard
        MIPS_SYS(sys_capset        , 2)        /* 4205 */
1364 048f6b4d bellard
        MIPS_SYS(sys_sigaltstack        , 0)
1365 048f6b4d bellard
        MIPS_SYS(sys_sendfile        , 4)
1366 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1367 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1368 048f6b4d bellard
        MIPS_SYS(sys_mmap2        , 6)        /* 4210 */
1369 048f6b4d bellard
        MIPS_SYS(sys_truncate64        , 4)
1370 048f6b4d bellard
        MIPS_SYS(sys_ftruncate64        , 4)
1371 048f6b4d bellard
        MIPS_SYS(sys_stat64        , 2)
1372 048f6b4d bellard
        MIPS_SYS(sys_lstat64        , 2)
1373 048f6b4d bellard
        MIPS_SYS(sys_fstat64        , 2)        /* 4215 */
1374 048f6b4d bellard
        MIPS_SYS(sys_pivot_root        , 2)
1375 048f6b4d bellard
        MIPS_SYS(sys_mincore        , 3)
1376 048f6b4d bellard
        MIPS_SYS(sys_madvise        , 3)
1377 048f6b4d bellard
        MIPS_SYS(sys_getdents64        , 3)
1378 048f6b4d bellard
        MIPS_SYS(sys_fcntl64        , 3)        /* 4220 */
1379 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)
1380 048f6b4d bellard
        MIPS_SYS(sys_gettid        , 0)
1381 048f6b4d bellard
        MIPS_SYS(sys_readahead        , 5)
1382 048f6b4d bellard
        MIPS_SYS(sys_setxattr        , 5)
1383 048f6b4d bellard
        MIPS_SYS(sys_lsetxattr        , 5)        /* 4225 */
1384 048f6b4d bellard
        MIPS_SYS(sys_fsetxattr        , 5)
1385 048f6b4d bellard
        MIPS_SYS(sys_getxattr        , 4)
1386 048f6b4d bellard
        MIPS_SYS(sys_lgetxattr        , 4)
1387 048f6b4d bellard
        MIPS_SYS(sys_fgetxattr        , 4)
1388 048f6b4d bellard
        MIPS_SYS(sys_listxattr        , 3)        /* 4230 */
1389 048f6b4d bellard
        MIPS_SYS(sys_llistxattr        , 3)
1390 048f6b4d bellard
        MIPS_SYS(sys_flistxattr        , 3)
1391 048f6b4d bellard
        MIPS_SYS(sys_removexattr        , 2)
1392 048f6b4d bellard
        MIPS_SYS(sys_lremovexattr, 2)
1393 048f6b4d bellard
        MIPS_SYS(sys_fremovexattr, 2)        /* 4235 */
1394 048f6b4d bellard
        MIPS_SYS(sys_tkill        , 2)
1395 048f6b4d bellard
        MIPS_SYS(sys_sendfile64        , 5)
1396 048f6b4d bellard
        MIPS_SYS(sys_futex        , 2)
1397 048f6b4d bellard
        MIPS_SYS(sys_sched_setaffinity, 3)
1398 048f6b4d bellard
        MIPS_SYS(sys_sched_getaffinity, 3)        /* 4240 */
1399 048f6b4d bellard
        MIPS_SYS(sys_io_setup        , 2)
1400 048f6b4d bellard
        MIPS_SYS(sys_io_destroy        , 1)
1401 048f6b4d bellard
        MIPS_SYS(sys_io_getevents, 5)
1402 048f6b4d bellard
        MIPS_SYS(sys_io_submit        , 3)
1403 048f6b4d bellard
        MIPS_SYS(sys_io_cancel        , 3)        /* 4245 */
1404 048f6b4d bellard
        MIPS_SYS(sys_exit_group        , 1)
1405 048f6b4d bellard
        MIPS_SYS(sys_lookup_dcookie, 3)
1406 048f6b4d bellard
        MIPS_SYS(sys_epoll_create, 1)
1407 048f6b4d bellard
        MIPS_SYS(sys_epoll_ctl        , 4)
1408 048f6b4d bellard
        MIPS_SYS(sys_epoll_wait        , 3)        /* 4250 */
1409 048f6b4d bellard
        MIPS_SYS(sys_remap_file_pages, 5)
1410 048f6b4d bellard
        MIPS_SYS(sys_set_tid_address, 1)
1411 048f6b4d bellard
        MIPS_SYS(sys_restart_syscall, 0)
1412 048f6b4d bellard
        MIPS_SYS(sys_fadvise64_64, 7)
1413 048f6b4d bellard
        MIPS_SYS(sys_statfs64        , 3)        /* 4255 */
1414 048f6b4d bellard
        MIPS_SYS(sys_fstatfs64        , 2)
1415 048f6b4d bellard
        MIPS_SYS(sys_timer_create, 3)
1416 048f6b4d bellard
        MIPS_SYS(sys_timer_settime, 4)
1417 048f6b4d bellard
        MIPS_SYS(sys_timer_gettime, 2)
1418 048f6b4d bellard
        MIPS_SYS(sys_timer_getoverrun, 1)        /* 4260 */
1419 048f6b4d bellard
        MIPS_SYS(sys_timer_delete, 1)
1420 048f6b4d bellard
        MIPS_SYS(sys_clock_settime, 2)
1421 048f6b4d bellard
        MIPS_SYS(sys_clock_gettime, 2)
1422 048f6b4d bellard
        MIPS_SYS(sys_clock_getres, 2)
1423 048f6b4d bellard
        MIPS_SYS(sys_clock_nanosleep, 4)        /* 4265 */
1424 048f6b4d bellard
        MIPS_SYS(sys_tgkill        , 3)
1425 048f6b4d bellard
        MIPS_SYS(sys_utimes        , 2)
1426 048f6b4d bellard
        MIPS_SYS(sys_mbind        , 4)
1427 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* sys_get_mempolicy */
1428 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* 4270 sys_set_mempolicy */
1429 048f6b4d bellard
        MIPS_SYS(sys_mq_open        , 4)
1430 048f6b4d bellard
        MIPS_SYS(sys_mq_unlink        , 1)
1431 048f6b4d bellard
        MIPS_SYS(sys_mq_timedsend, 5)
1432 048f6b4d bellard
        MIPS_SYS(sys_mq_timedreceive, 5)
1433 048f6b4d bellard
        MIPS_SYS(sys_mq_notify        , 2)        /* 4275 */
1434 048f6b4d bellard
        MIPS_SYS(sys_mq_getsetattr, 3)
1435 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* sys_vserver */
1436 048f6b4d bellard
        MIPS_SYS(sys_waitid        , 4)
1437 048f6b4d bellard
        MIPS_SYS(sys_ni_syscall        , 0)        /* available, was setaltroot */
1438 048f6b4d bellard
        MIPS_SYS(sys_add_key        , 5)
1439 388bb21a ths
        MIPS_SYS(sys_request_key, 4)
1440 048f6b4d bellard
        MIPS_SYS(sys_keyctl        , 5)
1441 6f5b89a0 ths
        MIPS_SYS(sys_set_thread_area, 1)
1442 388bb21a ths
        MIPS_SYS(sys_inotify_init, 0)
1443 388bb21a ths
        MIPS_SYS(sys_inotify_add_watch, 3) /* 4285 */
1444 388bb21a ths
        MIPS_SYS(sys_inotify_rm_watch, 2)
1445 388bb21a ths
        MIPS_SYS(sys_migrate_pages, 4)
1446 388bb21a ths
        MIPS_SYS(sys_openat, 4)
1447 388bb21a ths
        MIPS_SYS(sys_mkdirat, 3)
1448 388bb21a ths
        MIPS_SYS(sys_mknodat, 4)        /* 4290 */
1449 388bb21a ths
        MIPS_SYS(sys_fchownat, 5)
1450 388bb21a ths
        MIPS_SYS(sys_futimesat, 3)
1451 388bb21a ths
        MIPS_SYS(sys_fstatat64, 4)
1452 388bb21a ths
        MIPS_SYS(sys_unlinkat, 3)
1453 388bb21a ths
        MIPS_SYS(sys_renameat, 4)        /* 4295 */
1454 388bb21a ths
        MIPS_SYS(sys_linkat, 5)
1455 388bb21a ths
        MIPS_SYS(sys_symlinkat, 3)
1456 388bb21a ths
        MIPS_SYS(sys_readlinkat, 4)
1457 388bb21a ths
        MIPS_SYS(sys_fchmodat, 3)
1458 388bb21a ths
        MIPS_SYS(sys_faccessat, 3)        /* 4300 */
1459 388bb21a ths
        MIPS_SYS(sys_pselect6, 6)
1460 388bb21a ths
        MIPS_SYS(sys_ppoll, 5)
1461 388bb21a ths
        MIPS_SYS(sys_unshare, 1)
1462 388bb21a ths
        MIPS_SYS(sys_splice, 4)
1463 388bb21a ths
        MIPS_SYS(sys_sync_file_range, 7) /* 4305 */
1464 388bb21a ths
        MIPS_SYS(sys_tee, 4)
1465 388bb21a ths
        MIPS_SYS(sys_vmsplice, 4)
1466 388bb21a ths
        MIPS_SYS(sys_move_pages, 6)
1467 388bb21a ths
        MIPS_SYS(sys_set_robust_list, 2)
1468 388bb21a ths
        MIPS_SYS(sys_get_robust_list, 3) /* 4310 */
1469 388bb21a ths
        MIPS_SYS(sys_kexec_load, 4)
1470 388bb21a ths
        MIPS_SYS(sys_getcpu, 3)
1471 388bb21a ths
        MIPS_SYS(sys_epoll_pwait, 6)
1472 388bb21a ths
        MIPS_SYS(sys_ioprio_set, 3)
1473 388bb21a ths
        MIPS_SYS(sys_ioprio_get, 2)
1474 048f6b4d bellard
};
1475 048f6b4d bellard
1476 048f6b4d bellard
#undef MIPS_SYS
1477 048f6b4d bellard
1478 048f6b4d bellard
void cpu_loop(CPUMIPSState *env)
1479 048f6b4d bellard
{
1480 048f6b4d bellard
    target_siginfo_t info;
1481 388bb21a ths
    int trapnr, ret;
1482 048f6b4d bellard
    unsigned int syscall_num;
1483 048f6b4d bellard
1484 048f6b4d bellard
    for(;;) {
1485 048f6b4d bellard
        trapnr = cpu_mips_exec(env);
1486 048f6b4d bellard
        switch(trapnr) {
1487 048f6b4d bellard
        case EXCP_SYSCALL:
1488 ead9360e ths
            syscall_num = env->gpr[2][env->current_tc] - 4000;
1489 ead9360e ths
            env->PC[env->current_tc] += 4;
1490 388bb21a ths
            if (syscall_num >= sizeof(mips_syscall_args)) {
1491 388bb21a ths
                ret = -ENOSYS;
1492 388bb21a ths
            } else {
1493 388bb21a ths
                int nb_args;
1494 388bb21a ths
                target_ulong sp_reg;
1495 388bb21a ths
                target_ulong arg5 = 0, arg6 = 0, arg7 = 0, arg8 = 0;
1496 388bb21a ths
1497 388bb21a ths
                nb_args = mips_syscall_args[syscall_num];
1498 ead9360e ths
                sp_reg = env->gpr[29][env->current_tc];
1499 388bb21a ths
                switch (nb_args) {
1500 388bb21a ths
                /* these arguments are taken from the stack */
1501 388bb21a ths
                case 8: arg8 = tgetl(sp_reg + 28);
1502 388bb21a ths
                case 7: arg7 = tgetl(sp_reg + 24);
1503 388bb21a ths
                case 6: arg6 = tgetl(sp_reg + 20);
1504 388bb21a ths
                case 5: arg5 = tgetl(sp_reg + 16);
1505 388bb21a ths
                default:
1506 388bb21a ths
                    break;
1507 048f6b4d bellard
                }
1508 ead9360e ths
                ret = do_syscall(env, env->gpr[2][env->current_tc],
1509 ead9360e ths
                                 env->gpr[4][env->current_tc],
1510 ead9360e ths
                                 env->gpr[5][env->current_tc],
1511 ead9360e ths
                                 env->gpr[6][env->current_tc],
1512 ead9360e ths
                                 env->gpr[7][env->current_tc],
1513 388bb21a ths
                                 arg5, arg6/*, arg7, arg8*/);
1514 388bb21a ths
            }
1515 388bb21a ths
            if ((unsigned int)ret >= (unsigned int)(-1133)) {
1516 ead9360e ths
                env->gpr[7][env->current_tc] = 1; /* error flag */
1517 388bb21a ths
                ret = -ret;
1518 388bb21a ths
            } else {
1519 ead9360e ths
                env->gpr[7][env->current_tc] = 0; /* error flag */
1520 048f6b4d bellard
            }
1521 ead9360e ths
            env->gpr[2][env->current_tc] = ret;
1522 048f6b4d bellard
            break;
1523 ca7c2b1b ths
        case EXCP_TLBL:
1524 ca7c2b1b ths
        case EXCP_TLBS:
1525 6900e84b bellard
        case EXCP_CpU:
1526 048f6b4d bellard
        case EXCP_RI:
1527 bc1ad2de bellard
            info.si_signo = TARGET_SIGILL;
1528 bc1ad2de bellard
            info.si_errno = 0;
1529 bc1ad2de bellard
            info.si_code = 0;
1530 bc1ad2de bellard
            queue_signal(info.si_signo, &info);
1531 048f6b4d bellard
            break;
1532 106ec879 bellard
        case EXCP_INTERRUPT:
1533 106ec879 bellard
            /* just indicate that signals should be handled asap */
1534 106ec879 bellard
            break;
1535 d08b2a28 pbrook
        case EXCP_DEBUG:
1536 d08b2a28 pbrook
            {
1537 d08b2a28 pbrook
                int sig;
1538 d08b2a28 pbrook
1539 d08b2a28 pbrook
                sig = gdb_handlesig (env, TARGET_SIGTRAP);
1540 d08b2a28 pbrook
                if (sig)
1541 d08b2a28 pbrook
                  {
1542 d08b2a28 pbrook
                    info.si_signo = sig;
1543 d08b2a28 pbrook
                    info.si_errno = 0;
1544 d08b2a28 pbrook
                    info.si_code = TARGET_TRAP_BRKPT;
1545 d08b2a28 pbrook
                    queue_signal(info.si_signo, &info);
1546 d08b2a28 pbrook
                  }
1547 d08b2a28 pbrook
            }
1548 d08b2a28 pbrook
            break;
1549 048f6b4d bellard
        default:
1550 048f6b4d bellard
            //        error:
1551 5fafdf24 ths
            fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
1552 048f6b4d bellard
                    trapnr);
1553 048f6b4d bellard
            cpu_dump_state(env, stderr, fprintf, 0);
1554 048f6b4d bellard
            abort();
1555 048f6b4d bellard
        }
1556 048f6b4d bellard
        process_pending_signals(env);
1557 048f6b4d bellard
    }
1558 048f6b4d bellard
}
1559 048f6b4d bellard
#endif
1560 048f6b4d bellard
1561 fdf9b3e8 bellard
#ifdef TARGET_SH4
1562 fdf9b3e8 bellard
void cpu_loop (CPUState *env)
1563 fdf9b3e8 bellard
{
1564 fdf9b3e8 bellard
    int trapnr, ret;
1565 355fb23d pbrook
    target_siginfo_t info;
1566 3b46e624 ths
1567 fdf9b3e8 bellard
    while (1) {
1568 fdf9b3e8 bellard
        trapnr = cpu_sh4_exec (env);
1569 3b46e624 ths
1570 fdf9b3e8 bellard
        switch (trapnr) {
1571 fdf9b3e8 bellard
        case 0x160:
1572 5fafdf24 ths
            ret = do_syscall(env,
1573 5fafdf24 ths
                             env->gregs[3],
1574 5fafdf24 ths
                             env->gregs[4],
1575 5fafdf24 ths
                             env->gregs[5],
1576 5fafdf24 ths
                             env->gregs[6],
1577 5fafdf24 ths
                             env->gregs[7],
1578 5fafdf24 ths
                             env->gregs[0],
1579 fdf9b3e8 bellard
                             0);
1580 9c2a9ea1 pbrook
            env->gregs[0] = ret;
1581 fdf9b3e8 bellard
            env->pc += 2;
1582 fdf9b3e8 bellard
            break;
1583 355fb23d pbrook
        case EXCP_DEBUG:
1584 355fb23d pbrook
            {
1585 355fb23d pbrook
                int sig;
1586 355fb23d pbrook
1587 355fb23d pbrook
                sig = gdb_handlesig (env, TARGET_SIGTRAP);
1588 355fb23d pbrook
                if (sig)
1589 355fb23d pbrook
                  {
1590 355fb23d pbrook
                    info.si_signo = sig;
1591 355fb23d pbrook
                    info.si_errno = 0;
1592 355fb23d pbrook
                    info.si_code = TARGET_TRAP_BRKPT;
1593 355fb23d pbrook
                    queue_signal(info.si_signo, &info);
1594 355fb23d pbrook
                  }
1595 355fb23d pbrook
            }
1596 355fb23d pbrook
            break;
1597 fdf9b3e8 bellard
        default:
1598 fdf9b3e8 bellard
            printf ("Unhandled trap: 0x%x\n", trapnr);
1599 fdf9b3e8 bellard
            cpu_dump_state(env, stderr, fprintf, 0);
1600 fdf9b3e8 bellard
            exit (1);
1601 fdf9b3e8 bellard
        }
1602 fdf9b3e8 bellard
        process_pending_signals (env);
1603 fdf9b3e8 bellard
    }
1604 fdf9b3e8 bellard
}
1605 fdf9b3e8 bellard
#endif
1606 fdf9b3e8 bellard
1607 e6e5906b pbrook
#ifdef TARGET_M68K
1608 e6e5906b pbrook
1609 e6e5906b pbrook
void cpu_loop(CPUM68KState *env)
1610 e6e5906b pbrook
{
1611 e6e5906b pbrook
    int trapnr;
1612 e6e5906b pbrook
    unsigned int n;
1613 e6e5906b pbrook
    target_siginfo_t info;
1614 e6e5906b pbrook
    TaskState *ts = env->opaque;
1615 3b46e624 ths
1616 e6e5906b pbrook
    for(;;) {
1617 e6e5906b pbrook
        trapnr = cpu_m68k_exec(env);
1618 e6e5906b pbrook
        switch(trapnr) {
1619 e6e5906b pbrook
        case EXCP_ILLEGAL:
1620 e6e5906b pbrook
            {
1621 e6e5906b pbrook
                if (ts->sim_syscalls) {
1622 e6e5906b pbrook
                    uint16_t nr;
1623 e6e5906b pbrook
                    nr = lduw(env->pc + 2);
1624 e6e5906b pbrook
                    env->pc += 4;
1625 e6e5906b pbrook
                    do_m68k_simcall(env, nr);
1626 e6e5906b pbrook
                } else {
1627 e6e5906b pbrook
                    goto do_sigill;
1628 e6e5906b pbrook
                }
1629 e6e5906b pbrook
            }
1630 e6e5906b pbrook
            break;
1631 a87295e8 pbrook
        case EXCP_HALT_INSN:
1632 e6e5906b pbrook
            /* Semihosing syscall.  */
1633 a87295e8 pbrook
            env->pc += 4;
1634 e6e5906b pbrook
            do_m68k_semihosting(env, env->dregs[0]);
1635 e6e5906b pbrook
            break;
1636 e6e5906b pbrook
        case EXCP_LINEA:
1637 e6e5906b pbrook
        case EXCP_LINEF:
1638 e6e5906b pbrook
        case EXCP_UNSUPPORTED:
1639 e6e5906b pbrook
        do_sigill:
1640 e6e5906b pbrook
            info.si_signo = SIGILL;
1641 e6e5906b pbrook
            info.si_errno = 0;
1642 e6e5906b pbrook
            info.si_code = TARGET_ILL_ILLOPN;
1643 e6e5906b pbrook
            info._sifields._sigfault._addr = env->pc;
1644 e6e5906b pbrook
            queue_signal(info.si_signo, &info);
1645 e6e5906b pbrook
            break;
1646 e6e5906b pbrook
        case EXCP_TRAP0:
1647 e6e5906b pbrook
            {
1648 e6e5906b pbrook
                ts->sim_syscalls = 0;
1649 e6e5906b pbrook
                n = env->dregs[0];
1650 e6e5906b pbrook
                env->pc += 2;
1651 5fafdf24 ths
                env->dregs[0] = do_syscall(env,
1652 5fafdf24 ths
                                          n,
1653 e6e5906b pbrook
                                          env->dregs[1],
1654 e6e5906b pbrook
                                          env->dregs[2],
1655 e6e5906b pbrook
                                          env->dregs[3],
1656 e6e5906b pbrook
                                          env->dregs[4],
1657 e6e5906b pbrook
                                          env->dregs[5],
1658 e6e5906b pbrook
                                          env->dregs[6]);
1659 e6e5906b pbrook
            }
1660 e6e5906b pbrook
            break;
1661 e6e5906b pbrook
        case EXCP_INTERRUPT:
1662 e6e5906b pbrook
            /* just indicate that signals should be handled asap */
1663 e6e5906b pbrook
            break;
1664 e6e5906b pbrook
        case EXCP_ACCESS:
1665 e6e5906b pbrook
            {
1666 e6e5906b pbrook
                info.si_signo = SIGSEGV;
1667 e6e5906b pbrook
                info.si_errno = 0;
1668 e6e5906b pbrook
                /* XXX: check env->error_code */
1669 e6e5906b pbrook
                info.si_code = TARGET_SEGV_MAPERR;
1670 e6e5906b pbrook
                info._sifields._sigfault._addr = env->mmu.ar;
1671 e6e5906b pbrook
                queue_signal(info.si_signo, &info);
1672 e6e5906b pbrook
            }
1673 e6e5906b pbrook
            break;
1674 e6e5906b pbrook
        case EXCP_DEBUG:
1675 e6e5906b pbrook
            {
1676 e6e5906b pbrook
                int sig;
1677 e6e5906b pbrook
1678 e6e5906b pbrook
                sig = gdb_handlesig (env, TARGET_SIGTRAP);
1679 e6e5906b pbrook
                if (sig)
1680 e6e5906b pbrook
                  {
1681 e6e5906b pbrook
                    info.si_signo = sig;
1682 e6e5906b pbrook
                    info.si_errno = 0;
1683 e6e5906b pbrook
                    info.si_code = TARGET_TRAP_BRKPT;
1684 e6e5906b pbrook
                    queue_signal(info.si_signo, &info);
1685 e6e5906b pbrook
                  }
1686 e6e5906b pbrook
            }
1687 e6e5906b pbrook
            break;
1688 e6e5906b pbrook
        default:
1689 5fafdf24 ths
            fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
1690 e6e5906b pbrook
                    trapnr);
1691 e6e5906b pbrook
            cpu_dump_state(env, stderr, fprintf, 0);
1692 e6e5906b pbrook
            abort();
1693 e6e5906b pbrook
        }
1694 e6e5906b pbrook
        process_pending_signals(env);
1695 e6e5906b pbrook
    }
1696 e6e5906b pbrook
}
1697 e6e5906b pbrook
#endif /* TARGET_M68K */
1698 e6e5906b pbrook
1699 7a3148a9 j_mayer
#ifdef TARGET_ALPHA
1700 7a3148a9 j_mayer
void cpu_loop (CPUState *env)
1701 7a3148a9 j_mayer
{
1702 e96efcfc j_mayer
    int trapnr;
1703 7a3148a9 j_mayer
    target_siginfo_t info;
1704 3b46e624 ths
1705 7a3148a9 j_mayer
    while (1) {
1706 7a3148a9 j_mayer
        trapnr = cpu_alpha_exec (env);
1707 3b46e624 ths
1708 7a3148a9 j_mayer
        switch (trapnr) {
1709 7a3148a9 j_mayer
        case EXCP_RESET:
1710 7a3148a9 j_mayer
            fprintf(stderr, "Reset requested. Exit\n");
1711 7a3148a9 j_mayer
            exit(1);
1712 7a3148a9 j_mayer
            break;
1713 7a3148a9 j_mayer
        case EXCP_MCHK:
1714 7a3148a9 j_mayer
            fprintf(stderr, "Machine check exception. Exit\n");
1715 7a3148a9 j_mayer
            exit(1);
1716 7a3148a9 j_mayer
            break;
1717 7a3148a9 j_mayer
        case EXCP_ARITH:
1718 7a3148a9 j_mayer
            fprintf(stderr, "Arithmetic trap.\n");
1719 7a3148a9 j_mayer
            exit(1);
1720 7a3148a9 j_mayer
            break;
1721 7a3148a9 j_mayer
        case EXCP_HW_INTERRUPT:
1722 5fafdf24 ths
            fprintf(stderr, "External interrupt. Exit\n");
1723 7a3148a9 j_mayer
            exit(1);
1724 7a3148a9 j_mayer
            break;
1725 7a3148a9 j_mayer
        case EXCP_DFAULT:
1726 7a3148a9 j_mayer
            fprintf(stderr, "MMU data fault\n");
1727 7a3148a9 j_mayer
            exit(1);
1728 7a3148a9 j_mayer
            break;
1729 7a3148a9 j_mayer
        case EXCP_DTB_MISS_PAL:
1730 7a3148a9 j_mayer
            fprintf(stderr, "MMU data TLB miss in PALcode\n");
1731 7a3148a9 j_mayer
            exit(1);
1732 7a3148a9 j_mayer
            break;
1733 7a3148a9 j_mayer
        case EXCP_ITB_MISS:
1734 7a3148a9 j_mayer
            fprintf(stderr, "MMU instruction TLB miss\n");
1735 7a3148a9 j_mayer
            exit(1);
1736 7a3148a9 j_mayer
            break;
1737 7a3148a9 j_mayer
        case EXCP_ITB_ACV:
1738 7a3148a9 j_mayer
            fprintf(stderr, "MMU instruction access violation\n");
1739 7a3148a9 j_mayer
            exit(1);
1740 7a3148a9 j_mayer
            break;
1741 7a3148a9 j_mayer
        case EXCP_DTB_MISS_NATIVE:
1742 7a3148a9 j_mayer
            fprintf(stderr, "MMU data TLB miss\n");
1743 7a3148a9 j_mayer
            exit(1);
1744 7a3148a9 j_mayer
            break;
1745 7a3148a9 j_mayer
        case EXCP_UNALIGN:
1746 7a3148a9 j_mayer
            fprintf(stderr, "Unaligned access\n");
1747 7a3148a9 j_mayer
            exit(1);
1748 7a3148a9 j_mayer
            break;
1749 7a3148a9 j_mayer
        case EXCP_OPCDEC:
1750 7a3148a9 j_mayer
            fprintf(stderr, "Invalid instruction\n");
1751 7a3148a9 j_mayer
            exit(1);
1752 7a3148a9 j_mayer
            break;
1753 7a3148a9 j_mayer
        case EXCP_FEN:
1754 7a3148a9 j_mayer
            fprintf(stderr, "Floating-point not allowed\n");
1755 7a3148a9 j_mayer
            exit(1);
1756 7a3148a9 j_mayer
            break;
1757 7a3148a9 j_mayer
        case EXCP_CALL_PAL ... (EXCP_CALL_PALP - 1):
1758 7a3148a9 j_mayer
            fprintf(stderr, "Call to PALcode\n");
1759 7a3148a9 j_mayer
            call_pal(env, (trapnr >> 6) | 0x80);
1760 7a3148a9 j_mayer
            break;
1761 7a3148a9 j_mayer
        case EXCP_CALL_PALP ... (EXCP_CALL_PALE - 1):
1762 7f75ffd3 blueswir1
            fprintf(stderr, "Privileged call to PALcode\n");
1763 7a3148a9 j_mayer
            exit(1);
1764 7a3148a9 j_mayer
            break;
1765 7a3148a9 j_mayer
        case EXCP_DEBUG:
1766 7a3148a9 j_mayer
            {
1767 7a3148a9 j_mayer
                int sig;
1768 7a3148a9 j_mayer
1769 7a3148a9 j_mayer
                sig = gdb_handlesig (env, TARGET_SIGTRAP);
1770 7a3148a9 j_mayer
                if (sig)
1771 7a3148a9 j_mayer
                  {
1772 7a3148a9 j_mayer
                    info.si_signo = sig;
1773 7a3148a9 j_mayer
                    info.si_errno = 0;
1774 7a3148a9 j_mayer
                    info.si_code = TARGET_TRAP_BRKPT;
1775 7a3148a9 j_mayer
                    queue_signal(info.si_signo, &info);
1776 7a3148a9 j_mayer
                  }
1777 7a3148a9 j_mayer
            }
1778 7a3148a9 j_mayer
            break;
1779 7a3148a9 j_mayer
        default:
1780 7a3148a9 j_mayer
            printf ("Unhandled trap: 0x%x\n", trapnr);
1781 7a3148a9 j_mayer
            cpu_dump_state(env, stderr, fprintf, 0);
1782 7a3148a9 j_mayer
            exit (1);
1783 7a3148a9 j_mayer
        }
1784 7a3148a9 j_mayer
        process_pending_signals (env);
1785 7a3148a9 j_mayer
    }
1786 7a3148a9 j_mayer
}
1787 7a3148a9 j_mayer
#endif /* TARGET_ALPHA */
1788 7a3148a9 j_mayer
1789 31e31b8a bellard
void usage(void)
1790 31e31b8a bellard
{
1791 84f2e8ef bellard
    printf("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003-2007 Fabrice Bellard\n"
1792 b1f9be31 j_mayer
           "usage: qemu-" TARGET_ARCH " [-h] [-g] [-d opts] [-L path] [-s size] [-cpu model] program [arguments...]\n"
1793 b346ff46 bellard
           "Linux CPU emulator (compiled for %s emulation)\n"
1794 d691f669 bellard
           "\n"
1795 b12b6a18 ths
           "-h                print this help\n"
1796 b12b6a18 ths
           "-g port           wait gdb connection to port\n"
1797 b12b6a18 ths
           "-L path           set the elf interpreter prefix (default=%s)\n"
1798 b12b6a18 ths
           "-s size           set the stack size in bytes (default=%ld)\n"
1799 b12b6a18 ths
           "-cpu model        select CPU (-cpu ? for list)\n"
1800 b12b6a18 ths
           "-drop-ld-preload  drop LD_PRELOAD for target process\n"
1801 54936004 bellard
           "\n"
1802 54936004 bellard
           "debug options:\n"
1803 c6981055 bellard
#ifdef USE_CODE_COPY
1804 c6981055 bellard
           "-no-code-copy   disable code copy acceleration\n"
1805 c6981055 bellard
#endif
1806 6f1f31c0 bellard
           "-d options   activate log (logfile=%s)\n"
1807 54936004 bellard
           "-p pagesize  set the host page size to 'pagesize'\n",
1808 b346ff46 bellard
           TARGET_ARCH,
1809 5fafdf24 ths
           interp_prefix,
1810 54936004 bellard
           x86_stack_size,
1811 54936004 bellard
           DEBUG_LOGFILE);
1812 74cd30b8 bellard
    _exit(1);
1813 31e31b8a bellard
}
1814 31e31b8a bellard
1815 9de5e440 bellard
/* XXX: currently only used for async signals (see signal.c) */
1816 b346ff46 bellard
CPUState *global_env;
1817 59faf6d6 bellard
1818 851e67a1 bellard
/* used to free thread contexts */
1819 851e67a1 bellard
TaskState *first_task_state;
1820 9de5e440 bellard
1821 31e31b8a bellard
int main(int argc, char **argv)
1822 31e31b8a bellard
{
1823 31e31b8a bellard
    const char *filename;
1824 b1f9be31 j_mayer
    const char *cpu_model;
1825 01ffc75b bellard
    struct target_pt_regs regs1, *regs = &regs1;
1826 31e31b8a bellard
    struct image_info info1, *info = &info1;
1827 851e67a1 bellard
    TaskState ts1, *ts = &ts1;
1828 b346ff46 bellard
    CPUState *env;
1829 586314f2 bellard
    int optind;
1830 d691f669 bellard
    const char *r;
1831 74c33bed bellard
    int gdbstub_port = 0;
1832 b12b6a18 ths
    int drop_ld_preload = 0, environ_count = 0;
1833 b12b6a18 ths
    char **target_environ, **wrk, **dst;
1834 b12b6a18 ths
1835 31e31b8a bellard
    if (argc <= 1)
1836 31e31b8a bellard
        usage();
1837 f801f97e bellard
1838 cc38b844 bellard
    /* init debug */
1839 cc38b844 bellard
    cpu_set_log_filename(DEBUG_LOGFILE);
1840 cc38b844 bellard
1841 b1f9be31 j_mayer
    cpu_model = NULL;
1842 586314f2 bellard
    optind = 1;
1843 d691f669 bellard
    for(;;) {
1844 d691f669 bellard
        if (optind >= argc)
1845 d691f669 bellard
            break;
1846 d691f669 bellard
        r = argv[optind];
1847 d691f669 bellard
        if (r[0] != '-')
1848 d691f669 bellard
            break;
1849 586314f2 bellard
        optind++;
1850 d691f669 bellard
        r++;
1851 d691f669 bellard
        if (!strcmp(r, "-")) {
1852 d691f669 bellard
            break;
1853 d691f669 bellard
        } else if (!strcmp(r, "d")) {
1854 e19e89a5 bellard
            int mask;
1855 e19e89a5 bellard
            CPULogItem *item;
1856 6f1f31c0 bellard
1857 6f1f31c0 bellard
            if (optind >= argc)
1858 6f1f31c0 bellard
                break;
1859 3b46e624 ths
1860 6f1f31c0 bellard
            r = argv[optind++];
1861 6f1f31c0 bellard
            mask = cpu_str_to_log_mask(r);
1862 e19e89a5 bellard
            if (!mask) {
1863 e19e89a5 bellard
                printf("Log items (comma separated):\n");
1864 e19e89a5 bellard
                for(item = cpu_log_items; item->mask != 0; item++) {
1865 e19e89a5 bellard
                    printf("%-10s %s\n", item->name, item->help);
1866 e19e89a5 bellard
                }
1867 e19e89a5 bellard
                exit(1);
1868 e19e89a5 bellard
            }
1869 e19e89a5 bellard
            cpu_set_log(mask);
1870 d691f669 bellard
        } else if (!strcmp(r, "s")) {
1871 d691f669 bellard
            r = argv[optind++];
1872 d691f669 bellard
            x86_stack_size = strtol(r, (char **)&r, 0);
1873 d691f669 bellard
            if (x86_stack_size <= 0)
1874 d691f669 bellard
                usage();
1875 d691f669 bellard
            if (*r == 'M')
1876 d691f669 bellard
                x86_stack_size *= 1024 * 1024;
1877 d691f669 bellard
            else if (*r == 'k' || *r == 'K')
1878 d691f669 bellard
                x86_stack_size *= 1024;
1879 d691f669 bellard
        } else if (!strcmp(r, "L")) {
1880 d691f669 bellard
            interp_prefix = argv[optind++];
1881 54936004 bellard
        } else if (!strcmp(r, "p")) {
1882 83fb7adf bellard
            qemu_host_page_size = atoi(argv[optind++]);
1883 83fb7adf bellard
            if (qemu_host_page_size == 0 ||
1884 83fb7adf bellard
                (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) {
1885 54936004 bellard
                fprintf(stderr, "page size must be a power of two\n");
1886 54936004 bellard
                exit(1);
1887 54936004 bellard
            }
1888 1fddef4b bellard
        } else if (!strcmp(r, "g")) {
1889 74c33bed bellard
            gdbstub_port = atoi(argv[optind++]);
1890 c5937220 pbrook
        } else if (!strcmp(r, "r")) {
1891 c5937220 pbrook
            qemu_uname_release = argv[optind++];
1892 b1f9be31 j_mayer
        } else if (!strcmp(r, "cpu")) {
1893 b1f9be31 j_mayer
            cpu_model = argv[optind++];
1894 b1f9be31 j_mayer
            if (strcmp(cpu_model, "?") == 0) {
1895 b1f9be31 j_mayer
#if defined(TARGET_PPC)
1896 b1f9be31 j_mayer
                ppc_cpu_list(stdout, &fprintf);
1897 b1f9be31 j_mayer
#elif defined(TARGET_ARM)
1898 b1f9be31 j_mayer
                arm_cpu_list();
1899 b1f9be31 j_mayer
#elif defined(TARGET_MIPS)
1900 b1f9be31 j_mayer
                mips_cpu_list(stdout, &fprintf);
1901 925fb139 blueswir1
#elif defined(TARGET_SPARC)
1902 925fb139 blueswir1
                sparc_cpu_list(stdout, &fprintf);
1903 b1f9be31 j_mayer
#endif
1904 cff4cbed ths
                _exit(1);
1905 b1f9be31 j_mayer
            }
1906 b12b6a18 ths
        } else if (!strcmp(r, "drop-ld-preload")) {
1907 b12b6a18 ths
            drop_ld_preload = 1;
1908 5fafdf24 ths
        } else
1909 c6981055 bellard
#ifdef USE_CODE_COPY
1910 c6981055 bellard
        if (!strcmp(r, "no-code-copy")) {
1911 c6981055 bellard
            code_copy_enabled = 0;
1912 5fafdf24 ths
        } else
1913 c6981055 bellard
#endif
1914 c6981055 bellard
        {
1915 d691f669 bellard
            usage();
1916 d691f669 bellard
        }
1917 586314f2 bellard
    }
1918 d691f669 bellard
    if (optind >= argc)
1919 d691f669 bellard
        usage();
1920 586314f2 bellard
    filename = argv[optind];
1921 586314f2 bellard
1922 31e31b8a bellard
    /* Zero out regs */
1923 01ffc75b bellard
    memset(regs, 0, sizeof(struct target_pt_regs));
1924 31e31b8a bellard
1925 31e31b8a bellard
    /* Zero out image_info */
1926 31e31b8a bellard
    memset(info, 0, sizeof(struct image_info));
1927 31e31b8a bellard
1928 74cd30b8 bellard
    /* Scan interp_prefix dir for replacement files. */
1929 74cd30b8 bellard
    init_paths(interp_prefix);
1930 74cd30b8 bellard
1931 83fb7adf bellard
    /* NOTE: we need to init the CPU at this stage to get
1932 83fb7adf bellard
       qemu_host_page_size */
1933 b346ff46 bellard
    env = cpu_init();
1934 15338fd7 bellard
    global_env = env;
1935 3b46e624 ths
1936 b12b6a18 ths
    wrk = environ;
1937 b12b6a18 ths
    while (*(wrk++))
1938 b12b6a18 ths
        environ_count++;
1939 b12b6a18 ths
1940 b12b6a18 ths
    target_environ = malloc((environ_count + 1) * sizeof(char *));
1941 b12b6a18 ths
    if (!target_environ)
1942 b12b6a18 ths
        abort();
1943 b12b6a18 ths
    for (wrk = environ, dst = target_environ; *wrk; wrk++) {
1944 b12b6a18 ths
        if (drop_ld_preload && !strncmp(*wrk, "LD_PRELOAD=", 11))
1945 b12b6a18 ths
            continue;
1946 b12b6a18 ths
        *(dst++) = strdup(*wrk);
1947 b12b6a18 ths
    }
1948 403f14ef ths
    *dst = NULL; /* NULL terminate target_environ */
1949 b12b6a18 ths
1950 b12b6a18 ths
    if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
1951 b12b6a18 ths
        printf("Error loading %s\n", filename);
1952 b12b6a18 ths
        _exit(1);
1953 b12b6a18 ths
    }
1954 b12b6a18 ths
1955 b12b6a18 ths
    for (wrk = target_environ; *wrk; wrk++) {
1956 b12b6a18 ths
        free(*wrk);
1957 31e31b8a bellard
    }
1958 3b46e624 ths
1959 b12b6a18 ths
    free(target_environ);
1960 b12b6a18 ths
1961 4b74fe1f bellard
    if (loglevel) {
1962 54936004 bellard
        page_dump(logfile);
1963 3b46e624 ths
1964 4b74fe1f bellard
        fprintf(logfile, "start_brk   0x%08lx\n" , info->start_brk);
1965 4b74fe1f bellard
        fprintf(logfile, "end_code    0x%08lx\n" , info->end_code);
1966 4b74fe1f bellard
        fprintf(logfile, "start_code  0x%08lx\n" , info->start_code);
1967 e5fe0c52 pbrook
        fprintf(logfile, "start_data  0x%08lx\n" , info->start_data);
1968 4b74fe1f bellard
        fprintf(logfile, "end_data    0x%08lx\n" , info->end_data);
1969 4b74fe1f bellard
        fprintf(logfile, "start_stack 0x%08lx\n" , info->start_stack);
1970 4b74fe1f bellard
        fprintf(logfile, "brk         0x%08lx\n" , info->brk);
1971 b346ff46 bellard
        fprintf(logfile, "entry       0x%08lx\n" , info->entry);
1972 4b74fe1f bellard
    }
1973 31e31b8a bellard
1974 53a5960a pbrook
    target_set_brk(info->brk);
1975 31e31b8a bellard
    syscall_init();
1976 66fb9763 bellard
    signal_init();
1977 31e31b8a bellard
1978 851e67a1 bellard
    /* build Task State */
1979 851e67a1 bellard
    memset(ts, 0, sizeof(TaskState));
1980 851e67a1 bellard
    env->opaque = ts;
1981 851e67a1 bellard
    ts->used = 1;
1982 978efd6a pbrook
    ts->info = info;
1983 59faf6d6 bellard
    env->user_mode_only = 1;
1984 3b46e624 ths
1985 b346ff46 bellard
#if defined(TARGET_I386)
1986 2e255c6b bellard
    cpu_x86_set_cpl(env, 3);
1987 2e255c6b bellard
1988 3802ce26 bellard
    env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
1989 1bde465e bellard
    env->hflags |= HF_PE_MASK;
1990 1bde465e bellard
    if (env->cpuid_features & CPUID_SSE) {
1991 1bde465e bellard
        env->cr[4] |= CR4_OSFXSR_MASK;
1992 1bde465e bellard
        env->hflags |= HF_OSFXSR_MASK;
1993 1bde465e bellard
    }
1994 1bde465e bellard
1995 415e561f bellard
    /* flags setup : we activate the IRQs by default as in user mode */
1996 415e561f bellard
    env->eflags |= IF_MASK;
1997 3b46e624 ths
1998 6dbad63e bellard
    /* linux register setup */
1999 84409ddb j_mayer
#if defined(TARGET_X86_64)
2000 84409ddb j_mayer
    env->regs[R_EAX] = regs->rax;
2001 84409ddb j_mayer
    env->regs[R_EBX] = regs->rbx;
2002 84409ddb j_mayer
    env->regs[R_ECX] = regs->rcx;
2003 84409ddb j_mayer
    env->regs[R_EDX] = regs->rdx;
2004 84409ddb j_mayer
    env->regs[R_ESI] = regs->rsi;
2005 84409ddb j_mayer
    env->regs[R_EDI] = regs->rdi;
2006 84409ddb j_mayer
    env->regs[R_EBP] = regs->rbp;
2007 84409ddb j_mayer
    env->regs[R_ESP] = regs->rsp;
2008 84409ddb j_mayer
    env->eip = regs->rip;
2009 84409ddb j_mayer
#else
2010 0ecfa993 bellard
    env->regs[R_EAX] = regs->eax;
2011 0ecfa993 bellard
    env->regs[R_EBX] = regs->ebx;
2012 0ecfa993 bellard
    env->regs[R_ECX] = regs->ecx;
2013 0ecfa993 bellard
    env->regs[R_EDX] = regs->edx;
2014 0ecfa993 bellard
    env->regs[R_ESI] = regs->esi;
2015 0ecfa993 bellard
    env->regs[R_EDI] = regs->edi;
2016 0ecfa993 bellard
    env->regs[R_EBP] = regs->ebp;
2017 0ecfa993 bellard
    env->regs[R_ESP] = regs->esp;
2018 dab2ed99 bellard
    env->eip = regs->eip;
2019 84409ddb j_mayer
#endif
2020 31e31b8a bellard
2021 f4beb510 bellard
    /* linux interrupt setup */
2022 53a5960a pbrook
    env->idt.base = h2g(idt_table);
2023 f4beb510 bellard
    env->idt.limit = sizeof(idt_table) - 1;
2024 f4beb510 bellard
    set_idt(0, 0);
2025 f4beb510 bellard
    set_idt(1, 0);
2026 f4beb510 bellard
    set_idt(2, 0);
2027 f4beb510 bellard
    set_idt(3, 3);
2028 f4beb510 bellard
    set_idt(4, 3);
2029 f4beb510 bellard
    set_idt(5, 3);
2030 f4beb510 bellard
    set_idt(6, 0);
2031 f4beb510 bellard
    set_idt(7, 0);
2032 f4beb510 bellard
    set_idt(8, 0);
2033 f4beb510 bellard
    set_idt(9, 0);
2034 f4beb510 bellard
    set_idt(10, 0);
2035 f4beb510 bellard
    set_idt(11, 0);
2036 f4beb510 bellard
    set_idt(12, 0);
2037 f4beb510 bellard
    set_idt(13, 0);
2038 f4beb510 bellard
    set_idt(14, 0);
2039 f4beb510 bellard
    set_idt(15, 0);
2040 f4beb510 bellard
    set_idt(16, 0);
2041 f4beb510 bellard
    set_idt(17, 0);
2042 f4beb510 bellard
    set_idt(18, 0);
2043 f4beb510 bellard
    set_idt(19, 0);
2044 f4beb510 bellard
    set_idt(0x80, 3);
2045 f4beb510 bellard
2046 6dbad63e bellard
    /* linux segment setup */
2047 53a5960a pbrook
    env->gdt.base = h2g(gdt_table);
2048 6dbad63e bellard
    env->gdt.limit = sizeof(gdt_table) - 1;
2049 f4beb510 bellard
    write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff,
2050 5fafdf24 ths
             DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
2051 f4beb510 bellard
             (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT));
2052 f4beb510 bellard
    write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff,
2053 5fafdf24 ths
             DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
2054 f4beb510 bellard
             (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT));
2055 6dbad63e bellard
    cpu_x86_load_seg(env, R_CS, __USER_CS);
2056 6dbad63e bellard
    cpu_x86_load_seg(env, R_DS, __USER_DS);
2057 6dbad63e bellard
    cpu_x86_load_seg(env, R_ES, __USER_DS);
2058 6dbad63e bellard
    cpu_x86_load_seg(env, R_SS, __USER_DS);
2059 6dbad63e bellard
    cpu_x86_load_seg(env, R_FS, __USER_DS);
2060 6dbad63e bellard
    cpu_x86_load_seg(env, R_GS, __USER_DS);
2061 92ccca6a bellard
2062 d6eb40f6 ths
    /* This hack makes Wine work... */
2063 d6eb40f6 ths
    env->segs[R_FS].selector = 0;
2064 b346ff46 bellard
#elif defined(TARGET_ARM)
2065 b346ff46 bellard
    {
2066 b346ff46 bellard
        int i;
2067 b1f9be31 j_mayer
        if (cpu_model == NULL)
2068 b1f9be31 j_mayer
            cpu_model = "arm926";
2069 b1f9be31 j_mayer
        cpu_arm_set_model(env, cpu_model);
2070 b5ff1b31 bellard
        cpsr_write(env, regs->uregs[16], 0xffffffff);
2071 b346ff46 bellard
        for(i = 0; i < 16; i++) {
2072 b346ff46 bellard
            env->regs[i] = regs->uregs[i];
2073 b346ff46 bellard
        }
2074 b346ff46 bellard
    }
2075 93ac68bc bellard
#elif defined(TARGET_SPARC)
2076 060366c5 bellard
    {
2077 060366c5 bellard
        int i;
2078 925fb139 blueswir1
        const sparc_def_t *def;
2079 925fb139 blueswir1
#ifdef TARGET_SPARC64
2080 925fb139 blueswir1
        if (cpu_model == NULL)
2081 925fb139 blueswir1
            cpu_model = "TI UltraSparc II";
2082 925fb139 blueswir1
#else
2083 925fb139 blueswir1
        if (cpu_model == NULL)
2084 925fb139 blueswir1
            cpu_model = "Fujitsu MB86904";
2085 925fb139 blueswir1
#endif
2086 925fb139 blueswir1
        sparc_find_by_name(cpu_model, &def);
2087 925fb139 blueswir1
        if (def == NULL) {
2088 925fb139 blueswir1
            fprintf(stderr, "Unable to find Sparc CPU definition\n");
2089 925fb139 blueswir1
            exit(1);
2090 925fb139 blueswir1
        }
2091 925fb139 blueswir1
        cpu_sparc_register(env, def);
2092 060366c5 bellard
        env->pc = regs->pc;
2093 060366c5 bellard
        env->npc = regs->npc;
2094 060366c5 bellard
        env->y = regs->y;
2095 060366c5 bellard
        for(i = 0; i < 8; i++)
2096 060366c5 bellard
            env->gregs[i] = regs->u_regs[i];
2097 060366c5 bellard
        for(i = 0; i < 8; i++)
2098 060366c5 bellard
            env->regwptr[i] = regs->u_regs[i + 8];
2099 060366c5 bellard
    }
2100 67867308 bellard
#elif defined(TARGET_PPC)
2101 67867308 bellard
    {
2102 3fc6c082 bellard
        ppc_def_t *def;
2103 67867308 bellard
        int i;
2104 3fc6c082 bellard
2105 3fc6c082 bellard
        /* Choose and initialise CPU */
2106 b1f9be31 j_mayer
        if (cpu_model == NULL)
2107 b1f9be31 j_mayer
            cpu_model = "750";
2108 b1f9be31 j_mayer
        ppc_find_by_name(cpu_model, &def);
2109 3fc6c082 bellard
        if (def == NULL) {
2110 c68ea704 bellard
            cpu_abort(env,
2111 3fc6c082 bellard
                      "Unable to find PowerPC CPU definition\n");
2112 3fc6c082 bellard
        }
2113 c68ea704 bellard
        cpu_ppc_register(env, def);
2114 3fc6c082 bellard
2115 61190b14 bellard
        for (i = 0; i < 32; i++) {
2116 4c2e770f bellard
            if (i != 12 && i != 6 && i != 13)
2117 61190b14 bellard
                env->msr[i] = (regs->msr >> i) & 1;
2118 61190b14 bellard
        }
2119 84409ddb j_mayer
#if defined(TARGET_PPC64)
2120 84409ddb j_mayer
        msr_sf = 1;
2121 84409ddb j_mayer
#endif
2122 67867308 bellard
        env->nip = regs->nip;
2123 67867308 bellard
        for(i = 0; i < 32; i++) {
2124 67867308 bellard
            env->gpr[i] = regs->gpr[i];
2125 67867308 bellard
        }
2126 67867308 bellard
    }
2127 e6e5906b pbrook
#elif defined(TARGET_M68K)
2128 e6e5906b pbrook
    {
2129 0633879f pbrook
        if (cpu_model == NULL)
2130 0402f767 pbrook
            cpu_model = "any";
2131 0633879f pbrook
        if (cpu_m68k_set_model(env, cpu_model)) {
2132 e6e5906b pbrook
            cpu_abort(cpu_single_env,
2133 e6e5906b pbrook
                      "Unable to find m68k CPU definition\n");
2134 e6e5906b pbrook
        }
2135 e6e5906b pbrook
        env->pc = regs->pc;
2136 e6e5906b pbrook
        env->dregs[0] = regs->d0;
2137 e6e5906b pbrook
        env->dregs[1] = regs->d1;
2138 e6e5906b pbrook
        env->dregs[2] = regs->d2;
2139 e6e5906b pbrook
        env->dregs[3] = regs->d3;
2140 e6e5906b pbrook
        env->dregs[4] = regs->d4;
2141 e6e5906b pbrook
        env->dregs[5] = regs->d5;
2142 e6e5906b pbrook
        env->dregs[6] = regs->d6;
2143 e6e5906b pbrook
        env->dregs[7] = regs->d7;
2144 e6e5906b pbrook
        env->aregs[0] = regs->a0;
2145 e6e5906b pbrook
        env->aregs[1] = regs->a1;
2146 e6e5906b pbrook
        env->aregs[2] = regs->a2;
2147 e6e5906b pbrook
        env->aregs[3] = regs->a3;
2148 e6e5906b pbrook
        env->aregs[4] = regs->a4;
2149 e6e5906b pbrook
        env->aregs[5] = regs->a5;
2150 e6e5906b pbrook
        env->aregs[6] = regs->a6;
2151 e6e5906b pbrook
        env->aregs[7] = regs->usp;
2152 e6e5906b pbrook
        env->sr = regs->sr;
2153 e6e5906b pbrook
        ts->sim_syscalls = 1;
2154 e6e5906b pbrook
    }
2155 048f6b4d bellard
#elif defined(TARGET_MIPS)
2156 048f6b4d bellard
    {
2157 cff4cbed ths
        mips_def_t *def;
2158 048f6b4d bellard
        int i;
2159 048f6b4d bellard
2160 cff4cbed ths
        /* Choose and initialise CPU */
2161 cff4cbed ths
        if (cpu_model == NULL)
2162 cff4cbed ths
            cpu_model = "24Kf";
2163 cff4cbed ths
        mips_find_by_name(cpu_model, &def);
2164 cff4cbed ths
        if (def == NULL)
2165 cff4cbed ths
            cpu_abort(env, "Unable to find MIPS CPU definition\n");
2166 cff4cbed ths
        cpu_mips_register(env, def);
2167 cff4cbed ths
2168 048f6b4d bellard
        for(i = 0; i < 32; i++) {
2169 ead9360e ths
            env->gpr[i][env->current_tc] = regs->regs[i];
2170 048f6b4d bellard
        }
2171 ead9360e ths
        env->PC[env->current_tc] = regs->cp0_epc;
2172 048f6b4d bellard
    }
2173 fdf9b3e8 bellard
#elif defined(TARGET_SH4)
2174 fdf9b3e8 bellard
    {
2175 fdf9b3e8 bellard
        int i;
2176 fdf9b3e8 bellard
2177 fdf9b3e8 bellard
        for(i = 0; i < 16; i++) {
2178 fdf9b3e8 bellard
            env->gregs[i] = regs->regs[i];
2179 fdf9b3e8 bellard
        }
2180 fdf9b3e8 bellard
        env->pc = regs->pc;
2181 fdf9b3e8 bellard
    }
2182 7a3148a9 j_mayer
#elif defined(TARGET_ALPHA)
2183 7a3148a9 j_mayer
    {
2184 7a3148a9 j_mayer
        int i;
2185 7a3148a9 j_mayer
2186 7a3148a9 j_mayer
        for(i = 0; i < 28; i++) {
2187 7a3148a9 j_mayer
            env->ir[i] = ((target_ulong *)regs)[i];
2188 7a3148a9 j_mayer
        }
2189 7a3148a9 j_mayer
        env->ipr[IPR_USP] = regs->usp;
2190 7a3148a9 j_mayer
        env->ir[30] = regs->usp;
2191 7a3148a9 j_mayer
        env->pc = regs->pc;
2192 7a3148a9 j_mayer
        env->unique = regs->unique;
2193 7a3148a9 j_mayer
    }
2194 b346ff46 bellard
#else
2195 b346ff46 bellard
#error unsupported target CPU
2196 b346ff46 bellard
#endif
2197 31e31b8a bellard
2198 a87295e8 pbrook
#if defined(TARGET_ARM) || defined(TARGET_M68K)
2199 a87295e8 pbrook
    ts->stack_base = info->start_stack;
2200 a87295e8 pbrook
    ts->heap_base = info->brk;
2201 a87295e8 pbrook
    /* This will be filled in on the first SYS_HEAPINFO call.  */
2202 a87295e8 pbrook
    ts->heap_limit = 0;
2203 a87295e8 pbrook
#endif
2204 a87295e8 pbrook
2205 74c33bed bellard
    if (gdbstub_port) {
2206 74c33bed bellard
        gdbserver_start (gdbstub_port);
2207 1fddef4b bellard
        gdb_handlesig(env, 0);
2208 1fddef4b bellard
    }
2209 1b6b029e bellard
    cpu_loop(env);
2210 1b6b029e bellard
    /* never exits */
2211 31e31b8a bellard
    return 0;
2212 31e31b8a bellard
}