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