1
Index: qemu-0.9.1/configure
2
===================================================================
3
--- qemu-0.9.1.orig/configure 2008-01-06 20:38:42.000000000 +0100
4
+++ qemu-0.9.1/configure 2008-04-14 11:27:20.000000000 +0200
15
*) echo "ERROR: unknown option $opt"; show_help="yes"
17
+ --disable-nptl) nptl="no"
23
echo " --disable-linux-user disable all linux usermode emulation targets"
24
echo " --enable-darwin-user enable all darwin usermode emulation targets"
25
echo " --disable-darwin-user disable all darwin usermode emulation targets"
26
+echo " --disable-nptl disable usermode NPTL guest support"
27
echo " --fmod-lib path to FMOD library"
28
echo " --fmod-inc path to FMOD includes"
29
echo " --enable-uname-release=R Return R for uname -r in usermode emulation"
45
+if $cc -c -o $TMPO $TMPC 2> /dev/null ; then
51
##########################################
55
echo "Documentation $build_docs"
56
[ ! -z "$uname_release" ] && \
57
echo "uname -r $uname_release"
58
+echo "NPTL support $nptl"
60
if test $sdl_too_old = "yes"; then
61
echo "-> Your SDL version is too old - please upgrade to have SDL support"
64
echo "SDL_CFLAGS=`$sdl_config --cflags`" >> $config_mak
67
+ if test "$nptl" = "yes" ; then
68
+ case "$target_cpu" in
70
+ echo "#define USE_NPTL 1" >> $config_h
75
if test "$cocoa" = "yes" ; then
76
echo "#define CONFIG_COCOA 1" >> $config_h
77
Index: qemu-0.9.1/exec-all.h
78
===================================================================
79
--- qemu-0.9.1.orig/exec-all.h 2008-01-06 20:38:42.000000000 +0100
80
+++ qemu-0.9.1/exec-all.h 2008-04-14 11:26:14.000000000 +0200
82
extern CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4];
83
extern void *io_mem_opaque[IO_MEM_NB_ENTRIES];
85
-#if defined(__powerpc__)
86
-static inline int testandset (int *p)
89
- __asm__ __volatile__ (
90
- "0: lwarx %0,0,%1\n"
97
- : "r" (p), "r" (1), "r" (0)
101
-#elif defined(__i386__)
102
-static inline int testandset (int *p)
104
- long int readval = 0;
106
- __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
107
- : "+m" (*p), "+a" (readval)
112
-#elif defined(__x86_64__)
113
-static inline int testandset (int *p)
115
- long int readval = 0;
117
- __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
118
- : "+m" (*p), "+a" (readval)
123
-#elif defined(__s390__)
124
-static inline int testandset (int *p)
128
- __asm__ __volatile__ ("0: cs %0,%1,0(%2)\n"
131
- : "r" (1), "a" (p), "0" (*p)
132
- : "cc", "memory" );
135
-#elif defined(__alpha__)
136
-static inline int testandset (int *p)
141
- __asm__ __volatile__ ("0: mov 1,%2\n"
148
- : "=r" (ret), "=m" (*p), "=r" (one)
152
-#elif defined(__sparc__)
153
-static inline int testandset (int *p)
157
- __asm__ __volatile__("ldstub [%1], %0"
162
- return (ret ? 1 : 0);
164
-#elif defined(__arm__)
165
-static inline int testandset (int *spinlock)
167
- register unsigned int ret;
168
- __asm__ __volatile__("swp %0, %1, [%2]"
170
- : "0"(1), "r"(spinlock));
174
-#elif defined(__mc68000)
175
-static inline int testandset (int *p)
178
- __asm__ __volatile__("tas %1; sne %0"
184
-#elif defined(__ia64)
186
-#include <ia64intrin.h>
188
-static inline int testandset (int *p)
190
- return __sync_lock_test_and_set (p, 1);
192
-#elif defined(__mips__)
193
-static inline int testandset (int *p)
197
- __asm__ __volatile__ (
206
- : "=r" (ret), "+R" (*p)
213
-#error unimplemented CPU support
216
-typedef int spinlock_t;
218
-#define SPIN_LOCK_UNLOCKED 0
220
-#if defined(CONFIG_USER_ONLY)
221
-static inline void spin_lock(spinlock_t *lock)
223
- while (testandset(lock));
226
-static inline void spin_unlock(spinlock_t *lock)
231
-static inline int spin_trylock(spinlock_t *lock)
233
- return !testandset(lock);
236
-static inline void spin_lock(spinlock_t *lock)
240
-static inline void spin_unlock(spinlock_t *lock)
244
-static inline int spin_trylock(spinlock_t *lock)
249
+#include "spinlock.h"
251
extern spinlock_t tb_lock;
253
Index: qemu-0.9.1/linux-user/arm/syscall.h
254
===================================================================
255
--- qemu-0.9.1.orig/linux-user/arm/syscall.h 2008-01-06 20:38:43.000000000 +0100
256
+++ qemu-0.9.1/linux-user/arm/syscall.h 2008-04-14 11:26:14.000000000 +0200
258
#define ARM_SYSCALL_BASE 0x900000
259
#define ARM_THUMB_SYSCALL 0
261
-#define ARM_NR_cacheflush (ARM_SYSCALL_BASE + 0xf0000 + 2)
262
+#define ARM_NR_BASE 0xf0000
263
+#define ARM_NR_cacheflush (ARM_NR_BASE + 2)
264
+#define ARM_NR_set_tls (ARM_NR_BASE + 5)
266
#define ARM_NR_semihosting 0x123456
267
#define ARM_NR_thumb_semihosting 0xAB
268
Index: qemu-0.9.1/linux-user/main.c
269
===================================================================
270
--- qemu-0.9.1.orig/linux-user/main.c 2008-04-14 11:26:14.000000000 +0200
271
+++ qemu-0.9.1/linux-user/main.c 2008-04-14 11:26:14.000000000 +0200
276
+/* Handle a jump to the kernel code page. */
278
+do_kernel_trap(CPUARMState *env)
284
+ switch (env->regs[15]) {
285
+ case 0xffff0fc0: /* __kernel_cmpxchg */
286
+ /* XXX: This only works between threads, not between processes.
287
+ Use native atomic operations. */
288
+ /* ??? This probably breaks horribly if the access segfaults. */
290
+ ptr = (uint32_t *)env->regs[2];
291
+ cpsr = cpsr_read(env);
292
+ if (*ptr == env->regs[0]) {
293
+ *ptr = env->regs[1];
300
+ cpsr_write(env, cpsr, CPSR_C);
303
+ case 0xffff0fe0: /* __kernel_get_tls */
304
+ env->regs[0] = env->cp15.c13_tls2;
309
+ /* Jump back to the caller. */
310
+ addr = env->regs[14];
315
+ env->regs[15] = addr;
320
void cpu_loop(CPUARMState *env)
327
- if (n == ARM_NR_cacheflush) {
328
- arm_cache_flush(env->regs[0], env->regs[1]);
329
- } else if (n == ARM_NR_semihosting
330
- || n == ARM_NR_thumb_semihosting) {
331
+ if (n == ARM_NR_semihosting
332
+ || n == ARM_NR_thumb_semihosting) {
333
env->regs[0] = do_arm_semihosting (env);
334
} else if (n == 0 || n >= ARM_SYSCALL_BASE
335
|| (env->thumb && n == ARM_THUMB_SYSCALL)) {
336
@@ -487,14 +529,35 @@
337
n -= ARM_SYSCALL_BASE;
340
- env->regs[0] = do_syscall(env,
348
+ if (n > ARM_NR_BASE) {
351
+ case ARM_NR_cacheflush:
352
+ arm_cache_flush(env->regs[0], env->regs[1]);
355
+ case ARM_NR_set_tls:
356
+ cpu_set_tls(env, env->regs[0]);
361
+ printf ("Error: Bad syscall: %x\n", n);
362
+ env->regs[0] = -ENOSYS;
368
+ env->regs[0] = do_syscall(env,
384
+ case EXCP_KERNEL_TRAP:
385
+ if (do_kernel_trap(env))
390
fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
391
@@ -2398,6 +2465,10 @@
392
ts->heap_base = info->brk;
393
/* This will be filled in on the first SYS_HEAPINFO call. */
395
+ /* Register the magic kernel code page. The cpu will generate a
396
+ special exception when it tries to execute code here. We can't
397
+ put real code here because it may be in use by the host kernel. */
398
+ page_set_flags(0xffff0000, 0xffff0fff, 0);
402
Index: qemu-0.9.1/linux-user/qemu.h
403
===================================================================
404
--- qemu-0.9.1.orig/linux-user/qemu.h 2008-01-06 20:38:42.000000000 +0100
405
+++ qemu-0.9.1/linux-user/qemu.h 2008-04-14 11:26:14.000000000 +0200
408
int used; /* non zero if used */
409
struct image_info *info;
411
+ uint32_t *child_tidptr;
414
} __attribute__((aligned(16))) TaskState;
416
Index: qemu-0.9.1/linux-user/syscall.c
417
===================================================================
418
--- qemu-0.9.1.orig/linux-user/syscall.c 2008-04-14 11:26:14.000000000 +0200
419
+++ qemu-0.9.1/linux-user/syscall.c 2008-04-14 11:27:21.000000000 +0200
421
#include <linux/kd.h>
424
+#include "spinlock.h"
429
+#define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
430
+ CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
432
+/* XXX: Hardcode the above values. */
433
+#define CLONE_NPTL_FLAGS2 0
436
#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
437
|| defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
438
/* 16 bit uid wrappers emulation */
439
@@ -2807,9 +2816,19 @@
441
#define NEW_STACK_SIZE 8192
444
+static spinlock_t nptl_lock = SPIN_LOCK_UNLOCKED;
447
static int clone_func(void *arg)
451
+ /* Wait until the parent has finshed initializing the tls state. */
452
+ while (!spin_trylock(&nptl_lock))
454
+ spin_unlock(&nptl_lock);
459
@@ -2817,12 +2836,20 @@
461
/* do_fork() Must return host values and target errnos (unlike most
462
do_*() functions). */
463
-int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp)
464
+int do_fork(CPUState *env, unsigned int flags, unsigned long newsp,
465
+ uint32_t *parent_tidptr, void *newtls,
466
+ uint32_t *child_tidptr)
473
+ unsigned int nptl_flags;
475
+ if (flags & CLONE_PARENT_SETTID)
476
+ *parent_tidptr = gettid();
479
if (flags & CLONE_VM) {
480
ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
481
@@ -2889,16 +2916,64 @@
482
#error unsupported target CPU
484
new_env->opaque = ts;
486
+ nptl_flags = flags;
487
+ flags &= ~CLONE_NPTL_FLAGS2;
489
+ if (nptl_flags & CLONE_CHILD_CLEARTID) {
490
+ ts->child_tidptr = child_tidptr;
493
+ if (nptl_flags & CLONE_SETTLS)
494
+ cpu_set_tls (new_env, newtls);
496
+ /* Grab the global cpu lock so that the thread setup appears
498
+ if (nptl_flags & CLONE_CHILD_SETTID)
499
+ spin_lock(&nptl_lock);
502
+ if (flags & CLONE_NPTL_FLAGS2)
506
ret = __clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
508
ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
512
+ if (nptl_flags & CLONE_CHILD_SETTID)
513
+ *child_tidptr = ret;
516
+ /* Allow the child to continue. */
517
+ if (nptl_flags & CLONE_CHILD_SETTID)
518
+ spin_unlock(&nptl_lock);
521
/* if no CLONE_VM, we consider it is a fork */
522
- if ((flags & ~CSIGNAL) != 0)
523
+ if ((flags & ~(CSIGNAL | CLONE_NPTL_FLAGS2)) != 0)
527
+ /* There is a race condition here. The parent process could
528
+ theoretically read the TID in the child process before the child
529
+ tid is set. This would require using either ptrace
530
+ (not implemented) or having *_tidptr to point at a shared memory
531
+ mapping. We can't repeat the spinlock hack used above because
532
+ the child process gets its own copy of the lock. */
534
+ /* Child Process. */
535
+ if (flags & CLONE_CHILD_SETTID)
536
+ *child_tidptr = gettid();
537
+ ts = (TaskState *)env->opaque;
538
+ if (flags & CLONE_CHILD_CLEARTID)
539
+ ts->child_tidptr = child_tidptr;
540
+ if (flags & CLONE_SETTLS)
541
+ cpu_set_tls (env, newtls);
547
@@ -3223,7 +3298,7 @@
551
- ret = get_errno(do_fork(cpu_env, SIGCHLD, 0));
552
+ ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, NULL, NULL, NULL));
554
#ifdef TARGET_NR_waitpid
555
case TARGET_NR_waitpid:
556
@@ -4586,7 +4661,8 @@
557
ret = get_errno(fsync(arg1));
559
case TARGET_NR_clone:
560
- ret = get_errno(do_fork(cpu_env, arg1, arg2));
561
+ ret = get_errno(do_fork(cpu_env, arg1, arg2, (uint32_t *)arg3,
562
+ (void *)arg4, (uint32_t *)arg5));
564
#ifdef __NR_exit_group
565
/* new thread calls */
566
@@ -5031,7 +5107,8 @@
568
#ifdef TARGET_NR_vfork
569
case TARGET_NR_vfork:
570
- ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0));
571
+ ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0,
572
+ NULL, NULL, NULL));
575
#ifdef TARGET_NR_ugetrlimit
576
Index: qemu-0.9.1/spinlock.h
577
===================================================================
578
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
579
+++ qemu-0.9.1/spinlock.h 2008-04-14 11:26:14.000000000 +0200
582
+ * Atomic operation helper include
584
+ * Copyright (c) 2005 Fabrice Bellard
586
+ * This library is free software; you can redistribute it and/or
587
+ * modify it under the terms of the GNU Lesser General Public
588
+ * License as published by the Free Software Foundation; either
589
+ * version 2 of the License, or (at your option) any later version.
591
+ * This library is distributed in the hope that it will be useful,
592
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
593
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
594
+ * Lesser General Public License for more details.
596
+ * You should have received a copy of the GNU Lesser General Public
597
+ * License along with this library; if not, write to the Free Software
598
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
603
+#if defined(__powerpc__)
604
+static inline int testandset (int *p)
607
+ __asm__ __volatile__ (
608
+ "0: lwarx %0,0,%1\n"
611
+ " stwcx. %2,0,%1\n"
615
+ : "r" (p), "r" (1), "r" (0)
616
+ : "cr0", "memory");
619
+#elif defined(__i386__)
620
+static inline int testandset (int *p)
622
+ long int readval = 0;
624
+ __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
625
+ : "+m" (*p), "+a" (readval)
630
+#elif defined(__x86_64__)
631
+static inline int testandset (int *p)
633
+ long int readval = 0;
635
+ __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
636
+ : "+m" (*p), "+a" (readval)
641
+#elif defined(__s390__)
642
+static inline int testandset (int *p)
646
+ __asm__ __volatile__ ("0: cs %0,%1,0(%2)\n"
649
+ : "r" (1), "a" (p), "0" (*p)
650
+ : "cc", "memory" );
653
+#elif defined(__alpha__)
654
+static inline int testandset (int *p)
659
+ __asm__ __volatile__ ("0: mov 1,%2\n"
666
+ : "=r" (ret), "=m" (*p), "=r" (one)
670
+#elif defined(__sparc__)
671
+static inline int testandset (int *p)
675
+ __asm__ __volatile__("ldstub [%1], %0"
680
+ return (ret ? 1 : 0);
682
+#elif defined(__arm__)
683
+static inline int testandset (int *spinlock)
685
+ register unsigned int ret;
686
+ __asm__ __volatile__("swp %0, %1, [%2]"
688
+ : "0"(1), "r"(spinlock));
692
+#elif defined(__mc68000)
693
+static inline int testandset (int *p)
696
+ __asm__ __volatile__("tas %1; sne %0"
702
+#elif defined(__ia64)
704
+#include <ia64intrin.h>
706
+static inline int testandset (int *p)
708
+ return __sync_lock_test_and_set (p, 1);
710
+#elif defined(__mips__)
711
+static inline int testandset (int *p)
715
+ __asm__ __volatile__ (
724
+ : "=r" (ret), "+R" (*p)
731
+#error unimplemented CPU support
734
+typedef int spinlock_t;
736
+#define SPIN_LOCK_UNLOCKED 0
738
+#if defined(CONFIG_USER_ONLY)
739
+static inline void spin_lock(spinlock_t *lock)
741
+ while (testandset(lock));
744
+static inline void spin_unlock(spinlock_t *lock)
749
+static inline int spin_trylock(spinlock_t *lock)
751
+ return !testandset(lock);
754
+static inline void spin_lock(spinlock_t *lock)
758
+static inline void spin_unlock(spinlock_t *lock)
762
+static inline int spin_trylock(spinlock_t *lock)
769
Index: qemu-0.9.1/target-arm/cpu.h
770
===================================================================
771
--- qemu-0.9.1.orig/target-arm/cpu.h 2008-01-06 20:38:44.000000000 +0100
772
+++ qemu-0.9.1/target-arm/cpu.h 2008-04-14 11:26:14.000000000 +0200
776
#define EXCP_EXCEPTION_EXIT 8 /* Return from v7M exception. */
777
+#define EXCP_KERNEL_TRAP 9 /* Jumped to kernel code page. */
779
#define ARMV7M_EXCP_RESET 1
780
#define ARMV7M_EXCP_NMI 2
783
void cpu_unlock(void);
785
+void cpu_lock(void);
786
+void cpu_unlock(void);
787
+#if defined(USE_NPTL)
788
+static inline void cpu_set_tls(CPUARMState *env, void *newtls)
790
+ env->cp15.c13_tls2 = (uint32_t)(long)newtls;
794
#define CPSR_M (0x1f)
795
#define CPSR_T (1 << 5)
796
#define CPSR_F (1 << 6)
797
Index: qemu-0.9.1/target-arm/op.c
798
===================================================================
799
--- qemu-0.9.1.orig/target-arm/op.c 2008-01-06 20:38:44.000000000 +0100
800
+++ qemu-0.9.1/target-arm/op.c 2008-04-14 11:26:14.000000000 +0200
801
@@ -1009,6 +1009,12 @@
805
+void OPPROTO op_kernel_trap(void)
807
+ env->exception_index = EXCP_KERNEL_TRAP;
811
/* VFP support. We follow the convention used for VFP instrunctions:
812
Single precition routines have a "s" suffix, double precision a
814
Index: qemu-0.9.1/target-arm/translate.c
815
===================================================================
816
--- qemu-0.9.1.orig/target-arm/translate.c 2008-01-06 20:38:44.000000000 +0100
817
+++ qemu-0.9.1/target-arm/translate.c 2008-04-14 11:26:14.000000000 +0200
818
@@ -7519,6 +7519,13 @@
819
conditional execution block. */
820
gen_op_exception_exit();
823
+ /* Intercept jump to the magic kernel page. */
824
+ if (dc->pc > 0xffff0000) {
825
+ gen_op_kernel_trap();
826
+ dc->is_jmp = DISAS_UPDATE;
831
if (env->nb_breakpoints > 0) {