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