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