]>
Commit | Line | Data |
---|---|---|
84778508 BS |
1 | /* |
2 | * qemu user main | |
3 | * | |
4 | * Copyright (c) 2003-2008 Fabrice Bellard | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
8167ee88 | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
84778508 BS |
18 | */ |
19 | #include <stdlib.h> | |
20 | #include <stdio.h> | |
21 | #include <stdarg.h> | |
22 | #include <string.h> | |
23 | #include <errno.h> | |
24 | #include <unistd.h> | |
25 | #include <machine/trap.h> | |
31fc12df BS |
26 | #include <sys/types.h> |
27 | #include <sys/mman.h> | |
84778508 BS |
28 | |
29 | #include "qemu.h" | |
30 | #include "qemu-common.h" | |
31 | /* For tb_lock */ | |
2b41f10e | 32 | #include "cpu.h" |
9002ec79 | 33 | #include "tcg.h" |
1de7afc9 PB |
34 | #include "qemu/timer.h" |
35 | #include "qemu/envlist.h" | |
fc0d96b4 | 36 | |
1b530a6d | 37 | int singlestep; |
2fa5d9ba BS |
38 | unsigned long mmap_min_addr; |
39 | unsigned long guest_base; | |
40 | int have_guest_base; | |
d6ef40bf | 41 | unsigned long reserved_va; |
1b530a6d | 42 | |
7ee2822c | 43 | static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; |
fccae322 | 44 | const char *qemu_uname_release; |
84778508 | 45 | extern char **environ; |
78cfb07f | 46 | enum BSDType bsd_type; |
84778508 BS |
47 | |
48 | /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so | |
49 | we allocate a bigger stack. Need a better solution, for example | |
50 | by remapping the process stack directly at the right place */ | |
51 | unsigned long x86_stack_size = 512 * 1024; | |
52 | ||
53 | void gemu_log(const char *fmt, ...) | |
54 | { | |
55 | va_list ap; | |
56 | ||
57 | va_start(ap, fmt); | |
58 | vfprintf(stderr, fmt, ap); | |
59 | va_end(ap); | |
60 | } | |
9399f095 | 61 | |
31fc12df | 62 | #if defined(TARGET_I386) |
b98e9ca8 | 63 | int cpu_get_pic_interrupt(CPUX86State *env) |
31fc12df BS |
64 | { |
65 | return -1; | |
66 | } | |
67 | #endif | |
68 | ||
9399f095 | 69 | /* These are no-ops because we are not threadsafe. */ |
9349b4f9 | 70 | static inline void cpu_exec_start(CPUArchState *env) |
9399f095 BS |
71 | { |
72 | } | |
73 | ||
9349b4f9 | 74 | static inline void cpu_exec_end(CPUArchState *env) |
9399f095 BS |
75 | { |
76 | } | |
77 | ||
78 | static inline void start_exclusive(void) | |
79 | { | |
80 | } | |
81 | ||
82 | static inline void end_exclusive(void) | |
83 | { | |
84 | } | |
85 | ||
86 | void fork_start(void) | |
87 | { | |
88 | } | |
89 | ||
90 | void fork_end(int child) | |
91 | { | |
92 | if (child) { | |
f7ec7f7b | 93 | gdbserver_fork(thread_cpu); |
9399f095 BS |
94 | } |
95 | } | |
96 | ||
97 | void cpu_list_lock(void) | |
98 | { | |
99 | } | |
100 | ||
101 | void cpu_list_unlock(void) | |
102 | { | |
103 | } | |
104 | ||
31fc12df BS |
105 | #ifdef TARGET_I386 |
106 | /***********************************************************/ | |
107 | /* CPUX86 core interface */ | |
108 | ||
31fc12df BS |
109 | uint64_t cpu_get_tsc(CPUX86State *env) |
110 | { | |
4a7428c5 | 111 | return cpu_get_host_ticks(); |
31fc12df BS |
112 | } |
113 | ||
114 | static void write_dt(void *ptr, unsigned long addr, unsigned long limit, | |
115 | int flags) | |
116 | { | |
117 | unsigned int e1, e2; | |
118 | uint32_t *p; | |
119 | e1 = (addr << 16) | (limit & 0xffff); | |
120 | e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000); | |
121 | e2 |= flags; | |
122 | p = ptr; | |
123 | p[0] = tswap32(e1); | |
124 | p[1] = tswap32(e2); | |
125 | } | |
126 | ||
127 | static uint64_t *idt_table; | |
128 | #ifdef TARGET_X86_64 | |
129 | static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, | |
130 | uint64_t addr, unsigned int sel) | |
131 | { | |
132 | uint32_t *p, e1, e2; | |
133 | e1 = (addr & 0xffff) | (sel << 16); | |
134 | e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); | |
135 | p = ptr; | |
136 | p[0] = tswap32(e1); | |
137 | p[1] = tswap32(e2); | |
138 | p[2] = tswap32(addr >> 32); | |
139 | p[3] = 0; | |
140 | } | |
141 | /* only dpl matters as we do only user space emulation */ | |
142 | static void set_idt(int n, unsigned int dpl) | |
143 | { | |
144 | set_gate64(idt_table + n * 2, 0, dpl, 0, 0); | |
145 | } | |
146 | #else | |
147 | static void set_gate(void *ptr, unsigned int type, unsigned int dpl, | |
148 | uint32_t addr, unsigned int sel) | |
149 | { | |
150 | uint32_t *p, e1, e2; | |
151 | e1 = (addr & 0xffff) | (sel << 16); | |
152 | e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); | |
153 | p = ptr; | |
154 | p[0] = tswap32(e1); | |
155 | p[1] = tswap32(e2); | |
156 | } | |
157 | ||
158 | /* only dpl matters as we do only user space emulation */ | |
159 | static void set_idt(int n, unsigned int dpl) | |
160 | { | |
161 | set_gate(idt_table + n, 0, dpl, 0, 0); | |
162 | } | |
163 | #endif | |
164 | ||
78cfb07f | 165 | void cpu_loop(CPUX86State *env) |
31fc12df | 166 | { |
ea3e9847 PC |
167 | X86CPU *cpu = x86_env_get_cpu(env); |
168 | CPUState *cs = CPU(cpu); | |
31fc12df BS |
169 | int trapnr; |
170 | abi_ulong pc; | |
171 | //target_siginfo_t info; | |
172 | ||
173 | for(;;) { | |
cb48f67a | 174 | trapnr = cpu_x86_exec(cs); |
31fc12df BS |
175 | switch(trapnr) { |
176 | case 0x80: | |
177 | /* syscall from int $0x80 */ | |
78cfb07f JL |
178 | if (bsd_type == target_freebsd) { |
179 | abi_ulong params = (abi_ulong) env->regs[R_ESP] + | |
180 | sizeof(int32_t); | |
181 | int32_t syscall_nr = env->regs[R_EAX]; | |
182 | int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; | |
183 | ||
184 | if (syscall_nr == TARGET_FREEBSD_NR_syscall) { | |
185 | get_user_s32(syscall_nr, params); | |
186 | params += sizeof(int32_t); | |
187 | } else if (syscall_nr == TARGET_FREEBSD_NR___syscall) { | |
188 | get_user_s32(syscall_nr, params); | |
189 | params += sizeof(int64_t); | |
190 | } | |
191 | get_user_s32(arg1, params); | |
192 | params += sizeof(int32_t); | |
193 | get_user_s32(arg2, params); | |
194 | params += sizeof(int32_t); | |
195 | get_user_s32(arg3, params); | |
196 | params += sizeof(int32_t); | |
197 | get_user_s32(arg4, params); | |
198 | params += sizeof(int32_t); | |
199 | get_user_s32(arg5, params); | |
200 | params += sizeof(int32_t); | |
201 | get_user_s32(arg6, params); | |
202 | params += sizeof(int32_t); | |
203 | get_user_s32(arg7, params); | |
204 | params += sizeof(int32_t); | |
205 | get_user_s32(arg8, params); | |
206 | env->regs[R_EAX] = do_freebsd_syscall(env, | |
207 | syscall_nr, | |
208 | arg1, | |
209 | arg2, | |
210 | arg3, | |
211 | arg4, | |
212 | arg5, | |
213 | arg6, | |
214 | arg7, | |
215 | arg8); | |
216 | } else { //if (bsd_type == target_openbsd) | |
217 | env->regs[R_EAX] = do_openbsd_syscall(env, | |
218 | env->regs[R_EAX], | |
219 | env->regs[R_EBX], | |
220 | env->regs[R_ECX], | |
221 | env->regs[R_EDX], | |
222 | env->regs[R_ESI], | |
223 | env->regs[R_EDI], | |
224 | env->regs[R_EBP]); | |
225 | } | |
226 | if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) { | |
227 | env->regs[R_EAX] = -env->regs[R_EAX]; | |
228 | env->eflags |= CC_C; | |
229 | } else { | |
230 | env->eflags &= ~CC_C; | |
231 | } | |
31fc12df BS |
232 | break; |
233 | #ifndef TARGET_ABI32 | |
234 | case EXCP_SYSCALL: | |
5ba18547 | 235 | /* syscall from syscall instruction */ |
78cfb07f JL |
236 | if (bsd_type == target_freebsd) |
237 | env->regs[R_EAX] = do_freebsd_syscall(env, | |
238 | env->regs[R_EAX], | |
239 | env->regs[R_EDI], | |
240 | env->regs[R_ESI], | |
241 | env->regs[R_EDX], | |
242 | env->regs[R_ECX], | |
243 | env->regs[8], | |
244 | env->regs[9], 0, 0); | |
245 | else { //if (bsd_type == target_openbsd) | |
246 | env->regs[R_EAX] = do_openbsd_syscall(env, | |
247 | env->regs[R_EAX], | |
248 | env->regs[R_EDI], | |
249 | env->regs[R_ESI], | |
250 | env->regs[R_EDX], | |
251 | env->regs[10], | |
252 | env->regs[8], | |
253 | env->regs[9]); | |
254 | } | |
31fc12df | 255 | env->eip = env->exception_next_eip; |
78cfb07f JL |
256 | if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) { |
257 | env->regs[R_EAX] = -env->regs[R_EAX]; | |
258 | env->eflags |= CC_C; | |
259 | } else { | |
260 | env->eflags &= ~CC_C; | |
261 | } | |
31fc12df BS |
262 | break; |
263 | #endif | |
264 | #if 0 | |
265 | case EXCP0B_NOSEG: | |
266 | case EXCP0C_STACK: | |
267 | info.si_signo = SIGBUS; | |
268 | info.si_errno = 0; | |
269 | info.si_code = TARGET_SI_KERNEL; | |
270 | info._sifields._sigfault._addr = 0; | |
271 | queue_signal(env, info.si_signo, &info); | |
272 | break; | |
273 | case EXCP0D_GPF: | |
274 | /* XXX: potential problem if ABI32 */ | |
275 | #ifndef TARGET_X86_64 | |
276 | if (env->eflags & VM_MASK) { | |
277 | handle_vm86_fault(env); | |
278 | } else | |
279 | #endif | |
280 | { | |
281 | info.si_signo = SIGSEGV; | |
282 | info.si_errno = 0; | |
283 | info.si_code = TARGET_SI_KERNEL; | |
284 | info._sifields._sigfault._addr = 0; | |
285 | queue_signal(env, info.si_signo, &info); | |
286 | } | |
287 | break; | |
288 | case EXCP0E_PAGE: | |
289 | info.si_signo = SIGSEGV; | |
290 | info.si_errno = 0; | |
291 | if (!(env->error_code & 1)) | |
292 | info.si_code = TARGET_SEGV_MAPERR; | |
293 | else | |
294 | info.si_code = TARGET_SEGV_ACCERR; | |
295 | info._sifields._sigfault._addr = env->cr[2]; | |
296 | queue_signal(env, info.si_signo, &info); | |
297 | break; | |
298 | case EXCP00_DIVZ: | |
299 | #ifndef TARGET_X86_64 | |
300 | if (env->eflags & VM_MASK) { | |
301 | handle_vm86_trap(env, trapnr); | |
302 | } else | |
303 | #endif | |
304 | { | |
305 | /* division by zero */ | |
306 | info.si_signo = SIGFPE; | |
307 | info.si_errno = 0; | |
308 | info.si_code = TARGET_FPE_INTDIV; | |
309 | info._sifields._sigfault._addr = env->eip; | |
310 | queue_signal(env, info.si_signo, &info); | |
311 | } | |
312 | break; | |
313 | case EXCP01_DB: | |
314 | case EXCP03_INT3: | |
315 | #ifndef TARGET_X86_64 | |
316 | if (env->eflags & VM_MASK) { | |
317 | handle_vm86_trap(env, trapnr); | |
318 | } else | |
319 | #endif | |
320 | { | |
321 | info.si_signo = SIGTRAP; | |
322 | info.si_errno = 0; | |
323 | if (trapnr == EXCP01_DB) { | |
324 | info.si_code = TARGET_TRAP_BRKPT; | |
325 | info._sifields._sigfault._addr = env->eip; | |
326 | } else { | |
327 | info.si_code = TARGET_SI_KERNEL; | |
328 | info._sifields._sigfault._addr = 0; | |
329 | } | |
330 | queue_signal(env, info.si_signo, &info); | |
331 | } | |
332 | break; | |
333 | case EXCP04_INTO: | |
334 | case EXCP05_BOUND: | |
335 | #ifndef TARGET_X86_64 | |
336 | if (env->eflags & VM_MASK) { | |
337 | handle_vm86_trap(env, trapnr); | |
338 | } else | |
339 | #endif | |
340 | { | |
341 | info.si_signo = SIGSEGV; | |
342 | info.si_errno = 0; | |
343 | info.si_code = TARGET_SI_KERNEL; | |
344 | info._sifields._sigfault._addr = 0; | |
345 | queue_signal(env, info.si_signo, &info); | |
346 | } | |
347 | break; | |
348 | case EXCP06_ILLOP: | |
349 | info.si_signo = SIGILL; | |
350 | info.si_errno = 0; | |
351 | info.si_code = TARGET_ILL_ILLOPN; | |
352 | info._sifields._sigfault._addr = env->eip; | |
353 | queue_signal(env, info.si_signo, &info); | |
354 | break; | |
355 | #endif | |
356 | case EXCP_INTERRUPT: | |
357 | /* just indicate that signals should be handled asap */ | |
358 | break; | |
359 | #if 0 | |
360 | case EXCP_DEBUG: | |
361 | { | |
362 | int sig; | |
363 | ||
364 | sig = gdb_handlesig (env, TARGET_SIGTRAP); | |
365 | if (sig) | |
366 | { | |
367 | info.si_signo = sig; | |
368 | info.si_errno = 0; | |
369 | info.si_code = TARGET_TRAP_BRKPT; | |
370 | queue_signal(env, info.si_signo, &info); | |
371 | } | |
372 | } | |
373 | break; | |
374 | #endif | |
375 | default: | |
376 | pc = env->segs[R_CS].base + env->eip; | |
377 | fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n", | |
378 | (long)pc, trapnr); | |
379 | abort(); | |
380 | } | |
381 | process_pending_signals(env); | |
382 | } | |
383 | } | |
384 | #endif | |
385 | ||
84778508 BS |
386 | #ifdef TARGET_SPARC |
387 | #define SPARC64_STACK_BIAS 2047 | |
388 | ||
389 | //#define DEBUG_WIN | |
390 | /* WARNING: dealing with register windows _is_ complicated. More info | |
391 | can be found at http://www.sics.se/~psm/sparcstack.html */ | |
392 | static inline int get_reg_index(CPUSPARCState *env, int cwp, int index) | |
393 | { | |
394 | index = (index + cwp * 16) % (16 * env->nwindows); | |
395 | /* wrap handling : if cwp is on the last window, then we use the | |
396 | registers 'after' the end */ | |
397 | if (index < 8 && env->cwp == env->nwindows - 1) | |
398 | index += 16 * env->nwindows; | |
399 | return index; | |
400 | } | |
401 | ||
402 | /* save the register window 'cwp1' */ | |
403 | static inline void save_window_offset(CPUSPARCState *env, int cwp1) | |
404 | { | |
405 | unsigned int i; | |
406 | abi_ulong sp_ptr; | |
407 | ||
408 | sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)]; | |
409 | #ifdef TARGET_SPARC64 | |
410 | if (sp_ptr & 3) | |
411 | sp_ptr += SPARC64_STACK_BIAS; | |
412 | #endif | |
413 | #if defined(DEBUG_WIN) | |
414 | printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n", | |
415 | sp_ptr, cwp1); | |
416 | #endif | |
417 | for(i = 0; i < 16; i++) { | |
418 | /* FIXME - what to do if put_user() fails? */ | |
419 | put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr); | |
420 | sp_ptr += sizeof(abi_ulong); | |
421 | } | |
422 | } | |
423 | ||
424 | static void save_window(CPUSPARCState *env) | |
425 | { | |
426 | #ifndef TARGET_SPARC64 | |
427 | unsigned int new_wim; | |
428 | new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) & | |
429 | ((1LL << env->nwindows) - 1); | |
430 | save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2)); | |
431 | env->wim = new_wim; | |
432 | #else | |
433 | save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2)); | |
434 | env->cansave++; | |
435 | env->canrestore--; | |
436 | #endif | |
437 | } | |
438 | ||
439 | static void restore_window(CPUSPARCState *env) | |
440 | { | |
441 | #ifndef TARGET_SPARC64 | |
442 | unsigned int new_wim; | |
443 | #endif | |
444 | unsigned int i, cwp1; | |
445 | abi_ulong sp_ptr; | |
446 | ||
447 | #ifndef TARGET_SPARC64 | |
448 | new_wim = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) & | |
449 | ((1LL << env->nwindows) - 1); | |
450 | #endif | |
451 | ||
452 | /* restore the invalid window */ | |
453 | cwp1 = cpu_cwp_inc(env, env->cwp + 1); | |
454 | sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)]; | |
455 | #ifdef TARGET_SPARC64 | |
456 | if (sp_ptr & 3) | |
457 | sp_ptr += SPARC64_STACK_BIAS; | |
458 | #endif | |
459 | #if defined(DEBUG_WIN) | |
460 | printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n", | |
461 | sp_ptr, cwp1); | |
462 | #endif | |
463 | for(i = 0; i < 16; i++) { | |
464 | /* FIXME - what to do if get_user() fails? */ | |
465 | get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr); | |
466 | sp_ptr += sizeof(abi_ulong); | |
467 | } | |
468 | #ifdef TARGET_SPARC64 | |
469 | env->canrestore++; | |
470 | if (env->cleanwin < env->nwindows - 1) | |
471 | env->cleanwin++; | |
472 | env->cansave--; | |
473 | #else | |
474 | env->wim = new_wim; | |
475 | #endif | |
476 | } | |
477 | ||
478 | static void flush_windows(CPUSPARCState *env) | |
479 | { | |
480 | int offset, cwp1; | |
481 | ||
482 | offset = 1; | |
483 | for(;;) { | |
484 | /* if restore would invoke restore_window(), then we can stop */ | |
485 | cwp1 = cpu_cwp_inc(env, env->cwp + offset); | |
486 | #ifndef TARGET_SPARC64 | |
487 | if (env->wim & (1 << cwp1)) | |
488 | break; | |
489 | #else | |
490 | if (env->canrestore == 0) | |
491 | break; | |
492 | env->cansave++; | |
493 | env->canrestore--; | |
494 | #endif | |
495 | save_window_offset(env, cwp1); | |
496 | offset++; | |
497 | } | |
498 | cwp1 = cpu_cwp_inc(env, env->cwp + 1); | |
499 | #ifndef TARGET_SPARC64 | |
500 | /* set wim so that restore will reload the registers */ | |
501 | env->wim = 1 << cwp1; | |
502 | #endif | |
503 | #if defined(DEBUG_WIN) | |
504 | printf("flush_windows: nb=%d\n", offset - 1); | |
505 | #endif | |
506 | } | |
507 | ||
78cfb07f | 508 | void cpu_loop(CPUSPARCState *env) |
84778508 | 509 | { |
878096ee | 510 | CPUState *cs = CPU(sparc_env_get_cpu(env)); |
84778508 BS |
511 | int trapnr, ret, syscall_nr; |
512 | //target_siginfo_t info; | |
513 | ||
514 | while (1) { | |
ea3e9847 | 515 | trapnr = cpu_sparc_exec(cs); |
84778508 BS |
516 | |
517 | switch (trapnr) { | |
77b9435f BS |
518 | #ifndef TARGET_SPARC64 |
519 | case 0x80: | |
520 | #else | |
78cfb07f JL |
521 | /* FreeBSD uses 0x141 for syscalls too */ |
522 | case 0x141: | |
523 | if (bsd_type != target_freebsd) | |
524 | goto badtrap; | |
84778508 | 525 | case 0x100: |
77b9435f | 526 | #endif |
84778508 | 527 | syscall_nr = env->gregs[1]; |
84778508 BS |
528 | if (bsd_type == target_freebsd) |
529 | ret = do_freebsd_syscall(env, syscall_nr, | |
530 | env->regwptr[0], env->regwptr[1], | |
531 | env->regwptr[2], env->regwptr[3], | |
78cfb07f | 532 | env->regwptr[4], env->regwptr[5], 0, 0); |
84778508 BS |
533 | else if (bsd_type == target_netbsd) |
534 | ret = do_netbsd_syscall(env, syscall_nr, | |
535 | env->regwptr[0], env->regwptr[1], | |
536 | env->regwptr[2], env->regwptr[3], | |
537 | env->regwptr[4], env->regwptr[5]); | |
cdba95bd BS |
538 | else { //if (bsd_type == target_openbsd) |
539 | #if defined(TARGET_SPARC64) | |
540 | syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG | | |
541 | TARGET_OPENBSD_SYSCALL_G2RFLAG); | |
542 | #endif | |
84778508 BS |
543 | ret = do_openbsd_syscall(env, syscall_nr, |
544 | env->regwptr[0], env->regwptr[1], | |
545 | env->regwptr[2], env->regwptr[3], | |
546 | env->regwptr[4], env->regwptr[5]); | |
cdba95bd | 547 | } |
84778508 | 548 | if ((unsigned int)ret >= (unsigned int)(-515)) { |
78cfb07f | 549 | ret = -ret; |
84778508 BS |
550 | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) |
551 | env->xcc |= PSR_CARRY; | |
552 | #else | |
553 | env->psr |= PSR_CARRY; | |
554 | #endif | |
555 | } else { | |
556 | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) | |
557 | env->xcc &= ~PSR_CARRY; | |
558 | #else | |
559 | env->psr &= ~PSR_CARRY; | |
560 | #endif | |
561 | } | |
562 | env->regwptr[0] = ret; | |
563 | /* next instruction */ | |
cdba95bd BS |
564 | #if defined(TARGET_SPARC64) |
565 | if (bsd_type == target_openbsd && | |
566 | env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) { | |
84778508 BS |
567 | env->pc = env->gregs[2]; |
568 | env->npc = env->pc + 4; | |
cdba95bd BS |
569 | } else if (bsd_type == target_openbsd && |
570 | env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) { | |
84778508 BS |
571 | env->pc = env->gregs[7]; |
572 | env->npc = env->pc + 4; | |
573 | } else { | |
574 | env->pc = env->npc; | |
575 | env->npc = env->npc + 4; | |
576 | } | |
577 | #else | |
578 | env->pc = env->npc; | |
579 | env->npc = env->npc + 4; | |
580 | #endif | |
581 | break; | |
582 | case 0x83: /* flush windows */ | |
583 | #ifdef TARGET_ABI32 | |
584 | case 0x103: | |
585 | #endif | |
586 | flush_windows(env); | |
587 | /* next instruction */ | |
588 | env->pc = env->npc; | |
589 | env->npc = env->npc + 4; | |
590 | break; | |
591 | #ifndef TARGET_SPARC64 | |
592 | case TT_WIN_OVF: /* window overflow */ | |
593 | save_window(env); | |
594 | break; | |
595 | case TT_WIN_UNF: /* window underflow */ | |
596 | restore_window(env); | |
597 | break; | |
598 | case TT_TFAULT: | |
599 | case TT_DFAULT: | |
600 | #if 0 | |
601 | { | |
602 | info.si_signo = SIGSEGV; | |
603 | info.si_errno = 0; | |
604 | /* XXX: check env->error_code */ | |
605 | info.si_code = TARGET_SEGV_MAPERR; | |
606 | info._sifields._sigfault._addr = env->mmuregs[4]; | |
607 | queue_signal(env, info.si_signo, &info); | |
608 | } | |
609 | #endif | |
610 | break; | |
611 | #else | |
612 | case TT_SPILL: /* window overflow */ | |
613 | save_window(env); | |
614 | break; | |
615 | case TT_FILL: /* window underflow */ | |
616 | restore_window(env); | |
617 | break; | |
618 | case TT_TFAULT: | |
619 | case TT_DFAULT: | |
620 | #if 0 | |
621 | { | |
622 | info.si_signo = SIGSEGV; | |
623 | info.si_errno = 0; | |
624 | /* XXX: check env->error_code */ | |
625 | info.si_code = TARGET_SEGV_MAPERR; | |
626 | if (trapnr == TT_DFAULT) | |
627 | info._sifields._sigfault._addr = env->dmmuregs[4]; | |
628 | else | |
629 | info._sifields._sigfault._addr = env->tsptr->tpc; | |
630 | //queue_signal(env, info.si_signo, &info); | |
631 | } | |
632 | #endif | |
633 | break; | |
634 | #endif | |
635 | case EXCP_INTERRUPT: | |
636 | /* just indicate that signals should be handled asap */ | |
637 | break; | |
638 | case EXCP_DEBUG: | |
639 | { | |
640 | int sig; | |
641 | ||
db6b81d4 | 642 | sig = gdb_handlesig(cs, TARGET_SIGTRAP); |
84778508 BS |
643 | #if 0 |
644 | if (sig) | |
645 | { | |
646 | info.si_signo = sig; | |
647 | info.si_errno = 0; | |
648 | info.si_code = TARGET_TRAP_BRKPT; | |
649 | //queue_signal(env, info.si_signo, &info); | |
650 | } | |
651 | #endif | |
652 | } | |
653 | break; | |
654 | default: | |
78cfb07f JL |
655 | #ifdef TARGET_SPARC64 |
656 | badtrap: | |
657 | #endif | |
84778508 | 658 | printf ("Unhandled trap: 0x%x\n", trapnr); |
878096ee | 659 | cpu_dump_state(cs, stderr, fprintf, 0); |
84778508 BS |
660 | exit (1); |
661 | } | |
662 | process_pending_signals (env); | |
663 | } | |
664 | } | |
665 | ||
666 | #endif | |
667 | ||
668 | static void usage(void) | |
669 | { | |
2e59915d PB |
670 | printf("qemu-" TARGET_NAME " version " QEMU_VERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" |
671 | "usage: qemu-" TARGET_NAME " [options] program [arguments...]\n" | |
84778508 BS |
672 | "BSD CPU emulator (compiled for %s emulation)\n" |
673 | "\n" | |
674 | "Standard options:\n" | |
675 | "-h print this help\n" | |
676 | "-g port wait gdb connection to port\n" | |
677 | "-L path set the elf interpreter prefix (default=%s)\n" | |
678 | "-s size set the stack size in bytes (default=%ld)\n" | |
c8057f95 | 679 | "-cpu model select CPU (-cpu help for list)\n" |
84778508 | 680 | "-drop-ld-preload drop LD_PRELOAD for target process\n" |
fc0d96b4 BS |
681 | "-E var=value sets/modifies targets environment variable(s)\n" |
682 | "-U var unsets targets environment variable(s)\n" | |
2fa5d9ba | 683 | "-B address set guest_base address to address\n" |
84778508 BS |
684 | "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n" |
685 | "\n" | |
686 | "Debug options:\n" | |
989b697d PM |
687 | "-d item1[,...] enable logging of specified items\n" |
688 | " (use '-d help' for a list of log items)\n" | |
689 | "-D logfile write logs to 'logfile' (default stderr)\n" | |
690 | "-p pagesize set the host page size to 'pagesize'\n" | |
691 | "-singlestep always run in singlestep mode\n" | |
692 | "-strace log system calls\n" | |
84778508 BS |
693 | "\n" |
694 | "Environment variables:\n" | |
695 | "QEMU_STRACE Print system calls and arguments similar to the\n" | |
696 | " 'strace' program. Enable by setting to any value.\n" | |
fc0d96b4 BS |
697 | "You can use -E and -U options to set/unset environment variables\n" |
698 | "for target process. It is possible to provide several variables\n" | |
699 | "by repeating the option. For example:\n" | |
700 | " -E var1=val2 -E var2=val2 -U LD_PRELOAD -U LD_DEBUG\n" | |
701 | "Note that if you provide several changes to single variable\n" | |
702 | "last change will stay in effect.\n" | |
84778508 | 703 | , |
2e59915d | 704 | TARGET_NAME, |
84778508 | 705 | interp_prefix, |
989b697d | 706 | x86_stack_size); |
2d18e637 | 707 | exit(1); |
84778508 BS |
708 | } |
709 | ||
dca1173c | 710 | THREAD CPUState *thread_cpu; |
84778508 BS |
711 | |
712 | /* Assumes contents are already zeroed. */ | |
713 | void init_task_state(TaskState *ts) | |
714 | { | |
715 | int i; | |
716 | ||
717 | ts->used = 1; | |
718 | ts->first_free = ts->sigqueue_table; | |
719 | for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) { | |
720 | ts->sigqueue_table[i].next = &ts->sigqueue_table[i + 1]; | |
721 | } | |
722 | ts->sigqueue_table[i].next = NULL; | |
723 | } | |
724 | ||
725 | int main(int argc, char **argv) | |
726 | { | |
727 | const char *filename; | |
728 | const char *cpu_model; | |
989b697d | 729 | const char *log_file = NULL; |
c235d738 | 730 | const char *log_mask = NULL; |
84778508 BS |
731 | struct target_pt_regs regs1, *regs = ®s1; |
732 | struct image_info info1, *info = &info1; | |
733 | TaskState ts1, *ts = &ts1; | |
9349b4f9 | 734 | CPUArchState *env; |
db6b81d4 | 735 | CPUState *cpu; |
84778508 BS |
736 | int optind; |
737 | const char *r; | |
738 | int gdbstub_port = 0; | |
fc0d96b4 BS |
739 | char **target_environ, **wrk; |
740 | envlist_t *envlist = NULL; | |
78cfb07f | 741 | bsd_type = target_openbsd; |
84778508 BS |
742 | |
743 | if (argc <= 1) | |
744 | usage(); | |
745 | ||
ce008c1f AF |
746 | module_call_init(MODULE_INIT_QOM); |
747 | ||
fc0d96b4 BS |
748 | if ((envlist = envlist_create()) == NULL) { |
749 | (void) fprintf(stderr, "Unable to allocate envlist\n"); | |
750 | exit(1); | |
751 | } | |
752 | ||
753 | /* add current environment into the list */ | |
754 | for (wrk = environ; *wrk != NULL; wrk++) { | |
755 | (void) envlist_setenv(envlist, *wrk); | |
756 | } | |
757 | ||
84778508 | 758 | cpu_model = NULL; |
0c62de2f JL |
759 | #if defined(cpudef_setup) |
760 | cpudef_setup(); /* parse cpu definitions in target config file (TBD) */ | |
761 | #endif | |
762 | ||
84778508 BS |
763 | optind = 1; |
764 | for(;;) { | |
765 | if (optind >= argc) | |
766 | break; | |
767 | r = argv[optind]; | |
768 | if (r[0] != '-') | |
769 | break; | |
770 | optind++; | |
771 | r++; | |
772 | if (!strcmp(r, "-")) { | |
773 | break; | |
774 | } else if (!strcmp(r, "d")) { | |
c235d738 | 775 | if (optind >= argc) { |
84778508 | 776 | break; |
84778508 | 777 | } |
c235d738 MF |
778 | log_mask = argv[optind++]; |
779 | } else if (!strcmp(r, "D")) { | |
780 | if (optind >= argc) { | |
781 | break; | |
782 | } | |
783 | log_file = argv[optind++]; | |
fc0d96b4 BS |
784 | } else if (!strcmp(r, "E")) { |
785 | r = argv[optind++]; | |
786 | if (envlist_setenv(envlist, r) != 0) | |
787 | usage(); | |
f66724c9 SW |
788 | } else if (!strcmp(r, "ignore-environment")) { |
789 | envlist_free(envlist); | |
790 | if ((envlist = envlist_create()) == NULL) { | |
791 | (void) fprintf(stderr, "Unable to allocate envlist\n"); | |
792 | exit(1); | |
793 | } | |
fc0d96b4 BS |
794 | } else if (!strcmp(r, "U")) { |
795 | r = argv[optind++]; | |
796 | if (envlist_unsetenv(envlist, r) != 0) | |
797 | usage(); | |
84778508 BS |
798 | } else if (!strcmp(r, "s")) { |
799 | r = argv[optind++]; | |
800 | x86_stack_size = strtol(r, (char **)&r, 0); | |
801 | if (x86_stack_size <= 0) | |
802 | usage(); | |
803 | if (*r == 'M') | |
804 | x86_stack_size *= 1024 * 1024; | |
805 | else if (*r == 'k' || *r == 'K') | |
806 | x86_stack_size *= 1024; | |
807 | } else if (!strcmp(r, "L")) { | |
808 | interp_prefix = argv[optind++]; | |
809 | } else if (!strcmp(r, "p")) { | |
810 | qemu_host_page_size = atoi(argv[optind++]); | |
811 | if (qemu_host_page_size == 0 || | |
812 | (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { | |
813 | fprintf(stderr, "page size must be a power of two\n"); | |
814 | exit(1); | |
815 | } | |
816 | } else if (!strcmp(r, "g")) { | |
817 | gdbstub_port = atoi(argv[optind++]); | |
818 | } else if (!strcmp(r, "r")) { | |
819 | qemu_uname_release = argv[optind++]; | |
820 | } else if (!strcmp(r, "cpu")) { | |
821 | cpu_model = argv[optind++]; | |
c8057f95 | 822 | if (is_help_option(cpu_model)) { |
84778508 BS |
823 | /* XXX: implement xxx_cpu_list for targets that still miss it */ |
824 | #if defined(cpu_list) | |
825 | cpu_list(stdout, &fprintf); | |
826 | #endif | |
2d18e637 | 827 | exit(1); |
84778508 | 828 | } |
2fa5d9ba BS |
829 | } else if (!strcmp(r, "B")) { |
830 | guest_base = strtol(argv[optind++], NULL, 0); | |
831 | have_guest_base = 1; | |
84778508 | 832 | } else if (!strcmp(r, "drop-ld-preload")) { |
fc0d96b4 | 833 | (void) envlist_unsetenv(envlist, "LD_PRELOAD"); |
84778508 BS |
834 | } else if (!strcmp(r, "bsd")) { |
835 | if (!strcasecmp(argv[optind], "freebsd")) { | |
836 | bsd_type = target_freebsd; | |
837 | } else if (!strcasecmp(argv[optind], "netbsd")) { | |
838 | bsd_type = target_netbsd; | |
839 | } else if (!strcasecmp(argv[optind], "openbsd")) { | |
840 | bsd_type = target_openbsd; | |
841 | } else { | |
842 | usage(); | |
843 | } | |
844 | optind++; | |
1b530a6d AJ |
845 | } else if (!strcmp(r, "singlestep")) { |
846 | singlestep = 1; | |
84778508 BS |
847 | } else if (!strcmp(r, "strace")) { |
848 | do_strace = 1; | |
849 | } else | |
850 | { | |
851 | usage(); | |
852 | } | |
853 | } | |
84778508 | 854 | |
c235d738 | 855 | /* init debug */ |
9a7e5424 | 856 | qemu_set_log_filename(log_file); |
c235d738 MF |
857 | if (log_mask) { |
858 | int mask; | |
c235d738 | 859 | |
4fde1eba | 860 | mask = qemu_str_to_log_mask(log_mask); |
c235d738 | 861 | if (!mask) { |
59a6fa6e | 862 | qemu_print_log_usage(stdout); |
c235d738 MF |
863 | exit(1); |
864 | } | |
24537a01 | 865 | qemu_set_log(mask); |
c235d738 MF |
866 | } |
867 | ||
4b5dfd82 PM |
868 | if (optind >= argc) { |
869 | usage(); | |
870 | } | |
871 | filename = argv[optind]; | |
872 | ||
84778508 BS |
873 | /* Zero out regs */ |
874 | memset(regs, 0, sizeof(struct target_pt_regs)); | |
875 | ||
876 | /* Zero out image_info */ | |
877 | memset(info, 0, sizeof(struct image_info)); | |
878 | ||
879 | /* Scan interp_prefix dir for replacement files. */ | |
880 | init_paths(interp_prefix); | |
881 | ||
882 | if (cpu_model == NULL) { | |
31fc12df BS |
883 | #if defined(TARGET_I386) |
884 | #ifdef TARGET_X86_64 | |
885 | cpu_model = "qemu64"; | |
886 | #else | |
887 | cpu_model = "qemu32"; | |
888 | #endif | |
889 | #elif defined(TARGET_SPARC) | |
84778508 BS |
890 | #ifdef TARGET_SPARC64 |
891 | cpu_model = "TI UltraSparc II"; | |
892 | #else | |
893 | cpu_model = "Fujitsu MB86904"; | |
894 | #endif | |
895 | #else | |
896 | cpu_model = "any"; | |
897 | #endif | |
898 | } | |
d5ab9713 | 899 | tcg_exec_init(0); |
84778508 BS |
900 | /* NOTE: we need to init the CPU at this stage to get |
901 | qemu_host_page_size */ | |
2994fd96 EH |
902 | cpu = cpu_init(cpu_model); |
903 | if (!cpu) { | |
84778508 BS |
904 | fprintf(stderr, "Unable to find CPU definition\n"); |
905 | exit(1); | |
906 | } | |
2994fd96 | 907 | env = cpu->env_ptr; |
77868120 | 908 | #if defined(TARGET_SPARC) || defined(TARGET_PPC) |
db6b81d4 | 909 | cpu_reset(cpu); |
b55a37c9 | 910 | #endif |
db6b81d4 | 911 | thread_cpu = cpu; |
84778508 BS |
912 | |
913 | if (getenv("QEMU_STRACE")) { | |
914 | do_strace = 1; | |
915 | } | |
916 | ||
fc0d96b4 BS |
917 | target_environ = envlist_to_environ(envlist, NULL); |
918 | envlist_free(envlist); | |
919 | ||
2fa5d9ba BS |
920 | /* |
921 | * Now that page sizes are configured in cpu_init() we can do | |
922 | * proper page alignment for guest_base. | |
923 | */ | |
924 | guest_base = HOST_PAGE_ALIGN(guest_base); | |
925 | ||
926 | /* | |
927 | * Read in mmap_min_addr kernel parameter. This value is used | |
928 | * When loading the ELF image to determine whether guest_base | |
929 | * is needed. | |
930 | * | |
931 | * When user has explicitly set the quest base, we skip this | |
932 | * test. | |
933 | */ | |
934 | if (!have_guest_base) { | |
935 | FILE *fp; | |
936 | ||
937 | if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) { | |
938 | unsigned long tmp; | |
939 | if (fscanf(fp, "%lu", &tmp) == 1) { | |
940 | mmap_min_addr = tmp; | |
941 | qemu_log("host mmap_min_addr=0x%lx\n", mmap_min_addr); | |
942 | } | |
943 | fclose(fp); | |
944 | } | |
945 | } | |
84778508 BS |
946 | |
947 | if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) { | |
948 | printf("Error loading %s\n", filename); | |
949 | _exit(1); | |
950 | } | |
951 | ||
952 | for (wrk = target_environ; *wrk; wrk++) { | |
953 | free(*wrk); | |
954 | } | |
955 | ||
956 | free(target_environ); | |
957 | ||
2e77eac6 | 958 | if (qemu_log_enabled()) { |
2fa5d9ba | 959 | qemu_log("guest_base 0x%lx\n", guest_base); |
2e77eac6 BS |
960 | log_page_dump(); |
961 | ||
962 | qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); | |
963 | qemu_log("end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); | |
964 | qemu_log("start_code 0x" TARGET_ABI_FMT_lx "\n", | |
965 | info->start_code); | |
966 | qemu_log("start_data 0x" TARGET_ABI_FMT_lx "\n", | |
967 | info->start_data); | |
968 | qemu_log("end_data 0x" TARGET_ABI_FMT_lx "\n", info->end_data); | |
969 | qemu_log("start_stack 0x" TARGET_ABI_FMT_lx "\n", | |
970 | info->start_stack); | |
971 | qemu_log("brk 0x" TARGET_ABI_FMT_lx "\n", info->brk); | |
972 | qemu_log("entry 0x" TARGET_ABI_FMT_lx "\n", info->entry); | |
973 | } | |
84778508 BS |
974 | |
975 | target_set_brk(info->brk); | |
976 | syscall_init(); | |
977 | signal_init(); | |
978 | ||
9002ec79 RH |
979 | /* Now that we've loaded the binary, GUEST_BASE is fixed. Delay |
980 | generating the prologue until now so that the prologue can take | |
981 | the real value of GUEST_BASE into account. */ | |
982 | tcg_prologue_init(&tcg_ctx); | |
9002ec79 | 983 | |
84778508 BS |
984 | /* build Task State */ |
985 | memset(ts, 0, sizeof(TaskState)); | |
986 | init_task_state(ts); | |
987 | ts->info = info; | |
0429a971 | 988 | cpu->opaque = ts; |
84778508 | 989 | |
31fc12df | 990 | #if defined(TARGET_I386) |
31fc12df | 991 | env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; |
b98dbc90 | 992 | env->hflags |= HF_PE_MASK | HF_CPL_MASK; |
0514ef2f | 993 | if (env->features[FEAT_1_EDX] & CPUID_SSE) { |
31fc12df BS |
994 | env->cr[4] |= CR4_OSFXSR_MASK; |
995 | env->hflags |= HF_OSFXSR_MASK; | |
996 | } | |
997 | #ifndef TARGET_ABI32 | |
998 | /* enable 64 bit mode if possible */ | |
0514ef2f | 999 | if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) { |
31fc12df BS |
1000 | fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n"); |
1001 | exit(1); | |
1002 | } | |
1003 | env->cr[4] |= CR4_PAE_MASK; | |
1004 | env->efer |= MSR_EFER_LMA | MSR_EFER_LME; | |
1005 | env->hflags |= HF_LMA_MASK; | |
1006 | #endif | |
1007 | ||
1008 | /* flags setup : we activate the IRQs by default as in user mode */ | |
1009 | env->eflags |= IF_MASK; | |
1010 | ||
1011 | /* linux register setup */ | |
1012 | #ifndef TARGET_ABI32 | |
1013 | env->regs[R_EAX] = regs->rax; | |
1014 | env->regs[R_EBX] = regs->rbx; | |
1015 | env->regs[R_ECX] = regs->rcx; | |
1016 | env->regs[R_EDX] = regs->rdx; | |
1017 | env->regs[R_ESI] = regs->rsi; | |
1018 | env->regs[R_EDI] = regs->rdi; | |
1019 | env->regs[R_EBP] = regs->rbp; | |
1020 | env->regs[R_ESP] = regs->rsp; | |
1021 | env->eip = regs->rip; | |
1022 | #else | |
1023 | env->regs[R_EAX] = regs->eax; | |
1024 | env->regs[R_EBX] = regs->ebx; | |
1025 | env->regs[R_ECX] = regs->ecx; | |
1026 | env->regs[R_EDX] = regs->edx; | |
1027 | env->regs[R_ESI] = regs->esi; | |
1028 | env->regs[R_EDI] = regs->edi; | |
1029 | env->regs[R_EBP] = regs->ebp; | |
1030 | env->regs[R_ESP] = regs->esp; | |
1031 | env->eip = regs->eip; | |
1032 | #endif | |
1033 | ||
1034 | /* linux interrupt setup */ | |
1035 | #ifndef TARGET_ABI32 | |
1036 | env->idt.limit = 511; | |
1037 | #else | |
1038 | env->idt.limit = 255; | |
1039 | #endif | |
1040 | env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), | |
1041 | PROT_READ|PROT_WRITE, | |
1042 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); | |
1043 | idt_table = g2h(env->idt.base); | |
1044 | set_idt(0, 0); | |
1045 | set_idt(1, 0); | |
1046 | set_idt(2, 0); | |
1047 | set_idt(3, 3); | |
1048 | set_idt(4, 3); | |
1049 | set_idt(5, 0); | |
1050 | set_idt(6, 0); | |
1051 | set_idt(7, 0); | |
1052 | set_idt(8, 0); | |
1053 | set_idt(9, 0); | |
1054 | set_idt(10, 0); | |
1055 | set_idt(11, 0); | |
1056 | set_idt(12, 0); | |
1057 | set_idt(13, 0); | |
1058 | set_idt(14, 0); | |
1059 | set_idt(15, 0); | |
1060 | set_idt(16, 0); | |
1061 | set_idt(17, 0); | |
1062 | set_idt(18, 0); | |
1063 | set_idt(19, 0); | |
1064 | set_idt(0x80, 3); | |
1065 | ||
1066 | /* linux segment setup */ | |
1067 | { | |
1068 | uint64_t *gdt_table; | |
1069 | env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, | |
1070 | PROT_READ|PROT_WRITE, | |
1071 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); | |
1072 | env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; | |
1073 | gdt_table = g2h(env->gdt.base); | |
1074 | #ifdef TARGET_ABI32 | |
1075 | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, | |
1076 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | | |
1077 | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); | |
1078 | #else | |
1079 | /* 64 bit code segment */ | |
1080 | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, | |
1081 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | | |
1082 | DESC_L_MASK | | |
1083 | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); | |
1084 | #endif | |
1085 | write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, | |
1086 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | | |
1087 | (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); | |
1088 | } | |
1089 | ||
1090 | cpu_x86_load_seg(env, R_CS, __USER_CS); | |
1091 | cpu_x86_load_seg(env, R_SS, __USER_DS); | |
1092 | #ifdef TARGET_ABI32 | |
1093 | cpu_x86_load_seg(env, R_DS, __USER_DS); | |
1094 | cpu_x86_load_seg(env, R_ES, __USER_DS); | |
1095 | cpu_x86_load_seg(env, R_FS, __USER_DS); | |
1096 | cpu_x86_load_seg(env, R_GS, __USER_DS); | |
1097 | /* This hack makes Wine work... */ | |
1098 | env->segs[R_FS].selector = 0; | |
1099 | #else | |
1100 | cpu_x86_load_seg(env, R_DS, 0); | |
1101 | cpu_x86_load_seg(env, R_ES, 0); | |
1102 | cpu_x86_load_seg(env, R_FS, 0); | |
1103 | cpu_x86_load_seg(env, R_GS, 0); | |
1104 | #endif | |
1105 | #elif defined(TARGET_SPARC) | |
84778508 BS |
1106 | { |
1107 | int i; | |
1108 | env->pc = regs->pc; | |
1109 | env->npc = regs->npc; | |
1110 | env->y = regs->y; | |
1111 | for(i = 0; i < 8; i++) | |
1112 | env->gregs[i] = regs->u_regs[i]; | |
1113 | for(i = 0; i < 8; i++) | |
1114 | env->regwptr[i] = regs->u_regs[i + 8]; | |
1115 | } | |
1116 | #else | |
1117 | #error unsupported target CPU | |
1118 | #endif | |
1119 | ||
1120 | if (gdbstub_port) { | |
1121 | gdbserver_start (gdbstub_port); | |
db6b81d4 | 1122 | gdb_handlesig(cpu, 0); |
84778508 | 1123 | } |
78cfb07f | 1124 | cpu_loop(env); |
84778508 BS |
1125 | /* never exits */ |
1126 | return 0; | |
1127 | } |