Commit 83fb7adf6c653a0285a89d51b746cb642d2859cf

Authored by bellard
1 parent 1d43a717

Darwin patch (initial patch by Pierre d'Herbemont)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@980 c046a42c-6fe2-441c-8c8c-71466251a162
Makefile
1 include config-host.mak 1 include config-host.mak
2 2
3 CFLAGS=-Wall -O2 -g 3 CFLAGS=-Wall -O2 -g
  4 +ifdef CONFIG_DARWIN
  5 +CFLAGS+= -mdynamic-no-pic
  6 +endif
4 ifdef CONFIG_WIN32 7 ifdef CONFIG_WIN32
5 CFLAGS+=-fpack-struct 8 CFLAGS+=-fpack-struct
6 endif 9 endif
Makefile.target
@@ -100,6 +100,7 @@ LDFLAGS+=-Wl,-T,$(SRC_PATH)/amd64.ld @@ -100,6 +100,7 @@ LDFLAGS+=-Wl,-T,$(SRC_PATH)/amd64.ld
100 endif 100 endif
101 101
102 ifeq ($(ARCH),ppc) 102 ifeq ($(ARCH),ppc)
  103 +CFLAGS+= -D__powerpc__
103 OP_CFLAGS=$(CFLAGS) 104 OP_CFLAGS=$(CFLAGS)
104 LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld 105 LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld
105 endif 106 endif
@@ -152,6 +153,10 @@ ifeq ($(HAVE_GCC3_OPTIONS),yes) @@ -152,6 +153,10 @@ ifeq ($(HAVE_GCC3_OPTIONS),yes)
152 OP_CFLAGS+=-fno-reorder-blocks -fno-optimize-sibling-calls 153 OP_CFLAGS+=-fno-reorder-blocks -fno-optimize-sibling-calls
153 endif 154 endif
154 155
  156 +ifeq ($(CONFIG_DARWIN),yes)
  157 +OP_CFLAGS+= -mdynamic-no-pic
  158 +endif
  159 +
155 ######################################################### 160 #########################################################
156 161
157 DEFINES+=-D_GNU_SOURCE 162 DEFINES+=-D_GNU_SOURCE
@@ -267,9 +272,11 @@ endif @@ -267,9 +272,11 @@ endif
267 ifndef CONFIG_SOFTMMU 272 ifndef CONFIG_SOFTMMU
268 VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld 273 VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld
269 endif 274 endif
  275 +ifndef CONFIG_DARWIN
270 ifndef CONFIG_WIN32 276 ifndef CONFIG_WIN32
271 VL_LIBS=-lutil 277 VL_LIBS=-lutil
272 endif 278 endif
  279 +endif
273 280
274 $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a 281 $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
275 $(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(VL_LIBS) 282 $(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(VL_LIBS)
configure
@@ -88,12 +88,18 @@ bsd="yes" @@ -88,12 +88,18 @@ bsd="yes"
88 OpenBSD) 88 OpenBSD)
89 bsd="yes" 89 bsd="yes"
90 ;; 90 ;;
  91 +Darwin)
  92 +bsd="yes"
  93 +darwin="yes"
  94 +;;
91 *) ;; 95 *) ;;
92 esac 96 esac
93 97
94 if [ "$bsd" = "yes" ] ; then 98 if [ "$bsd" = "yes" ] ; then
95 - make="gmake"  
96 - target_list="i386-softmmu" 99 + if [ ! "$darwin" = "yes" ] ; then
  100 + make="gmake"
  101 + fi
  102 + target_list="i386-softmmu ppc-softmmu"
97 fi 103 fi
98 104
99 # find source path 105 # find source path
@@ -391,6 +397,10 @@ if test "$mingw32" = "yes" ; then @@ -391,6 +397,10 @@ if test "$mingw32" = "yes" ; then
391 elif test -f "/usr/include/byteswap.h" ; then 397 elif test -f "/usr/include/byteswap.h" ; then
392 echo "#define HAVE_BYTESWAP_H 1" >> $config_h 398 echo "#define HAVE_BYTESWAP_H 1" >> $config_h
393 fi 399 fi
  400 +if test "$darwin" = "yes" ; then
  401 + echo "CONFIG_DARWIN=yes" >> $config_mak
  402 + echo "#define CONFIG_DARWIN 1" >> $config_h
  403 +fi
394 if test "$gdbstub" = "yes" ; then 404 if test "$gdbstub" = "yes" ; then
395 echo "CONFIG_GDBSTUB=yes" >> $config_mak 405 echo "CONFIG_GDBSTUB=yes" >> $config_mak
396 echo "#define CONFIG_GDBSTUB 1" >> $config_h 406 echo "#define CONFIG_GDBSTUB 1" >> $config_h
@@ -417,10 +427,13 @@ echo "\"" >> $config_h @@ -417,10 +427,13 @@ echo "\"" >> $config_h
417 echo "SRC_PATH=$source_path" >> $config_mak 427 echo "SRC_PATH=$source_path" >> $config_mak
418 echo "TARGET_DIRS=$target_list" >> $config_mak 428 echo "TARGET_DIRS=$target_list" >> $config_mak
419 429
  430 +# XXX: suppress that
420 if [ "$bsd" = "yes" ] ; then 431 if [ "$bsd" = "yes" ] ; then
421 echo "#define O_LARGEFILE 0" >> $config_h 432 echo "#define O_LARGEFILE 0" >> $config_h
422 echo "#define lseek64 lseek" >> $config_h 433 echo "#define lseek64 lseek" >> $config_h
  434 + echo "#define mkstemp64 mkstemp" >> $config_h
423 echo "#define ftruncate64 ftruncate" >> $config_h 435 echo "#define ftruncate64 ftruncate" >> $config_h
  436 + echo "#define off64_t off_t" >> $config_h
424 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h 437 echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
425 echo "#define _BSD 1" >> $config_h 438 echo "#define _BSD 1" >> $config_h
426 fi 439 fi
cpu-all.h
@@ -538,12 +538,12 @@ static inline void stfq_raw(void *ptr, double v) @@ -538,12 +538,12 @@ static inline void stfq_raw(void *ptr, double v)
538 #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1) 538 #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
539 #define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK) 539 #define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
540 540
541 -extern unsigned long real_host_page_size;  
542 -extern unsigned long host_page_bits;  
543 -extern unsigned long host_page_size;  
544 -extern unsigned long host_page_mask; 541 +extern unsigned long qemu_real_host_page_size;
  542 +extern unsigned long qemu_host_page_bits;
  543 +extern unsigned long qemu_host_page_size;
  544 +extern unsigned long qemu_host_page_mask;
545 545
546 -#define HOST_PAGE_ALIGN(addr) (((addr) + host_page_size - 1) & host_page_mask) 546 +#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
547 547
548 /* same as PROT_xxx */ 548 /* same as PROT_xxx */
549 #define PAGE_READ 0x0001 549 #define PAGE_READ 0x0001
cpu-exec.c
@@ -852,24 +852,72 @@ int cpu_signal_handler(int host_signum, struct siginfo *info, @@ -852,24 +852,72 @@ int cpu_signal_handler(int host_signum, struct siginfo *info,
852 &uc->uc_sigmask, puc); 852 &uc->uc_sigmask, puc);
853 } 853 }
854 854
855 -#elif defined(__powerpc) 855 +#elif defined(__powerpc__)
856 856
857 -int cpu_signal_handler(int host_signum, struct siginfo *info, 857 +/***********************************************************************
  858 + * signal context platform-specific definitions
  859 + * From Wine
  860 + */
  861 +#ifdef linux
  862 +/* All Registers access - only for local access */
  863 +# define REG_sig(reg_name, context) ((context)->uc_mcontext.regs->reg_name)
  864 +/* Gpr Registers access */
  865 +# define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context)
  866 +# define IAR_sig(context) REG_sig(nip, context) /* Program counter */
  867 +# define MSR_sig(context) REG_sig(msr, context) /* Machine State Register (Supervisor) */
  868 +# define CTR_sig(context) REG_sig(ctr, context) /* Count register */
  869 +# define XER_sig(context) REG_sig(xer, context) /* User's integer exception register */
  870 +# define LR_sig(context) REG_sig(link, context) /* Link register */
  871 +# define CR_sig(context) REG_sig(ccr, context) /* Condition register */
  872 +/* Float Registers access */
  873 +# define FLOAT_sig(reg_num, context) (((double*)((char*)((context)->uc_mcontext.regs+48*4)))[reg_num])
  874 +# define FPSCR_sig(context) (*(int*)((char*)((context)->uc_mcontext.regs+(48+32*2)*4)))
  875 +/* Exception Registers access */
  876 +# define DAR_sig(context) REG_sig(dar, context)
  877 +# define DSISR_sig(context) REG_sig(dsisr, context)
  878 +# define TRAP_sig(context) REG_sig(trap, context)
  879 +#endif /* linux */
  880 +
  881 +#ifdef __APPLE__
  882 +# include <sys/ucontext.h>
  883 +typedef struct ucontext SIGCONTEXT;
  884 +/* All Registers access - only for local access */
  885 +# define REG_sig(reg_name, context) ((context)->uc_mcontext->ss.reg_name)
  886 +# define FLOATREG_sig(reg_name, context) ((context)->uc_mcontext->fs.reg_name)
  887 +# define EXCEPREG_sig(reg_name, context) ((context)->uc_mcontext->es.reg_name)
  888 +# define VECREG_sig(reg_name, context) ((context)->uc_mcontext->vs.reg_name)
  889 +/* Gpr Registers access */
  890 +# define GPR_sig(reg_num, context) REG_sig(r##reg_num, context)
  891 +# define IAR_sig(context) REG_sig(srr0, context) /* Program counter */
  892 +# define MSR_sig(context) REG_sig(srr1, context) /* Machine State Register (Supervisor) */
  893 +# define CTR_sig(context) REG_sig(ctr, context)
  894 +# define XER_sig(context) REG_sig(xer, context) /* Link register */
  895 +# define LR_sig(context) REG_sig(lr, context) /* User's integer exception register */
  896 +# define CR_sig(context) REG_sig(cr, context) /* Condition register */
  897 +/* Float Registers access */
  898 +# define FLOAT_sig(reg_num, context) FLOATREG_sig(fpregs[reg_num], context)
  899 +# define FPSCR_sig(context) ((double)FLOATREG_sig(fpscr, context))
  900 +/* Exception Registers access */
  901 +# define DAR_sig(context) EXCEPREG_sig(dar, context) /* Fault registers for coredump */
  902 +# define DSISR_sig(context) EXCEPREG_sig(dsisr, context)
  903 +# define TRAP_sig(context) EXCEPREG_sig(exception, context) /* number of powerpc exception taken */
  904 +#endif /* __APPLE__ */
  905 +
  906 +int cpu_signal_handler(int host_signum, siginfo *info,
858 void *puc) 907 void *puc)
859 { 908 {
860 struct ucontext *uc = puc; 909 struct ucontext *uc = puc;
861 - struct pt_regs *regs = uc->uc_mcontext.regs;  
862 unsigned long pc; 910 unsigned long pc;
863 int is_write; 911 int is_write;
864 912
865 - pc = regs->nip; 913 + pc = IAR_sig(uc);
866 is_write = 0; 914 is_write = 0;
867 #if 0 915 #if 0
868 /* ppc 4xx case */ 916 /* ppc 4xx case */
869 - if (regs->dsisr & 0x00800000) 917 + if (DSISR_sig(uc) & 0x00800000)
870 is_write = 1; 918 is_write = 1;
871 #else 919 #else
872 - if (regs->trap != 0x400 && (regs->dsisr & 0x02000000)) 920 + if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000))
873 is_write = 1; 921 is_write = 1;
874 #endif 922 #endif
875 return handle_cpu_signal(pc, (unsigned long)info->si_addr, 923 return handle_cpu_signal(pc, (unsigned long)info->si_addr,
dyngen-exec.h
@@ -59,8 +59,14 @@ extern int fprintf(FILE *, const char *, ...); @@ -59,8 +59,14 @@ extern int fprintf(FILE *, const char *, ...);
59 extern int printf(const char *, ...); 59 extern int printf(const char *, ...);
60 #undef NULL 60 #undef NULL
61 #define NULL 0 61 #define NULL 0
62 -#ifdef _BSD 62 +#if defined(_BSD) && !defined(__APPLE__)
63 #include <ieeefp.h> 63 #include <ieeefp.h>
  64 +
  65 +#define FE_TONEAREST FP_RN
  66 +#define FE_DOWNWARD FP_RM
  67 +#define FE_UPWARD FP_RP
  68 +#define FE_TOWARDZERO FP_RZ
  69 +#define fesetround(x) fpsetround(x)
64 #else 70 #else
65 #include <fenv.h> 71 #include <fenv.h>
66 #endif 72 #endif
@@ -100,10 +100,10 @@ typedef struct VirtPageDesc { @@ -100,10 +100,10 @@ typedef struct VirtPageDesc {
100 100
101 static void io_mem_init(void); 101 static void io_mem_init(void);
102 102
103 -unsigned long real_host_page_size;  
104 -unsigned long host_page_bits;  
105 -unsigned long host_page_size;  
106 -unsigned long host_page_mask; 103 +unsigned long qemu_real_host_page_size;
  104 +unsigned long qemu_host_page_bits;
  105 +unsigned long qemu_host_page_size;
  106 +unsigned long qemu_host_page_mask;
107 107
108 /* XXX: for system emulation, it could just be an array */ 108 /* XXX: for system emulation, it could just be an array */
109 static PageDesc *l1_map[L1_SIZE]; 109 static PageDesc *l1_map[L1_SIZE];
@@ -127,21 +127,21 @@ int loglevel; @@ -127,21 +127,21 @@ int loglevel;
127 127
128 static void page_init(void) 128 static void page_init(void)
129 { 129 {
130 - /* NOTE: we can always suppose that host_page_size >= 130 + /* NOTE: we can always suppose that qemu_host_page_size >=
131 TARGET_PAGE_SIZE */ 131 TARGET_PAGE_SIZE */
132 #ifdef _WIN32 132 #ifdef _WIN32
133 - real_host_page_size = 4096; 133 + qemu_real_host_page_size = 4096;
134 #else 134 #else
135 - real_host_page_size = getpagesize(); 135 + qemu_real_host_page_size = getpagesize();
136 #endif 136 #endif
137 - if (host_page_size == 0)  
138 - host_page_size = real_host_page_size;  
139 - if (host_page_size < TARGET_PAGE_SIZE)  
140 - host_page_size = TARGET_PAGE_SIZE;  
141 - host_page_bits = 0;  
142 - while ((1 << host_page_bits) < host_page_size)  
143 - host_page_bits++;  
144 - host_page_mask = ~(host_page_size - 1); 137 + if (qemu_host_page_size == 0)
  138 + qemu_host_page_size = qemu_real_host_page_size;
  139 + if (qemu_host_page_size < TARGET_PAGE_SIZE)
  140 + qemu_host_page_size = TARGET_PAGE_SIZE;
  141 + qemu_host_page_bits = 0;
  142 + while ((1 << qemu_host_page_bits) < qemu_host_page_size)
  143 + qemu_host_page_bits++;
  144 + qemu_host_page_mask = ~(qemu_host_page_size - 1);
145 #if !defined(CONFIG_USER_ONLY) 145 #if !defined(CONFIG_USER_ONLY)
146 virt_valid_tag = 1; 146 virt_valid_tag = 1;
147 #endif 147 #endif
@@ -831,12 +831,12 @@ static inline void tb_alloc_page(TranslationBlock *tb, @@ -831,12 +831,12 @@ static inline void tb_alloc_page(TranslationBlock *tb,
831 831
832 /* force the host page as non writable (writes will have a 832 /* force the host page as non writable (writes will have a
833 page fault + mprotect overhead) */ 833 page fault + mprotect overhead) */
834 - host_start = page_addr & host_page_mask;  
835 - host_end = host_start + host_page_size; 834 + host_start = page_addr & qemu_host_page_mask;
  835 + host_end = host_start + qemu_host_page_size;
836 prot = 0; 836 prot = 0;
837 for(addr = host_start; addr < host_end; addr += TARGET_PAGE_SIZE) 837 for(addr = host_start; addr < host_end; addr += TARGET_PAGE_SIZE)
838 prot |= page_get_flags(addr); 838 prot |= page_get_flags(addr);
839 - mprotect((void *)host_start, host_page_size, 839 + mprotect((void *)host_start, qemu_host_page_size,
840 (prot & PAGE_BITS) & ~PAGE_WRITE); 840 (prot & PAGE_BITS) & ~PAGE_WRITE);
841 #ifdef DEBUG_TB_INVALIDATE 841 #ifdef DEBUG_TB_INVALIDATE
842 printf("protecting code page: 0x%08lx\n", 842 printf("protecting code page: 0x%08lx\n",
@@ -1737,12 +1737,12 @@ int page_unprotect(unsigned long address, unsigned long pc, void *puc) @@ -1737,12 +1737,12 @@ int page_unprotect(unsigned long address, unsigned long pc, void *puc)
1737 PageDesc *p, *p1; 1737 PageDesc *p, *p1;
1738 unsigned long host_start, host_end, addr; 1738 unsigned long host_start, host_end, addr;
1739 1739
1740 - host_start = address & host_page_mask; 1740 + host_start = address & qemu_host_page_mask;
1741 page_index = host_start >> TARGET_PAGE_BITS; 1741 page_index = host_start >> TARGET_PAGE_BITS;
1742 p1 = page_find(page_index); 1742 p1 = page_find(page_index);
1743 if (!p1) 1743 if (!p1)
1744 return 0; 1744 return 0;
1745 - host_end = host_start + host_page_size; 1745 + host_end = host_start + qemu_host_page_size;
1746 p = p1; 1746 p = p1;
1747 prot = 0; 1747 prot = 0;
1748 for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) { 1748 for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) {
@@ -1754,7 +1754,7 @@ int page_unprotect(unsigned long address, unsigned long pc, void *puc) @@ -1754,7 +1754,7 @@ int page_unprotect(unsigned long address, unsigned long pc, void *puc)
1754 if (prot & PAGE_WRITE_ORG) { 1754 if (prot & PAGE_WRITE_ORG) {
1755 pindex = (address - host_start) >> TARGET_PAGE_BITS; 1755 pindex = (address - host_start) >> TARGET_PAGE_BITS;
1756 if (!(p1[pindex].flags & PAGE_WRITE)) { 1756 if (!(p1[pindex].flags & PAGE_WRITE)) {
1757 - mprotect((void *)host_start, host_page_size, 1757 + mprotect((void *)host_start, qemu_host_page_size,
1758 (prot & PAGE_BITS) | PAGE_WRITE); 1758 (prot & PAGE_BITS) | PAGE_WRITE);
1759 p1[pindex].flags |= PAGE_WRITE; 1759 p1[pindex].flags |= PAGE_WRITE;
1760 /* and since the content will be modified, we must invalidate 1760 /* and since the content will be modified, we must invalidate
linux-user/elfload.c
@@ -13,6 +13,16 @@ @@ -13,6 +13,16 @@
13 #include "qemu.h" 13 #include "qemu.h"
14 #include "disas.h" 14 #include "disas.h"
15 15
  16 +/* this flag is uneffective under linux too, should be deleted */
  17 +#ifndef MAP_DENYWRITE
  18 +#define MAP_DENYWRITE 0
  19 +#endif
  20 +
  21 +/* should probably go in elf.h */
  22 +#ifndef ELIBBAD
  23 +#define ELIBBAD 80
  24 +#endif
  25 +
16 #ifdef TARGET_I386 26 #ifdef TARGET_I386
17 27
18 #define ELF_START_MMAP 0x80000000 28 #define ELF_START_MMAP 0x80000000
@@ -332,7 +342,7 @@ static void * get_free_page(void) @@ -332,7 +342,7 @@ static void * get_free_page(void)
332 /* User-space version of kernel get_free_page. Returns a page-aligned 342 /* User-space version of kernel get_free_page. Returns a page-aligned
333 * page-sized chunk of memory. 343 * page-sized chunk of memory.
334 */ 344 */
335 - retval = (void *)target_mmap(0, host_page_size, PROT_READ|PROT_WRITE, 345 + retval = (void *)target_mmap(0, qemu_host_page_size, PROT_READ|PROT_WRITE,
336 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); 346 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
337 347
338 if((long)retval == -1) { 348 if((long)retval == -1) {
@@ -346,7 +356,7 @@ static void * get_free_page(void) @@ -346,7 +356,7 @@ static void * get_free_page(void)
346 356
347 static void free_page(void * pageaddr) 357 static void free_page(void * pageaddr)
348 { 358 {
349 - target_munmap((unsigned long)pageaddr, host_page_size); 359 + target_munmap((unsigned long)pageaddr, qemu_host_page_size);
350 } 360 }
351 361
352 /* 362 /*
@@ -502,7 +512,7 @@ unsigned long setup_arg_pages(unsigned long p, struct linux_binprm * bprm, @@ -502,7 +512,7 @@ unsigned long setup_arg_pages(unsigned long p, struct linux_binprm * bprm,
502 if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE) 512 if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
503 size = MAX_ARG_PAGES*TARGET_PAGE_SIZE; 513 size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
504 error = target_mmap(0, 514 error = target_mmap(0,
505 - size + host_page_size, 515 + size + qemu_host_page_size,
506 PROT_READ | PROT_WRITE, 516 PROT_READ | PROT_WRITE,
507 MAP_PRIVATE | MAP_ANONYMOUS, 517 MAP_PRIVATE | MAP_ANONYMOUS,
508 -1, 0); 518 -1, 0);
@@ -511,7 +521,7 @@ unsigned long setup_arg_pages(unsigned long p, struct linux_binprm * bprm, @@ -511,7 +521,7 @@ unsigned long setup_arg_pages(unsigned long p, struct linux_binprm * bprm,
511 exit(-1); 521 exit(-1);
512 } 522 }
513 /* we reserve one extra page at the top of the stack as guard */ 523 /* we reserve one extra page at the top of the stack as guard */
514 - target_mprotect(error + size, host_page_size, PROT_NONE); 524 + target_mprotect(error + size, qemu_host_page_size, PROT_NONE);
515 525
516 stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE; 526 stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE;
517 p += stack_base; 527 p += stack_base;
@@ -562,10 +572,10 @@ static void padzero(unsigned long elf_bss) @@ -562,10 +572,10 @@ static void padzero(unsigned long elf_bss)
562 of the file may not be mapped. A better fix would be to 572 of the file may not be mapped. A better fix would be to
563 patch target_mmap(), but it is more complicated as the file 573 patch target_mmap(), but it is more complicated as the file
564 size must be known */ 574 size must be known */
565 - if (real_host_page_size < host_page_size) { 575 + if (qemu_real_host_page_size < qemu_host_page_size) {
566 unsigned long end_addr, end_addr1; 576 unsigned long end_addr, end_addr1;
567 - end_addr1 = (elf_bss + real_host_page_size - 1) &  
568 - ~(real_host_page_size - 1); 577 + end_addr1 = (elf_bss + qemu_real_host_page_size - 1) &
  578 + ~(qemu_real_host_page_size - 1);
569 end_addr = HOST_PAGE_ALIGN(elf_bss); 579 end_addr = HOST_PAGE_ALIGN(elf_bss);
570 if (end_addr1 < end_addr) { 580 if (end_addr1 < end_addr) {
571 mmap((void *)end_addr1, end_addr - end_addr1, 581 mmap((void *)end_addr1, end_addr - end_addr1,
@@ -574,9 +584,9 @@ static void padzero(unsigned long elf_bss) @@ -574,9 +584,9 @@ static void padzero(unsigned long elf_bss)
574 } 584 }
575 } 585 }
576 586
577 - nbyte = elf_bss & (host_page_size-1); 587 + nbyte = elf_bss & (qemu_host_page_size-1);
578 if (nbyte) { 588 if (nbyte) {
579 - nbyte = host_page_size - nbyte; 589 + nbyte = qemu_host_page_size - nbyte;
580 fpnt = (char *) elf_bss; 590 fpnt = (char *) elf_bss;
581 do { 591 do {
582 *fpnt++ = 0; 592 *fpnt++ = 0;
@@ -811,7 +821,7 @@ static unsigned long load_elf_interp(struct elfhdr * interp_elf_ex, @@ -811,7 +821,7 @@ static unsigned long load_elf_interp(struct elfhdr * interp_elf_ex,
811 * bss page. 821 * bss page.
812 */ 822 */
813 padzero(elf_bss); 823 padzero(elf_bss);
814 - elf_bss = TARGET_ELF_PAGESTART(elf_bss + host_page_size - 1); /* What we have mapped so far */ 824 + elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); /* What we have mapped so far */
815 825
816 /* Map the last of the bss segment */ 826 /* Map the last of the bss segment */
817 if (last_bss > elf_bss) { 827 if (last_bss > elf_bss) {
@@ -1252,7 +1262,7 @@ static int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * r @@ -1252,7 +1262,7 @@ static int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * r
1252 and some applications "depend" upon this behavior. 1262 and some applications "depend" upon this behavior.
1253 Since we do not have the power to recompile these, we 1263 Since we do not have the power to recompile these, we
1254 emulate the SVr4 behavior. Sigh. */ 1264 emulate the SVr4 behavior. Sigh. */
1255 - mapped_addr = target_mmap(0, host_page_size, PROT_READ | PROT_EXEC, 1265 + mapped_addr = target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC,
1256 MAP_FIXED | MAP_PRIVATE, -1, 0); 1266 MAP_FIXED | MAP_PRIVATE, -1, 0);
1257 } 1267 }
1258 1268
linux-user/main.c
@@ -28,6 +28,11 @@ @@ -28,6 +28,11 @@
28 28
29 #define DEBUG_LOGFILE "/tmp/qemu.log" 29 #define DEBUG_LOGFILE "/tmp/qemu.log"
30 30
  31 +#ifdef __APPLE__
  32 +#include <crt_externs.h>
  33 +# define environ (*_NSGetEnviron())
  34 +#endif
  35 +
31 static const char *interp_prefix = CONFIG_QEMU_PREFIX; 36 static const char *interp_prefix = CONFIG_QEMU_PREFIX;
32 37
33 #if defined(__i386__) && !defined(CONFIG_STATIC) 38 #if defined(__i386__) && !defined(CONFIG_STATIC)
@@ -977,9 +982,9 @@ int main(int argc, char **argv) @@ -977,9 +982,9 @@ int main(int argc, char **argv)
977 } else if (!strcmp(r, "L")) { 982 } else if (!strcmp(r, "L")) {
978 interp_prefix = argv[optind++]; 983 interp_prefix = argv[optind++];
979 } else if (!strcmp(r, "p")) { 984 } else if (!strcmp(r, "p")) {
980 - host_page_size = atoi(argv[optind++]);  
981 - if (host_page_size == 0 ||  
982 - (host_page_size & (host_page_size - 1)) != 0) { 985 + qemu_host_page_size = atoi(argv[optind++]);
  986 + if (qemu_host_page_size == 0 ||
  987 + (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) {
983 fprintf(stderr, "page size must be a power of two\n"); 988 fprintf(stderr, "page size must be a power of two\n");
984 exit(1); 989 exit(1);
985 } 990 }
@@ -1006,8 +1011,8 @@ int main(int argc, char **argv) @@ -1006,8 +1011,8 @@ int main(int argc, char **argv)
1006 /* Scan interp_prefix dir for replacement files. */ 1011 /* Scan interp_prefix dir for replacement files. */
1007 init_paths(interp_prefix); 1012 init_paths(interp_prefix);
1008 1013
1009 - /* NOTE: we need to init the CPU at this stage to get the  
1010 - host_page_size */ 1014 + /* NOTE: we need to init the CPU at this stage to get
  1015 + qemu_host_page_size */
1011 env = cpu_init(); 1016 env = cpu_init();
1012 1017
1013 if (elf_exec(filename, argv+optind, environ, regs, info) != 0) { 1018 if (elf_exec(filename, argv+optind, environ, regs, info) != 0) {
linux-user/mmap.c
@@ -53,7 +53,7 @@ int target_mprotect(unsigned long start, unsigned long len, int prot) @@ -53,7 +53,7 @@ int target_mprotect(unsigned long start, unsigned long len, int prot)
53 if (len == 0) 53 if (len == 0)
54 return 0; 54 return 0;
55 55
56 - host_start = start & host_page_mask; 56 + host_start = start & qemu_host_page_mask;
57 host_end = HOST_PAGE_ALIGN(end); 57 host_end = HOST_PAGE_ALIGN(end);
58 if (start > host_start) { 58 if (start > host_start) {
59 /* handle host page containing start */ 59 /* handle host page containing start */
@@ -61,27 +61,27 @@ int target_mprotect(unsigned long start, unsigned long len, int prot) @@ -61,27 +61,27 @@ int target_mprotect(unsigned long start, unsigned long len, int prot)
61 for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { 61 for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
62 prot1 |= page_get_flags(addr); 62 prot1 |= page_get_flags(addr);
63 } 63 }
64 - if (host_end == host_start + host_page_size) { 64 + if (host_end == host_start + qemu_host_page_size) {
65 for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { 65 for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
66 prot1 |= page_get_flags(addr); 66 prot1 |= page_get_flags(addr);
67 } 67 }
68 end = host_end; 68 end = host_end;
69 } 69 }
70 - ret = mprotect((void *)host_start, host_page_size, prot1 & PAGE_BITS); 70 + ret = mprotect((void *)host_start, qemu_host_page_size, prot1 & PAGE_BITS);
71 if (ret != 0) 71 if (ret != 0)
72 return ret; 72 return ret;
73 - host_start += host_page_size; 73 + host_start += qemu_host_page_size;
74 } 74 }
75 if (end < host_end) { 75 if (end < host_end) {
76 prot1 = prot; 76 prot1 = prot;
77 for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { 77 for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
78 prot1 |= page_get_flags(addr); 78 prot1 |= page_get_flags(addr);
79 } 79 }
80 - ret = mprotect((void *)(host_end - host_page_size), host_page_size, 80 + ret = mprotect((void *)(host_end - qemu_host_page_size), qemu_host_page_size,
81 prot1 & PAGE_BITS); 81 prot1 & PAGE_BITS);
82 if (ret != 0) 82 if (ret != 0)
83 return ret; 83 return ret;
84 - host_end -= host_page_size; 84 + host_end -= qemu_host_page_size;
85 } 85 }
86 86
87 /* handle the pages in the middle */ 87 /* handle the pages in the middle */
@@ -102,7 +102,7 @@ int mmap_frag(unsigned long host_start, @@ -102,7 +102,7 @@ int mmap_frag(unsigned long host_start,
102 unsigned long host_end, ret, addr; 102 unsigned long host_end, ret, addr;
103 int prot1, prot_new; 103 int prot1, prot_new;
104 104
105 - host_end = host_start + host_page_size; 105 + host_end = host_start + qemu_host_page_size;
106 106
107 /* get the protection of the target pages outside the mapping */ 107 /* get the protection of the target pages outside the mapping */
108 prot1 = 0; 108 prot1 = 0;
@@ -113,7 +113,7 @@ int mmap_frag(unsigned long host_start, @@ -113,7 +113,7 @@ int mmap_frag(unsigned long host_start,
113 113
114 if (prot1 == 0) { 114 if (prot1 == 0) {
115 /* no page was there, so we allocate one */ 115 /* no page was there, so we allocate one */
116 - ret = (long)mmap((void *)host_start, host_page_size, prot, 116 + ret = (long)mmap((void *)host_start, qemu_host_page_size, prot,
117 flags | MAP_ANONYMOUS, -1, 0); 117 flags | MAP_ANONYMOUS, -1, 0);
118 if (ret == -1) 118 if (ret == -1)
119 return ret; 119 return ret;
@@ -130,18 +130,18 @@ int mmap_frag(unsigned long host_start, @@ -130,18 +130,18 @@ int mmap_frag(unsigned long host_start,
130 130
131 /* adjust protection to be able to read */ 131 /* adjust protection to be able to read */
132 if (!(prot1 & PROT_WRITE)) 132 if (!(prot1 & PROT_WRITE))
133 - mprotect((void *)host_start, host_page_size, prot1 | PROT_WRITE); 133 + mprotect((void *)host_start, qemu_host_page_size, prot1 | PROT_WRITE);
134 134
135 /* read the corresponding file data */ 135 /* read the corresponding file data */
136 pread(fd, (void *)start, end - start, offset); 136 pread(fd, (void *)start, end - start, offset);
137 137
138 /* put final protection */ 138 /* put final protection */
139 if (prot_new != (prot1 | PROT_WRITE)) 139 if (prot_new != (prot1 | PROT_WRITE))
140 - mprotect((void *)host_start, host_page_size, prot_new); 140 + mprotect((void *)host_start, qemu_host_page_size, prot_new);
141 } else { 141 } else {
142 /* just update the protection */ 142 /* just update the protection */
143 if (prot_new != prot1) { 143 if (prot_new != prot1) {
144 - mprotect((void *)host_start, host_page_size, prot_new); 144 + mprotect((void *)host_start, qemu_host_page_size, prot_new);
145 } 145 }
146 } 146 }
147 return 0; 147 return 0;
@@ -188,7 +188,7 @@ long target_mmap(unsigned long start, unsigned long len, int prot, @@ -188,7 +188,7 @@ long target_mmap(unsigned long start, unsigned long len, int prot,
188 len = TARGET_PAGE_ALIGN(len); 188 len = TARGET_PAGE_ALIGN(len);
189 if (len == 0) 189 if (len == 0)
190 return start; 190 return start;
191 - host_start = start & host_page_mask; 191 + host_start = start & qemu_host_page_mask;
192 192
193 if (!(flags & MAP_FIXED)) { 193 if (!(flags & MAP_FIXED)) {
194 #if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__) 194 #if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__)
@@ -198,10 +198,10 @@ long target_mmap(unsigned long start, unsigned long len, int prot, @@ -198,10 +198,10 @@ long target_mmap(unsigned long start, unsigned long len, int prot,
198 last_start += HOST_PAGE_ALIGN(len); 198 last_start += HOST_PAGE_ALIGN(len);
199 } 199 }
200 #endif 200 #endif
201 - if (host_page_size != real_host_page_size) { 201 + if (qemu_host_page_size != qemu_real_host_page_size) {
202 /* NOTE: this code is only for debugging with '-p' option */ 202 /* NOTE: this code is only for debugging with '-p' option */
203 /* reserve a memory area */ 203 /* reserve a memory area */
204 - host_len = HOST_PAGE_ALIGN(len) + host_page_size - TARGET_PAGE_SIZE; 204 + host_len = HOST_PAGE_ALIGN(len) + qemu_host_page_size - TARGET_PAGE_SIZE;
205 host_start = (long)mmap((void *)host_start, host_len, PROT_NONE, 205 host_start = (long)mmap((void *)host_start, host_len, PROT_NONE,
206 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 206 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
207 if (host_start == -1) 207 if (host_start == -1)
@@ -217,7 +217,7 @@ long target_mmap(unsigned long start, unsigned long len, int prot, @@ -217,7 +217,7 @@ long target_mmap(unsigned long start, unsigned long len, int prot,
217 flags |= MAP_FIXED; 217 flags |= MAP_FIXED;
218 } else { 218 } else {
219 /* if not fixed, no need to do anything */ 219 /* if not fixed, no need to do anything */
220 - host_offset = offset & host_page_mask; 220 + host_offset = offset & qemu_host_page_mask;
221 host_len = len + offset - host_offset; 221 host_len = len + offset - host_offset;
222 start = (long)mmap((void *)host_start, host_len, 222 start = (long)mmap((void *)host_start, host_len,
223 prot, flags, fd, host_offset); 223 prot, flags, fd, host_offset);
@@ -238,7 +238,7 @@ long target_mmap(unsigned long start, unsigned long len, int prot, @@ -238,7 +238,7 @@ long target_mmap(unsigned long start, unsigned long len, int prot,
238 /* worst case: we cannot map the file because the offset is not 238 /* worst case: we cannot map the file because the offset is not
239 aligned, so we read it */ 239 aligned, so we read it */
240 if (!(flags & MAP_ANONYMOUS) && 240 if (!(flags & MAP_ANONYMOUS) &&
241 - (offset & ~host_page_mask) != (start & ~host_page_mask)) { 241 + (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) {
242 /* msync() won't work here, so we return an error if write is 242 /* msync() won't work here, so we return an error if write is
243 possible while it is a shared mapping */ 243 possible while it is a shared mapping */
244 if ((flags & MAP_TYPE) == MAP_SHARED && 244 if ((flags & MAP_TYPE) == MAP_SHARED &&
@@ -260,7 +260,7 @@ long target_mmap(unsigned long start, unsigned long len, int prot, @@ -260,7 +260,7 @@ long target_mmap(unsigned long start, unsigned long len, int prot,
260 260
261 /* handle the start of the mapping */ 261 /* handle the start of the mapping */
262 if (start > host_start) { 262 if (start > host_start) {
263 - if (host_end == host_start + host_page_size) { 263 + if (host_end == host_start + qemu_host_page_size) {
264 /* one single host page */ 264 /* one single host page */
265 ret = mmap_frag(host_start, start, end, 265 ret = mmap_frag(host_start, start, end,
266 prot, flags, fd, offset); 266 prot, flags, fd, offset);
@@ -268,21 +268,21 @@ long target_mmap(unsigned long start, unsigned long len, int prot, @@ -268,21 +268,21 @@ long target_mmap(unsigned long start, unsigned long len, int prot,
268 return ret; 268 return ret;
269 goto the_end1; 269 goto the_end1;
270 } 270 }
271 - ret = mmap_frag(host_start, start, host_start + host_page_size, 271 + ret = mmap_frag(host_start, start, host_start + qemu_host_page_size,
272 prot, flags, fd, offset); 272 prot, flags, fd, offset);
273 if (ret == -1) 273 if (ret == -1)
274 return ret; 274 return ret;
275 - host_start += host_page_size; 275 + host_start += qemu_host_page_size;
276 } 276 }
277 /* handle the end of the mapping */ 277 /* handle the end of the mapping */
278 if (end < host_end) { 278 if (end < host_end) {
279 - ret = mmap_frag(host_end - host_page_size,  
280 - host_end - host_page_size, host_end, 279 + ret = mmap_frag(host_end - qemu_host_page_size,
  280 + host_end - qemu_host_page_size, host_end,
281 prot, flags, fd, 281 prot, flags, fd,
282 - offset + host_end - host_page_size - start); 282 + offset + host_end - qemu_host_page_size - start);
283 if (ret == -1) 283 if (ret == -1)
284 return ret; 284 return ret;
285 - host_end -= host_page_size; 285 + host_end -= qemu_host_page_size;
286 } 286 }
287 287
288 /* map the middle (easier) */ 288 /* map the middle (easier) */
@@ -322,7 +322,7 @@ int target_munmap(unsigned long start, unsigned long len) @@ -322,7 +322,7 @@ int target_munmap(unsigned long start, unsigned long len)
322 if (len == 0) 322 if (len == 0)
323 return -EINVAL; 323 return -EINVAL;
324 end = start + len; 324 end = start + len;
325 - host_start = start & host_page_mask; 325 + host_start = start & qemu_host_page_mask;
326 host_end = HOST_PAGE_ALIGN(end); 326 host_end = HOST_PAGE_ALIGN(end);
327 327
328 if (start > host_start) { 328 if (start > host_start) {
@@ -331,14 +331,14 @@ int target_munmap(unsigned long start, unsigned long len) @@ -331,14 +331,14 @@ int target_munmap(unsigned long start, unsigned long len)
331 for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { 331 for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
332 prot |= page_get_flags(addr); 332 prot |= page_get_flags(addr);
333 } 333 }
334 - if (host_end == host_start + host_page_size) { 334 + if (host_end == host_start + qemu_host_page_size) {
335 for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { 335 for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
336 prot |= page_get_flags(addr); 336 prot |= page_get_flags(addr);
337 } 337 }
338 end = host_end; 338 end = host_end;
339 } 339 }
340 if (prot != 0) 340 if (prot != 0)
341 - host_start += host_page_size; 341 + host_start += qemu_host_page_size;
342 } 342 }
343 if (end < host_end) { 343 if (end < host_end) {
344 prot = 0; 344 prot = 0;
@@ -346,7 +346,7 @@ int target_munmap(unsigned long start, unsigned long len) @@ -346,7 +346,7 @@ int target_munmap(unsigned long start, unsigned long len)
346 prot |= page_get_flags(addr); 346 prot |= page_get_flags(addr);
347 } 347 }
348 if (prot != 0) 348 if (prot != 0)
349 - host_end -= host_page_size; 349 + host_end -= qemu_host_page_size;
350 } 350 }
351 351
352 /* unmap what we can */ 352 /* unmap what we can */
@@ -391,7 +391,7 @@ int target_msync(unsigned long start, unsigned long len, int flags) @@ -391,7 +391,7 @@ int target_msync(unsigned long start, unsigned long len, int flags)
391 if (end == start) 391 if (end == start)
392 return 0; 392 return 0;
393 393
394 - start &= host_page_mask; 394 + start &= qemu_host_page_mask;
395 return msync((void *)start, end - start, flags); 395 return msync((void *)start, end - start, flags);
396 } 396 }
397 397
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 */ 23 */
24 #include "vl.h" 24 #include "vl.h"
25 25
26 -#ifndef _WIN32 26 +#if !defined(_WIN32) && !defined(__APPLE__)
27 #include <ctype.h> 27 #include <ctype.h>
28 #include <fcntl.h> 28 #include <fcntl.h>
29 #include <errno.h> 29 #include <errno.h>
target-i386/exec.h
@@ -498,7 +498,7 @@ static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr) @@ -498,7 +498,7 @@ static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr)
498 498
499 #define FPUC_EM 0x3f 499 #define FPUC_EM 0x3f
500 500
501 -const CPU86_LDouble f15rk[7]; 501 +extern const CPU86_LDouble f15rk[7];
502 502
503 void helper_fldt_ST0_A0(void); 503 void helper_fldt_ST0_A0(void);
504 void helper_fstt_ST0_A0(void); 504 void helper_fstt_ST0_A0(void);
@@ -528,9 +528,9 @@ void helper_frstor(uint8_t *ptr, int data32); @@ -528,9 +528,9 @@ void helper_frstor(uint8_t *ptr, int data32);
528 void restore_native_fp_state(CPUState *env); 528 void restore_native_fp_state(CPUState *env);
529 void save_native_fp_state(CPUState *env); 529 void save_native_fp_state(CPUState *env);
530 530
531 -const uint8_t parity_table[256];  
532 -const uint8_t rclw_table[32];  
533 -const uint8_t rclb_table[32]; 531 +extern const uint8_t parity_table[256];
  532 +extern const uint8_t rclw_table[32];
  533 +extern const uint8_t rclb_table[32];
534 534
535 static inline uint32_t compute_eflags(void) 535 static inline uint32_t compute_eflags(void)
536 { 536 {
target-i386/op.c
@@ -1955,24 +1955,6 @@ void OPPROTO op_fldcw_A0(void) @@ -1955,24 +1955,6 @@ void OPPROTO op_fldcw_A0(void)
1955 int rnd_type; 1955 int rnd_type;
1956 env->fpuc = lduw((void *)A0); 1956 env->fpuc = lduw((void *)A0);
1957 /* set rounding mode */ 1957 /* set rounding mode */
1958 -#ifdef _BSD  
1959 - switch(env->fpuc & RC_MASK) {  
1960 - default:  
1961 - case RC_NEAR:  
1962 - rnd_type = FP_RN;  
1963 - break;  
1964 - case RC_DOWN:  
1965 - rnd_type = FP_RM;  
1966 - break;  
1967 - case RC_UP:  
1968 - rnd_type = FP_RP;  
1969 - break;  
1970 - case RC_CHOP:  
1971 - rnd_type = FP_RZ;  
1972 - break;  
1973 - }  
1974 - fpsetround(rnd_type);  
1975 -#else  
1976 switch(env->fpuc & RC_MASK) { 1958 switch(env->fpuc & RC_MASK) {
1977 default: 1959 default:
1978 case RC_NEAR: 1960 case RC_NEAR:
@@ -1989,7 +1971,6 @@ void OPPROTO op_fldcw_A0(void) @@ -1989,7 +1971,6 @@ void OPPROTO op_fldcw_A0(void)
1989 break; 1971 break;
1990 } 1972 }
1991 fesetround(rnd_type); 1973 fesetround(rnd_type);
1992 -#endif  
1993 } 1974 }
1994 1975
1995 void OPPROTO op_fclex(void) 1976 void OPPROTO op_fclex(void)
@@ -40,7 +40,9 @@ @@ -40,7 +40,9 @@
40 #include <sys/socket.h> 40 #include <sys/socket.h>
41 #ifdef _BSD 41 #ifdef _BSD
42 #include <sys/stat.h> 42 #include <sys/stat.h>
  43 +#ifndef __APPLE__
43 #include <libutil.h> 44 #include <libutil.h>
  45 +#endif
44 #else 46 #else
45 #include <linux/if.h> 47 #include <linux/if.h>
46 #include <linux/if_tun.h> 48 #include <linux/if_tun.h>
@@ -63,6 +65,7 @@ @@ -63,6 +65,7 @@
63 #endif 65 #endif
64 66
65 #ifdef CONFIG_SDL 67 #ifdef CONFIG_SDL
  68 +#include <SDL/SDL.h>
66 #if defined(__linux__) 69 #if defined(__linux__)
67 /* SDL use the pthreads and they modify sigaction. We don't 70 /* SDL use the pthreads and they modify sigaction. We don't
68 want that. */ 71 want that. */
@@ -909,6 +912,7 @@ static void init_timers(void) @@ -909,6 +912,7 @@ static void init_timers(void)
909 the emulated kernel requested a too high timer frequency */ 912 the emulated kernel requested a too high timer frequency */
910 getitimer(ITIMER_REAL, &itv); 913 getitimer(ITIMER_REAL, &itv);
911 914
  915 +#if defined(__linux__)
912 if (itv.it_interval.tv_usec > 1000) { 916 if (itv.it_interval.tv_usec > 1000) {
913 /* try to use /dev/rtc to have a faster timer */ 917 /* try to use /dev/rtc to have a faster timer */
914 if (start_rtc_timer() < 0) 918 if (start_rtc_timer() < 0)
@@ -924,7 +928,9 @@ static void init_timers(void) @@ -924,7 +928,9 @@ static void init_timers(void)
924 sigaction(SIGIO, &act, NULL); 928 sigaction(SIGIO, &act, NULL);
925 fcntl(rtc_fd, F_SETFL, O_ASYNC); 929 fcntl(rtc_fd, F_SETFL, O_ASYNC);
926 fcntl(rtc_fd, F_SETOWN, getpid()); 930 fcntl(rtc_fd, F_SETOWN, getpid());
927 - } else { 931 + } else
  932 +#endif /* defined(__linux__) */
  933 + {
928 use_itimer: 934 use_itimer:
929 pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * 935 pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec *
930 PIT_FREQ) / 1000000; 936 PIT_FREQ) / 1000000;
@@ -2622,8 +2628,8 @@ int main(int argc, char **argv) @@ -2622,8 +2628,8 @@ int main(int argc, char **argv)
2622 2628
2623 #ifdef CONFIG_SOFTMMU 2629 #ifdef CONFIG_SOFTMMU
2624 #ifdef _BSD 2630 #ifdef _BSD
2625 - /* mallocs are always aligned on BSD. */  
2626 - phys_ram_base = malloc(phys_ram_size); 2631 + /* mallocs are always aligned on BSD. valloc is better for correctness */
  2632 + phys_ram_base = valloc(phys_ram_size);
2627 #else 2633 #else
2628 phys_ram_base = memalign(TARGET_PAGE_SIZE, phys_ram_size); 2634 phys_ram_base = memalign(TARGET_PAGE_SIZE, phys_ram_size);
2629 #endif 2635 #endif